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

Commit 447f714e authored by Jack Yu's avatar Jack Yu
Browse files

Fixed LocaleTracker behaviors

1. Decouple network country code with SIM country code. This makes
   TelephonyManager.getNetworkCountryIso() behave as the description
   on the API documents. getNetworkCountryIso() returns the country
   codecurrent derived from the registered cell or nearby cell's
   MCC.
2. Fixed a bug that when device is on airplane mode with wifi calling
   available, service state was actually overridden to IN_SERVICE.

Fix: 179849551
Test: Manual
Change-Id: Ie3ec6768ffe924dd0be3e91a64dac32dacebe50b
parent 45bbb83e
Loading
Loading
Loading
Loading
+4 −15
Original line number Original line Diff line number Diff line
@@ -49,7 +49,6 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashMap;
import java.util.List;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map;
import java.util.Objects;
import java.util.Objects;


@@ -261,17 +260,6 @@ public class LocaleTracker extends Handler {
        mPhone.registerForCellInfo(this, EVENT_UNSOL_CELL_INFO, null);
        mPhone.registerForCellInfo(this, EVENT_UNSOL_CELL_INFO, null);
    }
    }


    private @NonNull String getCarrierCountry() {
        // The locale from the "ro.carrier" system property or R.array.carrier_properties.
        // This will be overwritten by the Locale from the SIM language settings (EF-PL, EF-LI)
        // if applicable.
        final Locale carrierLocale = mPhone.getLocaleFromCarrierProperties();
        if (carrierLocale != null && !TextUtils.isEmpty(carrierLocale.getCountry())) {
            return carrierLocale.getCountry();
        }
        return "";
    }

    /**
    /**
     * Get the device's current country.
     * Get the device's current country.
     *
     *
@@ -494,8 +482,8 @@ public class LocaleTracker extends Handler {
     */
     */
    private synchronized void updateLocale() {
    private synchronized void updateLocale() {
        // If MCC is available from network service state, use it first.
        // If MCC is available from network service state, use it first.
        String countryIso = getCarrierCountry();
        String countryIso = "";
        String countryIsoDebugInfo = "getCarrierCountry()";
        String countryIsoDebugInfo = "empty as default";


        // For time zone detection we want the best geographical match we can get, which may differ
        // For time zone detection we want the best geographical match we can get, which may differ
        // from the countryIso.
        // from the countryIso.
@@ -541,8 +529,9 @@ public class LocaleTracker extends Handler {
            timeZoneCountryIsoDebugInfo = countryIsoDebugInfo;
            timeZoneCountryIsoDebugInfo = countryIsoDebugInfo;
        }
        }


        if (mLastServiceState == ServiceState.STATE_POWER_OFF) {
        if (!mPhone.isRadioOn()) {
            countryIso = "";
            countryIso = "";
            countryIsoDebugInfo = "radio off";
        }
        }


        log("updateLocale: countryIso = " + countryIso
        log("updateLocale: countryIso = " + countryIso
+9 −0
Original line number Original line Diff line number Diff line
@@ -87,6 +87,7 @@ public class LocaleTrackerTest extends TelephonyTest {
            m.sendToTarget();
            m.sendToTarget();
            return null; }).when(mPhone).requestCellInfoUpdate(any(), any());
            return null; }).when(mPhone).requestCellInfoUpdate(any(), any());


        doReturn(true).when(mPhone).isRadioOn();
        processAllMessages();
        processAllMessages();
        logd("LocaleTrackerTest -Setup!");
        logd("LocaleTrackerTest -Setup!");
    }
    }
