From 889f702829ceb8a9951df871800cc6cc52605b4b Mon Sep 17 00:00:00 2001 From: Jiashen Wang Date: Fri, 24 Jan 2020 12:42:08 -0800 Subject: [PATCH] Change MobileNetworkUtils to use EuiccManager.isSupportedCountry Currently LPA passed supported/unsupported countries to Settings by writing the value into properties which is not ideal. Instead, we should call EuiccManager.isSupportedCountry instead. Bug: 147674689 Test: 1) Manually tested by flashing the change to the device 2) Change LPA to override onGetIsEuiccSupportedCountry 3) Make sure LPA can get the request Merged-In: Ib136beea325eabdfbd8a6a843611143958dce603 Change-Id: If406d9d803affa334c1ad4f871fcfdc0561c9bf6 --- .../network/telephony/MobileNetworkUtils.java | 72 +++++++------------ 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java index ce8a1167bb1..11ea6c6a6cf 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java +++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java @@ -330,33 +330,11 @@ public class MobileNetworkUtils { final EuiccManager euiccManager = (EuiccManager) context.getSystemService(EuiccManager.class); if (!euiccManager.isEnabled()) { + Log.w(TAG, "EuiccManager is not enabled."); return false; } final ContentResolver cr = context.getContentResolver(); - - final TelephonyManager tm = - (TelephonyManager) context.getSystemService(TelephonyManager.class); - final String currentCountry = tm.getNetworkCountryIso().toLowerCase(); - final String supportedCountries = - Settings.Global.getString(cr, Settings.Global.EUICC_SUPPORTED_COUNTRIES); - final String unsupportedCountries = - Settings.Global.getString(cr, Settings.Global.EUICC_UNSUPPORTED_COUNTRIES); - - boolean inEsimSupportedCountries = false; - - if (TextUtils.isEmpty(supportedCountries)) { - // White list is empty, use blacklist. - Log.d(TAG, "Using blacklist unsupportedCountries=" + unsupportedCountries); - inEsimSupportedCountries = !isEsimUnsupportedCountry(currentCountry, - unsupportedCountries); - } else { - Log.d(TAG, "Using whitelist supportedCountries=" + supportedCountries); - inEsimSupportedCountries = isEsimSupportedCountry(currentCountry, supportedCountries); - } - - Log.d(TAG, "inEsimSupportedCountries=" + inEsimSupportedCountries); - final boolean esimIgnoredDevice = Arrays.asList(TextUtils.split(SystemProperties.get(KEY_ESIM_CID_IGNORE, ""), ",")) .contains(SystemProperties.get(KEY_CID, null)); @@ -366,9 +344,13 @@ public class MobileNetworkUtils { Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0; final boolean inDeveloperMode = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(context); - + Log.i(TAG, + String.format("showEuiccSettings: esimIgnoredDevice: %b, enabledEsimUiByDefault: " + + "%b, euiccProvisioned: %b, inDeveloperMode: %b.", + esimIgnoredDevice, enabledEsimUiByDefault, euiccProvisioned, inDeveloperMode)); return (inDeveloperMode || euiccProvisioned - || (!esimIgnoredDevice && enabledEsimUiByDefault && inEsimSupportedCountries)); + || (!esimIgnoredDevice && enabledEsimUiByDefault + && isCurrentCountrySupported(context))); } /** @@ -733,26 +715,6 @@ public class MobileNetworkUtils { return tm.getNetworkOperatorName(); } - private static boolean isEsimSupportedCountry(String country, String countriesListString) { - if (TextUtils.isEmpty(country)) { - return true; - } else if (TextUtils.isEmpty(countriesListString)) { - return false; - } - final List supportedCountries = - Arrays.asList(TextUtils.split(countriesListString.toLowerCase(), ",")); - return supportedCountries.contains(country); - } - - private static boolean isEsimUnsupportedCountry(String country, String countriesListString) { - if (TextUtils.isEmpty(country) || TextUtils.isEmpty(countriesListString)) { - return false; - } - final List unsupportedCountries = - Arrays.asList(TextUtils.split(countriesListString.toLowerCase(), ",")); - return unsupportedCountries.contains(country); - } - private static int[] getActiveSubscriptionIdList(Context context) { final SubscriptionManager subscriptionManager = context.getSystemService( SubscriptionManager.class); @@ -770,6 +732,26 @@ public class MobileNetworkUtils { return activeSubIds; } + /** + * Loop through all the device logical slots to check whether the user's current country + * supports eSIM. + */ + private static boolean isCurrentCountrySupported(Context context) { + final EuiccManager em = (EuiccManager) context.getSystemService(EuiccManager.class); + final TelephonyManager tm = + (TelephonyManager) context.getSystemService(TelephonyManager.class); + + for (int i = 0; i < tm.getPhoneCount(); i++) { + String countryCode = tm.getNetworkCountryIso(i); + if (em.isSupportedCountry(countryCode)) { + Log.i(TAG, "isCurrentCountrySupported: eSIM is supported in " + countryCode); + return true; + } + } + Log.i(TAG, "isCurrentCountrySupported: eSIM is not supported in the current country."); + return false; + } + /** * Imported from {@link android.telephony.RadioAccessFamily} */