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

Commit 9c4db782 authored by Jorge Gil's avatar Jorge Gil
Browse files

Apply task-limit policy in #moveToDisplay

Moving a task to a another displays means that if the display already
had desktop tasks at the limit, one of them must be minimized to make
room for the opening one.

The task-limit policy is already handled in addDeskActivationChanges,
but it relies on the |newTask| paremeter to indicate that a task is
moving into the desk along with the activation.

Flag: com.android.window.flags.enable_move_to_next_display_shortcut
Bug: 402144410
Test: Move task to other display with already open tasks at the limit,
verify the last task closes
Test: atest WMShellUnitTests

Change-Id: I4a26098ec2e386faf543011c655616df86518ee2
parent 7d9d76cf
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -1255,8 +1255,7 @@ class DesktopTasksController(
            wct.reparent(task.token, displayAreaInfo.token, /* onTop= */ true)
        }

        // TODO: b/391485148 - pass in the moving-to-desk |task| here to apply task-limit policy.
        val activationRunnable = addDeskActivationChanges(destinationDeskId, wct)
        val activationRunnable = addDeskActivationChanges(destinationDeskId, wct, task)

        if (Flags.enableDisplayFocusInShellTransitions()) {
            // Bring the destination display to top with includingParents=true, so that the
+32 −1
Original line number Diff line number Diff line
@@ -3121,6 +3121,36 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        verify(desksOrganizer).reorderTaskToFront(wct, targetDeskId, task2)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun moveToNextDisplay_toDesktopInOtherDisplay_appliesTaskLimit() {
        val transition = Binder()
        val sourceDeskId = 0
        val targetDeskId = 2
        taskRepository.addDesk(displayId = SECOND_DISPLAY, deskId = targetDeskId)
        taskRepository.setDeskInactive(deskId = targetDeskId)
        val targetDeskTasks =
            (1..MAX_TASK_LIMIT + 1).map { _ ->
                setUpFreeformTask(displayId = SECOND_DISPLAY, deskId = targetDeskId)
            }
        // Set up two display ids
        whenever(rootTaskDisplayAreaOrganizer.displayIds)
            .thenReturn(intArrayOf(DEFAULT_DISPLAY, SECOND_DISPLAY))
        // Create a mock for the target display area: second display
        val secondDisplayArea = DisplayAreaInfo(MockToken().token(), SECOND_DISPLAY, 0)
        whenever(rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(SECOND_DISPLAY))
            .thenReturn(secondDisplayArea)
        whenever(transitions.startTransition(eq(TRANSIT_CHANGE), any(), anyOrNull()))
            .thenReturn(transition)
        val task = setUpFreeformTask(displayId = DEFAULT_DISPLAY, deskId = sourceDeskId)

        controller.moveToNextDisplay(task.taskId)

        val wct = getLatestTransition()
        assertNotNull(wct)
        verify(desksOrganizer).minimizeTask(wct, targetDeskId, targetDeskTasks[0])
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY,
@@ -3190,10 +3220,11 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        verify(desksOrganizer).activateDesk(any(), eq(targetDeskId))
        verify(desksTransitionsObserver)
            .addPendingTransition(
                DeskTransition.ActivateDesk(
                DeskTransition.ActiveDeskWithTask(
                    token = transition,
                    displayId = SECOND_DISPLAY,
                    deskId = targetDeskId,
                    enterTaskId = task.taskId,
                )
            )
    }