Bug 993255 - Part 4: Fix hang up pending outgoing call. r=hsinyi
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Tue, 29 Apr 2014 10:02:20 +0800
changeset 181148 2b844dff91b3123d4c797944c6cf82cc298f2ad1
parent 181147 0340af9aed4631ac788d121482b33e472a87d5ce
child 181149 a507a8d9a79ed43428abb806ae965d91f42ee961
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewershsinyi
bugs993255
milestone32.0a1
Bug 993255 - Part 4: Fix hang up pending outgoing call. r=hsinyi
dom/system/gonk/ril_worker.js
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -219,16 +219,18 @@ function RilObject(aContext) {
   this._pendingSentSmsMap = {};
   this.pendingNetworkType = {};
   this._receivedSmsCbPagesMap = {};
 
   // Init properties that are only initialized once.
   this.v5Legacy = RILQUIRKS_V5_LEGACY;
   this.cellBroadcastDisabled = RIL_CELLBROADCAST_DISABLED;
   this.clirMode = RIL_CLIR_MODE;
+
+  this._hasHangUpPendingOutgoingCall = false;
 }
 RilObject.prototype = {
   context: null,
 
   v5Legacy: null,
 
   /**
    * Valid calls.
@@ -413,16 +415,21 @@ RilObject.prototype = {
     /**
      * Cell Broadcast Search Lists.
      */
     let cbmmi = this.cellBroadcastConfigs && this.cellBroadcastConfigs.MMI;
     this.cellBroadcastConfigs = {
       MMI: cbmmi || null
     };
     this.mergedCellBroadcastConfig = null;
+
+    /**
+     * True if the pending outgoing call is hung up by user.
+     */
+    this._hasHangUpPendingOutgoingCall = false;
   },
 
   /**
    * Parse an integer from a string, falling back to a default value
    * if the the provided value is not a string or does not contain a valid
    * number.
    *
    * @param string
@@ -1542,16 +1549,17 @@ RilObject.prototype = {
     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;
     }
 
     call.hangUpLocal = true;
 
     if (call.state === CALL_STATE_HOLDING) {
       this.sendHangUpBackgroundRequest(callIndex);
@@ -3865,31 +3873,37 @@ RilObject.prototype = {
         // 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) {
-        if (newCall.isMpty) {
-          conferenceChanged = true;
-        }
-        if (!pendingOutgoingCall &&
-            (newCall.state === CALL_STATE_DIALING ||
-             newCall.state === CALL_STATE_ALERTING)) {
-          // Receive a new outgoing call which is already hung up by user.
-          if (DEBUG) this.context.debug("Pending outgoing call is hung up by user.");
-          this.sendHangUpRequest(newCall.callIndex);
-        } else {
-          this._addNewVoiceCall(newCall);
-        }
-      }
-    }
+      if (!newCall.isVoice) {
+        continue;
+      }
+
+      if (newCall.isMpty) {
+        conferenceChanged = true;
+      }
+
+      if (this._hasHangUpPendingOutgoingCall &&
+          (newCall.state === CALL_STATE_DIALING ||
+           newCall.state === CALL_STATE_ALERTING)) {
+        // Receive a new outgoing call which is already hung up by user.
+        if (DEBUG) this.context.debug("Pending outgoing call is hung up by user.");
+        this._hasHangUpPendingOutgoingCall = false;
+        this.sendHangUpRequest(newCall.callIndex);
+      } else {
+        this._addNewVoiceCall(newCall);
+      }
+    }
+
+    this._hasHangUpPendingOutgoingCall = false;
 
     if (clearConferenceRequest) {
       this._hasConferenceRequest = false;
     }
     if (conferenceChanged) {
       this._ensureConference();
     }
   },
@@ -3956,17 +3970,17 @@ RilObject.prototype = {
 
   _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(pendingOutgoingCall, failCause);
+    this._removeVoiceCall(call, failCause);
   },
 
   _ensureConference: function() {
     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.
@@ -5359,16 +5373,17 @@ RilObject.prototype[REQUEST_GET_CURRENT_
   }
   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) {
     this.getFailCauseCode((function(failCause) {
       this._removePendingOutgoingCall(failCause);
+      this._hasHangUpPendingOutgoingCall = false;
     }).bind(this));
   }
 };
 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;
   }