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

Commit 9788452a authored by d34d's avatar d34d Committed by Gerrit Code Review
Browse files

Themes: Fail theme install if common resources fail

If a theme uses common resources and those fail to build with aapt,
fail the entire theme install.  Since overalys can reference this
common resource package, we should fail the theme install if those
resources could not be compiled, otherwise other overlays will also
fail to install when referencing @*common

Change-Id: If79bfb6819e4ae2175b9348e9a164544ff24be80
TICKET: OPO-578
parent 26cdefbb
Loading
Loading
Loading
Loading
+41 −11
Original line number Diff line number Diff line
@@ -7888,6 +7888,17 @@ public class PackageManagerService extends IPackageManager.Stub {
                    }
                    if (failedException != null) {
                        if (failedException instanceof AaptException &&
                                ((AaptException) failedException).isCommon) {
                            Slog.e(TAG, "Unable to process common resources for " + pkgName +
                                    ", uninstalling theme.", failedException);
                            uninstallThemeForAllApps(pkg);
                            deletePackageLI(pkg.packageName, null, true, null, null, 0, null,
                                    false);
                            throw new PackageManagerException(
                                    PackageManager.INSTALL_FAILED_THEME_AAPT_ERROR,
                                    "Unable to process theme " + pkgName, failedException);
                        } else {
                            Slog.w(TAG, "Unable to process theme " + pkgName + " for " + target,
                                    failedException);
                            // remove target from mOverlayTargets
@@ -7895,6 +7906,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                        }
                    }
                }
            }
            //Icon Packs need aapt too
            if (isBootScan && (mBootThemeConfig != null &&
@@ -8264,8 +8276,15 @@ public class PackageManagerService extends IPackageManager.Stub {
    }
    public class AaptException extends Exception {
        boolean isCommon;
        public AaptException(String message) {
            this(message, false);
        }
        public AaptException(String message, boolean isCommon) {
            super(message);
            this.isCommon = isCommon;
        }
    }
@@ -8291,16 +8310,17 @@ public class PackageManagerService extends IPackageManager.Stub {
        String internalPath = APK_PATH_TO_OVERLAY + target + File.separator;
        String resPath = ThemeUtils.getTargetCacheDir(target, pkg);
        final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid);
        final boolean isCommonResources = COMMON_OVERLAY.equals(target);
        int pkgId;
        if ("android".equals(target)) {
            pkgId = Resources.THEME_FRAMEWORK_PKG_ID;
        } else if (COMMON_OVERLAY.equals(target)) {
        } else if (isCommonResources) {
            pkgId = Resources.THEME_COMMON_PKG_ID;
        } else {
            pkgId = Resources.THEME_APP_PKG_ID;
        }
        boolean hasCommonResources = (hasCommonResources(pkg) && !COMMON_OVERLAY.equals(target));
        boolean hasCommonResources = (hasCommonResources(pkg) && !isCommonResources);
        PackageParser.Package targetPkg = mPackages.get(target);
        String appPath = targetPkg != null ? targetPkg.baseCodePath :
                Environment.getRootDirectory() + "/framework/framework-res.apk";
@@ -8310,7 +8330,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                appPath,
                hasCommonResources ? ThemeUtils.getTargetCacheDir(COMMON_OVERLAY, pkg)
                        + File.separator + "resources.apk" : "") != 0) {
            throw new AaptException("Failed to run aapt");
            throw new AaptException("Failed to run aapt", isCommonResources);
        }
    }
@@ -17782,12 +17802,22 @@ public class PackageManagerService extends IPackageManager.Stub {
            }
            if (failedException != null) {
                if (failedException instanceof AaptException &&
                        ((AaptException) failedException).isCommon) {
                    Slog.e(TAG, "Unable to process common resources for " + pkg.packageName +
                            ", uninstalling theme.", failedException);
                    uninstallThemeForAllApps(pkg);
                    deletePackageX(pkg.packageName, getCallingUid(),
                            PackageManager.DELETE_ALL_USERS);
                    return PackageManager.INSTALL_FAILED_THEME_AAPT_ERROR;
                } else {
                    Slog.w(TAG, "Unable to process theme " + pkg.packageName + " for " + target,
                            failedException);
                    // remove target from mOverlayTargets
                    iterator.remove();
                }
            }
        }
        return 0;
    }