This repository has been 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
/
operator_variant_manager.js
108 lines (99 loc) · 3.2 KB
/
operator_variant_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
/* global BaseModule, OperatorVariantHandler, SIMSlotManager */
'use strict';
/**
* Singleton object that helps to set some carrier-specific settings on boot.
* Detects the ICC cards on boot and creates objects in charge of setting
* some operator-specific settings relying on the ICC card.
*/
(function() {
var OperatorVariantManager = function(core) {
/** Array of OperatorVariantHandler objects. */
if (core) {
this.mobileConnections = core.mobileConnections;
}
this.operatorVariantHandlers = [];
};
OperatorVariantManager.IMPORTS = [
'js/operator_variant_handler.js',
'../shared/js/operator_variant_helper.js'
];
OperatorVariantManager.EVENTS = [
'simslot-updated',
'simslot-iccinfochange'
];
BaseModule.create(OperatorVariantManager, {
name: 'OperatorVariantManager',
_start: function() {
Promise.all([
this.ensureValueUnderKeyIsArray('ril.iccInfo.mbdn'),
this.ensureValueUnderKeyIsArray('ril.cellbroadcast.disabled'),
this.ensureValueUnderKeyIsArray('ril.cellbroadcast.searchlist'),
this.readSetting('deviceinfo.os')
]).then(function(result) {
this.deviceInfoOs = result[3];
this.init();
}.bind(this));
},
_stop: function() {
this._operatorVariantHandlers = [];
},
'_handle_simslot-updated': function(evt) {
var simslot = evt.detail;
this._updateOperatorVariantHandler(simslot);
},
'_handle_simslot-iccinfochange': function(evt) {
var simslot = evt.detail;
this._updateOperatorVariantHandler(simslot);
},
_updateOperatorVariantHandler: function(simslot) {
if (!simslot.simCard ||
!simslot.simCard.iccInfo ||
!simslot.simCard.iccInfo.iccid) {
this.operatorVariantHandlers[simslot.index] = null;
return;
}
if (!this.operatorVariantHandlers[simslot.index]) {
this.operatorVariantHandlers[simslot.index] =
new OperatorVariantHandler(simslot.simCard.iccInfo.iccid,
simslot.index, this);
this.operatorVariantHandlers[simslot.index].start();
}
},
init: function() {
SIMSlotManager.getSlots().forEach(function(slot) {
this._updateOperatorVariantHandler(slot);
}, this);
},
/**
* Helper function. Ensure the value stored under the specified key is an
* array.
*/
ensureValueUnderKeyIsArray: function(key) {
return new Promise(function(resolve, reject) {
this.readSetting(key).then(function(value) {
var originalSetting = value;
var newSetting = null;
if (!originalSetting) {
newSetting = ['', ''];
} else if (!Array.isArray(originalSetting)) {
// Migrate settings field if needed
newSetting = [originalSetting, ''];
}
if (newSetting) {
var obj = {};
obj[key] = newSetting;
this.writeSetting(obj).then(function() {
resolve();
}, function() {
resolve();
});
} else {
resolve();
}
}.bind(this), function() {
resolve();
}.bind(this));
}.bind(this));
}
});
})();