Repository navigation
Expand file tree
/
Copy pathicc.js
More file actions
404 lines (347 loc) · 11.4 KB
/
Copy pathicc.js
File metadata and controls
404 lines (347 loc) · 11.4 KB
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
(function() {
var _ = navigator.mozL10n.get;
// Consts
const STK_SCREEN_DEFAULT = 0x00;
const STK_SCREEN_MAINMENU = 0x01;
const STK_SCREEN_HELP = 0x02;
/**
* Init
*/
var iccMenuItem = document.getElementById('menuItem-icc');
var iccStkList = document.getElementById('icc-stk-list');
var iccStkHeader = document.getElementById('icc-stk-header');
var iccStkSubheader = document.getElementById('icc-stk-subheader');
var iccLastCommand = null;
var iccLastCommandProcessed = false;
var stkOpenAppName = null;
var stkLastSelectedTest = null;
var goBackTimer = {
timer: null,
timeout: 0
};
var selectTimer = {
timer: null,
timeout: 0
};
var icc;
var iccManager;
init();
/**
* Init STK UI
*/
function init() {
// See bug 932134
// To keep all tests passed while introducing multi-sim APIs, in bug 928325
// we use IccHelper. Stop using IccHelper after the APIs land.
icc = IccHelper;
iccManager = window.navigator.mozIccManager;
icc. handleSTKSessionEnd(event) {
updateMenu();
Settings.currentPanel = '#icc';
};
document.getElementById('icc-stk-app-back').>
document.getElementById('icc-stk-help-exit').>
document.addEventListener('visibilitychange', function() {
if (document.hidden && Settings.currentPanel == '#icc') {
stkResTerminate();
}
}, false);
window. {
responseSTKCommand({
resultCode: iccManager.STK_RESULT_NO_RESPONSE_FROM_USER
}, true);
};
window.addEventListener('stkasynccommand',
function do_handleAsyncSTKCmd(event) {
handleSTKCommand(event.detail.command);
});
/**
* Open STK main application
*/
iccMenuItem. onclick() {
updateMenu();
};
// Load STK apps
updateMenu();
}
function stkResTerminate() {
Settings.currentPanel = '#root';
iccLastCommandProcessed = true;
responseSTKCommand({
resultCode: iccManager.STK_RESULT_UICC_SESSION_TERM_BY_USER
}, true);
}
function stkResGoBack() {
iccLastCommandProcessed = true;
responseSTKCommand({
resultCode: iccManager.STK_RESULT_BACKWARD_MOVE_BY_USER
});
// We'll return to settings if no STK response received in a grace period
var reqTimerGoBack =
window.navigator.mozSettings.createLock().get('icc.goBackTimeout');
reqTimerGoBack. icc_getTimerGoBackSuccess() {
goBackTimer.timeout = reqTimerGoBack.result['icc.goBackTimeout'];
goBackTimer.timer = setTimeout(function() {
Settings.currentPanel = '#root';
}, goBackTimer.timeout);
};
};
function stkResNoResponse() {
var reqTimerSelect =
window.navigator.mozSettings.createLock().get('icc.selectTimeout');
reqTimerSelect. icc_getTimerSelectSuccess() {
selectTimer.timeout = reqTimerSelect.result['icc.selectTimeout'];
selectTimer.timer = setTimeout(function() {
iccLastCommandProcessed = true;
responseSTKCommand({
resultCode: iccManager.STK_RESULT_NO_RESPONSE_FROM_USER
}, true);
stkResGoBack();
}, selectTimer.timeout);
};
};
function stkCancelGoBack() {
if (goBackTimer.timer) {
window.clearTimeout(goBackTimer.timer);
goBackTimer.timer = null;
}
if (selectTimer.timer) {
window.clearTimeout(selectTimer.timer);
selectTimer.timer = null;
}
}
/**
* Updates the STK header buttons
*/
function setSTKScreenType(type) {
var exit = document.getElementById('icc-stk-exit');
var back = document.getElementById('icc-stk-app-back');
var helpExit = document.getElementById('icc-stk-help-exit');
switch (type) {
case STK_SCREEN_MAINMENU:
exit.classList.remove('hidden');
back.classList.add('hidden');
helpExit.classList.add('hidden');
break;
case STK_SCREEN_HELP:
exit.classList.add('hidden');
back.classList.add('hidden');
helpExit.classList.remove('hidden');
break;
default: // STK_SCREEN_DEFAULT
exit.classList.add('hidden');
back.classList.remove('hidden');
helpExit.classList.add('hidden');
}
}
/**
* Response ICC Command
*/
function responseSTKCommand(response, force) {
if (!force && (!iccLastCommand || !iccLastCommandProcessed)) {
DUMP('sendStkResponse NO COMMAND TO RESPONSE. Ignoring');
return;
}
DUMP('sendStkResponse to command: ', iccLastCommand);
DUMP('sendStkResponse -- # response = ', response);
icc.sendStkResponse(iccLastCommand, response);
iccLastCommand = null;
iccLastCommandProcessed = false;
}
/**
* Handle ICC Commands
*/
function handleSTKCommand(command) {
DUMP('STK Proactive Command:', command);
iccLastCommand = command;
var options = command.options;
stkCancelGoBack();
// By default a generic screen
setSTKScreenType(STK_SCREEN_DEFAULT);
reopenSettings();
switch (command.typeOfCommand) {
case iccManager.STK_CMD_SELECT_ITEM:
updateSelection(command);
openSTKApplication();
iccLastCommandProcessed = true;
break;
default:
DUMP('STK Message not managed... response OK');
iccLastCommandProcessed = true;
responseSTKCommand({
resultCode: iccManager.STK_RESULT_OK
});
}
}
/**
* Navigate through all available STK applications
*/
function updateMenu() {
DUMP('Showing STK main menu');
stkOpenAppName = null;
stkCancelGoBack();
var reqApplications =
window.navigator.mozSettings.createLock().get('icc.applications');
reqApplications. icc_getApplications() {
var json = reqApplications.result['icc.applications'];
var menu = json && JSON.parse(json);
clearList();
setSTKScreenType(STK_SCREEN_MAINMENU);
if (!menu || !menu.items ||
(menu.items.length == 1 && menu.items[0] === null)) {
DUMP('No STK available - hide & exit');
document.getElementById('icc-mainheader').hidden = true;
document.getElementById('icc-mainentry').hidden = true;
return;
}
DUMP('STK Main App Menu title: ' + menu.title);
DUMP('STK Main App Menu default item: ' + menu.defaultItem);
iccMenuItem.textContent = menu.title;
showTitle(menu.title);
menu.items.forEach(function(menuItem) {
DUMP('STK Main App Menu item: ' + menuItem.text + ' # ' +
menuItem.identifier);
iccStkList.appendChild(buildMenuEntry({
id: 'stk-menuitem-' + menuItem.identifier,
text: menuItem.text,
nai: _(menuItem.nai),
onclick: onMainMenuItemClick,
attributes: [['stk-menu-item-identifier', menuItem.identifier]]
}));
});
// Optional Help menu
if (menu.isHelpAvailable) {
iccStkList.appendChild(buildMenuEntry({
id: 'stk-helpmenuitem',
text: _('operatorServices-helpmenu'),
onclick: showHelpMenu,
attributes: []
}));
}
};
stkResNoResponse();
}
function onMainMenuItemClick(event) {
var identifier = event.target.getAttribute('stk-menu-item-identifier');
DUMP('sendStkMenuSelection: ', identifier);
icc.sendStkMenuSelection(identifier, false);
stkLastSelectedTest = event.target.textContent;
stkOpenAppName = stkLastSelectedTest;
}
function showHelpMenu(event) {
DUMP('Showing STK help menu');
stkOpenAppName = null;
var reqApplications =
window.navigator.mozSettings.createLock().get('icc.applications');
reqApplications. icc_getApplications() {
var menu = JSON.parse(reqApplications.result['icc.applications']);
clearList();
setSTKScreenType(STK_SCREEN_HELP);
iccMenuItem.textContent = menu.title;
showTitle(_('operatorServices-helpmenu'));
menu.items.forEach(function(menuItem) {
DUMP('STK Main App Help item: ' + menuItem.text + ' # ' +
menuItem.identifier);
iccStkList.appendChild(buildMenuEntry({
id: 'stk-helpitem-' + menuItem.identifier,
text: menuItem.text,
onclick: onMainMenuHelpItemClick,
attributes: [['stk-help-item-identifier', menuItem.identifier]]
}));
});
};
}
function onMainMenuHelpItemClick(event) {
var identifier = event.target.getAttribute('stk-help-item-identifier');
DUMP('sendStkHelpMenuSelection: ', identifier);
icc.sendStkMenuSelection(identifier, true);
stkLastSelectedTest = event.target.textContent;
stkOpenAppName = stkLastSelectedTest;
}
/**
* Navigate through the STK application options
*/
function updateSelection(command) {
var menu = command.options;
DUMP('Showing STK menu');
clearList();
DUMP('STK App Menu title: ' + menu.title);
DUMP('STK App Menu default item: ' + menu.defaultItem);
showTitle(menu.title);
menu.items.forEach(function(menuItem) {
DUMP('STK App Menu item: ' + menuItem.text + ' # ' +
menuItem.identifier);
iccStkList.appendChild(buildMenuEntry({
id: 'stk-menuitem-' + menuItem.identifier,
text: menuItem.text,
nai: _(menuItem.nai),
onclick: onSelectOptionClick.bind(null, command),
attributes: [['stk-select-option-identifier', menuItem.identifier]]
}));
});
stkResNoResponse();
}
function onSelectOptionClick(command, event) {
var identifier = event.target.getAttribute('stk-select-option-identifier');
responseSTKCommand({
resultCode: iccManager.STK_RESULT_OK,
itemIdentifier: identifier
});
stkLastSelectedTest = event.target.textContent;
}
/**
* Auxiliar methods
*/
function showTitle(title) {
// If the application is automatically opened (no come from main menu)
if (!stkOpenAppName) {
stkOpenAppName = title;
}
iccStkHeader.textContent = stkOpenAppName;
// Show section
if (stkOpenAppName != title) {
iccStkSubheader.textContent = title;
iccStkSubheader.parentNode.classList.remove('hiddenheader');
iccStkSubheader.classList.remove('hidden');
} else {
iccStkSubheader.textContent = '';
iccStkSubheader.parentNode.classList.add('hiddenheader');
iccStkSubheader.classList.add('hidden');
}
}
function clearList() {
while (iccStkList.hasChildNodes()) {
iccStkList.removeChild(iccStkList.lastChild);
}
}
function buildMenuEntry(entry) {
var li = document.createElement('li');
if (entry.nai) {
var small = document.createElement('small');
small.textContent = entry.nai;
li.appendChild(small);
}
var a = document.createElement('a');
a.id = entry.id;
entry.attributes.forEach(function attrIterator(attr) {
a.setAttribute(attr[0], attr[1]);
});
a.textContent = entry.text;
a.>
li.appendChild(a);
return li;
}
/**
* Open settings application with ICC section opened
*/
function openSTKApplication() {
Settings.currentPanel = '#icc';
window.navigator.mozApps.getSelf(). getSelfCB(evt) {
var app = evt.target.result;
app.launch('settings');
};
};
})();
You can’t perform that action at this time.