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

Commit b2ded53e authored by Josh Guilfoyle's avatar Josh Guilfoyle
Browse files

Fixed ESPRESSO-257, ESPRESSO-258.

ESPRESSO-257 was fixed by a trivial change to check the original theme
package name for an empty string (in addition to null).

ESPRESSO-258 required addition of new AssetManager values to track
whether the AssetManager should have themes attached, persisting this
value across configuration changes.  We should once again respect is the
isThemeable flag by keeping themed assets out of the AssetManager of
apps that don't ask for it.

CR: Ed Carrigan
parent b84f65cc
Loading
Loading
Loading
Loading
+22 −19
Original line number Diff line number Diff line
@@ -173,6 +173,7 @@ public final class ActivityThread {
            //}

            AssetManager assets = new AssetManager();
            assets.setThemeSupport(isThemable);
            if (assets.addAssetPath(appDir) == 0) {
                return null;
            }
@@ -3467,7 +3468,6 @@ public final class ActivityThread {
                = new ArrayList<ComponentCallbacks>();
        
        int diff;
        String originalThemePackageName = (mConfiguration == null)? null : mConfiguration.customTheme.getThemePackageName();
        
        synchronized(mPackages) {
            if (mConfiguration == null) {
@@ -3493,27 +3493,29 @@ public final class ActivityThread {
                while (it.hasNext()) {
                    WeakReference<Resources> v = it.next();
                    Resources r = v.get();
                    /* If the theme has changed, remove the cached Resources
                     * object anyway.  Similarly, each Application will need
                     * to refresh its internal resources object. */
                    if (r != null) {
                        boolean themeChanged = (diff & ActivityInfo.CONFIG_THEME_RESOURCE) != 0;
                        if (themeChanged) {
                            AssetManager am = r.getAssets();
                            if (originalThemePackageName != null) {
                            /*
                             * Dynamically modify the AssetManager object to
                             * replace the old asset path with the new one. This
                             * is made possibly by native layer changes made by
                             * T-Mobile.
                             */
                            if (am.hasThemeSupport()) {
                                String oldThemePackage = am.getThemePackageName();
                                if (!TextUtils.isEmpty(oldThemePackage)) {
                                    am.setThemePackageName(null);
//                                Log.i(TAG, "============ Dump resources BEFORE removeAssetPath");
//                                am.dumpResources();
                                am.removeAssetPath(originalThemePackageName, getPackageResDir(originalThemePackageName));
//                                Log.i(TAG, "============ Dump resources AFTER removeAssetPath");
//                                am.dumpResources();
                                    am.removeAssetPath(oldThemePackage,
                                            getPackageResDir(oldThemePackage));
                                }
                            String resDir = getPackageResDir(config.customTheme.getThemePackageName());
                                String newThemePackage = config.customTheme.getThemePackageName();
                                String resDir = getPackageResDir(newThemePackage);
                                if (resDir != null) {
                                am.setThemePackageName(config.customTheme.getThemePackageName());
                                    am.setThemePackageName(newThemePackage);
                                    am.updateResourcesWithAssetPath(resDir);
//                                Log.i(TAG, "============ Dump resources AFTER addAssetPath");
//                                am.dumpResources();
                                }
                            }
                        }
                        r.updateConfiguration(config, dm);
@@ -3535,7 +3537,6 @@ public final class ActivityThread {
        final int N = callbacks.size();
        for (int i=0; i<N; i++) {
            ComponentCallbacks cb = callbacks.get(i);
            performConfigurationChanged(cb, config);

            // We removed the old resources object from the mActiveResources
            // cache, now we need to trigger an update for each application.
@@ -3547,6 +3548,8 @@ public final class ActivityThread {
                    }
                }
            }

            performConfigurationChanged(cb, config);
        }
    }

+20 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public final class AssetManager {
    private String mAssetDir;
    private String mAppName;

    private boolean mThemeSupport;
    private String mThemePackageName;

    /**
@@ -617,6 +618,25 @@ public final class AssetManager {
     */
    public native final void dumpResources();

    /**
     * Sets a flag indicating that this AssetManager should have themes
     * attached, according to the initial request to create it by the
     * ApplicationContext.
     *
     * {@hide}
     */
    public final void setThemeSupport(boolean themeSupport) {
        mThemeSupport = themeSupport;
    }

    /**
     * Should this AssetManager have themes attached, according to the initial
     * request to create it by the ApplicationContext?
     */
    public final boolean hasThemeSupport() {
        return mThemeSupport;
    }

    /**
     * Get package name of current theme (may return null).
     * {@hide}
+1 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ public class ContextThemeWrapper extends ContextWrapper {
            AssetManager assets = new AssetManager();
            assets.addAssetPath(getPackageResDir(getPackageName()));
            assets.addAssetPath(getPackageResDir(themePackage));
            assets.setThemeSupport(true);
            assets.setThemePackageName(themePackage);

            DisplayMetrics metrics = new DisplayMetrics();