Repository navigation
Expand file tree
/
Copy pathsettings.js
More file actions
170 lines (140 loc) · 4.76 KB
/
Copy pathsettings.js
File metadata and controls
170 lines (140 loc) · 4.76 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
/*
Message app settings related value and utilities.
*/
/* global MobileOperator*/
/* exported Settings */
'use strict';
var Settings = {
SERVICE_ID_KEYS: {
mmsServiceId: 'ril.mms.defaultServiceId',
smsServiceId: 'ril.sms.defaultServiceId'
},
_serviceIds: null,
mmsSizeLimitation: 300 * 1024, // Default mms message size limitation is 300K.
mmsServiceId: null, // Default mms service SIM ID
smsServiceId: null, // Default sms service SIM ID
init: function settings_init() {
var keyHandlerSet = {
'dom.mms.operatorSizeLimitation': Settings.initMmsSizeLimitation
};
var settings = navigator.mozSettings;
var conns = navigator.mozMobileConnections;
function setHandlerMap(key) {
var req = settings.createLock().get(key);
req. settings_getSizeSuccess() {
var handler = keyHandlerSet[key];
handler(req.result[key]);
};
}
this._serviceIds = [];
if (!settings) {
return;
}
// Only DSDS will need to handle mmsServiceId
if (conns && conns.length > 1) {
for (var prop in this.SERVICE_ID_KEYS) {
var setting = this.SERVICE_ID_KEYS[prop];
keyHandlerSet[setting] = this.initServiceId.bind(this, setting, prop);
}
// Cache all existing serviceIds
for (var i = 0, l = conns.length; i < l; i++) {
this._serviceIds.push(conns[i].iccId);
}
}
for (var key in keyHandlerSet) {
setHandlerMap(key);
}
},
// Set MMS size limitation:
// If operator does not specify MMS message size, we leave the decision to
// MessageManager and return nothing if we can't get size limitation from db
initMmsSizeLimitation: function initMmsSizeLimitation(size) {
if (size && !isNaN(size)) {
Settings.mmsSizeLimitation = size;
}
},
// Set default mms service SIM ID and add observer:
// In DSDS scenario, if we notify user to switch to subscription to retrieve
// the MMS from non-active subscription, we'll need current mmsServiceId
// information to tell user the active/non-active subscription
initServiceId: function initMmsServiceId(settingName, propName, id) {
if (id !== undefined) {
Settings[propName] = id;
}
navigator.mozSettings.addObserver(settingName, function(e) {
Settings[propName] = e.settingValue;
});
},
setMmsSimServiceId: function setSimServiceId(id) {
// DSDS: mms & data are both necessary for connection switch.
navigator.mozSettings.createLock().set({
'ril.mms.defaultServiceId': id,
'ril.data.defaultServiceId': id
});
},
switchMmsSimHandler: function switchSimHandler(targetId, callback) {
var conn = window.navigator.mozMobileConnections[targetId];
if (conn && conn.data.state !== 'registered') {
// Listen to MobileConnections datachange to make sure we can start
// to retrieve mms only when data.state is registered. But we can't
// guarantee datachange event will work in other device.
conn.addEventListener('datachange', function onDataChange() {
if (conn.data.state === 'registered') {
conn.removeEventListener('datachange', onDataChange);
callback();
}
});
this.setMmsSimServiceId(targetId);
}
},
/**
* returns true if the device has more than 1 SIM port
*/
isDualSimDevice: function isDualSimDevice() {
return this._serviceIds && this._serviceIds.length > 1;
},
/**
* Returns true if the device has more than 1 SIM port and at least 2 SIMs are
* inserted.
*/
hasSeveralSim: function hasSeveralSim() {
if (!this.isDualSimDevice()) {
return false;
}
var simCount = this._serviceIds.reduce(function(simCount, iccId) {
return iccId === null ? simCount : simCount + 1;
}, 0);
return simCount > 1;
},
getServiceIdByIccId: function getServiceIdByIccId(iccId) {
if (!this._serviceIds) {
return null;
}
var index = this._serviceIds.indexOf(iccId);
return index > -1 ? index : null;
},
/**
* Will return SIM1 or SIM2 (locale dependent) depending on the iccId.
* Will return the empty string in a single SIM scenario.
*/
getSimNameByIccId: function getSimNameByIccId(iccId) {
var index = this.getServiceIdByIccId(iccId);
if (index === null) {
return '';
}
var simName = navigator.mozL10n.get('sim-name', { id: index + 1 });
return simName;
},
/**
* Will return operator name depending on the iccId.
* Will return the empty string in a single SIM scenario.
*/
getOperatorByIccId: function getOperatorByIccId(iccId) {
var index = this.getServiceIdByIccId(iccId);
if (index === null) {
return '';
}
var conn = navigator.mozMobileConnections[index];
return MobileOperator.userFacingInfo(conn).operator;
}
};