From 92203589f1f77a73466eada42f2ce5dd3f1485bc Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Thu, 26 Sep 2019 11:44:52 -0700 Subject: [PATCH] Added read phone state permission for getNetworkCountryIso The slot based version of getNetworkCountryIso is a system API. So it needs to be gaurded by permission. Bug: 141646066 Test: Telephony sanity tests Merged-In: I810ff0b77b93870ae3f62769977c7094789d0a5a Change-Id: I810ff0b77b93870ae3f62769977c7094789d0a5a (cherry picked from commit 105f65068cf38d41ac5275e52f66e5ab5b7023cc) --- api/system-current.txt | 2 +- api/test-current.txt | 2 +- .../java/android/telephony/TelephonyManager.java | 12 ++++++++++-- .../com/android/internal/telephony/ITelephony.aidl | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index 52e5255609c9f..9b8e8472be5c4 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -8884,7 +8884,7 @@ package android.telephony { method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.Map getLogicalToPhysicalSlotMapping(); method public int getMaxNumberOfSimultaneouslyActiveSims(); method public static long getMaxNumberVerificationTimeoutMillis(); - method @NonNull public String getNetworkCountryIso(int); + 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 c29ef996ee438..b5cd479b4e970 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -3041,7 +3041,7 @@ package android.telephony { method @Nullable public static android.content.ComponentName getDefaultRespondViaMessageApplication(@NonNull android.content.Context, boolean); method public int getEmergencyNumberDbVersion(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getLine1AlphaTag(); - method @NonNull public String getNetworkCountryIso(int); + method @NonNull @RequiresPermission("android.permission.READ_PRIVILEGED_PHONE_STATE") public String getNetworkCountryIso(int); method public android.util.Pair getRadioHalVersion(); method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void refreshUiccProfile(); method @Deprecated public void setCarrierTestOverride(String, String, String, String, String, String, String); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 58f1e8407d13a..042ed15a54435 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -2346,7 +2346,14 @@ public class TelephonyManager { * @return the lowercase 2 character ISO-3166 country code, or empty string if not available. */ public String getNetworkCountryIso() { - return getNetworkCountryIso(getPhoneId()); + try { + ITelephony telephony = getITelephony(); + if (telephony == null) return ""; + return telephony.getNetworkCountryIsoForPhone(getPhoneId(), + null /* no permission check */); + } catch (RemoteException ex) { + return ""; + } } /** @@ -2372,11 +2379,12 @@ public class TelephonyManager { @SystemApi @TestApi @NonNull + @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getNetworkCountryIso(int slotIndex) { try { ITelephony telephony = getITelephony(); if (telephony == null) return ""; - return telephony.getNetworkCountryIsoForPhone(slotIndex); + return telephony.getNetworkCountryIsoForPhone(slotIndex, getOpPackageName()); } 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 eedfc6a53e096..3264c751c90d5 100644 --- a/telephony/java/com/android/internal/telephony/ITelephony.aidl +++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl @@ -301,7 +301,7 @@ interface ITelephony { * operator's MCC (Mobile Country Code). * @see android.telephony.TelephonyManager#getNetworkCountryIso */ - String getNetworkCountryIsoForPhone(int phoneId); + String getNetworkCountryIsoForPhone(int phoneId, String callingPkg); /** * Returns the neighboring cell information of the device.