Skip to content

Commit

Permalink
Implement hidden network toggle in settings.
Browse files Browse the repository at this point in the history
This allows users to control whether an individual Wi-Fi
network is marked as "hidden".

Bug: 1175894
Change-Id: I3600c4a5b1b34d4f5fbf6413e44b5fd6616f9f48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2785126
Reviewed-by: Emily Stark <estark@chromium.org>
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Jon Mann <jonmann@chromium.org>
Cr-Commit-Position: refs/heads/master@{#867892}
  • Loading branch information
Jon Mann authored and Chromium LUCI CQ committed Mar 31, 2021
1 parent 87622e4 commit 700e1ea
Show file tree
Hide file tree
Showing 19 changed files with 323 additions and 23 deletions.
6 changes: 6 additions & 0 deletions chrome/app/os_settings_search_tag_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
<message name="IDS_OS_SETTINGS_TAG_AUTO_CONNECT_NETWORK_ALT1" desc="Text for search result item which, when clicked, navigates the user to settings to toggle whether the device auto-connects to a network. Alternate phrase for: 'Automatically connect to network'">
Auto connect to network
</message>
<message name="IDS_OS_SETTINGS_TAG_HIDDEN_NETWORK" desc="Text for search result item which, when clicked, navigates the user to settings to toggle whether the device auto-connects to a network. Alternate phrase for: 'Auto connect to network'">
Hidden network
</message>
<message name="IDS_OS_SETTINGS_TAG_HIDDEN_NETWORK_ALT1" desc="Text for search result item which, when clicked, navigates the user to settings to toggle whether the device auto-connects to a network. Alternate phrase for: 'Automatically connect to network'">
Hidden SSID
</message>
<message name="IDS_OS_SETTINGS_TAG_CONFIGURE_IP_AUTOMATICALLY" desc="Text for search result item which, when clicked, navigates the user to network settings which allow the user to set whether the device's IP address is configured automatically. Alternate phrase for: 'Auto configure IP address', 'Configure network address'">
Configure IP address automatically
</message>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ed59b88c53b835b4f850d98005161c1fbe6b18a4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ed59b88c53b835b4f850d98005161c1fbe6b18a4
6 changes: 6 additions & 0 deletions chrome/app/os_settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -2262,6 +2262,12 @@ Press an assigned switch to remove assignment.
<message name="IDS_SETTINGS_INTERNET_NETWORK_AUTO_CONNECT" desc="Settings > Internet > Network details: Label for the checkbox determining whether to automatically connect to the network.">
Automatically connect to this network
</message>
<message name="IDS_SETTINGS_INTERNET_NETWORK_HIDDEN" desc="Settings > Internet > Network details: Label for the checkbox to set a wi-fi network as hidden.">
Hidden network
</message>
<message name="IDS_SETTINGS_INTERNET_NETWORK_HIDDEN_SUBLABEL" desc="Settings > Internet > Network details: Label for the checkbox to set a wi-fi network as hidden.">
Using a hidden network isn't recommended for security reasons.
</message>
<message name="IDS_SETTINGS_INTERNET_NETWORK_AUTO_CONNECT_CELLULAR" desc="Settings > Internet > Mobile Data details: Label for the checkbox determining whether to automatically connect to the cellular network.">
Automatically connect to cellular network
</message>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ed59b88c53b835b4f850d98005161c1fbe6b18a4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ed59b88c53b835b4f850d98005161c1fbe6b18a4
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@
</cr-toggle>
</div>
</template>
<!-- Hidden. -->
<template is="dom-if"
if="[[showHiddenNetwork_(managedProperties_, globalPolicy,
managedNetworkAvailable)]]">
<settings-toggle-button id="hiddenToggle" class="hr"
pref="{{hiddenPref_}}"
label="$i18n{networkHidden}"
sub-label="$i18n{networkHiddenSublabel}"
sub-label-icon="cr20:warning"
learn-more-url="$i18n{wifiHiddenNetworkLearnMoreUrl}"
deep-link-focus-id$="[[Setting.kWifiHidden]]">
</settings-toggle-button>
</template>
<!-- Autoconnect. -->
<template is="dom-if"
if="[[showAutoConnect_(managedProperties_, globalPolicy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ Polymer({
},
},

