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

Commit 5477b578 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Fix warning of activity LRU list removal

In ActivityRecord#destroyImmediately, the #cleanUp has
removed the destroying activity from LRU list (since
2322bedc), so the later removal cannot find the existing
record and then always prints warning log.

Also update LRU list for the case of reparenting
(onActivityAddedToStack).

Bug: 80414790
Test: Launch and finish an activity. The log should not
      have warning "not in LRU list".
Change-Id: Ie7ce1ba7a4af95af6640b5833f6a7cd06ac8f8d4
parent 6f7e2d56
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -2658,14 +2658,16 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, mUserId,
                System.identityHashCode(this), task.mTaskId, shortComponentName, reason);

        final ActivityStack stack = getActivityStack();
        if (hasProcess() && !stack.inLruList(this)) {
            Slog.w(TAG, "Activity " + this + " being finished, but not in LRU list");
        }

        boolean removedFromHistory = false;

        cleanUp(false /* cleanServices */, false /* setState */);

        final ActivityStack stack = getActivityStack();
        final boolean hadApp = hasProcess();

        if (hadApp) {
        if (hasProcess()) {
            if (removeFromApp) {
                app.removeActivity(this);
                if (!app.hasActivities()) {
@@ -2730,10 +2732,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

        configChangeFlags = 0;

        if (!stack.removeActivityFromLRUList(this) && hadApp) {
            Slog.w(TAG, "Activity " + this + " being finished, but not in LRU list");
        }

        return removedFromHistory;
    }

+17 −13
Original line number Diff line number Diff line
@@ -297,7 +297,7 @@ class ActivityStack extends TaskStack {
     * The first entry in the list is the least recently used.
     * It contains HistoryRecord objects.
     */
    private final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>();
    private final ArrayList<ActivityRecord> mLruActivities = new ArrayList<>();

    /**
     * When we are in the process of pausing an activity, before starting the
@@ -1060,14 +1060,15 @@ class ActivityStack extends TaskStack {
    }

    /** @return {@code true} if LRU list contained the specified activity. */
    final boolean removeActivityFromLRUList(ActivityRecord activity) {
        return mLRUActivities.remove(activity);
    final boolean inLruList(ActivityRecord activity) {
        return mLruActivities.contains(activity);
    }

    final boolean updateLRUListLocked(ActivityRecord r) {
        final boolean hadit = mLRUActivities.remove(r);
        mLRUActivities.add(r);
        return hadit;
    /** @return {@code true} if the given activity was contained in LRU list. */
    final boolean updateLruList(ActivityRecord r) {
        final boolean contained = mLruActivities.remove(r);
        mLruActivities.add(r);
        return contained;
    }

    final boolean isHomeOrRecentsStack() {
@@ -2653,7 +2654,7 @@ class ActivityStack extends TaskStack {

            next.app.updateProcessInfo(false /* updateServiceConnectionActivities */,
                    true /* activityChange */, true /* updateOomAdj */);
            updateLRUListLocked(next);
            updateLruList(next);

            // Have the window manager re-evaluate the orientation of
            // the screen based on the new activity order.
@@ -3643,10 +3644,10 @@ class ActivityStack extends TaskStack {
     * an activity moves away from the stack.
     */
    void onActivityRemovedFromStack(ActivityRecord r) {
        removeActivityFromLRUList(r);
        removeTimeoutsForActivity(r);

        mExitingActivities.remove(r);
        mLruActivities.remove(r);

        if (mResumedActivity != null && mResumedActivity == r) {
            setResumedActivity(null, "onActivityRemovedFromStack");
@@ -3657,9 +3658,12 @@ class ActivityStack extends TaskStack {
    }

    void onActivityAddedToStack(ActivityRecord r) {
        if(r.getState() == RESUMED) {
        if (r.isState(RESUMED)) {
            setResumedActivity(r, "onActivityAddedToStack");
        }
        if (r.hasProcess()) {
            updateLruList(r);
        }
    }

    /// HANDLER INTERFACE BEGIN
@@ -3817,7 +3821,7 @@ class ActivityStack extends TaskStack {
    }

    private boolean removeHistoryRecordsForAppLocked(WindowProcessController app) {
        removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities");
        removeHistoryRecordsForAppLocked(mLruActivities, app, "mLruActivities");
        removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app,
                "mStoppingActivities");
        removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app,
@@ -4381,7 +4385,7 @@ class ActivityStack extends TaskStack {
        boolean printed = dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage,
                needSep);

        printed |= dumpHistoryList(fd, pw, mLRUActivities, "    ", "Run", false,
        printed |= dumpHistoryList(fd, pw, mLruActivities, "    ", "Run", false,
                !dumpAll, false, dumpPackage, true,
                "    Running activities (most recent first):", null);

@@ -4658,7 +4662,7 @@ class ActivityStack extends TaskStack {
        // Apps may depend on onResume()/onPause() being called in pairs.
        if (setResume) {
            r.setState(RESUMED, "moveToFrontAndResumeStateIfNeeded");
            updateLRUListLocked(r);
            updateLruList(r);
        }
        // If the activity was previously pausing, then ensure we transfer that as well
        if (setPause) {
+1 −1
Original line number Diff line number Diff line
@@ -913,7 +913,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
        }

        r.launchFailed = false;
        if (stack.updateLRUListLocked(r)) {
        if (stack.updateLruList(r)) {
            Slog.w(TAG, "Activity " + r + " being launched, but already in LRU list");
        }