From b5c139eef0853c5e1d824b30a89ebe7a0d6901a4 Mon Sep 17 00:00:00 2001 From: Jorge Gil Date: Wed, 26 Feb 2025 04:51:03 +0000 Subject: [28/N] Desks: Always use prepareMoveTaskToDesk Migrates callsites still using addMoveToDesktopChanges() to using prepareMoveTaskToDesk(). The latter is the multi-desk version of the former that ensures the task is reparented to the destination desk and skips some windowing-mode changes that are not needed because it doesn't need to be inherited from the TDA anymore. In the next CL, these two will be merged into a single function to avoid repetition and misuse of either one. Flag: com.android.window.flags.enable_multiple_desktops_backend Bug: 362720497 Test: (1) while in desktop, force launch a fullscreen task via adb and make sure it is reparented to the freeform root when it gets forced into freeform. (2) move a freeform task to another display and make sure it is also reparented to the freeform root. (3) same as (2) but moving a fullscreen task. Change-Id: Iff6475b6c367d6cdb4215ee067330acc19294f3c --- .../wm/shell/desktopmode/DesktopTasksController.kt | 29 ++++++++++++++++------ .../desktopmode/DesktopTasksControllerTest.kt | 16 ++++++++++-- 2 files changed, 36 insertions(+), 9 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 5331a52ae112..0e2328154474 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 @@ -1252,6 +1252,8 @@ class DesktopTasksController( * Move [task] to display with [displayId]. * * No-op if task is already on that display per [RunningTaskInfo.displayId]. + * + * TODO: b/399411604 - split this up into smaller functions. */ private fun moveToDisplay(task: RunningTaskInfo, displayId: Int) { logV("moveToDisplay: taskId=%d displayId=%d", task.taskId, displayId) @@ -1307,16 +1309,24 @@ class DesktopTasksController( // TODO: b/393977830 and b/397437641 - do not assume that freeform==desktop. if (!task.isFreeform) { - addMoveToDesktopChanges(wct, task, displayId) - } else if (Flags.enableMoveToNextDisplayShortcut()) { - applyFreeformDisplayChange(wct, task, displayId) + if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) { + prepareMoveTaskToDesk(wct, task, destinationDeskId) + } else { + addMoveToDesktopChanges(wct, task, displayId) + } + } else { + if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) { + desksOrganizer.moveTaskToDesk(wct, destinationDeskId, task) + } + if (Flags.enableMoveToNextDisplayShortcut()) { + applyFreeformDisplayChange(wct, task, displayId) + } } - if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) { - desksOrganizer.moveTaskToDesk(wct, destinationDeskId, task) - } else { + if (!DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) { wct.reparent(task.token, displayAreaInfo.token, /* onTop= */ true) } + addDeskActivationChanges(destinationDeskId, wct) val activationRunnable: RunOnTransitStart = { transition -> desksTransitionObserver.addPendingTransition( @@ -2408,7 +2418,12 @@ class DesktopTasksController( if (shouldFullscreenTaskLaunchSwitchToDesktop(task)) { logD("Switch fullscreen task to freeform on transition: taskId=%d", task.taskId) return WindowContainerTransaction().also { wct -> - addMoveToDesktopChanges(wct, task) + val deskId = getDefaultDeskId(task.displayId) + if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) { + prepareMoveTaskToDesk(wct, task, deskId) + } else { + addMoveToDesktopChanges(wct, task) + } // In some launches home task is moved behind new task being launched. Make sure // that's not the case for launches in desktop. Also, if this launch is the first // one to trigger the desktop mode (e.g., when [forceEnterDesktop()]), activate the 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 521b8f7d1d49..20123d1f8235 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 @@ -2819,7 +2819,6 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() } @Test - @DisableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun moveToNextDisplay_toDesktopInOtherDisplay_bringsExistingTasksToFront() { val transition = Binder() val sourceDeskId = 0 @@ -2851,7 +2850,6 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() Flags.FLAG_ENABLE_PER_DISPLAY_DESKTOP_WALLPAPER_ACTIVITY, Flags.FLAG_ENABLE_DESKTOP_WALLPAPER_ACTIVITY_FOR_SYSTEM_USER, ) - @DisableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) fun moveToNextDisplay_toDesktopInOtherDisplay_movesHomeAndWallpaperToFront() { val homeTask = setUpHomeTask(displayId = SECOND_DISPLAY) whenever(desktopWallpaperActivityTokenProvider.getToken(SECOND_DISPLAY)) @@ -3500,6 +3498,20 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() verify(snapEventHandler).removeTaskIfTiled(eq(DEFAULT_DISPLAY), eq(task.taskId)) } + @Test + @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND) + fun handleRequest_fullscreenTask_switchToDesktop_movesTaskToDesk() { + taskRepository.addDesk(displayId = DEFAULT_DISPLAY, deskId = 5) + setUpFreeformTask(displayId = DEFAULT_DISPLAY, deskId = 5) + taskRepository.setActiveDesk(displayId = DEFAULT_DISPLAY, deskId = 5) + + val fullscreenTask = createFullscreenTask() + val wct = controller.handleRequest(Binder(), createTransition(fullscreenTask)) + + assertNotNull(wct, "should handle request") + verify(desksOrganizer).moveTaskToDesk(wct = wct, deskId = 5, task = fullscreenTask) + } + @Test fun handleRequest_fullscreenTask_freeformVisible_returnSwitchToFreeformWCT() { val homeTask = setUpHomeTask() -- cgit v1.2.3-59-g8ed1b