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

Commit 0214b541 authored by Sarah Chin's avatar Sarah Chin Committed by Automerger Merge Worker
Browse files

Merge "Update TelephonyDisplayInfo on preferred network type changed" into rvc-dev am: 2353e47b

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

Change-Id: Ib015531851a3a2c53aa8ae15317c5320cd700c52
parents e317326f 2353e47b
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.IntentFilter;
import android.os.AsyncResult;
import android.os.Message;
import android.os.PersistableBundle;
import android.provider.Settings;
import android.telephony.AccessNetworkConstants;
import android.telephony.Annotation;
import android.telephony.CarrierConfigManager;
@@ -87,13 +88,14 @@ public class NetworkTypeController extends StateMachine {
    private static final int EVENT_SECONDARY_TIMER_EXPIRED = 9;
    private static final int EVENT_RADIO_OFF_OR_UNAVAILABLE = 10;
    private static final int EVENT_DATA_CONNECTION_STATE_CHANGED = 11;
    private static final int EVENT_PREFERRED_NETWORK_MODE_CHANGED = 12;
    // events that don't reset the timer
    private static final int[] ALL_EVENTS = { EVENT_DATA_RAT_CHANGED, EVENT_NR_STATE_CHANGED,
            EVENT_NR_FREQUENCY_CHANGED, EVENT_DATA_ACTIVITY_CHANGED,
            EVENT_PHYSICAL_CHANNEL_CONFIG_NOTIF_CHANGED, EVENT_CARRIER_CONFIG_CHANGED,
            EVENT_PRIMARY_TIMER_EXPIRED, EVENT_SECONDARY_TIMER_EXPIRED,
            EVENT_DATA_CONNECTION_STATE_CHANGED};
            EVENT_PHYSICAL_CHANNEL_CONFIG_NOTIF_CHANGED, EVENT_PRIMARY_TIMER_EXPIRED,
            EVENT_SECONDARY_TIMER_EXPIRED, EVENT_DATA_CONNECTION_STATE_CHANGED };

    private static final String[] sEvents = new String[EVENT_DATA_CONNECTION_STATE_CHANGED + 1];
    private static final String[] sEvents = new String[EVENT_PREFERRED_NETWORK_MODE_CHANGED + 1];
    static {
        sEvents[EVENT_UPDATE] = "EVENT_UPDATE";
        sEvents[EVENT_QUIT] = "EVENT_QUIT";
@@ -108,11 +110,13 @@ public class NetworkTypeController extends StateMachine {
        sEvents[EVENT_SECONDARY_TIMER_EXPIRED] = "EVENT_SECONDARY_TIMER_EXPIRED";
        sEvents[EVENT_RADIO_OFF_OR_UNAVAILABLE] = "EVENT_RADIO_OFF_OR_UNAVAILABLE";
        sEvents[EVENT_DATA_CONNECTION_STATE_CHANGED] = "EVENT_DATA_CONNECTION_STATE_CHANGED";
        sEvents[EVENT_PREFERRED_NETWORK_MODE_CHANGED] = "EVENT_PREFERRED_NETWORK_MODE_CHANGED";
    }

    private final Phone mPhone;
    private final DisplayInfoController mDisplayInfoController;
    private final TelephonyManager mTelephonyManager;
    private final SettingsObserver mSettingsObserver;
    private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
@@ -158,6 +162,7 @@ public class NetworkTypeController extends StateMachine {
        mDisplayInfoController = displayInfoController;
        mTelephonyManager = TelephonyManager.from(phone.getContext())
                .createForSubscriptionId(phone.getSubId());
        mSettingsObserver = new SettingsObserver(mPhone.getContext(), getHandler());
        mOverrideNetworkType = TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE;
        mIsPhysicalChannelConfigOn = true;
        addState(mDefaultState);
@@ -198,6 +203,8 @@ public class NetworkTypeController extends StateMachine {
            mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_DATA_ACTIVITY
                    | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
        }
        mSettingsObserver.observe(Settings.Global.getUriFor(Settings.Global.PREFERRED_NETWORK_MODE),
                EVENT_PREFERRED_NETWORK_MODE_CHANGED);
    }

    private void unRegisterForAllEvents() {
@@ -211,6 +218,7 @@ public class NetworkTypeController extends StateMachine {
        if (mTelephonyManager != null) {
            mTelephonyManager.listen(mPhoneStateListener, 0);
        }
        mSettingsObserver.unobserve();
    }

    private void parseCarrierConfigs() {
@@ -497,6 +505,10 @@ public class NetworkTypeController extends StateMachine {
                        transitionToCurrentState();
                    }
                    break;
                case EVENT_PREFERRED_NETWORK_MODE_CHANGED:
                    resetAllTimers();
                    transitionToCurrentState();
                    break;
                default:
                    throw new RuntimeException("Received invalid event: " + msg.what);
            }
+56 −1
Original line number Diff line number Diff line
@@ -54,6 +54,9 @@ public class NetworkTypeControllerTest extends TelephonyTest {
    private static final int EVENT_CARRIER_CONFIG_CHANGED = 7;
    private static final int EVENT_PRIMARY_TIMER_EXPIRED = 8;
    private static final int EVENT_SECONDARY_TIMER_EXPIRED = 9;
    private static final int EVENT_RADIO_OFF_OR_UNAVAILABLE = 10;
    private static final int EVENT_DATA_CONNECTION_STATE_CHANGED = 11;
    private static final int EVENT_PREFERRED_NETWORK_MODE_CHANGED = 12;

    private NetworkTypeController mNetworkTypeController;
    private PersistableBundle mBundle;
@@ -88,7 +91,7 @@ public class NetworkTypeControllerTest extends TelephonyTest {
        broadcastCarrierConfigs();

        replaceInstance(Handler.class, "mLooper", mDisplayInfoController, Looper.myLooper());
        doReturn((int) TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA).when(mPhone)
        doReturn(TelephonyManager.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA).when(mPhone)
                .getCachedPreferredNetworkType();
        mNetworkTypeController = new NetworkTypeController(mPhone, mDisplayInfoController);
    }
@@ -316,6 +319,58 @@ public class NetworkTypeControllerTest extends TelephonyTest {
                mNetworkTypeController.getOverrideNetworkType());
    }

    @Test
    public void testEventRadioOffOrUnavailable() throws Exception {
        testTransitionToCurrentStateNrConnected();
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA,
                mNetworkTypeController.getOverrideNetworkType());

        doReturn(NetworkRegistrationInfo.NR_STATE_NONE).when(mServiceState).getNrState();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getDataNetworkType();

        mNetworkTypeController.sendMessage(EVENT_RADIO_OFF_OR_UNAVAILABLE);
        processAllMessages();
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE,
                mNetworkTypeController.getOverrideNetworkType());
    }

    @Test
    public void testEventDataConnectionStateChanged() throws Exception {
        testTransitionToCurrentStateNrConnected();
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA,
                mNetworkTypeController.getOverrideNetworkType());

        // TelephonyDisplayInfo can't be mocked since it's final, so create a new one for testing
        TelephonyDisplayInfo telephonyDisplayInfo = new TelephonyDisplayInfo(
                TelephonyManager.NETWORK_TYPE_UNKNOWN,
                TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE);

        doReturn(NetworkRegistrationInfo.NR_STATE_NONE).when(mServiceState).getNrState();
        doReturn(telephonyDisplayInfo).when(mDisplayInfoController).getTelephonyDisplayInfo();
        doReturn(TelephonyManager.NETWORK_TYPE_HSPAP).when(mServiceState).getDataNetworkType();

        mNetworkTypeController.sendMessage(EVENT_DATA_CONNECTION_STATE_CHANGED);
        processAllMessages();
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE,
                mNetworkTypeController.getOverrideNetworkType());
    }

    @Test
    public void testEventPreferredNetworkModeChanged() throws Exception {
        testTransitionToCurrentStateNrConnected();
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA,
                mNetworkTypeController.getOverrideNetworkType());

        // remove NR from preferred network types
        doReturn(TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA).when(mPhone)
                .getCachedPreferredNetworkType();

        mNetworkTypeController.sendMessage(EVENT_PREFERRED_NETWORK_MODE_CHANGED);
        processAllMessages();
        assertEquals(TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NONE,
                mNetworkTypeController.getOverrideNetworkType());
    }

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