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

Commit 49bd9cd5 authored by Shuo Qian's avatar Shuo Qian
Browse files

Clear country ISO in both LocaleTracker and EmergencyNumberTracker in APM

Test: manual; atest LocaleTrackerTest; https://paste.googleplex.com/5828746235871232
Bug: 147966042
Change-Id: I17ad7cd7691e02d65714ca727b0e8c4def220e42
Merged-In: I17ad7cd7691e02d65714ca727b0e8c4def220e42
(cherry picked from commit 78e5f863)
parent d5c62b55
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -563,6 +563,10 @@ public class LocaleTracker extends Handler {
            timeZoneCountryIsoDebugInfo = countryIsoDebugInfo;
        }

        if (mLastServiceState == ServiceState.STATE_POWER_OFF) {
            countryIso = "";
        }

        log("updateLocale: countryIso = " + countryIso
                + ", countryIsoDebugInfo = " + countryIsoDebugInfo);
        if (!Objects.equals(countryIso, mCurrentCountryIso)) {
+14 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.PersistableBundle;
import android.os.SystemProperties;
import android.telephony.CarrierConfigManager;
import android.telephony.PhoneNumberUtils;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.emergency.EmergencyNumber;
import android.telephony.emergency.EmergencyNumber.EmergencyCallRouting;
@@ -144,17 +145,27 @@ public class EmergencyNumberTracker extends Handler {
                            TelephonyManager.EXTRA_NETWORK_COUNTRY);
                    logd("ACTION_NETWORK_COUNTRY_CHANGED: PhoneId: " + phoneId + " CountryIso: "
                            + countryIso);

                    boolean isInApm = false;
                    ServiceStateTracker serviceStateTracker = mPhone.getServiceStateTracker();
                    if (serviceStateTracker != null) {
                        if (serviceStateTracker.getServiceState().getState()
                                == ServiceState.STATE_POWER_OFF) {
                            isInApm = true;
                        }
                    }
                    // Sometimes the country is updated as an empty string when the network signal
                    // is lost; though we may not call emergency when there is no signal, we want
                    // to keep the old country iso to provide country-related emergency numbers,
                    // because they think they are still in that country. We don't need to update
                    // country change in this case.
                    if (TextUtils.isEmpty(countryIso)) {
                    // country change in this case. We will still need to update the empty string
                    // if device is in APM.
                    if (TextUtils.isEmpty(countryIso) && !isInApm) {
                        return;
                    }

                    // Update country iso change for available Phones
                    updateEmergencyCountryIsoAllPhones(countryIso);
                    updateEmergencyCountryIsoAllPhones(countryIso == null ? "" : countryIso);
                }
                return;
            }
+15 −3
Original line number Diff line number Diff line
@@ -136,19 +136,24 @@ public class LocaleTrackerTest extends TelephonyTest {
    @SmallTest
    public void testUpdateOperatorNumericSync() throws Exception {
        mLocaleTracker.updateOperatorNumeric(US_MCC + FAKE_MNC);
        assertEquals(US_COUNTRY_CODE, mLocaleTracker.getCurrentCountry());
        verifyCountryCodeNotified(new String[]{US_COUNTRY_CODE});
        // Because the service state is in APM, the country ISO should be set empty.
        assertEquals(COUNTRY_CODE_UNAVAILABLE, mLocaleTracker.getCurrentCountry());
    }

    @Test
    @SmallTest
    public void testNoSim() throws Exception {
        // Set the state as STATE_OUT_OF_SERVICE. This will trigger an country change to US.
        sendServiceState(ServiceState.STATE_OUT_OF_SERVICE);
        assertEquals(US_COUNTRY_CODE, mLocaleTracker.getCurrentCountry());
        verifyCountryCodeNotified(new String[]{COUNTRY_CODE_UNAVAILABLE, US_COUNTRY_CODE});

        // updateOperatorNumeric("") will not trigger an instantaneous country change
        mLocaleTracker.updateOperatorNumeric("");
        sendGsmCellInfo();
        sendServiceState(ServiceState.STATE_EMERGENCY_ONLY);
        assertEquals(US_COUNTRY_CODE, mLocaleTracker.getCurrentCountry());
        verifyCountryCodeNotified(new String[]{US_COUNTRY_CODE});
        verifyCountryCodeNotified(new String[]{COUNTRY_CODE_UNAVAILABLE, US_COUNTRY_CODE});
        assertTrue(mLocaleTracker.isTracking());
    }

@@ -178,6 +183,13 @@ public class LocaleTrackerTest extends TelephonyTest {
        verifyCountryCodeNotified(new String[]{COUNTRY_CODE_UNAVAILABLE, US_COUNTRY_CODE});
        sendServiceState(ServiceState.STATE_POWER_OFF);
        assertFalse(mLocaleTracker.isTracking());

        // updateOperatorNumeric("") will trigger a country change in APM
        mLocaleTracker.updateOperatorNumeric("");
        processAllMessages();
        assertEquals(COUNTRY_CODE_UNAVAILABLE, mLocaleTracker.getCurrentCountry());
        verifyCountryCodeNotified(new String[]{COUNTRY_CODE_UNAVAILABLE, US_COUNTRY_CODE,
                COUNTRY_CODE_UNAVAILABLE});
    }

    @Test