From 08d3ecb8a3ca7cac3b29aa9fab85145c342d55f2 Mon Sep 17 00:00:00 2001 From: Gene Lian Date: Mon, 24 Jun 2013 20:08:30 +0800 Subject: [PATCH] Bug 885652 - B2G SMS: DOMRequest in sending SMS API does not trigger onsuccess or onerror function when the SIM card is not installed or radio is disabled. r=vicamo a=leo+ --- dom/mobilemessage/src/ril/MmsService.js | 6 +++--- dom/system/gonk/RadioInterfaceLayer.js | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/dom/mobilemessage/src/ril/MmsService.js b/dom/mobilemessage/src/ril/MmsService.js index 1c6a6696013b..022e57e75c40 100644 --- a/dom/mobilemessage/src/ril/MmsService.js +++ b/dom/mobilemessage/src/ril/MmsService.js @@ -1454,7 +1454,7 @@ MmsService.prototype = { send: function send(aParams, aRequest) { if (DEBUG) debug("send: aParams: " + JSON.stringify(aParams)); if (aParams.receivers.length == 0) { - aRequest.notifySendMmsMessageFailed(Ci.nsIMobileMessageCallback.INTERNAL_ERROR); + aRequest.notifySendMessageFailed(Ci.nsIMobileMessageCallback.INTERNAL_ERROR); return; } @@ -1497,14 +1497,14 @@ MmsService.prototype = { if (DEBUG) debug("Saving sending message is done. Start to send."); // For radio disabled error. - if(gMmsConnection.radioDisabled) { + if (gMmsConnection.radioDisabled) { if (DEBUG) debug("Error! Radio is disabled when sending MMS."); sendTransactionCb(aDomMessage.id, Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR); return; } // For SIM card is not ready. - if(gRIL.rilContext.cardState != "ready") { + if (gRIL.rilContext.cardState != "ready") { if (DEBUG) debug("Error! SIM card is not ready when sending MMS."); sendTransactionCb(aDomMessage.id, Ci.nsIMobileMessageCallback.NO_SIM_CARD_ERROR); return; diff --git a/dom/system/gonk/RadioInterfaceLayer.js b/dom/system/gonk/RadioInterfaceLayer.js index d60e1e04b3af..bcd1d440d8e2 100644 --- a/dom/system/gonk/RadioInterfaceLayer.js +++ b/dom/system/gonk/RadioInterfaceLayer.js @@ -2840,6 +2840,30 @@ RadioInterfaceLayer.prototype = { // TODO bug 832140 handle !Components.isSuccessCode(rv) Services.obs.notifyObservers(domMessage, kSmsSendingObserverTopic, null); + // If the radio is disabled or the SIM card is not ready, just directly + // return with the corresponding error code. + let errorCode; + if (!this._radioEnabled) { + debug("Error! Radio is disabled when sending SMS."); + errorCode = Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR; + } else if (this.rilContext.cardState != "ready") { + debug("Error! SIM card is not ready when sending SMS."); + errorCode = Ci.nsIMobileMessageCallback.NO_SIM_CARD_ERROR; + } + if (errorCode) { + gMobileMessageDatabaseService + .setMessageDelivery(domMessage.id, + null, + DOM_MOBILE_MESSAGE_DELIVERY_ERROR, + RIL.GECKO_SMS_DELIVERY_STATUS_ERROR, + function notifyResult(rv, domMessage) { + // TODO bug 832140 handle !Components.isSuccessCode(rv) + request.notifySendMessageFailed(errorCode); + Services.obs.notifyObservers(domMessage, kSmsFailedObserverTopic, null); + }); + return; + } + // Keep current SMS message info for sent/delivered notifications options.envelopeId = this.createSmsEnvelope({ request: request,