Bug 797277 - Part 3/5: RIL implementation, r=philikon
authorVicamo Yang <vyang@mozilla.com>
Wed, 31 Oct 2012 17:10:48 +0800
changeset 112013 c02178f03fa4
parent 112012 e57c5417fb2c
child 112014 9ce2043663d8
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersphilikon
bugs797277
milestone19.0a1
Bug 797277 - Part 3/5: RIL implementation, r=philikon
dom/sms/src/ril/SmsDatabaseService.js
dom/system/gonk/RadioInterfaceLayer.js
dom/system/gonk/ril_consts.js
dom/system/gonk/ril_worker.js
--- a/dom/sms/src/ril/SmsDatabaseService.js
+++ b/dom/sms/src/ril/SmsDatabaseService.js
@@ -20,16 +20,18 @@ const STORE_NAME = "sms";
 const DELIVERY_SENT = "sent";
 const DELIVERY_RECEIVED = "received";
 
 const DELIVERY_STATUS_NOT_APPLICABLE = "not-applicable";
 const DELIVERY_STATUS_SUCCESS = "success";
 const DELIVERY_STATUS_PENDING = "pending";
 const DELIVERY_STATUS_ERROR = "error";
 
+const MESSAGE_CLASS_NORMAL = "normal";
+
 const FILTER_TIMESTAMP = "timestamp";
 const FILTER_NUMBERS = "numbers";
 const FILTER_DELIVERY = "delivery";
 const FILTER_READ = "read";
 
 // We can´t create an IDBKeyCursor with a boolean, so we need to use numbers
 // instead.
 const FILTER_READ_UNREAD = 0;
@@ -321,16 +323,17 @@ SmsDatabaseService.prototype = {
         self.lastMessageListId += 1;
         self.messageLists[self.lastMessageListId] = messageList;
         let sms = gSmsService.createSmsMessage(message.id,
                                                message.delivery,
                                                message.deliveryStatus,
                                                message.sender,
                                                message.receiver,
                                                message.body,
+                                               message.messageClass,
                                                message.timestamp,
                                                message.read);
         gSmsRequestManager.notifyCreateMessageList(requestId,
                                                    self.lastMessageListId,
                                                    sms);
       };
     });
   },
@@ -349,37 +352,39 @@ SmsDatabaseService.prototype = {
     return message.id;
   },
 
 
   /**
    * nsISmsDatabaseService API
    */
 
