From 62cfde14423922948928c40eddd212d1dc51d591 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 c3dd638316bea..abaf27ee85ec1 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 @@ 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: {