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

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

DesktopTasksController: Supply displayId when creating new instance.

When launching new instances of apps we don't go through the normal
PendingIntent flow, and instead goes through a new window flow. This
supplies the displayId to the ActivityOptions so that Core processes the
display correctly.

Bug: 415268190
Test: atest, Manual (new window on Clank via app header)
Flag: com.android.window.flags.enable_bug_fixes_for_secondary_display
Change-Id: I5fa6ce1f6b89b1e51cdbfac7901897e8a1eac681
parent f23196c5
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -2825,11 +2825,16 @@ class DesktopTasksController(
                    error("Invalid windowing mode: $newTaskWindowingMode")
                }
            }
        val displayId =
            if (ENABLE_BUG_FIXES_FOR_SECONDARY_DISPLAY.isTrue)
                taskRepository.getDisplayForDesk(deskId)
            else DEFAULT_DISPLAY
        return ActivityOptions.makeBasic().apply {
            launchWindowingMode = newTaskWindowingMode
            pendingIntentBackgroundActivityStartMode =
                ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS
            launchBounds = bounds
            launchDisplayId = displayId
        }
    }

+51 −0
Original line number Diff line number Diff line
@@ -8011,6 +8011,57 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            .isEqualTo(WINDOWING_MODE_FREEFORM)
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MULTI_INSTANCE_FEATURES,
        Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND,
        Flags.FLAG_ENABLE_BUG_FIXES_FOR_SECONDARY_DISPLAY,
    )
    fun newWindow_fromFreeformAddsNewWindow_launchesToCallingDisplay() {
        setUpLandscapeDisplay()
        val deskId = 2
        taskRepository.addDesk(displayId = SECOND_DISPLAY, deskId = deskId)
        taskRepository.setActiveDesk(displayId = SECOND_DISPLAY, deskId = deskId)
        val task = setUpFreeformTask(displayId = SECOND_DISPLAY, deskId = deskId)
        val wctCaptor = argumentCaptor<WindowContainerTransaction>()
        val transition = Binder()
        whenever(
                mMockDesktopImmersiveController.exitImmersiveIfApplicable(
                    any(),
                    anyInt(),
                    anyOrNull(),
                    any(),
                )
            )
            .thenReturn(ExitResult.NoExit)
        whenever(
                desktopMixedTransitionHandler.startLaunchTransition(
                    anyInt(),
                    any(),
                    anyOrNull(),
                    anyOrNull(),
                    anyOrNull(),
                    anyOrNull(),
                    anyOrNull(),
                )
            )
            .thenReturn(transition)

        runOpenNewWindow(task)

        verify(desktopMixedTransitionHandler)
            .startLaunchTransition(
                anyInt(),
                wctCaptor.capture(),
                anyOrNull(),
                anyOrNull(),
                anyOrNull(),
                anyOrNull(),
                anyOrNull(),
            )
        wctCaptor.firstValue.assertLaunchTaskOnDisplay(SECOND_DISPLAY)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MULTI_INSTANCE_FEATURES)
    fun newWindow_fromFreeform_exitsImmersiveIfNeeded() {