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

Commit 37176b54 authored by Sarah Kim's avatar Sarah Kim Committed by Android (Google) Code Review
Browse files

Merge "Finish poll state when radio is off or unavailable" into main

parents c31929f5 83f26984
Loading
Loading
Loading
Loading
+25 −36
Original line number Diff line number Diff line
@@ -1946,16 +1946,15 @@ public class ServiceStateTracker extends Handler {
                err = ((CommandException)(ar.exception)).getCommandError();
            }

            if (mCi.getRadioState() != TelephonyManager.RADIO_POWER_ON) {
                log("handlePollStateResult: Invalid response due to radio off or unavailable. "
                        + "Set ServiceState to out of service.");
                pollStateInternal(false);
                return;
            }

            if (err == CommandException.Error.RADIO_NOT_AVAILABLE) {
                loge("handlePollStateResult: RIL returned RADIO_NOT_AVAILABLE when radio is on.");
                loge("handlePollStateResult: RIL returned RADIO_NOT_AVAILABLE.");
                if (mCi.getRadioState() == TelephonyManager.RADIO_POWER_ON) {
                    cancelPollState();
                } else {
                    handlePollStateInternalForRadioOffOrUnavailable(
                            mCi.getRadioState() == TelephonyManager.RADIO_POWER_OFF);
                    pollStateDone();
                }
                return;
            }

