From f413cfed260cb4c5327571d7ec6e0a6f18e9639e Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Wed, 20 Nov 2019 16:32:50 -0800 Subject: [PATCH] [DO NOT MERGE] Add country blacklist support Adding a country blacklist, except for pixel2(walleye, taimen) will still uses whitelist Bug: 144702079 Test: manually tested (cherry picked from commit 3844ba12596bd518bc7af6df50a1dc1c0c328fa4) Change-Id: I4133e38ba2a979dc0bff4ca5090004ccc9f7a757 --- .../network/telephony/MobileNetworkUtils.java | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java index cd4489daa93..9823d6f838b 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java +++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java @@ -226,16 +226,23 @@ public class MobileNetworkUtils { 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(currentCountry)) { - inEsimSupportedCountries = true; - } else if (!TextUtils.isEmpty(supportedCountries)) { - final List supportedCountryList = - Arrays.asList(TextUtils.split(supportedCountries.toLowerCase(), ",")); - if (supportedCountryList.contains(currentCountry)) { - inEsimSupportedCountries = true; - } + + 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)); @@ -611,4 +618,24 @@ 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); + } }