Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5c139ee authored by Jorge Gil's avatar Jorge Gil
Browse files

[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
parent 2403a485
Loading
Loading
Loading
Loading
+22 −7
Original line number Diff line number Diff line
@@ -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) {
            if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
                prepareMoveTaskToDesk(wct, task, destinationDeskId)
            } else {
                addMoveToDesktopChanges(wct, task, displayId)
        } else if (Flags.enableMoveToNextDisplayShortcut()) {
            applyFreeformDisplayChange(wct, task, displayId)
            }

        } else {
            if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
                desksOrganizer.moveTaskToDesk(wct, destinationDeskId, task)
        } else {
            }
            if (Flags.enableMoveToNextDisplayShortcut()) {
                applyFreeformDisplayChange(wct, task, displayId)
            }
        }

        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 ->
                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
+14 −2
Original line number Diff line number Diff line
@@ -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()