Bug 990472 - Part 1: Refactor: check of call on other client. r=hsinyi
authorSzu-Yu Chen [:aknow] <szchen@mozilla.com>
Wed, 16 Apr 2014 10:26:50 -0400
changeset 178876 c36ef908c673266fdb5f26a95d76f20874d30a7f
parent 178875 c48e44a0e5d128ba198b7da24ba1876f4bd1d613
child 178877 7d26e5a537d86ded99dfc347e542a1fb83159bde
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewershsinyi
bugs990472
milestone31.0a1
Bug 990472 - Part 1: Refactor: check of call on other client. r=hsinyi
dom/telephony/gonk/TelephonyProvider.js
--- a/dom/telephony/gonk/TelephonyProvider.js
+++ b/dom/telephony/gonk/TelephonyProvider.js
@@ -425,29 +425,31 @@ TelephonyProvider.prototype = {
     if (DEBUG) debug("Dialing " + (aIsEmergency ? "emergency " : "") + aNumber);
 
     if (this.isDialing) {
       if (DEBUG) debug("Already has a dialing call. Drop.");
       aTelephonyCallback.notifyDialError(DIAL_ERROR_INVALID_STATE_ERROR);
       return;
     }
 
-    // For DSDS, if there is aleady a call on SIM X, we cannot place any new
-    // call on other SIM.
-    let callOnOtherSim = false;
-    for (let cid = 0; cid < this._numClients; ++cid) {
-      if (cid === aClientId) {
-        continue;
+    function hasCallsOnOtherClient(aClientId) {
+      for (let cid = 0; cid < this._numClients; ++cid) {
+        if (cid === aClientId) {
+          continue;
+        }
+        if (Object.keys(this._currentCalls[cid]).length !== 0) {
+          return true;
+        }
       }
-      if (Object.keys(this._currentCalls[cid]).length !== 0) {
-        callOnOtherSim = true;
-        break;
-      }
+      return false;
     }
-    if (callOnOtherSim) {
+
+    // For DSDS, if there is aleady a call on SIM 'aClientId', we cannot place
+    // any new call on other SIM.
+    if (hasCallsOnOtherClient.call(this, aClientId)) {
       if (DEBUG) debug("Already has a call on other sim. Drop.");
       aTelephonyCallback.notifyDialError(DIAL_ERROR_OTHER_CONNECTION_IN_USE);
       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) {