Loading libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayModeController.kt +20 −23 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) } Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopDisplayModeControllerTest.kt +10 −6 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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()) Loading @@ -139,7 +143,7 @@ class DesktopDisplayModeControllerTest : ShellTestCase() { testDisplayWindowingModeSwitch( defaultWindowingMode = WINDOWING_MODE_FULLSCREEN, extendedDisplayEnabled = false, expectTransition = false, expectToSwitch = false, ) } Loading @@ -148,7 +152,7 @@ class DesktopDisplayModeControllerTest : ShellTestCase() { testDisplayWindowingModeSwitch( defaultWindowingMode = WINDOWING_MODE_FULLSCREEN, extendedDisplayEnabled = true, expectTransition = true, expectToSwitch = true, ) } Loading @@ -157,7 +161,7 @@ class DesktopDisplayModeControllerTest : ShellTestCase() { testDisplayWindowingModeSwitch( defaultWindowingMode = WINDOWING_MODE_FREEFORM, extendedDisplayEnabled = true, expectTransition = false, expectToSwitch = false, ) } Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayModeController.kt +20 −23 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) } Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopDisplayModeControllerTest.kt +10 −6 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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()) Loading @@ -139,7 +143,7 @@ class DesktopDisplayModeControllerTest : ShellTestCase() { testDisplayWindowingModeSwitch( defaultWindowingMode = WINDOWING_MODE_FULLSCREEN, extendedDisplayEnabled = false, expectTransition = false, expectToSwitch = false, ) } Loading @@ -148,7 +152,7 @@ class DesktopDisplayModeControllerTest : ShellTestCase() { testDisplayWindowingModeSwitch( defaultWindowingMode = WINDOWING_MODE_FULLSCREEN, extendedDisplayEnabled = true, expectTransition = true, expectToSwitch = true, ) } Loading @@ -157,7 +161,7 @@ class DesktopDisplayModeControllerTest : ShellTestCase() { testDisplayWindowingModeSwitch( defaultWindowingMode = WINDOWING_MODE_FREEFORM, extendedDisplayEnabled = true, expectTransition = false, expectToSwitch = false, ) } Loading