FileDocCategorySizeDatePackage
AttributeCache.javaAPI DocAndroid 5.1 API4612Thu Mar 12 22:22:42 GMT 2015com.android.server

AttributeCache

public final class AttributeCache extends Object
TODO: This should be better integrated into the system so it doesn't need special calls from the activity manager to clear it.

Fields Summary
private static AttributeCache
sInstance
private final android.content.Context
mContext
private final WeakHashMap
mPackages
private final android.content.res.Configuration
mConfiguration
Constructors Summary
public AttributeCache(android.content.Context context)

        mContext = context;
    
Methods Summary
public com.android.server.AttributeCache$Entryget(java.lang.String packageName, int resId, int[] styleable, int userId)

        synchronized (this) {
            Package pkg = mPackages.get(packageName);
            HashMap<int[], Entry> map = null;
            Entry ent = null;
            if (pkg != null) {
                map = pkg.mMap.get(resId);
                if (map != null) {
                    ent = map.get(styleable);
                    if (ent != null) {
                        return ent;
                    }
                }
            } else {
                Context context;
                try {
                    context = mContext.createPackageContextAsUser(packageName, 0,
                            new UserHandle(userId));
                    if (context == null) {
                        return null;
                    }
                } catch (PackageManager.NameNotFoundException e) {
                    return null;
                }
                pkg = new Package(context);
                mPackages.put(packageName, pkg);
            }
            
            if (map == null) {
                map = new HashMap<int[], Entry>();
                pkg.mMap.put(resId, map);
            }
            
            try {
                ent = new Entry(pkg.context,
                        pkg.context.obtainStyledAttributes(resId, styleable));
                map.put(styleable, ent);
            } catch (Resources.NotFoundException e) {
                return null;
            }
            
            return ent;
        }
    
public static voidinit(android.content.Context context)

        if (sInstance == null) {
            sInstance = new AttributeCache(context);
        }
    
public static com.android.server.AttributeCacheinstance()

        return sInstance;
    
public voidremovePackage(java.lang.String packageName)

        synchronized (this) {
            mPackages.remove(packageName);
        }
    
public voidupdateConfiguration(android.content.res.Configuration config)

        synchronized (this) {
            int changes = mConfiguration.updateFrom(config);
            if ((changes & ~(ActivityInfo.CONFIG_FONT_SCALE |
                    ActivityInfo.CONFIG_KEYBOARD_HIDDEN |
                    ActivityInfo.CONFIG_ORIENTATION)) != 0) {
                // The configurations being masked out are ones that commonly
                // change so we don't want flushing the cache... all others
                // will flush the cache.
                mPackages.clear();
            }
        }