@@ -135,6 +136,7 @@ public class LocaleTrackerTest extends TelephonyTest {
    @Test
    @Test
    @SmallTest
    @SmallTest
    public void testUpdateOperatorNumericSync() throws Exception {
    public void testUpdateOperatorNumericSync() throws Exception {
        doReturn(false).when(mPhone).isRadioOn();
        mLocaleTracker.updateOperatorNumeric(US_MCC + FAKE_MNC);
        mLocaleTracker.updateOperatorNumeric(US_MCC + FAKE_MNC);
        // Because the service state is in APM, the country ISO should be set empty.
        // Because the service state is in APM, the country ISO should be set empty.
        assertEquals(COUNTRY_CODE_UNAVAILABLE, mLocaleTracker.getCurrentCountry());
        assertEquals(COUNTRY_CODE_UNAVAILABLE, mLocaleTracker.getCurrentCountry());
@@ -161,6 +163,7 @@ public class LocaleTrackerTest extends TelephonyTest {
    @SmallTest
    @SmallTest
    public void testBootupInAirplaneModeOn() throws Exception {
    public void testBootupInAirplaneModeOn() throws Exception {
        mLocaleTracker.updateOperatorNumeric("");
        mLocaleTracker.updateOperatorNumeric("");
        doReturn(false).when(mPhone).isRadioOn();
        sendServiceState(ServiceState.STATE_POWER_OFF);
        sendServiceState(ServiceState.STATE_POWER_OFF);
        assertEquals(COUNTRY_CODE_UNAVAILABLE, mLocaleTracker.getCurrentCountry());
        assertEquals(COUNTRY_CODE_UNAVAILABLE, mLocaleTracker.getCurrentCountry());
        verifyCountryCodeNotified(new String[]{COUNTRY_CODE_UNAVAILABLE});
        verifyCountryCodeNotified(new String[]{COUNTRY_CODE_UNAVAILABLE});
@@ -170,6 +173,7 @@ public class LocaleTrackerTest extends TelephonyTest {
    @Test
    @Test
    @SmallTest
    @SmallTest
    public void testToggleAirplaneModeOn() throws Exception {
    public void testToggleAirplaneModeOn() throws Exception {
        doReturn(true).when(mPhone).isRadioOn();
        sendServiceState(ServiceState.STATE_IN_SERVICE);
        sendServiceState(ServiceState.STATE_IN_SERVICE);
        mLocaleTracker.updateOperatorNumeric(US_MCC + FAKE_MNC);
        mLocaleTracker.updateOperatorNumeric(US_MCC + FAKE_MNC);
        assertEquals(US_COUNTRY_CODE, mLocaleTracker.getCurrentCountry());
        assertEquals(US_COUNTRY_CODE, mLocaleTracker.getCurrentCountry());
@@ -183,6 +187,7 @@ public class LocaleTrackerTest extends TelephonyTest {
        assertEquals(US_COUNTRY_CODE, mLocaleTracker.getCurrentCountry());
        assertEquals(US_COUNTRY_CODE, mLocaleTracker.getCurrentCountry());
        assertEquals(US_COUNTRY_CODE, mLocaleTracker.getLastKnownCountryIso());
        assertEquals(US_COUNTRY_CODE, mLocaleTracker.getLastKnownCountryIso());
        verifyCountryCodeNotified(new String[]{COUNTRY_CODE_UNAVAILABLE, US_COUNTRY_CODE});
        verifyCountryCodeNotified(new String[]{COUNTRY_CODE_UNAVAILABLE, US_COUNTRY_CODE});
        doReturn(false).when(mPhone).isRadioOn();
        sendServiceState(ServiceState.STATE_POWER_OFF);
        sendServiceState(ServiceState.STATE_POWER_OFF);
        assertFalse(mLocaleTracker.isTracking());
        assertFalse(mLocaleTracker.isTracking());


@@ -198,6 +203,7 @@ public class LocaleTrackerTest extends TelephonyTest {
    @Test
    @Test
    @SmallTest
    @SmallTest
    public void testToggleAirplaneModeOff() throws Exception {
    public void testToggleAirplaneModeOff() throws Exception {
        doReturn(false).when(mPhone).isRadioOn();
        sendServiceState(ServiceState.STATE_POWER_OFF);
        sendServiceState(ServiceState.STATE_POWER_OFF);
        mLocaleTracker.updateOperatorNumeric("");
        mLocaleTracker.updateOperatorNumeric("");
        processAllMessages();
        processAllMessages();
@@ -205,6 +211,7 @@ public class LocaleTrackerTest extends TelephonyTest {
        verifyCountryCodeNotified(new String[]{COUNTRY_CODE_UNAVAILABLE});
        verifyCountryCodeNotified(new String[]{COUNTRY_CODE_UNAVAILABLE});
        assertFalse(mLocaleTracker.isTracking());
        assertFalse(mLocaleTracker.isTracking());


        doReturn(true).when(mPhone).isRadioOn();
        sendServiceState(ServiceState.STATE_OUT_OF_SERVICE);
        sendServiceState(ServiceState.STATE_OUT_OF_SERVICE);
        processAllMessages();
        processAllMessages();
        assertTrue(mLocaleTracker.isTracking());
        assertTrue(mLocaleTracker.isTracking());
@@ -214,6 +221,7 @@ public class LocaleTrackerTest extends TelephonyTest {
    @Test
    @Test
    @SmallTest
    @SmallTest
    public void testToggleAirplaneModeOosPlmn() throws Exception {
    public void testToggleAirplaneModeOosPlmn() throws Exception {
        doReturn(false).when(mPhone).isRadioOn();
        sendServiceState(ServiceState.STATE_POWER_OFF);
        sendServiceState(ServiceState.STATE_POWER_OFF);
        mLocaleTracker.updateOperatorNumeric("");
        mLocaleTracker.updateOperatorNumeric("");
        processAllMessages();
        processAllMessages();
@@ -228,6 +236,7 @@ public class LocaleTrackerTest extends TelephonyTest {
            m.sendToTarget();
            m.sendToTarget();
            return null; }).when(mPhone).requestCellInfoUpdate(any(), any());
            return null; }).when(mPhone).requestCellInfoUpdate(any(), any());


        doReturn(true).when(mPhone).isRadioOn();
        sendServiceState(ServiceState.STATE_OUT_OF_SERVICE);
        sendServiceState(ServiceState.STATE_OUT_OF_SERVICE);
        processAllMessages();
        processAllMessages();
        assertTrue(mLocaleTracker.isTracking());
        assertTrue(mLocaleTracker.isTracking());