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

Commit 2297155a authored by Eric Lin's avatar Eric Lin
Browse files

Fix bubble task inheriting freeform windowing mode.

Prevent bubble tasks from inheriting the windowing mode from their
source task if the source is in freeform mode. This fixes an issue where
launching a recycled bubble task from a trampoline activity in desktop
mode would incorrectly change its windowing mode to freeform.

The expected behavior is for the bubbled task to relaunch and expand
while remaining in multi-window mode. This allows the shell
DefaultMixedHandler (LaunchNewTaskBubbleForExistingTransition) to
process the transition correctly, avoiding an unnecessary windowing mode
change in the WM core.

Bug: 432606505
Flag: EXEMPT BUGFIX
Test: atest WmTests:TaskLaunchParamsModifierTests
Change-Id: I4f55dd764e4f52fdad25826b5b92d23f9ea325cc
parent 1996bc3a
Loading
Loading
Loading
Loading
+20 −2
Original line number Original line Diff line number Diff line
@@ -153,7 +153,7 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
        // source is a freeform window in a fullscreen display launching an activity on the same
        // source is a freeform window in a fullscreen display launching an activity on the same
        // display.
        // display.
        if (launchMode == WINDOWING_MODE_UNDEFINED
        if (launchMode == WINDOWING_MODE_UNDEFINED
                && canInheritWindowingModeFromSource(display, suggestedDisplayArea, source)) {
                && canInheritWindowingModeFromSource(display, suggestedDisplayArea, source, task)) {
            // The source's windowing mode may be different from its task, e.g. activity is set
            // The source's windowing mode may be different from its task, e.g. activity is set
            // to fullscreen and its task is pinned windowing mode when the activity is entering
            // to fullscreen and its task is pinned windowing mode when the activity is entering
            // pip.
            // pip.
@@ -411,8 +411,18 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
                && launchMode != task.getRequestedOverrideWindowingMode();
                && launchMode != task.getRequestedOverrideWindowingMode();
    }
    }


    /**
     * Determines whether a task can inherit the windowing mode from its source activity.
     *
     * @param display the display where the task will be launched.
     * @param suggestedDisplayArea the suggested display area for the task.
     * @param source the source activity that initiated the launch, or null if none.
     * @param targetTask the task being launched, or null if creating a new task.
     * @return true if the target task can inherit the source's windowing mode, false otherwise.
     */
    private boolean canInheritWindowingModeFromSource(@NonNull DisplayContent display,
    private boolean canInheritWindowingModeFromSource(@NonNull DisplayContent display,
            TaskDisplayArea suggestedDisplayArea, @Nullable ActivityRecord source) {
            TaskDisplayArea suggestedDisplayArea, @Nullable ActivityRecord source,
            @Nullable Task targetTask) {
        if (source == null) {
        if (source == null) {
            return false;
            return false;
        }
        }
@@ -424,12 +434,20 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
            return false;
            return false;
        }
        }


        // Only fullscreen and freeform sources are allowed to inherit their windowing mode.
        final int sourceWindowingMode = source.getTask().getWindowingMode();
        final int sourceWindowingMode = source.getTask().getWindowingMode();
        if (sourceWindowingMode != WINDOWING_MODE_FULLSCREEN
        if (sourceWindowingMode != WINDOWING_MODE_FULLSCREEN
                && sourceWindowingMode != WINDOWING_MODE_FREEFORM) {
                && sourceWindowingMode != WINDOWING_MODE_FREEFORM) {
            return false;
            return false;
        }
        }


        // Bubble task can only inherit from the fullscreen source task.
        // TODO(b/407669465): Replace mLaunchNextToBubble with property check in root task approach.
        if (sourceWindowingMode == WINDOWING_MODE_FREEFORM && targetTask != null
                && targetTask.mLaunchNextToBubble) {
            return false;
        }

        // Only inherit windowing mode if both source and target activities are on the same display.
        // Only inherit windowing mode if both source and target activities are on the same display.
        // Otherwise we may have unintended freeform windows showing up if an activity in freeform
        // Otherwise we may have unintended freeform windows showing up if an activity in freeform
        // window launches an activity on a fullscreen display by specifying display ID.
        // window launches an activity on a fullscreen display by specifying display ID.
+21 −0
Original line number Original line Diff line number Diff line
@@ -681,6 +681,27 @@ public class TaskLaunchParamsModifierTests extends
                WINDOWING_MODE_FULLSCREEN);
                WINDOWING_MODE_FULLSCREEN);
    }
    }


    @Test
    public void testBubbleTaskDoesNotInheritFreeformModeFromSource() {
        final TestDisplayContent fullscreenDisplay = createNewDisplayContent(
                WINDOWING_MODE_FULLSCREEN);
        // Source activity is in a freeform trampoline task.
        final ActivityRecord source = createSourceActivity(fullscreenDisplay);
        source.getTask().setWindowingMode(WINDOWING_MODE_FREEFORM);
        // The task to be launched is a bubble task
        final Task bubbleTask = new TaskBuilder(mSupervisor)
                .setTaskDisplayArea(fullscreenDisplay.getDefaultTaskDisplayArea())
                .setWindowingMode(WINDOWING_MODE_MULTI_WINDOW)
                .build();
        bubbleTask.mLaunchNextToBubble = true;

        assertEquals(RESULT_CONTINUE,
                new CalculateRequestBuilder().setSource(source).setTask(bubbleTask).calculate());

        assertEquivalentWindowingMode(WINDOWING_MODE_MULTI_WINDOW, mResult.mWindowingMode,
                WINDOWING_MODE_FULLSCREEN /* parentWindowingMode */);
    }

    @Test
    @Test
    public void testInheritsSourceTaskWindowingModeWhenActivityIsInDifferentWindowingMode() {
    public void testInheritsSourceTaskWindowingModeWhenActivityIsInDifferentWindowingMode() {
        final TestDisplayContent fullscreenDisplay = createNewDisplayContent(
        final TestDisplayContent fullscreenDisplay = createNewDisplayContent(