diff --git a/dom/cellbroadcast/CellBroadcastMessage.cpp b/dom/cellbroadcast/CellBroadcastMessage.cpp index 1f46a2b9b435..c8e90b526085 100644 --- a/dom/cellbroadcast/CellBroadcastMessage.cpp +++ b/dom/cellbroadcast/CellBroadcastMessage.cpp @@ -83,14 +83,12 @@ CellBroadcastMessage::CellBroadcastMessage(nsPIDOMWindow* aWindow, aEtwsPopup) : nullptr) { - if (aGsmGeographicalScope < - static_cast(CellBroadcastGsmGeographicalScope::EndGuard_)) { + if (aGsmGeographicalScope < nsICellBroadcastService::GSM_GEOGRAPHICAL_SCOPE_INVALID) { mGsmGeographicalScope.SetValue( ToWebidlEnum(aGsmGeographicalScope)); } - if (aMessageClass < - static_cast(CellBroadcastMessageClass::EndGuard_)) { + if (aMessageClass < nsICellBroadcastService::GSM_MESSAGE_CLASS_INVALID) { mMessageClass.SetValue( ToWebidlEnum(aMessageClass)); } @@ -136,8 +134,7 @@ CellBroadcastEtwsInfo::CellBroadcastEtwsInfo(nsPIDOMWindow* aWindow, , mEmergencyUserAlert(aEmergencyUserAlert) , mPopup(aPopup) { - if (aWarningType < - static_cast(CellBroadcastEtwsWarningType::EndGuard_)) { + if (aWarningType < nsICellBroadcastService::GSM_ETWS_WARNING_INVALID) { mWarningType.SetValue( ToWebidlEnum(aWarningType)); } diff --git a/dom/cellbroadcast/gonk/CellBroadcastService.js b/dom/cellbroadcast/gonk/CellBroadcastService.js index 2894d81bd393..a4b1d91471c4 100644 --- a/dom/cellbroadcast/gonk/CellBroadcastService.js +++ b/dom/cellbroadcast/gonk/CellBroadcastService.js @@ -20,9 +20,9 @@ const kMozSettingsChangedObserverTopic = "mozsettings-changed"; const kSettingsCellBroadcastDisabled = "ril.cellbroadcast.disabled"; const kSettingsCellBroadcastSearchList = "ril.cellbroadcast.searchlist"; -XPCOMUtils.defineLazyServiceGetter(this, "gCellbroadcastMessenger", - "@mozilla.org/ril/system-messenger-helper;1", - "nsICellbroadcastMessenger"); +XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger", + "@mozilla.org/system-message-internal;1", + "nsISystemMessagesInternal"); XPCOMUtils.defineLazyServiceGetter(this, "gSettingsService", "@mozilla.org/settingsService;1", @@ -112,6 +112,24 @@ CellBroadcastService.prototype = { } catch (e) {} }, + _convertCbGsmGeographicalScope: function(aGeographicalScope) { + return (aGeographicalScope >= Ci.nsICellBroadcastService.GSM_GEOGRAPHICAL_SCOPE_INVALID) + ? null + : RIL.CB_GSM_GEOGRAPHICAL_SCOPE_NAMES[aGeographicalScope]; + }, + + _convertCbMessageClass: function(aMessageClass) { + return (aMessageClass >= Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS) + ? null + : RIL.GECKO_SMS_MESSAGE_CLASSES[aMessageClass]; + }, + + _convertCbEtwsWarningType: function(aWarningType) { + return (aWarningType >= Ci.nsICellBroadcastService.GSM_ETWS_WARNING_INVALID) + ? null + : RIL.CB_ETWS_WARNING_TYPE_NAMES[aWarningType]; + }, + _retrieveSettingValueByClient: function(aClientId, aSettings) { return Array.isArray(aSettings) ? aSettings[aClientId] : aSettings; }, @@ -218,19 +236,38 @@ CellBroadcastService.prototype = { aEtwsEmergencyUserAlert, aEtwsPopup) { // Broadcast CBS System message - gCellbroadcastMessenger.notifyCbMessageReceived(aServiceId, - aGsmGeographicalScope, - aMessageCode, - aMessageId, - aLanguage, - aBody, - aMessageClass, - aTimestamp, - aCdmaServiceCategory, - aHasEtwsInfo, - aEtwsWarningType, - aEtwsEmergencyUserAlert, - aEtwsPopup); + // Align the same layout to MozCellBroadcastMessage + let systemMessage = { + serviceId: aServiceId, + gsmGeographicalScope: this._convertCbGsmGeographicalScope(aGsmGeographicalScope), + messageCode: aMessageCode, + messageId: aMessageId, + language: aLanguage, + body: aBody, + messageClass: this._convertCbMessageClass(aMessageClass), + timestamp: aTimestamp, + cdmaServiceCategory: null, + etws: null + }; + + if (aHasEtwsInfo) { + systemMessage.etws = { + warningType: this._convertCbEtwsWarningType(aEtwsWarningType), + emergencyUserAlert: aEtwsEmergencyUserAlert, + popup: aEtwsPopup + }; + } + + if (aCdmaServiceCategory != + Ci.nsICellBroadcastService.CDMA_SERVICE_CATEGORY_INVALID) { + systemMessage.cdmaServiceCategory = aCdmaServiceCategory; + } + + if (DEBUG) { + debug("CBS system message to be broadcasted: " + JSON.stringify(systemMessage)); + } + + gSystemMessenger.broadcastMessage("cellbroadcast-received", systemMessage); // Notify received message to registered listener for (let listener of this._listeners) { diff --git a/dom/cellbroadcast/interfaces/moz.build b/dom/cellbroadcast/interfaces/moz.build index 86b53fe3c48d..bfef8e925a5f 100644 --- a/dom/cellbroadcast/interfaces/moz.build +++ b/dom/cellbroadcast/interfaces/moz.build @@ -10,7 +10,6 @@ XPIDL_SOURCES += [ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']: XPIDL_SOURCES += [ - 'nsICellbroadcastMessenger.idl', 'nsIGonkCellBroadcastService.idl', ] diff --git a/dom/cellbroadcast/interfaces/nsICellBroadcastService.idl b/dom/cellbroadcast/interfaces/nsICellBroadcastService.idl index a694da28b895..8b04739eed7f 100644 --- a/dom/cellbroadcast/interfaces/nsICellBroadcastService.idl +++ b/dom/cellbroadcast/interfaces/nsICellBroadcastService.idl @@ -36,7 +36,7 @@ interface nsICellBroadcastListener : nsISupports /** * XPCOM component that provides the cell broadcast information. */ -[scriptable, uuid(906cda5a-6b18-11e4-973b-5ff3fc075b6b)] +[scriptable, uuid(eed283f6-44a8-11e4-b364-afb894b7a283)] interface nsICellBroadcastService : nsISupports { /** @@ -47,13 +47,11 @@ interface nsICellBroadcastService : nsISupports const unsigned short GSM_GEOGRAPHICAL_SCOPE_PLMN = 1; const unsigned short GSM_GEOGRAPHICAL_SCOPE_LOCATION_AREA = 2; const unsigned short GSM_GEOGRAPHICAL_SCOPE_CELL = 3; - const unsigned short GSM_GEOGRAPHICAL_SCOPE_INVALID = 0xFFFF; + const unsigned short GSM_GEOGRAPHICAL_SCOPE_INVALID = 4; /** * Constant definitions of predefined GSM Message Class * See 3GPP TS 23.038 clause 5 CBS Data Coding Scheme - * - * Set to GSM_MESSAGE_CLASS_NORMAL if no message class is specified. */ const unsigned short GSM_MESSAGE_CLASS_0 = 0; const unsigned short GSM_MESSAGE_CLASS_1 = 1; @@ -62,6 +60,7 @@ interface nsICellBroadcastService : nsISupports const unsigned short GSM_MESSAGE_CLASS_USER_1 = 4; const unsigned short GSM_MESSAGE_CLASS_USER_2 = 5; const unsigned short GSM_MESSAGE_CLASS_NORMAL = 6; + const unsigned short GSM_MESSAGE_CLASS_INVALID = 7; /** * Constant definitions of predefined GSM ETWS Warning Types @@ -72,7 +71,7 @@ interface nsICellBroadcastService : nsISupports const unsigned short GSM_ETWS_WARNING_EARTHQUAKE_TSUNAMI = 2; const unsigned short GSM_ETWS_WARNING_TEST = 3; const unsigned short GSM_ETWS_WARNING_OTHER = 4; - const unsigned short GSM_ETWS_WARNING_INVALID = 0xFFFF; + const unsigned short GSM_ETWS_WARNING_INVALID = 5; /** * Attribute CdmaServiceCategory is only valid in CDMA network. diff --git a/dom/cellbroadcast/interfaces/nsICellbroadcastMessenger.idl b/dom/cellbroadcast/interfaces/nsICellbroadcastMessenger.idl deleted file mode 100644 index 86ebc8b4f6c2..000000000000 --- a/dom/cellbroadcast/interfaces/nsICellbroadcastMessenger.idl +++ /dev/null @@ -1,55 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "domstubs.idl" -#include "nsISupports.idl" - -[scriptable, uuid(47764f4a-5b3f-11e4-a2ec-4b99529b9288)] -interface nsICellbroadcastMessenger : nsISupports -{ - /** - * To broadcast 'cellbroadcast-received' system message. - * - * @param aServiceId - * The ID of Service where this info is notified from. - * @param aGsmGeographicalScope - * @See nsICellBroadcastService.GSM_GEOGRAPHICAL_SCOPE_*. - * @param aMessageCode - * The Message Code differentiates between messages from the same - * source and type (e.g., with the same Message Identifier). - * @param aMessageId - * Source and type of the message which is coded in binary. - * @param aLanguage - * ISO-639-1 language code for this message. Null if unspecified. - * @param aBody - * Text message carried by the message. - * @param aMessageClass - * @See nsICellBroadcastService.GSM_MESSAGE_CLASS_*. - * @param aTimestamp - * System time stamp at receival. - * @param aCdmaServiceCategory - * CDMA Service Category. - * @param aHasEtwsInfo - * True if ETWS Info is included in this message. - * @param aEtwsWarningType - * @See nsICellBroadcastService.GSM_ETWS_WARNING_*. - * @param aEtwsEmergencyUserAlert - * True if Emergency user alert indication is set. - * @param aEtwsPopup - * True if Message popup indication is set. - */ - void notifyCbMessageReceived(in unsigned long aServiceId, - in unsigned long aGsmGeographicalScope, - in unsigned short aMessageCode, - in unsigned short aMessageId, - in DOMString aLanguage, - in DOMString aBody, - in unsigned long aMessageClass, - in DOMTimeStamp aTimestamp, - in unsigned long aCdmaServiceCategory, - in boolean aHasEtwsInfo, - in unsigned long aEtwsWarningType, - in boolean aEtwsEmergencyUserAlert, - in boolean aEtwsPopup); -}; diff --git a/dom/system/gonk/RILSystemMessenger.jsm b/dom/system/gonk/RILSystemMessenger.jsm index 73cefec8584c..0725ffebbefc 100644 --- a/dom/system/gonk/RILSystemMessenger.jsm +++ b/dom/system/gonk/RILSystemMessenger.jsm @@ -106,55 +106,6 @@ RILSystemMessenger.prototype = { deliveryTimestamp: aDeliveryTimestamp, read: aRead }); - }, - - _convertCbGsmGeographicalScope: function(aGeographicalScope) { - return RIL.CB_GSM_GEOGRAPHICAL_SCOPE_NAMES[aGeographicalScope] || null; - }, - - _convertCbMessageClass: function(aMessageClass) { - return RIL.GECKO_SMS_MESSAGE_CLASSES[aMessageClass] || null; - }, - - _convertCbEtwsWarningType: function(aWarningType) { - return RIL.CB_ETWS_WARNING_TYPE_NAMES[aWarningType] || null; - }, - - /** - * Wrapper to send 'cellbroadcast-received' system message. - */ - notifyCbMessageReceived: function(aServiceId, aGsmGeographicalScope, aMessageCode, - aMessageId, aLanguage, aBody, aMessageClass, - aTimestamp, aCdmaServiceCategory, aHasEtwsInfo, - aEtwsWarningType, aEtwsEmergencyUserAlert, aEtwsPopup) { - // Align the same layout to MozCellBroadcastMessage - let data = { - serviceId: aServiceId, - gsmGeographicalScope: this._convertCbGsmGeographicalScope(aGsmGeographicalScope), - messageCode: aMessageCode, - messageId: aMessageId, - language: aLanguage, - body: aBody, - messageClass: this._convertCbMessageClass(aMessageClass), - timestamp: aTimestamp, - cdmaServiceCategory: null, - etws: null - }; - - if (aHasEtwsInfo) { - data.etws = { - warningType: this._convertCbEtwsWarningType(aEtwsWarningType), - emergencyUserAlert: aEtwsEmergencyUserAlert, - popup: aEtwsPopup - }; - } - - if (aCdmaServiceCategory != - Ci.nsICellBroadcastService.CDMA_SERVICE_CATEGORY_INVALID) { - data.cdmaServiceCategory = aCdmaServiceCategory; - } - - this.broadcastMessage("cellbroadcast-received", data); } }; diff --git a/dom/system/gonk/RILSystemMessengerHelper.js b/dom/system/gonk/RILSystemMessengerHelper.js index 40cb78ce1908..65dfe7b4d19d 100644 --- a/dom/system/gonk/RILSystemMessengerHelper.js +++ b/dom/system/gonk/RILSystemMessengerHelper.js @@ -50,8 +50,7 @@ RILSystemMessengerHelper.prototype = { classID: RILSYSTEMMESSENGERHELPER_CID, QueryInterface: XPCOMUtils.generateQI([Ci.nsITelephonyMessenger, - Ci.nsISmsMessenger, - Ci.nsICellbroadcastMessenger]), + Ci.nsISmsMessenger]), /** * RILSystemMessenger instance. @@ -80,19 +79,6 @@ RILSystemMessengerHelper.prototype = { this.messenger.notifySms(aNotificationType, aId, aThreadId, aIccId, aDelivery, aDeliveryStatus, aSender, aReceiver, aBody, aMessageClass, aTimestamp, aSentTimestamp, aDeliveryTimestamp, aRead); - }, - - /** - * nsICellbroadcastMessenger API - */ - notifyCbMessageReceived: function(aServiceId, aGsmGeographicalScope, aMessageCode, - aMessageId, aLanguage, aBody, aMessageClass, - aTimestamp, aCdmaServiceCategory, aHasEtwsInfo, - aEtwsWarningType, aEtwsEmergencyUserAlert, aEtwsPopup) { - this.messenger.notifyCbMessageReceived(aServiceId, aGsmGeographicalScope, aMessageCode, - aMessageId, aLanguage, aBody, aMessageClass, - aTimestamp, aCdmaServiceCategory, aHasEtwsInfo, - aEtwsWarningType, aEtwsEmergencyUserAlert, aEtwsPopup); } }; diff --git a/dom/system/gonk/RadioInterfaceLayer.js b/dom/system/gonk/RadioInterfaceLayer.js index aa327d4c9381..2044b1ab3275 100644 --- a/dom/system/gonk/RadioInterfaceLayer.js +++ b/dom/system/gonk/RadioInterfaceLayer.js @@ -2827,7 +2827,7 @@ RadioInterface.prototype = { let index = RIL.GECKO_SMS_MESSAGE_CLASSES.indexOf(aMessageClass); return (index != -1) ? index - : Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS_NORMAL; + : Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS_INVALID; }, _convertCbEtwsWarningType: function(aWarningType) { diff --git a/dom/system/gonk/tests/test_ril_system_messenger.js b/dom/system/gonk/tests/test_ril_system_messenger.js index 104be1a40e44..7995a10e38d1 100644 --- a/dom/system/gonk/tests/test_ril_system_messenger.js +++ b/dom/system/gonk/tests/test_ril_system_messenger.js @@ -51,12 +51,8 @@ function run_test() { let smsMessenger = Cc["@mozilla.org/ril/system-messenger-helper;1"] .getService(Ci.nsISmsMessenger); - let cellbroadcastMessenger = Cc["@mozilla.org/ril/system-messenger-helper;1"] - .getService(Ci.nsICellbroadcastMessenger); - ok(telephonyMessenger !== null, "Get TelephonyMessenger."); ok(smsMessenger != null, "Get SmsMessenger."); - ok(cellbroadcastMessenger != null, "Get CellbroadcastMessenger."); run_next_test(); } @@ -247,129 +243,3 @@ add_test(function test_sms_messenger_notify_sms() { run_next_test(); }); - -/** - * Verify RILSystemMessenger.notifyCbMessageReceived() - */ -add_test(function test_cellbroadcast_messenger_notify_cb_message_received() { - let messenger = newRILSystemMessenger(); - let timestamp = Date.now(); - - // Verify ETWS - messenger.notifyCbMessageReceived(0, - Ci.nsICellBroadcastService.GSM_GEOGRAPHICAL_SCOPE_CELL_IMMEDIATE, - 256, - 4352, - null, - null, - Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS_NORMAL, - timestamp, - Ci.nsICellBroadcastService.CDMA_SERVICE_CATEGORY_INVALID, - true, - Ci.nsICellBroadcastService.GSM_ETWS_WARNING_EARTHQUAKE, - false, - true); - equal_received_system_message("cellbroadcast-received", { - serviceId: 0, - gsmGeographicalScope: "cell-immediate", - messageCode: 256, - messageId: 4352, - language: null, - body: null, - messageClass: "normal", - timestamp: timestamp, - cdmaServiceCategory: null, - etws: { - warningType: "earthquake", - emergencyUserAlert: false, - popup: true - } - }); - - // Verify Normal CB Message - messenger.notifyCbMessageReceived(1, - Ci.nsICellBroadcastService.GSM_GEOGRAPHICAL_SCOPE_PLMN, - 0, - 50, - "en", - "The quick brown fox jumps over the lazy dog", - Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS_NORMAL, - timestamp, - Ci.nsICellBroadcastService.CDMA_SERVICE_CATEGORY_INVALID, - false, - Ci.nsICellBroadcastService.GSM_ETWS_WARNING_INVALID, - false, - false); - equal_received_system_message("cellbroadcast-received", { - serviceId: 1, - gsmGeographicalScope: "plmn", - messageCode: 0, - messageId: 50, - language: "en", - body: "The quick brown fox jumps over the lazy dog", - messageClass: "normal", - timestamp: timestamp, - cdmaServiceCategory: null, - etws: null - }); - - // Verify CB Message with ETWS Info - messenger.notifyCbMessageReceived(0, - Ci.nsICellBroadcastService.GSM_GEOGRAPHICAL_SCOPE_LOCATION_AREA, - 0, - 4354, - "en", - "Earthquake & Tsunami Warning!", - Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS_0, - timestamp, - Ci.nsICellBroadcastService.CDMA_SERVICE_CATEGORY_INVALID, - true, - Ci.nsICellBroadcastService.GSM_ETWS_WARNING_EARTHQUAKE_TSUNAMI, - true, - false); - equal_received_system_message("cellbroadcast-received", { - serviceId: 0, - gsmGeographicalScope: "location-area", - messageCode: 0, - messageId: 4354, - language: "en", - body: "Earthquake & Tsunami Warning!", - messageClass: "class-0", - timestamp: timestamp, - cdmaServiceCategory: null, - etws: { - warningType: "earthquake-tsunami", - emergencyUserAlert: true, - popup: false - } - }); - - // Verify CDMA CB Message - messenger.notifyCbMessageReceived(0, - Ci.nsICellBroadcastService.GSM_GEOGRAPHICAL_SCOPE_INVALID, - 0, - 0, - null, - "CDMA CB Message", - Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS_NORMAL, - timestamp, - 512, - false, - Ci.nsICellBroadcastService.GSM_ETWS_WARNING_INVALID, - false, - false); - equal_received_system_message("cellbroadcast-received", { - serviceId: 0, - gsmGeographicalScope: null, - messageCode: 0, - messageId: 0, - language: null, - body: "CDMA CB Message", - messageClass: "normal", - timestamp: timestamp, - cdmaServiceCategory: 512, - etws: null - }); - - run_next_test(); -});