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

Commit 6623a410 authored by Andy Mast's avatar Andy Mast
Browse files

Fix ResourceNotFoundException when updating applied theme

If the user has a theme applied and there is an update to that theme,
then the themed apps will crash. This is because the theme's APK path changes,
but the apps do not update their resources. Apps were not updating their resources
because updateConfiguration() determined that the config (which only has pkgName) hasn't changed.

The problem is fixed by first applying the default theme config and then re-applying the
updated theme.

SystemUI was crashing with a NPE while verifying this fix, so a NP check was added to SystemUI as well.

Change-Id: I00e32fc1535b4d279fcb37c35f868501ecc1dd19
parent f3866d67
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -108,9 +108,14 @@ public class UserTile extends QuickSettingsTile {
    void updateQuickSettings() {
        ImageView iv = (ImageView) mTile.findViewById(R.id.user_imageview);
        TextView tv = (TextView) mTile.findViewById(R.id.user_textview);
        if (tv != null) {
            tv.setText(mLabel);
        }

        if (iv != null) {
            iv.setImageDrawable(userAvatar);
        }
    }

    private void queryForUserInformation() {
        Context currentUserContext = null;
+26 −8
Original line number Diff line number Diff line
@@ -553,8 +553,25 @@ public class ThemeService extends IThemeService.Stub {
            final long token = Binder.clearCallingIdentity();
            try {
                Configuration config = am.getConfiguration();
                ThemeConfig.Builder themeBuilder = createBuilderFrom(config, components);
                config.themeConfig = themeBuilder.build();
                ThemeConfig.Builder themeBuilder = createBuilderFrom(config, components, mPkgName);
                ThemeConfig newConfig = themeBuilder.build();

                // If this is a theme upgrade then new config equals existing config. The result
                // is that the config is not considered changed and therefore not propagated,
                // which can be problem if the APK path changes (ex theme-1.apk -> theme-2.apk)
                if (newConfig.equals(config.themeConfig)) {
                    // We can't just use null for the themeConfig, it won't be registered as
                    // a changed config value because of the way equals in config had to be written.
                    final String defaultThemePkg =
                            Settings.Secure.getString(mContext.getContentResolver(),
                            Settings.Secure.DEFAULT_THEME_PACKAGE);
                    ThemeConfig.Builder defaultBuilder =
                            createBuilderFrom(config, components, defaultThemePkg);
                    config.themeConfig = defaultBuilder.build();
                    am.updateConfiguration(config);
                }

                config.themeConfig = newConfig;
                am.updateConfiguration(config);
            } catch (RemoteException e) {
                return false;
@@ -565,27 +582,28 @@ public class ThemeService extends IThemeService.Stub {
        return true;
    }

    private ThemeConfig.Builder createBuilderFrom(Configuration config, List<String> components) {
    private static ThemeConfig.Builder createBuilderFrom(Configuration config,
                                                         List<String> components, String pkgName) {
        ThemeConfig.Builder builder = new ThemeConfig.Builder(config.themeConfig);

        if (components.contains(ThemesContract.ThemesColumns.MODIFIES_ICONS)) {
            builder.defaultIcon(mPkgName);
            builder.defaultIcon(pkgName);
        }

        if (components.contains(ThemesContract.ThemesColumns.MODIFIES_OVERLAYS)) {
            builder.defaultOverlay(mPkgName);
            builder.defaultOverlay(pkgName);
        }

        if (components.contains(ThemesContract.ThemesColumns.MODIFIES_FONTS)) {
            builder.defaultFont(mPkgName);
            builder.defaultFont(pkgName);
        }

        if (components.contains(ThemesContract.ThemesColumns.MODIFIES_STATUS_BAR)) {
            builder.overlay("com.android.systemui", mPkgName);
            builder.overlay("com.android.systemui", pkgName);
        }

        if (components.contains(ThemesContract.ThemesColumns.MODIFIES_NAVIGATION_BAR)) {
            builder.overlay(ThemeConfig.SYSTEMUI_NAVBAR_PKG, mPkgName);
            builder.overlay(ThemeConfig.SYSTEMUI_NAVBAR_PKG, pkgName);
        }

        return builder;