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: I90adf45a6611ab8bc953765c72af77a6a4f7aae8
This commit is contained in:
@@ -1011,4 +1011,10 @@ public abstract class PackageManagerInternal {
|
||||
* that b/141413692 is not reproducible on Q.
|
||||
*/
|
||||
public abstract void userRemovedForTest();
|
||||
|
||||
/**
|
||||
* Get installed SDK version of the package
|
||||
* @param pkg package for which to retrieve the installed sdk version
|
||||
*/
|
||||
public abstract int getInstalledSdkVersion(PackageParser.Package pkg);
|
||||
}
|
||||
|
||||
@@ -25165,6 +25165,11 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
public void userRemovedForTest() {
|
||||
mBlockDeleteOnUserRemoveForTest.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledSdkVersion(PackageParser.Package pkg) {
|
||||
return PackageManagerService.this.getSettingsVersionForPackage(pkg).sdkVersion;
|
||||
}
|
||||
}
|
||||
|
||||
@GuardedBy("mPackages")
|
||||
|
||||
@@ -1096,21 +1096,27 @@ public class PermissionManagerService {
|
||||
// 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.
|
||||
int numSplitPerms = PermissionManager.SPLIT_PERMISSIONS.size();
|
||||
for (int splitPermNum = 0; splitPermNum < numSplitPerms; splitPermNum++) {
|
||||
PermissionManager.SplitPermissionInfo sp =
|
||||
PermissionManager.SPLIT_PERMISSIONS.get(splitPermNum);
|
||||
String splitPermName = sp.getSplitPermission();
|
||||
if (sp.getNewPermissions().contains(permName)
|
||||
&& origPermissions.hasInstallPermission(splitPermName)) {
|
||||
upgradedActivityRecognitionPermission = splitPermName;
|
||||
newImplicitPermissions.add(permName);
|
||||
// b/210065877: Check that the installed version is pre Q to auto-grant in
|
||||
// case of OS update
|
||||
if (mPackageManagerInt.getInstalledSdkVersion(pkg)
|
||||
< Build.VERSION_CODES.Q) {
|
||||
int numSplitPerms = PermissionManager.SPLIT_PERMISSIONS.size();
|
||||
for (int splitPermNum = 0; splitPermNum < numSplitPerms;
|
||||
splitPermNum++) {
|
||||
PermissionManager.SplitPermissionInfo sp =
|
||||
PermissionManager.SPLIT_PERMISSIONS.get(splitPermNum);
|
||||
String splitPermName = sp.getSplitPermission();
|
||||
if (sp.getNewPermissions().contains(permName)
|
||||
&& origPermissions.hasInstallPermission(splitPermName)) {
|
||||
upgradedActivityRecognitionPermission = splitPermName;
|
||||
newImplicitPermissions.add(permName);
|
||||
|
||||
if (DEBUG_PERMISSIONS) {
|
||||
Slog.i(TAG, permName + " is newly added for "
|
||||
+ pkg.packageName);
|
||||
if (DEBUG_PERMISSIONS) {
|
||||
Slog.i(TAG, permName + " is newly added for "
|
||||
+ pkg.packageName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user