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

Commit 32f0e481 authored by Louis Chang's avatar Louis Chang Committed by Android (Google) Code Review
Browse files

Merge "Rename RWC#getLaunchRootTask" into tm-dev

parents d24d8427 fd49c022
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -1816,7 +1816,8 @@ class ActivityStarter {
        }

        if (mTargetRootTask == null) {
            mTargetRootTask = getLaunchRootTask(mStartActivity, mLaunchFlags, targetTask, mOptions);
            mTargetRootTask = getOrCreateRootTask(mStartActivity, mLaunchFlags, targetTask,
                    mOptions);
        }
        if (newTask) {
            final Task taskToAffiliate = (mLaunchTaskBehind && mSourceRecord != null)
@@ -1925,7 +1926,7 @@ class ActivityStarter {
        } else if (mInTask != null) {
            return mInTask;
        } else {
            final Task rootTask = getLaunchRootTask(mStartActivity, mLaunchFlags, null /* task */,
            final Task rootTask = getOrCreateRootTask(mStartActivity, mLaunchFlags, null /* task */,
                    mOptions);
            final ActivityRecord top = rootTask.getTopNonFinishingActivity();
            if (top != null) {
@@ -2233,7 +2234,7 @@ class ActivityStarter {
                if (targetTask.getRootTask() == null) {
                    // Target root task got cleared when we all activities were removed above.
                    // Go ahead and reset it.
                    mTargetRootTask = getLaunchRootTask(mStartActivity, mLaunchFlags,
                    mTargetRootTask = getOrCreateRootTask(mStartActivity, mLaunchFlags,
                        null /* task */, mOptions);
                    mTargetRootTask.addChild(targetTask, !mLaunchTaskBehind /* toTop */,
                            (mStartActivity.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0);
@@ -2695,10 +2696,11 @@ class ActivityStarter {
                // launched into the same root task.
                mTargetRootTask = Task.fromWindowContainerToken(mSourceRecord.mLaunchRootTask);
            } else {
                final Task launchRootTask =
                        getLaunchRootTask(mStartActivity, mLaunchFlags, intentTask, mOptions);
                final Task rootTask =
                        getOrCreateRootTask(mStartActivity, mLaunchFlags, intentTask, mOptions);
                // TODO(b/184806710): #getOrCreateRootTask should never return null?
                mTargetRootTask =
                        launchRootTask != null ? launchRootTask : intentActivity.getRootTask();
                        rootTask != null ? rootTask : intentActivity.getRootTask();
            }
        }

@@ -2929,7 +2931,7 @@ class ActivityStarter {
        return launchFlags;
    }

    private Task getLaunchRootTask(ActivityRecord r, int launchFlags, Task task,
    private Task getOrCreateRootTask(ActivityRecord r, int launchFlags, Task task,
            ActivityOptions aOptions) {
        // We are reusing a task, keep the root task!
        if (mReuseTask != null) {
@@ -2938,7 +2940,7 @@ class ActivityStarter {

        final boolean onTop =
                (aOptions == null || !aOptions.getAvoidMoveToFront()) && !mLaunchTaskBehind;
        return mRootWindowContainer.getLaunchRootTask(r, aOptions, task, mSourceRootTask, onTop,
        return mRootWindowContainer.getOrCreateRootTask(r, aOptions, task, mSourceRootTask, onTop,
                mLaunchParams, launchFlags);
    }

+9 −9
Original line number Diff line number Diff line
@@ -1439,20 +1439,20 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                final Rect bounds = options.getLaunchBounds();
                task.setBounds(bounds);

                Task launchRootTask =
                        mRootWindowContainer.getLaunchRootTask(null, options, task, ON_TOP);
                Task targetRootTask =
                        mRootWindowContainer.getOrCreateRootTask(null, options, task, ON_TOP);

                if (launchRootTask != currentRootTask) {
                    moveHomeRootTaskToFrontIfNeeded(flags, launchRootTask.getDisplayArea(), reason);
                    task.reparent(launchRootTask, ON_TOP, REPARENT_KEEP_ROOT_TASK_AT_FRONT,
                if (targetRootTask != currentRootTask) {
                    moveHomeRootTaskToFrontIfNeeded(flags, targetRootTask.getDisplayArea(), reason);
                    task.reparent(targetRootTask, ON_TOP, REPARENT_KEEP_ROOT_TASK_AT_FRONT,
                            !ANIMATE, DEFER_RESUME, reason);
                    currentRootTask = launchRootTask;
                    currentRootTask = targetRootTask;
                    reparented = true;
                    // task.reparent() should already placed the task on top,
                    // still need moveTaskToFrontLocked() below for any transition settings.
                }
                if (launchRootTask.shouldResizeRootTaskWithLaunchBounds()) {
                    launchRootTask.resize(bounds, !PRESERVE_WINDOWS, !DEFER_RESUME);
                if (targetRootTask.shouldResizeRootTaskWithLaunchBounds()) {
                    targetRootTask.resize(bounds, !PRESERVE_WINDOWS, !DEFER_RESUME);
                } else {
                    // WM resizeTask must be done after the task is moved to the correct stack,
                    // because Task's setBounds() also updates dim layer's bounds, but that has
@@ -1696,7 +1696,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
     */
    boolean restoreRecentTaskLocked(Task task, ActivityOptions aOptions, boolean onTop) {
        final Task rootTask =
                mRootWindowContainer.getLaunchRootTask(null, aOptions, task, onTop);
                mRootWindowContainer.getOrCreateRootTask(null, aOptions, task, onTop);
        final WindowContainer parent = task.getParent();

        if (parent == rootTask || task == rootTask) {
+8 −8
Original line number Diff line number Diff line
@@ -2728,9 +2728,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        return false;
    }

    Task getLaunchRootTask(@Nullable ActivityRecord r, @Nullable ActivityOptions options,
    Task getOrCreateRootTask(@Nullable ActivityRecord r, @Nullable ActivityOptions options,
            @Nullable Task candidateTask, boolean onTop) {
        return getLaunchRootTask(r, options, candidateTask, null /* sourceTask */, onTop,
        return getOrCreateRootTask(r, options, candidateTask, null /* sourceTask */, onTop,
                null /* launchParams */, 0 /* launchFlags */);
    }

@@ -2745,9 +2745,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
     * @param launchFlags    The launch flags for this launch.
     * @param realCallingPid The pid from {@link ActivityStarter#setRealCallingPid}
     * @param realCallingUid The uid from {@link ActivityStarter#setRealCallingUid}
     * @return The root task to use for the launch or INVALID_TASK_ID.
     * @return The root task to use for the launch.
     */
    Task getLaunchRootTask(@Nullable ActivityRecord r,
    Task getOrCreateRootTask(@Nullable ActivityRecord r,
            @Nullable ActivityOptions options, @Nullable Task candidateTask,
            @Nullable Task sourceTask, boolean onTop,
            @Nullable LaunchParamsController.LaunchParams launchParams, int launchFlags) {
@@ -3236,12 +3236,12 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            if (aOptions != null) {
                // Resolve the root task the task should be placed in now based on options
                // and reparent if needed.
                final Task launchRootTask =
                        getLaunchRootTask(null, aOptions, task, onTop);
                if (launchRootTask != null && task.getRootTask() != launchRootTask) {
                final Task targetRootTask =
                        getOrCreateRootTask(null, aOptions, task, onTop);
                if (targetRootTask != null && task.getRootTask() != targetRootTask) {
                    final int reparentMode = onTop
                            ? REPARENT_MOVE_ROOT_TASK_TO_FRONT : REPARENT_LEAVE_ROOT_TASK_IN_PLACE;
                    task.reparent(launchRootTask, onTop, reparentMode, ANIMATE, DEFER_RESUME,
                    task.reparent(targetRootTask, onTop, reparentMode, ANIMATE, DEFER_RESUME,
                            "anyTaskForId");
                }
            }
+15 −15
Original line number Diff line number Diff line
@@ -308,12 +308,12 @@ public class ActivityStarterTests extends WindowTestsBase {
    }

    private ActivityStarter prepareStarter(@Intent.Flags int launchFlags) {
        return prepareStarter(launchFlags, true /* mockGetLaunchStack */, LAUNCH_MULTIPLE);
        return prepareStarter(launchFlags, true /* mockGetRootTask */, LAUNCH_MULTIPLE);
    }

    private ActivityStarter prepareStarter(@Intent.Flags int launchFlags,
            boolean mockGetLaunchStack) {
        return prepareStarter(launchFlags, mockGetLaunchStack, LAUNCH_MULTIPLE);
            boolean mockGetRootTask) {
        return prepareStarter(launchFlags, mockGetRootTask, LAUNCH_MULTIPLE);
    }

    private void setupImeWindow() {
@@ -326,20 +326,20 @@ public class ActivityStarterTests extends WindowTestsBase {
     * Creates a {@link ActivityStarter} with default parameters and necessary mocks.
     *
     * @param launchFlags The intent flags to launch activity.
     * @param mockGetLaunchStack Whether to mock {@link RootWindowContainer#getLaunchRootTask} for
     * @param mockGetRootTask Whether to mock {@link RootWindowContainer#getOrCreateRootTask} for
     *                           always launching to the testing stack. Set to false when allowing
     *                           the activity can be launched to any stack that is decided by real
     *                           implementation.
     * @return A {@link ActivityStarter} with default setup.
     */
    private ActivityStarter prepareStarter(@Intent.Flags int launchFlags,
            boolean mockGetLaunchStack, int launchMode) {
            boolean mockGetRootTask, int launchMode) {
        // always allow test to start activity.
        doReturn(true).when(mSupervisor).checkStartAnyActivityPermission(
                any(), any(), any(), anyInt(), anyInt(), anyInt(), any(), any(),
                anyBoolean(), anyBoolean(), any(), any(), any());

        if (mockGetLaunchStack) {
        if (mockGetRootTask) {
            // Instrument the stack and task used.
            final Task stack = mRootWindowContainer.getDefaultTaskDisplayArea()
                    .createRootTask(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD,
@@ -347,9 +347,9 @@ public class ActivityStarterTests extends WindowTestsBase {

            // Direct starter to use spy stack.
            doReturn(stack).when(mRootWindowContainer)
                    .getLaunchRootTask(any(), any(), any(), anyBoolean());
            doReturn(stack).when(mRootWindowContainer).getLaunchRootTask(any(), any(), any(), any(),
                    anyBoolean(), any(), anyInt());
                    .getOrCreateRootTask(any(), any(), any(), anyBoolean());
            doReturn(stack).when(mRootWindowContainer).getOrCreateRootTask(any(), any(), any(),
                    any(), anyBoolean(), any(), anyInt());
        }

        // Set up mock package manager internal and make sure no unmocked methods are called
@@ -434,7 +434,7 @@ public class ActivityStarterTests extends WindowTestsBase {
    public void testSplitScreenDeliverToTop() {
        final ActivityStarter starter = prepareStarter(
                FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | FLAG_ACTIVITY_SINGLE_TOP,
                false /* mockGetLaunchStack */);
                false /* mockGetRootTask */);
        final Pair<ActivityRecord, ActivityRecord> activities = createActivitiesInSplit();
        final ActivityRecord splitPrimaryFocusActivity = activities.first;
        final ActivityRecord splitSecondReusableActivity = activities.second;
@@ -790,7 +790,7 @@ public class ActivityStarterTests extends WindowTestsBase {
        finishingTopActivity.finishing = true;

        // Launch the bottom task of the target root task.
        prepareStarter(FLAG_ACTIVITY_NEW_TASK, false /* mockGetLaunchStack */)
        prepareStarter(FLAG_ACTIVITY_NEW_TASK, false /* mockGetRootTask */)
                .setReason("testBringTaskToFrontWhenFocusedTaskIsFinishing")
                .setIntent(activity.intent.addFlags(
                        FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))
@@ -809,7 +809,7 @@ public class ActivityStarterTests extends WindowTestsBase {
    @Test
    public void testDeliverIntentToTopActivityOfNonTopDisplay() {
        final ActivityStarter starter = prepareStarter(FLAG_ACTIVITY_NEW_TASK,
                false /* mockGetLaunchStack */);
                false /* mockGetRootTask */);

        // Create a secondary display at bottom.
        final TestDisplayContent secondaryDisplay =
@@ -849,7 +849,7 @@ public class ActivityStarterTests extends WindowTestsBase {
    @Test
    public void testBringTaskToFrontOnSecondaryDisplay() {
        final ActivityStarter starter = prepareStarter(FLAG_ACTIVITY_NEW_TASK,
                false /* mockGetLaunchStack */);
                false /* mockGetRootTask */);

        // Create a secondary display with an activity.
        final TestDisplayContent secondaryDisplay =
@@ -943,7 +943,7 @@ public class ActivityStarterTests extends WindowTestsBase {
    @Test
    public void testReparentTopFocusedActivityToSecondaryDisplay() {
        final ActivityStarter starter = prepareStarter(FLAG_ACTIVITY_NEW_TASK,
                false /* mockGetLaunchStack */);
                false /* mockGetRootTask */);

        // Create a secondary display at bottom.
        final TestDisplayContent secondaryDisplay = addNewDisplayContentAt(POSITION_BOTTOM);
@@ -1076,7 +1076,7 @@ public class ActivityStarterTests extends WindowTestsBase {
    @Test
    public void testTargetStackInSplitScreen() {
        final ActivityStarter starter =
                prepareStarter(FLAG_ACTIVITY_LAUNCH_ADJACENT, false /* mockGetLaunchStack */);
                prepareStarter(FLAG_ACTIVITY_LAUNCH_ADJACENT, false /* mockGetRootTask */);
        final ActivityRecord top = new ActivityBuilder(mAtm).setCreateTask(true).build();
        final ActivityOptions options = ActivityOptions.makeBasic();
        final ActivityRecord[] outActivity = new ActivityRecord[1];
+2 −2
Original line number Diff line number Diff line
@@ -949,7 +949,7 @@ public class RootWindowContainerTests extends WindowTestsBase {
        LaunchParamsController.LaunchParams launchParams =
                new LaunchParamsController.LaunchParams();
        launchParams.mPreferredTaskDisplayArea = taskDisplayArea;
        Task root = mRootWindowContainer.getLaunchRootTask(null /* r */, null /* options */,
        Task root = mRootWindowContainer.getOrCreateRootTask(null /* r */, null /* options */,
                null /* candidateTask */, null /* sourceTask */, true /* onTop */, launchParams,
                0 /* launchParams */);
        assertEquals(taskDisplayArea, root.getTaskDisplayArea());
@@ -957,7 +957,7 @@ public class RootWindowContainerTests extends WindowTestsBase {
        // Making sure still getting the root task from the preferred TDA when passing in a
        // launching activity.
        ActivityRecord r = new ActivityBuilder(mAtm).build();
        root = mRootWindowContainer.getLaunchRootTask(r, null /* options */,
        root = mRootWindowContainer.getOrCreateRootTask(r, null /* options */,
                null /* candidateTask */, null /* sourceTask */, true /* onTop */, launchParams,
                0 /* launchParams */);
        assertEquals(taskDisplayArea, root.getTaskDisplayArea());