OSDN Git Service

Add command to start incoming call. DO NOT MERGE
authorXia Wang <xiaw@google.com>
Thu, 7 Oct 2010 01:54:58 +0000 (18:54 -0700)
committerXia Wang <xiaw@google.com>
Fri, 8 Oct 2010 20:57:58 +0000 (13:57 -0700)
Add start incoming call command,
add ril request: RIL_REQUEST_ANSWER to Mock Ril
Fix: rilRequestHangupWaitingOrBackground should also hang up incoming call

Change-Id: I48b8cc98ced2ee5f449d4cc212a9b8e8413b0cff

14 files changed:
mock-ril/src/cpp/requests.cpp
mock-ril/src/cpp/responses.cpp
mock-ril/src/cpp/worker.cpp
mock-ril/src/generated/cpp/ctrl.pb.cpp
mock-ril/src/generated/cpp/ctrl.pb.h
mock-ril/src/generated/desc/ctrl.desc
mock-ril/src/generated/java/com/android/internal/telephony/ril_proto/RilCtrlCmds.java
mock-ril/src/generated/python/ctrl_pb2.py
mock-ril/src/js/ctrl_server.js
mock-ril/src/js/mock_ril.js
mock-ril/src/js/ril_vars.js
mock-ril/src/js/simulated_radio.js
mock-ril/src/js/simulated_radio_tests.js
mock-ril/src/proto/ctrl.proto

index 8cd1bf4..d88eff8 100644 (file)
@@ -421,6 +421,7 @@ int requestsInit(v8::Handle<v8::Context> context, RilRequestWorkerQueue **rwq) {
     rilReqConversionMap[RIL_REQUEST_OPERATOR] = ReqWithNoData; // 22
     rilReqConversionMap[RIL_REQUEST_GET_IMEI] = ReqWithNoData; // 38
     rilReqConversionMap[RIL_REQUEST_GET_IMEISV] = ReqWithNoData; // 39
+    rilReqConversionMap[RIL_REQUEST_ANSWER] = ReqWithNoData; // 40
     rilReqConversionMap[RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE] = ReqWithNoData; // 45
     rilReqConversionMap[RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC] = ReqWithNoData; // 46
     rilReqConversionMap[RIL_REQUEST_BASEBAND_VERSION] = ReqWithNoData; // 51
index 5705010..b2339f0 100644 (file)
@@ -508,6 +508,7 @@ int responsesInit(v8::Handle<v8::Context> context) {
     rilRspConversionMap[RIL_REQUEST_OPERATOR] = RspOperator; // 22
     rilRspConversionMap[RIL_REQUEST_GET_IMEI] = RspString; // 38
     rilRspConversionMap[RIL_REQUEST_GET_IMEISV] = RspString; // 39
+    rilRspConversionMap[RIL_REQUEST_ANSWER] = RspWithNoData; // 39
     rilRspConversionMap[RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE] = RspIntegers; // 45
     rilRspConversionMap[RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC] = RspWithNoData; // 46
     rilRspConversionMap[RIL_REQUEST_BASEBAND_VERSION] = RspString; // 51
index fcd3969..0379621 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <time.h>
 
-#define WORKER_DEBUG
+//#define WORKER_DEBUG
 #ifdef  WORKER_DEBUG
 
 #define DBG(...) LOGD(__VA_ARGS__)
index 03eed89..3266b30 100644 (file)
@@ -125,13 +125,13 @@ void protobuf_AddDesc_ctrl_2eproto() {
     "rlReqRadioState\022$\n\005state\030\001 \002(\0162\025.ril_pro"
     "to.RadioState\"9\n\021CtrlRspRadioState\022$\n\005st"
     "ate\030\001 \002(\0162\025.ril_proto.RadioState\"(\n\020Ctrl"
-    "ReqSetMTCall\022\024\n\014phone_number\030\001 \002(\t*r\n\007Ct"
+    "ReqSetMTCall\022\024\n\014phone_number\030\001 \002(\t*s\n\007Ct"
     "rlCmd\022\021\n\rCTRL_CMD_ECHO\020\000\022\034\n\030CTRL_CMD_GET"
     "_RADIO_STATE\020\001\022\034\n\030CTRL_CMD_SET_RADIO_STA"
-    "TE\020\002\022\030\n\024CTRL_CMD_SET_MT_CALL\020\003*5\n\nCtrlSt"
-    "atus\022\022\n\016CTRL_STATUS_OK\020\000\022\023\n\017CTRL_STATUS_"
-    "ERR\020\001B7\n(com.android.internal.telephony."
-    "ril_protoB\013RilCtrlCmds", 422);
+    "TE\020\002\022\031\n\024CTRL_CMD_SET_MT_CALL\020\351\007*5\n\nCtrlS"
+    "tatus\022\022\n\016CTRL_STATUS_OK\020\000\022\023\n\017CTRL_STATUS"
+    "_ERR\020\001B7\n(com.android.internal.telephony"
+    ".ril_protoB\013RilCtrlCmds", 423);
   ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
     "ctrl.proto", &protobuf_RegisterTypes);
   CtrlReqRadioState::default_instance_ = new CtrlReqRadioState();
