diff options
author | Sarah Chin <sarahchin@google.com> | 2020-03-24 22:32:36 -0700 |
---|---|---|
committer | Sarah Chin <sarahchin@google.com> | 2020-04-14 11:42:19 -0700 |
commit | 4f8716bb8d43420f9cf970a7d2a3cf714d612316 (patch) | |
tree | 33799dfd10ba961f3598dbd7c05c477442d8429c /telephony/common/com | |
parent | 1ace38473c9eb9853aedbc908d45a91d155ff196 (diff) |
Update READ_PHONE_NUMBER security checks
For SDK R+, READ_PRIVILEGE_PHONE_STATE and carrier privilege should
allow access.
Test: atest TelephonyPermissionsTest
Bug: 151952050
Change-Id: Ie97d0b195937d4729875afd1e74357c1284e101f
Merged-In: Ie97d0b195937d4729875afd1e74357c1284e101f
Diffstat (limited to 'telephony/common/com')
-rw-r--r-- | telephony/common/com/android/internal/telephony/TelephonyPermissions.java | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java index 333a4f703f8b..fff6696604dc 100644 --- a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java +++ b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java @@ -478,16 +478,40 @@ public final class TelephonyPermissions { // NOTE(b/73308711): If an app has one of the following AppOps bits explicitly revoked, they // will be denied access, even if they have another permission and AppOps bit if needed. - // First, check if we can read the phone state and the SDK version is below R. + // First, check if the SDK version is below R + boolean preR = false; try { ApplicationInfo info = context.getPackageManager().getApplicationInfoAsUser( callingPackage, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); - if (info.targetSdkVersion <= Build.VERSION_CODES.Q) { + 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) { + } + } } - } catch (SecurityException | PackageManager.NameNotFoundException e) { } + // Can be read with READ_SMS too. try { context.enforcePermission(android.Manifest.permission.READ_SMS, pid, uid, message); |