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

Commit f23196c5 authored by Ben Lin's avatar Ben Lin
Browse files

DesktopTasksController: Supply displayId when re-launching bg apps.

When launching background apps we don't go through the normal flow -
launcher requests a re-launch of background apps since they are depicted
as "minimized". Because this is a different codepath, we end up creating
a different ActivityOptions, and by default without a displayId supplied
the task ends up being launched into default display.

This also passes displayId into startLaunchTransition so the desk
activation work can be properly setup.

Bug: 414393986
Test: Manual (Open Chrome on ext. display, press back, open chrome again
using taskbar - Chrome opens on ext. display)
Test: atest
Flag:com.android.window.flags.enable_bug_fixes_for_secondary_display

Change-Id: I8937ab08bbd38cf5c3a97051f89c2ae1cd8c8b97
parent 894af0f1
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -1451,22 +1451,30 @@ class DesktopTasksController(
    ) {
        logV("moveBackgroundTaskToFront taskId=%s", taskId)
        val wct = WindowContainerTransaction()

        val deskId =
            taskRepository.getDeskIdForTask(taskId)
                ?: getOrCreateDefaultDeskId(DEFAULT_DISPLAY)
                ?: return
        val displayId =
            if (ENABLE_BUG_FIXES_FOR_SECONDARY_DISPLAY.isTrue)
                taskRepository.getDisplayForDesk(deskId)
            else DEFAULT_DISPLAY
        wct.startTask(
            taskId,
            ActivityOptions.makeBasic()
                .apply { launchWindowingMode = WINDOWING_MODE_FREEFORM }
                .apply {
                    launchWindowingMode = WINDOWING_MODE_FREEFORM
                    launchDisplayId = displayId
                }
                .toBundle(),
        )
        val deskId =
            taskRepository.getDeskIdForTask(taskId)
                ?: getOrCreateDefaultDeskId(DEFAULT_DISPLAY)
                ?: return
        startLaunchTransition(
            TRANSIT_OPEN,
            wct,
            taskId,
            deskId = deskId,
            displayId = DEFAULT_DISPLAY,
            displayId = displayId,
            remoteTransition = remoteTransition,
            unminimizeReason = unminimizeReason,
        )
+44 −0
Original line number Diff line number Diff line
@@ -3157,6 +3157,43 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        wct.assertLaunchTask(task.taskId, WINDOWING_MODE_FREEFORM)
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND,
        Flags.FLAG_ENABLE_BUG_FIXES_FOR_SECONDARY_DISPLAY,
    )
    fun moveTaskToFront_backgroundTask_launchesTask_launchesToExistingDisplay() {
        val deskId = 2
        val taskId = 1
        val task = createRecentTaskInfo(taskId, displayId = SECOND_DISPLAY)
        taskRepository.addDesk(displayId = SECOND_DISPLAY, deskId = deskId)
        taskRepository.setActiveDesk(displayId = SECOND_DISPLAY, deskId = deskId)
        taskRepository.addTaskToDesk(
            displayId = SECOND_DISPLAY,
            deskId = deskId,
            taskId = task.taskId,
            isVisible = true,
        )
        whenever(shellTaskOrganizer.getRunningTaskInfo(anyInt())).thenReturn(null)
        whenever(
                desktopMixedTransitionHandler.startLaunchTransition(
                    eq(TRANSIT_OPEN),
                    any(),
                    anyOrNull(),
                    anyOrNull(),
                    anyOrNull(),
                    anyOrNull(),
                    anyOrNull(),
                )
            )
            .thenReturn(Binder())

        controller.moveTaskToFront(task.taskId, unminimizeReason = UnminimizeReason.UNKNOWN)

        val wct = getLatestDesktopMixedTaskWct(type = TRANSIT_OPEN)
        wct.assertLaunchTaskOnDisplay(SECOND_DISPLAY)
    }

    @Test
    @DisableFlags(
        Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND,
@@ -10544,6 +10581,13 @@ private fun WindowContainerTransaction.assertLaunchTask(taskId: Int, windowingMo
    }
}

private fun WindowContainerTransaction.assertLaunchTaskOnDisplay(displayId: Int) {
    val keyLaunchWindowingMode = "android.activity.windowingMode"
    val keyLaunchDisplayId = "android.activity.launchDisplayId"

    assertHop { hop -> hop.launchOptions?.getInt(keyLaunchDisplayId, DEFAULT_DISPLAY) == displayId }
}

private fun WindowContainerTransaction.assertLaunchTaskAt(
    index: Int,
    taskId: Int,