summaryrefslogtreecommitdiffstats
path: root/services/java/com/android/server/AttributeCache.java
diff options
context:
space:
mode:
Diffstat (limited to 'services/java/com/android/server/AttributeCache.java')
-rw-r--r--services/java/com/android/server/AttributeCache.java51
1 files changed, 33 insertions, 18 deletions
diff --git a/services/java/com/android/server/AttributeCache.java b/services/java/com/android/server/AttributeCache.java
index 81378dc..81613c6 100644
--- a/services/java/com/android/server/AttributeCache.java
+++ b/services/java/com/android/server/AttributeCache.java
@@ -23,6 +23,7 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
+import android.os.UserHandle;
import android.util.SparseArray;
import java.util.HashMap;
@@ -34,52 +35,54 @@ import java.util.WeakHashMap;
*/
public final class AttributeCache {
private static AttributeCache sInstance = null;
-
+
private final Context mContext;
- private final WeakHashMap<String, Package> mPackages =
- new WeakHashMap<String, Package>();
+ private final SparseArray<WeakHashMap<String, Package>> mPackages =
+ new SparseArray<WeakHashMap<String, Package>>();
private final Configuration mConfiguration = new Configuration();
-
+
public final static class Package {
public final Context context;
private final SparseArray<HashMap<int[], Entry>> mMap
= new SparseArray<HashMap<int[], Entry>>();
-
+
public Package(Context c) {
context = c;
}
}
-
+
public final static class Entry {
public final Context context;
public final TypedArray array;
-
+
public Entry(Context c, TypedArray ta) {
context = c;
array = ta;
}
}
-
+
public static void init(Context context) {
if (sInstance == null) {
sInstance = new AttributeCache(context);
}
}
-
+
public static AttributeCache instance() {
return sInstance;
}
-
+
public AttributeCache(Context context) {
mContext = context;
}
-
+
public void removePackage(String packageName) {
synchronized (this) {
- mPackages.remove(packageName);
+ for (int i=0; i<mPackages.size(); i++) {
+ mPackages.valueAt(i).remove(packageName);
+ }
}
}
-
+
public void updateConfiguration(Configuration config) {
synchronized (this) {
int changes = mConfiguration.updateFrom(config);
@@ -93,10 +96,21 @@ public final class AttributeCache {
}
}
}
-
- public Entry get(String packageName, int resId, int[] styleable) {
+
+ public void removeUser(int userId) {
+ synchronized (this) {
+ mPackages.remove(userId);
+ }
+ }
+
+ public Entry get(int userId, String packageName, int resId, int[] styleable) {
synchronized (this) {
- Package pkg = mPackages.get(packageName);
+ WeakHashMap<String, Package> packages = mPackages.get(userId);
+ if (packages == null) {
+ packages = new WeakHashMap<String, Package>();
+ mPackages.put(userId, packages);
+ }
+ Package pkg = packages.get(packageName);
HashMap<int[], Entry> map = null;
Entry ent = null;
if (pkg != null) {
@@ -110,7 +124,8 @@ public final class AttributeCache {
} else {
Context context;
try {
- context = mContext.createPackageContext(packageName, 0);
+ context = mContext.createPackageContextAsUser(packageName, 0,
+ new UserHandle(userId));
if (context == null) {
return null;
}
@@ -118,7 +133,7 @@ public final class AttributeCache {
return null;
}
pkg = new Package(context);
- mPackages.put(packageName, pkg);
+ packages.put(packageName, pkg);
}
if (map == null) {