From 5536feadca39e2ad93c0a449ee37df68e8be98a3 Mon Sep 17 00:00:00 2001 From: Benoit Chabod Date: Fri, 28 Aug 2015 13:41:02 +0200 Subject: [PATCH] Apply new API, resolve promise instead of system message --- dom/telephony/gonk/TelephonyService.js | 30 +++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/dom/telephony/gonk/TelephonyService.js b/dom/telephony/gonk/TelephonyService.js index 6c851bda59143..deb6454c8bf20 100644 --- a/dom/telephony/gonk/TelephonyService.js +++ b/dom/telephony/gonk/TelephonyService.js @@ -361,6 +361,7 @@ function TelephonyService() { this._currentConferenceState = nsITelephonyService.CALL_STATE_UNKNOWN; this._audioStates = []; this._ussdSessions = []; + this._ussdCallbacks = []; this._cdmaCallWaitingNumber = null; @@ -375,6 +376,7 @@ function TelephonyService() { for (let i = 0; i < this._numClients; ++i) { this._audioStates[i] = nsITelephonyAudioService.PHONE_STATE_NORMAL; this._ussdSessions[i] = false; + this._ussdCallbacks[i] = null; this._currentCalls[i] = {}; this._enumerateCallsForClient(i); } @@ -405,6 +407,7 @@ TelephonyService.prototype = { * b) Receiving a session end unsolicited event. */ _ussdSessions: null, + _ussdCallbacks: null, _acquireCallRingWakeLock: function() { if (!this._callRingWakeLock) { @@ -1679,7 +1682,7 @@ TelephonyService.prototype = { * The response from ril_worker. */ _defaultCallbackHandler: function(aCallback, aResponse) { - if (aResponse.errorMsg) { + if (aResponse && aResponse.errorMsg) { aCallback.notifyError(aResponse.errorMsg); } else { aCallback.notifySuccess(); @@ -1687,10 +1690,10 @@ TelephonyService.prototype = { }, _defaultMMICallbackHandler: function(aCallback, aResponse) { - if (aResponse.errorMsg) { + if (aResponse && aResponse.errorMsg) { aCallback.notifyDialMMIError(aResponse.errorMsg); } else { - aCallback.notifyDialMMISuccess(""); + aCallback.notifyDialMMISuccess(aResponse); } }, @@ -2149,10 +2152,8 @@ TelephonyService.prototype = { }, _sendUSSDInternal: function(aClientId, aUssd, aCallback) { - this._sendToRilWorker(aClientId, "sendUSSD", { ussd: aUssd }, aResponse => { - this._ussdSessions[aClientId] = !aResponse.errorMsg; - aCallback(aResponse); - }); + this._ussdCallbacks[aClientId] = aCallback; + this._sendToRilWorker(aClientId, "sendUSSD", { ussd: aUssd }, aResponse => {}); }, cancelUSSD: function(aClientId, aCallback) { @@ -2162,10 +2163,8 @@ TelephonyService.prototype = { }, _cancelUSSDInternal: function(aClientId, aCallback) { - this._sendToRilWorker(aClientId, "cancelUSSD", {}, aResponse => { - this._ussdSessions[aClientId] = !!aResponse.errorMsg; - aCallback(aResponse); - }); + this._ussdCallbacks[aClientId] = aCallback; + this._sendToRilWorker(aClientId, "cancelUSSD", {}, aResponse => {}); }, get microphoneMuted() { @@ -2444,7 +2443,14 @@ TelephonyService.prototype = { return; } - gTelephonyMessenger.notifyUssdReceived(aClientId, aMessage, aSessionEnded); + // If there is a callback registered, call it + if (this._ussdCallbacks[aClientId]) { + this._ussdCallbacks[aClientId](aMessage); + this._ussdCallbacks[aClientId] = null; + } else { + gTelephonyMessenger.notifyUssdReceived(aClientId, aMessage, aSessionEnded); + } + }, /**