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

Commit b7e2699c authored by Thomas Nguyen's avatar Thomas Nguyen Committed by Android (Google) Code Review
Browse files

Merge "Add TelephonyCountryDetector class" into main

parents d95e8fc8 6bce5f2a
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.util.LocalLog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.MccTable.MccMnc;
import com.android.internal.telephony.flags.FeatureFlags;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.internal.util.IndentingPrintWriter;
import com.android.telephony.Rlog;
@@ -154,6 +155,8 @@ public class LocaleTracker extends Handler {
    @Nullable
    private String mCurrentCountryIso;

    @NonNull private final FeatureFlags mFeatureFlags;

    /** The country override for testing purposes */
    @Nullable
    private String mCountryOverride;
@@ -244,12 +247,14 @@ public class LocaleTracker extends Handler {
     * @param nitzStateMachine NITZ state machine
     * @param looper The looper message handler
     */
    public LocaleTracker(Phone phone, NitzStateMachine nitzStateMachine, Looper looper)  {
    public LocaleTracker(Phone phone, NitzStateMachine nitzStateMachine, Looper looper,
            FeatureFlags featureFlags)  {
        super(looper);
        mPhone = phone;
        mNitzStateMachine = nitzStateMachine;
        mSimState = TelephonyManager.SIM_STATE_UNKNOWN;
        mTag = LocaleTracker.class.getSimpleName() + "-" + mPhone.getPhoneId();
        mFeatureFlags = featureFlags;

        final IntentFilter filter = new IntentFilter();
        filter.addAction(TelephonyManager.ACTION_SIM_CARD_STATE_CHANGED);
@@ -560,6 +565,10 @@ public class LocaleTracker extends Handler {
                TelephonyProperties.operator_iso_country(newProp);
            }

            if (mFeatureFlags.oemEnabledSatelliteFlag()) {
                TelephonyCountryDetector.getInstance(mPhone.getContext())
                        .onNetworkCountryCodeChanged(mPhone, countryIso);
            }
            Intent intent = new Intent(TelephonyManager.ACTION_NETWORK_COUNTRY_CHANGED);
            intent.putExtra(TelephonyManager.EXTRA_NETWORK_COUNTRY, countryIso);
            intent.putExtra(TelephonyManager.EXTRA_LAST_KNOWN_NETWORK_COUNTRY,
+1 −1
Original line number Diff line number Diff line
@@ -681,7 +681,7 @@ public class ServiceStateTracker extends Handler {
        }
        mLocaleTracker = TelephonyComponentFactory.getInstance()
                .inject(LocaleTracker.class.getName())
                .makeLocaleTracker(mPhone, mNitzState, getLooper());
                .makeLocaleTracker(mPhone, mNitzState, getLooper(), featureFlags);

        mCi.registerForImsNetworkStateChanged(this, EVENT_IMS_STATE_CHANGED, null);
        mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null);
+2 −2
Original line number Diff line number Diff line
@@ -469,8 +469,8 @@ public class TelephonyComponentFactory {
    }

    public LocaleTracker makeLocaleTracker(Phone phone, NitzStateMachine nitzStateMachine,
                                           Looper looper) {
        return new LocaleTracker(phone, nitzStateMachine, looper);
                                           Looper looper, @NonNull FeatureFlags featureFlags) {
        return new LocaleTracker(phone, nitzStateMachine, looper, featureFlags);
    }

    public Phone makePhone(Context context, CommandsInterface ci, PhoneNotifier notifier,
+570 −0

File added.

Preview size limit exceeded, changes collapsed.

+38 −2
Original line number Diff line number Diff line
@@ -22,8 +22,10 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Intent;
import android.os.AsyncResult;
@@ -44,6 +46,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.Arrays;
import java.util.Collections;
@@ -66,13 +70,18 @@ public class LocaleTrackerTest extends TelephonyTest {
    private LocaleTracker mLocaleTracker;

    private CellInfoGsm mCellInfo;
    @Mock TelephonyCountryDetector mCountryDetector;

    @Before
    public void setUp() throws Exception {
        logd("LocaleTrackerTest +Setup!");
        super.setUp(getClass().getSimpleName());
        MockitoAnnotations.initMocks(this);
        logd(TAG + " Setup!");

        mLocaleTracker = new LocaleTracker(mPhone, mNitzStateMachine, Looper.myLooper());
        mLocaleTracker =
                new LocaleTracker(mPhone, mNitzStateMachine, Looper.myLooper(), mFeatureFlags);
        replaceInstance(TelephonyCountryDetector.class, "sInstance", null,
                mCountryDetector);

        // This is a workaround to bypass setting system properties, which causes access violation.
        doReturn(-1).when(mPhone).getPhoneId();
@@ -335,4 +344,31 @@ public class LocaleTrackerTest extends TelephonyTest {
        sendServiceState(ServiceState.STATE_IN_SERVICE);
        assertEquals(COUNTRY_CODE_UNAVAILABLE, mLocaleTracker.getCurrentCountry());
    }

    @Test
    public void testNotifyCountryCodeChangedToTelephonyCountryDetector_featureFlagEnabled() {
        testNotifyCountryCodeChangedToTelephonyCountryDetector(true);
    }

    @Test
    public void testNotifyCountryCodeChangedToTelephonyCountryDetector_featureFlagDisabled() {
        testNotifyCountryCodeChangedToTelephonyCountryDetector(false);
    }

    private void testNotifyCountryCodeChangedToTelephonyCountryDetector(
            boolean oemEnabledSatelliteFlag) {
        reset(mCountryDetector);
        when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(oemEnabledSatelliteFlag);
        doReturn(true).when(mPhone).isRadioOn();
        sendServiceState(ServiceState.STATE_IN_SERVICE);
        mLocaleTracker.updateOperatorNumeric(US_MCC + FAKE_MNC);
        assertEquals(US_COUNTRY_CODE, mLocaleTracker.getCurrentCountry());
        assertEquals(US_COUNTRY_CODE, mLocaleTracker.getLastKnownCountryIso());
        verifyCountryCodeNotified(new String[]{COUNTRY_CODE_UNAVAILABLE, US_COUNTRY_CODE});
        assertFalse(mLocaleTracker.isTracking());

        int notifiedCount = oemEnabledSatelliteFlag ? 1 : 0;
        verify(mCountryDetector, times(notifiedCount))
                .onNetworkCountryCodeChanged(mPhone, US_COUNTRY_CODE);
    }
}
Loading