Bug 1072367 - Part 1: Broadcast 'cdma-info-rec-received' system message per record. r=echen
authorBevis Tseng <btseng@mozilla.com>
Thu, 02 Oct 2014 14:04:27 +0800
changeset 210134 0dbedf3aec62456e4bf777a2e77579a675219a92
parent 210133 d2a2cce2dff19054499ff2a45089eb878f4922ba
child 210135 80c3e34f21ff2a1b0a034b0fcea18a399cc3a6ac
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersechen
bugs1072367
milestone35.0a1
Bug 1072367 - Part 1: Broadcast 'cdma-info-rec-received' system message per record. r=echen
dom/system/gonk/RadioInterfaceLayer.js
dom/system/gonk/ril_worker.js
dom/system/gonk/tests/test_ril_worker_cdma_info_rec.js
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -2087,17 +2087,19 @@ RadioInterface.prototype = {
       case "stkcommand":
         this.handleStkProactiveCommand(message);
         break;
       case "stksessionend":
         gMessageManager.sendIccMessage("RIL:StkSessionEnd", this.clientId, null);
         break;
       case "cdma-info-rec-received":
         if (DEBUG) this.debug("cdma-info-rec-received: " + JSON.stringify(message));
-        gSystemMessenger.broadcastMessage("cdma-info-rec-received", message);
+        message.records.forEach(function(aRecord) {
+          gSystemMessenger.broadcastMessage("cdma-info-rec-received", aRecord);
+        });
         break;
       default:
         throw new Error("Don't know about this message type: " +
                         message.rilMessageType);
     }
   },
 
   /**
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -6915,19 +6915,20 @@ RilObject.prototype[UNSOLICITED_CDMA_OTA
     CDMA_OTA_PROVISION_STATUS_TO_GECKO[this.context.Buf.readInt32List()[0]];
   if (!status) {
     return;
   }
   this.sendChromeMessage({rilMessageType: "otastatuschange",
                           status: status});
 };
 RilObject.prototype[UNSOLICITED_CDMA_INFO_REC] = function UNSOLICITED_CDMA_INFO_REC(length) {
-  let record = this.context.CdmaPDUHelper.decodeInformationRecord();
-  record.rilMessageType = "cdma-info-rec-received";
-  this.sendChromeMessage(record);
+  this.sendChromeMessage({
+    rilMessageType: "cdma-info-rec-received",
+    records: this.context.CdmaPDUHelper.decodeInformationRecord()
+  });
 };
 RilObject.prototype[UNSOLICITED_OEM_HOOK_RAW] = null;
 RilObject.prototype[UNSOLICITED_RINGBACK_TONE] = null;
 RilObject.prototype[UNSOLICITED_RESEND_INCALL_MUTE] = null;
 RilObject.prototype[UNSOLICITED_CDMA_SUBSCRIPTION_SOURCE_CHANGED] = null;
 RilObject.prototype[UNSOLICITED_CDMA_PRL_CHANGED] = function UNSOLICITED_CDMA_PRL_CHANGED(length) {
   let version = this.context.Buf.readInt32List()[0];
   if (version !== this.iccInfo.prlVersion) {
@@ -9982,21 +9983,23 @@ CdmaPDUHelperObject.prototype = {
     return result;
   },
 
   /**
    * Decode information record parcel.
    */
   decodeInformationRecord: function() {
     let Buf = this.context.Buf;
-    let record = {};
+    let records = [];
     let numOfRecords = Buf.readInt32();
 
     let type;
+    let record;
     for (let i = 0; i < numOfRecords; i++) {
+      record = {};
       type = Buf.readInt32();
 
       switch (type) {
         /*
          * Every type is encaped by ril, except extended display
          */
         case PDU_CDMA_INFO_REC_TYPE_DISPLAY:
           record.display = Buf.readString();
@@ -10083,21 +10086,23 @@ CdmaPDUHelperObject.prototype = {
         case PDU_CDMA_INFO_REC_TYPE_T53_AUDIO_CONTROL:
           record.audioControl = {};
           record.audioControl.upLink = Buf.readInt32();
           record.audioControl.downLink = Buf.readInt32();
           break;
         case PDU_CDMA_INFO_REC_TYPE_T53_RELEASE:
           // Fall through
         default:
-          throw new Error("UNSOLICITED_CDMA_INFO_REC(), Unsupported information record type " + record.type + "\n");
-      }
-    }
-
-    return record;
+          throw new Error("UNSOLICITED_CDMA_INFO_REC(), Unsupported information record type " + type + "\n");
+      }
+
+      records.push(record);
+    }
+
+    return records;
   }
 };
 
 /**
  * Helper for processing ICC PDUs.
  */
 function ICCPDUHelperObject(aContext) {
   this.context = aContext;
--- a/dom/system/gonk/tests/test_ril_worker_cdma_info_rec.js
+++ b/dom/system/gonk/tests/test_ril_worker_cdma_info_rec.js
@@ -48,19 +48,19 @@ add_test(function test_display() {
   let worker = newWorkerWithParcel([
                 0x01, // one inforemation record
                 0x00, // type: display
                 0x09, // length: 9
                 0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E, 0x66,
                 0x6F, 0x00]);
   let context = worker.ContextPool._contexts[0];
   let helper = context.CdmaPDUHelper;
-  let record = helper.decodeInformationRecord();
+  let records = helper.decodeInformationRecord();
 
-  do_check_eq(record.display, "Test Info");
+  do_check_eq(records[0].display, "Test Info");
 
   run_next_test();
 });
 
 /**
  * Verify decoder for type EXTENDED DISPLAY
  */
 add_test(function test_extended_display() {
@@ -71,28 +71,29 @@ add_test(function test_extended_display(
                 0x80, // header byte
                 0x80, // Blank
                 0x81, // Skip
                 0x9B, // Text
                 0x09, 0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E,
                 0x66, 0x6F, 0x00]);
   let context = worker.ContextPool._contexts[0];
   let helper = context.CdmaPDUHelper;
-  let record = helper.decodeInformationRecord();
+  let records = helper.decodeInformationRecord();
 
-  do_check_eq(record.extendedDisplay.indicator, 1);
-  do_check_eq(record.extendedDisplay.type, 0);
-  do_check_eq(record.extendedDisplay.records.length, 3);
-  do_check_eq(record.extendedDisplay.records[0].tag, 0x80);
-  do_check_eq(record.extendedDisplay.records[1].tag, 0x81);
-  do_check_eq(record.extendedDisplay.records[2].tag, 0x9B);
-  do_check_eq(record.extendedDisplay.records[2].content, "Test Info");
+  do_check_eq(records[0].extendedDisplay.indicator, 1);
+  do_check_eq(records[0].extendedDisplay.type, 0);
+  do_check_eq(records[0].extendedDisplay.records.length, 3);
+  do_check_eq(records[0].extendedDisplay.records[0].tag, 0x80);
+  do_check_eq(records[0].extendedDisplay.records[1].tag, 0x81);
+  do_check_eq(records[0].extendedDisplay.records[2].tag, 0x9B);
+  do_check_eq(records[0].extendedDisplay.records[2].content, "Test Info");
 
   run_next_test();
 });
+
 /**
  * Verify decoder for mixed type
  */
 add_test(function test_mixed() {
   let worker = newWorkerWithParcel([
                 0x02, // two inforemation record
                 0x00, // type: display
                 0x09, // length: 9
@@ -103,21 +104,45 @@ add_test(function test_mixed() {
                 0x80, // header byte
                 0x80, // Blank
                 0x81, // Skip
                 0x9B, // Text
                 0x09, 0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E,
                 0x66, 0x6F, 0x00]);
   let context = worker.ContextPool._contexts[0];
   let helper = context.CdmaPDUHelper;
-  let record = helper.decodeInformationRecord();
+  let records = helper.decodeInformationRecord();
 
-  do_check_eq(record.display, "Test Info");
-  do_check_eq(record.extendedDisplay.indicator, 1);
-  do_check_eq(record.extendedDisplay.type, 0);
-  do_check_eq(record.extendedDisplay.records.length, 3);
-  do_check_eq(record.extendedDisplay.records[0].tag, 0x80);
-  do_check_eq(record.extendedDisplay.records[1].tag, 0x81);
-  do_check_eq(record.extendedDisplay.records[2].tag, 0x9B);
-  do_check_eq(record.extendedDisplay.records[2].content, "Test Info");
+  do_check_eq(records[0].display, "Test Info");
+  do_check_eq(records[1].extendedDisplay.indicator, 1);
+  do_check_eq(records[1].extendedDisplay.type, 0);
+  do_check_eq(records[1].extendedDisplay.records.length, 3);
+  do_check_eq(records[1].extendedDisplay.records[0].tag, 0x80);
+  do_check_eq(records[1].extendedDisplay.records[1].tag, 0x81);
+  do_check_eq(records[1].extendedDisplay.records[2].tag, 0x9B);
+  do_check_eq(records[1].extendedDisplay.records[2].content, "Test Info");
 
   run_next_test();
 });
+
+/**
+ * Verify decoder for multiple types
+ */
+add_test(function test_multiple() {
+  let worker = newWorkerWithParcel([
+                0x02, // two inforemation record
+                0x00, // type: display
+                0x0B, // length: 11
+                0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E, 0x66,
+                0x6F, 0x20, 0x31, 0x00,
+                0x00, // type: display
+                0x0B, // length: 11
+                0x54, 0x65, 0x73, 0x74, 0x20, 0x49, 0x6E, 0x66,
+                0x6F, 0x20, 0x32, 0x00]);
+  let context = worker.ContextPool._contexts[0];
+  let helper = context.CdmaPDUHelper;
+  let records = helper.decodeInformationRecord();
+
+  do_check_eq(records[0].display, "Test Info 1");
+  do_check_eq(records[1].display, "Test Info 2");
+
+  run_next_test();
+});