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

Commit c4f67aad authored by Bhargav Upperla's avatar Bhargav Upperla Committed by Linux Build Service Account
Browse files

Start Home Process as an empty app when killed by LMK.

We maintain the empty app as a persistent process and keep it around
until we go back to home. Once we go back to home, the original
home app behavior persists.

Helps with back-to-home latencies, especially under memory pressure.

Change-Id: I447aeb4c84629c9e3b9d2d4b3095d2b3e43343dc
parent e7b6415c
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -522,6 +522,10 @@ public final class ActivityManagerService extends ActivityManagerNative
    private static final int PERSISTENT_MASK =
            ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PERSISTENT;
    // Start home process as an empty app
    private boolean mHomeKilled = false;
    private String mHomeProcessName = null;
    // Intent sent when remote bugreport collection has been completed
    private static final String INTENT_REMOTE_BUGREPORT_FINISHED =
            "android.intent.action.REMOTE_BUGREPORT_FINISHED";
@@ -5176,7 +5180,12 @@ public final class ActivityManagerService extends ActivityManagerNative
                app.thread.asBinder() == thread.asBinder()) {
            boolean doLowMem = app.instrumentationClass == null;
            boolean doOomAdj = doLowMem;
            boolean homeRestart = false;
            if (!app.killedByAm) {
                if (mHomeProcessName != null && app.processName.equals(mHomeProcessName)) {
                    mHomeKilled = true;
                    homeRestart = true;
                }
                Slog.i(TAG, "Process " + app.processName + " (pid " + pid
                        + ") has died");
                mAllowLowerMemLevel = true;
@@ -5197,6 +5206,13 @@ public final class ActivityManagerService extends ActivityManagerNative
            if (doLowMem) {
                doLowMemReportIfNeededLocked(app);
            }
            if (mHomeKilled && homeRestart) {
                Intent intent = getHomeIntent();
                ActivityInfo aInfo = mStackSupervisor.resolveActivity(intent, null, 0, null, 0);
                startProcessLocked(aInfo.processName, aInfo.applicationInfo, true, 0,
                        "activity", null, false, false, true);
                homeRestart = false;
            }
        } else if (app.pid != pid) {
            // A new process has already been started.
            Slog.i(TAG, "Process " + app.processName + " (pid " + pid
@@ -16820,6 +16836,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        mProcessesOnHold.remove(app);
        if (app == mHomeProcess) {
            mHomeProcessName = mHomeProcess.processName;
            mHomeProcess = null;
        }
        if (app == mPreviousProcess) {
@@ -19104,6 +19121,10 @@ public final class ActivityManagerService extends ActivityManagerNative
            app.adjType = "top-activity";
            foregroundActivities = true;
            procState = PROCESS_STATE_CUR_TOP;
            if(app == mHomeProcess) {
                mHomeKilled = false;
                mHomeProcessName = mHomeProcess.processName;
            }
        } else if (app.instrumentationClass != null) {
            // Don't want to kill running instrumentation.
            adj = ProcessList.FOREGROUND_APP_ADJ;
@@ -19139,6 +19160,14 @@ public final class ActivityManagerService extends ActivityManagerNative
            app.cached = true;
            app.empty = true;
            app.adjType = "cch-empty";
            if (mHomeKilled && app.processName.equals(mHomeProcessName)) {
                adj = ProcessList.PERSISTENT_PROC_ADJ;
                schedGroup = Process.THREAD_GROUP_DEFAULT;
                app.cached = false;
                app.empty = false;
                app.adjType = "top-activity";
            }
        }
        // Examine all activities if not already foreground.