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

Commit 40750098 authored by Louis Chang's avatar Louis Chang
Browse files

Use the display of existing task as preferred

While reparenting a task to an external freeform display,
the task was moving back on default display because of
no preferred display information specified - option and
source are null for #getPreferredLaunchDisplay - while
laying out the task.

For example, opening Chrome on a secondary freefrom display
will only bring back Chrome on default display.

So, we use the display where the task was on as the preferred
display when nothing specified.

Bug: 118354537
Test: verified by following the reproduce steps in comment#1
      atest TaskLaunchParamsModifierTests

Change-Id: I6d7a9e2d53a69bd2675dbab812a9e1a7791b1342
parent 0215e993
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
        }

        // STEP 1: Determine the display to launch the activity/task.
        final int displayId = getPreferredLaunchDisplay(options, source, currentParams);
        final int displayId = getPreferredLaunchDisplay(task, options, source, currentParams);
        outParams.mPreferredDisplayId = displayId;
        ActivityDisplay display = mSupervisor.getActivityDisplay(displayId);
        if (DEBUG) {
@@ -268,8 +268,8 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
        return RESULT_CONTINUE;
    }

    private int getPreferredLaunchDisplay(@Nullable ActivityOptions options,
            ActivityRecord source, LaunchParams currentParams) {
    private int getPreferredLaunchDisplay(@Nullable TaskRecord task,
            @Nullable ActivityOptions options, ActivityRecord source, LaunchParams currentParams) {
        int displayId = INVALID_DISPLAY;
        final int optionLaunchId = options != null ? options.getLaunchDisplayId() : INVALID_DISPLAY;
        if (optionLaunchId != INVALID_DISPLAY) {
@@ -283,6 +283,13 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
            displayId = sourceDisplayId;
        }

        ActivityStack stack =
                (displayId == INVALID_DISPLAY && task != null) ? task.getStack() : null;
        if (stack != null) {
            if (DEBUG) appendLog("display-from-task=" + stack.mDisplayId);
            displayId = stack.mDisplayId;
        }

        if (displayId != INVALID_DISPLAY && mSupervisor.getActivityDisplay(displayId) == null) {
            displayId = INVALID_DISPLAY;
        }
+12 −0
Original line number Diff line number Diff line
@@ -167,6 +167,18 @@ public class TaskLaunchParamsModifierTests extends ActivityTestsBase {
        assertEquals(fullscreenDisplay.mDisplayId, mResult.mPreferredDisplayId);
    }

    @Test
    public void testUsesTaskDisplayIdIfSet() {
        final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
                WINDOWING_MODE_FREEFORM);
        ActivityRecord source = createSourceActivity(freeformDisplay);

        assertEquals(RESULT_CONTINUE, mTarget.onCalculate(source.getTask(), null /* layout */,
                null /* activity */, null /* source */, null /* options */, mCurrent, mResult));

        assertEquals(freeformDisplay.mDisplayId, mResult.mPreferredDisplayId);
    }

    // =====================================
    // Launch Windowing Mode Related Tests
    // =====================================