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

Commit 6cd5cb89 authored by Jack Yu's avatar Jack Yu Committed by Automerger Merge Worker
Browse files

Merge "Fixed LocaleTracker behaviors" into sc-dev am: 895ccaf8 am: 808b434f

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/14441328

Change-Id: I1a476b01ba156a9be0a076b3effe7dfceddbe3f6
parents efdbe7db 808b434f
Loading
Loading
Loading
Loading
+4 −15
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

@@ -261,17 +260,6 @@ public class LocaleTracker extends Handler {
        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.
     *
@@ -494,8 +482,8 @@ public class LocaleTracker extends Handler {
     */
    private synchronized void updateLocale() {
        // If MCC is available from network service state, use it first.
        String countryIso = getCarrierCountry();
        String countryIsoDebugInfo = "getCarrierCountry()";
        String countryIso = "";
        String countryIsoDebugInfo = "empty as default";

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

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

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

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

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

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

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