Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 217e8871 authored by Jiashen Wang's avatar Jiashen Wang
Browse files

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
parent 7d932e4e
Loading
Loading
Loading
Loading
+27 −45
Original line number Diff line number Diff line
@@ -226,33 +226,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));
@@ -262,9 +240,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)));
    }

    /**
@@ -625,26 +607,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<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);
@@ -662,6 +624,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}
     */