diff options
author | Xia Wang <xiaw@google.com> | 2010-08-18 09:45:45 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-08-18 09:45:45 -0700 |
commit | 0dde5157776c24d37eff566e37b5f70cbc47ed26 (patch) | |
tree | ad1d8585dd1fb35b83f48980855f1d1a5d4b912e /telephony | |
parent | 243efd2c573eea5ee571d619503e81be8de3ff9b (diff) | |
parent | e9be34c22789d2cecd7704498c5a20547490863d (diff) | |
download | frameworks_base-0dde5157776c24d37eff566e37b5f70cbc47ed26.zip frameworks_base-0dde5157776c24d37eff566e37b5f70cbc47ed26.tar.gz frameworks_base-0dde5157776c24d37eff566e37b5f70cbc47ed26.tar.bz2 |
Merge "Add setRadioState to MockRilController and the corresponding test case. Add test case for setRadioState command in Mock Ril"
Diffstat (limited to 'telephony')
3 files changed, 63 insertions, 0 deletions
diff --git a/telephony/mockril/src/com/android/internal/telephony/mockril/MockRilController.java b/telephony/mockril/src/com/android/internal/telephony/mockril/MockRilController.java index 0bf321e..a5139bd 100644 --- a/telephony/mockril/src/com/android/internal/telephony/mockril/MockRilController.java +++ b/telephony/mockril/src/com/android/internal/telephony/mockril/MockRilController.java @@ -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; + } } diff --git a/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java b/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java index 87001c8..3ea1cf2 100644 --- a/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java +++ b/telephony/tests/telephonymockriltests/src/com/android/telephonymockriltests/functional/SimpleTestUsingMockRil.java @@ -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)); + } } diff --git a/telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java b/telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java index ee03b7c..f0d5b31 100644 --- a/telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java +++ b/telephony/tests/telephonytests/src/com/android/internal/telephony/mockril/MockRilTest.java @@ -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); + } } |