Bug 999334 - Redesign pending outgoing call mechanism. r=hsinyi a=1.3t+
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Tue, 29 Apr 2014 13:48:23 -0700
changeset 171832 3c5c7e61b5895156d68b4a478b0185cb37755fbe
parent 171831 97952535b72db8ae530f179135aed9da1db3a94d
child 171833 bc5f0e461c9ecd6df64f4129dc804578a395abd2
push id389
push userfdesre@mozilla.com
push dateTue, 29 Apr 2014 20:48:34 +0000
reviewershsinyi, 1.3t
bugs999334
milestone28.1
Bug 999334 - Redesign pending outgoing call mechanism. r=hsinyi a=1.3t+
dom/system/gonk/ril_worker.js
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -1485,16 +1485,18 @@ RilObject.prototype = {
       this.setRadioEnabled({enabled: true});
       return;
     }
 
     this.sendDialRequest(options);
   },
 
   sendDialRequest: function sendDialRequest(options) {
+    this._createPendingOutgoingCall(options);
+
     let Buf = this.context.Buf;
     Buf.newParcel(options.request, options);
     Buf.writeString(options.number);
     Buf.writeInt32(options.clirMode || 0);
     Buf.writeInt32(options.uusInfo || 0);
     // TODO Why do we need this extra 0? It was put it in to make this
     // match the format of the binary message.
     Buf.writeInt32(0);
@@ -1519,16 +1521,17 @@ RilObject.prototype = {
   hangUp: function hangUp(options) {
     let call = this.currentCalls[options.callIndex];
     if (!call) {
       return;
     }
 
     let callIndex = call.callIndex;
     if (callIndex === OUTGOING_PLACEHOLDER_CALL_INDEX) {
+      if (DEBUG) this.context.debug("Hang up pending outgoing call.");
       this._hasHangUpPendingOutgoingCall = true;
       this._removeVoiceCall(call, GECKO_CALL_ERROR_NORMAL_CALL_CLEARING);
       return;
     }
 
     if (call.state === CALL_STATE_HOLDING) {
       this.sendHangUpBackgroundRequest(callIndex);
     } else {
@@ -3703,24 +3706,24 @@ RilObject.prototype = {
         this.currentConference.cache[currentCall.callIndex] = newCall;
         currentCall.state = newCall.state;
         currentCall.isMpty = newCall.isMpty;
         conferenceChanged = true;
       }
     }
 
     if (pendingOutgoingCall) {
-      // We don't get a successful call for pendingOutgoingCall.
       if (!newCalls || Object.keys(newCalls).length === 0) {
-        if (DEBUG) this.context.debug("No result for pending outgoing call.");
-        pendingOutgoingCall.failCause = GECKO_CALL_ERROR_UNSPECIFIED;
-        this._handleDisconnectedCall(pendingOutgoingCall);
-      }
-
-      delete this.currentCalls[OUTGOING_PLACEHOLDER_CALL_INDEX];
+        // We don't get a successful call for pendingOutgoingCall.
+        this._removePendingOutgoingCall(GECKO_CALL_ERROR_UNSPECIFIED);
+      } else {
+        // Only remove it from currentCalls map. Will use the new call to
+        // replace the placeholder.
+        delete this.currentCalls[OUTGOING_PLACEHOLDER_CALL_INDEX];
+      }
     }
 
     // Go through any remaining calls that are new to us.
     for each (let newCall in newCalls) {
       if (!newCall.isVoice) {
         continue;
       }
 
@@ -3793,16 +3796,35 @@ RilObject.prototype = {
         removedCall.failCause = failCause;
         this._handleDisconnectedCall(removedCall);
       } else {
         this.getFailCauseCode(removedCall);
       }
     }
   },
 
+  _createPendingOutgoingCall: function(options) {
+    if (DEBUG) this.context.debug("Create a pending outgoing call.");
+    this._addNewVoiceCall({
+      number: options.number,
+      state: CALL_STATE_DIALING,
+      callIndex: OUTGOING_PLACEHOLDER_CALL_INDEX
+    });
+  },
+
+  _removePendingOutgoingCall: function(failCause) {
+    let call = this.currentCalls[OUTGOING_PLACEHOLDER_CALL_INDEX];
+    if (!call) {
+      return;
+    }
+
+    if (DEBUG) this.context.debug("Remove pending outgoing call.");
+    this._removeVoiceCall(call, failCause);
+  },
+
   _ensureConference: function _ensureConference() {
     let oldState = this.currentConference.state;
     let remaining = Object.keys(this.currentConference.participants);
 
     if (remaining.length == 1) {
       // Remove that if only does one remain in a conference call.
       let call = this.currentCalls[remaining[0]];
       call.isConference = false;
@@ -5220,31 +5242,24 @@ RilObject.prototype[REQUEST_GET_CURRENT_
       };
     }
 
     calls[call.callIndex] = call;
   }
   this._processCalls(calls);
 };
 RilObject.prototype[REQUEST_DIAL] = function REQUEST_DIAL(length, options) {
+  // We already return a successful response before. Don't respond it again!
   if (options.rilRequestError) {
-    // The connection is not established yet.
     options.callIndex = -1;
-    this.getFailCauseCode(options);
+    this._removePendingOutgoingCall(GECKO_CALL_ERROR_UNSPECIFIED);
     this._hasHangUpPendingOutgoingCall = false;
-  } else {
-    // Create a pending outgoing call.
-    if (DEBUG) this.context.debug("Create a pending outgoing call.");
-    this._addNewVoiceCall({
-      number: options.number,
-      state: CALL_STATE_DIALING,
-      callIndex: OUTGOING_PLACEHOLDER_CALL_INDEX
-    });
-  }
-};
+  }
+};
+RilObject.prototype[REQUEST_DIAL_EMERGENCY_CALL] = RilObject.prototype[REQUEST_DIAL];
 RilObject.prototype[REQUEST_GET_IMSI] = function REQUEST_GET_IMSI(length, options) {
   if (options.rilRequestError) {
     return;
   }
 
   this.iccInfoPrivate.imsi = this.context.Buf.readString();
   if (DEBUG) {
     this.context.debug("IMSI: " + this.iccInfoPrivate.imsi);