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

Commit 0b2765ee authored by d34d's avatar d34d Committed by Gerrit Code Review
Browse files

Themes: Add theme change timestamp to ThemeConfig

Rather than perform two configuration changes when an applied theme
is upadted, this patch adds an additional member to the ThemeConfig
which tracks the time at which the theme is applied.  This allows us
to only perform one configuration change since the new config should
differ from the previous one if the time stamp changes.

The case where this is needed is when a currently applied theme is
updated and needs to be re-applied so that apps pick up the new
resources.

Change-Id: I0036fd6465428bb8e972e294a99839e55203cfaf
parent 1a3dd05d
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -60,6 +60,9 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi
    // Maps pkgname to theme (ex com.angry.birds -> red theme)
    protected final Map<String, AppTheme> mThemes = new HashMap<String, AppTheme>();

    // Theme change timestamp
    private long mThemeChangeTimestamp;

    public ThemeConfig(Map<String, AppTheme> appThemes) {
        mThemes.putAll(appThemes);
    }
@@ -127,7 +130,8 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi
            Map<String, AppTheme> newThemes = (o.mThemes == null) ?
                    new HashMap<String, AppTheme>() : o.mThemes;

            return (currThemes.equals(newThemes));
            return (currThemes.equals(newThemes) &&
                    mThemeChangeTimestamp == o.mThemeChangeTimestamp);
        }
        return false;
    }
@@ -200,13 +204,16 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi
    public void writeToParcel(Parcel dest, int flags) {
        String json = JsonSerializer.toJson(this);
        dest.writeString(json);
        dest.writeLong(mThemeChangeTimestamp);
    }

    public static final Parcelable.Creator<ThemeConfig> CREATOR =
            new Parcelable.Creator<ThemeConfig>() {
        public ThemeConfig createFromParcel(Parcel source) {
            String json = source.readString();
            return JsonSerializer.fromJson(json);
            ThemeConfig themeConfig = JsonSerializer.fromJson(json);
            themeConfig.mThemeChangeTimestamp = source.readLong();
            return themeConfig;
        }

        public ThemeConfig[] newArray(int size) {
@@ -324,6 +331,7 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi
        private HashMap<String, String> mOverlays = new HashMap<String, String>();
        private HashMap<String, String> mIcons = new HashMap<String, String>();
        private HashMap<String, String> mFonts = new HashMap<String, String>();
        private long mThemeChangeTimestamp;

        public Builder() {}

@@ -335,6 +343,7 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi
                mIcons.put(key, appTheme.getIconPackPkgName());
                mOverlays.put(key, appTheme.getOverlayPkgName());
            }
            mThemeChangeTimestamp = theme.mThemeChangeTimestamp;
        }

        /**
@@ -395,6 +404,11 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi
            return this;
        }

        public Builder setThemeChangeTimestamp(long timestamp) {
            mThemeChangeTimestamp = timestamp;
            return this;
        }

        public ThemeConfig build() {
            HashSet<String> appPkgSet = new HashSet<String>();
            appPkgSet.addAll(mOverlays.keySet());
@@ -410,7 +424,9 @@ public class ThemeConfig implements Cloneable, Parcelable, Comparable<ThemeConfi
                AppTheme appTheme = new AppTheme(overlay, icon, font);
                appThemes.put(appPkgName, appTheme);
            }
            return new ThemeConfig(appThemes);
            ThemeConfig themeConfig = new ThemeConfig(appThemes);
            themeConfig.mThemeChangeTimestamp = mThemeChangeTimestamp;
            return themeConfig;
        }
    }

+2 −15
Original line number Diff line number Diff line
@@ -724,21 +724,6 @@ public class ThemeService extends IThemeService.Stub {
                ThemeConfig.Builder themeBuilder = createBuilderFrom(config, components, null);
                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) {
@@ -779,6 +764,8 @@ public class ThemeService extends IThemeService.Stub {
                    componentMap.get(ThemesColumns.MODIFIES_NAVIGATION_BAR) : pkgName);
        }

        builder.setThemeChangeTimestamp(System.currentTimeMillis());

        return builder;
    }