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

Commit 2a44dd47 authored by Josh Guilfoyle's avatar Josh Guilfoyle
Browse files

Only add themed apks to the AssetManager when app is themeable.

This change adds the theme APK to the AssetManager only for applications
whose manifests explicitly request isThemeable=true.

CR: Sergey Ten
parent 2c6963d0
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -160,6 +160,10 @@ public final class ActivityThread {
    }

    Resources getTopLevelResources(String appDir) {
        return getTopLevelResources(appDir, false);
    }
    
    Resources getTopLevelResources(String appDir, boolean isThemable) {
        synchronized (mPackages) {
            //Log.w(TAG, "getTopLevelResources: " + appDir);
            WeakReference<Resources> wr = mActiveResources.get(appDir);
@@ -179,7 +183,7 @@ public final class ActivityThread {
                return null;
            }
            Configuration config = getConfiguration();
            if (config != null) {
            if (isThemable && config != null) {
                if (config.customTheme == null) {
                    config.customTheme = CustomTheme.getDefault();
                }
@@ -444,19 +448,26 @@ public final class ActivityThread {
            return mDataDirFile;
        }

        /**
         * @deprecated getResources has additional parameters introduced to
         *             support theming which make less sense to extend to this
         *             method.
         */
        public AssetManager getAssets(ActivityThread mainThread) {
            return getResources(mainThread).getAssets();
        }
        
        public Resources getResources(ActivityThread mainThread, boolean force) {
        public Resources getResources(ActivityThread mainThread, boolean themeable,
                boolean force) {
            if (mResources == null || force == true) {
                mResources = mainThread.getTopLevelResources(mResDir);
                mResources = mainThread.getTopLevelResources(mResDir, themeable);
            }
            return mResources;            
        }
        
        /** @deprecated */
        public Resources getResources(ActivityThread mainThread) {
            return getResources(mainThread, false);
            return getResources(mainThread, false, false);
        }

        public Application makeApplication() {
@@ -3500,7 +3511,7 @@ public final class ActivityThread {
                if (cb instanceof Activity || cb instanceof Application) {
                    Context context = ((ContextWrapper)cb).getBaseContext();
                    if (context instanceof ApplicationContext) {
                        ((ApplicationContext)context).refreshResources();
                        ((ApplicationContext)context).refreshResourcesIfNecessary();
                    }
                }
            }
+10 −6
Original line number Diff line number Diff line
@@ -216,14 +216,17 @@ class ApplicationContext extends Context {
     * Refresh resources object which may have been changed by a theme
     * configuration change.
     */
    /* package */ void refreshResources() {
    /* package */ void refreshResourcesIfNecessary() {
        if (mResources == Resources.getSystem()) {
            /* FIXME: refreshResources called on system resources! */
            return;
        }
        mResources = mPackageInfo.getResources(mMainThread, true);

        if (mPackageInfo.mApplicationInfo.isThemeable) {
            mResources = mPackageInfo.getResources(mMainThread, true, true);
            mTheme = null;
        }
    }

    @Override
    public PackageManager getPackageManager() {
@@ -261,7 +264,7 @@ class ApplicationContext extends Context {
    }

    private int determineDefaultThemeResource() {
        if (getResources() != Resources.getSystem() && mPackageInfo.mApplicationInfo.isThemeable) {
        if (getResources() != Resources.getSystem()) {
            try {
                Configuration config = ActivityManagerNative.getDefault().getConfiguration();
                if (config.customTheme != null) {
@@ -1476,7 +1479,8 @@ class ApplicationContext extends Context {
    final void init(ActivityThread.PackageInfo packageInfo,
            IBinder activityToken, ActivityThread mainThread) {
        mPackageInfo = packageInfo;
        mResources = mPackageInfo.getResources(mainThread);
        mResources = mPackageInfo.getResources(mainThread, 
                packageInfo.mApplicationInfo.isThemeable, false);
        mMainThread = mainThread;
        mContentResolver = new ApplicationContentResolver(this, mainThread);

@@ -2113,7 +2117,7 @@ class ApplicationContext extends Context {
            }
            Resources r = mContext.mMainThread.getTopLevelResources(
                    app.uid == Process.myUid() ? app.sourceDir
                    : app.publicSourceDir);
                    : app.publicSourceDir, app.isThemeable);
            if (r != null) {
                return r;
            }