From a7d6da803241d45aec5edb0e357be88afc862739 Mon Sep 17 00:00:00 2001 From: Siting Mo Date: Mon, 11 Jul 2022 15:32:25 +0800 Subject: [PATCH] Add AMS lock protection to mAppsInBackgroundRestricted collection When the process is started asynchronously, the mAppsInBackgroundRestricted collection lacks AMS lock protection and will throw ConcurrentModificationException crash with a low probability. Bug: 236582924 Test: Treehugger Change-Id: Ieec1de9ee1fd336cf1de54566f80442e3cd3acdd --- services/core/java/com/android/server/am/ProcessList.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java index 92a8dcd2ba8f3..98e3a214435a4 100644 --- a/services/core/java/com/android/server/am/ProcessList.java +++ b/services/core/java/com/android/server/am/ProcessList.java @@ -2269,7 +2269,9 @@ public final class ProcessList { final boolean inBgRestricted = ast.isAppBackgroundRestricted( app.info.uid, app.info.packageName); if (inBgRestricted) { - mAppsInBackgroundRestricted.add(app); + synchronized (mService) { + mAppsInBackgroundRestricted.add(app); + } } app.mState.setBackgroundRestricted(inBgRestricted); }