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

Commit cf32f049 authored by Jack Yu's avatar Jack Yu Committed by Gerrit Code Review
Browse files

Merge "Timezone won't be correctly set for bogus MCC"

parents 4a357e95 a4a8217d
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -456,10 +456,15 @@ public class LocaleTracker extends Handler {
        // If MCC is available from network service state, use it first.
        String mcc = null;
        String countryIso = getCarrierCountry();
        boolean isBogusMcc = false;

        if (!TextUtils.isEmpty(mOperatorNumeric)) {
            try {
                mcc = mOperatorNumeric.substring(0, 3);
                countryIso = MccTable.countryCodeForMcc(mcc);
                if (!TextUtils.isEmpty(mcc) && TextUtils.isEmpty(countryIso)) {
                    isBogusMcc = true;
                }
            } catch (StringIndexOutOfBoundsException ex) {
                loge("updateLocale: Can't get country from operator numeric. mcc = "
                        + mcc + ". ex=" + ex);
@@ -478,7 +483,8 @@ public class LocaleTracker extends Handler {
            log("Override current country to " + mCountryOverride);
        }

        log("updateLocale: mcc = " + mcc + ", country = " + countryIso);
        log("updateLocale: mcc = " + mcc + ", country = " + countryIso
                + ", isBogusMcc = " + isBogusMcc);
        boolean countryChanged = false;
        if (!Objects.equals(countryIso, mCurrentCountryIso)) {
            String msg = "updateLocale: Change the current country to \"" + countryIso
@@ -498,7 +504,8 @@ public class LocaleTracker extends Handler {
            countryChanged = true;
        }

        if (TextUtils.isEmpty(countryIso)) {
        // For bogus mcc, the countryIso is always empty, it should be marked as available.
        if (TextUtils.isEmpty(countryIso) && !isBogusMcc) {
            mNitzStateMachine.handleNetworkCountryCodeUnavailable();
        } else {
            mNitzStateMachine.handleNetworkCountryCodeSet(countryChanged);
+24 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
@@ -54,6 +55,7 @@ public class LocaleTrackerTest extends TelephonyTest {

    private static final String US_MCC = "310";
    private static final String LIECHTENSTEIN_MCC = "295";
    private static final String BOGUS_MCC = "001";

    private static final String FAKE_MNC = "123";

@@ -113,6 +115,11 @@ public class LocaleTrackerTest extends TelephonyTest {
        processAllMessages();
    }

    private void sendOperatorLost() {
        mLocaleTracker.sendMessage(mLocaleTracker.obtainMessage(6 /* EVENT_OPERATOR_LOST */));
        processAllMessages();
    }

    private void verifyCountryCodeNotified(String[] countryCodes) {
        ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mContext, times(countryCodes.length)).sendBroadcast(intentArgumentCaptor.capture());
@@ -270,4 +277,21 @@ public class LocaleTrackerTest extends TelephonyTest {
            assertEquals(600000, LocaleTracker.getCellInfoDelayTime(i));
        }
    }

    @Test
    @SmallTest
    public void updateOperatorNumeric_NoSim_shouldHandleNetworkCountryCodeUnavailable()
            throws Exception {
        mLocaleTracker.updateOperatorNumeric("");
        sendOperatorLost();
        verify(mNitzStateMachine, times(1)).handleNetworkCountryCodeUnavailable();
    }

    @Test
    @SmallTest
    public void updateOperatorNumeric_BogusNetwork_shouldHandleNetworkCountryCodeSet()
            throws Exception {
        mLocaleTracker.updateOperatorNumeric(BOGUS_MCC + FAKE_MNC);
        verify(mNitzStateMachine, times(1)).handleNetworkCountryCodeSet(anyBoolean());
    }
}