diff options
author | stevenjb <stevenjb@chromium.org> | 2015-08-26 15:37:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-26 22:38:48 +0000 |
commit | cb3e62bb1c12287fd489abba028fb828aa99668c (patch) | |
tree | f9a1b25fcb113ea2a7e32ccc5e4dd2e6de03b8fa | |
parent | 510aaf4ba59a05ec3219f3aa5d0bfcac50decf5d (diff) | |
download | chromium_src-cb3e62bb1c12287fd489abba028fb828aa99668c.zip chromium_src-cb3e62bb1c12287fd489abba028fb828aa99668c.tar.gz chromium_src-cb3e62bb1c12287fd489abba028fb828aa99668c.tar.bz2 |
Add SIM state to DeviceStateProperties
On an actual device, no Shill network exists for Cellular networks
with a locked SIM, so we need to provide the SIM state in the
DeviceStateProperties.
BUG=516367
Review URL: https://codereview.chromium.org/1304413004
Cr-Commit-Position: refs/heads/master@{#345702}
5 files changed, 32 insertions, 23 deletions
diff --git a/chrome/browser/resources/options/chromeos/network_list.js b/chrome/browser/resources/options/chromeos/network_list.js index fa90fac..d3978c9 100644 --- a/chrome/browser/resources/options/chromeos/network_list.js +++ b/chrome/browser/resources/options/chromeos/network_list.js @@ -71,10 +71,10 @@ cr.define('options.network', function() { /** * The state of the cellular device or undefined if not available. - * @type {string|undefined} + * @type {?chrome.networkingPrivate.DeviceStateProperties} * @private */ - var cellularDeviceState_ = undefined; + var cellularDevice_ = null; /** * The active cellular network or null if none. @@ -467,25 +467,20 @@ cr.define('options.network', function() { /** * Returns true if |cellular| is a GSM network with no sim present. - * @param {?NetworkProperties} cellular The network state properties. + * @param {?chrome.networkingPrivate.DeviceStateProperties} cellularDevice * @return {boolean} Whether |network| is missing a SIM card. */ - function isCellularSimAbsent(cellular) { - if (!cellular || !cellular.Cellular) - return false; - return cellular.Cellular.Family == 'GSM' && !cellular.Cellular.SIMPresent; + function isCellularSimAbsent(cellularDevice) { + return !!cellularDevice && cellularDevice.SimPresent === false; } /** * Returns true if |cellular| has a locked SIM card. - * @param {?NetworkProperties} cellular The network state properties. + * @param {?chrome.networkingPrivate.DeviceStateProperties} cellularDevice * @return {boolean} Whether |network| has a locked SIM card. */ - function isCellularSimLocked(cellular) { - if (!cellular || !cellular.Cellular) - return false; - var simLockStatus = cellular.Cellular.SIMLockStatus; - return !!(simLockStatus && simLockStatus.LockType); + function isCellularSimLocked(cellularDevice) { + return !!cellularDevice && !!cellularDevice.SimLockType; } NetworkSelectorItem.prototype = { @@ -551,7 +546,7 @@ cr.define('options.network', function() { data: {} }); } else if (this.data_.key == 'Cellular') { - if (cellularDeviceState_ == 'Enabled' && + if (cellularDevice_.State == 'Enabled' && cellularNetwork_ && cellularNetwork_.Cellular && cellularNetwork_.Cellular.SupportNetworkScan) { addendum.push({ @@ -1118,7 +1113,7 @@ cr.define('options.network', function() { */ updateNetworkStates: function(deviceStates, networkStates) { // Update device states. - cellularDeviceState_ = undefined; + cellularDevice_ = null; wifiDeviceState_ = undefined; wimaxDeviceState_ = undefined; for (var i = 0; i < deviceStates.length; ++i) { @@ -1126,7 +1121,7 @@ cr.define('options.network', function() { var type = device.Type; var state = device.State; if (type == 'Cellular') - cellularDeviceState_ = cellularDeviceState_ || state; + cellularDevice_ = cellularDevice_ || device; else if (type == 'WiFi') wifiDeviceState_ = wifiDeviceState_ || state; else if (type == 'WiMAX') @@ -1205,10 +1200,10 @@ cr.define('options.network', function() { addEnableNetworkButton_(chrome.networkingPrivate.NetworkType.WI_FI); // Only show cellular control if available. - if (cellularDeviceState_) { - if (cellularDeviceState_ == 'Enabled' && - !isCellularSimLocked(cellularNetwork_) && - !isCellularSimAbsent(cellularNetwork_)) { + if (cellularDevice_) { + if (cellularDevice_.State == 'Enabled' && + !isCellularSimAbsent(cellularDevice_) && + !isCellularSimLocked(cellularDevice_)) { loadData_('Cellular', networkStates); } else { addEnableNetworkButton_( @@ -1247,10 +1242,10 @@ cr.define('options.network', function() { if (type == chrome.networkingPrivate.NetworkType.WI_FI) sendChromeMetricsAction('Options_NetworkWifiToggle'); if (type == chrome.networkingPrivate.NetworkType.CELLULAR) { - if (isCellularSimLocked(cellularNetwork_)) { + if (isCellularSimLocked(cellularDevice_)) { chrome.send('simOperation', ['unlock']); return; - } else if (isCellularSimAbsent(cellularNetwork_)) { + } else if (isCellularSimAbsent(cellularDevice_)) { chrome.send('simOperation', ['configure']); return; } diff --git a/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js b/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js index 8c5d600..33740bf 100644 --- a/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js +++ b/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js @@ -417,7 +417,7 @@ var availableTests = [ assertEq([ {Scanning: false, State: 'Enabled', Type: 'Ethernet'}, {Scanning: false, State: 'Enabled', Type: 'WiFi'}, - {State: 'Uninitialized', Type: 'Cellular'}, + {State: 'Uninitialized', Type: 'Cellular', SimPresent: true}, {State: 'Disabled', Type: 'WiMAX'}, ], result); diff --git a/extensions/browser/api/networking_private/networking_private_chromeos.cc b/extensions/browser/api/networking_private/networking_private_chromeos.cc index fb04158..76f504c 100644 --- a/extensions/browser/api/networking_private/networking_private_chromeos.cc +++ b/extensions/browser/api/networking_private/networking_private_chromeos.cc @@ -120,6 +120,11 @@ void AppendDeviceState( properties->state = state; if (device && state == private_api::DEVICE_STATE_TYPE_ENABLED) properties->scanning.reset(new bool(device->scanning())); + if (device && type == ::onc::network_config::kCellular) { + properties->sim_present.reset(new bool(!device->IsSimAbsent())); + if (!device->sim_lock_type().empty()) + properties->sim_lock_type.reset(new std::string(device->sim_lock_type())); + } device_state_list->push_back(properties.Pass()); } diff --git a/extensions/common/api/networking_private.idl b/extensions/common/api/networking_private.idl index 6f77414..f393d23 100644 --- a/extensions/common/api/networking_private.idl +++ b/extensions/common/api/networking_private.idl @@ -105,6 +105,13 @@ namespace networkingPrivate { // Set if the device is enabled. True if the device is currently scanning. boolean? Scanning; + // Set to the SIM lock type if the device type is Cellular and the device + // is locked. + DOMString? SimLockType; + + // Set to the SIM present state if the device type is Cellular. + boolean? SimPresent; + // The current state of the device. DeviceStateType State; diff --git a/third_party/closure_compiler/externs/networking_private.js b/third_party/closure_compiler/externs/networking_private.js index 5bca988..ccfb608 100644 --- a/third_party/closure_compiler/externs/networking_private.js +++ b/third_party/closure_compiler/externs/networking_private.js @@ -142,6 +142,8 @@ chrome.networkingPrivate.CellularStateProperties; /** * @typedef {{ * Scanning: (boolean|undefined), + * SimLockType: (string|undefined), + * SimPresent: (boolean|undefined), * State: !chrome.networkingPrivate.DeviceStateType, * Type: !chrome.networkingPrivate.NetworkType * }} |