diff options
Diffstat (limited to 'libs')
2 files changed, 30 insertions, 29 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayModeController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayModeController.kt index 78c377bc1234..e89aafe267ed 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayModeController.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayModeController.kt @@ -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) } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopDisplayModeControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopDisplayModeControllerTest.kt index 0ff7230f6e0c..f0c97d359a16 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopDisplayModeControllerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopDisplayModeControllerTest.kt @@ -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() - defaultTDA.configuration.windowConfiguration.windowingMode = WINDOWING_MODE_FREEFORM + 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, ) } |