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

Commit 704cc228 authored by Jeff Chang's avatar Jeff Chang
Browse files

Fix the IntentTests test case failed

NPE occurs when process the pending reparent activities on
ResetTargetTaskHelper. Activities that enable the
allowTaskReparenting were not reparented to other tasks
while an activity was started with RESET_TASK_IF_NEEDED
flag.

This CL refactor the reparent path to fix the NPE.

Bug: 150303302
Test: atest CtsWindowManagerDeviceTestCases:IntentTests
Change-Id: I55f4eed0e6be8a2f59757fe9308b726196a1f011
parent 8a69fa18
Loading
Loading
Loading
Loading
+25 −32
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.server.wm.ActivityStack.TAG_ADD_REMOVE;
import static com.android.server.wm.ActivityStack.TAG_TASKS;
import static com.android.server.wm.ActivityStack.TAG_TASKS;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ADD_REMOVE;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ADD_REMOVE;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS;
import static com.android.server.wm.Task.REPARENT_LEAVE_STACK_IN_PLACE;


import android.app.ActivityOptions;
import android.app.ActivityOptions;
import android.content.Intent;
import android.content.Intent;
@@ -233,48 +232,42 @@ class ResetTargetTaskHelper {
        }
        }


        final ActivityTaskManagerService atmService = mTargetStack.mAtmService;
        final ActivityTaskManagerService atmService = mTargetStack.mAtmService;
        final ArrayList<Task> createdTasks = new ArrayList<>();
        DisplayContent display = mTargetStack.getDisplay();
        final boolean singleTaskInstanceDisplay = display.isSingleTaskInstance();
        if (singleTaskInstanceDisplay) {
            display = atmService.mRootWindowContainer.getDefaultDisplay();
        }

        final int windowingMode = mTargetStack.getWindowingMode();
        final int activityType = mTargetStack.getActivityType();

        while (!mPendingReparentActivities.isEmpty()) {
        while (!mPendingReparentActivities.isEmpty()) {
            final ActivityRecord r = mPendingReparentActivities.remove(0);
            final ActivityRecord r = mPendingReparentActivities.remove(0);
            final ActivityRecord bottom = mTargetStack.getBottomMostActivity();
            final boolean alwaysCreateTask = DisplayContent.alwaysCreateStack(windowingMode,
            final Task targetTask;
                    activityType);
            if (bottom != null && r.taskAffinity.equals(bottom.getTask().affinity)) {
            final Task task = alwaysCreateTask
                    ? display.getBottomMostTask() : mTargetStack.getBottomMostTask();
            Task targetTask = null;
            if (task != null && r.taskAffinity.equals(task.affinity)) {
                // If the activity currently at the bottom has the same task affinity as
                // If the activity currently at the bottom has the same task affinity as
                // the one we are moving, then merge it into the same task.
                // the one we are moving, then merge it into the same task.
                targetTask = bottom.getTask();
                targetTask = task;
                if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity "
                if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity "
                        + r + " out to bottom task " + targetTask);
                        + r + " out to bottom task " + targetTask);
            }
            if (targetTask == null) {
                if (alwaysCreateTask) {
                    targetTask = display.getOrCreateStack(windowingMode, activityType,
                            false /* onTop */);
                } else {
                } else {
                targetTask = mTargetStack.reuseOrCreateTask(
                    targetTask = mTargetStack.reuseOrCreateTask(r.info, null /*intent*/,
                        r.info, null /*intent*/, false /*toTop*/);
                            false /*toTop*/);
                }
                targetTask.affinityIntent = r.intent;
                targetTask.affinityIntent = r.intent;
                createdTasks.add(targetTask);
                if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity "
                        + r + " out to new task " + targetTask);
            }
            }
            r.reparent(targetTask, 0 /* position */, "resetTargetTaskIfNeeded");
            r.reparent(targetTask, 0 /* position */, "resetTargetTaskIfNeeded");
            atmService.mStackSupervisor.mRecentTasks.add(targetTask);
            atmService.mStackSupervisor.mRecentTasks.add(targetTask);
        }
        }

        DisplayContent display = mTargetStack.getDisplay();
        final boolean singleTaskInstanceDisplay = display.isSingleTaskInstance();
        if (singleTaskInstanceDisplay) {
            display = atmService.mRootWindowContainer.getDefaultDisplay();
        }

        final int windowingMode = mTargetStack.getWindowingMode();
        final int activityType = mTargetStack.getActivityType();
        if (!singleTaskInstanceDisplay && !display.alwaysCreateStack(windowingMode, activityType)) {
            return;
        }

        while (!createdTasks.isEmpty()) {
            final Task targetTask = createdTasks.remove(createdTasks.size() - 1);
            final ActivityStack targetStack = display.getOrCreateStack(
                    windowingMode, activityType, false /* onTop */);
            targetTask.reparent(targetStack, false /* toTop */, REPARENT_LEAVE_STACK_IN_PLACE,
                    false /* animate */, true /* deferResume */, "resetTargetTask");
        }
    }
    }


    private boolean takeOption(ActivityRecord p, boolean noOptions) {
    private boolean takeOption(ActivityRecord p, boolean noOptions) {