Skip to content

Commit 8e2434e

Browse files
committed
Bug 883298 - [FTU] Check whether there is no need to retrieve the APN settings from the apn.json database.
1 parent 8e5de39 commit 8e2434e

File tree

6 files changed

+62
-196
lines changed

6 files changed

+62
-196
lines changed

apps/communications/ftu/js/data_mobile.js

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var DataMobile = {
44
key: 'ril.data.enabled',
55
apnRetrieved: false,
66
init: function dm_init() {
7-
var settings = window.navigator.mozSettings;
7+
var settings = navigator.mozSettings;
88
if (!settings) {
99
console.log('Settings is not available');
1010
return;
@@ -39,49 +39,32 @@ var DataMobile = {
3939
return;
4040
}
4141
this.settings.createLock().set(options);
42-
self.apnRetrieved = true;
42+
this.apnRetrieved = true;
4343
this.isDataAvailable = status;
4444
if (callback)
4545
callback();
4646
},
47-
// TODO: Bug 883298 - [FTU] Check whether there is no need to retrieve the APN
48-
// settings from the apn.json database
4947
getAPN: function dm_getapn(callback) {
50-
// TODO Use 'shared' version
51-
var APN_FILE = '/shared/resources/apn.json';
52-
var self = this;
53-
// Retrieve the list of APN configurations
54-
// load and query APN database, then trigger callback on results
55-
var xhr = new XMLHttpRequest();
56-
xhr.open('GET', APN_FILE, true);
57-
xhr.responseType = 'json';
58-
xhr.onreadystatechange = function() {
59-
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status === 0)) {
60-
// TODO: read mcc and mnc codes from 'operatorvariant.{mcc, mnc}'.
61-
var mcc = IccHelper.iccInfo.mcc;
62-
var mnc = IccHelper.iccInfo.mnc;
63-
var apnList = xhr.response;
64-
var apns = apnList[mcc] ? (apnList[mcc][mnc] || []) : [];
65-
// Looks for a valid APN configuration for data calls.
66-
var selectedAPN = {};
67-
for (var i = 0; i < apns.length; i++) {
68-
if (apns[i] && apns[i].type.indexOf('default') != -1) {
69-
selectedAPN = apns[i];
70-
break;
48+
// By the time the APN settings are needed in the FTU before enabling data
49+
// calls the system app (through the operator variant logic) might store the
50+
// APN settings into the settings database. If not wait for that before
51+
// enabling data calls.
52+
var _self = this;
53+
function ensureApnSettings() {
54+
var req = _self.settings.createLock().get('ril.data.apnSettings');
55+
req.onsuccess = function loadApn() {
56+
var apnSettings = req.result['ril.data.apnSettings'];
57+
if (apnSettings) {
58+
if (callback) {
59+
callback(req.result);
7160
}
61+
_self.settings.removeObserver('ril.data.apnSettings',
62+
ensureApnSettings);
7263
}
73-
// Set data in 'Settings'
74-
var lock = self.settings.createLock();
75-
lock.set({ 'ril.data.apn': selectedAPN.apn || '' });
76-
lock.set({ 'ril.data.user': selectedAPN.user || '' });
77-
lock.set({ 'ril.data.passwd': selectedAPN.password || '' });
78-
lock.set({ 'ril.data.httpProxyHost': selectedAPN.proxy || '' });
79-
lock.set({ 'ril.data.httpProxyPort': selectedAPN.port || '' });
80-
if (callback) {
81-
callback();
82-
}
83-
}
84-
};
85-
xhr.send();
64+
};
65+
}
66+
67+
ensureApnSettings();
68+
this.settings.addObserver('ril.data.apnSettings', ensureApnSettings);
8669
}
8770
};

apps/communications/ftu/test/unit/data_mobile_test.js

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,65 @@
11
'use strict';
22

3-
requireApp('communications/ftu/test/unit/mock_icc_helper.js');
4-
requireApp('communications/ftu/test/unit/mock_settings.js');
5-
requireApp('system/test/unit/mock_settings_listener.js');
3+
requireApp('communications/shared/test/unit/mocks/mock_navigator_moz_settings.js');
64
requireApp('communications/ftu/js/data_mobile.js');
75

8-
var mocksHelperForNavigation = new MocksHelper(['IccHelper']);
9-
mocksHelperForNavigation.init();
10-
116
suite('mobile data >', function() {
127
var realSettings,
13-
settingKey = 'ril.data.enabled';
8+
settingToggleKey = 'ril.data.enabled',
9+
settingApnKey = 'ril.data.apnSettings';
1410
var mocksHelper = mocksHelperForNavigation;
1511

1612
suiteSetup(function() {
1713
realSettings = navigator.mozSettings;
18-
navigator.mozSettings = MockNavigatorSettings;
14+
navigator.mozSettings = window.MockNavigatorSettings;
1915

20-
mocksHelper.suiteSetup();
2116
DataMobile.init();
2217
});
2318

2419
suiteTeardown(function() {
2520
navigator.mozSettings = realSettings;
2621
realSettings = null;
27-
28-
mocksHelper.suiteTeardown();
2922
});
3023

31-
test('load APN values from file', function(done) {
32-
var settingList = ['ril.data.apn',
33-
'ril.data.user',
34-
'ril.data.passwd',
35-
'ril.data.httpProxyHost',
36-
'ril.data.httpProxyPort'];
37-
// real values taken from /shared/resources/apn.json, careful if changed
38-
IccHelper.setProperty('iccInfo', {mcc: '214', mnc: '07'});
39-
for (var settingName in settingList) {
40-
MockNavigatorSettings.mSettings[settingList[settingName]] = null;
41-
}
42-
43-
DataMobile.getAPN(function() {
44-
for (var settingName in settingList) {
45-
assert.isNotNull(
46-
MockNavigatorSettings.mSettings[settingList[settingName]]);
47-
}
48-
done();
24+
suite('Load APN values from database', function() {
25+
var result;
26+
27+
setup(function(done) {
28+
window.MockNavigatorSettings.mSettings[settingApnKey] = '[[]]';
29+
DataMobile.getAPN(function(response) {
30+
result = response;
31+
done();
32+
});
33+
});
34+
35+
test('Values are loaded', function() {
36+
assert.isNotNull(result);
37+
});
38+
39+
test('Observer is added before', function() {
40+
assert.isNotNull(window.MockNavigatorSettings.mObservers);
41+
});
42+
43+
test('Observer is removed after', function() {
44+
assert.isNotNull(window.MockNavigatorSettings.mRemovedObservers);
4945
});
5046
});
5147

52-
test('toggle status of mobile data', function(done) {
53-
// real values taken from /shared/resources/apn.json, careful if changed
54-
IccHelper.setProperty('iccInfo', {mcc: '214', mnc: '07'});
55-
DataMobile.toggle(false, function() {
56-
assert.isFalse(MockNavigatorSettings.mSettings[settingKey]);
57-
done();
48+
suite('Toggle status of mobile data', function() {
49+
test('toggle status of mobile data', function(done) {
50+
DataMobile.toggle(true, function() {
51+
assert.isTrue(window.MockNavigatorSettings.mSettings[settingToggleKey]);
52+
done();
53+
});
54+
});
55+
56+
test('toggle status of mobile data', function(done) {
57+
DataMobile.toggle(false, function() {
58+
assert.isFalse(
59+
window.MockNavigatorSettings.mSettings[settingToggleKey]
60+
);
61+
done();
62+
});
5863
});
5964
});
6065

apps/communications/ftu/test/unit/language_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
requireApp('communications/ftu/test/unit/mock_navigator_settings.js');
3+
requireApp('communications/shared/test/unit/mocks/mock_navigator_moz_settings.js');
44
requireApp('communications/ftu/test/unit/mock_settings.js');
55
requireApp('communications/ftu/js/language.js');
66

apps/communications/ftu/test/unit/mock_navigator_settings.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

apps/communications/ftu/test/unit/mock_settings.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

apps/communications/ftu/test/unit/mock_settings_listener.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)