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

Commit 1dcbc5de authored by Ricardo Cerqueira's avatar Ricardo Cerqueira
Browse files

PackageManager: Prevent themes from going into ASEC containers

Themes on ASEC cause all kinds of random timing/racey issues at boot
time, and more kinds of racey concurrency issues at uninstall/upgrade
time. Stop them from getting into containers at all.

Change-Id: If08e90c51137b22239831a4eca17ea00d5d87d93
parent 6530cb8c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ public class PackageInfoLite implements Parcelable {
     */
    public int recommendedInstallLocation;
    public int installLocation;
    public boolean isTheme;

    public VerifierInfo[] verifiers;

@@ -66,6 +67,7 @@ public class PackageInfoLite implements Parcelable {
        dest.writeInt(versionCode);
        dest.writeInt(recommendedInstallLocation);
        dest.writeInt(installLocation);
        dest.writeInt(isTheme ? 1 : 0);

        if (verifiers == null || verifiers.length == 0) {
            dest.writeInt(0);
@@ -91,6 +93,7 @@ public class PackageInfoLite implements Parcelable {
        versionCode = source.readInt();
        recommendedInstallLocation = source.readInt();
        installLocation = source.readInt();
        isTheme = source.readInt() == 1 ? true : false;

        final int verifiersLength = source.readInt();
        if (verifiersLength == 0) {
+12 −2
Original line number Diff line number Diff line
@@ -205,12 +205,14 @@ public class PackageParser {
        public final int versionCode;
        public final int installLocation;
        public final VerifierInfo[] verifiers;
        public final boolean isTheme;

        public PackageLite(String packageName, int versionCode,
                int installLocation, List<VerifierInfo> verifiers) {
                int installLocation, List<VerifierInfo> verifiers, boolean isTheme) {
            this.packageName = packageName;
            this.versionCode = versionCode;
            this.installLocation = installLocation;
            this.isTheme = isTheme;
            this.verifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
        }
    }
@@ -905,6 +907,7 @@ public class PackageParser {
        int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
        int versionCode = 0;
        int numFound = 0;

        for (int i = 0; i < attrs.getAttributeCount(); i++) {
            String attr = attrs.getAttributeName(i);
            if (attr.equals("installLocation")) {
@@ -924,6 +927,8 @@ public class PackageParser {
        final int searchDepth = parser.getDepth() + 1;

        final List<VerifierInfo> verifiers = new ArrayList<VerifierInfo>();
        boolean isTheme = false;

        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                && (type != XmlPullParser.END_TAG || parser.getDepth() >= searchDepth)) {
            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
@@ -936,9 +941,14 @@ public class PackageParser {
                    verifiers.add(verifier);
                }
            }

            if (parser.getDepth() == searchDepth && "theme".equals(parser.getName())) {
                isTheme = true;
                installLocation = PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY;
            }
        }

        return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers);
        return new PackageLite(pkgName.intern(), versionCode, installLocation, verifiers, isTheme);
    }

    /**
+1 −0
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ public class DefaultContainerService extends IntentService {
            ret.versionCode = pkg.versionCode;
            ret.installLocation = pkg.installLocation;
            ret.verifiers = pkg.verifiers;
            ret.isTheme = pkg.isTheme;

            ret.recommendedInstallLocation = recommendAppInstallLocation(pkg.installLocation,
                    packagePath, flags, threshold);
+7 −1
Original line number Diff line number Diff line
@@ -6836,6 +6836,9 @@ public class PackageManagerService extends IPackageManager.Stub {
            // reader
            synchronized (mPackages) {
                PackageParser.Package pkg = mPackages.get(packageName);
                if (pkgLite.isTheme) {
                    return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
                }
                if (pkg != null) {
                    if ((flags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) {
                        // Check for downgrading.
@@ -7008,7 +7011,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                    loc = installLocationPolicy(pkgLite, flags);
                    if (loc == PackageHelper.RECOMMEND_FAILED_VERSION_DOWNGRADE) {
                        ret = PackageManager.INSTALL_FAILED_VERSION_DOWNGRADE;
                    } else if (!onSd && !onInt) {
                    } else if ((!onSd && !onInt) || pkgLite.isTheme) {
                        // Override install location with flags
                        if (loc == PackageHelper.RECOMMEND_INSTALL_EXTERNAL) {
                            // Set the flag to install on external media.
@@ -7020,6 +7023,9 @@ public class PackageManagerService extends IPackageManager.Stub {
                            flags |= PackageManager.INSTALL_INTERNAL;
                            flags &= ~PackageManager.INSTALL_EXTERNAL;
                        }
                        if (pkgLite.isTheme) {
                            flags &= ~PackageManager.INSTALL_FORWARD_LOCK;
                        }
                    }
                }
            }