Bug 1077075 - Part 4: Internal architecture (TelephonyService.js). r=aknow
authorBen Hsu <bhsu@mozilla.com>
Tue, 23 Dec 2014 19:06:00 -0500
changeset 247919 935a274524336b744e15167cbb273ef395d4cbfa
parent 247918 ae350b46932a368c6309699a1b6a1d5644e3ed20
child 247920 f05cb6eb5ff8cbde5425dfe7094f5b6166388496
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaknow
bugs1077075
milestone37.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 1077075 - Part 4: Internal architecture (TelephonyService.js). r=aknow
dom/telephony/gonk/TelephonyService.js
--- a/dom/telephony/gonk/TelephonyService.js
+++ b/dom/telephony/gonk/TelephonyService.js
@@ -492,17 +492,17 @@ TelephonyService.prototype = {
         }
       };
 
       if (aNumber === "0") {
         this._sendToRilWorker(aClientId, "hangUpBackground", null, mmiCallback);
       } else if (aNumber === "1") {
         this._sendToRilWorker(aClientId, "hangUpForeground", null, mmiCallback);
       } else if (aNumber[0] === "1" && aNumber.length === 2) {
-        this._sendToRilWorker(aClientId, "hangUp",
+        this._sendToRilWorker(aClientId, "hangUpCall",
                               { callIndex: parseInt(aNumber[1]) }, mmiCallback);
       } else if (aNumber === "2") {
         this._sendToRilWorker(aClientId, "switchActiveCall", null, mmiCallback);
       } else if (aNumber[0] === "2" && aNumber.length === 2) {
         this._sendToRilWorker(aClientId, "separateCall",
                               { callIndex: parseInt(aNumber[1]) }, mmiCallback);
       } else if (aNumber === "3") {
         this._sendToRilWorker(aClientId, "conferenceCall", null, mmiCallback);
@@ -584,17 +584,19 @@ TelephonyService.prototype = {
         clientId: aClientId,
         options: aOptions,
         callback: aCallback
       };
 
       if (activeCall.isConference) {
         this.holdConference(aClientId);
       } else {
-        this.holdCall(aClientId, activeCall.callIndex);
+        this.holdCall(aClientId, activeCall.callIndex,
+                      { notifySuccess: function () {},
+                        notifyError: function (errorMsg) {} });
       }
     }
   },
 
   _sendDialCallRequest: function(aClientId, aOptions, aCallback) {
     this._isDialing = true;
 
     this._sendToRilWorker(aClientId, "dial", aOptions, response => {
@@ -874,63 +876,82 @@ TelephonyService.prototype = {
         return RIL.MMI_KS_SC_CALL_WAITING;
       case RIL.MMI_SC_CHANGE_PASSWORD:
         return RIL.MMI_KS_SC_CHANGE_PASSWORD;
       default:
         return RIL.MMI_KS_SC_USSD;
     }
   },
 
-  hangUp: function(aClientId, aCallIndex) {
-    let parentId = this._currentCalls[aClientId][aCallIndex].parentId;
-    if (parentId) {
-      // Should release both, child and parent, together. Since RIL holds only
-      // the parent call, we send 'parentId' to RIL.
-      this.hangUp(aClientId, parentId);
+  /**
+   * The default callback handler for call operations.
+   *
+   * @param aCallback
+   *        An callback object including notifySuccess() and notifyError(aMsg)
+   * @param aResponse
+   *        The response from ril_worker.
+   */
+  _defaultCallbackHandler: function(aCallback, aResponse) {
+    if (!aResponse.success) {
+      aCallback.notifyError(aResponse.errorMsg);
     } else {
-      this._sendToRilWorker(aClientId, "hangUp", { callIndex: aCallIndex });
+      aCallback.notifySuccess();
     }
   },
 
   startTone: function(aClientId, aDtmfChar) {
     this._sendToRilWorker(aClientId, "startTone", { dtmfChar: aDtmfChar });
   },
 
   stopTone: function(aClientId) {
     this._sendToRilWorker(aClientId, "stopTone");
   },
 
-  answerCall: function(aClientId, aCallIndex) {
-    this._sendToRilWorker(aClientId, "answerCall", { callIndex: aCallIndex });
+  answerCall: function(aClientId, aCallIndex, aCallback) {
+    this._sendToRilWorker(aClientId, "answerCall", { callIndex: aCallIndex },
+                          this._defaultCallbackHandler.bind(this, aCallback));
+  },
+
+  rejectCall: function(aClientId, aCallIndex, aCallback) {
+    this._sendToRilWorker(aClientId, "rejectCall", { callIndex: aCallIndex },
+                          this._defaultCallbackHandler.bind(this, aCallback));
   },
 
-  rejectCall: function(aClientId, aCallIndex) {
-    this._sendToRilWorker(aClientId, "rejectCall", { callIndex: aCallIndex });
+  hangUpCall: function(aClientId, aCallIndex, aCallback) {
+    let parentId = this._currentCalls[aClientId][aCallIndex].parentId;
+    if (parentId) {
+      // Should release both, child and parent, together. Since RIL holds only
+      // the parent call, we send 'parentId' to RIL.
+      this.hangUpCall(aClientId, parentId, aCallback);
+    } else {
+      this._sendToRilWorker(aClientId, "hangUpCall", { callIndex: aCallIndex },
+                            this._defaultCallbackHandler.bind(this, aCallback));
+    }
   },
 
-  holdCall: function(aClientId, aCallIndex) {
+  holdCall: function(aClientId, aCallIndex, aCallback) {
     let call = this._currentCalls[aClientId][aCallIndex];
     if (!call || !call.isSwitchable) {
-      // TODO: Bug 975949 - [B2G] Telephony should throw exceptions when some
-      // operations aren't allowed instead of simply ignoring them.
+      aCallback.notifyError(RIL.GECKO_ERROR_GENERIC_FAILURE);
       return;
     }
 
-    this._sendToRilWorker(aClientId, "holdCall", { callIndex: aCallIndex });
+    this._sendToRilWorker(aClientId, "holdCall", { callIndex: aCallIndex },
+                          this._defaultCallbackHandler.bind(this, aCallback));
   },
 
-  resumeCall: function(aClientId, aCallIndex) {
+  resumeCall: function(aClientId, aCallIndex, aCallback) {
     let call = this._currentCalls[aClientId][aCallIndex];
     if (!call || !call.isSwitchable) {
-      // TODO: Bug 975949 - [B2G] Telephony should throw exceptions when some
-      // operations aren't allowed instead of simply ignoring them.
+      aCallback.notifyError(RIL.GECKO_ERROR_GENERIC_FAILURE);
       return;
     }
 
-    this._sendToRilWorker(aClientId, "resumeCall", { callIndex: aCallIndex });
+    this._sendToRilWorker(aClientId, "resumeCall", { callIndex: aCallIndex },
+                          this._defaultCallbackHandler.bind(this, aCallback));
   },
 
   conferenceCall: function(aClientId) {
     let indexes = Object.keys(this._currentCalls[aClientId]);
     if (indexes.length < 2) {
       // TODO: Bug 975949 - [B2G] Telephony should throw exceptions when some
       // operations aren't allowed instead of simply ignoring them.
       return;