Add mock ril control commands and tests
Add mock ril controller commands and test cases:
- testStartIncomingCallAndHangup: test start incoming cal and hangup remote
- testSetCallTransitionFlag: test call transition flag and call state transition
Change-Id: I25ff8ef7931159ef7101b5e8638b9b7438db4f66
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 9b6a850..99f0abe 100644
--- a/telephony/mockril/src/com/android/internal/telephony/mockril/MockRilController.java
+++ b/telephony/mockril/src/com/android/internal/telephony/mockril/MockRilController.java
@@ -134,17 +134,15 @@
return curstate == state;
}
-
-
/**
- * Set an MT call
+ * Start an incoming call for the given phone number
*
- * @param phoneNumber for the number shown
+ * @param phoneNumber is the number to show as incoming call
+ * @return true if the incoming call is started successfully, false if it fails.
*/
- public boolean setMTCall(String phoneNumber) {
+ public boolean startIncomingCall(String phoneNumber) {
RilCtrlCmds.CtrlReqSetMTCall req = new RilCtrlCmds.CtrlReqSetMTCall();
- // Check whether it is a valid number
req.setPhoneNumber(phoneNumber);
if (!sendCtrlCommand(RilCtrlCmds.CTRL_CMD_SET_MT_CALL, 0, 0, req)) {
Log.v(TAG, "send CMD_SET_MT_CALL request failed");
@@ -153,4 +151,68 @@
return true;
}
+ /**
+ * Hang up a connection remotelly for the given call fail cause
+ *
+ * @param connectionID is the connection to be hung up
+ * @param failCause is the call fail cause defined in ril.h
+ * @return true if the hangup is successful, false if it fails
+ */
+ public boolean hangupRemote(int connectionId, int failCause) {
+ RilCtrlCmds.CtrlHangupConnRemote req = new RilCtrlCmds.CtrlHangupConnRemote();
+ req.setConnectionId(connectionId);
+ req.setCallFailCause(failCause);
+
+ if (!sendCtrlCommand(RilCtrlCmds.CTRL_CMD_HANGUP_CONN_REMOTE, 0, 0, req)) {
+ Log.v(TAG, "send CTRL_CMD_HANGUP_CONN_REMOTE request failed");
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Set call transition flag to the Mock Ril
+ *
+ * @param flag is a boolean value for the call transiton flag
+ * true: call transition: dialing->alert, alert->active is controlled
+ * false: call transition is automatically handled by Mock Ril
+ * @return true if the request is successful, false if it failed to set the flag
+ */
+ public boolean setCallTransitionFlag(boolean flag) {
+ RilCtrlCmds.CtrlSetCallTransitionFlag req = new RilCtrlCmds.CtrlSetCallTransitionFlag();
+
+ req.setFlag(flag);
+
+ if (!sendCtrlCommand(RilCtrlCmds.CTRL_CMD_SET_CALL_TRANSITION_FLAG, 0, 0, req)) {
+ Log.v(TAG, "send CTRL_CMD_SET_CALL_TRANSITION_FLAG request failed");
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Set the dialing call to alert if the call transition flag is true
+ *
+ * @return true if the call transition is successful, false if it fails
+ */
+ public boolean setDialCallToAlert() {
+ if (!sendCtrlCommand(RilCtrlCmds.CTRL_CMD_SET_CALL_ALERT, 0, 0, null)) {
+ Log.v(TAG, "send CTRL_CMD_SET_CALL_ALERT request failed");
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Set the alert call to active if the call transition flag is true
+ *
+ * @return true if the call transition is successful, false if it fails
+ */
+ public boolean setAlertCallToActive() {
+ if (!sendCtrlCommand(RilCtrlCmds.CTRL_CMD_SET_CALL_ACTIVE, 0, 0, null)) {
+ Log.v(TAG, "send CTRL_CMD_SET_CALL_ACTIVE request failed");
+ return false;
+ }
+ return true;
+ }
}
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 f0d5b31..3149ee1 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
@@ -55,7 +55,7 @@
}
/**
- * Test protobuf serialization and deserialization
+ * Test Case 1: Test protobuf serialization and deserialization
* @throws InvalidProtocolBufferMicroException
*/
public void testProtobufSerDes() throws InvalidProtocolBufferMicroException {
@@ -77,7 +77,7 @@
}
/**
- * Test echo command works using writeMsg & readMsg
+ * Test case 2: Test echo command works using writeMsg & readMsg
*/
public void testEchoMsg() throws IOException {
log("testEchoMsg E");
@@ -110,7 +110,7 @@
}
/**
- * Test get as
+ * Test case 3: Test get as
*/
public void testGetAs() {
log("testGetAs E");
@@ -150,6 +150,9 @@
log("testGetAs X");
}
+ /**
+ * Test case 3: test get radio state
+ */
public void testGetRadioState() throws IOException {
log("testGetRadioState E");
@@ -175,6 +178,9 @@
log("testGetRadioState X");
}
+ /**
+ * Test case 5: test set radio state
+ */
public void testSetRadioState() throws IOException {
log("testSetRadioState E");
@@ -187,6 +193,9 @@
Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_RADIO_STATE, 0, 0, cmdrs);
Msg resp = Msg.recv(mMockRilChannel);
+ log("get response status :" + resp.getStatus());
+ log("get response for command: " + resp.getCmd());
+ log("get command token: " + resp.getToken());
RilCtrlCmds.CtrlRspRadioState rsp = resp.getDataAs(RilCtrlCmds.CtrlRspRadioState.class);
@@ -194,4 +203,102 @@
log("get response for testSetRadioState: " + state);
assertTrue(RilCmds.RADIOSTATE_SIM_NOT_READY == state);
}
+
+ /**
+ * Test case 6: test start incoming call and hangup it.
+ */
+ public void testStartIncomingCallAndHangup() throws IOException {
+ log("testStartIncomingCallAndHangup");
+ RilCtrlCmds.CtrlReqSetMTCall cmd = new RilCtrlCmds.CtrlReqSetMTCall();
+ String incomingCall = "6502889108";
+ // set the MT call
+ cmd.setPhoneNumber(incomingCall);
+ Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_MT_CALL, 0, 0, cmd);
+ // get response
+ Msg resp = Msg.recv(mMockRilChannel);
+ log("Get response status: " + resp.getStatus());
+ assertTrue("The ril is not in a proper state to set MT calls.",
+ resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK);
+
+ // allow the incoming call alerting for some time
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {}
+
+ // we are playing a trick to assume the current is 1
+ RilCtrlCmds.CtrlHangupConnRemote hangupCmd = new RilCtrlCmds.CtrlHangupConnRemote();
+ hangupCmd.setConnectionId(1);
+ hangupCmd.setCallFailCause(16); // normal hangup
+ Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_HANGUP_CONN_REMOTE, 0, 0, hangupCmd);
+
+ // get response
+ resp = Msg.recv(mMockRilChannel);
+ log("Get response for hangup connection: " + resp.getStatus());
+ assertTrue("CTRL_CMD_HANGUP_CONN_REMOTE failed",
+ resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK);
+ }
+
+ /**
+ * Test case 7: test set call transition flag
+ */
+ public void testSetCallTransitionFlag() throws IOException {
+ log("testSetCallTransitionFlag");
+ // Set flag to true:
+ RilCtrlCmds.CtrlSetCallTransitionFlag cmd = new RilCtrlCmds.CtrlSetCallTransitionFlag();
+ cmd.setFlag(true);
+ Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_CALL_TRANSITION_FLAG, 0, 0, cmd);
+
+ Msg resp = Msg.recv(mMockRilChannel);
+ log("Get response status: " + resp.getStatus());
+ assertTrue("Set call transition flag failed",
+ resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK);
+
+ // add a dialing call
+ RilCtrlCmds.CtrlReqAddDialingCall cmdDialCall = new RilCtrlCmds.CtrlReqAddDialingCall();
+ String phoneNumber = "5102345678";
+ cmdDialCall.setPhoneNumber(phoneNumber);
+ Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_ADD_DIALING_CALL, 0, 0, cmdDialCall);
+ resp = Msg.recv(mMockRilChannel);
+ log("Get response status for adding a dialing call: " + resp.getStatus());
+ assertTrue("add dialing call failed",
+ resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK);
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {}
+
+ // send command to force call state change
+ Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_CALL_ALERT, 0, 0, null);
+ resp = Msg.recv(mMockRilChannel);
+ log("Get response status: " + resp.getStatus());
+ assertTrue("Set call alert failed",
+ resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK);
+
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {}
+
+ // send command to force call state change
+ Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_CALL_ACTIVE, 0, 0, null);
+ resp = Msg.recv(mMockRilChannel);
+ log("Get response status: " + resp.getStatus());
+ assertTrue("Set call active failed",
+ resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK);
+
+ // hangup the active all remotely
+ RilCtrlCmds.CtrlHangupConnRemote hangupCmd = new RilCtrlCmds.CtrlHangupConnRemote();
+ hangupCmd.setConnectionId(1);
+ hangupCmd.setCallFailCause(16); // normal hangup
+ Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_HANGUP_CONN_REMOTE, 0, 0, hangupCmd);
+ resp = Msg.recv(mMockRilChannel);
+ log("Get response for hangup connection: " + resp.getStatus());
+ assertTrue("CTRL_CMD_HANGUP_CONN_REMOTE failed",
+ resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK);
+
+ // set the flag to false
+ cmd.setFlag(false);
+ Msg.send(mMockRilChannel, RilCtrlCmds.CTRL_CMD_SET_CALL_TRANSITION_FLAG, 0, 0, cmd);
+ resp = Msg.recv(mMockRilChannel);
+ assertTrue("Set call transition flag failed",
+ resp.getStatus() == RilCtrlCmds.CTRL_STATUS_OK);
+ }
}