summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jorge Gil <jorgegil@google.com> 2025-03-18 06:49:40 +0000
committer Jorge Gil <jorgegil@google.com> 2025-03-18 21:16:01 +0000
commitf79e25ab7129408d3160c62d4fc6b75d16810664 (patch)
tree9ac9eaf4b0f6994b8cdfbe3bc4c686f7faf8faee
parent066735051374dda7e6584bcacb0250186717dd4d (diff)
Desks: Deactivate desk on other desk activation
Flag: com.android.window.flags.enable_multiple_desktops_backend Bug: 404545438 Test: have two desks, move from one to the other using adb command, verify dumpsys shows it as deactivated. Then go home, new tasks open in fullscreen. Change-Id: I2f1765f7bfe7f6e420ca260a045f0eeef0da7c36
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt5
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt27
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,