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

Commit dd48aab8 authored by Ganesh Olekar's avatar Ganesh Olekar
Browse files

DO NOT MERGE Fix auto-grant of AR runtime permission if device is upgrading from pre-Q

Test: Manually install app apks targeting Q and verifying that AR permission is not auto-granted
Test: atest ActivityRecognitionPermissionTest
Bug: 210065877
Change-Id: I5b2f25218fcbb34a940dfa2ff722cc6595732cfa
parent 499f8362
Loading
Loading
Loading
Loading
+2 −39
Original line number Diff line number Diff line
@@ -2764,7 +2764,6 @@ public class PermissionManagerService extends IPermissionManager.Stub {
                    final Permission bp = mRegistry.getPermission(permName);
                    final boolean appSupportsRuntimePermissions =
                            pkg.getTargetSdkVersion() >= Build.VERSION_CODES.M;
                    String legacyActivityRecognitionPermission = null;

                    if (DEBUG_INSTALL && bp != null) {
                        Log.i(TAG, "Package " + friendlyName
@@ -2788,47 +2787,12 @@ public class PermissionManagerService extends IPermissionManager.Stub {
                    // Cache newImplicitPermissions before modifing permissionsState as for the
                    // shared uids the original and new state are the same object
                    if (!origState.hasPermissionState(permName)
                            && (pkg.getImplicitPermissions().contains(permName)
                            || (permName.equals(Manifest.permission.ACTIVITY_RECOGNITION)))) {
                        if (pkg.getImplicitPermissions().contains(permName)) {
                            && (pkg.getImplicitPermissions().contains(permName))) {
                            // If permName is an implicit permission, try to auto-grant
                            newImplicitPermissions.add(permName);

                            if (DEBUG_PERMISSIONS) {
                                Slog.i(TAG, permName + " is newly added for " + friendlyName);
                            }
                        } else {
                            // Special case for Activity Recognition permission. Even if AR
                            // permission is not an implicit permission we want to add it to the
                            // list (try to auto-grant it) if the app was installed on a device
                            // before AR permission was split, regardless of if the app now requests
                            // the new AR permission or has updated its target SDK and AR is no
                            // longer implicit to it. This is a compatibility workaround for apps
                            // when AR permission was split in Q.
                            // TODO(zhanghai): This calls into SystemConfig, which generally
                            //  shouldn't  cause deadlock, but maybe we should keep a cache of the
                            //  split permission  list and just eliminate the possibility.
                            final List<PermissionManager.SplitPermissionInfo> permissionList =
                                    getSplitPermissionInfos();
                            int numSplitPerms = permissionList.size();
                            for (int splitPermNum = 0; splitPermNum < numSplitPerms;
                                    splitPermNum++) {
                                PermissionManager.SplitPermissionInfo sp = permissionList.get(
                                        splitPermNum);
                                String splitPermName = sp.getSplitPermission();
                                if (sp.getNewPermissions().contains(permName)
                                        && origState.isPermissionGranted(splitPermName)) {
                                    legacyActivityRecognitionPermission = splitPermName;
                                    newImplicitPermissions.add(permName);

                                    if (DEBUG_PERMISSIONS) {
                                        Slog.i(TAG, permName + " is newly added for "
                                                + friendlyName);
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    // TODO(b/140256621): The package instant app method has been removed
@@ -2959,8 +2923,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
                            // Hard restricted permissions cannot be held.
                            } else if (!permissionPolicyInitialized
                                    || (!hardRestricted || restrictionExempt)) {
                                if ((origPermState != null && origPermState.isGranted())
                                        || legacyActivityRecognitionPermission != null) {
                                if ((origPermState != null && origPermState.isGranted())) {
                                    if (!uidState.grantPermission(bp)) {
                                        wasChanged = true;
                                    }