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

Commit 50685606 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Improve how we manage the previous app.

Setting it when a new activity is being resumed is too soon, because
things like an activity launching an exiting (without being seen by
the user) can knock out the real previous app that we want.

So now we set it when an activity is stopped.  At this point it is
going to move from the preceptible to background oom adj, so it is
a good point to determine whether it should be a previous app to
instead put it to that oom adj.  This also avoids things like
activities that start and immediately finish from impacting the
previous app.

Further, we keep track of the time each activity was last shown, and
use this to further filter what is set as the previous app.

Change-Id: I72d1cac4de0cc2d4598170296028f11b06918d4f
parent a1240184
Loading
Loading
Loading
Loading
+12 −1
Original line number Original line Diff line number Diff line
@@ -415,6 +415,11 @@ public final class ActivityManagerService extends ActivityManagerNative
     */
     */
    ProcessRecord mPreviousProcess;
    ProcessRecord mPreviousProcess;
    /**
     * The time at which the previous process was last visible.
     */
    long mPreviousProcessVisibleTime;
    /**
    /**
     * Packages that the user has asked to have run in screen size
     * Packages that the user has asked to have run in screen size
     * compatibility mode instead of filling the screen.
     * compatibility mode instead of filling the screen.
@@ -8361,6 +8366,12 @@ public final class ActivityManagerService extends ActivityManagerNative
        pw.println();
        pw.println();
        pw.println("  mHomeProcess: " + mHomeProcess);
        pw.println("  mHomeProcess: " + mHomeProcess);
        pw.println("  mPreviousProcess: " + mPreviousProcess);
        pw.println("  mPreviousProcess: " + mPreviousProcess);
        if (dumpAll) {
            StringBuilder sb = new StringBuilder(128);
            sb.append("  mPreviousProcessVisibleTime: ");
            TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb);
            pw.println(sb);
        }
        if (mHeavyWeightProcess != null) {
        if (mHeavyWeightProcess != null) {
            pw.println("  mHeavyWeightProcess: " + mHeavyWeightProcess);
            pw.println("  mHeavyWeightProcess: " + mHeavyWeightProcess);
        }
        }
+6 −0
Original line number Original line Diff line number Diff line
@@ -80,6 +80,7 @@ final class ActivityRecord {
    ThumbnailHolder thumbHolder; // where our thumbnails should go.
    ThumbnailHolder thumbHolder; // where our thumbnails should go.
    long launchTime;        // when we starting launching this activity
    long launchTime;        // when we starting launching this activity
    long startTime;         // last time this activity was started
    long startTime;         // last time this activity was started
    long lastVisibleTime;   // last time this activity became visible
    long cpuTimeAtResume;   // the cpu time of host process at the time of resuming activity
    long cpuTimeAtResume;   // the cpu time of host process at the time of resuming activity
    Configuration configuration; // configuration activity was last running in
    Configuration configuration; // configuration activity was last running in
    CompatibilityInfo compat;// last used compatibility mode
    CompatibilityInfo compat;// last used compatibility mode
@@ -188,6 +189,10 @@ final class ActivityRecord {
                    TimeUtils.formatDuration(launchTime, pw); pw.print(" startTime=");
                    TimeUtils.formatDuration(launchTime, pw); pw.print(" startTime=");
                    TimeUtils.formatDuration(startTime, pw); pw.println("");
                    TimeUtils.formatDuration(startTime, pw); pw.println("");
        }
        }
        if (lastVisibleTime != 0) {
            pw.print(prefix); pw.print("lastVisibleTime=");
                    TimeUtils.formatDuration(lastVisibleTime, pw); pw.println("");
        }
        if (waitingVisible || nowVisible) {
        if (waitingVisible || nowVisible) {
            pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
            pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
                    pw.print(" nowVisible="); pw.println(nowVisible);
                    pw.print(" nowVisible="); pw.println(nowVisible);
@@ -632,6 +637,7 @@ final class ActivityRecord {
                    ActivityManagerService.TAG, "windowsVisible(): " + this);
                    ActivityManagerService.TAG, "windowsVisible(): " + this);
            if (!nowVisible) {
            if (!nowVisible) {
                nowVisible = true;
                nowVisible = true;
                lastVisibleTime = SystemClock.uptimeMillis();
                if (!idle) {
                if (!idle) {
                    // Instead of doing the full stop routine here, let's just
                    // Instead of doing the full stop routine here, let's just
                    // hide any activities we now can, and let them stop when
                    // hide any activities we now can, and let them stop when
+16 −8
Original line number Original line Diff line number Diff line
@@ -949,6 +949,22 @@ final class ActivityStack {
            if (r.configDestroy) {
            if (r.configDestroy) {
                destroyActivityLocked(r, true, false, "stop-config");
                destroyActivityLocked(r, true, false, "stop-config");
                resumeTopActivityLocked(null);
                resumeTopActivityLocked(null);
            } else {
                // Now that this process has stopped, we may want to consider
                // it to be the previous app to try to keep around in case
                // the user wants to return to it.
                ProcessRecord fgApp = null;
                if (mResumedActivity != null) {
                    fgApp = mResumedActivity.app;
                } else if (mPausingActivity != null) {
                    fgApp = mPausingActivity.app;
                }
                if (r.app != null && fgApp != null && r.app != fgApp
                        && r.lastVisibleTime > mService.mPreviousProcessVisibleTime
                        && r.app != mService.mHomeProcess) {
                    mService.mPreviousProcess = r.app;
                    mService.mPreviousProcessVisibleTime = r.lastVisibleTime;
                }
            }
            }
        }
        }
    }
    }
@@ -1363,14 +1379,6 @@ final class ActivityStack {
                        + ", nowVisible=" + next.nowVisible);
                        + ", nowVisible=" + next.nowVisible);
                }
                }
            }
            }

            if (!prev.finishing && prev.app != null && prev.app != next.app
                    && prev.app != mService.mHomeProcess) {
                // We are switching to a new activity that is in a different
                // process than the previous one.  Note the previous process,
                // so we can try to keep it around.
                mService.mPreviousProcess = prev.app;
            }
        }
        }


        // Launching this app's activity, make sure the app is no longer
        // Launching this app's activity, make sure the app is no longer