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