Hold service lock when AMS.setProcessMemoryTrimLevel() is called
Bug: 21633189
Change-Id: I7203807466593ced6ec3dd328c1a03532caf3a31
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index efc38e2..7363e3b 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -3615,19 +3615,21 @@
@Override
public boolean setProcessMemoryTrimLevel(String process, int userId, int level) {
- ProcessRecord app = getProcessRecordLocked(process, userId, true);
- if (app == null) {
- return false;
- }
- if (app.trimMemoryLevel < level && app.thread != null &&
- (level < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN ||
- app.trimMemoryLevel >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN)) {
- try {
- app.thread.scheduleTrimMemory(level);
- app.trimMemoryLevel = level;
- return true;
- } catch (RemoteException e) {
- // Fallthrough to failure case.
+ synchronized (this) {
+ final ProcessRecord app = getProcessRecordLocked(process, userId, true);
+ if (app == null) {
+ return false;
+ }
+ if (app.trimMemoryLevel < level && app.thread != null &&
+ (level < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN ||
+ app.trimMemoryLevel >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN)) {
+ try {
+ app.thread.scheduleTrimMemory(level);
+ app.trimMemoryLevel = level;
+ return true;
+ } catch (RemoteException e) {
+ // Fallthrough to failure case.
+ }
}
}
return false;