From 71e737c8e8b970d780b930ebc6eacb4464d4a6aa Mon Sep 17 00:00:00 2001 From: louis_chang Date: Tue, 2 Dec 2014 12:57:39 +0800 Subject: [PATCH] [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 --- .../java/com/android/server/am/ActivityManagerService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 6823119d0c024..34fefcde2a45d 100755 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -1669,7 +1669,9 @@ public final class ActivityManagerService extends ActivityManagerNative break; } case REQUEST_ALL_PSS_MSG: { - requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false); + synchronized (ActivityManagerService.this) { + requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false); + } break; } case START_PROFILES_MSG: {