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

Commit c7cbdd11 authored by Wale Ogunwale's avatar Wale Ogunwale Committed by Android (Google) Code Review
Browse files

Merge "Don't kill process with active service/receiver when task is removed." into mnc-dev

parents 2df124b8 5069e675
Loading
Loading
Loading
Loading
+17 −11
Original line number Diff line number Diff line
@@ -8537,13 +8537,16 @@ public final class ActivityManagerService extends ActivityManagerNative
            return;
        }
        // Find any running services associated with this app and stop if needed.
        mServices.cleanUpRemovedTaskLocked(tr, component, new Intent(tr.getBaseIntent()));
        if (!killProcess) {
            return;
        }
        // Determine if the process(es) for this task should be killed.
        final String pkg = component.getPackageName();
        ArrayList<ProcessRecord> procsToKill = new ArrayList<ProcessRecord>();
        ArrayList<ProcessRecord> procsToKill = new ArrayList<>();
        ArrayMap<String, SparseArray<ProcessRecord>> pmap = mProcessNames.getMap();
        for (int i = 0; i < pmap.size(); i++) {
@@ -8572,20 +8575,24 @@ public final class ActivityManagerService extends ActivityManagerNative
                    }
                }
                if (proc.foregroundServices) {
                    // Don't kill process(es) with foreground service.
                    return;
                }
                // Add process to kill list.
                procsToKill.add(proc);
            }
        }
        // Find any running services associated with this app and stop if needed.
        mServices.cleanUpRemovedTaskLocked(tr, component, new Intent(tr.getBaseIntent()));
        // Kill the running processes.
        for (int i = 0; i < procsToKill.size(); i++) {
            ProcessRecord pr = procsToKill.get(i);
            if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
            if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
                    && pr.curReceiver == null) {
                pr.kill("remove task", true);
            } else {
                // We delay killing processes that are not in the background or running a receiver.
                pr.waitingToKill = "remove task";
            }
        }
@@ -18344,8 +18351,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
    }
    private final boolean applyOomAdjLocked(ProcessRecord app,
            ProcessRecord TOP_APP, boolean doingAll, long now) {
    private final boolean applyOomAdjLocked(ProcessRecord app, boolean doingAll, long now) {
        boolean success = true;
        if (app.curRawAdj != app.setRawAdj) {
@@ -18367,8 +18373,8 @@ public final class ActivityManagerService extends ActivityManagerNative
            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG_OOM_ADJ,
                    "Setting process group of " + app.processName
                    + " to " + app.curSchedGroup);
            if (app.waitingToKill != null &&
                    app.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
            if (app.waitingToKill != null && app.curReceiver == null
                    && app.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
                app.kill(app.waitingToKill, true);
                success = false;
            } else {
@@ -18598,7 +18604,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        computeOomAdjLocked(app, cachedAdj, TOP_APP, doingAll, now);
        return applyOomAdjLocked(app, TOP_APP, doingAll, now);
        return applyOomAdjLocked(app, doingAll, now);
    }
    final void updateProcessForegroundLocked(ProcessRecord proc, boolean isForeground,
@@ -18816,7 +18822,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                    }
                }
                applyOomAdjLocked(app, TOP_APP, true, now);
                applyOomAdjLocked(app, true, now);
                // Count the number of process types.
                switch (app.curProcState) {