-  saveReceivedMessage: function saveReceivedMessage(sender, body, date) {
+  saveReceivedMessage: function saveReceivedMessage(sender, body, messageClass, date) {
     let receiver = this.mRIL.rilContext.icc ? this.mRIL.rilContext.icc.msisdn : null;
 
     let message = {delivery:       DELIVERY_RECEIVED,
                    deliveryStatus: DELIVERY_STATUS_SUCCESS,
                    sender:         sender,
                    receiver:       receiver,
                    body:           body,
+                   messageClass:   messageClass,
                    timestamp:      date,
                    read:           FILTER_READ_UNREAD};
     return this.saveMessage(message);
   },
 
   saveSentMessage: function saveSentMessage(receiver, body, date) {
     let sender = this.mRIL.rilContext.icc ? this.mRIL.rilContext.icc.msisdn : null;
 
     let message = {delivery:       DELIVERY_SENT,
                    deliveryStatus: DELIVERY_STATUS_PENDING,
                    sender:         sender,
                    receiver:       receiver,
                    body:           body,
+                   messageClass:   MESSAGE_CLASS_NORMAL,
                    timestamp:      date,
                    read:           FILTER_READ_READ};
     return this.saveMessage(message);
   },
 
   setMessageDeliveryStatus: function setMessageDeliveryStatus(messageId, deliveryStatus) {
     if ((deliveryStatus != DELIVERY_STATUS_SUCCESS)
         && (deliveryStatus != DELIVERY_STATUS_ERROR)) {
@@ -464,16 +469,17 @@ SmsDatabaseService.prototype = {
           return;
         }
         let message = gSmsService.createSmsMessage(data.id,
                                                    data.delivery,
                                                    data.deliveryStatus,
                                                    data.sender,
                                                    data.receiver,
                                                    data.body,
+                                                   data.messageClass,
                                                    data.timestamp,
                                                    data.read);
         gSmsRequestManager.notifyGotSms(requestId, message);
       };
 
       txn.onerror = function onerror(event) {
         if (DEBUG) debug("Caught error on transaction", event.target.errorCode);
         //TODO look at event.target.errorCode, pick appropriate error constant
@@ -689,16 +695,17 @@ SmsDatabaseService.prototype = {
             requestId, Ci.nsISmsRequestManager.NOT_FOUND_ERROR);
         }
         let sms = gSmsService.createSmsMessage(message.id,
                                                message.delivery,
                                                message.deliveryStatus,
                                                message.sender,
                                                message.receiver,
                                                message.body,
+                                               message.messageClass,
                                                message.timestamp,
                                                message.read);
         gSmsRequestManager.notifyGotNextMessage(requestId, sms);
       };
 
       txn.onerror = function onerror(event) {
         //TODO check event.target.errorCode
         if (DEBUG) {
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -1225,37 +1225,40 @@ RadioInterfaceLayer.prototype = {
     if (mwi) {
       mwi.returnNumber = message.sender || null;
       mwi.returnMessage = message.fullBody || null;
       this._sendTargetMessage("voicemail", "RIL:VoicemailNotification", mwi);
       return;
     }
 
     let id = -1;
-    if (message.messageClass != RIL.PDU_DCS_MSG_CLASS_0) {
+    if (message.messageClass != RIL.GECKO_SMS_MESSAGE_CLASSES[RIL.PDU_DCS_MSG_CLASS_0]) {
       id = gSmsDatabaseService.saveReceivedMessage(message.sender || null,
                                                    message.fullBody || null,
+                                                   message.messageClass,
                                                    message.timestamp);
     }
     let sms = gSmsService.createSmsMessage(id,
                                            DOM_SMS_DELIVERY_RECEIVED,
                                            RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS,
                                            message.sender || null,
                                            message.receiver || null,
                                            message.fullBody || null,
+                                           message.messageClass,
                                            message.timestamp,
                                            false);
 
     gSystemMessenger.broadcastMessage("sms-received",
                                       {id: id,
                                        delivery: DOM_SMS_DELIVERY_RECEIVED,
                                        deliveryStatus: RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS,
                                        sender: message.sender || null,
                                        receiver: message.receiver || null,
                                        body: message.fullBody || null,
+                                       messageClass: message.messageClass,
                                        timestamp: message.timestamp,
                                        read: false});
     Services.obs.notifyObservers(sms, kSmsReceivedObserverTopic, null);
   },
 
   /**
    * Local storage for sent SMS messages.
    */
@@ -1275,25 +1278,27 @@ RadioInterfaceLayer.prototype = {
     debug("handleSmsSent: " + JSON.stringify(message));
 
     let options = this._sentSmsEnvelopes[message.envelopeId];
     if (!options) {
       return;
     }
 
     let timestamp = Date.now();
+    let messageClass = RIL.GECKO_SMS_MESSAGE_CLASSES[RIL.PDU_DCS_MSG_CLASS_NORMAL];
     let id = gSmsDatabaseService.saveSentMessage(options.number,
                                                  options.fullBody,
                                                  timestamp);
     let sms = gSmsService.createSmsMessage(id,
                                            DOM_SMS_DELIVERY_SENT,
                                            RIL.GECKO_SMS_DELIVERY_STATUS_PENDING,
                                            null,
                                            options.number,
                                            options.fullBody,
+                                           messageClass,
                                            timestamp,
                                            true);
 
     if (!options.requestStatusReport) {
       // No more used if STATUS-REPORT not requested.
       delete this._sentSmsEnvelopes[message.envelopeId];
     } else {
       options.id = id;
@@ -1309,24 +1314,26 @@ RadioInterfaceLayer.prototype = {
     debug("handleSmsDelivery: " + JSON.stringify(message));
 
     let options = this._sentSmsEnvelopes[message.envelopeId];
     if (!options) {
       return;
     }
     delete this._sentSmsEnvelopes[message.envelopeId];
 
+    let messageClass = RIL.GECKO_SMS_MESSAGE_CLASSES[RIL.PDU_DCS_MSG_CLASS_NORMAL];
     gSmsDatabaseService.setMessageDeliveryStatus(options.id,
                                                  message.deliveryStatus);
     let sms = gSmsService.createSmsMessage(options.id,
                                            DOM_SMS_DELIVERY_SENT,
                                            message.deliveryStatus,
                                            null,
                                            options.number,
                                            options.fullBody,
+                                           messageClass,
                                            options.timestamp,
                                            true);
 
     let topic = (message.deliveryStatus == RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS)
                 ? kSmsDeliverySuccessObserverTopic
                 : kSmsDeliveryErrorObserverTopic;
     Services.obs.notifyObservers(sms, topic, null);
   },
--- a/dom/system/gonk/ril_consts.js
+++ b/dom/system/gonk/ril_consts.js
@@ -959,31 +959,38 @@ const PDU_PID_ANSI_136_R_DATA           
 const PDU_PID_ME_DATA_DOWNLOAD             = 0x7D;
 const PDU_PID_ME_DEPERSONALIZATION         = 0x7E;
 const PDU_PID_USIM_DATA_DOWNLOAD           = 0x7F;
 
 // DCS - Data Coding Scheme
 const PDU_DCS_MSG_CODING_7BITS_ALPHABET  = 0x00;
 const PDU_DCS_MSG_CODING_8BITS_ALPHABET  = 0x04;
 const PDU_DCS_MSG_CODING_16BITS_ALPHABET = 0x08;
-const PDU_DCS_MSG_CLASS_UNKNOWN          = 0xFF;
+const PDU_DCS_MSG_CLASS_NORMAL           = 0xFF;
 const PDU_DCS_MSG_CLASS_0                = 0x00;
-const PDU_DCS_MSG_CLASS_ME_SPECIFIC      = 0x01;
-const PDU_DCS_MSG_CLASS_SIM_SPECIFIC     = 0x02;
-const PDU_DCS_MSG_CLASS_TE_SPECIFIC      = 0x03;
+const PDU_DCS_MSG_CLASS_1                = 0x01;
+const PDU_DCS_MSG_CLASS_2                = 0x02;
+const PDU_DCS_MSG_CLASS_3                = 0x03;
 const PDU_DCS_CODING_GROUP_BITS          = 0xF0;
 const PDU_DCS_MSG_CLASS_BITS             = 0x03;
 const PDU_DCS_MWI_ACTIVE_BITS            = 0x08;
 const PDU_DCS_MWI_ACTIVE_VALUE           = 0x08;
 const PDU_DCS_MWI_TYPE_BITS              = 0x03;
 const PDU_DCS_MWI_TYPE_VOICEMAIL         = 0x00;
 const PDU_DCS_MWI_TYPE_FAX               = 0x01;
 const PDU_DCS_MWI_TYPE_EMAIL             = 0x02;
 const PDU_DCS_MWI_TYPE_OTHER             = 0x03;
 
+const GECKO_SMS_MESSAGE_CLASSES = {};
+GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_NORMAL] = "normal";
+GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_0]      = "class-0";
+GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_1]      = "class-1";
+GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_2]      = "class-2";
+GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_3]      = "class-3";
+
 // Because service center timestamp omit the century. Yay.
 const PDU_TIMESTAMP_YEAR_OFFSET = 2000;
 
 // See 9.2.3.24 TP‑User Data (TP‑UD)
 const PDU_IEI_CONCATENATED_SHORT_MESSAGES_8BIT         = 0x00;
 const PDU_IEI_SPECIAL_SMS_MESSAGE_INDICATION           = 0x01;
 const PDU_IEI_APPLICATION_PORT_ADDRESSING_SCHEME_8BIT  = 0x04;
 const PDU_IEI_APPLICATION_PORT_ADDRESSING_SCHEME_16BIT = 0x05;
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -3746,17 +3746,17 @@ let RIL = {
 
     if (message.epid == PDU_PID_SHORT_MESSAGE_TYPE_0) {
       // `A short message type 0 indicates that the ME must acknowledge receipt
       // of the short message but shall discard its contents.` ~ 3GPP TS 23.040
       // 9.2.3.9
       return PDU_FCS_OK;
     }
 
-    if (message.messageClass == PDU_DCS_MSG_CLASS_SIM_SPECIFIC) {
+    if (message.messageClass == GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_2]) {
       switch (message.epid) {
         case PDU_PID_ANSI_136_R_DATA:
         case PDU_PID_USIM_DATA_DOWNLOAD:
           if (this.isICCServiceAvailable("DATA_DOWNLOAD_SMS_PP")) {
             // `If the service "data download via SMS Point-to-Point" is
             // allocated and activated in the (U)SIM Service Table, ... then the
             // ME shall pass the message transparently to the UICC using the
             // ENVELOPE (SMS-PP DOWNLOAD).` ~ 3GPP TS 31.111 7.1.1.1
@@ -3772,23 +3772,23 @@ let RIL = {
           // EFsms in accordance with TS 31.102` ~ 3GPP TS 31.111 7.1.1.1
         default:
           this.writeSmsToSIM(message);
           break;
       }
     }
 
     // TODO: Bug 739143: B2G SMS: Support SMS Storage Full event
-    if ((message.messageClass != PDU_DCS_MSG_CLASS_0) && !true) {
+    if ((message.messageClass != GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_0]) && !true) {
       // `When a mobile terminated message is class 0..., the MS shall display
       // the message immediately and send a ACK to the SC ..., irrespective of
       // whether there is memory available in the (U)SIM or ME.` ~ 3GPP 23.038
       // clause 4.
 
-      if (message.messageClass == PDU_DCS_MSG_CLASS_SIM_SPECIFIC) {
+      if (message.messageClass == GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_2]) {
         // `If all the short message storage at the MS is already in use, the
         // MS shall return "memory capacity exceeded".` ~ 3GPP 23.038 clause 4.
         return PDU_FCS_MEMORY_CAPACITY_EXCEEDED;
       }
 
       return PDU_FCS_UNSPECIFIED;
     }
 
@@ -3804,17 +3804,17 @@ let RIL = {
       }
     }
 
     if (message) {
       message.rilMessageType = "sms-received";
       this.sendDOMMessage(message);
     }
 
-    if (message.messageClass == PDU_DCS_MSG_CLASS_SIM_SPECIFIC) {
+    if (message.messageClass == GECKO_SMS_MESSAGE_CLASSES[PDU_DCS_MSG_CLASS_2]) {
       // `MS shall ensure that the message has been to the SMS data field in
       // the (U)SIM before sending an ACK to the SC.`  ~ 3GPP 23.038 clause 4
       return PDU_FCS_RESERVED;
     }
 
     return PDU_FCS_OK;
   },
 
@@ -5920,17 +5920,17 @@ let GsmPDUHelper = {
    *
    * @see 3GPP TS 23.040 9.2.3.10, 3GPP TS 23.038 4.
    */
   readDataCodingScheme: function readDataCodingScheme(msg) {
     let dcs = this.readHexOctet();
     if (DEBUG) debug("PDU: read dcs: " + dcs);
 
     // No message class by default.
-    let messageClass = PDU_DCS_MSG_CLASS_UNKNOWN;
+    let messageClass = PDU_DCS_MSG_CLASS_NORMAL;
     // 7 bit is the default fallback encoding.
     let encoding = PDU_DCS_MSG_CODING_7BITS_ALPHABET;
     switch (dcs & PDU_DCS_CODING_GROUP_BITS) {
       case 0x40: // bits 7..4 = 01xx
       case 0x50:
       case 0x60:
       case 0x70:
         // Bit 5..0 are coded exactly the same as Group 00xx
@@ -5997,17 +5997,17 @@ let GsmPDUHelper = {
 
       default:
         // Falling back to default encoding.
         break;
     }
 
     msg.dcs = dcs;
     msg.encoding = encoding;
-    msg.messageClass = messageClass;
+    msg.messageClass = GECKO_SMS_MESSAGE_CLASSES[messageClass];
 
     if (DEBUG) debug("PDU: message encoding is " + encoding + " bit.");
   },
 
   /**
    * Read GSM TP-Service-Centre-Time-Stamp(TP-SCTS).
    *
    * @see 3GPP TS 23.040 9.2.3.11