Bug 1103731 - Part 1: Internal architecture (TelephonySerive.js). r=aknow
authorBen Hsu <bhsu@mozilla.com>
Mon, 19 Jan 2015 21:32:00 -0500
changeset 226489 4ff3dd299e6a3061193809c0e77672fdbb78ae94
parent 226364 9db3770660dfa707ff7928921b51dccd84d2a9dc
child 226490 422bed2705ee75d95574385aef6bf17321c2ad69
push id28198
push usercbook@mozilla.com
push dateThu, 29 Jan 2015 15:11:14 +0000
treeherdermozilla-central@0467412f8413 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaknow
bugs1103731
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1103731 - Part 1: Internal architecture (TelephonySerive.js). r=aknow
dom/telephony/gonk/TelephonyService.js
--- a/dom/telephony/gonk/TelephonyService.js
+++ b/dom/telephony/gonk/TelephonyService.js
@@ -580,38 +580,53 @@ TelephonyService.prototype = {
       aClientId = gRadioInterfaceLayer.getClientIdForEmergencyCall() ;
       if (aClientId === -1) {
         if (DEBUG) debug("Error: No client is avaialble for emergency call.");
         aCallback.notifyError(DIAL_ERROR_INVALID_STATE_ERROR);
         return;
       }
     }
 
-    // Before we dial, we have to hold the active call first.
+    // If there is no active call, we can dial a new call directly.
     let activeCall = this._getOneActiveCall(aClientId);
     if (!activeCall) {
       this._sendDialCallRequest(aClientId, aOptions, aCallback);
-    } else {
-      if (DEBUG) debug("There is an active call. Hold it first before dial.");
+      return;
+    }
+
+    // Otherwise, we should hold the active call before dialing another one.
+    if (DEBUG) debug("There is an active call. Hold it first before dial.");
 
-      this._cachedDialRequest = {
-        clientId: aClientId,
-        options: aOptions,
-        callback: aCallback
-      };
+    if (this._cachedDialRequest) {
+      if (DEBUG) debug("Error: There already is a pending dial request.");
+      aCallback.notifyError(DIAL_ERROR_INVALID_STATE_ERROR);
+      return;
+    }
+
+    let autoHoldCallback = {
+      QueryInterface: XPCOMUtils.generateQI([Ci.nsITelephonyCallback]),
 
-      if (activeCall.isConference) {
-        this.holdConference(aClientId,
-                            { notifySuccess: function () {},
-                              notifyError: function (errorMsg) {} });
-      } else {
-        this.holdCall(aClientId, activeCall.callIndex,
-                      { notifySuccess: function () {},
-                        notifyError: function (errorMsg) {} });
+      notifySuccess: () => {
+        this._cachedDialRequest = {
+          clientId: aClientId,
+          options: aOptions,
+          callback: aCallback
+        };
+      },
+
+      notifyError: (aErrorMsg) => {
+        if (DEBUG) debug("Error: Fail to automatically hold the active call.");
+        aCallback.notifyError(aErrorMsg);
       }
+    };
+
+    if (activeCall.isConference) {
+      this.holdConference(aClientId, autoHoldCallback);
+    } else {
+      this.holdCall(aClientId, activeCall.callIndex, autoHoldCallback);
     }
   },
 
   _sendDialCallRequest: function(aClientId, aOptions, aCallback) {
     this._isDialing = true;
 
     this._sendToRilWorker(aClientId, "dial", aOptions, response => {
       this._isDialing = false;