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

Commit c68053a3 authored by Jing Ji's avatar Jing Ji
Browse files

Fix spurious undead process warning

Set the strict mode policy before Process.waitForProcessDeath.

Also eliminate some of the wtf warnings because we know it's
a legitimate case: a large process could get killed during
getProcessLocked(), and the caller would start a new process
right after that.

Bug: 161835160
Test: See b/161835160#comment3 for detailed test steps
Change-Id: I357b522943c88aa833dcf06013a9f8d2240c3967
parent 0eae0b2a
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -2050,7 +2050,9 @@ public final class ProcessList {
            final int pid = precedence.pid;
            long now = System.currentTimeMillis();
            final long end = now + PROC_KILL_TIMEOUT;
            final int oldPolicy = StrictMode.getThreadPolicyMask();
            try {
                StrictMode.setThreadPolicyMask(0);
                Process.waitForProcessDeath(pid, PROC_KILL_TIMEOUT);
                // It's killed successfully, but we'd make sure the cleanup work is done.
                synchronized (precedence) {
@@ -2069,9 +2071,11 @@ public final class ProcessList {
                    }
                }
            } catch (Exception e) {
                // It's still alive...
                // It's still alive... maybe blocked at uninterruptible sleep ?
                Slog.wtf(TAG, precedence.toString() + " refused to die, but we need to launch "
                        + app);
                        + app, e);
            } finally {
                StrictMode.setThreadPolicyMask(oldPolicy);
            }
        }
        try {
@@ -2416,7 +2420,15 @@ public final class ProcessList {
            ProcessList.killProcessGroup(app.uid, app.pid);
            checkSlow(startTime, "startProcess: done killing old proc");

            if (!app.killed || mService.mLastMemoryLevel <= ProcessStats.ADJ_MEM_FACTOR_NORMAL
                    || app.setProcState < ActivityManager.PROCESS_STATE_CACHED_EMPTY
                    || app.lastCachedPss < getCachedRestoreThresholdKb()) {
                // Throw a wtf if it's not killed, or killed but not because the system was in
                // memory pressure + the app was in "cch-empty" and used large amount of memory
                Slog.wtf(TAG_PROCESSES, app.toString() + " is attached to a previous process");
            } else {
                Slog.w(TAG_PROCESSES, app.toString() + " is attached to a previous process");
            }
            // We are not going to re-use the ProcessRecord, as we haven't dealt with the cleanup
            // routine of it yet, but we'd set it as the precedence of the new process.
            precedence = app;
@@ -2819,8 +2831,16 @@ public final class ProcessList {
            // We are re-adding a persistent process.  Whatevs!  Just leave it there.
            Slog.w(TAG, "Re-adding persistent process " + proc);
        } else if (old != null) {
            if (old.killed) {
                // The old process has been killed, we probably haven't had
                // a chance to clean up the old record, just log a warning
                Slog.w(TAG, "Existing proc " + old + " was killed "
                        + (SystemClock.uptimeMillis() - old.mKillTime)
                        + "ms ago when adding " + proc);
            } else {
                Slog.wtf(TAG, "Already have existing proc " + old + " when adding " + proc);
            }
        }
        UidRecord uidRec = mActiveUids.get(proc.uid);
        if (uidRec == null) {
            uidRec = new UidRecord(proc.uid);
+3 −0
Original line number Diff line number Diff line
@@ -352,6 +352,8 @@ class ProcessRecord implements WindowProcessListener {

    boolean mReachable; // Whether or not this process is reachable from given process

    long mKillTime; // The timestamp in uptime when this process was killed.

    void setStartParams(int startUid, HostingRecord hostingRecord, String seInfo,
            long startTime) {
        this.startUid = startUid;
@@ -925,6 +927,7 @@ class ProcessRecord implements WindowProcessListener {
            if (!mPersistent) {
                killed = true;
                killedByAm = true;
                mKillTime = SystemClock.uptimeMillis();
            }
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
        }