@@ -159,7 +159,7 @@ bool CtrlCmd_IsValid(int value) {
     case 0:
     case 1:
     case 2:
-    case 3:
+    case 1001:
       return true;
     default:
       return false;
index 28432ce..945add4 100644 (file)
@@ -41,7 +41,7 @@ enum CtrlCmd {
   CTRL_CMD_ECHO = 0,
   CTRL_CMD_GET_RADIO_STATE = 1,
   CTRL_CMD_SET_RADIO_STATE = 2,
-  CTRL_CMD_SET_MT_CALL = 3
+  CTRL_CMD_SET_MT_CALL = 1001
 };
 bool CtrlCmd_IsValid(int value);
 const CtrlCmd CtrlCmd_MIN = CTRL_CMD_ECHO;
index b76019d..8bba2d7 100644 (file)
Binary files a/mock-ril/src/generated/desc/ctrl.desc and b/mock-ril/src/generated/desc/ctrl.desc differ
index 1b78faa..712f319 100644 (file)
@@ -8,7 +8,7 @@ public final class RilCtrlCmds {
   public static final int CTRL_CMD_ECHO = 0;
   public static final int CTRL_CMD_GET_RADIO_STATE = 1;
   public static final int CTRL_CMD_SET_RADIO_STATE = 2;
-  public static final int CTRL_CMD_SET_MT_CALL = 3;
+  public static final int CTRL_CMD_SET_MT_CALL = 1001;
   
   // enum CtrlStatus
   public static final int CTRL_STATUS_OK = 0;
index 807f2d1..f323740 100644 (file)
@@ -10,7 +10,7 @@ from google.protobuf import descriptor_pb2
 DESCRIPTOR = descriptor.FileDescriptor(
   name='ctrl.proto',
   package='ril_proto',
-  serialized_pb='\n\nctrl.proto\x12\tril_proto\x1a\tril.proto\"9\n\x11\x43trlReqRadioState\x12$\n\x05state\x18\x01 \x02(\x0e\x32\x15.ril_proto.RadioState\"9\n\x11\x43trlRspRadioState\x12$\n\x05state\x18\x01 \x02(\x0e\x32\x15.ril_proto.RadioState\"(\n\x10\x43trlReqSetMTCall\x12\x14\n\x0cphone_number\x18\x01 \x02(\t*r\n\x07\x43trlCmd\x12\x11\n\rCTRL_CMD_ECHO\x10\x00\x12\x1c\n\x18\x43TRL_CMD_GET_RADIO_STATE\x10\x01\x12\x1c\n\x18\x43TRL_CMD_SET_RADIO_STATE\x10\x02\x12\x18\n\x14\x43TRL_CMD_SET_MT_CALL\x10\x03*5\n\nCtrlStatus\x12\x12\n\x0e\x43TRL_STATUS_OK\x10\x00\x12\x13\n\x0f\x43TRL_STATUS_ERR\x10\x01\x42\x37\n(com.android.internal.telephony.ril_protoB\x0bRilCtrlCmds')
+  serialized_pb='\n\nctrl.proto\x12\tril_proto\x1a\tril.proto\"9\n\x11\x43trlReqRadioState\x12$\n\x05state\x18\x01 \x02(\x0e\x32\x15.ril_proto.RadioState\"9\n\x11\x43trlRspRadioState\x12$\n\x05state\x18\x01 \x02(\x0e\x32\x15.ril_proto.RadioState\"(\n\x10\x43trlReqSetMTCall\x12\x14\n\x0cphone_number\x18\x01 \x02(\t*s\n\x07\x43trlCmd\x12\x11\n\rCTRL_CMD_ECHO\x10\x00\x12\x1c\n\x18\x43TRL_CMD_GET_RADIO_STATE\x10\x01\x12\x1c\n\x18\x43TRL_CMD_SET_RADIO_STATE\x10\x02\x12\x19\n\x14\x43TRL_CMD_SET_MT_CALL\x10\xe9\x07*5\n\nCtrlStatus\x12\x12\n\x0e\x43TRL_STATUS_OK\x10\x00\x12\x13\n\x0f\x43TRL_STATUS_ERR\x10\x01\x42\x37\n(com.android.internal.telephony.ril_protoB\x0bRilCtrlCmds')
 
 _CTRLCMD = descriptor.EnumDescriptor(
   name='CtrlCmd',
@@ -31,14 +31,14 @@ _CTRLCMD = descriptor.EnumDescriptor(
       options=None,
       type=None),
     descriptor.EnumValueDescriptor(
-      name='CTRL_CMD_SET_MT_CALL', index=3, number=3,
+      name='CTRL_CMD_SET_MT_CALL', index=3, number=1001,
       options=None,
       type=None),
   ],
   containing_type=None,
   options=None,
   serialized_start=196,
-  serialized_end=310,
+  serialized_end=311,
 )
 
 
