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

Commit 0dde5157 authored by Xia Wang's avatar Xia Wang Committed by Android (Google) Code Review
Browse files

Merge "Add setRadioState to MockRilController and the corresponding test case....

Merge "Add setRadioState to MockRilController and the corresponding test case. Add test case for setRadioState command in Mock Ril"
parents 243efd2c e9be34c2
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -104,4 +104,32 @@ public class MockRilController {
        else
            return -1;
    }

    /**
     * Set the radio state of mock ril to the given state
     * @param state for given radio state
     * @return true if the state is set successful, false if it fails
     */
    public boolean setRadioState(int state) {
        RilCtrlCmds.CtrlReqRadioState req = new RilCtrlCmds.CtrlReqRadioState();
        if (state < 0 || state > RilCmds.RADIOSTATE_NV_READY) {
            Log.v(TAG, "the give radio state is not valid.");
            return false;
        }
        req.setState(state);
        if (!sendCtrlCommand(RilCtrlCmds.CTRL_CMD_SET_RADIO_STATE, 0, 0, req)) {
            Log.v(TAG, "send set radio state request failed.");
            return false;
        }
        Msg response = getCtrlResponse();
        if (response == null) {
            Log.v(TAG, "failed to get response for setRadioState");
            return false;
        }
        response.printHeader(TAG);
        RilCtrlCmds.CtrlRspRadioState resp =
            response.getDataAs(RilCtrlCmds.CtrlRspRadioState.class);
        int curstate = resp.getState();
        return curstate == state;
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -46,4 +46,18 @@ public class SimpleTestUsingMockRil extends InstrumentationTestCase {
        Log.v(TAG, "testGetRadioState: " + state);
        assertTrue(state >= 0 && state <= 9);
    }

    /**
     * Set the current radio state of RIL
     * and verify the radio state is set correctly
     */
    public void testSetRadioState() {
        for (int state = 0; state <= 9; state++) {
            Log.v(TAG, "set radio state to be " + state);
            assertTrue("set radio state: " + state + " failed.",
                       mMockRilCtrl.setRadioState(state));
        }
        assertFalse("use an invalid radio state", mMockRilCtrl.setRadioState(-1));
        assertFalse("the radio state doesn't exist", mMockRilCtrl.setRadioState(10));
    }
}
+21 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.internal.communication.MsgHeader;
import com.android.internal.communication.Msg;
import com.android.internal.telephony.RilChannel;
import com.android.internal.telephony.ril_proto.RilCtrlCmds;
import com.android.internal.telephony.ril_proto.RilCmds;

import com.android.frameworks.telephonytests.TelephonyMockRilTestRunner;
import com.google.protobuf.micro.InvalidProtocolBufferMicroException;
@@ -173,4 +174,24 @@ public class MockRilTest extends InstrumentationTestCase {

        log("testGetRadioState X");
    }

    public void testSetRadioState() throws IOException {
        log("testSetRadioState E");

        RilCtrlCmds.CtrlReqRadioState cmdrs = new RilCtrlCmds.CtrlReqRadioState();
        assertEquals(0, cmdrs.getState());

        cmdrs.setState(RilCmds.RADIOSTATE_SIM_NOT_READY);
        assertEquals(2, cmdrs.getState());

        Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_RADIO_STATE, 0, 0, cmdrs);

        Msg resp = Msg.recv(mMockRilChannel);

        RilCtrlCmds.CtrlRspRadioState rsp = resp.getDataAs(RilCtrlCmds.CtrlRspRadioState.class);

        int state = rsp.getState();
        log("get response for testSetRadioState: " + state);
        assertTrue(RilCmds.RADIOSTATE_SIM_NOT_READY == state);
    }
}