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

Commit eb1def1d authored by Joanne Chung's avatar Joanne Chung Committed by Android (Google) Code Review
Browse files

Merge "Allow checking install constraints for your own app"

parents fdfb8f16 b0943a33
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -1318,10 +1318,16 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
    }

    private boolean isValidForInstallConstraints(PackageStateInternal ps,
            String installerPackageName) {
            String installerPackageName, int installerUid, String packageName) {
        final var snapshot = mPm.snapshotComputer();
        final var isSelfUpdatePermissionGranted =
                (snapshot.checkUidPermission(android.Manifest.permission.INSTALL_SELF_UPDATES,
                        installerUid) == PackageManager.PERMISSION_GRANTED);
        final var isSelfUpdateAllowed = isSelfUpdatePermissionGranted && TextUtils.equals(
                packageName, installerPackageName);
        return TextUtils.equals(ps.getInstallSource().mInstallerPackageName, installerPackageName)
                || TextUtils.equals(ps.getInstallSource().mUpdateOwnerPackageName,
                installerPackageName);
                installerPackageName) || isSelfUpdateAllowed;
    }

    private CompletableFuture<InstallConstraintsResult> checkInstallConstraintsInternal(
@@ -1340,7 +1346,8 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        if (!PackageManagerServiceUtils.isSystemOrRootOrShell(callingUid)) {
            for (var packageName : packageNames) {
                var ps = snapshot.getPackageStateInternal(packageName);
                if (ps == null || !isValidForInstallConstraints(ps, installerPackageName)) {
                if (ps == null || !isValidForInstallConstraints(ps, installerPackageName,
                        callingUid, packageName)) {
                    throw new SecurityException("Caller has no access to package " + packageName);
                }
            }