Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Bug 824705 - Data connection is lost on reboot if SIM PIN code is enabled #7232

Merged
merged 1 commit into from

2 participants

@fabi1cazenave
Collaborator

https://bugzilla.mozilla.org/show_bug.cgi?id=824705

I’m afraid I had to rewrite most of the operator_variant.js file…

apps/system/js/operator_variant/operator_variant.js
((43 lines not shown))
+ function getICCSettings(callback) {
+ var transaction = settings.createLock();
+ var mccKey = 'operatorvariant.mcc';
+ var mncKey = 'operatorvariant.mnc';
+
+ var mccRequest = transaction.get(mccKey);
+ mccRequest.onsuccess = function() {
+ iccSettings.mcc = parseInt(mccRequest.result[mccKey], 10) || 0;
+ callback();
+ };
+
+ var mncRequest = transaction.get(mncKey);
+ mncRequest.onsuccess = function() {
+ iccSettings.mnc = parseInt(mncRequest.result[mncKey], 10) || 0;
+ callback();
+ };
@vingtetun Collaborator

Why can't you simply nest them so the callback will be called only once?

@fabi1cazenave Collaborator

ugh. Yes of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
apps/system/js/operator_variant/operator_variant.js
((3 lines not shown))
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
(function OperatorVariant() {
- var gNetwork = null;
- var cset = null;
+ var iccSettings = { mcc: -1, mnc: -1 };
@vingtetun Collaborator

Let's declare that after the mozSettings check. No need to assign something that will be never used in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@vingtetun vingtetun merged commit 640173d into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 126 additions and 133 deletions.
  1. +126 −133 apps/system/js/operator_variant/operator_variant.js
View
259 apps/system/js/operator_variant/operator_variant.js
@@ -1,132 +1,83 @@
-/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
+/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
(function OperatorVariant() {
- var gNetwork = null;
- var cset = null;
+ /**
+ * Get the mcc/mnc info that has been stored in the settings.
+ */
- // Ensure Home Network Identity data.
- function ensureHNI() {
- var iccInfo = mobileConnection.iccInfo;
- if (!iccInfo) {
- return;
- }
+ var settings = window.navigator.mozSettings;
+ if (!settings)
+ return;
- if (gNetwork &&
- gNetwork.mcc == iccInfo.mcc &&
- gNetwork.mnc == iccInfo.mnc) {
- return;
- }
+ var iccSettings = { mcc: -1, mnc: -1 };
+
+ // Read the mcc/mnc settings, then trigger callback.
+ function getICCSettings(callback) {
+ var transaction = settings.createLock();
+ var mccKey = 'operatorvariant.mcc';
+ var mncKey = 'operatorvariant.mnc';
+
+ var mccRequest = transaction.get(mccKey);
+ mccRequest.onsuccess = function() {
+ iccSettings.mcc = parseInt(mccRequest.result[mccKey], 10) || 0;
+ var mncRequest = transaction.get(mncKey);
+ mncRequest.onsuccess = function() {
+ iccSettings.mnc = parseInt(mncRequest.result[mncKey], 10) || 0;
+ callback();
+ };
+ };
+ }
- gNetwork = {};
- gNetwork.mcc = iccInfo.mcc;
- gNetwork.mnc = iccInfo.mnc;
- applyOperatorVariantSettings();
- };
- function handleSettingsReady(key, value) {
- cset[key] = value;
- ensureHNI();
- applyOperatorVariantSettings();
- };
+ /**
+ * Compare the cached mcc/mnc info with the one in the SIM card,
+ * and retrieve/apply APN settings if they differ.
+ */
- function applyOperatorVariantSettings() {
- if (!cset['operatorvariant.mcc'] ||
- !cset['operatorvariant.mnc']) {
+ var mobileConnection = window.navigator.mozMobileConnection;
+ if (!mobileConnection)
+ return;
+
+ // Check the mcc/mnc information on the SIM card.
+ function checkICCInfo() {
+ if (!mobileConnection.iccInfo || mobileConnection.cardState !== 'ready')
return;
- }
- var cardState = mobileConnection.cardState;
- if (gNetwork.mcc == 0 && gNetwork.mnc == 0 && cardState == 'ready') {
+ // ensure that the iccSettings have been retrieved
+ if ((iccSettings.mcc < 0) || (iccSettings.mnc < 0))
return;
- }
- if ((gNetwork.mcc == cset['operatorvariant.mcc']) &&
- (gNetwork.mnc == cset['operatorvariant.mnc'])) {
+
+ // XXX sometimes we get 0/0 for mcc/mnc, even when cardState === 'ready'...
+ var mcc = parseInt(mobileConnection.iccInfo.mcc, 10) || 0;
+ var mnc = parseInt(mobileConnection.iccInfo.mnc, 10) || 0;
+ if (!mcc || !mnc)
return;
- }
- // new SIM card
- cset['operatorvariant.mcc'] = gNetwork.mcc;
- cset['operatorvariant.mnc'] = gNetwork.mnc;
- retrieveOperatorVariantSettings(function onsuccess(result) {
- var apnPrefNames = {
- 'default': {
- 'ril.data.carrier': 'carrier',
- 'ril.data.apn': 'apn',
- 'ril.data.user': 'user',
- 'ril.data.passwd': 'password',
- 'ril.data.httpProxyHost': 'proxy',
- 'ril.data.httpProxyPort': 'port'
- },
- 'supl': {
- 'ril.supl.carrier': 'carrier',
- 'ril.supl.apn': 'apn',
- 'ril.supl.user': 'user',
- 'ril.supl.passwd': 'password',
- 'ril.supl.httpProxyHost': 'proxy',
- 'ril.supl.httpProxyPort': 'port'
- },
- 'mms': {
- 'ril.mms.carrier': 'carrier',
- 'ril.mms.apn': 'apn',
- 'ril.mms.user': 'user',
- 'ril.mms.passwd': 'password',
- 'ril.mms.httpProxyHost': 'proxy',
- 'ril.mms.httpProxyPort': 'port',
- 'ril.mms.mmsc': 'mmsc',
- 'ril.mms.mmsproxy': 'mmsproxy',
- 'ril.mms.mmsport': 'mmsport'
- },
- 'operatorvariant': {
- 'ril.iccInfo.mbdn': 'voicemail',
- 'ril.sms.strict7BitEncoding.enabled': 'enableStrict7BitEncodingForSms',
- 'ril.cellbroadcast.searchlist': 'cellBroadcastSearchList'
- }
- };
+ // same SIM card => do nothing
+ if ((mcc == iccSettings.mcc) && (mnc == iccSettings.mnc))
+ return;
- var booleanPrefNames = [
- 'ril.sms.strict7BitEncoding.enabled'
- ];
-
- var transaction = settings.createLock();
- transaction.set(cset);
- for (var type in apnPrefNames) {
- var apn = {};
- for (var i = 0; i < result.length; i++) {
- if (result[i] && result[i].type.indexOf(type) != -1) {
- apn = result[i];
- break;
- }
- }
- var prefNames = apnPrefNames[type];
- for (var key in prefNames) {
- var name = apnPrefNames[type][key];
- var item = {};
- if (booleanPrefNames.indexOf(key) != -1) {
- item[key] = apn[name] || false;
- } else {
- item[key] = apn[name] || '';
- }
- transaction.set(item);
- }
- }
- });
+ // new SIM card => cache iccInfo, load and apply new APN settings
+ iccSettings.mcc = mcc;
+ iccSettings.mnc = mnc;
+ retrieveOperatorVariantSettings(applyOperatorVariantSettings);
};
+ // Load and query APN database, then trigger callback on results.
function retrieveOperatorVariantSettings(callback) {
var OPERATOR_VARIANT_FILE = 'shared/resources/apn.json';
- // load and query APN database, then trigger callback on results
var xhr = new XMLHttpRequest();
xhr.open('GET', OPERATOR_VARIANT_FILE, true);
xhr.responseType = 'json';
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status === 0)) {
var apn = xhr.response;
- var mcc = parseInt(cset['operatorvariant.mcc'], 10);
- var mnc = parseInt(cset['operatorvariant.mnc'], 10);
+ var mcc = iccSettings.mcc;
+ var mnc = iccSettings.mnc;
// get a list of matching APNs
var compatibleAPN = apn[mcc] ? (apn[mcc][mnc] || []) : [];
callback(compatibleAPN);
@@ -135,41 +86,83 @@
xhr.send();
}
- var settings = window.navigator.mozSettings;
- if (!settings) {
- return;
- }
- var mobileConnection = window.navigator.mozMobileConnection;
- if (!mobileConnection) {
- return;
- }
+ // Store APN settings for the first carrier matching the mcc/mnc info.
+ function applyOperatorVariantSettings(result) {
+ var apnPrefNames = {
+ 'default': {
+ 'ril.data.carrier': 'carrier',
+ 'ril.data.apn': 'apn',
+ 'ril.data.user': 'user',
+ 'ril.data.passwd': 'password',
+ 'ril.data.httpProxyHost': 'proxy',
+ 'ril.data.httpProxyPort': 'port'
+ },
+ 'supl': {
+ 'ril.supl.carrier': 'carrier',
+ 'ril.supl.apn': 'apn',
+ 'ril.supl.user': 'user',
+ 'ril.supl.passwd': 'password',
+ 'ril.supl.httpProxyHost': 'proxy',
+ 'ril.supl.httpProxyPort': 'port'
+ },
+ 'mms': {
+ 'ril.mms.carrier': 'carrier',
+ 'ril.mms.apn': 'apn',
+ 'ril.mms.user': 'user',
+ 'ril.mms.passwd': 'password',
+ 'ril.mms.httpProxyHost': 'proxy',
+ 'ril.mms.httpProxyPort': 'port',
+ 'ril.mms.mmsc': 'mmsc',
+ 'ril.mms.mmsproxy': 'mmsproxy',
+ 'ril.mms.mmsport': 'mmsport'
+ },
+ 'operatorvariant': {
+ 'ril.iccInfo.mbdn': 'voicemail',
+ 'ril.sms.strict7BitEncoding.enabled': 'enableStrict7BitEncodingForSms',
+ 'ril.cellbroadcast.searchlist': 'cellBroadcastSearchList'
+ }
+ };
- function onerrorRequest() {
- };
+ var booleanPrefNames = [
+ 'ril.sms.strict7BitEncoding.enabled'
+ ];
+
+ // store relevant APN settings
+ var transaction = settings.createLock();
+ for (var type in apnPrefNames) {
+ var apn = {};
+ for (var i = 0; i < result.length; i++) {
+ if (result[i] && result[i].type.indexOf(type) != -1) {
+ apn = result[i];
+ break;
+ }
+ }
+ var prefNames = apnPrefNames[type];
+ for (var key in prefNames) {
+ var name = apnPrefNames[type][key];
+ var item = {};
+ if (booleanPrefNames.indexOf(key) != -1) {
+ item[key] = apn[name] || false;
+ } else {
+ item[key] = apn[name] || '';
+ }
+ transaction.set(item);
+ }
+ }
- cset = {};
- var transaction = settings.createLock();
+ // store the current mcc/mnc info in the settings
+ transaction.set({
+ 'operatorvariant.mcc': iccSettings.mcc,
+ 'operatorvariant.mnc': iccSettings.mnc
+ });
+ }
- var mcc_request = transaction.get('operatorvariant.mcc');
- mcc_request.onsuccess = function() {
- var value = -1;
- if (mcc_request.result['operatorvariant.mcc']) {
- value = mcc_request.result['operatorvariant.mcc'];
- }
- handleSettingsReady('operatorvariant.mcc', value);
- };
- mcc_request.onerror = onerrorRequest;
- var mnc_request = transaction.get('operatorvariant.mnc');
- mnc_request.onsuccess = function() {
- var value = -1;
- if (mnc_request.result['operatorvariant.mnc']) {
- value = mnc_request.result['operatorvariant.mnc'];
- }
- handleSettingsReady('operatorvariant.mnc', value);
- };
- mnc_request.onerror = onerrorRequest;
+ /**
+ * Check the APN settings on startup and when the SIM card is changed.
+ */
- mobileConnection.addEventListener('iccinfochange', ensureHNI);
+ getICCSettings(checkICCInfo);
+ mobileConnection.addEventListener('iccinfochange', checkICCInfo);
})();
Something went wrong with that request. Please try again.