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.
<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.
</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.">
VPN disconnected
</message>
......
......@@ -165,10 +165,15 @@ int MobileSectionHeaderView::UpdateToggleAndGetStatusMessage(
SetToggleVisibility(false);
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;
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 &&
!cellular_device->sim_lock_status->lock_type.empty()) {
......
......@@ -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.">
Enabling
</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.">
Initializing
</message>
......
......@@ -13,14 +13,12 @@ import "chromeos/services/network_config/public/mojom/network_types.mojom";
enum NetworkState {
// The network type is available but not yet initialized.
kUninitialized,
// The network type is available but disabled.
// The network type is available but disabled or disabling.
kDisabled,
// The network type is available and enabling.
kEnabling,
// The network type is prohibited by policy.
kProhibited,
// The network type is available and enabled, but no network connection has
// been established.
// The network type is available and enabled or enabling, but no network
// connection has been established.
kNotConnected,
// The network type is available and enabled, and a network connection is
// in progress.
......
......@@ -22,9 +22,11 @@ constexpr mojom::NetworkState DeviceStateToNetworkState(
case network_config::mojom::DeviceStateType::kUninitialized:
return mojom::NetworkState::kUninitialized;
case network_config::mojom::DeviceStateType::kDisabled:
return mojom::NetworkState::kDisabled;
case network_config::mojom::DeviceStateType::kDisabling:
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:
return mojom::NetworkState::kNotConnected;
case network_config::mojom::DeviceStateType::kProhibited:
......
......@@ -105,8 +105,6 @@ TEST_F(NetworkHealthTest, NetworkStateDisabled) {
ValidateState(network_health::mojom::NetworkState::kDisabled);
}
// TODO(crbug/1081488): implement test for kEnabling state.
TEST_F(NetworkHealthTest, NetworkStateProhibited) {
cros_network_config_test_helper_.network_state_helper()
.manager_test()
......
......@@ -439,7 +439,8 @@ Polymer({
enableToggleIsEnabled_(deviceState) {
return !!deviceState &&
deviceState.deviceState !=
chromeos.networkConfig.mojom.DeviceStateType.kProhibited;
chromeos.networkConfig.mojom.DeviceStateType.kProhibited &&
!OncMojo.deviceStateIsIntermediate(deviceState.deviceState);
},
/**
......
......@@ -52,7 +52,7 @@
[[getTitleText_(activeNetworkState)]]
</div>
<div id="networkState">
[[getNetworkStateText_(activeNetworkState, deviceState)]]
[[getNetworkStateText_(activeNetworkState, deviceState.*)]]
</div>
</div>
</div>
......
......@@ -77,18 +77,17 @@ Polymer({
},
/**
* @param {!OncMojo.NetworkStateProperties} activeNetworkState
* @param {!OncMojo.DeviceStateProperties|undefined} deviceState
* @return {string}
* @private
*/
getNetworkStateText_(activeNetworkState, deviceState) {
getNetworkStateText_() {
const stateText =
this.getConnectionStateText_(activeNetworkState, deviceState);
this.getConnectionStateText_(this.activeNetworkState, this.deviceState);
if (stateText) {
return stateText;
}
// No network state, use device state.
const deviceState = this.deviceState;
if (deviceState) {
// Type specific scanning or initialization states.
if (deviceState.type == mojom.NetworkType.kCellular) {
......@@ -98,6 +97,9 @@ Polymer({
if (deviceState.deviceState == mojom.DeviceStateType.kUninitialized) {
return this.i18n('internetDeviceInitializing');
}
if (deviceState.deviceState == mojom.DeviceStateType.kDisabling) {
return this.i18n('internetDeviceDisabling');
}
} else if (deviceState.type == mojom.NetworkType.kTether) {
if (deviceState.deviceState == mojom.DeviceStateType.kUninitialized) {
return this.i18n('tetherEnableBluetooth');
......@@ -119,7 +121,7 @@ Polymer({
},
/**
* @param {!OncMojo.NetworkStateProperties} networkState
* @param {!OncMojo.NetworkStateProperties|undefined} networkState
* @param {!OncMojo.DeviceStateProperties|undefined} deviceState
* @return {string}
* @private
......@@ -236,7 +238,7 @@ Polymer({
enableToggleIsEnabled_(deviceState) {
return this.enableToggleIsVisible_(deviceState) &&
deviceState.deviceState != mojom.DeviceStateType.kProhibited &&
deviceState.deviceState != mojom.DeviceStateType.kUninitialized;
!OncMojo.deviceStateIsIntermediate(deviceState.deviceState);
},
/**
......@@ -359,6 +361,10 @@ Polymer({
this.fire(
'device-enabled-toggled',
{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) {
{"internetConfigName", IDS_SETTINGS_INTERNET_CONFIG_NAME},
{"internetDetailPageTitle", IDS_SETTINGS_INTERNET_DETAIL},
{"internetDeviceEnabling", IDS_SETTINGS_INTERNET_DEVICE_ENABLING},
{"internetDeviceDisabling", IDS_SETTINGS_INTERNET_DEVICE_DISABLING},
{"internetDeviceInitializing", IDS_SETTINGS_INTERNET_DEVICE_INITIALIZING},
{"internetJoinType", IDS_SETTINGS_INTERNET_JOIN_TYPE},
{"internetKnownNetworksPageTitle", IDS_SETTINGS_INTERNET_KNOWN_NETWORKS},
......
......@@ -117,14 +117,14 @@ suite('InternetPage', function() {
assertFalse(toggle.disabled);
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();
return flushAsync().then(() => {
assertTrue(toggle.checked);
const wifiDevice =
mojoApi_.getDeviceStateForTest(mojom.NetworkType.kWiFi);
assertTrue(!!wifiDevice);
assertEquals(mojom.DeviceStateType.kEnabled, wifiDevice.deviceState);
assertEquals(mojom.DeviceStateType.kEnabling, wifiDevice.deviceState);
});
});
});
......
......@@ -207,8 +207,7 @@ mojom::DeviceStateType GetMojoDeviceStateType(
case NetworkStateHandler::TECHNOLOGY_AVAILABLE:
return mojom::DeviceStateType::kDisabled;
case NetworkStateHandler::TECHNOLOGY_DISABLING:
// TODO(jonmann): Add a DeviceStateType::kDisabling.
return mojom::DeviceStateType::kDisabled;
return mojom::DeviceStateType::kDisabling;
case NetworkStateHandler::TECHNOLOGY_ENABLING:
return mojom::DeviceStateType::kEnabling;
case NetworkStateHandler::TECHNOLOGY_ENABLED:
......
......@@ -19,6 +19,7 @@ enum ConnectionStateType {
enum DeviceStateType {
kUninitialized,
kDisabled,
kDisabling,
kEnabling,
kEnabled,
kProhibited,
......
......@@ -147,6 +147,8 @@ class OncMojo {
return 'Uninitialized';
case DeviceStateType.kDisabled:
return 'Disabled';
case DeviceStateType.kDisabling:
return 'Disabling';
case DeviceStateType.kEnabling:
return 'Enabling';
case DeviceStateType.kEnabled:
......@@ -161,27 +163,24 @@ class OncMojo {
}
/**
* @param {string} value
* @return {!chromeos.networkConfig.mojom.DeviceStateType}
* @param {!chromeos.networkConfig.mojom.DeviceStateType} value
* @return {boolean}
*/
static getDeviceStateTypeFromString(value) {
static deviceStateIsIntermediate(value) {
const DeviceStateType = chromeos.networkConfig.mojom.DeviceStateType;
switch (value) {
case 'Uninitialized':
return DeviceStateType.kUninitialized;
case 'Disabled':
return DeviceStateType.kDisabled;
case 'Enabling':
return DeviceStateType.kEnabling;
case 'Enabled':
return DeviceStateType.kEnabled;
case 'Prohibited':
return DeviceStateType.kProhibited;
case 'Unavailable':
return DeviceStateType.kUnavailable;
case DeviceStateType.kUninitialized:
case DeviceStateType.kDisabling:
case DeviceStateType.kEnabling:
case DeviceStateType.kUnavailable:
return true;
case DeviceStateType.kDisabled:
case DeviceStateType.kEnabled:
case DeviceStateType.kProhibited:
return false;
}
assertNotReached('Unexpected value: ' + value);
return DeviceStateType.kUnavailable;
assertNotReached('Unexpected enum value: ' + OncMojo.getEnumString(value));
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