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

Commit 50e42f8b authored by Louis Chang's avatar Louis Chang Committed by Automerger Merge Worker
Browse files

Merge "Adding the new activity on the same TF of the cleared activity" into tm-dev am: b4c09cd2

parents a5f967a2 b4c09cd2
Loading
Loading
Loading
Loading
+24 −11
Original line number Diff line number Diff line
@@ -192,6 +192,7 @@ class ActivityStarter {

    private Task mInTask;
    private TaskFragment mInTaskFragment;
    private TaskFragment mAddingToTaskFragment;
    @VisibleForTesting
    boolean mAddingToTask;

@@ -2254,20 +2255,27 @@ class ActivityStarter {
            // In this situation we want to remove all activities from the task up to the one
            // being started. In most cases this means we are resetting the task to its initial
            // state.
            final ActivityRecord top = targetTask.performClearTop(mStartActivity, mLaunchFlags);
            final ActivityRecord clearTop = targetTask.performClearTop(mStartActivity,
                    mLaunchFlags);

            if (top != null) {
                if (top.isRootOfTask()) {
            if (clearTop != null && !clearTop.finishing) {
                if (clearTop.isRootOfTask()) {
                    // Activity aliases may mean we use different intents for the top activity,
                    // so make sure the task now has the identity of the new intent.
                    top.getTask().setIntent(mStartActivity);
                    clearTop.getTask().setIntent(mStartActivity);
                }
                deliverNewIntent(top, intentGrants);
                deliverNewIntent(clearTop, intentGrants);
            } else {
                // A special case: we need to start the activity because it is not currently
                // running, and the caller has asked to clear the current task to have this
                // activity at the top.
                mAddingToTask = true;
                // Adding the new activity to the same embedded TF of the clear-top activity if
                // possible.
                if (clearTop != null && clearTop.getTaskFragment() != null
                        && clearTop.getTaskFragment().isEmbedded()) {
                    mAddingToTaskFragment = clearTop.getTaskFragment();
                }
                if (targetTask.getRootTask() == null) {
                    // Target root task got cleared when we all activities were removed above.
                    // Go ahead and reset it.
@@ -2892,14 +2900,19 @@ class ActivityStarter {
                newParent = mInTaskFragment;
            }
        } else {
            TaskFragment candidateTf = mAddingToTaskFragment != null ? mAddingToTaskFragment : null;
            if (candidateTf == null) {
                final ActivityRecord top = task.topRunningActivity(false /* focusableOnly */,
                        false /* includingEmbeddedTask */);
            final TaskFragment taskFragment = top != null ? top.getTaskFragment() : null;
            if (taskFragment != null && taskFragment.isEmbedded()
                    && canEmbedActivity(taskFragment, mStartActivity, false /* newTask */, task)) {
                if (top != null) {
                    candidateTf = top.getTaskFragment();
                }
            }
            if (candidateTf != null && candidateTf.isEmbedded()
                    && canEmbedActivity(candidateTf, mStartActivity, false /* newTask */, task)) {
                // Use the embedded TaskFragment of the top activity as the new parent if the
                // activity can be embedded.
                newParent = top.getTaskFragment();
                newParent = candidateTf;
            }
        }

+1 −2
Original line number Diff line number Diff line
@@ -1644,7 +1644,7 @@ class Task extends TaskFragment {
     * activities on top of it and return the instance.
     *
     * @param newR Description of the new activity being started.
     * @return Returns the old activity that should be continued to be used,
     * @return Returns the existing activity in the task that performs the clear-top operation,
     * or {@code null} if none was found.
     */
    private ActivityRecord clearTopActivities(ActivityRecord newR, int launchFlags) {
@@ -1663,7 +1663,6 @@ class Task extends TaskFragment {
                && !ActivityStarter.isDocumentLaunchesIntoExisting(launchFlags)) {
            if (!r.finishing) {
                r.finishIfPossible("clear-task-top", false /* oomAdj */);
                return null;
            }
        }

+1 −1
Original line number Diff line number Diff line
@@ -266,7 +266,7 @@ public class TaskTests extends WindowTestsBase {
        // Detach from process so the activities can be removed from hierarchy when finishing.
        activity1.detachFromProcess();
        activity2.detachFromProcess();
        assertNull(task.performClearTop(activity1, 0 /* launchFlags */));
        assertTrue(task.performClearTop(activity1, 0 /* launchFlags */).finishing);
        assertFalse(task.hasChild());
        // In real case, the task should be preserved for adding new activity.
        assertTrue(task.isAttached());