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

Commit 74e1e27f authored by Liana Kazanova (xWF)'s avatar Liana Kazanova (xWF) Committed by Android (Google) Code Review
Browse files

Revert "Use the newly introduced MCC to country table, from the ..."

Revert submission 31449888-telephony_mainline_mcc_table

Reason for revert: DroidMonitor: Potential culprit for http://b/393206105 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.

Reverted changes: /q/submissionid:31449888-telephony_mainline_mcc_table

Change-Id: I94264e8ce30ba9c7761bcc60192248b6f47c9dff
parent e6731b32
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -242,12 +242,7 @@ flag {
    namespace: "telephony"
    description: "Make No Emergency Wifi Calling Do Not Ask Again text translatable"
    bug:"382006472"
    metadata {
        purpose: PURPOSE_BUGFIX
    }

# OWNER=jackyu,boullanger TARGET=25Q3
flag {
    name: "use_i18n_for_mcc_mapping"
    namespace: "telephony"
    description: "Use the newly introduced MCC to country table, from the time zone mainline module"
    bug:"381070025"
}
+21 −37
Original line number Diff line number Diff line
@@ -24,12 +24,12 @@ import android.content.Context;
import android.os.Build;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.timezone.MobileCountries;
import android.timezone.TelephonyLookup;
import android.timezone.TelephonyNetwork;
import android.timezone.TelephonyNetworkFinder;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.telephony.Rlog;

@@ -87,6 +87,7 @@ public final class MccTable {
     *
     * @hide
     */
    @VisibleForTesting
    public static class MccMnc {
        @NonNull
        public final String mcc;
@@ -173,42 +174,29 @@ public final class MccTable {
     * Given a GSM Mobile Country Code, returns a lower-case ISO 3166 alpha-2 country code if
     * available. Returns empty string if unavailable.
     */
    @UnsupportedAppUsage
    @NonNull
    public static String countryCodeForMcc(@NonNull String mcc) {
        if (!isNewMccTableEnabled()) {
            try {
                MccEntry entry = entryForMcc(Integer.parseInt(mcc));
    public static String countryCodeForMcc(int mcc) {
        MccEntry entry = entryForMcc(mcc);

        if (entry == null) {
            return "";
        } else {
            return entry.mIso;
        }
            } catch (NumberFormatException ex) {
                return "";
            }
        }

        TelephonyNetworkFinder telephonyNetworkFinder;

        synchronized (MccTable.class) {
            if ((telephonyNetworkFinder = sTelephonyNetworkFinder) == null) {
                sTelephonyNetworkFinder = telephonyNetworkFinder =
                        TelephonyLookup.getInstance().getTelephonyNetworkFinder();
            }
    }

        if (telephonyNetworkFinder == null) {
            // This should not happen under normal circumstances, only when the data is missing.
            return "";
        }

        MobileCountries mobileCountries = telephonyNetworkFinder.findCountriesByMcc(mcc);
        if (mobileCountries == null) {
    /**
     * Given a GSM Mobile Country Code, returns a lower-case ISO 3166 alpha-2 country code if
     * available. Returns empty string if unavailable.
     */
    @NonNull
    public static String countryCodeForMcc(@NonNull String mcc) {
        try {
            return countryCodeForMcc(Integer.parseInt(mcc));
        } catch (NumberFormatException ex) {
            return "";
        }

        return mobileCountries.getDefaultCountryIsoCode();
    }

    /**
@@ -221,7 +209,7 @@ public final class MccTable {
     * help distinguish, or the MCC assigned to a country isn't used for geopolitical reasons.
     * When the geographical country is needed  (e.g. time zone detection) this version can provide
     * more pragmatic results than the official MCC-only answer. This method falls back to calling
     * {@link #countryCodeForMcc(String)} if no special MCC+MNC cases are found.
     * {@link #countryCodeForMcc(int)} if no special MCC+MNC cases are found.
     * Returns empty string if no code can be determined.
     */
    @NonNull
@@ -232,7 +220,7 @@ public final class MccTable {
        }
        if (TextUtils.isEmpty(countryCode)) {
            // Try the MCC-only fallback.
            countryCode = countryCodeForMcc(mccMnc.mcc);
            countryCode = MccTable.countryCodeForMcc(mccMnc.mcc);
        }
        return countryCode;
    }
@@ -256,6 +244,7 @@ public final class MccTable {
        return network.getCountryIsoCode();
    }


    /**
     * Given a GSM Mobile Country Code, returns
     * the smallest number of digits that M if available.
@@ -323,11 +312,6 @@ public final class MccTable {
     */
    public static final Map<Locale, Locale> FALLBACKS = new HashMap<Locale, Locale>();

    public static boolean isNewMccTableEnabled() {
        return com.android.icu.Flags.telephonyLookupMccExtension()
                && com.android.internal.telephony.flags.Flags.useI18nForMccMapping();
    }

    static {
        // If we have English (without a country) explicitly prioritize en_US. http://b/28998094
        FALLBACKS.put(Locale.ENGLISH, Locale.US);
+5 −4
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ public class LocaleUtils {
    public static Locale getLocaleFromMcc(Context context, int mcc, String simLanguage) {
        boolean hasSimLanguage = !TextUtils.isEmpty(simLanguage);
        String language = hasSimLanguage ? simLanguage : defaultLanguageForMcc(mcc);
        String country = MccTable.countryCodeForMcc(String.valueOf(mcc));
        String country = MccTable.countryCodeForMcc(mcc);

        Rlog.d(LOG_TAG, "getLocaleFromMcc(" + language + ", " + country + ", " + mcc);
        final Locale locale = getLocaleForLanguageCountry(context, language, country);
@@ -155,13 +155,14 @@ public class LocaleUtils {
     * Returns null if unavailable.
     */
    public static String defaultLanguageForMcc(int mcc) {
        String country = MccTable.countryCodeForMcc(String.valueOf(mcc));

        if (country.isEmpty()) {
        MccTable.MccEntry entry = MccTable.entryForMcc(mcc);
        if (entry == null) {
            Rlog.d(LOG_TAG, "defaultLanguageForMcc(" + mcc + "): no country for mcc");
            return null;
        }

        final String country = entry.mIso;

        // Choose English as the default language for India.
        if ("in".equals(country)) {
            return "en";
+14 −43
Original line number Diff line number Diff line
@@ -17,69 +17,40 @@
package com.android.internal.telephony;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import android.content.Context;
import android.platform.test.annotations.UsesFlags;
import android.platform.test.flag.junit.FlagsParameterization;
import android.platform.test.flag.junit.SetFlagsRule;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;

import com.android.internal.telephony.MccTable.MccMnc;
import com.android.internal.telephony.flags.Flags;
import com.android.internal.telephony.util.LocaleUtils;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.List;
import java.util.Locale;

@RunWith(Parameterized.class)
@UsesFlags({
        com.android.internal.telephony.flags.Flags.class,
        com.android.icu.Flags.class
})
public class MccTableTest {
    @ClassRule
    public static final SetFlagsRule.ClassRule mSetFlagsClassRule = new SetFlagsRule.ClassRule();

    @Parameterized.Parameters(name = "{0}")
    public static List<FlagsParameterization> getParams() {
        return FlagsParameterization.allCombinationsOf(
                Flags.FLAG_USE_I18N_FOR_MCC_MAPPING,
                com.android.icu.Flags.FLAG_TELEPHONY_LOOKUP_MCC_EXTENSION);
    }

    @Rule
    public final SetFlagsRule mSetFlagsRule;

    public MccTableTest(FlagsParameterization flags) {
        mSetFlagsRule = mSetFlagsClassRule.createSetFlagsRule(flags);
    }

    @SmallTest
    @Test
    public void testCountryCodeForMcc() throws Exception {
        checkMccLookupWithNoMnc("lu", "270");
        checkMccLookupWithNoMnc("gr", "202");
        checkMccLookupWithNoMnc("fk", "750");
        checkMccLookupWithNoMnc("mg", "646");
        checkMccLookupWithNoMnc("us", "314");
        checkMccLookupWithNoMnc("", "300");  // mcc not defined, hence default
        checkMccLookupWithNoMnc("", "0");    // mcc not defined, hence default
        checkMccLookupWithNoMnc("", "2000"); // mcc not defined, hence default
        checkMccLookupWithNoMnc("lu", 270);
        checkMccLookupWithNoMnc("gr", 202);
        checkMccLookupWithNoMnc("fk", 750);
        checkMccLookupWithNoMnc("mg", 646);
        checkMccLookupWithNoMnc("us", 314);
        checkMccLookupWithNoMnc("", 300);  // mcc not defined, hence default
        checkMccLookupWithNoMnc("", 0);    // mcc not defined, hence default
        checkMccLookupWithNoMnc("", 2000); // mcc not defined, hence default
    }

    private void checkMccLookupWithNoMnc(String expectedCountryIsoCode, String mcc) {
    private void checkMccLookupWithNoMnc(String expectedCountryIsoCode, int mcc) {
        assertEquals(expectedCountryIsoCode, MccTable.countryCodeForMcc(mcc));
        assertEquals(expectedCountryIsoCode, MccTable.countryCodeForMcc(mcc));
        assertEquals(expectedCountryIsoCode, MccTable.countryCodeForMcc("" + mcc));
        assertEquals(expectedCountryIsoCode,
                MccTable.geoCountryCodeForMccMnc(new MccMnc(mcc, "999")));
                MccTable.geoCountryCodeForMccMnc(new MccMnc("" + mcc, "999")));
    }

    @SmallTest
@@ -98,9 +69,9 @@ public class MccTableTest {
        assertEquals("nl", LocaleUtils.defaultLanguageForMcc(204));
        assertEquals("is", LocaleUtils.defaultLanguageForMcc(274));
        // mcc not defined, hence default
        assertNull(LocaleUtils.defaultLanguageForMcc(0));
        assertEquals(null, LocaleUtils.defaultLanguageForMcc(0));
        // mcc not defined, hence default
        assertNull(LocaleUtils.defaultLanguageForMcc(2000));
        assertEquals(null, LocaleUtils.defaultLanguageForMcc(2000));
    }

    @SmallTest