Search in sources :

Example 1 with IAssetRedirectionManager

use of com.android.internal.app.IAssetRedirectionManager in project android_frameworks_base by ParanoidAndroid.

the class ActivityThread method attachThemeAssets.

/**
     * Attach the necessary theme asset paths and meta information to convert an
     * AssetManager to being globally "theme-aware".
     *
     * @param assets
     * @param theme
     * @return true if the AssetManager is now theme-aware; false otherwise.
     *         This can fail, for example, if the theme package has been been
     *         removed and the theme manager has yet to revert formally back to
     *         the framework default.
     */
private boolean attachThemeAssets(AssetManager assets, CustomTheme theme) {
    IAssetRedirectionManager rm = getAssetRedirectionManager();
    if (rm == null) {
        return false;
    }
    PackageInfo pi = null;
    try {
        pi = getPackageManager().getPackageInfo(theme.getThemePackageName(), 0, UserHandle.myUserId());
    } catch (RemoteException e) {
    }
    if (pi != null && pi.applicationInfo != null && pi.themeInfos != null) {
        String themeResDir = pi.applicationInfo.publicSourceDir;
        int cookie = assets.attachThemePath(themeResDir);
        if (cookie != 0) {
            String themePackageName = theme.getThemePackageName();
            String themeId = theme.getThemeId();
            int N = assets.getBasePackageCount();
            for (int i = 0; i < N; i++) {
                String packageName = assets.getBasePackageName(i);
                int packageId = assets.getBasePackageId(i);
                /*
                     * For now, we only consider redirections coming from the
                     * framework or regular android packages. This excludes
                     * themes and other specialty APKs we are not aware of.
                     */
                if (packageId != 0x01 && packageId != 0x7f) {
                    continue;
                }
                try {
                    PackageRedirectionMap map = rm.getPackageRedirectionMap(themePackageName, themeId, packageName);
                    if (map != null) {
                        assets.addRedirections(map);
                    }
                } catch (RemoteException e) {
                    Log.e(TAG, "Failure accessing package redirection map, removing theme support.");
                    assets.detachThemePath(themePackageName, cookie);
                    return false;
                }
            }
            assets.setThemePackageName(theme.getThemePackageName());
            assets.setThemeCookie(cookie);
            return true;
        } else {
            Log.e(TAG, "Unable to attach theme assets at " + themeResDir);
        }
    }
    return false;
}
Also used : PackageInfo(android.content.pm.PackageInfo) PackageRedirectionMap(android.content.res.PackageRedirectionMap) IAssetRedirectionManager(com.android.internal.app.IAssetRedirectionManager) RemoteException(android.os.RemoteException)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1 PackageRedirectionMap (android.content.res.PackageRedirectionMap)1 RemoteException (android.os.RemoteException)1 IAssetRedirectionManager (com.android.internal.app.IAssetRedirectionManager)1