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

Commit 28d823bb authored by d34d's avatar d34d Committed by Clark Scheff
Browse files

Themes: Unapply specific components on theme uninstall

Because we are removing the theme's resource cache when the theme
is installed, it is possible for apps to still reference the paths
to these cached resources.  Once the directories are removed these
paths are no longer valid and can result in apps or even the system
crashing.

This patch checks the current ThemeConfig for any components that
may be applied from the theme being removed and sends a request to
the theme service to change the those components back to defaults.

Change-Id: I800348f9b7db57e5091f684ce5f931c19e8859d4
REF: ALCATELTCL-667
parent d2600361
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -678,6 +678,46 @@ public class ThemeUtils {
        }
    }

    /**
     * Creates a map of components found in the current ThemeConfig that come from {@themePkgName}
     * and sets them to the proper defaults.
     * @param context
     * @param themePkgName
     * @return
     */
    public static Map<String, String> returnToDefaults(Context context, String themePkgName) {
        final Configuration config = context.getResources().getConfiguration();
        final ThemeConfig themeConfig = config != null ? config.themeConfig : null;
        Map<String, String> returnToDefaultComponents = new HashMap<String, String>();
        if (themePkgName != null && themeConfig != null) {
            Map<String, String> defaultComponents = getDefaultComponents(context);
            if (themePkgName.equals(themeConfig.getOverlayPkgName())) {
                returnToDefaultComponents.put(ThemesColumns.MODIFIES_OVERLAYS,
                        defaultComponents.get(ThemesColumns.MODIFIES_OVERLAYS));
            }
            if (themePkgName.equals(
                    themeConfig.getOverlayPkgNameForApp(ThemeConfig.SYSTEMUI_PKG))) {
                returnToDefaultComponents.put(ThemesColumns.MODIFIES_STATUS_BAR,
                        defaultComponents.get(ThemesColumns.MODIFIES_STATUS_BAR));
            }
            if (themePkgName.equals(
                    themeConfig.getOverlayPkgNameForApp(ThemeConfig.SYSTEMUI_NAVBAR_PKG))) {
                returnToDefaultComponents.put(ThemesColumns.MODIFIES_NAVIGATION_BAR,
                        defaultComponents.get(ThemesColumns.MODIFIES_NAVIGATION_BAR));
            }
            if (themePkgName.equals(themeConfig.getIconPackPkgName())) {
                returnToDefaultComponents.put(ThemesColumns.MODIFIES_ICONS,
                        defaultComponents.get(ThemesColumns.MODIFIES_ICONS));
            }
            if (themePkgName.equals(themeConfig.getFontPkgName())) {
                returnToDefaultComponents.put(ThemesColumns.MODIFIES_FONTS,
                        defaultComponents.get(ThemesColumns.MODIFIES_FONTS));
            }
        }

        return returnToDefaultComponents;
    }

    /**
     * Get the boot theme by accessing the settings.db directly instead of using a content resolver.
     * Only use this when the system is starting up and the settings content provider is not ready.
@@ -722,4 +762,6 @@ public class ThemeUtils {

        return config;
    }


}
+2 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi
    public static final String TAG = ThemeConfig.class.getCanonicalName();
    public static final String HOLO_DEFAULT = "holo";

    public static final String SYSTEMUI_PKG = "com.android.systemui";

    /**
     * Special package name for theming the navbar separate from the rest of SystemUI
     */
+12 −0
Original line number Diff line number Diff line
@@ -5809,6 +5809,18 @@ public class PackageManagerService extends IPackageManager.Stub {
    }
    private void uninstallThemeForAllApps(PackageParser.Package opkg) {
        // Since we are uninstalling a theme, we need to check if it has any components applied
        // and switch back to defaults.  Since this method will remove the resource cache for this
        // theme, apps could still be trying to reference themed resources that no longer exist in
        // the given path.  Any other components that are applied from this theme, and not part of
        // the theme config, will be handled after package manager broadcasts its removal.
        Map<String, String> returnToDefaultComponents = ThemeUtils.returnToDefaults(mContext,
                opkg.packageName);
        if (returnToDefaultComponents != null && returnToDefaultComponents.size() > 0) {
            ThemeManager tm = (ThemeManager) mContext.getSystemService(Context.THEME_SERVICE);
            tm.requestThemeChange(returnToDefaultComponents);
        }
        for(String target : opkg.mOverlayTargets) {
            HashMap<String, PackageParser.Package> map = mOverlays.get(target);
            if (map != null) {