Loading core/java/android/app/ResourcesManager.java +35 −18 Original line number Diff line number Diff line Loading @@ -125,10 +125,13 @@ public class ResourcesManager { } } private static final boolean ENABLE_APK_ASSETS_CACHE = true; /** * The ApkAssets we are caching and intend to hold strong references to. */ private final LruCache<ApkKey, ApkAssets> mLoadedApkAssets = new LruCache<>(3); private final LruCache<ApkKey, ApkAssets> mLoadedApkAssets = (ENABLE_APK_ASSETS_CACHE) ? new LruCache<>(3) : null; /** * The ApkAssets that are being referenced in the wild that we can reuse, even if they aren't Loading Loading @@ -316,17 +319,23 @@ public class ResourcesManager { private @NonNull ApkAssets loadApkAssets(String path, boolean sharedLib, boolean overlay) throws IOException { final ApkKey newKey = new ApkKey(path, sharedLib, overlay); ApkAssets apkAssets = mLoadedApkAssets.get(newKey); ApkAssets apkAssets = null; if (mLoadedApkAssets != null) { apkAssets = mLoadedApkAssets.get(newKey); if (apkAssets != null) { return apkAssets; } } // Optimistically check if this ApkAssets exists somewhere else. final WeakReference<ApkAssets> apkAssetsRef = mCachedApkAssets.get(newKey); if (apkAssetsRef != null) { apkAssets = apkAssetsRef.get(); if (apkAssets != null) { if (mLoadedApkAssets != null) { mLoadedApkAssets.put(newKey, apkAssets); } return apkAssets; } else { // Clean up the reference. Loading @@ -341,7 +350,11 @@ public class ResourcesManager { } else { apkAssets = ApkAssets.loadFromPath(path, false /*system*/, sharedLib); } if (mLoadedApkAssets != null) { mLoadedApkAssets.put(newKey, apkAssets); } mCachedApkAssets.put(newKey, new WeakReference<>(apkAssets)); return apkAssets; } Loading Loading @@ -441,6 +454,7 @@ public class ResourcesManager { pw.println("ResourcesManager:"); pw.increaseIndent(); if (mLoadedApkAssets != null) { pw.print("cached apks: total="); pw.print(mLoadedApkAssets.size()); pw.print(" created="); Loading @@ -453,6 +467,9 @@ public class ResourcesManager { pw.print(mLoadedApkAssets.missCount()); pw.print(" max="); pw.print(mLoadedApkAssets.maxSize()); } else { pw.print("cached apks: 0 [cache disabled]"); } pw.println(); pw.print("total apks: "); Loading Loading
core/java/android/app/ResourcesManager.java +35 −18 Original line number Diff line number Diff line Loading @@ -125,10 +125,13 @@ public class ResourcesManager { } } private static final boolean ENABLE_APK_ASSETS_CACHE = true; /** * The ApkAssets we are caching and intend to hold strong references to. */ private final LruCache<ApkKey, ApkAssets> mLoadedApkAssets = new LruCache<>(3); private final LruCache<ApkKey, ApkAssets> mLoadedApkAssets = (ENABLE_APK_ASSETS_CACHE) ? new LruCache<>(3) : null; /** * The ApkAssets that are being referenced in the wild that we can reuse, even if they aren't Loading Loading @@ -316,17 +319,23 @@ public class ResourcesManager { private @NonNull ApkAssets loadApkAssets(String path, boolean sharedLib, boolean overlay) throws IOException { final ApkKey newKey = new ApkKey(path, sharedLib, overlay); ApkAssets apkAssets = mLoadedApkAssets.get(newKey); ApkAssets apkAssets = null; if (mLoadedApkAssets != null) { apkAssets = mLoadedApkAssets.get(newKey); if (apkAssets != null) { return apkAssets; } } // Optimistically check if this ApkAssets exists somewhere else. final WeakReference<ApkAssets> apkAssetsRef = mCachedApkAssets.get(newKey); if (apkAssetsRef != null) { apkAssets = apkAssetsRef.get(); if (apkAssets != null) { if (mLoadedApkAssets != null) { mLoadedApkAssets.put(newKey, apkAssets); } return apkAssets; } else { // Clean up the reference. Loading @@ -341,7 +350,11 @@ public class ResourcesManager { } else { apkAssets = ApkAssets.loadFromPath(path, false /*system*/, sharedLib); } if (mLoadedApkAssets != null) { mLoadedApkAssets.put(newKey, apkAssets); } mCachedApkAssets.put(newKey, new WeakReference<>(apkAssets)); return apkAssets; } Loading Loading @@ -441,6 +454,7 @@ public class ResourcesManager { pw.println("ResourcesManager:"); pw.increaseIndent(); if (mLoadedApkAssets != null) { pw.print("cached apks: total="); pw.print(mLoadedApkAssets.size()); pw.print(" created="); Loading @@ -453,6 +467,9 @@ public class ResourcesManager { pw.print(mLoadedApkAssets.missCount()); pw.print(" max="); pw.print(mLoadedApkAssets.maxSize()); } else { pw.print("cached apks: 0 [cache disabled]"); } pw.println(); pw.print("total apks: "); Loading