Merge "Fix race condition in UidRecord cleanup" into rvc-d1-dev am: c453c4aff9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12244064

Change-Id: Iee8b261b25ddd7cab96fdaf70439ac95b82a2c0b
This commit is contained in:
Jing Ji
2020-07-28 02:21:15 +00:00
committed by Automerger Merge Worker

View File

@@ -2940,25 +2940,26 @@ public final class ProcessList {
if ((expecting == null) || (old == expecting)) { if ((expecting == null) || (old == expecting)) {
mProcessNames.remove(name, uid); mProcessNames.remove(name, uid);
} }
if (old != null && old.uidRecord != null) { final ProcessRecord record = expecting != null ? expecting : old;
old.uidRecord.numProcs--; if (record != null && record.uidRecord != null) {
old.uidRecord.procRecords.remove(old); final UidRecord uidRecord = record.uidRecord;
if (old.uidRecord.numProcs == 0) { uidRecord.numProcs--;
uidRecord.procRecords.remove(record);
if (uidRecord.numProcs == 0) {
// No more processes using this uid, tell clients it is gone. // No more processes using this uid, tell clients it is gone.
if (DEBUG_UID_OBSERVERS) Slog.i(TAG_UID_OBSERVERS, if (DEBUG_UID_OBSERVERS) Slog.i(TAG_UID_OBSERVERS,
"No more processes in " + old.uidRecord); "No more processes in " + uidRecord);
mService.enqueueUidChangeLocked(old.uidRecord, -1, UidRecord.CHANGE_GONE); mService.enqueueUidChangeLocked(uidRecord, -1, UidRecord.CHANGE_GONE);
EventLogTags.writeAmUidStopped(uid); EventLogTags.writeAmUidStopped(uid);
mActiveUids.remove(uid); mActiveUids.remove(uid);
mService.noteUidProcessState(uid, ActivityManager.PROCESS_STATE_NONEXISTENT, mService.noteUidProcessState(uid, ActivityManager.PROCESS_STATE_NONEXISTENT,
ActivityManager.PROCESS_CAPABILITY_NONE); ActivityManager.PROCESS_CAPABILITY_NONE);
} }
old.uidRecord = null; record.uidRecord = null;
} }
mIsolatedProcesses.remove(uid); mIsolatedProcesses.remove(uid);
mGlobalIsolatedUids.freeIsolatedUidLocked(uid); mGlobalIsolatedUids.freeIsolatedUidLocked(uid);
// Remove the (expected) ProcessRecord from the app zygote // Remove the (expected) ProcessRecord from the app zygote
final ProcessRecord record = expecting != null ? expecting : old;
if (record != null && record.appZygote) { if (record != null && record.appZygote) {
removeProcessFromAppZygoteLocked(record); removeProcessFromAppZygoteLocked(record);
} }