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

Commit e4cf36fb authored by Chong Zhang's avatar Chong Zhang
Browse files

Check if task was top of stack before it's removed

To decide if home stack should be brought foreward. If the app is
finishing, it's no longer considered "running" and cleanUpActivityLocked
could move focus to the activity below. Then removeActivityFromHistoryLocked
would fail to bring front home stack as the removed task is no longer top.

bug: 29030518
Change-Id: I887e7c226258651d887cb0a4a6c6caab0a04e6e6
parent c0b602c4
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -3764,7 +3764,8 @@ final class ActivityStack {
        r.finishLaunchTickingLocked();
    }

    private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) {
    private void removeActivityFromHistoryLocked(
            ActivityRecord r, TaskRecord oldTop, String reason) {
        mStackSupervisor.removeChildActivityContainers(r);
        finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null);
        r.makeFinishingLocked();
@@ -3783,10 +3784,11 @@ final class ActivityStack {
            validateAppTokensLocked();
        }
        final TaskRecord task = r.task;
        final TaskRecord topTask = oldTop != null ? oldTop : topTask();
        if (task != null && task.removeActivity(r)) {
            if (DEBUG_STACK) Slog.i(TAG_STACK,
                    "removeActivityFromHistoryLocked: last activity removed from " + this);
            if (mStackSupervisor.isFocusedStack(this) && task == topTask() &&
            if (mStackSupervisor.isFocusedStack(this) && task == topTask &&
                    task.isOverHomeStack()) {
                mStackSupervisor.moveHomeStackTaskToTop(task.getTaskToReturnTo(), reason);
            }
@@ -3922,6 +3924,12 @@ final class ActivityStack {

        boolean removedFromHistory = false;

        // If the activity is finishing, it's no longer considered in topRunningActivityLocked,
        // and cleanUpActivityLocked() may change focus to another activity (or task).
        // Get the current top task now, as removeActivityFromHistoryLocked() below need this
        // to decide whether to return to home stack after removal.
        final TaskRecord topTask = topTask();

        cleanUpActivityLocked(r, false, false);

        final boolean hadApp = r.app != null;
@@ -3956,7 +3964,8 @@ final class ActivityStack {
                // up.
                //Slog.w(TAG, "Exception thrown during finish", e);
                if (r.finishing) {
                    removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy");
                    removeActivityFromHistoryLocked(
                            r, topTask, reason + " exceptionInScheduleDestroy");
                    removedFromHistory = true;
                    skipDestroy = true;
                }
@@ -3987,7 +3996,7 @@ final class ActivityStack {
        } else {
            // remove this record from the history.
            if (r.finishing) {
                removeActivityFromHistoryLocked(r, reason + " hadNoApp");
                removeActivityFromHistoryLocked(r, topTask, reason + " hadNoApp");
                removedFromHistory = true;
            } else {
                if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYED: " + r + " (no app)");
@@ -4018,7 +4027,7 @@ final class ActivityStack {
            if (isInStackLocked(r) != null) {
                if (r.state == ActivityState.DESTROYING) {
                    cleanUpActivityLocked(r, true, false);
                    removeActivityFromHistoryLocked(r, reason);
                    removeActivityFromHistoryLocked(r, null, reason);
                }
            }
            mStackSupervisor.resumeFocusedStackTopActivityLocked();
@@ -4176,7 +4185,7 @@ final class ActivityStack {
                    }
                    cleanUpActivityLocked(r, true, true);
                    if (remove) {
                        removeActivityFromHistoryLocked(r, "appDied");
                        removeActivityFromHistoryLocked(r, null, "appDied");
                    }
                }
            }