diff options
author | Robert Greenwalt <rgreenwalt@google.com> | 2020-04-14 20:31:24 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-04-14 20:31:24 +0000 |
commit | d19884c1f59b949ea475ada80bb527cc799bee50 (patch) | |
tree | 0ff121d6d6b90f695d84c1ddef8d6b9421d01879 /telephony | |
parent | fa22e9cbd68b31a8a774784576e72dfb2ff02211 (diff) | |
parent | 1ace38473c9eb9853aedbc908d45a91d155ff196 (diff) |
Move getMsisdn and getLine1Number to READ_PHONE_NUMBERS am: 1ace38473c
Change-Id: Ic6ccd682bf19ef5862078e3e785fe5bbf68d66df
Diffstat (limited to 'telephony')
-rw-r--r-- | telephony/common/com/android/internal/telephony/TelephonyPermissions.java | 23 | ||||
-rw-r--r-- | telephony/java/android/telephony/TelephonyManager.java | 56 |
2 files changed, 61 insertions, 18 deletions
diff --git a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java index 2077800cd808..333a4f703f8b 100644 --- a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java +++ b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java @@ -445,8 +445,9 @@ public final class TelephonyPermissions { /** * Returns whether the caller can read phone numbers. * - * <p>Besides apps with the ability to read phone state per {@link #checkReadPhoneState}, the - * default SMS app and apps with READ_SMS or READ_PHONE_NUMBERS can also read phone numbers. + * <p>Besides apps with the ability to read phone state per {@link #checkReadPhoneState} + * (only prior to R), the default SMS app and apps with READ_SMS or READ_PHONE_NUMBERS + * can also read phone numbers. */ public static boolean checkCallingOrSelfReadPhoneNumber( Context context, int subId, String callingPackage, @Nullable String callingFeatureId, @@ -459,8 +460,9 @@ public final class TelephonyPermissions { /** * Returns whether the caller can read phone numbers. * - * <p>Besides apps with the ability to read phone state per {@link #checkReadPhoneState}, the - * default SMS app and apps with READ_SMS or READ_PHONE_NUMBERS can also read phone numbers. + * <p>Besides apps with the ability to read phone state per {@link #checkReadPhoneState} + * (only prior to R), the default SMS app and apps with READ_SMS or READ_PHONE_NUMBERS + * can also read phone numbers. */ @VisibleForTesting public static boolean checkReadPhoneNumber( @@ -476,12 +478,15 @@ 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. + // First, check if we can read the phone state and the SDK version is below R. try { - return checkReadPhoneState( - context, subId, pid, uid, callingPackage, callingFeatureId, - message); - } catch (SecurityException readPhoneStateSecurityException) { + ApplicationInfo info = context.getPackageManager().getApplicationInfoAsUser( + callingPackage, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); + if (info.targetSdkVersion <= Build.VERSION_CODES.Q) { + return checkReadPhoneState( + context, subId, pid, uid, callingPackage, callingFeatureId, message); + } + } catch (SecurityException | PackageManager.NameNotFoundException e) { } // Can be read with READ_SMS too. try { diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 686d710e05f8..7a55a7b815ef 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -4233,14 +4233,18 @@ public class TelephonyManager { /** * Returns the phone number string for line 1, for example, the MSISDN - * for a GSM phone. Return null if it is unavailable. + * for a GSM phone for a particular subscription. Return null if it is unavailable. + * <p> + * The default SMS app can also use this. * * <p>Requires Permission: - * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}, * {@link android.Manifest.permission#READ_SMS READ_SMS}, * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, * that the caller is the default SMS app, - * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}). + * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) + * for any API level. + * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} + * for apps targeting SDK API level 29 and below. */ @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges or default SMS app @RequiresPermission(anyOf = { @@ -4258,6 +4262,15 @@ public class TelephonyManager { * <p> * The default SMS app can also use this. * + * <p>Requires Permission: + * {@link android.Manifest.permission#READ_SMS READ_SMS}, + * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, + * that the caller is the default SMS app, + * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) + * for any API level. + * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} + * for apps targeting SDK API level 29 and below. + * * @param subId whose phone number for line 1 is returned * @hide */ @@ -4436,25 +4449,50 @@ public class TelephonyManager { } /** - * Returns the MSISDN string. - * for a GSM phone. Return null if it is unavailable. + * Returns the MSISDN string for a GSM phone. Return null if it is unavailable. + * + * <p>Requires Permission: + * {@link android.Manifest.permission#READ_SMS READ_SMS}, + * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, + * that the caller is the default SMS app, + * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) + * for any API level. + * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} + * for apps targeting SDK API level 29 and below. * * @hide */ - @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) + @RequiresPermission(anyOf = { + android.Manifest.permission.READ_PHONE_STATE, + android.Manifest.permission.READ_SMS, + android.Manifest.permission.READ_PHONE_NUMBERS + }) @UnsupportedAppUsage public String getMsisdn() { return getMsisdn(getSubId()); } /** - * Returns the MSISDN string. - * for a GSM phone. Return null if it is unavailable. + * Returns the MSISDN string for a GSM phone. Return null if it is unavailable. * * @param subId for which msisdn is returned + * + * <p>Requires Permission: + * {@link android.Manifest.permission#READ_SMS READ_SMS}, + * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, + * that the caller is the default SMS app, + * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) + * for any API level. + * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} + * for apps targeting SDK API level 29 and below. + * * @hide */ - @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) + @RequiresPermission(anyOf = { + android.Manifest.permission.READ_PHONE_STATE, + android.Manifest.permission.READ_SMS, + android.Manifest.permission.READ_PHONE_NUMBERS + }) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) public String getMsisdn(int subId) { try { |