Skip to content

Commit 1be4f5d

Browse files
Ghislain 'Aus' Lacroixqdot
authored andcommitted
bug 915920 - ensure APN settings only get applied once per boot.
1 parent a360f6f commit 1be4f5d

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

apps/system/js/operator_variant/operator_variant.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
'use strict';
55

66
(function OperatorVariant() {
7+
// Reserved Test Network MCC. This is how we know we're running tests vs
8+
// running in the real world.
9+
const TEST_NETWORK_MCC = 1;
710

811
// Cache the values we've seen.
912
var iccSettings = { mcc: -1, mnc: -1 };
@@ -37,6 +40,14 @@
3740
operatorVariantHelper.listen();
3841

3942
function applySettings(mcc, mnc) {
43+
44+
// Only apply once per device boot-up, except when in tests. All tests
45+
// use the reserved Test Network MCC value of '1'. See this handy table
46+
// for more information: http://en.wikipedia.org/wiki/Mobile_country_code
47+
if (mcc != TEST_NETWORK_MCC) {
48+
operatorVariantHelper.listen(false);
49+
}
50+
4051
// same SIM card => do nothing
4152
if ((mcc == iccSettings.mcc) && (mnc == iccSettings.mnc)) {
4253
var apnSettingsKey = 'ril.data.apnSettings';

apps/system/test/unit/operator_variant_test.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var mocksForOperatorVariant = new MocksHelper([
1010
]).init();
1111

1212
suite('operator variant', function() {
13-
const TEST_NETWORK_MCC = 111;
13+
const TEST_NETWORK_MCC = 1;
1414

1515
const EXPECTED_DATA_MNC = 1;
1616
const EXPECTED_DATA_ICC_INFO = {
@@ -30,6 +30,20 @@ suite('operator variant', function() {
3030
mnc: EXPECTED_OV_MNC
3131
};
3232

33+
const T_MOBILE_US_MCC = 310;
34+
const T_MOBILE_160_US_MNC = 160;
35+
const T_MOBILE_200_US_MNC = 200;
36+
37+
const T_MOBILE_160_US_ICC_INFO = {
38+
mcc: T_MOBILE_US_MCC,
39+
mnc: T_MOBILE_160_US_MNC
40+
};
41+
42+
const T_MOBILE_200_US_ICC_INFO = {
43+
mcc: T_MOBILE_US_MCC,
44+
mnc: T_MOBILE_200_US_MNC
45+
};
46+
3347
const NULL_ICC_INFO = { mcc: 0, mnc: 0 };
3448
const PERSIST_KEY = 'operator_variant_test.customize';
3549

@@ -198,4 +212,37 @@ suite('operator variant', function() {
198212
MockIccHelper.mProps.iccInfo = EXPECTED_OV_ICC_INFO;
199213
MockIccHelper.mTriggerEventListeners('iccinfochange', {});
200214
});
215+
216+
test('operator variant apply once per boot', function() {
217+
var observer = {
218+
bound: null,
219+
hasApplied: false,
220+
func: function(event) {
221+
if (event.settingName == 'ril.data.carrier') {
222+
assert.false(
223+
this.hasApplied,
224+
'Settings should *not* be applied twice!'
225+
);
226+
227+
assert.match(
228+
event.settingValue,
229+
/^T-Mobile US/,
230+
'Expected network name to contain "T-Mobile US"'
231+
);
232+
233+
this.hasApplied = true;
234+
}
235+
}
236+
};
237+
238+
observer.bound = observer.func.bind(observer);
239+
MockNavigatorSettings.addObserver('ril.data.carrier', observer.bound);
240+
241+
// Testing apply once per boot requires *real* mcc/mnc information.
242+
MockIccHelper.mProps.iccInfo = T_MOBILE_160_US_ICC_INFO;
243+
MockIccHelper.mTriggerEventListeners('iccinfochange', {});
244+
245+
MockIccHelper.mProps.iccInfo = T_MOBILE_200_US_ICC_INFO;
246+
MockIccHelper.mTriggerEventListeners('iccinfochange', {});
247+
});
201248
});

shared/resources/apn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"111": {
2+
"1": {
33
"01": [
44
{"carrier":"Test Network","apn":"internet","user":"user","password":"password","proxy":"127.0.0.1","port":"8080","authtype":"0","type":["default","supl"]}
55
],

shared/resources/apn/apns_conf_local.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- This version must agree with that in apps/common/res/apns.xml -->
55
<apns version="7">
66
<apn carrier="Test Network"
7-
mcc="111"
7+
mcc="001"
88
mnc="01"
99
apn="internet"
1010
user="user"
@@ -16,7 +16,7 @@
1616
/>
1717

1818
<apn carrier="Test Network with MMS"
19-
mcc="111"
19+
mcc="001"
2020
mnc="02"
2121
apn="mms.internet"
2222
user="user"
@@ -31,7 +31,7 @@
3131
/>
3232

3333
<apn carrier="Test Network with Operator Variant Settings"
34-
mcc="111"
34+
mcc="001"
3535
mnc="03"
3636
apn="mms.internet"
3737
user="user"

0 commit comments

Comments
 (0)