From 5149ef3803dd5ff6ba9c28161a7d7b0c8b227879 Mon Sep 17 00:00:00 2001 From: Andy Mast Date: Mon, 1 Dec 2014 14:58:09 -0800 Subject: Themes: Remove an app's icons from cache when installing If an app is being updated then its icons will exist in cache. Go ahead and delete them so that they can be recreated. Change-Id: If0ee4388efd4aa146ebcdc46b1b0742f0852bad3 (cherry picked from commit 91cabc9b9006e8c2f06aa6cbbc237c4ca585e49d) --- core/java/android/app/IconPackHelper.java | 18 ++++++++++++++++++ .../com/android/server/pm/PackageManagerService.java | 12 +++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/IconPackHelper.java b/core/java/android/app/IconPackHelper.java index 321a1d496c4..ceea8987c24 100644 --- a/core/java/android/app/IconPackHelper.java +++ b/core/java/android/app/IconPackHelper.java @@ -16,6 +16,7 @@ package android.app; import java.io.File; +import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -603,6 +604,23 @@ public class IconPackHelper { getCachedIconName(pkgName, resId, density)); } + + // Returns paths for all densities + public static String[] getCachedIconPaths(String pkgName) { + File iconCache = new File(ThemeUtils.SYSTEM_THEME_ICON_CACHE_DIR); + final String prefix = String.format("%s", pkgName); + + FilenameFilter filter = new FilenameFilter() { + @Override + public boolean accept(File dir, String filename) { + return filename.startsWith(prefix); + } + }; + + String[] validPaths = iconCache.list(filter); + return validPaths != null ? validPaths : new String[0]; + } + private static String getCachedIconName(String pkgName, int resId, int density) { return String.format("%s_%08x_%d.png", pkgName, resId, density); } diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java index 1667ddea7f6..b7dd94da3f6 100644 --- a/services/java/com/android/server/pm/PackageManagerService.java +++ b/services/java/com/android/server/pm/PackageManagerService.java @@ -5178,6 +5178,17 @@ public class PackageManagerService extends IPackageManager.Stub { pkg.applicationInfo.themedIcon = id; } + // Clear out any icon in the cache so it can be recomopsed if needed + final boolean isBootScan = (scanMode & SCAN_BOOTING) != 0; + if (!isBootScan) { + String[] iconPaths = + IconPackHelper.IconCustomizer.getCachedIconPaths(pkg.packageName); + for(String iconPath : iconPaths) { + File file = new File(ThemeUtils.SYSTEM_THEME_ICON_CACHE_DIR, iconPath); + file.delete(); + } + } + // Add the new setting to mPackages mPackages.put(pkg.applicationInfo.packageName, pkg); // Make sure we don't accidentally delete its data. @@ -5495,7 +5506,6 @@ public class PackageManagerService extends IPackageManager.Stub { pkgSetting.setTimeStamp(scanFileTime); - final boolean isBootScan = (scanMode & SCAN_BOOTING) != 0; // Generate resources & idmaps if pkg is NOT a theme // We must compile resources here because during the initial boot process we may get // here before a default theme has had a chance to compile its resources -- cgit v1.2.3