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

Commit 1a665a30 authored by d34d's avatar d34d Committed by Clark Scheff
Browse files

Themes: Don't uninstall theme when processing an overlay fails

Themes can contain overlays for several packages so we should not
uninstall a theme when an overlay fails to be processed.  Simply
log the failure, remove the target from the themes overlay list and
move on to the next.

Change-Id: If701ddbf6e8fc648fa2d715fe8e25cdc5859e05d
parent 9909e283
Loading
Loading
Loading
Loading
+22 −28
Original line number Diff line number Diff line
@@ -7837,8 +7837,9 @@ public class PackageManagerService extends IPackageManager.Stub {
                            // Do not stop a pkg installation just because of one bad theme
                            // Also we don't break here because we should try to compile other
                            // themes
                            Log.e(TAG, "Unable to compile " + themePkg.packageName
                            Slog.w(TAG, "Unable to compile " + themePkg.packageName
                                    + " for target " + pkg.packageName, e);
                            themePkg.mOverlayTargets.remove(pkg.packageName);
                        }
                    }
                }
@@ -7851,9 +7852,10 @@ public class PackageManagerService extends IPackageManager.Stub {
            }
            // Generate Idmaps and res tables if pkg is a theme
            for(String target : pkg.mOverlayTargets) {
            Iterator<String> iterator = pkg.mOverlayTargets.iterator();
            while(iterator.hasNext()) {
                String target = iterator.next();
                Exception failedException = null;
                int failReason = 0;
                insertIntoOverlayMap(target, pkg);
                if (isBootScan && mBootThemeConfig != null &&
@@ -7864,21 +7866,17 @@ public class PackageManagerService extends IPackageManager.Stub {
                        compileResourcesAndIdmapIfNeeded(mPackages.get(target), pkg);
                    } catch (IdmapException e) {
                        failedException = e;
                        failReason = PackageManager.INSTALL_FAILED_THEME_IDMAP_ERROR;
                    } catch (AaptException e) {
                        failedException = e;
                        failReason = PackageManager.INSTALL_FAILED_THEME_AAPT_ERROR;
                    } catch (Exception e) {
                        failedException = e;
                        failReason = PackageManager.INSTALL_FAILED_THEME_UNKNOWN_ERROR;
                    }
                    if (failedException != null) {
                        Log.w(TAG, "Unable to process theme " + pkgName, failedException);
                        uninstallThemeForAllApps(pkg);
                        deletePackageLI(pkg.packageName, null, true, null, null, 0, null, false);
                        throw new PackageManagerException(failReason,
                                "Unable to process theme " + pkgName, failedException);
                        Slog.w(TAG, "Unable to process theme " + pkgName + " for " + target,
                                failedException);
                        // remove target from mOverlayTargets
                        iterator.remove();
                    }
                }
            }
@@ -8166,9 +8164,7 @@ public class PackageManagerService extends IPackageManager.Stub {
    }
    private void compileResourcesAndIdmapIfNeeded(PackageParser.Package targetPkg,
                                               PackageParser.Package themePkg)
            throws IdmapException, AaptException, IOException, Exception
    {
            PackageParser.Package themePkg) throws IdmapException, AaptException, IOException {
        if (!shouldCreateIdmap(targetPkg, themePkg)) {
            return;
        }
@@ -8186,7 +8182,7 @@ public class PackageManagerService extends IPackageManager.Stub {
    }
    private void compileResourcesIfNeeded(String target, PackageParser.Package pkg)
        throws AaptException, IOException, Exception
        throws AaptException, IOException
    {
        ThemeUtils.createCacheDirIfNotExists();
@@ -8201,7 +8197,8 @@ public class PackageManagerService extends IPackageManager.Stub {
        compileResources(target, pkg);
    }
    private void compileResources(String target, PackageParser.Package pkg) throws Exception {
    private void compileResources(String target, PackageParser.Package pkg)
            throws IOException, AaptException {
        if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Compile resource table for " + pkg.packageName);
        //TODO: cleanup this hack. Modify aapt? Aapt uses the manifests package name
        //when creating the resource table. We care about the resource table's name because
@@ -8263,7 +8260,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
    }
    private boolean hasCommonResources(PackageParser.Package pkg) throws Exception {
    private boolean hasCommonResources(PackageParser.Package pkg) throws IOException {
        boolean ret = false;
        // check if assets/overlays/common exists in this theme
        AssetManager assets = new AssetManager();
@@ -8275,7 +8272,7 @@ public class PackageManagerService extends IPackageManager.Stub {
    }
    private void compileResourcesWithAapt(String target, PackageParser.Package pkg)
            throws Exception {
            throws IOException, AaptException {
        String internalPath = APK_PATH_TO_OVERLAY + target + File.separator;
        String resPath = ThemeUtils.getTargetCacheDir(target, pkg);
        final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid);
@@ -8343,7 +8340,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        f.delete();
    }
    private void createTempManifest(String pkgName) throws Exception {
    private void createTempManifest(String pkgName) throws IOException {
        StringBuilder manifest = new StringBuilder();
        manifest.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        manifest.append("<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"");
@@ -17568,29 +17565,26 @@ public class PackageManagerService extends IPackageManager.Stub {
            }
        }
        int errorCode = 0;
        // Generate Idmaps and res tables if pkg is a theme
        for(String target : pkg.mOverlayTargets) {
        Iterator<String> iterator = pkg.mOverlayTargets.iterator();
        while(iterator.hasNext()) {
            String target = iterator.next();
            Exception failedException = null;
            try {
                compileResourcesAndIdmapIfNeeded(mPackages.get(target), pkg);
            } catch (IdmapException e) {
                failedException = e;
                errorCode = PackageManager.INSTALL_FAILED_THEME_IDMAP_ERROR;
            } catch (AaptException e) {
                failedException = e;
                errorCode = PackageManager.INSTALL_FAILED_THEME_AAPT_ERROR;
            } catch (Exception e) {
                failedException = e;
                errorCode = PackageManager.INSTALL_FAILED_THEME_UNKNOWN_ERROR;
            }
            if (failedException != null) {
                Log.e(TAG, "Unable to process theme, uninstalling " + pkg.packageName,
                Slog.w(TAG, "Unable to process theme " + pkg.packageName + " for " + target,
                      failedException);
                uninstallThemeForAllApps(pkg);
                deletePackageX(themePkgName, getCallingUid(), PackageManager.DELETE_ALL_USERS);
                return errorCode;
                // remove target from mOverlayTargets
                iterator.remove();
            }
        }