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

Commit 4d807141 authored by Clark Scheff's avatar Clark Scheff Committed by Gerrit Code Review
Browse files

Merge "Themes: Get resources with an explicit theme attached." into cm-11.0

parents 50638905 d00e6f9f
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1545,6 +1545,15 @@ public final class ActivityThread {
                overrideConfiguration, pkgInfo.getCompatibilityInfo(), null, context);
    }

    /**
     * Creates the top level resources for the given package.
     */
    Resources getTopLevelThemedResources(String resDir, int displayId, LoadedApk pkgInfo,
                                         String pkgName, String themePkgName) {
        return mResourcesManager.getTopLevelThemedResources(resDir, displayId, pkgName,
                themePkgName, pkgInfo.getCompatibilityInfo(), null);
    }

    final Handler getHandler() {
        return mH;
    }
+23 −0
Original line number Diff line number Diff line
@@ -788,6 +788,29 @@ final class ApplicationPackageManager extends PackageManager {
            getApplicationInfo(appPackageName, 0));
    }

    /** @hide */
    @Override public Resources getThemedResourcesForApplication(
            ApplicationInfo app, String themePkgName) throws NameNotFoundException {
        if (app.packageName.equals("system")) {
            return mContext.mMainThread.getSystemContext().getResources();
        }

        Resources r = mContext.mMainThread.getTopLevelThemedResources(
                app.uid == Process.myUid() ? app.sourceDir : app.publicSourceDir,
                Display.DEFAULT_DISPLAY, mContext.mPackageInfo, app.packageName, themePkgName);
        if (r != null) {
            return r;
        }
        throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
    }

    /** @hide */
    @Override public Resources getThemedResourcesForApplication(
            String appPackageName, String themePkgName) throws NameNotFoundException {
        return getThemedResourcesForApplication(
                getApplicationInfo(appPackageName, 0), themePkgName);
    }

    /** @hide */
    @Override
    public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
+46 −0
Original line number Diff line number Diff line
@@ -259,6 +259,52 @@ public class ResourcesManager {
        }
    }

    /**
     * Creates the top level Resources for applications with the given compatibility info.
     *
     * @param resDir the resource directory.
     * @param compatInfo the compability info. Must not be null.
     * @param token the application token for determining stack bounds.
     *
     * @hide
     */
    public Resources getTopLevelThemedResources(String resDir, int displayId,
                                                String packageName,
                                                String themePackageName,
                                                CompatibilityInfo compatInfo, IBinder token) {
        Resources r;

        AssetManager assets = new AssetManager();
        assets.setAppName(packageName);
        assets.setThemeSupport(true);
        if (assets.addAssetPath(resDir) == 0) {
            return null;
        }

        //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
        DisplayMetrics dm = getDisplayMetricsLocked(displayId);
        Configuration config;
        boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
        if (!isDefaultDisplay) {
            config = new Configuration(getConfiguration());
            applyNonDefaultDisplayMetricsToConfigurationLocked(dm, config);
        } else {
            config = getConfiguration();
        }

        /* Attach theme information to the resulting AssetManager when appropriate. */
        CustomTheme customTheme =
                new CustomTheme(themePackageName, themePackageName, themePackageName);
        attachThemeAssets(assets, customTheme);
        attachCommonAssets(assets, customTheme);
        attachIconAssets(assets, customTheme);

        r = new Resources(assets, dm, config, compatInfo, token);
        setActivityIcons(r);

        return r;
    }

    /**
     * Creates a map between an activity & app's icon ids to its component info. This map
     * is then stored in the resource object.
+10 −0
Original line number Diff line number Diff line
@@ -2631,6 +2631,16 @@ public abstract class PackageManager {
    public abstract Resources getResourcesForApplication(String appPackageName)
            throws NameNotFoundException;

    /** @hide */
    public abstract Resources getThemedResourcesForApplication(ApplicationInfo app,
                                                               String themePkgName)
            throws NameNotFoundException;

    /** @hide */
    public abstract Resources getThemedResourcesForApplication(String appPackageName,
                                                               String themePkgName)
            throws NameNotFoundException;

    /** @hide */
    public abstract Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
            throws NameNotFoundException;
+12 −0
Original line number Diff line number Diff line
@@ -400,6 +400,18 @@ public class MockPackageManager extends PackageManager {
        throw new UnsupportedOperationException();
    }

    @Override
    public Resources getThemedResourcesForApplication(ApplicationInfo app, String themePkgName)
    throws NameNotFoundException {
        return null;
    }

    @Override
    public Resources getThemedResourcesForApplication(String appPackageName, String themePkgName)
    throws NameNotFoundException {
        return null;
    }

    /** @hide */
    @Override
    public Resources getResourcesForApplicationAsUser(String appPackageName, int userId) {