Commit f9e92628 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Network config: Support Cellular disabling in UI

This introduces a 'disabling' state to the cros_network_config.mojo API
and uses it in the system menu and settigns UI.

It also removes the 'Enabling' state from network_health.mojom
(instead of adding 'Disabling') since we don't care about either from
a network health perspective; the intermediate states are pseudo states
for the UI only.

Bug: 1032030
Change-Id: I1301cd87068ee8d98bf63b004dc3e9857c3bcdca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225370Reviewed-by: default avatarAzeem Arshad <azeemarshad@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774627}
parent 179ba398
...@@ -1682,6 +1682,9 @@ This file contains the strings for ash. ...@@ -1682,6 +1682,9 @@ This file contains the strings for ash.
<message name="IDS_ASH_STATUS_TRAY_NETWORK_MOBILE_DISABLED" desc="The message to display in the network list when mobile data is turned off."> <message name="IDS_ASH_STATUS_TRAY_NETWORK_MOBILE_DISABLED" desc="The message to display in the network list when mobile data is turned off.">
Mobile data is turned off. Mobile data is turned off.
</message> </message>
<message name="IDS_ASH_STATUS_TRAY_NETWORK_MOBILE_DISABLING" desc="The message to display in the network list when mobile data is turning off (disabling).">
Mobile data is turning off...
</message>
<message name="IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED" desc="The label used in system tray bubble to display vpn is disconnected."> <message name="IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED" desc="The label used in system tray bubble to display vpn is disconnected.">
VPN disconnected VPN disconnected
</message> </message>
......
...@@ -165,10 +165,15 @@ int MobileSectionHeaderView::UpdateToggleAndGetStatusMessage( ...@@ -165,10 +165,15 @@ int MobileSectionHeaderView::UpdateToggleAndGetStatusMessage(
SetToggleVisibility(false); SetToggleVisibility(false);
return IDS_ASH_STATUS_TRAY_SIM_CARD_MISSING; return IDS_ASH_STATUS_TRAY_SIM_CARD_MISSING;
} }
bool toggle_enabled = default_toggle_enabled &&
(cellular_state == DeviceStateType::kEnabled ||
cellular_state == DeviceStateType::kDisabled);
bool cellular_enabled = cellular_state == DeviceStateType::kEnabled; bool cellular_enabled = cellular_state == DeviceStateType::kEnabled;
SetToggleVisibility(true); SetToggleVisibility(true);
SetToggleState(default_toggle_enabled, cellular_enabled); SetToggleState(toggle_enabled, cellular_enabled);
if (cellular_state == DeviceStateType::kDisabling) {
return IDS_ASH_STATUS_TRAY_NETWORK_MOBILE_DISABLING;
}
if (cellular_device->sim_lock_status && if (cellular_device->sim_lock_status &&
!cellular_device->sim_lock_status->lock_type.empty()) { !cellular_device->sim_lock_status->lock_type.empty()) {
......
...@@ -1686,6 +1686,9 @@ ...@@ -1686,6 +1686,9 @@
<message name="IDS_SETTINGS_INTERNET_DEVICE_ENABLING" desc="Settings > Internet > Message when a device (e.g a Cellular modem) is enabling."> <message name="IDS_SETTINGS_INTERNET_DEVICE_ENABLING" desc="Settings > Internet > Message when a device (e.g a Cellular modem) is enabling.">
Enabling Enabling
</message> </message>
<message name="IDS_SETTINGS_INTERNET_DEVICE_DISABLING" desc="Settings > Internet > Message when a Cellular modem is turning off (disabling).">
Turning off
</message>
<message name="IDS_SETTINGS_INTERNET_DEVICE_INITIALIZING" desc="Settings > Internet > Message when a device (e.g a Cellular modem) is initializing."> <message name="IDS_SETTINGS_INTERNET_DEVICE_INITIALIZING" desc="Settings > Internet > Message when a device (e.g a Cellular modem) is initializing.">
Initializing Initializing
</message> </message>
......
...@@ -13,14 +13,12 @@ import "chromeos/services/network_config/public/mojom/network_types.mojom"; ...@@ -13,14 +13,12 @@ import "chromeos/services/network_config/public/mojom/network_types.mojom";
enum NetworkState { enum NetworkState {
// The network type is available but not yet initialized. // The network type is available but not yet initialized.
kUninitialized, kUninitialized,
// The network type is available but disabled. // The network type is available but disabled or disabling.
kDisabled, kDisabled,
// The network type is available and enabling.
kEnabling,
// The network type is prohibited by policy. // The network type is prohibited by policy.
kProhibited, kProhibited,
// The network type is available and enabled, but no network connection has // The network type is available and enabled or enabling, but no network
// been established. // connection has been established.
kNotConnected, kNotConnected,
// The network type is available and enabled, and a network connection is // The network type is available and enabled, and a network connection is
// in progress. // in progress.
......
...@@ -22,9 +22,11 @@ constexpr mojom::NetworkState DeviceStateToNetworkState( ...@@ -22,9 +22,11 @@ constexpr mojom::NetworkState DeviceStateToNetworkState(
case network_config::mojom::DeviceStateType::kUninitialized: case network_config::mojom::DeviceStateType::kUninitialized:
return mojom::NetworkState::kUninitialized; return mojom::NetworkState::kUninitialized;
case network_config::mojom::DeviceStateType::kDisabled: case network_config::mojom::DeviceStateType::kDisabled:
return mojom::NetworkState::kDisabled; case network_config::mojom::DeviceStateType::kDisabling:
case network_config::mojom::DeviceStateType::kEnabling: case network_config::mojom::DeviceStateType::kEnabling:
return mojom::NetworkState::kEnabling; // Disabling and Enabling are intermediate state that we care about in the
// UI, but not for purposes of network health, we can treat as Disabled.
return mojom::NetworkState::kDisabled;
case network_config::mojom::DeviceStateType::kEnabled: case network_config::mojom::DeviceStateType::kEnabled:
return mojom::NetworkState::kNotConnected; return mojom::NetworkState::kNotConnected;
case network_config::mojom::DeviceStateType::kProhibited: case network_config::mojom::DeviceStateType::kProhibited:
......
...@@ -105,8 +105,6 @@ TEST_F(NetworkHealthTest, NetworkStateDisabled) { ...@@ -105,8 +105,6 @@ TEST_F(NetworkHealthTest, NetworkStateDisabled) {
ValidateState(network_health::mojom::NetworkState::kDisabled); ValidateState(network_health::mojom::NetworkState::kDisabled);
} }
// TODO(crbug/1081488): implement test for kEnabling state.
TEST_F(NetworkHealthTest, NetworkStateProhibited) { TEST_F(NetworkHealthTest, NetworkStateProhibited) {
cros_network_config_test_helper_.network_state_helper() cros_network_config_test_helper_.network_state_helper()
.manager_test() .manager_test()
......
...@@ -439,7 +439,8 @@ Polymer({ ...@@ -439,7 +439,8 @@ Polymer({
enableToggleIsEnabled_(deviceState) { enableToggleIsEnabled_(deviceState) {
return !!deviceState && return !!deviceState &&
deviceState.deviceState != deviceState.deviceState !=
chromeos.networkConfig.mojom.DeviceStateType.kProhibited; chromeos.networkConfig.mojom.DeviceStateType.kProhibited &&
!OncMojo.deviceStateIsIntermediate(deviceState.deviceState);
}, },
/** /**
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
[[getTitleText_(activeNetworkState)]] [[getTitleText_(activeNetworkState)]]
</div> </div>
<div id="networkState"> <div id="networkState">
[[getNetworkStateText_(activeNetworkState, deviceState)]] [[getNetworkStateText_(activeNetworkState, deviceState.*)]]
</div> </div>
</div> </div>
</div> </div>
......
...@@ -77,18 +77,17 @@ Polymer({ ...@@ -77,18 +77,17 @@ Polymer({
}, },
/** /**
* @param {!OncMojo.NetworkStateProperties} activeNetworkState
* @param {!OncMojo.DeviceStateProperties|undefined} deviceState
* @return {string} * @return {string}
* @private * @private
*/ */
getNetworkStateText_(activeNetworkState, deviceState) { getNetworkStateText_() {
const stateText = const stateText =
this.getConnectionStateText_(activeNetworkState, deviceState); this.getConnectionStateText_(this.activeNetworkState, this.deviceState);
if (stateText) { if (stateText) {
return stateText; return stateText;
} }
// No network state, use device state. // No network state, use device state.
const deviceState = this.deviceState;
if (deviceState) { if (deviceState) {
// Type specific scanning or initialization states. // Type specific scanning or initialization states.
if (deviceState.type == mojom.NetworkType.kCellular) { if (deviceState.type == mojom.NetworkType.kCellular) {
...@@ -98,6 +97,9 @@ Polymer({ ...@@ -98,6 +97,9 @@ Polymer({
if (deviceState.deviceState == mojom.DeviceStateType.kUninitialized) { if (deviceState.deviceState == mojom.DeviceStateType.kUninitialized) {
return this.i18n('internetDeviceInitializing'); return this.i18n('internetDeviceInitializing');
} }
if (deviceState.deviceState == mojom.DeviceStateType.kDisabling) {
return this.i18n('internetDeviceDisabling');
}
} else if (deviceState.type == mojom.NetworkType.kTether) { } else if (deviceState.type == mojom.NetworkType.kTether) {
if (deviceState.deviceState == mojom.DeviceStateType.kUninitialized) { if (deviceState.deviceState == mojom.DeviceStateType.kUninitialized) {
return this.i18n('tetherEnableBluetooth'); return this.i18n('tetherEnableBluetooth');
...@@ -119,7 +121,7 @@ Polymer({ ...@@ -119,7 +121,7 @@ Polymer({
}, },
/** /**
* @param {!OncMojo.NetworkStateProperties} networkState * @param {!OncMojo.NetworkStateProperties|undefined} networkState
* @param {!OncMojo.DeviceStateProperties|undefined} deviceState * @param {!OncMojo.DeviceStateProperties|undefined} deviceState
* @return {string} * @return {string}
* @private * @private
...@@ -236,7 +238,7 @@ Polymer({ ...@@ -236,7 +238,7 @@ Polymer({
enableToggleIsEnabled_(deviceState) { enableToggleIsEnabled_(deviceState) {
return this.enableToggleIsVisible_(deviceState) && return this.enableToggleIsVisible_(deviceState) &&
deviceState.deviceState != mojom.DeviceStateType.kProhibited && deviceState.deviceState != mojom.DeviceStateType.kProhibited &&
deviceState.deviceState != mojom.DeviceStateType.kUninitialized; !OncMojo.deviceStateIsIntermediate(deviceState.deviceState);
}, },
/** /**
...@@ -359,6 +361,10 @@ Polymer({ ...@@ -359,6 +361,10 @@ Polymer({
this.fire( this.fire(
'device-enabled-toggled', 'device-enabled-toggled',
{enabled: !deviceIsEnabled, type: this.deviceState.type}); {enabled: !deviceIsEnabled, type: this.deviceState.type});
// Set the device state to enabling or disabling until updated.
this.deviceState.deviceState = deviceIsEnabled ?
mojom.DeviceStateType.kDisabling :
mojom.DeviceStateType.kEnabling;
}, },
/** /**
......
...@@ -485,6 +485,7 @@ void InternetSection::AddLoadTimeData(content::WebUIDataSource* html_source) { ...@@ -485,6 +485,7 @@ void InternetSection::AddLoadTimeData(content::WebUIDataSource* html_source) {
{"internetConfigName", IDS_SETTINGS_INTERNET_CONFIG_NAME}, {"internetConfigName", IDS_SETTINGS_INTERNET_CONFIG_NAME},
{"internetDetailPageTitle", IDS_SETTINGS_INTERNET_DETAIL}, {"internetDetailPageTitle", IDS_SETTINGS_INTERNET_DETAIL},
{"internetDeviceEnabling", IDS_SETTINGS_INTERNET_DEVICE_ENABLING}, {"internetDeviceEnabling", IDS_SETTINGS_INTERNET_DEVICE_ENABLING},
{"internetDeviceDisabling", IDS_SETTINGS_INTERNET_DEVICE_DISABLING},
{"internetDeviceInitializing", IDS_SETTINGS_INTERNET_DEVICE_INITIALIZING}, {"internetDeviceInitializing", IDS_SETTINGS_INTERNET_DEVICE_INITIALIZING},
{"internetJoinType", IDS_SETTINGS_INTERNET_JOIN_TYPE}, {"internetJoinType", IDS_SETTINGS_INTERNET_JOIN_TYPE},
{"internetKnownNetworksPageTitle", IDS_SETTINGS_INTERNET_KNOWN_NETWORKS}, {"internetKnownNetworksPageTitle", IDS_SETTINGS_INTERNET_KNOWN_NETWORKS},
......
...@@ -117,14 +117,14 @@ suite('InternetPage', function() { ...@@ -117,14 +117,14 @@ suite('InternetPage', function() {
assertFalse(toggle.disabled); assertFalse(toggle.disabled);
assertFalse(toggle.checked); assertFalse(toggle.checked);
// Tap the enable toggle button and ensure the state becomes enabled. // Tap the enable toggle button and ensure the state becomes enabling.
toggle.click(); toggle.click();
return flushAsync().then(() => { return flushAsync().then(() => {
assertTrue(toggle.checked); assertTrue(toggle.checked);
const wifiDevice = const wifiDevice =
mojoApi_.getDeviceStateForTest(mojom.NetworkType.kWiFi); mojoApi_.getDeviceStateForTest(mojom.NetworkType.kWiFi);
assertTrue(!!wifiDevice); assertTrue(!!wifiDevice);
assertEquals(mojom.DeviceStateType.kEnabled, wifiDevice.deviceState); assertEquals(mojom.DeviceStateType.kEnabling, wifiDevice.deviceState);
}); });
}); });
}); });
......
...@@ -207,8 +207,7 @@ mojom::DeviceStateType GetMojoDeviceStateType( ...@@ -207,8 +207,7 @@ mojom::DeviceStateType GetMojoDeviceStateType(
case NetworkStateHandler::TECHNOLOGY_AVAILABLE: case NetworkStateHandler::TECHNOLOGY_AVAILABLE:
return mojom::DeviceStateType::kDisabled; return mojom::DeviceStateType::kDisabled;
case NetworkStateHandler::TECHNOLOGY_DISABLING: case NetworkStateHandler::TECHNOLOGY_DISABLING:
// TODO(jonmann): Add a DeviceStateType::kDisabling. return mojom::DeviceStateType::kDisabling;
return mojom::DeviceStateType::kDisabled;
case NetworkStateHandler::TECHNOLOGY_ENABLING: case NetworkStateHandler::TECHNOLOGY_ENABLING:
return mojom::DeviceStateType::kEnabling; return mojom::DeviceStateType::kEnabling;
case NetworkStateHandler::TECHNOLOGY_ENABLED: case NetworkStateHandler::TECHNOLOGY_ENABLED:
......
...@@ -19,6 +19,7 @@ enum ConnectionStateType { ...@@ -19,6 +19,7 @@ enum ConnectionStateType {
enum DeviceStateType { enum DeviceStateType {
kUninitialized, kUninitialized,
kDisabled, kDisabled,
kDisabling,
kEnabling, kEnabling,
kEnabled, kEnabled,
kProhibited, kProhibited,
......
...@@ -147,6 +147,8 @@ class OncMojo { ...@@ -147,6 +147,8 @@ class OncMojo {
return 'Uninitialized'; return 'Uninitialized';
case DeviceStateType.kDisabled: case DeviceStateType.kDisabled:
return 'Disabled'; return 'Disabled';
case DeviceStateType.kDisabling:
return 'Disabling';
case DeviceStateType.kEnabling: case DeviceStateType.kEnabling:
return 'Enabling'; return 'Enabling';
case DeviceStateType.kEnabled: case DeviceStateType.kEnabled:
...@@ -161,27 +163,24 @@ class OncMojo { ...@@ -161,27 +163,24 @@ class OncMojo {
} }
/** /**
* @param {string} value * @param {!chromeos.networkConfig.mojom.DeviceStateType} value
* @return {!chromeos.networkConfig.mojom.DeviceStateType} * @return {boolean}
*/ */
static getDeviceStateTypeFromString(value) { static deviceStateIsIntermediate(value) {
const DeviceStateType = chromeos.networkConfig.mojom.DeviceStateType; const DeviceStateType = chromeos.networkConfig.mojom.DeviceStateType;
switch (value) { switch (value) {
case 'Uninitialized': case DeviceStateType.kUninitialized:
return DeviceStateType.kUninitialized; case DeviceStateType.kDisabling:
case 'Disabled': case DeviceStateType.kEnabling:
return DeviceStateType.kDisabled; case DeviceStateType.kUnavailable:
case 'Enabling': return true;
return DeviceStateType.kEnabling; case DeviceStateType.kDisabled:
case 'Enabled': case DeviceStateType.kEnabled:
return DeviceStateType.kEnabled; case DeviceStateType.kProhibited:
case 'Prohibited': return false;
return DeviceStateType.kProhibited;
case 'Unavailable':
return DeviceStateType.kUnavailable;
} }
assertNotReached('Unexpected value: ' + value); assertNotReached('Unexpected enum value: ' + OncMojo.getEnumString(value));
return DeviceStateType.kUnavailable; return false;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment