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

Commit 6d7c9b76 authored by Sarah Chin's avatar Sarah Chin
Browse files

Get data network type from NetworkRegistrationInfo instead of ServiceState

Prevent the case when the data network type would be IWLAN instead of
LTE

Bug: 178951914
Test: atest NetworkTypeControllerTest
Change-Id: Ic49097543a6d6c19cc8e8e9fa9406ca1d17f7cad
parent 5e86920f
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -360,10 +360,7 @@ public class NetworkTypeController extends StateMachine {

    private @Annotation.OverrideNetworkType int getCurrentOverrideNetworkType() {
        int displayNetworkType = TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE;
        NetworkRegistrationInfo nri =  mPhone.getServiceState().getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
        int dataNetworkType = nri == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN
                : nri.getAccessNetworkTechnology();
        int dataNetworkType = getDataNetworkType();
        boolean nrNsa = isLte(dataNetworkType)
                && mPhone.getServiceState().getNrState() != NetworkRegistrationInfo.NR_STATE_NONE;
        boolean nrSa = dataNetworkType == TelephonyManager.NETWORK_TYPE_NR;
@@ -420,7 +417,7 @@ public class NetworkTypeController extends StateMachine {

    private @Annotation.OverrideNetworkType int getLteDisplayType() {
        int value = TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE;
        if ((mPhone.getServiceState().getDataNetworkType() == TelephonyManager.NETWORK_TYPE_LTE_CA
        if ((getDataNetworkType() == TelephonyManager.NETWORK_TYPE_LTE_CA
                || mPhone.getServiceState().isUsingCarrierAggregation())
                && (IntStream.of(mPhone.getServiceState().getCellBandwidths()).sum()
                        > mLtePlusThresholdBandwidth)) {
@@ -557,7 +554,7 @@ public class NetworkTypeController extends StateMachine {
        public boolean processMessage(Message msg) {
            if (DBG) log("LegacyState: process " + getEventName(msg.what));
            updateTimers();
            int rat = mPhone.getServiceState().getDataNetworkType();
            int rat = getDataNetworkType();
            switch (msg.what) {
                case EVENT_DATA_RAT_CHANGED:
                    if (rat == TelephonyManager.NETWORK_TYPE_NR || isLte(rat) && isNrConnected()) {
@@ -633,7 +630,7 @@ public class NetworkTypeController extends StateMachine {
            updateTimers();
            switch (msg.what) {
                case EVENT_DATA_RAT_CHANGED:
                    int rat = mPhone.getServiceState().getDataNetworkType();
                    int rat = getDataNetworkType();
                    if (rat == TelephonyManager.NETWORK_TYPE_NR) {
                        transitionTo(mNrConnectedState);
                    } else if (!isLte(rat) || !isNrNotRestricted()) {
@@ -700,7 +697,7 @@ public class NetworkTypeController extends StateMachine {
            updateTimers();
            switch (msg.what) {
                case EVENT_DATA_RAT_CHANGED:
                    int rat = mPhone.getServiceState().getDataNetworkType();
                    int rat = getDataNetworkType();
                    if (rat == TelephonyManager.NETWORK_TYPE_NR) {
                        transitionTo(mNrConnectedState);
                    } else if (!isLte(rat) || !isNrNotRestricted()) {
@@ -768,7 +765,7 @@ public class NetworkTypeController extends StateMachine {
        public boolean processMessage(Message msg) {
            if (DBG) log("NrConnectedState: process " + getEventName(msg.what));
            updateTimers();
            int rat = mPhone.getServiceState().getDataNetworkType();
            int rat = getDataNetworkType();
            switch (msg.what) {
                case EVENT_DATA_RAT_CHANGED:
                    if (rat == TelephonyManager.NETWORK_TYPE_NR || isLte(rat) && isNrConnected()) {
@@ -858,7 +855,7 @@ public class NetworkTypeController extends StateMachine {
    }

    private void transitionToCurrentState() {
        int dataRat = mPhone.getServiceState().getDataNetworkType();
        int dataRat = getDataNetworkType();
        IState transitionState;
        if (dataRat == TelephonyManager.NETWORK_TYPE_NR || isNrConnected()) {
            transitionState = mNrConnectedState;
@@ -911,7 +908,7 @@ public class NetworkTypeController extends StateMachine {
            resetAllTimers();
        }

        int rat = mPhone.getServiceState().getDataNetworkType();
        int rat = getDataNetworkType();
        if (!isLte(rat) && rat != TelephonyManager.NETWORK_TYPE_NR) {
            // Rat is 3G or 2G, and it doesn't need NR timer.
            resetAllTimers();
@@ -1040,6 +1037,13 @@ public class NetworkTypeController extends StateMachine {
        return mPhysicalLinkState == DcController.PHYSICAL_LINK_ACTIVE;
    }

    private int getDataNetworkType() {
        NetworkRegistrationInfo nri =  mPhone.getServiceState().getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
        return nri == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN
                : nri.getAccessNetworkTechnology();
    }

    private String getEventName(int event) {
        try {
            return sEvents[event];
+5 −1
Original line number Diff line number Diff line
@@ -723,7 +723,11 @@ public class NetworkTypeControllerTest extends TelephonyTest {
        assertTrue(mNetworkTypeController.is5GHysteresisActive());

        // rat is UMTS, should stop timer
        doReturn(TelephonyManager.NETWORK_TYPE_UMTS).when(mServiceState).getDataNetworkType();
        NetworkRegistrationInfo nri = new NetworkRegistrationInfo.Builder()
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_UMTS)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .build();
        doReturn(nri).when(mServiceState).getNetworkRegistrationInfo(anyInt(), anyInt());
        doReturn(NetworkRegistrationInfo.NR_STATE_NONE).when(mServiceState).getNrState();
        mNetworkTypeController.sendMessage(EVENT_DATA_RAT_CHANGED);
        processAllMessages();