Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #15752 from cctuan/950185-2
Browse files Browse the repository at this point in the history
Bug 950185 - [B2G] [Settings] Network type does not show user friendly o...
  • Loading branch information
cctuan committed Jan 28, 2014
2 parents 01156db + a2ff2a6 commit b24e02d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 64 deletions.
2 changes: 1 addition & 1 deletion apps/settings/js/call.js
Expand Up @@ -795,7 +795,7 @@ var CallSettings = (function(window, document, undefined) {
*/
function cs_initVoicePrivacyMode() {
// get network type
getSupportedNetworkInfo(function(result) {
getSupportedNetworkInfo(_mobileConnection, function(result) {
if (!result.cdma) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletions apps/settings/js/carrier.js
Expand Up @@ -89,7 +89,7 @@ var CarrierSettings = (function(window, document, undefined) {
* Bug 881862 is filed for tracking this.
*/
// get network type
getSupportedNetworkInfo(function(result) {
getSupportedNetworkInfo(_mobileConnection, function(result) {
var content =
document.getElementById('carrier-operatorSettings-content');

Expand Down Expand Up @@ -262,7 +262,8 @@ var CarrierSettings = (function(window, document, undefined) {
var continueButton = alertDialog.querySelector('button');
continueButton.addEventListener('click', function onClickHandler() {
alertDialog.hidden = true;
getSupportedNetworkInfo(function getSupportedNetworkInfoCb(result) {
getSupportedNetworkInfo(_mobileConnection,
function getSupportedNetworkInfoCb(result) {
if (result.networkTypes) {
cs_updateNetworkTypeSelector(result.networkTypes,
result.gsm,
Expand Down
17 changes: 11 additions & 6 deletions apps/settings/js/sound.js
@@ -1,17 +1,22 @@
/* global getSupportedNetworkInfo, SettingsListener, ForwardLock, URL,
MozActivity */
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */

(function() {
'use strict';

var _ = navigator.mozL10n.get;

// Show the touch tone selector if and only if we're on a CDMA network
getSupportedNetworkInfo(function(result) {
(function() {
var mobileConnections = window.navigator.mozMobileConnections;
// Show the touch tone selector if and only if we're on a CDMA network
var toneSelector = document.getElementById('touch-tone-selector');
toneSelector.hidden = !result.cdma;
});

Array.prototype.forEach.call(mobileConnections, function(mobileConnection) {
getSupportedNetworkInfo(mobileConnection, function(result) {
toneSelector.hidden = toneSelector.hidden && !result.cdma;
});
});
})();
// Now initialize the ring tone and alert tone menus.

// This array has one element for each selectable tone that appears in the
Expand Down
82 changes: 38 additions & 44 deletions apps/settings/js/utils.js
Expand Up @@ -209,53 +209,47 @@ var getNfc = function() {
* The function returns an object of the supporting state of category of network
* types. The categories are 'gsm' and 'cdma'.
*/
var getSupportedNetworkInfo = (function() {
var _result = null;

return function(callback) {
if (!callback)
return;

// early return if the result is available
if (_result) {
callback(_result);
return;
}
function getSupportedNetworkInfo(mobileConneciton, callback) {
var types = [
'wcdma/gsm',
'gsm',
'wcdma',
'wcdma/gsm-auto',
'cdma/evdo',
'cdma',
'evdo',
'wcdma/gsm/cdma/evdo'
];
if (!mobileConneciton)
return;

// get network type
loadJSON('/resources/network.json', function loadNetwork(network) {
_result = {
gsm: false,
cdma: false,
networkTypes: null
};
var _hwSupportedTypes = mobileConneciton.supportedNetworkTypes;

/*
* Possible values of the item in network.types are:
* "wcdma/gsm", "gsm", "wcdma", "wcdma/gsm-auto",
* "cdma/evdo", "cdma", "evdo", "wcdma/gsm/cdma/evdo"
*/
if (network.types) {
var types = _result.networkTypes = network.types;
for (var i = 0; i < types.length; i++) {
var type = types[i];
type.split('/').forEach(function(subType) {
_result.gsm = _result.gsm || (subType === 'gsm') ||
(subType === 'gsm-auto') || (subType === 'wcdma');
_result.cdma = _result.cdma || (subType === 'cdma') ||
(subType === 'evdo');
});

if (_result.gsm && _result.cdma) {
break;
}
}
}

callback(_result);
});
var _result = {
gsm: _hwSupportedTypes.indexOf('gsm') !== -1,
cdma: _hwSupportedTypes.indexOf('cdma') !== -1,
wcdma: _hwSupportedTypes.indexOf('wcdma') !== -1,
evdo: _hwSupportedTypes.indexOf('evdo') !== -1,
networkTypes: null
};
})();

var _networkTypes = [];
for (var i = 0; i < types.length; i++) {
var type = types[i];
var subtypes = type.split('/');
var allSubTypesSupported = true;
for (var j = 0; j < subtypes.length; j++) {
allSubTypesSupported =
allSubTypesSupported && _result[subtypes[j].split('-')[0]];
}
if (allSubTypesSupported)
_networkTypes.push(type);
}
if (_networkTypes.length !== 0) {
_result.networkTypes = _networkTypes;
}
callback(_result);
}

function isIP(address) {
return /^\d+\.\d+\.\d+\.\d+$/.test(address);
Expand Down
11 changes: 0 additions & 11 deletions build/applications-data.js
Expand Up @@ -382,17 +382,6 @@ function execute(options) {
utils.writeContent(init,
utils.getDistributionFileContent('support', content, distDir));

// Network Types
init = utils.getFile(config.GAIA_DIR,
'apps', 'settings', 'resources', 'network.json');
content = {
'types': ['wcdma/gsm', 'gsm', 'wcdma', 'wcdma/gsm-auto', 'cdma/evdo',
'cdma', 'evdo', 'wcdma/gsm/cdma/evdo']
};

utils.writeContent(init,
utils.getDistributionFileContent('network', content, distDir));

// ICC / STK
init = utils.getFile(config.GAIA_DIR,
'apps', 'system', 'resources', 'icc.json');
Expand Down

0 comments on commit b24e02d

Please sign in to comment.