summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2016-12-09 17:22:19 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-12-09 17:22:22 +0000
commit3350ae9c82edec4021be8161644474e8f396a3fd (patch)
treefbaf5dc1875d05af30fe78a18d4a29ad2fba51be
parent385277305e86b77d3e832d818b396a2e6c4c0260 (diff)
parent41d2be0f0f824c002090c2fb663a0a9cdafca034 (diff)
Merge "Fix race condition bug related to freezing apps." into cw-f-dev
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java17
1 files changed, 14 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 91d9ac7f51dd..7c9497df3d89 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -6278,8 +6278,19 @@ public final class ActivityManagerService extends ActivityManagerNative
}
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.
@@ -17043,7 +17054,7 @@ public final class ActivityManagerService extends ActivityManagerNative
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,