This repository was archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathlockscreen_connection_info_manager.js
336 lines (299 loc) · 10.7 KB
/
lockscreen_connection_info_manager.js
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
/* globals MobileOperator, SettingsListener, SIMSlotManager */
'use strict';
(function(exports) {
var _lockedStateMsgMap = {
'unknown': 'emergencyCallsOnly-unknownSIMState',
'pinRequired': 'emergencyCallsOnly-pinRequired',
'pukRequired': 'emergencyCallsOnly-pukRequired',
'networkLocked': 'emergencyCallsOnly-networkLocked',
'serviceProviderLocked': 'emergencyCallsOnly-serviceProviderLocked',
'corporateLocked': 'emergencyCallsOnly-corporateLocked',
'network1Locked': 'emergencyCallsOnly-network1Locked',
'network2Locked': 'emergencyCallsOnly-network2Locked',
'hrpdNetworkLocked' : 'emergencyCallsOnly-hrpdNetworkLocked',
'ruimCorporateLocked' : 'emergencyCallsOnly-ruimCorporateLocked',
'ruimServiceProviderLocked' : 'emergencyCallsOnly-ruimServiceProviderLocked'
};
/*
* Types of 2G Networks
*/
var _NETWORKS_2G = ['gsm', 'gprs', 'edge'];
/**
* Constructor of LockScreenConnInfoManager. LockScreenConnInfoManager updates
* mobile connection related information on lockscreen.
*
* @param {HTMLElement} root The root element of connection states.
* @constructor LockScreenConnInfoManager
*/
var LockScreenConnInfoManager = function(root) {
if (root) {
this._initialize(root);
}
};
var LockScreenConnInfoManagerPrototype = {
_connStates: null,
_settings: null,
_cellbroadcastLabel: null,
/*
* Telephony default service ID
*/
_telephonyDefaultServiceId: 0,
/*
* Airplane mode
*/
_airplaneMode: false
};
/**
* Initialize connection state elements and event handlers.
*
* @param {HTMLElement} root The root element of connection states.
*/
LockScreenConnInfoManagerPrototype._initialize =
function lscs_initialize(root) {
this._connStates = root;
this._settings = navigator.mozSettings;
this._connStates.hidden = false;
SIMSlotManager.getSlots().forEach(function(simslot, index) {
// connection state
this._connStates.appendChild(this._createConnStateElement());
simslot.conn.addEventListener('voicechange',
(function(index) {
this.updateConnState(simslot);
}).bind(this));
}, this);
// event handlers
this.simSlotCardStateChangeListener = (function(evt) {
this.updateConnState(evt.detail);
}).bind(this);
window.addEventListener('simslot-cardstatechange',
this.simSlotCardStateChangeListener);
this.simSlotIccInfoChangeListener = (function(evt) {
this.updateConnState(evt.detail);
}).bind(this);
window.addEventListener('simslot-iccinfochange',
this.simSlotIccInfoChangeListener);
// Handle incoming CB messages that need to be displayed.
this.cellBroadcastMsgChangedListener = (function(evt) {
this._cellbroadcastLabel = evt.detail;
this.updateConnStates();
}).bind(this);
window.addEventListener('cellbroadcastmsgchanged',
this.cellBroadcastMsgChangedListener);
this._settings.addObserver('ril.radio.disabled', (function(evt) {
this._airplaneMode = evt.settingValue;
this.updateConnStates();
}).bind(this));
this._settings.addObserver('ril.telephony.defaultServiceId',
(function(evt) {
this._telephonyDefaultServiceId = evt.settingValue;
this.updateConnStates();
}).bind(this));
// update UI
var req = SettingsListener.getSettingsLock().get('ril.radio.disabled');
req.onsuccess = (function() {
this._airplaneMode = !!req.result['ril.radio.disabled'];
var req2 =
SettingsListener.getSettingsLock()
.get('ril.telephony.defaultServiceId');
req2.onsuccess = (function() {
this._telephonyDefaultServiceId =
req2.result['ril.telephony.defaultServiceId'] || 0;
this.updateConnStates();
}).bind(this);
}).bind(this);
/* Immediately update the UI, this will display default data which will
* soon be updated once the various event handlers start triggering. */
this.updateConnStates();
};
LockScreenConnInfoManagerPrototype.teardown =
function lscs_teardown() {
window.removeEventListener('simslot-cardstatechange',
this.simSlotCardStateChangeListener);
window.removeEventListener('simslot-iccinfochange',
this.simSlotIccInfoChangeListener);
window.removeEventListener('cellbroadcastmsgchanged',
this.cellBroadcastMsgChangedListener);
};
/**
* Create connection state element.
*
* @this {LockScreenConnInfoManager}
*/
LockScreenConnInfoManagerPrototype._createConnStateElement =
function lscs_createConnStateElement() {
//
// <div>
// <span></span>
// <span class="connstate-line"></span>
// <span class="connstate-line"></span>
// </div>
//
var div = document.createElement('div');
var span = document.createElement('span');
var line1 = document.createElement('span');
var line2 = document.createElement('span');
line1.className = line2.className = 'connstate-line';
div.appendChild(span);
div.appendChild(line1);
div.appendChild(line2);
return div;
};
/**
* Update states of all sim slots.
*
* @this {LockScreenConnInfoManager}
*/
LockScreenConnInfoManagerPrototype.updateConnStates =
function lscs_updateConnStates() {
SIMSlotManager.getSlots().forEach((function(simslot) {
this.updateConnState(simslot);
}).bind(this));
};
/**
* This is a helper function that uses a flag dataset.content
* to determine if the line has content or not.
*
* The content of the connstateLine may come from l10nId or manually
* injected text content.
*/
function lineText(node, l10nId, l10nArgs, text) {
if (!l10nId && !text) {
node.setAttribute('data-content', true);
} else {
node.removeAttribute('data-content');
}
if (l10nId) {
document.l10n.setAttributes(node, l10nId, l10nArgs);
} else {
node.removeAttribute('data-l10n-id');
if (text) {
node.textContent = text;
} else {
node.textContent = '';
}
}
}
/**
* Update the state of a sim slot.
*
* @param {SIMSlot} simslot
* @this {LockScreenConnInfoManager}
*/
LockScreenConnInfoManagerPrototype.updateConnState =
function lscs_updateConnState(simslot) {
var conn = simslot.conn;
var index = simslot.index;
var connstate = this._connStates.children[index];
var simIDLine = connstate.children[0];
var connstateLines =
Array.prototype.slice.call(
connstate.querySelectorAll('.connstate-line'));
var iccObj = simslot.simCard;
var voice = conn.voice;
connstate.hidden = false;
// Set sim ID line
if (SIMSlotManager.isMultiSIM()) {
simIDLine.hidden = false;
lineText(simIDLine, 'lockscreen-sim-id', {n: (index + 1)});
} else {
simIDLine.hidden = true;
}
// Reset Lines
connstateLines.forEach(function(line) {
lineText(line);
});
var nextLine = function() {
for (var i = 0; i < connstateLines.length; i++) {
var line = connstateLines[i];
if (line.hasAttribute('data-content')) {
return line;
}
}
return connstateLines[connstateLines.length - 1];
};
// Airplane mode
if (this._airplaneMode) {
// Only show one airplane mode status
if (index === 0) {
lineText(nextLine(), 'airplaneMode');
} else {
connstate.hidden = true;
}
simIDLine.hidden = true;
return;
}
// If there is no sim card on the device, we only show one information.
if (SIMSlotManager.noSIMCardOnDevice()) {
if (index === 0) {
if (voice.emergencyCallsOnly) {
lineText(nextLine(), 'emergencyCallsOnly');
lineText(nextLine(), 'emergencyCallsOnly-noSIM');
} else {
lineText(nextLine(), 'emergencyCallsOnly-noSIM');
}
}
simIDLine.hidden = true;
return;
} else if (SIMSlotManager.noSIMCardConnectedToNetwork()) {
if (index === 0) {
lineText(nextLine(), 'emergencyCallsOnly');
}
simIDLine.hidden = true;
return;
}
// If there are multiple sim slots and only one sim card inserted, we
// only show the state of the inserted sim card.
if (SIMSlotManager.isMultiSIM() &&
navigator.mozIccManager.iccIds.length == 1 &&
simslot.isAbsent()) {
connstate.hidden = true;
return;
}
// Possible value of voice.state are:
// 'notSearching', 'searching', 'denied', 'registered',
// where the latter three mean the phone is trying to grab the network.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=777057
if (voice && 'state' in voice && voice.state == 'notSearching') {
lineText(nextLine(), 'noNetwork');
return;
}
if (!voice.connected && !voice.emergencyCallsOnly) {
// "Searching"
// voice.state can be any of the latter three values.
// (it's possible that the phone is briefly 'registered'
// but not yet connected.)
lineText(nextLine(), 'searching');
return;
}
if (voice.emergencyCallsOnly) {
if (this._telephonyDefaultServiceId == index) {
lineText(nextLine(), 'emergencyCallsOnly');
lineText(nextLine(), _lockedStateMsgMap[iccObj.cardState]);
} else {
connstate.hidden = true;
}
return;
}
var operatorInfos = MobileOperator.userFacingInfo(conn);
var operator = operatorInfos.operator;
var is2G = _NETWORKS_2G.some(function checkConnectionType(elem) {
return (conn.voice.type == elem);
});
var l10nArgs;
if (voice.roaming) {
l10nArgs = { operator: operator };
lineText(nextLine(), 'roaming', l10nArgs);
} else {
lineText(nextLine(), null, null, operator);
}
if (this._cellbroadcastLabel && is2G) {
lineText(nextLine(), null, null, this._cellbroadcastLabel);
} else if (operatorInfos.carrier) {
l10nArgs = { carrier: operatorInfos.carrier,
region: operatorInfos.region };
lineText(nextLine(), 'operator-info', l10nArgs);
}
};
LockScreenConnInfoManager.prototype = LockScreenConnInfoManagerPrototype;
exports.LockScreenConnInfoManager = LockScreenConnInfoManager;
})(window);