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

Commit 4d6564c9 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Simplify the processing of stopping activities

Now if all resumed activities are visible, the stopping
activities can continue to be stopped that also sets to
invisible, so it no longer needs to update visibility
from another method.

Bug: 130340090
Test: atest ActivityVisibilityTests
Change-Id: I25a8518fa2eeaa4dd71f2062ff786ca4c13533a3
parent 01a62ffa
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -6108,11 +6108,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                // This also avoids if the next activity never reports idle (e.g. animating view),
                // the previous will need to wait until idle timeout to be stopped or destroyed.
                mStackSupervisor.scheduleProcessStoppingAndFinishingActivities();
            } else {
                // Instead of doing the full stop routine here, let's just hide any activities
                // we now can, and let them stop when the normal idle happens.
                mStackSupervisor.processStoppingActivities(null /* launchedActivity */,
                        true /* onlyUpdateVisibility */, true /* unused */, null /* unused */);
            }
        }
        Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
+20 −47
Original line number Diff line number Diff line
@@ -2076,54 +2076,11 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
            boolean processPausingActivities, String reason) {
        // Stop any activities that are scheduled to do so but have been waiting for the transition
        // animation to finish.
        processStoppingActivities(launchedActivity, false /* onlyUpdateVisibility */,
                processPausingActivities, reason);

        final int numFinishingActivities = mFinishingActivities.size();
        if (numFinishingActivities == 0) {
            return;
        }

        // Finish any activities that are scheduled to do so but have been waiting for the next one
        // to start.
        final ArrayList<ActivityRecord> finishingActivities = new ArrayList<>(mFinishingActivities);
        mFinishingActivities.clear();
        for (int i = 0; i < numFinishingActivities; i++) {
            final ActivityRecord r = finishingActivities.get(i);
            if (r.isInHistory()) {
                r.destroyImmediately(true /* removeFromApp */, "finish-" + reason);
            }
        }
    }

    /** Stop or destroy the stopping activities if they are not interactive. */
    void processStoppingActivities(ActivityRecord launchedActivity, boolean onlyUpdateVisibility,
            boolean processPausingActivities, String reason) {
        final int numStoppingActivities = mStoppingActivities.size();
        if (numStoppingActivities == 0) {
            return;
        }
        ArrayList<ActivityRecord> readyToStopActivities = null;

        final boolean nowVisible = mRootWindowContainer.allResumedActivitiesVisible();
        for (int activityNdx = numStoppingActivities - 1; activityNdx >= 0; --activityNdx) {
            final ActivityRecord s = mStoppingActivities.get(activityNdx);
            if (nowVisible && s.finishing) {

                // If this activity is finishing, it is sitting on top of
                // everyone else but we now know it is no longer needed...
                // so get rid of it.  Otherwise, we need to go through the
                // normal flow and hide it once we determine that it is
                // hidden by the activities in front of it.
                if (DEBUG_STATES) Slog.v(TAG, "Before stopping, can hide: " + s);
                s.setVisibility(false);
            }
            if (onlyUpdateVisibility) {
                continue;
            }

        for (int i = mStoppingActivities.size() - 1; i >= 0; --i) {
            final ActivityRecord s = mStoppingActivities.get(i);
            final boolean animating = s.isAnimating(TRANSITION);
            if (DEBUG_STATES) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + nowVisible
            if (DEBUG_STATES) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + s.nowVisible
                    + " animating=" + animating + " finishing=" + s.finishing);

            final ActivityStack stack = s.getActivityStack();
@@ -2145,7 +2102,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
                }
                readyToStopActivities.add(s);

                mStoppingActivities.remove(activityNdx);
                mStoppingActivities.remove(i);
            }
        }

@@ -2161,6 +2118,22 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
                }
            }
        }

        final int numFinishingActivities = mFinishingActivities.size();
        if (numFinishingActivities == 0) {
            return;
        }

        // Finish any activities that are scheduled to do so but have been waiting for the next one
        // to start.
        final ArrayList<ActivityRecord> finishingActivities = new ArrayList<>(mFinishingActivities);
        mFinishingActivities.clear();
        for (int i = 0; i < numFinishingActivities; i++) {
            final ActivityRecord r = finishingActivities.get(i);
            if (r.isInHistory()) {
                r.destroyImmediately(true /* removeFromApp */, "finish-" + reason);
            }
        }
    }

    void removeHistoryRecords(WindowProcessController app) {