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

Commit 37634aef authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixed some issues with resuming already resumed activity" into nyc-dev

parents 4d826831 06579d63
Loading
Loading
Loading
Loading
+27 −12
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import static com.android.server.am.ActivityRecord.STARTING_WINDOW_REMOVED;
import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN;
import static com.android.server.am.ActivityStackSupervisor.FindTaskResult;
import static com.android.server.am.ActivityStackSupervisor.MOVING;
import static com.android.server.am.ActivityStackSupervisor.ON_TOP;
import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_CLOSE;
import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_OPEN;
@@ -220,6 +221,17 @@ final class ActivityStack {
    // activities and there is a specific combination of stacks.
    static final int STACK_VISIBLE_ACTIVITY_BEHIND = 2;

    /* The various modes for the method {@link #removeTask}. */
    // Task is being completely removed from all stacks in the system.
    static final int REMOVE_TASK_MODE_DESTROYING = 0;
    // Task is being removed from this stack so we can add it to another stack. In the case we are
    // moving we don't want to perform some operations on the task like removing it from window
    // manager or recents.
    static final int REMOVE_TASK_MODE_MOVING = 1;
    // Similar to {@link #REMOVE_TASK_MODE_MOVING} and the task will be added to the top of its new
    // stack and the new stack will be on top of all stacks.
    static final int REMOVE_TASK_MODE_MOVING_TO_TOP = 2;

    final ActivityManagerService mService;
    final WindowManagerService mWindowManager;
    private final RecentTasks mRecentTasks;
@@ -4919,18 +4931,18 @@ final class ActivityStack {
    }

    void removeTask(TaskRecord task, String reason) {
        removeTask(task, reason, !MOVING);
        removeTask(task, reason, REMOVE_TASK_MODE_DESTROYING);
    }

    /**
     * Removes the input task from this stack.
     * @param task to remove.
     * @param reason for removal.
     * @param moving task to another stack. In the case we are moving we don't want to perform
     *               some operations on the task like removing it from window manager or recents.
     * @param mode task removal mode. Either {@link #REMOVE_TASK_MODE_DESTROYING},
     *             {@link #REMOVE_TASK_MODE_MOVING}, {@link #REMOVE_TASK_MODE_MOVING_TO_TOP}.
     */
    void removeTask(TaskRecord task, String reason, boolean moving) {
        if (!moving) {
    void removeTask(TaskRecord task, String reason, int mode) {
        if (mode == REMOVE_TASK_MODE_DESTROYING) {
            mStackSupervisor.removeLockedTaskLocked(task);
            mWindowManager.removeTask(task.taskId);
            if (!StackId.persistTaskBounds(mStackId)) {
@@ -4956,7 +4968,7 @@ final class ActivityStack {
        mTaskHistory.remove(task);
        updateTaskMovement(task, true);

        if (!moving && task.mActivities.isEmpty()) {
        if (mode == REMOVE_TASK_MODE_DESTROYING && task.mActivities.isEmpty()) {
            // TODO: VI what about activity?
            final boolean isVoiceSession = task.voiceSession != null;
            if (isVoiceSession) {
@@ -4975,8 +4987,10 @@ final class ActivityStack {

        if (mTaskHistory.isEmpty()) {
            if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this);
            // We only need to adjust focused stack if this stack is in focus.
            if (isOnHomeDisplay() && mStackSupervisor.isFocusedStack(this)) {
            // We only need to adjust focused stack if this stack is in focus and we are not in the
            // process of moving the task to the top of the stack that will be focused.
            if (isOnHomeDisplay() && mode != REMOVE_TASK_MODE_MOVING_TO_TOP
                    && mStackSupervisor.isFocusedStack(this)) {
                String myReason = reason + " leftTaskHistoryEmpty";
                if (mFullscreen
                        || !adjustFocusToNextFocusableStackLocked(
@@ -5024,7 +5038,7 @@ final class ActivityStack {
    }

    void addTask(final TaskRecord task, final boolean toTop, String reason) {
        final ActivityStack prevStack = preAddTask(task, reason);
        final ActivityStack prevStack = preAddTask(task, reason, toTop);

        task.stack = this;
        if (toTop) {
@@ -5039,7 +5053,7 @@ final class ActivityStack {
    void positionTask(final TaskRecord task, int position) {
        final ActivityRecord topRunningActivity = task.topRunningActivityLocked();
        final boolean wasResumed = topRunningActivity == task.stack.mResumedActivity;
        final ActivityStack prevStack = preAddTask(task, "positionTask");
        final ActivityStack prevStack = preAddTask(task, "positionTask", ON_TOP);
        task.stack = this;
        insertTaskAtPosition(task, position);
        postAddTask(task, prevStack);
@@ -5053,10 +5067,11 @@ final class ActivityStack {
        }
    }

    private ActivityStack preAddTask(TaskRecord task, String reason) {
    private ActivityStack preAddTask(TaskRecord task, String reason, boolean toTop) {
        final ActivityStack prevStack = task.stack;
        if (prevStack != null && prevStack != this) {
            prevStack.removeTask(task, reason, MOVING);
            prevStack.removeTask(task, reason,
                    toTop ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING);
        }
        return prevStack;
    }
+11 −4
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@ import static com.android.server.am.ActivityStack.ActivityState.PAUSING;
import static com.android.server.am.ActivityStack.ActivityState.RESUMED;
import static com.android.server.am.ActivityStack.ActivityState.STOPPED;
import static com.android.server.am.ActivityStack.ActivityState.STOPPING;
import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING;
import static com.android.server.am.ActivityStack.STACK_INVISIBLE;
import static com.android.server.am.ActivityStack.STACK_VISIBLE;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK;
@@ -1785,7 +1786,10 @@ public final class ActivityStackSupervisor implements DisplayListener {
        if (targetStack != null && isFocusedStack(targetStack)) {
            return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions);
        }
        final ActivityRecord r = mFocusedStack.topRunningActivityLocked();
        if (r == null || r.state != RESUMED) {
            mFocusedStack.resumeTopActivityUncheckedLocked(null, null);
        }
        return false;
    }

@@ -2134,8 +2138,11 @@ public final class ActivityStackSupervisor implements DisplayListener {
                for (int i = 0; i < size; i++) {
                    moveTaskToStackLocked(tasks.get(i).taskId,
                            FULLSCREEN_WORKSPACE_STACK_ID, onTop, onTop /*forceFocus*/,
                            "moveTasksToFullscreenStack", ANIMATE);
                            "moveTasksToFullscreenStack", ANIMATE, DEFER_RESUME);
                }

                ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS);
                resumeFocusedStackTopActivityLocked();
            } else {
                for (int i = size - 1; i >= 0; i--) {
                    positionTaskInStackLocked(tasks.get(i).taskId,
@@ -2338,7 +2345,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
            }
            // Remove current stack association, so we can re-associate the task with the
            // right stack below.
            task.stack.removeTask(task, "restoreRecentTaskLocked", MOVING);
            task.stack.removeTask(task, "restoreRecentTaskLocked", REMOVE_TASK_MODE_MOVING);
        }

        final ActivityStack stack =
@@ -2381,7 +2388,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
                    + "support multi-window task=" + task + " to stackId=" + stackId);
        }

        final ActivityRecord r = task.getTopActivity();
        final ActivityRecord r = task.topRunningActivityLocked();
        final ActivityStack prevStack = task.stack;
        final boolean wasFocused = isFocusedStack(prevStack) && (topRunningActivityLocked() == r);
        final boolean wasResumed = prevStack.mResumedActivity == r;