Add non dangerous read phone state permission
Add non dangerous read phone state permission
Bug: 198535473
Test: CTS.
Change-Id: I38c3cf6b35411fbe957812a2a6fc491bf164bacc
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 4eae7ec..a35ac9b 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -5037,10 +5037,13 @@
@Override
public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
String callingFeatureId) {
- if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
- mApp, subId, callingPackage, callingFeatureId,
- "getDataNetworkTypeForSubscriber")) {
- return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+ String functionName = "getDataNetworkTypeForSubscriber";
+ if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
+ mApp, functionName)) {
+ if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
+ mApp, subId, callingPackage, callingFeatureId, functionName)) {
+ return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+ }
}
final long identity = Binder.clearCallingIdentity();
@@ -5062,10 +5065,13 @@
@Override
public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
String callingFeatureId) {
- if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
- mApp, subId, callingPackage, callingFeatureId,
- "getDataNetworkTypeForSubscriber")) {
- return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+ String functionName = "getVoiceNetworkTypeForSubscriber";
+ if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
+ mApp, functionName)) {
+ if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
+ mApp, subId, callingPackage, callingFeatureId, functionName)) {
+ return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+ }
}
final long identity = Binder.clearCallingIdentity();
@@ -6578,18 +6584,25 @@
* There are other factors deciding whether mobile data is actually enabled, but they are
* not considered here. See {@link #isDataEnabled(int)} for more details.
*
- * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
+ * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
+ * or carrier privileges.
*
* @return {@code true} if data is enabled else {@code false}
*/
@Override
public boolean isUserDataEnabled(int subId) {
+ String functionName = "isUserDataEnabled";
try {
- mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
- null);
+ try {
+ mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
+ functionName);
+ } catch (Exception e) {
+ mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
+ }
} catch (Exception e) {
TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
- mApp, subId, "isUserDataEnabled");
+ mApp, subId, functionName);
+
}
final long identity = Binder.clearCallingIdentity();
@@ -6619,17 +6632,24 @@
*/
@Override
public boolean isDataEnabled(int subId) {
+ String functionName = "isDataEnabled";
try {
try {
mApp.enforceCallingOrSelfPermission(
android.Manifest.permission.ACCESS_NETWORK_STATE,
- null);
+ functionName);
} catch (Exception e) {
- mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
- "isDataEnabled");
+ try {
+ mApp.enforceCallingOrSelfPermission(
+ android.Manifest.permission.READ_PHONE_STATE,
+ functionName);
+ } catch (Exception e2) {
+ mApp.enforceCallingOrSelfPermission(
+ permission.READ_BASIC_PHONE_STATE, functionName);
+ }
}
} catch (Exception e) {
- enforceReadPrivilegedPermission("isDataEnabled");
+ enforceReadPrivilegedPermission(functionName);
}
final long identity = Binder.clearCallingIdentity();
@@ -6659,16 +6679,23 @@
@Override
public boolean isDataEnabledForReason(int subId,
@TelephonyManager.DataEnabledReason int reason) {
+ String functionName = "isDataEnabledForReason";
try {
- mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
- null);
+ try {
+ mApp.enforceCallingOrSelfPermission(
+ android.Manifest.permission.ACCESS_NETWORK_STATE,
+ functionName);
+ } catch (Exception e) {
+ mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
+ functionName);
+ }
} catch (Exception e) {
try {
mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
- "isDataEnabledForReason");
+ functionName);
} catch (Exception e2) {
TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
- mApp, subId, "isDataEnabledForReason");
+ mApp, subId, functionName);
}
}
@@ -8589,6 +8616,7 @@
*
* <p>Requires one of the following permissions:
* {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
+ * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
* {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
* privileges.
*
@@ -8598,12 +8626,19 @@
*/
@Override
public boolean isDataRoamingEnabled(int subId) {
+ String functionName = "isDataRoamingEnabled";
try {
- mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
- null);
+ try {
+ mApp.enforceCallingOrSelfPermission(
+ android.Manifest.permission.ACCESS_NETWORK_STATE,
+ functionName);
+ } catch (Exception e) {
+ mApp.enforceCallingOrSelfPermission(
+ permission.READ_BASIC_PHONE_STATE, functionName);
+ }
} catch (Exception e) {
TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
- mApp, subId, "isDataRoamingEnabled");
+ mApp, subId, functionName);
}
boolean isEnabled = false;