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

Commit 6ffb81d8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix getting target SDK version for uid in PermissionManagerService."

parents 3cad27c2 053c3a23
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -777,14 +777,6 @@ public abstract class PackageManagerInternal {
     */
    public abstract void writePermissionSettings(@NonNull @UserIdInt int[] userIds, boolean async);

    /**
     * Returns the target SDK for the given UID. Will return {@code 0} if there is no
     * package associated with the UID or if the package has not been installed for
     * the user. Will return the highest target SDK if the UID references packages with
     * a shared user id.
     */
    public abstract int getTargetSdk(int uid);

    /**
     * Returns {@code true} if the caller is the installer of record for the given package.
     * Otherwise, {@code false}.
+0 −32
Original line number Diff line number Diff line
@@ -23739,38 +23739,6 @@ public class PackageManagerService extends IPackageManager.Stub
            }
        }
        @Override
        public int getTargetSdk(int uid) {
            int userId = UserHandle.getUserId(uid);
            synchronized (mLock) {
                final Object obj = mSettings.getSettingLPr(UserHandle.getAppId(uid));
                if (obj instanceof PackageSetting) {
                    final PackageSetting ps = (PackageSetting) obj;
                    if (!ps.getInstalled(userId)) {
                        return 0;
                    }
                    return ps.pkg.applicationInfo.targetSdkVersion;
                } else if (obj instanceof SharedUserSetting) {
                    int maxTargetSdk = 0;
                    final SharedUserSetting sus = (SharedUserSetting) obj;
                    final int numPkgs = sus.packages.size();
                    for (int i = 0; i < numPkgs; i++) {
                        final PackageSetting ps = sus.packages.valueAt(i);
                        if (!ps.getInstalled(userId)) {
                            continue;
                        }
                        if (ps.pkg.applicationInfo.targetSdkVersion < maxTargetSdk) {
                            continue;
                        }
                        maxTargetSdk = ps.pkg.applicationInfo.targetSdkVersion;
                    }
                    return maxTargetSdk;
                }
                return 0;
            }
        }
        @Override
        public boolean isCallerInstallerOfRecord(
                @NonNull PackageParser.Package pkg, int callingUid) {
+2 −2
Original line number Diff line number Diff line
@@ -627,7 +627,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
                                Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY,
                                "Need " + Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY
                                        + " to change policy flags");
                    } else if (mPackageManagerInt.getTargetSdk(callingUid)
                    } else if (mPackageManagerInt.getUidTargetSdkVersion(callingUid)
                            >= Build.VERSION_CODES.Q) {
                        throw new IllegalArgumentException(
                                Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY + " needs "
@@ -1583,7 +1583,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
            // If permission review is enabled and this is a legacy app, mark the
            // permission as requiring a review as this is the initial state.
            final int uid = mPackageManagerInt.getPackageUid(packageName, 0, userId);
            final int targetSdk = mPackageManagerInt.getTargetSdk(uid);
            final int targetSdk = mPackageManagerInt.getUidTargetSdkVersion(uid);
            final int flags = (targetSdk < Build.VERSION_CODES.M && bp.isRuntime())
                    ? FLAG_PERMISSION_REVIEW_REQUIRED | FLAG_PERMISSION_REVOKE_ON_UPGRADE
                    : 0;