@@ -3312,42 +3311,17 @@ public class ServiceStateTracker extends Handler {

    private void pollStateInternal(boolean modemTriggered) {
        mPollingContext = new int[1];
        NetworkRegistrationInfo nri;

        log("pollState: modemTriggered=" + modemTriggered + ", radioState=" + mCi.getRadioState());

        switch (mCi.getRadioState()) {
            case TelephonyManager.RADIO_POWER_UNAVAILABLE:
                // Preserve the IWLAN registration state, because that should not be affected by
                // radio availability.
                nri = mNewSS.getNetworkRegistrationInfo(
                        NetworkRegistrationInfo.DOMAIN_PS,
                        AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
                mNewSS.setOutOfService(false);
                // Add the IWLAN registration info back to service state.
                if (nri != null) {
                    mNewSS.addNetworkRegistrationInfo(nri);
                }
                mPhone.getSignalStrengthController().setSignalStrengthDefaultValues();
                mLastNitzData = null;
                mNitzState.handleNetworkUnavailable();
                handlePollStateInternalForRadioOffOrUnavailable(false);
                pollStateDone();
                break;

            case TelephonyManager.RADIO_POWER_OFF:
                // Preserve the IWLAN registration state, because that should not be affected by
                // radio availability.
                nri = mNewSS.getNetworkRegistrationInfo(
                        NetworkRegistrationInfo.DOMAIN_PS,
                        AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
                mNewSS.setOutOfService(true);
                // Add the IWLAN registration info back to service state.
                if (nri != null) {
                    mNewSS.addNetworkRegistrationInfo(nri);
                }
                mPhone.getSignalStrengthController().setSignalStrengthDefaultValues();
                mLastNitzData = null;
                mNitzState.handleNetworkUnavailable();
                handlePollStateInternalForRadioOffOrUnavailable(true);
                // Don't poll when device is shutting down or the poll was not modemTriggered
                // (they sent us new radio data) and the current network is not IWLAN
                if (mDeviceShuttingDown ||
@@ -3391,6 +3365,21 @@ public class ServiceStateTracker extends Handler {
        }
    }

    private void handlePollStateInternalForRadioOffOrUnavailable(boolean radioOff) {
        // Preserve the IWLAN registration state, which should not be affected by radio availability
        NetworkRegistrationInfo nri = mNewSS.getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS,
                AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
        mNewSS.setOutOfService(radioOff);
        // Add the IWLAN registration info back to service state.
        if (nri != null) {
            mNewSS.addNetworkRegistrationInfo(nri);
        }
        mPhone.getSignalStrengthController().setSignalStrengthDefaultValues();
        mLastNitzData = null;
        mNitzState.handleNetworkUnavailable();
    }

    /**
     * Get the highest-priority CellIdentity for a provided ServiceState.
     *
+73 −0
Original line number Diff line number Diff line
@@ -2064,6 +2064,79 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        assertEquals(null, sst.getServiceState().getOperatorAlpha());
    }

    @Test
    public void testPollStateExceptionRadioPowerOn() {
        assertEquals(TelephonyManager.RADIO_POWER_ON, mSimulatedCommands.getRadioState());
        assertEquals(ServiceState.STATE_IN_SERVICE, sst.getServiceState().getState());
        assertEquals(ServiceState.STATE_IN_SERVICE,
                sst.getServiceState().getDataRegistrationState());

        sst.mPollingContext[0] = 1;
        sst.sendMessage(sst.obtainMessage(
                ServiceStateTracker.EVENT_POLL_STATE_OPERATOR,
                new AsyncResult(sst.mPollingContext, null,
                        new CommandException(CommandException.Error.RADIO_NOT_AVAILABLE))));
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());

        assertEquals(ServiceState.STATE_IN_SERVICE, sst.getServiceState().getState());
        assertEquals(ServiceState.STATE_IN_SERVICE,
                sst.getServiceState().getDataRegistrationState());
        assertEquals(0, sst.mPollingContext[0]);
    }

    @Test
    public void testPollStateExceptionRadioPowerOff() {
        // Turn off radio first.
        sst.setRadioPower(false);
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());
        assertEquals(TelephonyManager.RADIO_POWER_OFF, mSimulatedCommands.getRadioState());
        assertEquals(ServiceState.STATE_POWER_OFF, sst.getServiceState().getState());
        assertEquals(ServiceState.STATE_POWER_OFF,
                sst.getServiceState().getDataRegistrationState());
        // Override service state
        sst.getServiceState().setVoiceRegState(ServiceState.STATE_IN_SERVICE);
        sst.getServiceState().setDataRegState(ServiceState.STATE_IN_SERVICE);

        sst.mPollingContext[0] = 1;
        sst.sendMessage(sst.obtainMessage(
                ServiceStateTracker.EVENT_POLL_STATE_OPERATOR,
                new AsyncResult(sst.mPollingContext, null,
                        new CommandException(CommandException.Error.RADIO_NOT_AVAILABLE))));
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());

        assertEquals(ServiceState.STATE_POWER_OFF, sst.getServiceState().getVoiceRegState());
        assertEquals(ServiceState.STATE_POWER_OFF, sst.getServiceState().getDataRegState());
        assertEquals(1, sst.mPollingContext[0]);
    }

    @Test
    public void testPollStateExceptionRadioPowerOffOnIwlan() {
        // Turn off radio first.
        sst.setRadioPower(false);
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());
        assertEquals(TelephonyManager.RADIO_POWER_OFF, mSimulatedCommands.getRadioState());
        assertEquals(ServiceState.STATE_POWER_OFF, sst.getServiceState().getState());
        assertEquals(ServiceState.STATE_POWER_OFF,
                sst.getServiceState().getDataRegistrationState());
        // Override service state
        sst.getServiceState().setVoiceRegState(ServiceState.STATE_IN_SERVICE);
        sst.getServiceState().setDataRegState(ServiceState.STATE_IN_SERVICE);
        // Override to IWLAN
        sst.mSS.setRilDataRadioTechnology(ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN);

        sst.mPollingContext[0] = 1;
        sst.sendMessage(sst.obtainMessage(
                ServiceStateTracker.EVENT_POLL_STATE_OPERATOR,
                new AsyncResult(sst.mPollingContext, null,
                        new CommandException(CommandException.Error.RADIO_NOT_AVAILABLE))));
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());

        assertNull(null, sst.getServiceState().getOperatorAlpha());
        assertEquals(ServiceState.STATE_POWER_OFF, sst.getServiceState().getVoiceRegState());
        assertEquals(ServiceState.STATE_POWER_OFF, sst.getServiceState().getDataRegState());
        assertEquals(1, sst.mPollingContext[0]);
    }

    @Test
    public void testCSEmergencyRegistrationState() throws Exception {
        CellIdentityGsm cellIdentity =