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

Commit 40260c4f authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Skip move-to-desktop for tasks with disabled entry points

When using the move-to-next-display shortcut, some tasks should not
be moved to the desktop. This change adds a check to respect the
`DesktopModeCompatPolicy` and prevents the move for such tasks.

Bug: 424748132
Test: DesktopTasksControllerTest
Flag: com.android.window.flags.move_to_next_display_shortcut_with_projected_mode
Change-Id: I9079aa20d781b2f0d8cbd0157c39eda8096ee58e
parent d42028a7
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2432,6 +2432,13 @@ class DesktopTasksController(
            snapEventHandler.removeTaskIfTiled(task.displayId, task.taskId)
            // TODO: b/393977830 and b/397437641 - do not assume that freeform==desktop.
            if (!task.isFreeform) {
                if (desktopModeCompatPolicy.shouldDisableDesktopEntryPoints(task)) {
                    logW(
                        "moveToDisplay: do nothing because the desktop entry points should be " +
                            "disabled for the focused task"
                    )
                    return
                }
                addMoveToDeskTaskChanges(wct = wct, task = task, deskId = destinationDeskId)
            } else {
                if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
+53 −1
Original line number Diff line number Diff line
@@ -4412,6 +4412,58 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        wct.assertPendingIntentActivityOptionsLaunchDisplayId(SECOND_DISPLAY)
    }

    @Test
    @EnableFlags(
        FLAG_ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT,
        FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND,
        FLAG_MOVE_TO_NEXT_DISPLAY_SHORTCUT_WITH_PROJECTED_MODE,
    )
    fun moveToNextDesktopDisplay_projectedMode_movesToDesktopOnConnectedDisplay() {
        // Setup state where a desktop task is running on a secondary display while the device is in
        // projected mode
        desktopState.isProjected = true
        whenever(rootTaskDisplayAreaOrganizer.displayIds)
            .thenReturn(intArrayOf(DEFAULT_DISPLAY, SECOND_DISPLAY))
        taskRepository.addDesk(displayId = SECOND_DISPLAY, deskId = SECOND_DISPLAY)
        val task = setUpFullscreenTask(displayId = DEFAULT_DISPLAY)
        doReturn(false).whenever(desktopModeCompatPolicy).shouldDisableDesktopEntryPoints(task)

        controller.moveToNextDesktopDisplay(
            taskId = task.taskId,
            userId = taskRepository.userId,
            enterReason = EnterReason.UNKNOWN_ENTER,
        )

        verify(desksOrganizer).moveTaskToDesk(any(), eq(SECOND_DISPLAY), eq(task), eq(false))
    }

    @Test
    @EnableFlags(
        FLAG_ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT,
        FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND,
        FLAG_MOVE_TO_NEXT_DISPLAY_SHORTCUT_WITH_PROJECTED_MODE,
    )
    fun moveToNextDesktopDisplay_projectedMode_movesToDesktopOnConnectedDisplay_skipTasksWithDisabledEntryPoints() {
        // Setup state where a desktop task is running on a secondary display while the device is in
        // projected mode
        desktopState.isProjected = true
        whenever(rootTaskDisplayAreaOrganizer.displayIds)
            .thenReturn(intArrayOf(DEFAULT_DISPLAY, SECOND_DISPLAY))
        taskRepository.addDesk(displayId = SECOND_DISPLAY, deskId = SECOND_DISPLAY)
        val task = setUpFullscreenTask(displayId = DEFAULT_DISPLAY)

        // The task should not have desktop entry points
        doReturn(true).whenever(desktopModeCompatPolicy).shouldDisableDesktopEntryPoints(task)

        controller.moveToNextDesktopDisplay(
            taskId = task.taskId,
            userId = taskRepository.userId,
            enterReason = EnterReason.UNKNOWN_ENTER,
        )

        verify(desksOrganizer, never()).moveTaskToDesk(any(), any(), eq(task), any())
    }

    private fun moveToNextDesktopDisplay_moveIifDesktopModeSupportedOnDestination(
        isDesktopModeSupportedOnDestination: Boolean
    ) {