From 3ffec4f568318f6cc6fd131f06cbab8099f10b31 Mon Sep 17 00:00:00 2001 From: Jing Ji Date: Fri, 9 Jun 2023 13:55:21 -0700 Subject: [PATCH] Do not reuse the same ProcessRecord if it's not fully gone yet When force-stopping apps, it's eligible for restart, and during that we might be reusing the old ProcessRecord before that process is really gone. Now don't reuse that. And also, remove the ProcessRecord from the LRU list when we know it's really gone. Bug: 286299952 Test: Manual - Clear app data and make sure it could restart correctly. Change-Id: I2c71c64b962cb9b4ae15881add50c35fd9e4a7af --- .../core/java/com/android/server/am/ProcessList.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java index 4342cb9947541..0027e7b72befd 100644 --- a/services/core/java/com/android/server/am/ProcessList.java +++ b/services/core/java/com/android/server/am/ProcessList.java @@ -2572,9 +2572,14 @@ public final class ProcessList { // and did the cleanup before the actual death notification. Check the dying processes. predecessor = mDyingProcesses.get(processName, info.uid); if (predecessor != null) { - if (app != null) { + // The process record could have existed but its pid is set to 0. In this case, + // the 'app' and 'predecessor' could end up pointing to the same instance; + // so make sure we check this case here. + if (app != null && app != predecessor) { app.mPredecessor = predecessor; predecessor.mSuccessor = app; + } else { + app = null; } Slog.w(TAG_PROCESSES, predecessor.toString() + " is attached to a previous process " + predecessor.getDyingPid()); @@ -5195,6 +5200,8 @@ public final class ProcessList { mDyingProcesses.remove(app.processName, app.uid); app.setDyingPid(0); handlePrecedingAppDiedLocked(app); + // Remove from the LRU list if it's still there. + removeLruProcessLocked(app); return true; } return false;