diff options
2 files changed, 31 insertions, 1 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt index 5849d4af4e7e..1e5514407ee5 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt @@ -2892,7 +2892,7 @@ class DesktopTasksController( * null and may be used to run other desktop policies, such as minimizing another task if the * task limit has been exceeded. */ - fun addDeskActivationChanges( + private fun addDeskActivationChanges( deskId: Int, wct: WindowContainerTransaction, newTask: TaskInfo? = null, @@ -2950,6 +2950,8 @@ class DesktopTasksController( } } } + val deactivatingDesk = taskRepository.getActiveDeskId(displayId)?.takeIf { it != deskId } + val deactivationRunnable = prepareDeskDeactivationIfNeeded(wct, deactivatingDesk) return { transition -> val activateDeskTransition = if (newTaskIdInFront != null) { @@ -2970,6 +2972,7 @@ class DesktopTasksController( taskIdToMinimize?.let { minimizingTask -> addPendingMinimizeTransition(transition, minimizingTask, MinimizeReason.TASK_LIMIT) } + deactivationRunnable?.invoke(transition) } } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt index b577667d8279..d495f76e7814 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt @@ -5639,6 +5639,33 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() } @Test + @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) + fun activateDesk_otherDeskWasActive_deactivatesOtherDesk() { + val previouslyActiveDeskId = 1 + val activatingDeskId = 0 + val transition = Binder() + val deskChange = mock(TransitionInfo.Change::class.java) + whenever(transitions.startTransition(eq(TRANSIT_TO_FRONT), any(), anyOrNull())) + .thenReturn(transition) + whenever(desksOrganizer.isDeskActiveAtEnd(deskChange, activatingDeskId)).thenReturn(true) + // Make desk inactive by activating another desk. + taskRepository.addDesk(DEFAULT_DISPLAY, deskId = previouslyActiveDeskId) + taskRepository.setActiveDesk(DEFAULT_DISPLAY, deskId = previouslyActiveDeskId) + + controller.activateDesk(activatingDeskId, RemoteTransition(TestRemoteTransition())) + + verify(desksOrganizer).deactivateDesk(any(), eq(previouslyActiveDeskId)) + verify(desksTransitionsObserver) + .addPendingTransition( + argThat { + this is DeskTransition.DeactivateDesk && + this.token == transition && + this.deskId == previouslyActiveDeskId + } + ) + } + + @Test @EnableFlags( Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION, Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND, |