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

Commit 7c9dd5a5 authored by Andy Mast's avatar Andy Mast
Browse files

Themes: Handle apps using "original-package" tag

Before this patch the themes code assumed the pkgName from PackageInfo was equal to the
manifest value. This is not the case however for upgraded system apps that have gone
through a pkg-name change. For example, Trebuchet was "com.android.launcher3" and now
it is "com.cyanogenmod.trebuchet". If the device had wiped data then PM would use the new
pkg-name, but if the system apps were being upgraded then PM would use the old name which is
now different from the manifest name.

Change-Id: Ie7eb1b4e17899d1055535dc890d4f7a7bca9a98a
parent f4b90e00
Loading
Loading
Loading
Loading
+30 −14
Original line number Diff line number Diff line
@@ -418,19 +418,31 @@ public class ResourcesManager {
        // from the res tables. The 0th base package name will be the android group. The
        // 1st base package name will be the app group if one is attached. Check if it is there
        // first or else the system will crash!
        String packageName = null;
        String basePackageName = null;
        String resourcePackageName = null;
        int count = assets.getBasePackageCount();
        if (count > 1) {
            packageName  = assets.getBasePackageName(1);
            basePackageName  = assets.getBasePackageName(1);
            resourcePackageName = assets.getBaseResourcePackageName(1);
        } else if (count == 1) {
            packageName  = assets.getBasePackageName(0);
            basePackageName  = assets.getBasePackageName(0);
        } else {
            return false;
        }

        try {
            piTheme = getPackageManager().getPackageInfo(theme.getThemePackageNameForApp(packageName), 0, UserHandle.myUserId());
            piTarget = getPackageManager().getPackageInfo(packageName, 0, UserHandle.myUserId());
            piTheme = getPackageManager().getPackageInfo(
                    theme.getThemePackageNameForApp(basePackageName), 0, UserHandle.myUserId());
            piTarget = getPackageManager().getPackageInfo(
                    basePackageName, 0, UserHandle.myUserId());

            // Handle special case where a system app (ex trebuchet) may have had its pkg name
            // renamed during an upgrade. basePackageName would be the manifest value which will
            // fail on getPackageInfo(). resource pkg is assumed to have the original name
            if (piTarget == null && resourcePackageName != null) {
                piTarget = getPackageManager().getPackageInfo(resourcePackageName,
                        0, UserHandle.myUserId());
            }
            piAndroid = getPackageManager().getPackageInfo("android", 0, UserHandle.myUserId());
        } catch (RemoteException e) {
        }
@@ -442,30 +454,34 @@ public class ResourcesManager {
            return false;
        }

        String themePackageName = piTheme.applicationInfo.packageName;
        String themePackageName = basePackageName;
        String themePath = piTheme.applicationInfo.publicSourceDir;

        if (!piTarget.isThemeApk && piTheme.mOverlayTargets.contains(packageName)) {
        if (!piTarget.isThemeApk && piTheme.mOverlayTargets.contains(basePackageName)) {
            String targetPackagePath = piTarget.applicationInfo.sourceDir;
            String prefixPath = piTheme.isLegacyThemeApk ? "" : ThemeUtils.getOverlayPathToTarget(piTarget.packageName);
            String resCachePath = ThemeUtils.getResDir(piTarget.packageName, piTheme);
            String prefixPath = piTheme.isLegacyThemeApk ?
                    "" : ThemeUtils.getOverlayPathToTarget(basePackageName);

            String resCachePath = ThemeUtils.getResDir(basePackageName, piTheme);
            String resTablePath = piTheme.isLegacyThemeApk ? "" : resCachePath + "/resources.arsc";
            String resApkPath = piTheme.isLegacyThemeApk ? "" : resCachePath + "/resources.apk";
            int cookie = assets.addOverlayPath(themePath, resTablePath, resApkPath, targetPackagePath, prefixPath);
            int cookie = assets.addOverlayPath(themePath, resTablePath, resApkPath,
                    targetPackagePath, prefixPath);

            if (cookie != 0) {
                assets.setThemePackageName(themePackageName);
                assets.setThemePackageName(basePackageName);
                assets.addThemeCookie(cookie);
            }
        }

        if (!piTarget.isThemeApk && piTheme.mOverlayTargets.contains("android")) {
            String resCachePath= ThemeUtils.getResDir(piAndroid.packageName, piTheme);
            String prefixPath = piTheme.isLegacyThemeApk ? "" : ThemeUtils.getOverlayPathToTarget(piAndroid.packageName);
            String prefixPath = piTheme.isLegacyThemeApk ?
                    "" : ThemeUtils.getOverlayPathToTarget(piAndroid.packageName);
            String targetPackagePath = piAndroid.applicationInfo.publicSourceDir;
            String resTablePath = piTheme.isLegacyThemeApk ? "" : resCachePath + "/resources.arsc";
            String resApkPath = piTheme.isLegacyThemeApk ? "" : resCachePath + "/resources.apk";
            int cookie = assets.addOverlayPath(themePath, resTablePath, resApkPath, targetPackagePath, prefixPath);
            int cookie = assets.addOverlayPath(themePath, resTablePath,
                    resApkPath, targetPackagePath, prefixPath);
            if (cookie != 0) {
                assets.setThemePackageName(themePackageName);
                assets.addThemeCookie(cookie);
+10 −1
Original line number Diff line number Diff line
@@ -5458,7 +5458,16 @@ public class PackageManagerService extends IPackageManager.Stub {
            return;
        }
        compileResourcesIfNeeded(targetPkg.packageName, themePkg);
        // Always use the manifest's pkgName when compiling resources
        // the member value of "packageName" is dependent on whether this was a clean install
        // or an upgrade w/  If the app is an upgrade then the original package name is used.
        // because libandroidfw uses the manifests's pkgName during idmap creation we must
        // be consistent here and use the same name, otherwise idmap will look in the wrong place
        // for the resource table.
        String pkgName = targetPkg.mRealPackage != null ?
                targetPkg.mRealPackage : targetPkg.packageName;
        compileResourcesIfNeeded(pkgName, themePkg);
        generateIdmap(targetPkg.packageName, themePkg);
    }