summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorriddle_hsu <riddle_hsu@htc.com>2015-11-23 13:22:03 +0800
committerSteve Kondik <steve@cyngn.com>2015-12-08 02:31:06 -0800
commit5f28002f095985ee1daad59863f091a651ffb9d4 (patch)
treeaa1a1f9b6f2b91946c75739f4528ef1acf5ed11e /services
parent29e7f0d08edf5754ffc30a92f100f99efa566908 (diff)
downloadframeworks_base-5f28002f095985ee1daad59863f091a651ffb9d4.zip
frameworks_base-5f28002f095985ee1daad59863f091a651ffb9d4.tar.gz
frameworks_base-5f28002f095985ee1daad59863f091a651ffb9d4.tar.bz2
Fix race condition when collecting op callback.
Other threads may change mOpModeWatchers, mPackageModeWatchers by startWatchingMode, stopWatchingMode. Change-Id: Id260172979ddfc2df9331880805d16ee13e183eb
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/AppOpsService.java46
1 files changed, 24 insertions, 22 deletions
diff --git a/services/core/java/com/android/server/AppOpsService.java b/services/core/java/com/android/server/AppOpsService.java
index b5bf12c..83a0a99 100644
--- a/services/core/java/com/android/server/AppOpsService.java
+++ b/services/core/java/com/android/server/AppOpsService.java
@@ -560,33 +560,35 @@ public class AppOpsService extends IAppOpsService.Stub {
String[] uidPackageNames = getPackagesForUid(uid);
ArrayMap<Callback, ArraySet<String>> callbackSpecs = null;
- ArrayList<Callback> callbacks = mOpModeWatchers.get(code);
- if (callbacks != null) {
- final int callbackCount = callbacks.size();
- for (int i = 0; i < callbackCount; i++) {
- Callback callback = callbacks.get(i);
- ArraySet<String> changedPackages = new ArraySet<>();
- Collections.addAll(changedPackages, uidPackageNames);
- callbackSpecs = new ArrayMap<>();
- callbackSpecs.put(callback, changedPackages);
- }
- }
-
- for (String uidPackageName : uidPackageNames) {
- callbacks = mPackageModeWatchers.get(uidPackageName);
+ synchronized (this) {
+ ArrayList<Callback> callbacks = mOpModeWatchers.get(code);
if (callbacks != null) {
- if (callbackSpecs == null) {
- callbackSpecs = new ArrayMap<>();
- }
final int callbackCount = callbacks.size();
for (int i = 0; i < callbackCount; i++) {
Callback callback = callbacks.get(i);
- ArraySet<String> changedPackages = callbackSpecs.get(callback);
- if (changedPackages == null) {
- changedPackages = new ArraySet<>();
- callbackSpecs.put(callback, changedPackages);
+ ArraySet<String> changedPackages = new ArraySet<>();
+ Collections.addAll(changedPackages, uidPackageNames);
+ callbackSpecs = new ArrayMap<>();
+ callbackSpecs.put(callback, changedPackages);
+ }
+ }
+
+ for (String uidPackageName : uidPackageNames) {
+ callbacks = mPackageModeWatchers.get(uidPackageName);
+ if (callbacks != null) {
+ if (callbackSpecs == null) {
+ callbackSpecs = new ArrayMap<>();
+ }
+ final int callbackCount = callbacks.size();
+ for (int i = 0; i < callbackCount; i++) {
+ Callback callback = callbacks.get(i);
+ ArraySet<String> changedPackages = callbackSpecs.get(callback);
+ if (changedPackages == null) {
+ changedPackages = new ArraySet<>();
+ callbackSpecs.put(callback, changedPackages);
+ }
+ changedPackages.add(uidPackageName);
}
- changedPackages.add(uidPackageName);
}
}
}