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

Commit 0fe85a94 authored by Christopher Tate's avatar Christopher Tate
Browse files

Make sure to maintain privilege when downgrading bundled apps

When reparsing because the data-volume update has been removed, be sure
to apply privilege when the bundled fallback APK should be allowed it.

Bug 10958159

Change-Id: Ibad52a5644606b27f4ebc5d5d7c1a671283b0752
parent fd65373d
Loading
Loading
Loading
Loading
+16 −2
Original line number Original line Diff line number Diff line
@@ -9120,6 +9120,17 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
        }
    }
    }


    boolean locationIsPrivileged(File path) {
        try {
            final String privilegedAppDir = new File(Environment.getRootDirectory(), "priv-app")
                    .getCanonicalPath();
            return path.getCanonicalPath().startsWith(privilegedAppDir);
        } catch (IOException e) {
            Slog.e(TAG, "Unable to access code path " + path);
        }
        return false;
    }

    /*
    /*
     * Tries to delete system package.
     * Tries to delete system package.
     */
     */
@@ -9175,9 +9186,12 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
        }
        // Install the system package
        // Install the system package
        if (DEBUG_REMOVE) Slog.d(TAG, "Re-installing system package: " + disabledPs);
        if (DEBUG_REMOVE) Slog.d(TAG, "Re-installing system package: " + disabledPs);
        int parseFlags = PackageParser.PARSE_MUST_BE_APK | PackageParser.PARSE_IS_SYSTEM;
        if (locationIsPrivileged(disabledPs.codePath)) {
            parseFlags |= PackageParser.PARSE_IS_PRIVILEGED;
        }
        PackageParser.Package newPkg = scanPackageLI(disabledPs.codePath,
        PackageParser.Package newPkg = scanPackageLI(disabledPs.codePath,
                PackageParser.PARSE_MUST_BE_APK | PackageParser.PARSE_IS_SYSTEM,
                parseFlags, SCAN_MONITOR | SCAN_NO_PATHS, 0, null);
                SCAN_MONITOR | SCAN_NO_PATHS, 0, null);


        if (newPkg == null) {
        if (newPkg == null) {
            Slog.w(TAG, "Failed to restore system package:" + newPs.name
            Slog.w(TAG, "Failed to restore system package:" + newPs.name