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

Commit 08bcaf4b authored by Geoffrey Boullanger's avatar Geoffrey Boullanger
Browse files

Fix crash when mcc is null in MccTable.getCountryCodeForMcc.

Previously, if SubscriptionInfo.getMccString() returns null, the method would call getCountryCodeForMcc with null, which could potentially lead to a null pointer exception. This CL modifies the method to return an empty string if the mcc is null, which is consistent with the previous implementation of countryCodeForMcc.

Note that the method has been marked as @NonNull since 2019 but the annotation is not enforced.

Bug: 394271686
Change-Id: I6426eb9d88427fc4fdd699b15518d6a5bb650f99
Test: atest
Flag: com.android.internal.telephony.flags.use_i18n_for_mcc_mapping
parent 222dcd43
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -175,6 +175,10 @@ public final class MccTable {
     */
    @NonNull
    public static String countryCodeForMcc(@NonNull String mcc) {
        if (mcc == null) {
            return "";
        }

        if (!isNewMccTableEnabled()) {
            try {
                MccEntry entry = entryForMcc(Integer.parseInt(mcc));
+6 −0
Original line number Diff line number Diff line
@@ -146,4 +146,10 @@ public class MccTableTest {
        // mcc not defined, hence default
        assertEquals(2, MccTable.smallestDigitsMccForMnc(2000));
    }

    @SmallTest
    @Test
    public void testNullMcc() throws Exception {
        assertEquals("", MccTable.countryCodeForMcc(null));
    }
}