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

Commit ec76e65d authored by Daichi Hirono's avatar Daichi Hirono
Browse files

Use source display for desktop mode cleanup

When moving a task to another display, the desktop mode cleanup was
incorrectly using the destination display ID. This change ensures that
the cleanup is performed on the source display where the task
originated.

Bug: 424748132
Test: DesktopTasksControllerTest
Flag: com.android.window.flags.move_to_next_display_shortcut_with_projected_mode
Change-Id: I85a5934aa5b0794369ddf18f0d661d4fcdb52635
parent fc934955
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -4148,10 +4148,30 @@ class DesktopTasksController(
            return performDesktopExitCleanUp(
                wct = wct,
                deskId = deskId,
                displayId = displayId,
                displayId =
                    if (
                        DesktopExperienceFlags.MOVE_TO_NEXT_DISPLAY_SHORTCUT_WITH_PROJECTED_MODE
                            .isTrue
                    ) {
                        // Use the source display ID for clean up when the bug fix flag is enabled.
                        taskInfo.displayId
                    } else {
                        // Before the bug fix, display move is not considered.
                        displayId
                    },
                willExitDesktop = true,
                removingLastTaskId = if (isLastTask) taskInfo.taskId else null,
                shouldEndUpAtHome = false,
                shouldEndUpAtHome =
                    if (
                        DesktopExperienceFlags.MOVE_TO_NEXT_DISPLAY_SHORTCUT_WITH_PROJECTED_MODE
                            .isTrue
                    ) {
                        // If the last task is moved from the display, it should go to home.
                        displayId != taskInfo.displayId
                    } else {
                        // Before the bug fix, display move is not considered.
                        false
                    },
                exitReason = ExitReason.FULLSCREEN_LAUNCH,
            )
        }
+42 −0
Original line number Diff line number Diff line
@@ -4201,6 +4201,48 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        assertThat(configChange.windowingMode).isEqualTo(WINDOWING_MODE_FULLSCREEN)
    }

    @Test
    @EnableFlags(
        FLAG_ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT,
        FLAG_MOVE_TO_NEXT_DISPLAY_SHORTCUT_WITH_PROJECTED_MODE,
    )
    fun moveToNextDesktopDisplay_projectedMode_cleansUpSourceDisplay() {
        // 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))
        val defaultDisplayArea = DisplayAreaInfo(MockToken().token(), DEFAULT_DISPLAY, 0)
        whenever(rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(DEFAULT_DISPLAY))
            .thenReturn(defaultDisplayArea)
        val deskId = SECOND_DISPLAY
        taskRepository.addDesk(displayId = SECOND_DISPLAY, deskId = deskId)
        taskRepository.setActiveDesk(displayId = SECOND_DISPLAY, deskId = deskId)
        val task = setUpFreeformTask(displayId = SECOND_DISPLAY)
        // Explicitly add task to the desk because removing the last task in a desk triggers desktop
        // mode cleanup.
        taskRepository.addTaskToDesk(
            displayId = SECOND_DISPLAY,
            deskId = deskId,
            taskId = task.taskId,
            isVisible = true,
            taskBounds = TASK_BOUNDS,
        )

        controller.moveToNextDesktopDisplay(task.taskId, EnterReason.UNKNOWN_ENTER)

        val wct =
            getLatestWct(
                type = TRANSIT_CHANGE,
                handlerClass = DesktopModeMoveToDisplayTransitionHandler::class.java,
            )

        // Verify that cleanup (e.g. resetting the launcher) is performed on the source display
        // where the task originated from.
        wct.assertPendingIntent(launchHomeIntent(SECOND_DISPLAY))
        wct.assertPendingIntentActivityOptionsLaunchDisplayId(SECOND_DISPLAY)
    }

    private fun moveToNextDesktopDisplay_moveIifDesktopModeSupportedOnDestination(
        isDesktopModeSupportedOnDestination: Boolean
    ) {