Bug 969218 - Part 5: gonk provider r=htsai
☠☠ backed out by 677c0fa83472 ☠ ☠
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Wed, 26 Feb 2014 11:03:56 -0800
changeset 171158 46fa16a18c2775c5a72a1bd7aecbbdaebae897a2
parent 171157 75219ceb5175014a94b6a8a767981f1ddb8dd1a9
child 171159 86356906ecf0089b36dbd22e3c0873bceef8ddff
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewershtsai
bugs969218
milestone30.0a1
Bug 969218 - Part 5: gonk provider r=htsai
dom/telephony/gonk/TelephonyProvider.js
--- a/dom/telephony/gonk/TelephonyProvider.js
+++ b/dom/telephony/gonk/TelephonyProvider.js
@@ -395,44 +395,54 @@ TelephonyProvider.prototype = {
     for (let i = 0; i < this._numClients; ++i) {
       promise = promise.then(this._enumerateCallsForClient.bind(this, i, aListener));
     }
     promise.then(function() {
       aListener.enumerateCallStateComplete();
     });
   },
 
-  dial: function(aClientId, aNumber, aIsEmergency) {
+  isDialing: false,
+  dial: function(aClientId, aNumber, aIsEmergency, aTelephonyCallback) {
     if (DEBUG) debug("Dialing " + (aIsEmergency ? "emergency " : "") + aNumber);
 
+    if (this.isDialing) {
+      if (DEBUG) debug("Already has a dialing call. Drop.");
+      aTelephonyCallback.notifyDialError("InvalidStateError");
+      return;
+    }
+
     // we don't try to be too clever here, as the phone is probably in the
     // locked state. Let's just check if it's a number without normalizing
     if (!aIsEmergency) {
       aNumber = gPhoneNumberUtils.normalize(aNumber);
     }
 
+    // Validate the number.
     if (!gPhoneNumberUtils.isPlainPhoneNumber(aNumber)) {
       // Note: isPlainPhoneNumber also accepts USSD and SS numbers
       if (DEBUG) debug("Number '" + aNumber + "' is not viable. Drop.");
       let errorMsg = RIL.RIL_CALL_FAILCAUSE_TO_GECKO_CALL_ERROR[RIL.CALL_FAIL_UNOBTAINABLE_NUMBER];
-      Services.tm.currentThread.dispatch(
-        this.notifyCallError.bind(this, aClientId, -1, errorMsg),
-        Ci.nsIThread.DISPATCH_NORMAL);
+      aTelephonyCallback.notifyDialError(errorMsg);
       return;
     }
 
+    this.isDialing = true;
     this._getClient(aClientId).sendWorkerMessage("dial", {
       number: aNumber,
       isDialEmergency: aIsEmergency
-    }, (function(clientId, response) {
-      if (!response.success) {
-        this.notifyCallError(clientId, -1, response.errorMsg);
+    }, (function(response) {
+      this.isDialing = false;
+      if (response.success) {
+        aTelephonyCallback.notifyDialSuccess();
+      } else {
+        aTelephonyCallback.notifyDialError(response.errorMsg);
       }
       return false;
-    }).bind(this, aClientId));
+    }).bind(this));
   },
 
   hangUp: function(aClientId, aCallIndex) {
     this._getClient(aClientId).sendWorkerMessage("hangUp", { callIndex: aCallIndex });
   },
 
   startTone: function(aClientId, aDtmfChar) {
     this._getClient(aClientId).sendWorkerMessage("startTone", { dtmfChar: aDtmfChar });