/**
* The network hidden state.
* @private {!chrome.settingsPrivate.PrefObject|undefined}
*/
hiddenPref_: {
type: Object,
observer: 'hiddenPrefChanged_',
value() {
return {
key: 'fakeHiddenPref',
type: chrome.settingsPrivate.PrefType.BOOLEAN,
value: false,
};
},
},

/**
* The always-on VPN state as a fake preference object.
* @private {!chrome.settingsPrivate.PrefObject|undefined}
Expand Down Expand Up @@ -199,6 +215,18 @@ Polymer({
}
},

/**
* Whether to show the Hidden toggle on configured wifi networks (flag).
* @private
*/
showHiddenToggle_: {
type: Boolean,
value() {
return loadTimeData.valueExists('showHiddenToggle') &&
loadTimeData.getBoolean('showHiddenToggle');
},
},

/** @private */
isUpdatedCellularUiEnabled_: {
type: Boolean,
Expand Down Expand Up @@ -232,6 +260,7 @@ Polymer({
chromeos.settings.mojom.Setting.kForgetWifiNetwork,
chromeos.settings.mojom.Setting.kWifiAutoConfigureIp,
chromeos.settings.mojom.Setting.kWifiDns,
chromeos.settings.mojom.Setting.kWifiHidden,
chromeos.settings.mojom.Setting.kWifiProxy,
chromeos.settings.mojom.Setting.kWifiAutoConnectToNetwork,
chromeos.settings.mojom.Setting.kCellularSimLock,
Expand All @@ -256,6 +285,7 @@ Polymer({
'updateAutoConnectPref_(globalPolicy)',
'autoConnectPrefChanged_(autoConnectPref_.*)',
'alwaysOnVpnChanged_(alwaysOnVpn_.*)',
'hiddenPrefChanged_(hiddenPref_.*)',
],

/** @private {boolean} */
Expand Down Expand Up @@ -552,6 +582,7 @@ Polymer({
return;
}
this.updateAutoConnectPref_();
this.updateHiddenPref_();

const metered = this.managedProperties_.metered;
if (metered && metered.activeValue !== this.meteredOverride_) {
Expand Down Expand Up @@ -666,6 +697,58 @@ Polymer({
this.setMojoNetworkProperties_(config);
},

/** @private */
hiddenPrefChanged_() {
if (!this.propertiesReceived_) {
return;
}
const config = this.getDefaultConfigProperties_();
config.typeConfig.wifi.hiddenSsid = this.hiddenPref_.value ?
chromeos.networkConfig.mojom.HiddenSsidMode.kEnabled :
chromeos.networkConfig.mojom.HiddenSsidMode.kDisabled;
this.setMojoNetworkProperties_(config);
},

/**
* @param {!chromeos.networkConfig.mojom.PolicySource} policySource
* @return {!chrome.settingsPrivate.Enforcement|undefined}
* @private
*/
getPolicyEnforcement_(policySource) {
switch (policySource) {
case chromeos.networkConfig.mojom.PolicySource.kUserPolicyEnforced:
case chromeos.networkConfig.mojom.PolicySource.kDevicePolicyEnforced:
return chrome.settingsPrivate.Enforcement.ENFORCED;

case chromeos.networkConfig.mojom.PolicySource.kUserPolicyRecommended:
case chromeos.networkConfig.mojom.PolicySource.kDevicePolicyRecommended:
return chrome.settingsPrivate.Enforcement.RECOMMENDED;

default:
return undefined;
}
},

/**
* @param {!chromeos.networkConfig.mojom.PolicySource} policySource
* @return {!chrome.settingsPrivate.ControlledBy|undefined}
* @private
*/
getPolicyController_(policySource) {
switch (policySource) {
case chromeos.networkConfig.mojom.PolicySource.kDevicePolicyEnforced:
case chromeos.networkConfig.mojom.PolicySource.kDevicePolicyRecommended:
return chrome.settingsPrivate.ControlledBy.DEVICE_POLICY;

case chromeos.networkConfig.mojom.PolicySource.kUserPolicyEnforced:
case chromeos.networkConfig.mojom.PolicySource.kUserPolicyRecommended:
return chrome.settingsPrivate.ControlledBy.USER_POLICY;

default:
return undefined;
}
},

/**
* Updates auto-connect pref value.
* @private
Expand All @@ -679,8 +762,6 @@ Polymer({
return;
}

const PolicySource = chromeos.networkConfig.mojom.PolicySource;

let enforcement;
let controlledBy;

Expand All @@ -689,27 +770,8 @@ Polymer({
enforcement = chrome.settingsPrivate.Enforcement.ENFORCED;
controlledBy = chrome.settingsPrivate.ControlledBy.DEVICE_POLICY;
} else {
switch (autoConnect.policySource) {
case PolicySource.kUserPolicyEnforced:
case PolicySource.kDevicePolicyEnforced:
enforcement = chrome.settingsPrivate.Enforcement.ENFORCED;
break;
case PolicySource.kUserPolicyRecommended:
case PolicySource.kDevicePolicyRecommended:
enforcement = chrome.settingsPrivate.Enforcement.RECOMMENDED;
break;
}

switch (autoConnect.policySource) {
case PolicySource.kDevicePolicyEnforced:
case PolicySource.kDevicePolicyRecommended:
controlledBy = chrome.settingsPrivate.ControlledBy.DEVICE_POLICY;
break;
case PolicySource.kUserPolicyEnforced:
case PolicySource.kUserPolicyRecommended:
controlledBy = chrome.settingsPrivate.ControlledBy.USER_POLICY;
break;
}
enforcement = this.getPolicyEnforcement_(autoConnect.policySource);
controlledBy = this.getPolicyController_(autoConnect.policySource);
}

if (this.autoConnectPref_ &&
Expand All @@ -732,6 +794,47 @@ Polymer({
this.autoConnectPref_ = newPrefValue;
},

/**
* Updates auto-connect pref value.
* @private
*/
updateHiddenPref_() {
if (!this.managedProperties_) {
return;
}

if (this.managedProperties_.type !==
chromeos.networkConfig.mojom.NetworkType.kWiFi) {
return;
}


const hidden = this.managedProperties_.typeProperties.wifi.hiddenSsid;
if (!hidden) {
return;
}

const enforcement = this.getPolicyEnforcement_(hidden.policySource);
const controlledBy = this.getPolicyController_(hidden.policySource);
if (this.hiddenPref_ && this.hiddenPref_.value === hidden.activeValue &&
enforcement === this.hiddenPref_.enforcement &&
controlledBy === this.hiddenPref_.controlledBy) {
return;
}

const newPrefValue = {
key: 'fakeHiddenPref',
value: hidden.activeValue,
type: chrome.settingsPrivate.PrefType.BOOLEAN,
};
if (enforcement) {
newPrefValue.enforcement = enforcement;
newPrefValue.controlledBy = controlledBy;
}

this.hiddenPref_ = newPrefValue;
},

/**
* @param {!CustomEvent<boolean>} e
* @private
Expand Down Expand Up @@ -1758,6 +1861,39 @@ Polymer({
managedProperties, globalPolicy, managedNetworkAvailable);
},

/**
* @param {!chromeos.networkConfig.mojom.ManagedProperties} managedProperties
* @param {!chromeos.networkConfig.mojom.GlobalPolicy} globalPolicy
* @param {boolean} managedNetworkAvailable
* @return {boolean} True if the Hidden checkbox should be shown.
* @private
*/
showHiddenNetwork_(managedProperties, globalPolicy, managedNetworkAvailable) {
if (!this.showHiddenToggle_) {
return false;
}

if (!managedProperties) {
return false;
}

if (managedProperties.type !==
chromeos.networkConfig.mojom.NetworkType.kWiFi) {
return false;
}

if (!this.isRemembered_(managedProperties)) {
return false;
}

if (this.isBlockedByPolicy_(
managedProperties, globalPolicy, managedNetworkAvailable)) {
return false;
}

return true;
},

/**
* @return {boolean}
* @private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<div class="flex" id="labelWrapper" hidden$="[[!label]]">
<div class="label" aria-hidden="true">[[label]]</div>
<div class="secondary label" id="sub-label">
<template is="dom-if" if="[[subLabelIcon]]">
<span id="sub-label-icon" aria-hidden="true">
<iron-icon slot="icon" icon="[[subLabelIcon]]">
</iron-icon>
</span>
</template>
<span id="sub-label-text" aria-hidden="true">
[[subLabel]]
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Polymer({
type: String,
reflectToAttribute: true,
},

subLabelIcon: {
type: String,
},
},

listeners: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum Setting {
kCellularAddNetwork = 26,
kCellularRemoveESimNetwork = 27,
kCellularRenameESimNetwork = 28,
kWifiHidden = 29,

// Bluetooth section.
kBluetoothOnOff = 100,
Expand Down

0 comments on commit 700e1ea

Please sign in to comment.