From 0b9a12c2c420e227d30d1ae3c3fe0ae0df8f212e Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Sat, 22 Feb 2020 19:41:41 -0800 Subject: [PATCH] Removed permission check Removed permission check for getNetworkCountryIso and made it public. This API was added since the first version of Android. Removed the permission check for backward compatibility reason. Test: Telephony sanity tests Bug: 149872821 Change-Id: I68833fdf6f078d69bc8c2e5f01cf4e058d6d7093 --- api/current.txt | 1 + api/system-current.txt | 1 - api/test-current.txt | 1 - .../android/telephony/TelephonyManager.java | 39 +++++-------------- .../internal/telephony/ITelephony.aidl | 2 +- 5 files changed, 11 insertions(+), 33 deletions(-) diff --git a/api/current.txt b/api/current.txt index c8a7956075579..8c6efaef7688d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -48147,6 +48147,7 @@ package android.telephony { method public String getMmsUserAgent(); method @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public String getNai(); method public String getNetworkCountryIso(); + method @NonNull public String getNetworkCountryIso(int); method public String getNetworkOperator(); method public String getNetworkOperatorName(); method @RequiresPermission(anyOf={"android.permission.READ_PRIVILEGED_PHONE_STATE", android.Manifest.permission.READ_PRECISE_PHONE_STATE}) public int getNetworkSelectionMode(); diff --git a/api/system-current.txt b/api/system-current.txt index 85ad66f3dec70..9cbc506075638 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -11738,7 +11738,6 @@ package android.telephony { method public int getMaxNumberOfSimultaneouslyActiveSims(); method public static long getMaxNumberVerificationTimeoutMillis(); method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String[] getMergedImsisFromGroup(); - method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getNetworkCountryIso(int); method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public long getPreferredNetworkTypeBitmask(); method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public int getRadioPowerState(); method public int getSimApplicationState(); diff --git a/api/test-current.txt b/api/test-current.txt index 2d15c0ea0ffb9..d53007f528e07 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -3753,7 +3753,6 @@ package android.telephony { method @NonNull public java.util.List getDevicePolicyOverrideApns(@NonNull android.content.Context); method public int getEmergencyNumberDbVersion(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getLine1AlphaTag(); - method @NonNull @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public String getNetworkCountryIso(int); method public android.util.Pair getRadioHalVersion(); method public boolean modifyDevicePolicyOverrideApn(@NonNull android.content.Context, int, @NonNull android.telephony.data.ApnSetting); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void refreshUiccProfile(); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 0660776c38681..a36df49064d2f 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -2788,39 +2788,22 @@ public class TelephonyManager { /** * Returns the ISO-3166 country code equivalent of the MCC (Mobile Country Code) of the current * registered operator or the cell nearby, if available. - *

- * The ISO-3166 country code is provided in lowercase 2 character format. - *

- * Note: In multi-sim, this returns a shared emergency network country iso from other - * subscription if the subscription used to create the TelephonyManager doesn't camp on - * a network due to some reason (e.g. pin/puk locked), or sim is absent in the corresponding - * slot. + * * Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine * if on a CDMA network). *

* @return the lowercase 2 character ISO-3166 country code, or empty string if not available. */ public String getNetworkCountryIso() { - try { - ITelephony telephony = getITelephony(); - if (telephony == null) return ""; - return telephony.getNetworkCountryIsoForPhone(getPhoneId(), - null /* no permission check */, null); - } catch (RemoteException ex) { - return ""; - } + return getNetworkCountryIso(getSlotIndex()); } /** * Returns the ISO-3166 country code equivalent of the MCC (Mobile Country Code) of the current - * registered operator or the cell nearby, if available. - *

- * The ISO-3166 country code is provided in lowercase 2 character format. - *

- * Note: In multi-sim, this returns a shared emergency network country iso from other - * subscription if the subscription used to create the TelephonyManager doesn't camp on - * a network due to some reason (e.g. pin/puk locked), or sim is absent in the corresponding - * slot. + * registered operator or the cell nearby, if available. This is same as + * {@link #getNetworkCountryIso()} but allowing specifying the SIM slot index. This is used for + * accessing network country info from the SIM slot that does not have SIM inserted. + * * Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine * if on a CDMA network). *

@@ -2831,22 +2814,18 @@ public class TelephonyManager { * * @throws IllegalArgumentException when the slotIndex is invalid. * - * {@hide} */ - @SystemApi - @TestApi @NonNull - @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getNetworkCountryIso(int slotIndex) { try { - if (!SubscriptionManager.isValidSlotIndex(slotIndex)) { + if (slotIndex != SubscriptionManager.DEFAULT_SIM_SLOT_INDEX + && !SubscriptionManager.isValidSlotIndex(slotIndex)) { throw new IllegalArgumentException("invalid slot index " + slotIndex); } ITelephony telephony = getITelephony(); if (telephony == null) return ""; - return telephony.getNetworkCountryIsoForPhone(slotIndex, getOpPackageName(), - getFeatureId()); + return telephony.getNetworkCountryIsoForPhone(slotIndex); } catch (RemoteException ex) { return ""; } diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl index 861925fd66e54..af5089f8e0d92 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -281,7 +281,7 @@ interface ITelephony { * operator's MCC (Mobile Country Code). * @see android.telephony.TelephonyManager#getNetworkCountryIso */ - String getNetworkCountryIsoForPhone(int phoneId, String callingPkg, String callingFeatureId); + String getNetworkCountryIsoForPhone(int phoneId); /** * Returns the neighboring cell information of the device.