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
Change-Id: Ib136beea325eabdfbd8a6a843611143958dce603
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
index 4f62f7f..1e3cd42 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -226,33 +226,11 @@
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));
@@ -262,9 +240,13 @@
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)));
}
/**
@@ -625,26 +607,6 @@
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<String> 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<String> unsupportedCountries =
- Arrays.asList(TextUtils.split(countriesListString.toLowerCase(), ","));
- return unsupportedCountries.contains(country);
- }
-
private static int[] getActiveSubscriptionIdList(Context context) {
final SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class);
@@ -663,6 +625,26 @@
}
/**
+ * 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}
*/
public static long getRafFromNetworkType(int type) {