Commit 03f08667 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Network config: Add Metered property to ONC

Shill's Service.Metered property can be modified by the user, or
potentially enforced by policy. This CL adds the property to the ONC
spec and the mojo API, and provides translation to and from Shill.

Bug: 1078427
Change-Id: Ic745d480a3f6898d14aa39130124f040c6d23423
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212986Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarAzeem Arshad <azeemarshad@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771953}
parent c533ed47
......@@ -52,6 +52,7 @@ chrome.test.runTests([
},
ConnectionState: 'NotConnected',
GUID: 'stub_cellular1_guid',
Metered: true,
Name: 'cellular1',
Source: 'User',
Type: 'Cellular',
......
......@@ -591,6 +591,7 @@ var availableTests = [
},
ConnectionState: ConnectionStateType.NOT_CONNECTED,
GUID: kCellularGuid,
Metered: true,
Name: 'cellular1',
Source: 'User',
Type: NetworkType.CELLULAR,
......
......@@ -327,6 +327,7 @@ const OncFieldSignature network_configuration_fields[] = {
{::onc::network_config::kEthernet, &kEthernetSignature},
{::onc::network_config::kGUID, &kStringSignature},
{::onc::network_config::kIPAddressConfigType, &kStringSignature},
{::onc::network_config::kMetered, &kBoolSignature},
{::onc::network_config::kName, &kStringSignature},
{::onc::network_config::kNameServersConfigType, &kStringSignature},
{::onc::network_config::kPriority, &kIntegerSignature},
......
......@@ -213,6 +213,7 @@ const FieldTranslationEntry cellular_fields[] = {
const FieldTranslationEntry network_fields[] = {
{::onc::network_config::kGUID, shill::kGuidProperty},
{::onc::network_config::kConnectable, shill::kConnectableProperty},
{::onc::network_config::kMetered, shill::kMeteredProperty},
{::onc::network_config::kPriority, shill::kPriorityProperty},
// Shill doesn't allow setting the name for non-VPN networks.
......
......@@ -1207,6 +1207,8 @@ mojom::ManagedPropertiesPtr ManagedPropertiesToMojo(
// Managed properties
result->ip_address_config_type =
GetManagedString(properties, ::onc::network_config::kIPAddressConfigType);
result->metered =
GetManagedBoolean(properties, ::onc::network_config::kMetered);
result->name = GetManagedString(properties, ::onc::network_config::kName);
result->name_servers_config_type = GetManagedString(
properties, ::onc::network_config::kNameServersConfigType);
......@@ -1598,9 +1600,11 @@ std::unique_ptr<base::DictionaryValue> GetOncFromConfigProperties(
onc->SetStringKey(::onc::network_config::kIPAddressConfigType,
*properties->ip_address_config_type);
}
if (properties->metered) {
onc->SetBoolKey(::onc::network_config::kMetered,
properties->metered->value);
}
SetString(::onc::network_config::kName, properties->name, onc.get());
SetString(::onc::network_config::kNameServersConfigType,
properties->name_servers_config_type, onc.get());
......
......@@ -571,6 +571,7 @@ struct ManagedProperties {
string guid;
ManagedString? ip_address_config_type;
array<IPConfigProperties>? ip_configs;
ManagedBoolean? metered;
ManagedString? name;
ManagedString? name_servers_config_type;
ManagedInt32? priority;
......@@ -596,6 +597,11 @@ struct AutoConnectConfig {
bool value;
};
// Wrapper to allow optional metered configuration.
struct MeteredConfig {
bool value;
};
// Wrapper to allow optional priority configuration.
struct PriorityConfig {
int32 value;
......@@ -722,6 +728,7 @@ struct ConfigProperties {
// preserve the existing guid.
string? guid;
string? ip_address_config_type;
MeteredConfig? metered;
// Name is only required for new configurations.
string? name;
string? name_servers_config_type;
......
......@@ -222,8 +222,14 @@ Field **NetworkConfigurations** is an array of
* *DHCP*
* *Static*
* Determines whether the IP Address configuration is statically configured,
see **StaticIPConfig**, or automatically configured
using DHCP.
see **StaticIPConfig**, or automatically configured using DHCP.
* **Metered**
* (optional, defaults to "false") - **boolean**
* Whether the network should be considered metered. This may affect auto
update frequency, and may be used as a hint for apps to conserve data.
When not specified, the system will set this to the detected value.
See also **WiFi.TetheringState**.
* **NameServersConfigType**
* (optional if **Remove** is *false*, otherwise ignored. Defaults to *DHCP*
......@@ -232,8 +238,7 @@ Field **NetworkConfigurations** is an array of
* *DHCP*
* *Static*
* Determines whether the NameServers configuration is statically configured,
see **StaticIPConfig**, or automatically configured
using DHCP.
see **StaticIPConfig**, or automatically configured using DHCP.
* **IPConfigs**
* (optional for connected networks, read-only) -
......@@ -520,8 +525,7 @@ field **WiFi** must be set to an object of type [WiFi](#WiFi-type).
* (optional, read-only, defaults to "NotDetected") - **string**
* The tethering state of the WiFi connection. If the connection is
tethered the value is "Confirmed". If the connection is suspected to be
tethered the value is "Suspected". In all other cases it's
"NotDetected".
tethered the value is "Suspected". In all other cases it's "NotDetected".
---
* At least one of the fields **HexSSID** or **SSID** must be present.
......
......@@ -46,6 +46,7 @@ const char kIPConfigs[] = "IPConfigs";
const char kIPConfigTypeDHCP[] = "DHCP";
const char kIPConfigTypeStatic[] = "Static";
const char kMacAddress[] = "MacAddress";
const char kMetered[] = "Metered";
const char kNameServersConfigType[] = "NameServersConfigType";
const char kName[] = "Name";
const char kPriority[] = "Priority";
......
......@@ -68,6 +68,7 @@ ONC_EXPORT extern const char kIPConfigTypeStatic[];
ONC_EXPORT extern const char kSavedIPConfig[];
ONC_EXPORT extern const char kStaticIPConfig[];
ONC_EXPORT extern const char kMacAddress[];
ONC_EXPORT extern const char kMetered[];
ONC_EXPORT extern const char kNameServersConfigType[];
ONC_EXPORT extern const char kName[];
ONC_EXPORT extern const char kPriority[];
......
......@@ -1099,6 +1099,7 @@ TEST_F(NetworkingPrivateApiTest, GetCellularProperties) {
.Build())
.Set("ConnectionState", "Connected")
.Set("GUID", "cellular_guid")
.Set("Metered", true)
.Set("Name", "cellular")
.Set("Source", "User")
.Set("Type", "Cellular")
......@@ -1158,6 +1159,7 @@ TEST_F(NetworkingPrivateApiTest, GetCellularPropertiesFromWebUi) {
.Build())
.Set("ConnectionState", "Connected")
.Set("GUID", "cellular_guid")
.Set("Metered", true)
.Set("Name", "cellular")
.Set("Source", "User")
.Set("Type", "Cellular")
......
......@@ -706,6 +706,8 @@ namespace networking.onc {
IPConfigProperties[]? IPConfigs;
// The network's MAC address.
DOMString? MacAddress;
// Whether the network is metered.
boolean? Metered;
// A user friendly network name.
DOMString? Name;
// The IP configuration type for the name servers used by the network.
......@@ -762,6 +764,8 @@ namespace networking.onc {
IPConfigProperties[]? IPConfigs;
// See $(ref:NetworkProperties.MacAddress).
DOMString? MacAddress;
// See $(ref:NetworkProperties.Metered).
ManagedBoolean? Metered;
// See $(ref:NetworkProperties.Name).
ManagedDOMString? Name;
// See $(ref:NetworkProperties.NameServersConfigType).
......
......@@ -711,6 +711,7 @@ namespace networkingPrivate {
IPConfigType? IPAddressConfigType;
IPConfigProperties[]? IPConfigs;
DOMString? MacAddress;
boolean? Metered;
DOMString? Name;
IPConfigType? NameServersConfigType;
long? Priority;
......@@ -739,6 +740,7 @@ namespace networkingPrivate {
ManagedIPConfigType? IPAddressConfigType;
IPConfigProperties[]? IPConfigs;
DOMString? MacAddress;
ManagedBoolean? Metered;
ManagedDOMString? Name;
ManagedIPConfigType? NameServersConfigType;
ManagedLong? Priority;
......
......@@ -252,6 +252,7 @@ chrome.networkingPrivate.ManagedIssuerSubjectPattern;
* @typedef {{
* EnrollmentURI: (!Array<string>|undefined),
* Issuer: (!chrome.networkingPrivate.IssuerSubjectPattern|undefined),
* IssuerCAPEMs: (!Array<string>|undefined),
* IssuerCARef: (!Array<string>|undefined),
* Subject: (!chrome.networkingPrivate.IssuerSubjectPattern|undefined)
* }}
......@@ -862,6 +863,7 @@ chrome.networkingPrivate.NetworkConfigProperties;
* IPAddressConfigType: (!chrome.networkingPrivate.IPConfigType|undefined),
* IPConfigs: (!Array<!chrome.networkingPrivate.IPConfigProperties>|undefined),
* MacAddress: (string|undefined),
* Metered: (boolean|undefined),
* Name: (string|undefined),
* NameServersConfigType: (!chrome.networkingPrivate.IPConfigType|undefined),
* Priority: (number|undefined),
......@@ -889,6 +891,7 @@ chrome.networkingPrivate.NetworkProperties;
* IPAddressConfigType: (!chrome.networkingPrivate.ManagedIPConfigType|undefined),
* IPConfigs: (!Array<!chrome.networkingPrivate.IPConfigProperties>|undefined),
* MacAddress: (string|undefined),
* Metered: (!chrome.networkingPrivate.ManagedBoolean|undefined),
* Name: (!chrome.networkingPrivate.ManagedDOMString|undefined),
* NameServersConfigType: (!chrome.networkingPrivate.ManagedIPConfigType|undefined),
* Priority: (!chrome.networkingPrivate.ManagedLong|undefined),
......
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