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

Commit 311f8594 authored by Eric Lin's avatar Eric Lin Committed by Android (Google) Code Review
Browse files

Merge "Fix bubble task inheriting freeform windowing mode." into main

parents cad1071c 2297155a
Loading
Loading
Loading
Loading
+20 −2
Original line number 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
        // display.
        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
            // to fullscreen and its task is pinned windowing mode when the activity is entering
            // pip.
@@ -411,8 +411,18 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
                && 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,
            TaskDisplayArea suggestedDisplayArea, @Nullable ActivityRecord source) {
            TaskDisplayArea suggestedDisplayArea, @Nullable ActivityRecord source,
            @Nullable Task targetTask) {
        if (source == null) {
            return false;
        }
@@ -424,12 +434,20 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
            return false;
        }

        // Only fullscreen and freeform sources are allowed to inherit their windowing mode.
        final int sourceWindowingMode = source.getTask().getWindowingMode();
        if (sourceWindowingMode != WINDOWING_MODE_FULLSCREEN
                && sourceWindowingMode != WINDOWING_MODE_FREEFORM) {
            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.
        // 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.
+21 −0
Original line number Diff line number Diff line
@@ -681,6 +681,27 @@ public class TaskLaunchParamsModifierTests extends
                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
    public void testInheritsSourceTaskWindowingModeWhenActivityIsInDifferentWindowingMode() {
        final TestDisplayContent fullscreenDisplay = createNewDisplayContent(