Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91cabc9b authored by Andy Mast's avatar Andy Mast
Browse files

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
parent 347951e3
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -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);
        }
+11 −1
Original line number Diff line number Diff line
@@ -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