OSDN Git Service

Make sure to synchronize on references to plugin dependencies
authorJason Monk <jmonk@google.com>
Thu, 6 Apr 2017 18:41:00 +0000 (14:41 -0400)
committerJason Monk <jmonk@google.com>
Thu, 6 Apr 2017 18:41:00 +0000 (14:41 -0400)
Test: make
Change-Id: I361cb3e4ac4ff5d19e2b0322531c8c614f5b7635
Fixes: 36867744

packages/SystemUI/src/com/android/systemui/plugins/PluginDependencyProvider.java

index 59f6d56..c58d889 100644 (file)
@@ -34,7 +34,9 @@ public class PluginDependencyProvider extends DependencyProvider {
     }
 
     public <T> void allowPluginDependency(Class<T> cls, T obj) {
-        mDependencies.put(cls, obj);
+        synchronized (mDependencies) {
+            mDependencies.put(cls, obj);
+        }
     }
 
     @Override
@@ -42,9 +44,11 @@ public class PluginDependencyProvider extends DependencyProvider {
         if (!mManager.dependsOn(p, cls)) {
             throw new IllegalArgumentException(p.getClass() + " does not depend on " + cls);
         }
-        if (!mDependencies.containsKey(cls)) {
-            throw new IllegalArgumentException("Unknown dependency " + cls);
+        synchronized (mDependencies) {
+            if (!mDependencies.containsKey(cls)) {
+                throw new IllegalArgumentException("Unknown dependency " + cls);
+            }
+            return (T) mDependencies.get(cls);
         }
-        return (T) mDependencies.get(cls);
     }
 }