Bug 839402 - Part 1 - Make decoding cdma pdu message reusable. r=vicamo
authorPatrick Wang <kk1fff@patrickz.net>
Mon, 11 Mar 2013 22:01:37 +0800
changeset 124363 17b65305f13195c96aad14b33f7edb5643b978d7
parent 124362 db7aaa4e41844b03b3dd922db22fdf4978bf0394
child 124364 14415ab6c873743852644462a2831b3622067bcb
push id24417
push userryanvm@gmail.com
push dateMon, 11 Mar 2013 23:58:07 +0000
treeherdermozilla-central@7433bc4545c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo
bugs839402
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 839402 - Part 1 - Make decoding cdma pdu message reusable. r=vicamo
dom/system/gonk/ril_worker.js
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -8158,94 +8158,73 @@ let CdmaPDUHelper = {
     // Consume padding bits
     if (headerPaddingBits) {
       BitBufferHelper.readBits(headerPaddingBits);
     }
 
     return header;
   },
 
-  /**
-   * User data subparameter decoder : User Data
-   *
-   * @see 3GGP2 C.S0015-B 2.0, 4.5.2 User Data
-   */
-  decodeUserDataMsg: function cdma_decodeUserDataMsg(hasUserHeader) {
-    let result = {},
-        encoding = BitBufferHelper.readBits(5);
-
-    if(encoding === PDU_CDMA_MSG_CODING_IS_91) {
-      let msgType = BitBufferHelper.readBits(8);
-    }
-
-    let msgBodySize = BitBufferHelper.readBits(8);
-    const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
-    const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
+  getCdmaMsgEncoding: function getCdmaMsgEncoding(encoding) {
     // Determine encoding method
     switch (encoding) {
       case PDU_CDMA_MSG_CODING_7BITS_ASCII:
       case PDU_CDMA_MSG_CODING_IA5:
       case PDU_CDMA_MSG_CODING_7BITS_GSM:
-        result.encoding = PDU_DCS_MSG_CODING_7BITS_ALPHABET;
-        break;
+        return PDU_DCS_MSG_CODING_7BITS_ALPHABET;
       case PDU_CDMA_MSG_CODING_OCTET:
       case PDU_CDMA_MSG_CODING_IS_91:
       case PDU_CDMA_MSG_CODING_LATIN_HEBREW:
       case PDU_CDMA_MSG_CODING_LATIN:
-        result.encoding = PDU_DCS_MSG_CODING_8BITS_ALPHABET;
-        break;
+        return PDU_DCS_MSG_CODING_8BITS_ALPHABET;
       case PDU_CDMA_MSG_CODING_UNICODE:
       case PDU_CDMA_MSG_CODING_SHIFT_JIS:
       case PDU_CDMA_MSG_CODING_KOREAN:
-        result.encoding = PDU_DCS_MSG_CODING_16BITS_ALPHABET;
-        break;
-    }
-
-    // For segmented SMS, a user header is included before sms content
-    if (hasUserHeader) {
-      result.header = this.decodeUserDataHeader(result.encoding);
-      // header size is included in body size, they are decoded
-      msgBodySize -= result.header.length;
-    }
-
-    // Decode sms content
-    result.body = "";
+        return PDU_DCS_MSG_CODING_16BITS_ALPHABET;
+    }
+    return null;
+  },
+
+  decodeCdmaPDUMsg: function decodeCdmaPDUMsg(encoding, msgType, msgBodySize) {
+    const langTable = PDU_NL_LOCKING_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
+    const langShiftTable = PDU_NL_SINGLE_SHIFT_TABLES[PDU_NL_IDENTIFIER_DEFAULT];
+    let result = "";
     let msgDigit;
     switch (encoding) {
       case PDU_CDMA_MSG_CODING_OCTET:         // TODO : Require Test
         while(msgBodySize > 0) {
           msgDigit = String.fromCharCode(BitBufferHelper.readBits(8));
-          result.body += msgDigit;
+          result += msgDigit;
           msgBodySize--;
         }
         break;
       case PDU_CDMA_MSG_CODING_IS_91:         // TODO : Require Test
         // Referenced from android code
         switch (msgType) {
           case PDU_CDMA_MSG_CODING_IS_91_TYPE_SMS:
           case PDU_CDMA_MSG_CODING_IS_91_TYPE_SMS_FULL:
           case PDU_CDMA_MSG_CODING_IS_91_TYPE_VOICEMAIL_STATUS:
             while(msgBodySize > 0) {
               msgDigit = String.fromCharCode(BitBufferHelper.readBits(6) + 0x20);
-              result.body += msgDigit;
+              result += msgDigit;
               msgBodySize--;
             }
             break;
           case PDU_CDMA_MSG_CODING_IS_91_TYPE_CLI:
             let addrInfo = {};
             addrInfo.digitMode = PDU_CDMA_MSG_ADDR_DIGIT_MODE_DTMF;
             addrInfo.numberMode = PDU_CDMA_MSG_ADDR_NUMBER_MODE_ANSI;
             addrInfo.numberType = PDU_CDMA_MSG_ADDR_NUMBER_TYPE_UNKNOWN;
             addrInfo.numberPlan = PDU_CDMA_MSG_ADDR_NUMBER_PLAN_UNKNOWN;
             addrInfo.addrLength = msgBodySize;
             addrInfo.address = [];
             for (let i = 0; i < addrInfo.addrLength; i++) {
               addrInfo.address.push(BitBufferHelper.readBits(4));
             }
-            result.body = this.decodeAddr(addrInfo);
+            result = this.decodeAddr(addrInfo);
             break;
         }
       case PDU_CDMA_MSG_CODING_7BITS_ASCII:
       case PDU_CDMA_MSG_CODING_IA5:           // TODO : Require Test
         while(msgBodySize > 0) {
           msgDigit = BitBufferHelper.readBits(7);
           if (msgDigit >= 32) {
             msgDigit = String.fromCharCode(msgDigit);
@@ -8253,46 +8232,46 @@ let CdmaPDUHelper = {
             if (msgDigit !== PDU_NL_EXTENDED_ESCAPE) {
               msgDigit = langTable[msgDigit];
             } else {
               msgDigit = BitBufferHelper.readBits(7);
               msgBodySize--;
               msgDigit = langShiftTable[msgDigit];
             }
           }
-          result.body += msgDigit;
+          result += msgDigit;
           msgBodySize--;
         }
         break;
       case PDU_CDMA_MSG_CODING_UNICODE:
         while(msgBodySize > 0) {
           msgDigit = String.fromCharCode(BitBufferHelper.readBits(16));
-          result.body += msgDigit;
+          result += msgDigit;
           msgBodySize--;
         }
         break;
       case PDU_CDMA_MSG_CODING_7BITS_GSM:     // TODO : Require Test
         while(msgBodySize > 0) {
           msgDigit = BitBufferHelper.readBits(7);
           if (msgDigit !== PDU_NL_EXTENDED_ESCAPE) {
             msgDigit = langTable[msgDigit];
           } else {
             msgDigit = BitBufferHelper.readBits(7);
             msgBodySize--;
             msgDigit = langShiftTable[msgDigit];
           }
-          result.body += msgDigit;
+          result += msgDigit;
           msgBodySize--;
         }
         break;
       case PDU_CDMA_MSG_CODING_LATIN:         // TODO : Require Test
         // Reference : http://en.wikipedia.org/wiki/ISO/IEC_8859-1
         while(msgBodySize > 0) {
           msgDigit = String.fromCharCode(BitBufferHelper.readBits(8));
-          result.body += msgDigit;
+          result += msgDigit;
           msgBodySize--;
         }
         break;
       case PDU_CDMA_MSG_CODING_LATIN_HEBREW:  // TODO : Require Test
         // Reference : http://en.wikipedia.org/wiki/ISO/IEC_8859-8
         while(msgBodySize > 0) {
           msgDigit = BitBufferHelper.readBits(8);
           if (msgDigit === 0xDF) {
@@ -8301,28 +8280,57 @@ let CdmaPDUHelper = {
             msgDigit = String.fromCharCode(0x200E);
           } else if (msgDigit === 0xFE) {
             msgDigit = String.fromCharCode(0x200F);
           } else if (msgDigit >= 0xE0 && msgDigit <= 0xFA) {
             msgDigit = String.fromCharCode(0x4F0 + msgDigit);
           } else {
             msgDigit = String.fromCharCode(msgDigit);
           }
-          result.body += msgDigit;
+          result += msgDigit;
           msgBodySize--;
         }
         break;
       case PDU_CDMA_MSG_CODING_SHIFT_JIS:
         // Reference : http://msdn.microsoft.com/en-US/goglobal/cc305152.aspx
         //             http://demo.icu-project.org/icu-bin/convexp?conv=Shift_JIS
       case PDU_CDMA_MSG_CODING_KOREAN:
       case PDU_CDMA_MSG_CODING_GSM_DCS:
       default:
         break;
     }
+    return result;
+  },
+
+  /**
+   * User data subparameter decoder : User Data
+   *
+   * @see 3GGP2 C.S0015-B 2.0, 4.5.2 User Data
+   */
+  decodeUserDataMsg: function cdma_decodeUserDataMsg(hasUserHeader) {
+    let result = {},
+        encoding = BitBufferHelper.readBits(5),
+        msgType;
+
+    if(encoding === PDU_CDMA_MSG_CODING_IS_91) {
+      msgType = BitBufferHelper.readBits(8);
+    }
+    result.encoding = this.getCdmaMsgEncoding(encoding);
+
+    let msgBodySize = BitBufferHelper.readBits(8);
+
+    // For segmented SMS, a user header is included before sms content
+    if (hasUserHeader) {
+      result.header = this.decodeUserDataHeader(result.encoding);
+      // header size is included in body size, they are decoded
+      msgBodySize -= result.header.length;
+    }
+
+    // Decode sms content
+    result.body = this.decodeCdmaPDUMsg(encoding, msgType, msgBodySize);
 
     return result;
   },
 
   decodeBcd: function cdma_decodeBcd(value) {
     return ((value >> 4) & 0xF) * 10 + (value & 0x0F);
   },