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

Commit 053c3a23 authored by Hai Zhang's avatar Hai Zhang
Browse files

Fix getting target SDK version for uid in PermissionManagerService.

The lowest target SDK version (instead of the highest) should be used
in order to stay compatible with existing older apps.

Bug: 136503238
Test: presubmit
Change-Id: If3b23ae4441166c98934cdd1f4adb7ded714abc3
parent 3b049a53
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
@@ -23735,38 +23735,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;