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

Commit 4c9f9b54 authored by Sarah Chin's avatar Sarah Chin Committed by Sarah Kim
Browse files

Check network type before clearing primary timer

Only clear the timer if both the data network type and override
network type are the same. Prevents the bug where the primary timer
is cancelled when the device changes from connected->legacy states
due to NR->LTE data network change.

Test: atest NetworkTypeController
Test: manual test
Bug: 320266691
Change-Id: I499a93c0738163b4d93460f4df2acdf477980332
parent 51a2da4b
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -1349,7 +1349,9 @@ public class NetworkTypeController extends StateMachine {


        String currentState = getCurrentState().getName();
        String currentState = getCurrentState().getName();


        if (mIsPrimaryTimerActive && getOverrideNetworkType() == getCurrentOverrideNetworkType()) {
        if (mIsPrimaryTimerActive && getOverrideNetworkType() == getCurrentOverrideNetworkType()
                && getDataNetworkType()
                == mDisplayInfoController.getTelephonyDisplayInfo().getNetworkType()) {
            // remove primary timer if device goes back to the original icon
            // remove primary timer if device goes back to the original icon
            if (DBG) {
            if (DBG) {
                log("Remove primary timer since icon of primary state and current icon equal: "
                log("Remove primary timer since icon of primary state and current icon equal: "
+49 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;
@@ -991,6 +992,54 @@ public class NetworkTypeControllerTest extends TelephonyTest {
        assertFalse(mNetworkTypeController.areAnyTimersActive());
        assertFalse(mNetworkTypeController.areAnyTimersActive());
    }
    }


    @Test
    public void testPrimaryTimerNetworkTypeChanged() throws Exception {
        doAnswer(invocation -> {
            doReturn(new TelephonyDisplayInfo(
                    mNetworkTypeController.getDataNetworkType(),
                    mNetworkTypeController.getOverrideNetworkType(),
                    false)).when(mDisplayInfoController).getTelephonyDisplayInfo();
            return null;
        }).when(mDisplayInfoController).updateTelephonyDisplayInfo();
        mNetworkRegistrationInfo = new NetworkRegistrationInfo.Builder()
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_NR)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .build();
        doReturn(mNetworkRegistrationInfo).when(mServiceState).getNetworkRegistrationInfo(
                anyInt(), anyInt());
        mBundle.putString(CarrierConfigManager.KEY_5G_ICON_DISPLAY_GRACE_PERIOD_STRING,
                "connected_mmwave,any,10;connected,any,10;not_restricted_rrc_con,any,10");
        sendCarrierConfigChanged();

        assertEquals("connected", getCurrentState().getName());
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE,
                mNetworkTypeController.getOverrideNetworkType());

        // trigger 10 second timer after disconnecting from NR advanced
        mNetworkRegistrationInfo = new NetworkRegistrationInfo.Builder()
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_LTE)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .build();
        doReturn(mNetworkRegistrationInfo).when(mServiceState).getNetworkRegistrationInfo(
                anyInt(), anyInt());
        mNetworkTypeController.sendMessage(3 /* EVENT_SERVICE_STATE_CHANGED */);
        processAllMessages();

        assertEquals("legacy", getCurrentState().getName());
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE,
                mNetworkTypeController.getOverrideNetworkType());
        assertTrue(mNetworkTypeController.areAnyTimersActive());

        // timer expires
        moveTimeForward(10 * 1000);
        processAllMessages();

        assertEquals("legacy", getCurrentState().getName());
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE,
                mNetworkTypeController.getOverrideNetworkType());
        assertFalse(mNetworkTypeController.areAnyTimersActive());
    }

    @Test
    @Test
    public void testPrimaryTimerDeviceIdleMode() throws Exception {
    public void testPrimaryTimerDeviceIdleMode() throws Exception {
        doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(mServiceState).getNrState();
        doReturn(NetworkRegistrationInfo.NR_STATE_CONNECTED).when(mServiceState).getNrState();