Bug 1072808 - Part 3: Add CellBroadcastMessenger as a Wrapper for CellBroadcast System Messages. r=echen

This commit is contained in:
Bevis Tseng 2014-10-24 13:18:26 +08:00
parent ec3fe8670a
commit 1465f1e6c9
9 changed files with 278 additions and 62 deletions

View File

@ -83,12 +83,14 @@ CellBroadcastMessage::CellBroadcastMessage(nsPIDOMWindow* aWindow,
aEtwsPopup)
: nullptr)
{
if (aGsmGeographicalScope < nsICellBroadcastService::GSM_GEOGRAPHICAL_SCOPE_INVALID) {
if (aGsmGeographicalScope <
static_cast<uint32_t>(CellBroadcastGsmGeographicalScope::EndGuard_)) {
mGsmGeographicalScope.SetValue(
ToWebidlEnum<CellBroadcastGsmGeographicalScope>(aGsmGeographicalScope));
}
if (aMessageClass < nsICellBroadcastService::GSM_MESSAGE_CLASS_INVALID) {
if (aMessageClass <
static_cast<uint32_t>(CellBroadcastMessageClass::EndGuard_)) {
mMessageClass.SetValue(
ToWebidlEnum<CellBroadcastMessageClass>(aMessageClass));
}
@ -134,7 +136,8 @@ CellBroadcastEtwsInfo::CellBroadcastEtwsInfo(nsPIDOMWindow* aWindow,
, mEmergencyUserAlert(aEmergencyUserAlert)
, mPopup(aPopup)
{
if (aWarningType < nsICellBroadcastService::GSM_ETWS_WARNING_INVALID) {
if (aWarningType <
static_cast<uint32_t>(CellBroadcastEtwsWarningType::EndGuard_)) {
mWarningType.SetValue(
ToWebidlEnum<CellBroadcastEtwsWarningType>(aWarningType));
}

View File

@ -20,9 +20,9 @@ const kMozSettingsChangedObserverTopic = "mozsettings-changed";
const kSettingsCellBroadcastDisabled = "ril.cellbroadcast.disabled";
const kSettingsCellBroadcastSearchList = "ril.cellbroadcast.searchlist";
XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger",
"@mozilla.org/system-message-internal;1",
"nsISystemMessagesInternal");
XPCOMUtils.defineLazyServiceGetter(this, "gCellbroadcastMessenger",
"@mozilla.org/ril/system-messenger-helper;1",
"nsICellbroadcastMessenger");
XPCOMUtils.defineLazyServiceGetter(this, "gSettingsService",
"@mozilla.org/settingsService;1",
@ -112,24 +112,6 @@ 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;
},
@ -236,38 +218,19 @@ CellBroadcastService.prototype = {
aEtwsEmergencyUserAlert,
aEtwsPopup) {
// Broadcast CBS System message
// 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);
gCellbroadcastMessenger.notifyCbMessageReceived(aServiceId,
aGsmGeographicalScope,
aMessageCode,
aMessageId,
aLanguage,
aBody,
aMessageClass,
aTimestamp,
aCdmaServiceCategory,
aHasEtwsInfo,
aEtwsWarningType,
aEtwsEmergencyUserAlert,
aEtwsPopup);
// Notify received message to registered listener
for (let listener of this._listeners) {

View File

@ -10,6 +10,7 @@ XPIDL_SOURCES += [
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']:
XPIDL_SOURCES += [
'nsICellbroadcastMessenger.idl',
'nsIGonkCellBroadcastService.idl',
]

View File

@ -36,7 +36,7 @@ interface nsICellBroadcastListener : nsISupports
/**
* XPCOM component that provides the cell broadcast information.
*/
[scriptable, uuid(eed283f6-44a8-11e4-b364-afb894b7a283)]
[scriptable, uuid(906cda5a-6b18-11e4-973b-5ff3fc075b6b)]
interface nsICellBroadcastService : nsISupports
{
/**
@ -47,11 +47,13 @@ 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 = 4;
const unsigned short GSM_GEOGRAPHICAL_SCOPE_INVALID = 0xFFFF;
/**
* 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;
@ -60,7 +62,6 @@ 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
@ -71,7 +72,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 = 5;
const unsigned short GSM_ETWS_WARNING_INVALID = 0xFFFF;
/**
* Attribute CdmaServiceCategory is only valid in CDMA network.

View File

@ -0,0 +1,55 @@
/* 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);
};

View File

@ -106,6 +106,55 @@ 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);
}
};

View File

@ -50,7 +50,8 @@ RILSystemMessengerHelper.prototype = {
classID: RILSYSTEMMESSENGERHELPER_CID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsITelephonyMessenger,
Ci.nsISmsMessenger]),
Ci.nsISmsMessenger,
Ci.nsICellbroadcastMessenger]),
/**
* RILSystemMessenger instance.
@ -79,6 +80,19 @@ 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);
}
};

View File

@ -2827,7 +2827,7 @@ RadioInterface.prototype = {
let index = RIL.GECKO_SMS_MESSAGE_CLASSES.indexOf(aMessageClass);
return (index != -1)
? index
: Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS_INVALID;
: Ci.nsICellBroadcastService.GSM_MESSAGE_CLASS_NORMAL;
},
_convertCbEtwsWarningType: function(aWarningType) {

View File

@ -51,8 +51,12 @@ 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();
}
@ -243,3 +247,129 @@ 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();
});