Bug 921326 - Part 3: Support to Receive Cellbroadcast Messages from different serviceId. r=htsai
authorBevis Tseng <btseng@mozilla.com>
Thu, 12 Jun 2014 12:04:48 +0800
changeset 190217 da44ea22ec8962d63efc2ba38bf4335711f2524d
parent 190216 041dd3366df15ffcafa46567e4d1837924aa798e
child 190218 a26df6b1981bda37104b176e2c95c91632edcca5
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewershtsai
bugs921326
milestone33.0a1
Bug 921326 - Part 3: Support to Receive Cellbroadcast Messages from different serviceId. r=htsai
dom/cellbroadcast/interfaces/nsIDOMMozCellBroadcastMessage.idl
dom/system/gonk/RILContentHelper.js
--- a/dom/cellbroadcast/interfaces/nsIDOMMozCellBroadcastMessage.idl
+++ b/dom/cellbroadcast/interfaces/nsIDOMMozCellBroadcastMessage.idl
@@ -6,20 +6,25 @@
 #include "nsISupports.idl"
 
 interface nsIDOMMozCellBroadcastEtwsInfo;
 
 /**
  * MozCellBroadcastMessage encapsulates Cell Broadcast short message service
  * (CBS) messages.
  */
-[scriptable, uuid(701e74a9-5fc4-4e2d-a324-9b7693395159)]
+[scriptable, uuid(dc729df4-f1d8-11e3-b00d-d3332542c557)]
 interface nsIDOMMozCellBroadcastMessage : nsISupports
 {
   /**
+   * The Service Id in the device where the message is received from.
+   */
+  readonly attribute unsigned long serviceId;
+
+  /**
    * Indication of the geographical area over which the Message Code is unique,
    * and the display mode.
    *
    * Possible values are: "cell-immediate", "plmn", "location-area" and "cell".
    */
   readonly attribute DOMString gsmGeographicalScope;
 
   /**
--- a/dom/system/gonk/RILContentHelper.js
+++ b/dom/system/gonk/RILContentHelper.js
@@ -300,17 +300,18 @@ MobileCallForwardingInfo.prototype = {
   __exposedProps__ : {active: 'r',
                       action: 'r',
                       reason: 'r',
                       number: 'r',
                       timeSeconds: 'r',
                       serviceClass: 'r'}
 };
 
-function CellBroadcastMessage(pdu) {
+function CellBroadcastMessage(clientId, pdu) {
+  this.serviceId = clientId;
   this.gsmGeographicalScope = RIL.CB_GSM_GEOGRAPHICAL_SCOPE_NAMES[pdu.geographicalScope];
   this.messageCode = pdu.messageCode;
   this.messageId = pdu.messageId;
   this.language = pdu.language;
   this.body = pdu.fullBody;
   this.messageClass = pdu.messageClass;
   this.timestamp = pdu.timestamp;
 
@@ -326,16 +327,17 @@ CellBroadcastMessage.prototype = {
   classInfo:      XPCOMUtils.generateCI({
     classID:          CELLBROADCASTMESSAGE_CID,
     classDescription: "CellBroadcastMessage",
     flags:            Ci.nsIClassInfo.DOM_OBJECT,
     interfaces:       [Ci.nsIDOMMozCellBroadcastMessage]
   }),
 
   // nsIDOMMozCellBroadcastMessage
+  serviceId: -1,
 
   gsmGeographicalScope: null,
   messageCode: null,
   messageId: null,
   language: null,
   body: null,
   messageClass: null,
   timestamp: null,
@@ -1539,23 +1541,27 @@ RILContentHelper.prototype = {
     // To follow the listener unregistration scheme, we add a dummy clientId 0.
     // All voicemail events are routed to listener for client id 0.
     // See |handleVoicemailNotification|.
     this.unregisterListener("_voicemailListeners", 0, listener);
   },
 
   registerCellBroadcastMsg: function(listener) {
     if (DEBUG) debug("Registering for Cell Broadcast related messages");
-    //TODO: Bug 921326 - Cellbroadcast API: support multiple sim cards
+    // Instead of registering multiple listeners for Multi-SIM, we reuse
+    // clientId 0 to route all CBS messages to single listener and provide the
+    // |clientId| info by |CellBroadcastMessage.serviceId|.
     this.registerListener("_cellBroadcastListeners", 0, listener);
     cpmm.sendAsyncMessage("RIL:RegisterCellBroadcastMsg");
   },
 
   unregisterCellBroadcastMsg: function(listener) {
-    //TODO: Bug 921326 - Cellbroadcast API: support multiple sim cards
+    // Instead of unregistering multiple listeners for Multi-SIM, we reuse
+    // clientId 0 to route all CBS messages to single listener and provide the
+    // |clientId| info by |CellBroadcastMessage.serviceId|.
     this.unregisterListener("_cellBroadcastListeners", 0, listener);
   },
 
   registerIccMsg: function(clientId, listener) {
     if (DEBUG) debug("Registering for ICC related messages");
     this.registerListener("_iccListeners", clientId, listener);
     cpmm.sendAsyncMessage("RIL:RegisterIccMsg");
   },
@@ -1819,18 +1825,20 @@ RILContentHelper.prototype = {
         break;
       case "RIL:GetCallingLineIdRestriction":
         this.handleGetCallingLineIdRestriction(data);
         break;
       case "RIL:SetCallingLineIdRestriction":
         this.handleSimpleRequest(data.requestId, data.errorMsg, null);
         break;
       case "RIL:CellBroadcastReceived": {
-        let message = new CellBroadcastMessage(data);
-        this._deliverEvent(clientId,
+        // All CBS messages are to routed the listener for clientId 0 and
+        // provide the |clientId| info by |CellBroadcastMessage.serviceId|.
+        let message = new CellBroadcastMessage(clientId, data);
+        this._deliverEvent(0, // route to clientId 0.
                            "_cellBroadcastListeners",
                            "notifyMessageReceived",
                            [message]);
         break;
       }
       case "RIL:SetRoamingPreference":
         this.handleSimpleRequest(data.requestId, data.errorMsg, null);
         break;