[ActivityManager] Fix race condition in pss collection
Symptom:
There has a race condition that two threads are accessing
the mPendingPssProcesses simultaneously. One of the thread
is collecting the process pss by looping the mPendingPssProcesses.
The other thread is requesting to collect pss of all processes,
which clears mPendingPssProcesses and adding processes back.
Solution:
Avoid race condition by adding synchornized protection.
Change-Id: Ifb090eda9c4a1b8e3fd980fe0171e9dd77773b46
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index c3dd638..abaf27e 100755
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1836,7 +1836,9 @@
break;
}
case REQUEST_ALL_PSS_MSG: {
- requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false);
+ synchronized (ActivityManagerService.this) {
+ requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false);
+ }
break;
}
case START_PROFILES_MSG: {