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

Commit 11ad186c authored by Diego Vela's avatar Diego Vela
Browse files

Remove setting of reuse task on an ActivityRecord.

Remove setting of reuse task on activity record.

Setting the reuse task can lead to confusing states.
It would be possible to have activityRecord.getDisplayArea()
to differ from activityRecord.getTask().getDisplayArea().
Removing this possibility makes it easier to reason about the
code.

Bug: 153920825
Test: atest WmTests:ActivityStarterTests
      atest WmTests:RootActivityContainerTests
Change-Id: Ida68d1c0e995ef816191d4e17335bd07ec392cc7
parent 9e487698
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -1213,14 +1213,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return task;
    }

    /**
     * Sets the Task on this activity for the purposes of re-use during launch where we will
     * re-use another activity instead of this one for the launch.
     */
    void setTaskForReuse(Task task) {
        this.task = task;
    }

    Task getStack() {
        return task != null ? task.getRootTask() : null;
    }
+4 −17
Original line number Diff line number Diff line
@@ -1766,8 +1766,8 @@ class ActivityStarter {
        } else if (mInTask != null) {
            return mInTask;
        } else {
            final Task stack = getLaunchStack(mStartActivity, mLaunchFlags,
                    null /* task */, mOptions);
            final Task stack = getLaunchStack(mStartActivity, mLaunchFlags, null /* task */,
                    mOptions);
            final ActivityRecord top = stack.getTopNonFinishingActivity();
            if (top != null) {
                return top.getTask();
@@ -1870,13 +1870,7 @@ class ActivityStarter {
            return START_SUCCESS;
        }

        boolean clearTaskForReuse = false;
        if (reusedTask != null) {
            if (mStartActivity.getTask() == null) {
                mStartActivity.setTaskForReuse(reusedTask);
                clearTaskForReuse = true;
            }

            if (targetTask.intent == null) {
                // This task was started because of movement of the activity based on
                // affinity...
@@ -1923,13 +1917,6 @@ class ActivityStarter {
        complyActivityFlags(targetTask,
                reusedTask != null ? reusedTask.getTopNonFinishingActivity() : null, intentGrants);

        if (clearTaskForReuse) {
            // Clear task for re-use so later code to methods
            // {@link #setTaskFromReuseOrCreateNewTask}, {@link #setTaskFromSourceRecord}, or
            // {@link #setTaskFromInTask} can parent it to the task.
            mStartActivity.setTaskForReuse(null);
        }

        if (mAddingToTask) {
            return START_SUCCESS;
        }
@@ -2515,8 +2502,8 @@ class ActivityStarter {
                    intentActivity.setTaskToAffiliateWith(mSourceRecord.getTask());
                }

                final Task launchStack =
                        getLaunchStack(mStartActivity, mLaunchFlags, intentTask, mOptions);
                final Task launchStack = getLaunchStack(mStartActivity, mLaunchFlags, intentTask,
                        mOptions);
                if (launchStack == null || launchStack == mTargetStack) {
                    // Do not set mMovedToFront to true below for split-screen-top stack, or
                    // START_TASK_TO_FRONT will be returned and trigger unexpected animations when a
+2 −5
Original line number Diff line number Diff line
@@ -2816,7 +2816,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
     * @param launchParams The resolved launch params to use.
     * @param realCallingPid The pid from {@link ActivityStarter#setRealCallingPid}
     * @param realCallingUid The uid from {@link ActivityStarter#setRealCallingUid}
     *
     * @return The stack to use for the launch or INVALID_STACK_ID.
     */
    Task getLaunchStack(@Nullable ActivityRecord r,
@@ -2965,10 +2964,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        // If {@code r} is already in target display area and its task is the same as the candidate
        // task, the intention should be getting a launch stack for the reusable activity, so we can
        // use the existing stack.
        if (candidateTask != null && (r.getTask() == null || r.getTask() == candidateTask)) {
            // TODO(b/153920825): Fix incorrect evaluation of attached state
            final TaskDisplayArea attachedTaskDisplayArea = r.getTask() != null
                    ? r.getTask().getDisplayArea() : r.getDisplayArea();
        if (candidateTask != null) {
            final TaskDisplayArea attachedTaskDisplayArea = candidateTask.getDisplayArea();
            if (attachedTaskDisplayArea == null || attachedTaskDisplayArea == taskDisplayArea) {
                return candidateTask.getRootTask();
            }
+2 −2
Original line number Diff line number Diff line
@@ -890,8 +890,8 @@ public class RootActivityContainerTests extends WindowTestsBase {

        // Make sure the root task is valid and can be reused on default display.
        final Task stack = mRootWindowContainer.getValidLaunchStackInTaskDisplayArea(
                mRootWindowContainer.getDefaultTaskDisplayArea(), activity, task, null,
                null);
                mRootWindowContainer.getDefaultTaskDisplayArea(), activity, task,
                null /* options */, null /* launchParams */);
        assertEquals(task, stack);
    }