From d8104ecf5266b59ee84c54eadccc700dc2367090 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Wed, 18 Sep 2019 09:31:28 -0700 Subject: [PATCH] Added slot index version of getNetworkCountryIso Added this API to get network country ISO so in SIM absent case, we can get the information from the 2nd phone. Bug: 141128426 Test: CTS Merged-In: Ib02e4d145cb39683bcb13d39715003095ad93eef Change-Id: Ib02e4d145cb39683bcb13d39715003095ad93eef (cherry picked from commit a5fedc5c029b1cfd49ddb68e9cb17c0f0d167118) --- api/current.txt | 1 + api/system-current.txt | 1 + api/test-current.txt | 1 + .../telephony/SubscriptionManager.java | 6 +++ .../android/telephony/TelephonyManager.java | 40 +++++++++---------- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/api/current.txt b/api/current.txt index 1cfc86a33d211..f81d96068cbc7 100644 --- a/api/current.txt +++ b/api/current.txt @@ -44898,6 +44898,7 @@ package android.telephony { field public static final int DATA_ROAMING_DISABLE = 0; // 0x0 field public static final int DATA_ROAMING_ENABLE = 1; // 0x1 field public static final int DEFAULT_SUBSCRIPTION_ID = 2147483647; // 0x7fffffff + field public static final String EXTRA_SLOT_INDEX = "android.telephony.extra.SLOT_INDEX"; field public static final String EXTRA_SUBSCRIPTION_INDEX = "android.telephony.extra.SUBSCRIPTION_INDEX"; field public static final int INVALID_SIM_SLOT_INDEX = -1; // 0xffffffff field public static final int INVALID_SUBSCRIPTION_ID = -1; // 0xffffffff diff --git a/api/system-current.txt b/api/system-current.txt index 8c222b6175c2e..d7d4c25a094dc 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -8126,6 +8126,7 @@ package android.telephony { method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getIsimIst(); method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.Map getLogicalToPhysicalSlotMapping(); method public static long getMaxNumberVerificationTimeoutMillis(); + method @NonNull 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 077abe0b3537c..9e73f8f2e1207 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -2876,6 +2876,7 @@ package android.telephony { method public int checkCarrierPrivilegesForPackage(String); method public int getCarrierIdListVersion(); method @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public String getLine1AlphaTag(); + method @NonNull 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/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 519a954063120..04ef4e6bf9ba5 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -885,6 +885,11 @@ public class SubscriptionManager { */ public static final String EXTRA_SUBSCRIPTION_INDEX = "android.telephony.extra.SUBSCRIPTION_INDEX"; + /** + * Integer extra to specify SIM slot index. + */ + public static final String EXTRA_SLOT_INDEX = "android.telephony.extra.SLOT_INDEX"; + private final Context mContext; private volatile INetworkPolicyManager mNetworkPolicy; @@ -2112,6 +2117,7 @@ public class SubscriptionManager { if (VDBG) logd("putPhoneIdAndSubIdExtra: phoneId=" + phoneId + " subId=" + subId); intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); intent.putExtra(EXTRA_SUBSCRIPTION_INDEX, subId); + intent.putExtra(EXTRA_SLOT_INDEX, phoneId); intent.putExtra(PhoneConstants.PHONE_KEY, phoneId); } diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 74c6d5df9267c..9856b5756fc7a 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -2428,41 +2428,37 @@ public class TelephonyManager { * @return the lowercase 2 character ISO-3166 country code, or empty string if not available. */ public String getNetworkCountryIso() { - return getNetworkCountryIsoForPhone(getPhoneId()); + return getNetworkCountryIso(getPhoneId()); } /** - * Returns the ISO country code equivalent of the MCC (Mobile Country Code) of the current + * 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). - * - * @param subId for which Network CountryIso is returned - * @hide - */ - @UnsupportedAppUsage - public String getNetworkCountryIso(int subId) { - return getNetworkCountryIsoForPhone(getPhoneId(subId)); - } - - /** - * Returns the ISO country code equivalent of the current registered - * operator's MCC (Mobile Country Code) of a subscription. *

- * Availability: Only when user is registered to a network. Result may be - * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if - * on a CDMA network). * - * @param phoneId for which Network CountryIso is returned + * @param slotIndex the SIM slot index to get network country ISO. + * + * @return the lowercase 2 character ISO-3166 country code, or empty string if not available. + * + * {@hide} */ - /** {@hide} */ - @UnsupportedAppUsage - public String getNetworkCountryIsoForPhone(int phoneId) { + @SystemApi + @TestApi + @NonNull + public String getNetworkCountryIso(int slotIndex) { try { ITelephony telephony = getITelephony(); if (telephony == null) return ""; - return telephony.getNetworkCountryIsoForPhone(phoneId); + return telephony.getNetworkCountryIsoForPhone(slotIndex); } catch (RemoteException ex) { return ""; }