summaryrefslogtreecommitdiff
path: root/telephony/common
diff options
context:
space:
mode:
authorMichael Groover <mpgroover@google.com>2021-04-16 16:56:00 -0700
committerMichael Groover <mpgroover@google.com>2021-04-20 17:15:59 -0700
commit29475615008d57460350527d3f0806f62dd59c79 (patch)
treec7ef80006fd55dd8a616f59786da0a22e576f117 /telephony/common
parent855f753c8015ace99380475167601b8481e1d531 (diff)
Refactor Telephony phone number access checks to LegacyPermissionMgr
The TelephonyPermissions phone number access check can require several interactions with the system_server to obtain the targetSdkVersion and check the required permissions / appops for the requesting package. This commit refactors all of these checks into the LegacyPermissionManager (similar to what was previously done for the device identifier access checks), requiring only a single request to the system_server to check all non-subscriber access requirements. Fixes: 159662444 Test: atest TelephonyPermissionsTest Test: atest LegacyPermissionManagerServiceTest Test: atest SmsManagerTest Test: atest PhoneNumberTest Test: atest SubscriptionControllerTest Test: atest TelephonyManagerTest Change-Id: I6c5cdbeecc2c4a2e200dcc33eedcb9213376f1ad
Diffstat (limited to 'telephony/common')
-rw-r--r--telephony/common/com/android/internal/telephony/TelephonyPermissions.java67
1 files changed, 14 insertions, 53 deletions
diff --git a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java
index d250297e6f64..d361db2e9ee5 100644
--- a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java
+++ b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java
@@ -482,64 +482,25 @@ public final class TelephonyPermissions {
public static boolean checkReadPhoneNumber(
Context context, int subId, int pid, int uid,
String callingPackage, @Nullable String callingFeatureId, String message) {
- // First, check if the SDK version is below R
- boolean preR = false;
- try {
- ApplicationInfo info = context.getPackageManager().getApplicationInfoAsUser(
- callingPackage, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
- preR = info.targetSdkVersion <= Build.VERSION_CODES.Q;
- } catch (PackageManager.NameNotFoundException nameNotFoundException) {
- }
- if (preR) {
- // SDK < R allows READ_PHONE_STATE, READ_PRIVILEGED_PHONE_STATE, or carrier privilege
- try {
- return checkReadPhoneState(
- context, subId, pid, uid, callingPackage, callingFeatureId, message);
- } catch (SecurityException readPhoneStateException) {
- }
- } else {
- // SDK >= R allows READ_PRIVILEGED_PHONE_STATE or carrier privilege
- try {
- context.enforcePermission(
- android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, pid, uid, message);
- // Skip checking for runtime permission since caller has privileged permission
- return true;
- } catch (SecurityException readPrivilegedPhoneStateException) {
- if (SubscriptionManager.isValidSubscriptionId(subId)) {
- try {
- enforceCarrierPrivilege(context, subId, uid, message);
- // Skip checking for runtime permission since caller has carrier privilege
- return true;
- } catch (SecurityException carrierPrivilegeException) {
- }
- }
- }
- }
-
- // Default SMS app can always read it.
- AppOpsManager appOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
- if (appOps.noteOp(AppOpsManager.OPSTR_WRITE_SMS, uid, callingPackage, callingFeatureId,
- null) == AppOpsManager.MODE_ALLOWED) {
+ LegacyPermissionManager permissionManager = (LegacyPermissionManager)
+ context.getSystemService(Context.LEGACY_PERMISSION_SERVICE);
+ // Apps with target SDK version < R can have the READ_PHONE_STATE permission granted with
+ // the appop denied. If PERMISSION_GRANTED is not received then check if the caller has
+ // carrier privileges; if not and the permission result is MODE_IGNORED then return false
+ // to return null data to the caller.
+ int permissionResult = permissionManager.checkPhoneNumberAccess(callingPackage, message,
+ callingFeatureId, pid, uid);
+ if (permissionResult == PackageManager.PERMISSION_GRANTED) {
return true;
}
- // Can be read with READ_SMS too.
- try {
- context.enforcePermission(android.Manifest.permission.READ_SMS, pid, uid, message);
- if (appOps.noteOp(AppOpsManager.OPSTR_READ_SMS, uid, callingPackage,
- callingFeatureId, null) == AppOpsManager.MODE_ALLOWED) {
+ if (SubscriptionManager.isValidSubscriptionId(subId)) {
+ if (TelephonyPermissions.getCarrierPrivilegeStatus(context, subId, uid)
+ == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
return true;
}
- } catch (SecurityException readSmsSecurityException) {
}
- // Can be read with READ_PHONE_NUMBERS too.
- try {
- context.enforcePermission(android.Manifest.permission.READ_PHONE_NUMBERS, pid, uid,
- message);
- if (appOps.noteOp(AppOpsManager.OPSTR_READ_PHONE_NUMBERS, uid, callingPackage,
- callingFeatureId, null) == AppOpsManager.MODE_ALLOWED) {
- return true;
- }
- } catch (SecurityException readPhoneNumberSecurityException) {
+ if (permissionResult == AppOpsManager.MODE_IGNORED) {
+ return false;
}
throw new SecurityException(message + ": Neither user " + uid