summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Andrei-Valentin Onea <andreionea@google.com> 2021-02-26 17:33:30 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2021-02-26 17:33:30 +0000
commit75c6b35d4bcca8010b267418df62a0eebfdd2bc8 (patch)
treec4141969c85ce98f8fdf95deaccca82befdbeed0
parent87cb8b5efe92946f80dff286ad6fa2fd995dfd44 (diff)
parent0f53ddc2057e98e9f386c937b4c0c1609063098e (diff)
Merge "Fix deadlock on CompatConfig.mChanges" am: eaf3fd59ff am: 0f53ddc205
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1605516 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I9086ea63f1a062819e686d510b013dfb446fb3e7
-rw-r--r--services/core/java/com/android/server/compat/CompatConfig.java23
1 files changed, 15 insertions, 8 deletions
diff --git a/services/core/java/com/android/server/compat/CompatConfig.java b/services/core/java/com/android/server/compat/CompatConfig.java
index 422991e082a9..66a652053857 100644
--- a/services/core/java/com/android/server/compat/CompatConfig.java
+++ b/services/core/java/com/android/server/compat/CompatConfig.java
@@ -50,6 +50,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -595,18 +596,24 @@ final class CompatConfig {
* Rechecks all the existing overrides for a package.
*/
void recheckOverrides(String packageName) {
+ // Local cache of compat changes. Holding a lock on mChanges for the whole duration of the
+ // method will cause a deadlock.
+ List<CompatChange> changes;
synchronized (mChanges) {
- boolean shouldInvalidateCache = false;
+ changes = new ArrayList<>(mChanges.size());
for (int idx = 0; idx < mChanges.size(); ++idx) {
- CompatChange c = mChanges.valueAt(idx);
- OverrideAllowedState allowedState =
- mOverrideValidator.getOverrideAllowedState(c.getId(), packageName);
- shouldInvalidateCache |= c.recheckOverride(packageName, allowedState, mContext);
- }
- if (shouldInvalidateCache) {
- invalidateCache();
+ changes.add(mChanges.valueAt(idx));
}
}
+ boolean shouldInvalidateCache = false;
+ for (CompatChange c: changes) {
+ OverrideAllowedState allowedState =
+ mOverrideValidator.getOverrideAllowedState(c.getId(), packageName);
+ shouldInvalidateCache |= c.recheckOverride(packageName, allowedState, mContext);
+ }
+ if (shouldInvalidateCache) {
+ invalidateCache();
+ }
}
void registerContentObserver() {