Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ca541264 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Extract desktop-first decision factors into methods" into main

parents 90c86f58 603363a5
Loading
Loading
Loading
Loading
+20 −23
Original line number Diff line number Diff line
@@ -48,30 +48,8 @@ class DesktopDisplayModeController(

    fun refreshDisplayWindowingMode() {
        if (!DesktopExperienceFlags.ENABLE_DISPLAY_WINDOWING_MODE_SWITCHING.isTrue) return
        // TODO: b/375319538 - Replace the check with a DisplayManager API once it's available.
        val isExtendedDisplayEnabled =
            0 !=
                Settings.Global.getInt(
                    context.contentResolver,
                    DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS,
                    0,
                )
        if (!isExtendedDisplayEnabled) {
            // No action needed in mirror or projected mode.
            return
        }

        val hasNonDefaultDisplay =
            rootTaskDisplayAreaOrganizer.getDisplayIds().any { displayId ->
                displayId != DEFAULT_DISPLAY
            }
        val targetDisplayWindowingMode =
            if (hasNonDefaultDisplay) {
                WINDOWING_MODE_FREEFORM
            } else {
                // Use the default display windowing mode when no non-default display.
                windowManager.getWindowingMode(DEFAULT_DISPLAY)
            }
        val targetDisplayWindowingMode = getTargetWindowingModeForDefaultDisplay()
        val tdaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(DEFAULT_DISPLAY)
        requireNotNull(tdaInfo) { "DisplayAreaInfo of DEFAULT_DISPLAY must be non-null." }
        val currentDisplayWindowingMode = tdaInfo.configuration.windowConfiguration.windowingMode
@@ -111,6 +89,25 @@ class DesktopDisplayModeController(
        transitions.startTransition(TRANSIT_CHANGE, wct, /* handler= */ null)
    }

    private fun getTargetWindowingModeForDefaultDisplay(): Int {
        if (isExtendedDisplayEnabled() && hasExternalDisplay()) {
            return WINDOWING_MODE_FREEFORM
        }
        return windowManager.getWindowingMode(DEFAULT_DISPLAY)
    }

    // TODO: b/375319538 - Replace the check with a DisplayManager API once it's available.
    private fun isExtendedDisplayEnabled() =
        0 !=
            Settings.Global.getInt(
                context.contentResolver,
                DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS,
                0,
            )

    private fun hasExternalDisplay() =
        rootTaskDisplayAreaOrganizer.getDisplayIds().any { it != DEFAULT_DISPLAY }

    private fun logV(msg: String, vararg arguments: Any?) {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
    }
+10 −6
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ class DesktopDisplayModeControllerTest : ShellTestCase() {
    private fun testDisplayWindowingModeSwitch(
        defaultWindowingMode: Int,
        extendedDisplayEnabled: Boolean,
        expectTransition: Boolean,
        expectToSwitch: Boolean,
    ) {
        defaultTDA.configuration.windowConfiguration.windowingMode = defaultWindowingMode
        whenever(mockWindowManager.getWindowingMode(anyInt())).thenReturn(defaultWindowingMode)
@@ -113,10 +113,14 @@ class DesktopDisplayModeControllerTest : ShellTestCase() {

        settingsSession.use {
            connectExternalDisplay()
            if (expectToSwitch) {
                // Assumes [connectExternalDisplay] properly triggered the switching transition.
                // Will verify the transition later along with [disconnectExternalDisplay].
                defaultTDA.configuration.windowConfiguration.windowingMode = WINDOWING_MODE_FREEFORM
            }
            disconnectExternalDisplay()

            if (expectTransition) {
            if (expectToSwitch) {
                val arg = argumentCaptor<WindowContainerTransaction>()
                verify(transitions, times(2))
                    .startTransition(eq(TRANSIT_CHANGE), arg.capture(), isNull())
@@ -139,7 +143,7 @@ class DesktopDisplayModeControllerTest : ShellTestCase() {
        testDisplayWindowingModeSwitch(
            defaultWindowingMode = WINDOWING_MODE_FULLSCREEN,
            extendedDisplayEnabled = false,
            expectTransition = false,
            expectToSwitch = false,
        )
    }

@@ -148,7 +152,7 @@ class DesktopDisplayModeControllerTest : ShellTestCase() {
        testDisplayWindowingModeSwitch(
            defaultWindowingMode = WINDOWING_MODE_FULLSCREEN,
            extendedDisplayEnabled = true,
            expectTransition = true,
            expectToSwitch = true,
        )
    }

@@ -157,7 +161,7 @@ class DesktopDisplayModeControllerTest : ShellTestCase() {
        testDisplayWindowingModeSwitch(
            defaultWindowingMode = WINDOWING_MODE_FREEFORM,
            extendedDisplayEnabled = true,
            expectTransition = false,
            expectToSwitch = false,
        )
    }