Bug 727319 - Part 2: notify SMS send failed. r=philikon
authorVicamo Yang <vyang@mozilla.com>
Thu, 05 Apr 2012 14:16:56 -0700
changeset 91121 52643779c4d85e6c96b9b901abde96705ef02064
parent 91120 25b1bf1420ab8909e0dbaa146c6b41de01299914
child 91122 701495278c158b0fe22c322a1b37b06eae1eba2c
push id667
push usertim.taubert@gmx.de
push dateTue, 10 Apr 2012 10:56:50 +0000
treeherderfx-team@6fe5b0271cd1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilikon
bugs727319
milestone14.0a1
Bug 727319 - Part 2: notify SMS send failed. r=philikon
dom/system/gonk/RadioInterfaceLayer.js
dom/system/gonk/ril_consts.js
dom/system/gonk/ril_worker.js
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -257,16 +257,19 @@ RadioInterfaceLayer.prototype = {
         this.handleSmsReceived(message);
         return;
       case "sms-sent":
         this.handleSmsSent(message);
         return;
       case "sms-delivered":
         this.handleSmsDelivered(message);
         return;
+      case "sms-send-failed":
+        this.handleSmsSendFailed(message);
+        return;
       case "datacallstatechange":
         this.handleDataCallState(message.datacall);
         break;
       case "datacalllist":
         this.handleDataCallList(message);
         break;
       case "nitzTime":
         // TODO bug 714349
@@ -463,32 +466,50 @@ RadioInterfaceLayer.prototype = {
 
     if (!options.requestStatusReport) {
       // No more used if STATUS-REPORT not requested.
       delete this._sentSmsEnvelopes[message.envelopeId];
     } else {
       options.sms = sms;
     }
 
-    //TODO handle errors (bug 727319)
     gSmsRequestManager.notifySmsSent(options.requestId, sms);
   },
 
   handleSmsDelivered: function handleSmsDelivered(message) {
     debug("handleSmsDelivered: " + JSON.stringify(message));
 
     let options = this._sentSmsEnvelopes[message.envelopeId];
     if (!options) {
       return;
     }
     delete this._sentSmsEnvelopes[message.envelopeId];
 
     Services.obs.notifyObservers(options.sms, kSmsDeliveredObserverTopic, null);
   },
 
+  handleSmsSendFailed: function handleSmsSendFailed(message) {
+    debug("handleSmsSendFailed: " + JSON.stringify(message));
+
+    let options = this._sentSmsEnvelopes[message.envelopeId];
+    if (!options) {
+      return;
+    }
+    delete this._sentSmsEnvelopes[message.envelopeId];
+
+    let error = gSmsRequestManager.UNKNOWN_ERROR;
+    switch (message.error) {
+      case RIL.ERROR_RADIO_NOT_AVAILABLE:
+        error = gSmsRequestManager.NO_SIGNAL_ERROR;
+        break;
+    }
+
+    gSmsRequestManager.notifySmsSendFailed(options.requestId, error);
+  },
+
   /**
    * Handle data call state changes.
    */
   handleDataCallState: function handleDataCallState(datacall) {
     this._deliverDataCallCallback("dataCallStateChanged",
                                   [datacall.cid, datacall.ifname, datacall.state]);
   },
 
--- a/dom/system/gonk/ril_consts.js
+++ b/dom/system/gonk/ril_consts.js
@@ -236,16 +236,21 @@ const ERROR_DIAL_MODIFIED_TO_DIAL = 19;
 const ERROR_USSD_MODIFIED_TO_DIAL = 20;
 const ERROR_USSD_MODIFIED_TO_SS = 21;
 const ERROR_USSD_MODIFIED_TO_USSD = 22;
 const ERROR_SS_MODIFIED_TO_DIAL = 23;
 const ERROR_SS_MODIFIED_TO_USSD = 24;
 const ERROR_SS_MODIFIED_TO_SS = 25;
 const ERROR_SUBSCRIPTION_NOT_SUPPORTED = 26;
 
+// 3GPP 23.040 clause 9.2.3.6 TP-Message-Reference(TP-MR):
+// The number of times the MS automatically repeats the SMS-SUBMIT shall be in
+// the range 1 to 3 but the precise number is an implementation matter.
+const SMS_RETRY_MAX = 3;
+
 const RADIO_STATE_OFF = 0;
 const RADIO_STATE_UNAVAILABLE = 1;
 const RADIO_STATE_ON = 2;
 
 // RIL v5 legacy constants:
 const RADIO_STATE_SIM_NOT_READY = 2;
 const RADIO_STATE_SIM_LOCKED_OR_ABSENT = 3;
 const RADIO_STATE_SIM_READY = 4;
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -1021,16 +1021,20 @@ let RIL = {
     }
     // We explicitly save this information on the options object so that we
     // can refer to it later, in particular on the main thread (where this
     // object may get sent eventually.)
     options.SMSC = this.SMSC;
 
     //TODO: verify values on 'options'
 
+    if (!options.retryCount) {
+      options.retryCount = 0;
+    }
+
     if (options.segmentMaxSeq > 1) {
       if (!options.segmentSeq) {
         // Fist segment to send
         options.segmentSeq = 1;
         options.body = options.segments[0].body;
         options.encodedBodyLength = options.segments[0].encodedBodyLength;
       }
     } else {
@@ -1567,17 +1571,18 @@ let RIL = {
     // Pending. Waiting for next status report.
     if ((status >>> 5) == 0x01) {
       return PDU_FCS_OK;
     }
 
     delete this._pendingSentSmsMap[message.messageRef];
 
     if ((status >>> 5) != 0x00) {
-      // TODO: bug 727319 - Notify SMS send failures
+      // It seems unlikely to get a result code for a failure to deliver.
+      // Even if, we don't want to do anything with this.
       return PDU_FCS_OK;
     }
 
     if ((options.segmentMaxSeq > 1)
         && (options.segmentSeq < options.segmentMaxSeq)) {
       // Not last segment. Send next segment here.
       this._processSentSmsSegment(options);
     } else {
@@ -1949,17 +1954,34 @@ RIL[REQUEST_OPERATOR] = function REQUEST
     this.sendDOMMessage({type: "operatorchange",
                          operator: this.operator});
   }
 };
 RIL[REQUEST_RADIO_POWER] = null;
 RIL[REQUEST_DTMF] = null;
 RIL[REQUEST_SEND_SMS] = function REQUEST_SEND_SMS(length, options) {
   if (options.rilRequestError) {
-    //TODO handle errors (bug 727319)
+    switch (options.rilRequestError) {
+      case ERROR_SMS_SEND_FAIL_RETRY:
+        if (options.retryCount < SMS_RETRY_MAX) {
+          options.retryCount++;
+          // TODO: bug 736702 TP-MR, retry interval, retry timeout
+          this.sendSMS(options);
+          break;
+        }
+
+        // Fallback to default error handling if it meets max retry count.
+      default:
+        this.sendDOMMessage({
+          type: "sms-send-failed",
+          envelopeId: options.envelopeId,
+          error: options.rilRequestError,
+        });
+        break;
+    }
     return;
   }
 
   options.messageRef = Buf.readUint32();
   options.ackPDU = Buf.readString();
   options.errorCode = Buf.readUint32();
 
   if (options.requestStatusReport) {
@@ -2206,18 +2228,23 @@ RIL[REQUEST_CDMA_SET_BROADCAST_SMS_CONFI
 RIL[REQUEST_CDMA_SMS_BROADCAST_ACTIVATION] = null;
 RIL[REQUEST_CDMA_SUBSCRIPTION] = null;
 RIL[REQUEST_CDMA_WRITE_SMS_TO_RUIM] = null;
 RIL[REQUEST_CDMA_DELETE_SMS_ON_RUIM] = null;
 RIL[REQUEST_DEVICE_IDENTITY] = null;
 RIL[REQUEST_EXIT_EMERGENCY_CALLBACK_MODE] = null;
 RIL[REQUEST_GET_SMSC_ADDRESS] = function REQUEST_GET_SMSC_ADDRESS(length, options) {
   if (options.rilRequestError) {
-    //TODO: notify main thread if we fail retrieving the SMSC, especially
-    // if there was a pending SMS (bug 727319).
+    if (options.body) {
+      this.sendDOMMessage({
+        type: "sms-send-failed",
+        envelopeId: options.envelopeId,
+        error: options.rilRequestError,
+      });
+    }
     return;
   }
 
   this.SMSC = Buf.readString();
   // If the SMSC was not retrieved on RIL initialization, an attempt to
   // get it is triggered from this.sendSMS followed by the 'options'
   // parameter of the SMS, so that we can send it after successfully
   // retrieving the SMSC.