Move getMsisdn and getLine1Number to READ_PHONE_NUMBERS
This is done to get dangerous stuff off the READ_PHONE_STATE permission. Also keeping READ_PHONE_STATE for apps targeting old SDK versions. Refactored getPhoneNumber to allow READ_PHONE_STATE pre-R Bug: 136160623 Test: atest SubInfoControllerTest, TelephonyPermissionsTest Change-Id: I5c0adcbe432ffcbb22ac8959792ee60da7039f15 Merged-In: I5c0adcbe432ffcbb22ac8959792ee60da7039f15
This commit is contained in:
committed by
Sarah Chin
parent
8d7c075bee
commit
1ace38473c
@@ -1101,13 +1101,12 @@
|
|||||||
grants your app this permission. If you don't need this permission, be sure your <a
|
grants your app this permission. If you don't need this permission, be sure your <a
|
||||||
href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code
|
href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code
|
||||||
targetSdkVersion}</a> is 4 or higher.
|
targetSdkVersion}</a> is 4 or higher.
|
||||||
<p>Protection level: dangerous
|
<p>Protection level: normal
|
||||||
-->
|
-->
|
||||||
<permission android:name="android.permission.READ_PHONE_STATE"
|
<permission android:name="android.permission.READ_PHONE_STATE"
|
||||||
android:permissionGroup="android.permission-group.UNDEFINED"
|
|
||||||
android:label="@string/permlab_readPhoneState"
|
android:label="@string/permlab_readPhoneState"
|
||||||
android:description="@string/permdesc_readPhoneState"
|
android:description="@string/permdesc_readPhoneState"
|
||||||
android:protectionLevel="dangerous" />
|
android:protectionLevel="normal" />
|
||||||
|
|
||||||
<!-- Allows read access to the device's phone number(s). This is a subset of the capabilities
|
<!-- Allows read access to the device's phone number(s). This is a subset of the capabilities
|
||||||
granted by {@link #READ_PHONE_STATE} but is exposed to instant applications.
|
granted by {@link #READ_PHONE_STATE} but is exposed to instant applications.
|
||||||
|
|||||||
@@ -445,8 +445,9 @@ public final class TelephonyPermissions {
|
|||||||
/**
|
/**
|
||||||
* Returns whether the caller can read phone numbers.
|
* Returns whether the caller can read phone numbers.
|
||||||
*
|
*
|
||||||
* <p>Besides apps with the ability to read phone state per {@link #checkReadPhoneState}, the
|
* <p>Besides apps with the ability to read phone state per {@link #checkReadPhoneState}
|
||||||
* default SMS app and apps with READ_SMS or READ_PHONE_NUMBERS can also read phone numbers.
|
* (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(
|
public static boolean checkCallingOrSelfReadPhoneNumber(
|
||||||
Context context, int subId, String callingPackage, @Nullable String callingFeatureId,
|
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.
|
* Returns whether the caller can read phone numbers.
|
||||||
*
|
*
|
||||||
* <p>Besides apps with the ability to read phone state per {@link #checkReadPhoneState}, the
|
* <p>Besides apps with the ability to read phone state per {@link #checkReadPhoneState}
|
||||||
* default SMS app and apps with READ_SMS or READ_PHONE_NUMBERS can also read phone numbers.
|
* (only prior to R), the default SMS app and apps with READ_SMS or READ_PHONE_NUMBERS
|
||||||
|
* can also read phone numbers.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static boolean checkReadPhoneNumber(
|
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
|
// 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.
|
// 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 {
|
try {
|
||||||
return checkReadPhoneState(
|
ApplicationInfo info = context.getPackageManager().getApplicationInfoAsUser(
|
||||||
context, subId, pid, uid, callingPackage, callingFeatureId,
|
callingPackage, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
|
||||||
message);
|
if (info.targetSdkVersion <= Build.VERSION_CODES.Q) {
|
||||||
} catch (SecurityException readPhoneStateSecurityException) {
|
return checkReadPhoneState(
|
||||||
|
context, subId, pid, uid, callingPackage, callingFeatureId, message);
|
||||||
|
}
|
||||||
|
} catch (SecurityException | PackageManager.NameNotFoundException e) {
|
||||||
}
|
}
|
||||||
// Can be read with READ_SMS too.
|
// Can be read with READ_SMS too.
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -4233,14 +4233,18 @@ public class TelephonyManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the phone number string for line 1, for example, the MSISDN
|
* 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:
|
* <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_SMS READ_SMS},
|
||||||
* {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS},
|
* {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS},
|
||||||
* that the caller is the default SMS app,
|
* 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
|
@SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges or default SMS app
|
||||||
@RequiresPermission(anyOf = {
|
@RequiresPermission(anyOf = {
|
||||||
@@ -4258,6 +4262,15 @@ public class TelephonyManager {
|
|||||||
* <p>
|
* <p>
|
||||||
* The default SMS app can also use this.
|
* 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
|
* @param subId whose phone number for line 1 is returned
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@@ -4436,25 +4449,50 @@ public class TelephonyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the MSISDN string.
|
* Returns the MSISDN string for a GSM phone. Return null if it is unavailable.
|
||||||
* 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
|
* @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
|
@UnsupportedAppUsage
|
||||||
public String getMsisdn() {
|
public String getMsisdn() {
|
||||||
return getMsisdn(getSubId());
|
return getMsisdn(getSubId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the MSISDN string.
|
* Returns the MSISDN string for a GSM phone. Return null if it is unavailable.
|
||||||
* for a GSM phone. Return null if it is unavailable.
|
|
||||||
*
|
*
|
||||||
* @param subId for which msisdn is returned
|
* @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
|
* @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)
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
|
||||||
public String getMsisdn(int subId) {
|
public String getMsisdn(int subId) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user