Fix race condition bug related to freezing apps. am: 41d2be0f0f am: 453efdc065

am: 1395bf02cc

Change-Id: I7d9478a626e3217cf061da22394d4c6263f1fb66
This commit is contained in:
Jeff Sharkey
2016-12-09 17:44:19 +00:00
committed by android-build-merger

View File

@@ -6203,8 +6203,19 @@ public class ActivityManagerService extends IActivityManager.Stub
}
private final ProcessRecord removeProcessNameLocked(final String name, final int uid) {
ProcessRecord old = mProcessNames.remove(name, uid);
if (old != null) {
return removeProcessNameLocked(name, uid, null);
}
private final ProcessRecord removeProcessNameLocked(final String name, final int uid,
final ProcessRecord expecting) {
ProcessRecord old = mProcessNames.get(name, uid);
// Only actually remove when the currently recorded value matches the
// record that we expected; if it doesn't match then we raced with a
// newly created process and we don't want to destroy the new one.
if ((expecting == null) || (old == expecting)) {
mProcessNames.remove(name, uid);
}
if (old != null && old.uidRecord != null) {
old.uidRecord.numProcs--;
if (old.uidRecord.numProcs == 0) {
// No more processes using this uid, tell clients it is gone.
@@ -17041,7 +17052,7 @@ public class ActivityManagerService extends IActivityManager.Stub
if (DEBUG_PROCESSES || DEBUG_CLEANUP) Slog.v(TAG_CLEANUP,
"Removing non-persistent process during cleanup: " + app);
if (!replacingPid) {
removeProcessNameLocked(app.processName, app.uid);
removeProcessNameLocked(app.processName, app.uid, app);
}
if (mHeavyWeightProcess == app) {
mHandler.sendMessage(mHandler.obtainMessage(CANCEL_HEAVY_NOTIFICATION_MSG,