diff options
| author | 2019-05-23 02:04:20 +0000 | |
|---|---|---|
| committer | 2019-05-23 02:04:20 +0000 | |
| commit | ecd1e039a3101f194423e58d85ecb78bbfcddda9 (patch) | |
| tree | ce191770970d407c33af100a6e15788767f71961 | |
| parent | c5d8ea15360299f1b02393376af9984269fc11ee (diff) | |
| parent | 39444b39ba9ff9ecb44c97b1f9f62544a316cd2b (diff) | |
Merge "Add permissions check for getNetworkType" into qt-dev
3 files changed, 13 insertions, 24 deletions
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index dab1e6f4abde..4a58d949ea82 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -2246,7 +2246,7 @@ public class TelephonyManager { @UnsupportedAppUsage public String getNetworkOperatorForPhone(int phoneId) { return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, ""); - } + } /** @@ -2446,21 +2446,7 @@ public class TelephonyManager { * @return the NETWORK_TYPE_xxxx for current data connection. */ public @NetworkType int getNetworkType() { - try { - ITelephony telephony = getITelephony(); - if (telephony != null) { - return telephony.getNetworkType(); - } else { - // This can happen when the ITelephony interface is not up yet. - return NETWORK_TYPE_UNKNOWN; - } - } catch(RemoteException ex) { - // This shouldn't happen in the normal case - return NETWORK_TYPE_UNKNOWN; - } catch (NullPointerException ex) { - // This could happen before phone restarts due to crashing - return NETWORK_TYPE_UNKNOWN; - } + return getNetworkType(getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); } /** @@ -2491,7 +2477,7 @@ public class TelephonyManager { * @hide */ @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) - @UnsupportedAppUsage + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) public int getNetworkType(int subId) { try { ITelephony telephony = getITelephony(); diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 68fd9ac8d6bd..63aded1c4b20 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -460,13 +460,6 @@ interface ITelephony { void sendDialerSpecialCode(String callingPackageName, String inputCode); /** - * Returns the network type for data transmission - * Legacy call, permission-free - */ - @UnsupportedAppUsage - int getNetworkType(); - - /** * Returns the network type of a subId. * @param subId user preferred subId. * @param callingPackage package making the call. diff --git a/telephony/java/com/android/internal/telephony/TelephonyPermissions.java b/telephony/java/com/android/internal/telephony/TelephonyPermissions.java index 2552f045eedf..e8e2a3d8453e 100644 --- a/telephony/java/com/android/internal/telephony/TelephonyPermissions.java +++ b/telephony/java/com/android/internal/telephony/TelephonyPermissions.java @@ -102,6 +102,16 @@ public final class TelephonyPermissions { callingPackage, message); } + /** Identical to checkCallingOrSelfReadPhoneState but never throws SecurityException */ + public static boolean checkCallingOrSelfReadPhoneStateNoThrow( + Context context, int subId, String callingPackage, String message) { + try { + return checkCallingOrSelfReadPhoneState(context, subId, callingPackage, message); + } catch (SecurityException se) { + return false; + } + } + /** * Check whether the app with the given pid/uid can read phone state. * |