1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
/* 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/. */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyGetter(this, "RIL", function () {
let obj = {};
Cu.import("resource://gre/modules/ril_consts.js", obj);
return obj;
});
/**
* RILSystemMessenger
*/
this.RILSystemMessenger = function() {};
RILSystemMessenger.prototype = {
/**
* Hook of Broadcast function
*
* @param aType
* The type of the message to be sent.
* @param aMessage
* The message object to be broadcasted.
*/
broadcastMessage: function(aType, aMessage) {
// Function stub to be replaced by the owner of this messenger.
},
/**
* Hook of the function to create MozStkCommand message.
* @param aStkProactiveCmd
* nsIStkProactiveCmd instance.
*
* @return a JS object which complies the dictionary of MozStkCommand defined
* in MozStkCommandEvent.webidl
*/
createCommandMessage: function(aStkProactiveCmd) {
// Function stub to be replaced by the owner of this messenger.
},
/**
* Wrapper to send "telephony-new-call" system message.
*/
notifyNewCall: function() {
this.broadcastMessage("telephony-new-call", {});
},
/**
* Wrapper to send "telephony-call-ended" system message.
*/
notifyCallEnded: function(aServiceId, aNumber, aCdmaWaitingNumber, aEmergency,
aDuration, aOutgoing, aHangUpLocal) {
let data = {
serviceId: aServiceId,
number: aNumber,
emergency: aEmergency,
duration: aDuration,
direction: aOutgoing ? "outgoing" : "incoming",
hangUpLocal: aHangUpLocal
};
if (aCdmaWaitingNumber != null) {
data.secondNumber = aCdmaWaitingNumber;
}
this.broadcastMessage("telephony-call-ended", data);
},
_convertSmsMessageClass: function(aMessageClass) {
return RIL.GECKO_SMS_MESSAGE_CLASSES[aMessageClass] || null;
},
_convertSmsDelivery: function(aDelivery) {
return ["received", "sending", "sent", "error"][aDelivery] || null;
},
_convertSmsDeliveryStatus: function(aDeliveryStatus) {
return [
RIL.GECKO_SMS_DELIVERY_STATUS_NOT_APPLICABLE,
RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS,
RIL.GECKO_SMS_DELIVERY_STATUS_PENDING,
RIL.GECKO_SMS_DELIVERY_STATUS_ERROR
][aDeliveryStatus] || null;
},
/**
* Wrapper to send 'sms-received', 'sms-delivery-success', 'sms-sent',
* 'sms-failed', 'sms-delivery-error' system message.
*/
notifySms: function(aNotificationType, aId, aThreadId, aIccId, aDelivery,
aDeliveryStatus, aSender, aReceiver, aBody, aMessageClass,
aTimestamp, aSentTimestamp, aDeliveryTimestamp, aRead) {
let msgType = [
"sms-received",
"sms-sent",
"sms-delivery-success",
"sms-failed",
"sms-delivery-error"
][aNotificationType];
if (!msgType) {
throw new Error("Invalid Notification Type: " + aNotificationType);
}
this.broadcastMessage(msgType, {
iccId: aIccId,
type: "sms",
id: aId,
threadId: aThreadId,
delivery: this._convertSmsDelivery(aDelivery),
deliveryStatus: this._convertSmsDeliveryStatus(aDeliveryStatus),
sender: aSender,
receiver: aReceiver,
body: aBody,
messageClass: this._convertSmsMessageClass(aMessageClass),
timestamp: aTimestamp,
sentTimestamp: aSentTimestamp,
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);
},
/**
* Wrapper to send 'ussd-received' system message.
*/
notifyUssdReceived: function(aServiceId, aMessage, aSessionEnded) {
this.broadcastMessage("ussd-received", {
serviceId: aServiceId,
message: aMessage,
sessionEnded: aSessionEnded
});
},
/**
* Wrapper to send 'cdma-info-rec-received' system message with Display Info.
*/
notifyCdmaInfoRecDisplay: function(aServiceId, aDisplay) {
this.broadcastMessage("cdma-info-rec-received", {
clientId: aServiceId,
display: aDisplay
});
},
/**
* Wrapper to send 'cdma-info-rec-received' system message with Called Party
* Number Info.
*/
notifyCdmaInfoRecCalledPartyNumber: function(aServiceId, aType, aPlan,
aNumber, aPi, aSi) {
this.broadcastMessage("cdma-info-rec-received", {
clientId: aServiceId,
calledNumber: {
type: aType,
plan: aPlan,
number: aNumber,
pi: aPi,
si: aSi
}
});
},
/**
* Wrapper to send 'cdma-info-rec-received' system message with Calling Party
* Number Info.
*/
notifyCdmaInfoRecCallingPartyNumber: function(aServiceId, aType, aPlan,
aNumber, aPi, aSi) {
this.broadcastMessage("cdma-info-rec-received", {
clientId: aServiceId,
callingNumber: {
type: aType,
plan: aPlan,
number: aNumber,
pi: aPi,
si: aSi
}
});
},
/**
* Wrapper to send 'cdma-info-rec-received' system message with Connected Party
* Number Info.
*/
notifyCdmaInfoRecConnectedPartyNumber: function(aServiceId, aType, aPlan,
aNumber, aPi, aSi) {
this.broadcastMessage("cdma-info-rec-received", {
clientId: aServiceId,
connectedNumber: {
type: aType,
plan: aPlan,
number: aNumber,
pi: aPi,
si: aSi
}
});
},
/**
* Wrapper to send 'cdma-info-rec-received' system message with Signal Info.
*/
notifyCdmaInfoRecSignal: function(aServiceId, aType, aAlertPitch, aSignal) {
this.broadcastMessage("cdma-info-rec-received", {
clientId: aServiceId,
signal: {
type: aType,
alertPitch: aAlertPitch,
signal: aSignal
}
});
},
/**
* Wrapper to send 'cdma-info-rec-received' system message with Redirecting
* Number Info.
*/
notifyCdmaInfoRecRedirectingNumber: function(aServiceId, aType, aPlan,
aNumber, aPi, aSi, aReason) {
this.broadcastMessage("cdma-info-rec-received", {
clientId: aServiceId,
redirect: {
type: aType,
plan: aPlan,
number: aNumber,
pi: aPi,
si: aSi,
reason: aReason
}
});
},
/**
* Wrapper to send 'cdma-info-rec-received' system message with Line Control Info.
*/
notifyCdmaInfoRecLineControl: function(aServiceId, aPolarityIncluded,
aToggle, aReverse, aPowerDenial) {
this.broadcastMessage("cdma-info-rec-received", {
clientId: aServiceId,
lineControl: {
polarityIncluded: aPolarityIncluded,
toggle: aToggle,
reverse: aReverse,
powerDenial: aPowerDenial
}
});
},
/**
* Wrapper to send 'cdma-info-rec-received' system message with CLIR Info.
*/
notifyCdmaInfoRecClir: function(aServiceId, aCause) {
this.broadcastMessage("cdma-info-rec-received", {
clientId: aServiceId,
clirCause: aCause
});
},
/**
* Wrapper to send 'cdma-info-rec-received' system message with Audio Control Info.
*/
notifyCdmaInfoRecAudioControl: function(aServiceId, aUpLink, aDownLink) {
this.broadcastMessage("cdma-info-rec-received", {
clientId: aServiceId,
audioControl: {
upLink: aUpLink,
downLink: aDownLink
}
});
},
/**
* Wrapper to send 'icc-stkcommand' system message with Audio Control Info.
*/
notifyStkProactiveCommand: function(aIccId, aCommand) {
this.broadcastMessage("icc-stkcommand", {
iccId: aIccId,
command: this.createCommandMessage(aCommand)
});
}
};
this.EXPORTED_SYMBOLS = [
'RILSystemMessenger'
];
|