Loading src/java/com/android/internal/telephony/LocaleTracker.java +9 −2 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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 Loading @@ -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); Loading tests/telephonytests/src/com/android/internal/telephony/LocaleTrackerTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"; Loading Loading @@ -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()); Loading Loading @@ -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()); } } Loading
src/java/com/android/internal/telephony/LocaleTracker.java +9 −2 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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 Loading @@ -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); Loading
tests/telephonytests/src/com/android/internal/telephony/LocaleTrackerTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"; Loading Loading @@ -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()); Loading Loading @@ -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()); } }