@@ -59,15 +59,15 @@ _CTRLSTATUS = descriptor.EnumDescriptor(
   ],
   containing_type=None,
   options=None,
-  serialized_start=312,
-  serialized_end=365,
+  serialized_start=313,
+  serialized_end=366,
 )
 
 
 CTRL_CMD_ECHO = 0
 CTRL_CMD_GET_RADIO_STATE = 1
 CTRL_CMD_SET_RADIO_STATE = 2
-CTRL_CMD_SET_MT_CALL = 3
+CTRL_CMD_SET_MT_CALL = 1001
 CTRL_STATUS_OK = 0
 CTRL_STATUS_ERR = 1
 
index 905b761..cc19603 100644 (file)
@@ -51,21 +51,6 @@ function CtrlServer() {
     }
 
     /**
-     * Generate an MT call
-     */
-    this.ctrlSetMTCall = function(req) {
-        print('ctrlSetMTCall');
-
-        var mtReq = new Object();
-
-        mtReq = ctrlSchema['ril_proto.CtrlReqSetMTCall'].parse(req.protobuf);
-        setMTCall(mtReq.phoneNumber, mtReq.name);
-
-        result.sendResponse = false;
-        return result;
-    }
-
-    /**
      * Process the request
      */
     this.process = function(req) {
@@ -74,7 +59,7 @@ function CtrlServer() {
 
             // Assume the result will be true, successful and nothing to return
             result.sendResponse = true;
-            result.ctrlStatus = 0;
+            result.ctrlStatus = CTRL_STATUS_OK;
             result.responseProtobuf = emptyProtobuf;
 
             // Default result will be success with no response protobuf
@@ -101,7 +86,6 @@ function CtrlServer() {
     this.ctrlDispatchTable = new Array();
     this.ctrlDispatchTable[CTRL_CMD_GET_RADIO_STATE] = this.ctrlGetRadioState;
     this.ctrlDispatchTable[CTRL_CMD_SET_RADIO_STATE] = this.ctrlSetRadioState;
-    this.ctrlDispatchTable[CTRL_CMD_SET_MT_CALL] = this.ctrlSetMTCall;
     print('CtrlServer() ctor X');
 }
 
@@ -119,21 +103,65 @@ function onCtrlServerCmd(cmd, token, protobuf) {
     try {
         print('onCtrlServerCmd E cmd=' + cmd + ' token=' + token);
 
-        var req = new Object();
-        req.cmd = cmd;
-        req.token = token;
-        req.protobuf = protobuf;
-
         print('onCtrlServerCmd add the request:');
 
-        ctrlWorker.add(req);
 
+        if (!isCtrlServerDispatchCommand(cmd)) {
+            var ctrlServerReq = new Object();
+            ctrlServerReq.cmd = cmd;
+            ctrlServerReq.token = token;
+            ctrlServerReq.protobuf = protobuf;
+            print('onCtrlServerCmd: command to control server, add to the worker queue');
+            // If it is a command to the control server, add to the control server worker queue
+            ctrlWorker.add(ctrlServerReq);
+        } else {
+            // For other commands, we need to dispatch to the corresponding components
+            try {
+                print('onCtrlServerCmd: get entry from dispatchTable cmd:' + cmd );
+                entry = ctrlServerDispatchTable[cmd];
+                if (typeof entry == 'undefined') {
+                    throw ('entry = dispatchTable[' + cmd + '] was undefined');
+                } else {
+                    var req = new Request(cmd, token, protobuf, ctrlSchema, entry.schemaName);
+                    for(i = 0; i < entry.components.length; i++) {
+                        entry.components[i].add(req);
+                    }
+                }
+            } catch (err) {
+                print('onCtrlServerCmd: Unknown cmd=' + cmd + ' err=' + err);
+                sendCtrlRequestComplete(RIL_E_REQUEST_NOT_SUPPORTED, cmd, token);
+            }
+        }
         print('onCtrlServerCmd X cmd=' + cmd + ' token=' + token);
     } catch (err) {
         print('onCtrlServerCmd X Exception err=' + err);
     }
 }
 
+function isCtrlServerDispatchCommand(cmd) {
+    return (cmd > CTRL_CMD_DISPATH_BASE)
+}
+
+/**
+ * Dispatch table for request, the control server will send those requests to
+ * the corresponding components.
+ *
+ * Each table entry is index by the CTRL_CMD_xxxx
+ * and contains an array of components this request
+ * is to be sent to and the name of the schema
+ * that converts the incoming protobuf to the
+ * appropriate request data.
+ *
+ * ctrlServerDispatchTable[CTRL_CMD_xxx].components = Array of components
+ * ctrlServerDisptachTable[CTRL_CMD_xxx].Entry.schemaName = 'Name-of-schema';
+ */
+var ctrlServerDispatchTable = new Array();
+
+ctrlServerDispatchTable[CTRL_CMD_SET_MT_CALL] = { // 1001
+    'components' : [simulatedRadioWorker],
+    'schemaName' : 'CtrlReqSetMTCall',
+};
+
 /**
  * Optional tests
  */
index c3b6455..ed388f2 100644 (file)
@@ -272,6 +272,9 @@ dispatchTable[RIL_REQUEST_GET_IMEI] = { // 38
 dispatchTable[RIL_REQUEST_GET_IMEISV] = { // 39
     'components' : [simulatedIccWorker],
 };
+dispatchTable[RIL_REQUEST_ANSWER] = { // 40
+    'components' : [simulatedRadioWorker],
+};
 dispatchTable[RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE] = { // 45
     'components' : [simulatedRadioWorker],
 };
index 5a8d43b..4b72899 100644 (file)
@@ -285,18 +285,30 @@ var RIL_UNSOL_RINGBACK_TONE = 1029
 var RIL_UNSOL_RESEND_INCALL_MUTE = 1030
 
 /**
- * Control commands in ctrl.proto
+ * Control commands in ctrl.proto for control server
  */
 var CTRL_CMD_GET_RADIO_STATE = 1
 var CTRL_CMD_SET_RADIO_STATE = 2
 
 /**
+ * Control commands in ctrl.proto that will be dispatched to
+ * simulatedRadio or simulatedIcc
+ */
+var CTRL_CMD_DISPATH_BASE    = 1000
+var CTRL_CMD_SET_MT_CALL     = 1001
+
+/* status for control commands, defined in ctrl.proto */
+var CTRL_STATUS_OK = 0
+var CTRL_STATUS_ERR = 1
+
+/**
  * Local requests from simulated_radio or simulated_icc
  */
 var CMD_DELAY_TEST = 2000
 var CMD_UNSOL_SIGNAL_STRENGTH = 2001
 var CMD_UNSOL_CALL_STATE_CHANGED = 2002    // Send RIL_UNSOL_CALL_STATE_CHANGED
 var CMD_CALL_STATE_CHANGE = 2003           // call state change: dialing->alert->active
+var CMD_UNSOL_CALL_RING = 2004
 
 /**
  * Other variables
index 46a8f51..87281c7 100644 (file)
@@ -53,28 +53,6 @@ function setRadioState(newState) {
 }
 
 /**
- * Create an incoming call 
- */
-function setMTCall(phoneNumber) {
-    print('createIncomingCall, number=' + phoneNumber + ' E');
-    
-    if (simulatedRadio.numberActiveCalls <= 0) {
-        // If there is no connection in use, the call state is INCOMING
-        state = CALLSTATE_INCOMING;
-    } else {
-        // If the incoming call is a second call, the state is WAITING
-        state = CALLSTATE_WAITING;
-    }
-    
-    // Add call to the call array
-    simulatedRadio.addCall(state, phoneNumber, '');
-    
-    // Send unsolicited response of call state change
-    simulatedRadioWorker.add(
-      {'reqNum' : CMD_UNSOL_CALL_STATE_CHANGED});
-}
-
-/**
  * Create a call.
  *
  * @return a RilCall
@@ -126,6 +104,8 @@ function Radio() {
     var maxNumberActiveCalls = 7;
     var maxConnectionsPerCall = 5; // only 5 connections allowed per call
 
+    // Flag to denote whether an incoming/waiting call is answered
+    var incomingCallIsAnswered = false;
 
     // Array of "active" calls
     var calls = Array(maxNumberActiveCalls + 1);
@@ -404,7 +384,9 @@ function Radio() {
                     switch (calls[i].state) {
                         case CALLSTATE_HOLDING:
                         case CALLSTATE_WAITING:
+                        case CALLSTATE_INCOMING:
                             this.removeCall(i);
+                            incomingCallIsAnswered = true;
                             break;
                         default:
                             result.rilErrCode = RIL_E_GENERIC_FAILURE;
@@ -639,6 +621,35 @@ function Radio() {
     }
 
     /**
+     * Handle RIL_REQUEST_ANSWER
+     *
+     * @param req is the Request
+     */
+    this.rilRequestAnswer = function(req) { // 40
+        print('Radio: rilRequestAnswer');
+
+        if (numberActiveCalls != 1) {
+            result.rilErrCode = RIL_E_GENERIC_FAILURE;
+            return result;
+        } else {
+            for (var i = 0; i < calls.length; i++) {
+                if (typeof calls[i] != 'undefined') {
+                    if (calls[i].state == CALLSTATE_INCOMING) {
+                        calls[i].state = CALLSTATE_ACTIVE;
+                        break;
+                    } else {
+                        result.rilErrCode = RIL_E_GENERIC_FAILURE;
+                        this.removeCall(i);
+                        return result;
+                    }
+                } // end of processing call[i]
+            } // end of for
+        }
+        incomingCallIsAnswered = true;
+        return result;
+    }
+
+    /**
      * Handle RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE
      *
      * @param req is the Request
@@ -843,6 +854,70 @@ function Radio() {
          result.sendResponse = false;
          return result;
      }
+
+     /**
+      * send UNSOL_CALL_STATE_CHANGED and UNSOL_CALL_RING
+      */
+     this.cmdUnsolCallRing = function(req) { // 2004
+         print('cmdUnsolCallRing: req.reqNum=' + req.reqNum);
+         sendRilUnsolicitedResponse(RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED);
+         sendRilUnsolicitedResponse(RIL_UNSOL_CALL_RING);
+
+         // Send the next alert in 3 seconds. [refer to ril.h definition]
+         simulatedRadioWorker.addDelayed(
+             {'reqNum' : CMD_UNSOL_CALL_RING}, 3000);
+         result.sendResponse = false;
+         return result;
+     }
+
+     /**
+      * Create an incoming call for the giving number
+      * return CTRL_STATUS_ERR if there is already a call in any of the states of
+      * dialing, alerting, incoming, waiting [TS 22 030 6.5] , else
+      * return CTRL_STATUS_OK and update the call state
+      */
+     this.ctrlServerCmdStartInComingCall = function(req) {  // 1001
+         print('ctrlServerCmdStartInComingCall: req.reqNum:' + req.reqNum);
+         print('ctrlServerCmdStartInComingCall: req.data.phonenumber:' + req.data.phoneNumber);
+
+         var phoneNumber = req.data.phoneNumber;
+         var state;
+
+         if (numberActiveCalls <= 0) {
+             // If there is no connection in use, the call state is INCOMING
+             state = CALLSTATE_INCOMING;
+         } else {
+             // If there is call in any of the states of dialing, alerting, incoming
+             // waiting, this MT call can not be set
+             for (var i  = 0; i < calls.length; i++) {
+                 if (typeof calls[i] != 'undefined') {
+                     if ( (calls[i].state == CALLSTATE_DIALING) ||
+                          (calls[i].state == CALLSTATE_ALERTING) ||
+                          (calls[i].state == CALLSTATE_INCOMING) ||
+                          (calls[i].state == CALLSTATE_WAITING))
+                     {
+                         result.rilErrCode = CTRL_STATUS_ERR;
+                         return result;
+                     }
+                 }
+             }
+             // If the incoming call is a second call, the state is WAITING
+             state = CALLSTATE_WAITING;
+         }
+
+         // Add call to the call array
+         this.addCall(state, phoneNumber, '');
+
+         // set the incomingCallIsAnswered flag to be false
+         incomingCallIsAnswered = false;
+
+         simulatedRadioWorker.add(
+           {'reqNum' : CMD_UNSOL_CALL_RING});
+
+         result.rilErrCode = CTRL_STATUS_OK;
+         return result;
+     }
+
     /**
      * Process the request by dispatching to the request handlers
      */
@@ -858,7 +933,11 @@ function Radio() {
             try {
                 // Pass "this" object to each ril request call such that
                 // they have the same scope
-                result = (this.radioDispatchTable[req.reqNum]).call(this, req);
+                if ((req.reqNum == CMD_UNSOL_CALL_RING) && incomingCallIsAnswered) {
+                    print('no need to send UNSOL_CALL_RING');
+                } else {
+                    result = (this.radioDispatchTable[req.reqNum]).call(this, req);
+                }
             } catch (err) {
                 print('Radio:process err = ' + err);
                 print('Radio: Unknown reqNum=' + req.reqNum);
@@ -869,10 +948,16 @@ function Radio() {
                 lastReq = req.reqNum;
             }
             if (result.sendResponse) {
-                sendRilRequestComplete(result.rilErrCode, req.reqNum,
-                        req.token, result.responseProtobuf);
+                if (isCtrlServerDispatchCommand(req.reqNum)) {
+                    print('Command ' + req.reqNum + ' is a control server command');
+                    sendCtrlRequestComplete(result.rilErrCode, req.reqNum,
+                      req.token, result.responseProtobuf);
+                } else {
+                    print('Request ' + req.reqNum + ' is a ril request');
+                    sendRilRequestComplete(result.rilErrCode, req.reqNum,
+                      req.token, result.responseProtobuf);
+                }
             }
-
             //print('Radio X: req.reqNum=' + req.reqNum + ' req.token=' + req.token);
         } catch (err) {
             print('Radio: Exception req.reqNum=' +
@@ -905,6 +990,8 @@ function Radio() {
                 this.rilRequestRegistrationState;
     this.radioDispatchTable[RIL_REQUEST_GPRS_REGISTRATION_STATE] = // 21
                 this.rilRequestGprsRegistrationState;
+    this.radioDispatchTable[RIL_REQUEST_ANSWER] = // 40
+                this.rilRequestAnswer;
     this.radioDispatchTable[RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE] = // 45
                 this.rilRequestQueryNeworkSelectionMode;
     this.radioDispatchTable[RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC] = // 46
@@ -918,6 +1005,9 @@ function Radio() {
     this.radioDispatchTable[RIL_REQUEST_SCREEN_STATE] = // 61
                 this.rilRequestScreenState;
 
+    this.radioDispatchTable[CTRL_CMD_SET_MT_CALL] = //1001
+                this.ctrlServerCmdStartInComingCall;
+
     this.radioDispatchTable[CMD_DELAY_TEST] = // 2000
                 this.cmdDelayTest;
     this.radioDispatchTable[CMD_UNSOL_SIGNAL_STRENGTH] =  // 2001
@@ -926,6 +1016,11 @@ function Radio() {
                 this.cmdUnsolCallStateChanged;
     this.radioDispatchTable[CMD_CALL_STATE_CHANGE] = //2003
                 this.cmdCallStateChange;
+    this.radioDispatchTable[CMD_UNSOL_CALL_RING] = //2004
+                this.cmdUnsolCallRing;
+
+    this.radioDispatchTable[CTRL_CMD_SET_MT_CALL] = //1001
+                this.ctrlServerCmdStartInComingCall;
 
     print('Radio: constructor X');
 }
index 05106d8..e6b027b 100644 (file)
  * limitations under the License.
  */
 
-
+/**
+ * TODO:update tests in the format of test incoming call
+ *      Have a global counter to count passes and failures
+ */
 /**
  * A test to test set signal strength
  */
@@ -82,6 +85,108 @@ if (false) {
 }
 
 /**
+ * A test for creating incoming call
+ */
+if (false) {
+    /* Only one incoming call is in the call list */
+    function verifyIncomingCall() {
+        var calls = simulatedRadio.getCalls();
+        var numIncomingCalls = 0;
+        for (var i = 0; i < calls.length; i++) {
+            if (typeof calls[i] != 'undefined') {
+                if (calls[i].state == CALLSTATE_INCOMING) {
+                    numIncomingCalls++;
+                }
+            }
+        }
+        return (numIncomingCalls == 1);
+    }
+
+    function testStartIncomingCall() {
+        print('testCreateIncomingCall E:');
+
+        var req = new Object();
+        req.reqNum = CTRL_CMD_SET_MT_CALL;
+        req.data = new Object();
+        req.data.phoneNumber = '6502249208';
+
+        var numberTestPass = 0;
+        var numberTestFail = 0;
+
+        // case 1: incoming call is the only active call
+        var result = new Object();
+        result = simulatedRadio.ctrlServerCmdStartInComingCall(req);
+        if ( (result.rilErrCode == CTRL_STATUS_OK) && verifyIncomingCall()) {
+            numberTestPass++;
+        } else {
+            numberTestFail++;
+            print('testStartIncomingCall: TEST CASE 1 FAIL');
+        }
+
+        // case 2: one incoming call, add another incoming call will fail
+        req.data.phoneNumber = '6502223456';
+        result = simulatedRadio.ctrlServerCmdStartInComingCall(req);
+        if ((result.rilErrCode == CTRL_STATUS_ERR) && verifyIncomingCall()) {
+            numberTestPass++;
+        } else {
+            numberTestFail++;
+            print('testStartIncomingCall: TEST CASE 2 FAIL');
+        }
+
+        // case 3: one dialing call, add another incoming call will fail
+        // Make the first call in dialing state
+        var calls = simulatedRadio.getCalls();
+        for (var i = 0; i < calls.length; i++) {
+            if (typeof calls[i] != 'undefined') {
+                if (calls[i].state == CALLSTATE_INCOMING) {
+                    calls[i].state = CALLSTATE_DIALING;
+                    break;
+                }
+            }
+        }
+        result = simulatedRadio.ctrlServerCmdStartInComingCall(req);
+        if (result.rilErrCode == CTRL_STATUS_ERR) {
+            numberTestPass++;
+        } else {
+            numberTestFail++;
+            print('testStartIncomingCall: TEST CASE 3 FAIL');
+        }
+
+        // case 4: one dialing call, adding another incoming call will fail
+        calls[i].state = CALLSTATE_ALERTING;
+        result = simulatedRadio.ctrlServerCmdStartInComingCall(req);
+        if (result.rilErrCode == CTRL_STATUS_ERR) {
+            numberTestPass++;
+        } else {
+            numberTestFail++;
+            print('testStartIncomingCall: TEST CASE 4 FAIL');
+        }
+
+        // case 5: one active call, adding another incoming call will succeed
+        calls[i].state = CALLSTATE_ACTIVE;
+        result = simulatedRadio.ctrlServerCmdStartInComingCall(req);
+        if (result.rilErrCode == CTRL_STATUS_OK) {
+            numberTestPass++;
+        } else {
+            numberTestFail++;
+            print('testStartIncomingCall: TEST CASE 5 FAIL');
+        }
+
+        print('*************TEST RESULT ****************');
+        print('Number of Test Passed: ' + numberTestPass);
+        print('Number of Test Failed: ' + numberTestFail);
+        print('************   End **********************');
+        // after the test, remove any calls
+        for (i = 0; i < calls.length; i++) {
+            simulatedRadio.removeCall(i);
+        }
+        print('testStartIncomingCall X:');
+    }
+
+    testStartIncomingCall();
+}
+
+/**
  * A test for RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND
  */
 if (false) {
index e835c67..30ca6fd 100644 (file)
@@ -12,7 +12,7 @@ enum CtrlCmd {
   CTRL_CMD_ECHO = 0;
   CTRL_CMD_GET_RADIO_STATE      = 1;
   CTRL_CMD_SET_RADIO_STATE      = 2;
-  CTRL_CMD_SET_MT_CALL = 3;
+  CTRL_CMD_SET_MT_CALL          = 1001;
 }
 
 enum CtrlStatus {