Commit f7b4872f authored by khorimoto's avatar khorimoto Committed by Commit bot

[CrOS Tether] Add HasConnectedToHost property for Tether networks.

This property is necessary because the networking stack must show a dialog to users the first time they connect to a given host device which alerts the user that tethering will use mobile data and battery.

This change adds the new property to the networkingPrivate IDL file and pipes it through from NetworkState. Currently, the value is hard-coded to "false", but this value will be propagated through the network stack from the Tether component in a follow-up CL.

BUG=672263
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2844363003
Cr-Commit-Position: refs/heads/master@{#467865}
parent 3b669c73
...@@ -92,6 +92,9 @@ var privateHelpers = { ...@@ -92,6 +92,9 @@ var privateHelpers = {
: properties.Name); : properties.Name);
assertEq(expectedBatteryPercentage, properties.Tether.BatteryPercentage); assertEq(expectedBatteryPercentage, properties.Tether.BatteryPercentage);
assertEq(expectedCarrier, properties.Tether.Carrier); assertEq(expectedCarrier, properties.Tether.Carrier);
// TODO(khorimoto): Add the expected value as a parameter once it can be set
// via the Tether component.
assertFalse(properties.Tether.HasConnectedToHost);
assertEq(expectedSignalStrength, properties.Tether.SignalStrength); assertEq(expectedSignalStrength, properties.Tether.SignalStrength);
} }
}; };
......
...@@ -366,6 +366,9 @@ TEST_F(NetworkConfigurationHandlerTest, GetProperties_TetherNetwork) { ...@@ -366,6 +366,9 @@ TEST_F(NetworkConfigurationHandlerTest, GetProperties_TetherNetwork) {
NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED); NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED);
std::string kTetherGuid = "TetherGuid"; std::string kTetherGuid = "TetherGuid";
// TODO(khorimoto): Pass a has_connected_to_host parameter to this function
// and verify that it is present in the JSON below. Currently, it is hard-
// coded to false.
network_state_handler_->AddTetherNetworkState( network_state_handler_->AddTetherNetworkState(
kTetherGuid, "TetherNetworkName", "TetherNetworkCarrier", kTetherGuid, "TetherNetworkName", "TetherNetworkCarrier",
100 /* battery_percentage */, 100 /* signal_strength */); 100 /* battery_percentage */, 100 /* signal_strength */);
...@@ -380,6 +383,7 @@ TEST_F(NetworkConfigurationHandlerTest, GetProperties_TetherNetwork) { ...@@ -380,6 +383,7 @@ TEST_F(NetworkConfigurationHandlerTest, GetProperties_TetherNetwork) {
"\"State\": \"\",\n " "\"State\": \"\",\n "
"\"Tether.BatteryPercentage\": 100,\n " "\"Tether.BatteryPercentage\": 100,\n "
"\"Tether.Carrier\": \"TetherNetworkCarrier\",\n " "\"Tether.Carrier\": \"TetherNetworkCarrier\",\n "
"\"Tether.HasConnectedToHost\": false,\n "
"\"Tether.SignalStrength\": 100,\n " "\"Tether.SignalStrength\": 100,\n "
"\"Type\": \"wifi-tether\"\n" "\"Type\": \"wifi-tether\"\n"
"}\n"; "}\n";
......
...@@ -267,6 +267,8 @@ void NetworkState::GetStateProperties(base::DictionaryValue* dictionary) const { ...@@ -267,6 +267,8 @@ void NetworkState::GetStateProperties(base::DictionaryValue* dictionary) const {
dictionary->SetIntegerWithoutPathExpansion(kTetherBatteryPercentage, dictionary->SetIntegerWithoutPathExpansion(kTetherBatteryPercentage,
battery_percentage()); battery_percentage());
dictionary->SetStringWithoutPathExpansion(kTetherCarrier, carrier()); dictionary->SetStringWithoutPathExpansion(kTetherCarrier, carrier());
dictionary->SetBooleanWithoutPathExpansion(kTetherHasConnectedToHost,
tether_has_connected_to_host());
dictionary->SetIntegerWithoutPathExpansion(kTetherSignalStrength, dictionary->SetIntegerWithoutPathExpansion(kTetherSignalStrength,
signal_strength()); signal_strength());
} }
......
...@@ -114,6 +114,12 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState { ...@@ -114,6 +114,12 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState {
} }
const std::string& carrier() const { return carrier_; } const std::string& carrier() const { return carrier_; }
void set_carrier(const std::string& carrier) { carrier_ = carrier; } void set_carrier(const std::string& carrier) { carrier_ = carrier; }
bool tether_has_connected_to_host() const {
return tether_has_connected_to_host_;
}
void set_tether_has_connected_to_host(bool tether_has_connected_to_host) {
tether_has_connected_to_host_ = tether_has_connected_to_host;
}
const std::string& tether_guid() const { return tether_guid_; } const std::string& tether_guid() const { return tether_guid_; }
void set_tether_guid(const std::string& guid) { tether_guid_ = guid; } void set_tether_guid(const std::string& guid) { tether_guid_ = guid; }
...@@ -229,6 +235,12 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState { ...@@ -229,6 +235,12 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState {
// Tether properties. // Tether properties.
std::string carrier_; std::string carrier_;
int battery_percentage_; int battery_percentage_;
// Whether the current device has already connected to the tether host device
// providing the hotspot corresponding to this NetworkState.
// Note: this means that the current device has already connected to the
// tether host, but it does not necessarily mean that the current device has
// connected to the Tether network corresponding to this NetworkState.
bool tether_has_connected_to_host_;
// TODO(pneubeck): Remove this once (Managed)NetworkConfigurationHandler // TODO(pneubeck): Remove this once (Managed)NetworkConfigurationHandler
// provides proxy configuration. crbug.com/241775 // provides proxy configuration. crbug.com/241775
......
...@@ -531,6 +531,9 @@ void NetworkStateHandler::AddTetherNetworkState(const std::string& guid, ...@@ -531,6 +531,9 @@ void NetworkStateHandler::AddTetherNetworkState(const std::string& guid,
tether_network_state->set_connectable(true); tether_network_state->set_connectable(true);
tether_network_state->set_carrier(carrier); tether_network_state->set_carrier(carrier);
tether_network_state->set_battery_percentage(battery_percentage); tether_network_state->set_battery_percentage(battery_percentage);
// TODO(khorimoto): Add this field as a parameter to this function and set it
// accordingly from the Tether component.
tether_network_state->set_tether_has_connected_to_host(false);
tether_network_state->set_signal_strength(signal_strength); tether_network_state->set_signal_strength(signal_strength);
tether_network_list_.push_back(std::move(tether_network_state)); tether_network_list_.push_back(std::move(tether_network_state));
......
...@@ -262,6 +262,7 @@ TEST_F(NetworkStateTest, TetherProperties) { ...@@ -262,6 +262,7 @@ TEST_F(NetworkStateTest, TetherProperties) {
network_state_.set_type(kTypeTether); network_state_.set_type(kTypeTether);
network_state_.set_carrier("Project Fi"); network_state_.set_carrier("Project Fi");
network_state_.set_battery_percentage(85); network_state_.set_battery_percentage(85);
network_state_.set_tether_has_connected_to_host(true);
network_state_.set_signal_strength(75); network_state_.set_signal_strength(75);
base::DictionaryValue dictionary; base::DictionaryValue dictionary;
...@@ -277,6 +278,11 @@ TEST_F(NetworkStateTest, TetherProperties) { ...@@ -277,6 +278,11 @@ TEST_F(NetworkStateTest, TetherProperties) {
kTetherBatteryPercentage, &battery_percentage)); kTetherBatteryPercentage, &battery_percentage));
EXPECT_EQ(85, battery_percentage); EXPECT_EQ(85, battery_percentage);
bool tether_has_connected_to_host;
EXPECT_TRUE(dictionary.GetBooleanWithoutPathExpansion(
kTetherHasConnectedToHost, &tether_has_connected_to_host));
EXPECT_TRUE(tether_has_connected_to_host);
std::string carrier; std::string carrier;
EXPECT_TRUE( EXPECT_TRUE(
dictionary.GetStringWithoutPathExpansion(kTetherCarrier, &carrier)); dictionary.GetStringWithoutPathExpansion(kTetherCarrier, &carrier));
......
...@@ -172,6 +172,7 @@ const OncFieldSignature tether_fields[] = {{NULL}}; ...@@ -172,6 +172,7 @@ const OncFieldSignature tether_fields[] = {{NULL}};
const OncFieldSignature tether_with_state_fields[] = { const OncFieldSignature tether_with_state_fields[] = {
{::onc::tether::kBatteryPercentage, &kIntegerSignature}, {::onc::tether::kBatteryPercentage, &kIntegerSignature},
{::onc::tether::kCarrier, &kStringSignature}, {::onc::tether::kCarrier, &kStringSignature},
{::onc::tether::kHasConnectedToHost, &kBoolSignature},
{::onc::tether::kSignalStrength, &kIntegerSignature}, {::onc::tether::kSignalStrength, &kIntegerSignature},
{NULL}}; {NULL}};
......
...@@ -114,6 +114,7 @@ const FieldTranslationEntry vpn_fields[] = { ...@@ -114,6 +114,7 @@ const FieldTranslationEntry vpn_fields[] = {
const FieldTranslationEntry tether_fields[] = { const FieldTranslationEntry tether_fields[] = {
{::onc::tether::kBatteryPercentage, kTetherBatteryPercentage}, {::onc::tether::kBatteryPercentage, kTetherBatteryPercentage},
{::onc::tether::kCarrier, kTetherCarrier}, {::onc::tether::kCarrier, kTetherCarrier},
{::onc::tether::kHasConnectedToHost, kTetherHasConnectedToHost},
{::onc::tether::kSignalStrength, kTetherSignalStrength}, {::onc::tether::kSignalStrength, kTetherSignalStrength},
{NULL}}; {NULL}};
......
...@@ -1008,19 +1008,19 @@ bool Validator::ValidateCertificate(base::DictionaryValue* result) { ...@@ -1008,19 +1008,19 @@ bool Validator::ValidateCertificate(base::DictionaryValue* result) {
bool Validator::ValidateTether(base::DictionaryValue* result) { bool Validator::ValidateTether(base::DictionaryValue* result) {
using namespace ::onc::tether; using namespace ::onc::tether;
int batteryPercentage; int battery_percentage;
if (!result->GetIntegerWithoutPathExpansion(kBatteryPercentage, if (!result->GetIntegerWithoutPathExpansion(kBatteryPercentage,
&batteryPercentage) || &battery_percentage) ||
batteryPercentage < 0 || batteryPercentage > 100) { battery_percentage < 0 || battery_percentage > 100) {
// Battery percentage must be present and within [0, 100]. // Battery percentage must be present and within [0, 100].
error_or_warning_found_ = true; error_or_warning_found_ = true;
return false; return false;
} }
int signalStrength; int signal_strength;
if (!result->GetIntegerWithoutPathExpansion(kSignalStrength, if (!result->GetIntegerWithoutPathExpansion(kSignalStrength,
&signalStrength) || &signal_strength) ||
signalStrength < 0 || signalStrength > 100) { signal_strength < 0 || signal_strength > 100) {
// Signal strength must be present and within [0, 100]. // Signal strength must be present and within [0, 100].
error_or_warning_found_ = true; error_or_warning_found_ = true;
return false; return false;
...@@ -1034,8 +1034,12 @@ bool Validator::ValidateTether(base::DictionaryValue* result) { ...@@ -1034,8 +1034,12 @@ bool Validator::ValidateTether(base::DictionaryValue* result) {
return false; return false;
} }
// No required fields. bool all_required_exist = RequireField(*result, kHasConnectedToHost);
return true; if (!all_required_exist) {
error_or_warning_found_ = true;
}
return !error_on_missing_field_ || all_required_exist;
} }
std::string Validator::MessageHeader() { std::string Validator::MessageHeader() {
......
...@@ -564,6 +564,10 @@ INSTANTIATE_TEST_CASE_P( ...@@ -564,6 +564,10 @@ INSTANTIATE_TEST_CASE_P(
&kNetworkWithStateSignature, &kNetworkWithStateSignature,
true), true),
ExpectBothNotValid("", "")), ExpectBothNotValid("", "")),
std::make_pair(OncParams("tether-missing-has-connected-to-host",
&kNetworkWithStateSignature,
true),
ExpectBothNotValid("", "")),
std::make_pair(OncParams("tether-missing-signal-strength", std::make_pair(OncParams("tether-missing-signal-strength",
&kNetworkWithStateSignature, &kNetworkWithStateSignature,
true), true),
......
...@@ -9,6 +9,7 @@ namespace chromeos { ...@@ -9,6 +9,7 @@ namespace chromeos {
const char kTypeTether[] = "wifi-tether"; const char kTypeTether[] = "wifi-tether";
const char kTetherBatteryPercentage[] = "Tether.BatteryPercentage"; const char kTetherBatteryPercentage[] = "Tether.BatteryPercentage";
const char kTetherCarrier[] = "Tether.Carrier"; const char kTetherCarrier[] = "Tether.Carrier";
const char kTetherHasConnectedToHost[] = "Tether.HasConnectedToHost";
const char kTetherSignalStrength[] = "Tether.SignalStrength"; const char kTetherSignalStrength[] = "Tether.SignalStrength";
const char kTetherDevicePath[] = "tether-device-path"; const char kTetherDevicePath[] = "tether-device-path";
const char kTetherDeviceName[] = "tether-name"; const char kTetherDeviceName[] = "tether-name";
......
...@@ -20,6 +20,7 @@ CHROMEOS_EXPORT extern const char kTypeTether[]; ...@@ -20,6 +20,7 @@ CHROMEOS_EXPORT extern const char kTypeTether[];
// Properties associated with tether networks. // Properties associated with tether networks.
CHROMEOS_EXPORT extern const char kTetherBatteryPercentage[]; CHROMEOS_EXPORT extern const char kTetherBatteryPercentage[];
CHROMEOS_EXPORT extern const char kTetherCarrier[]; CHROMEOS_EXPORT extern const char kTetherCarrier[];
CHROMEOS_EXPORT extern const char kTetherHasConnectedToHost[];
CHROMEOS_EXPORT extern const char kTetherSignalStrength[]; CHROMEOS_EXPORT extern const char kTetherSignalStrength[];
// The device path used for the tether DeviceState. // The device path used for the tether DeviceState.
......
...@@ -383,6 +383,7 @@ ...@@ -383,6 +383,7 @@
"Type": "Tether", "Type": "Tether",
"Tether": { "Tether": {
"Carrier": "Project Fi", "Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": 75 "SignalStrength": 75
} }
}, },
...@@ -393,6 +394,7 @@ ...@@ -393,6 +394,7 @@
"Tether": { "Tether": {
"BatteryPercentage": -1, "BatteryPercentage": -1,
"Carrier": "Project Fi", "Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": 75 "SignalStrength": 75
} }
}, },
...@@ -403,6 +405,7 @@ ...@@ -403,6 +405,7 @@
"Tether": { "Tether": {
"BatteryPercentage": 101, "BatteryPercentage": 101,
"Carrier": "Project Fi", "Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": 75 "SignalStrength": 75
} }
}, },
...@@ -412,16 +415,28 @@ ...@@ -412,16 +415,28 @@
"Type": "Tether", "Type": "Tether",
"Tether": { "Tether": {
"BatteryPercentage": 85, "BatteryPercentage": 85,
"HasConnectedToHost": true,
"SignalStrength": 75 "SignalStrength": 75
} }
}, },
"tether-missing-has-connected-to-host": {
"GUID": "guid",
"Name": "name",
"Type": "Tether",
"Tether": {
"BatteryPercentage": 85,
"Carrier": "Project Fi",
"SignalStrength": 101
}
},
"tether-missing-signal-strength": { "tether-missing-signal-strength": {
"GUID": "guid", "GUID": "guid",
"Name": "name", "Name": "name",
"Type": "Tether", "Type": "Tether",
"Tether": { "Tether": {
"BatteryPercentage": 85, "BatteryPercentage": 85,
"Carrier": "Project Fi" "Carrier": "Project Fi",
"HasConnectedToHost": true,
} }
}, },
"tether-negative-signal-strength": { "tether-negative-signal-strength": {
...@@ -431,6 +446,7 @@ ...@@ -431,6 +446,7 @@
"Tether": { "Tether": {
"BatteryPercentage": 85, "BatteryPercentage": 85,
"Carrier": "Project Fi", "Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": -1 "SignalStrength": -1
} }
}, },
...@@ -441,6 +457,7 @@ ...@@ -441,6 +457,7 @@
"Tether": { "Tether": {
"BatteryPercentage": 85, "BatteryPercentage": 85,
"Carrier": "Project Fi", "Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": 101 "SignalStrength": 101
} }
}, },
......
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
"Name": "Tether Network", "Name": "Tether Network",
"Tether.BatteryPercentage": 85, "Tether.BatteryPercentage": 85,
"Tether.Carrier": "Project Fi", "Tether.Carrier": "Project Fi",
"Tether.HasConnectedToHost": true,
"Tether.SignalStrength": 75 "Tether.SignalStrength": 75
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
"Tether": { "Tether": {
"BatteryPercentage": 85, "BatteryPercentage": 85,
"Carrier": "Project Fi", "Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": 75 "SignalStrength": 75
} }
} }
...@@ -1456,6 +1456,12 @@ a phone. ...@@ -1456,6 +1456,12 @@ a phone.
* The name of the cellular carrier when the hotspot is provided by a * The name of the cellular carrier when the hotspot is provided by a
cellular connection. cellular connection.
* **HasConnectedToHost**
* (read-only) - **boolean**
* If *true*, the current device has already connected to a Tether network
created by the same external device which is providing this Tether
network.
* **SignalStrength** * **SignalStrength**
* (optional, read-only) - **integer** * (optional, read-only) - **integer**
* The current signal strength for the hotspot's connection in the range * The current signal strength for the hotspot's connection in the range
......
...@@ -197,6 +197,7 @@ const char k8021X[] = "8021X"; ...@@ -197,6 +197,7 @@ const char k8021X[] = "8021X";
namespace tether { namespace tether {
const char kBatteryPercentage[] = "BatteryPercentage"; const char kBatteryPercentage[] = "BatteryPercentage";
const char kCarrier[] = "Carrier"; const char kCarrier[] = "Carrier";
const char kHasConnectedToHost[] = "HasConnectedToHost";
const char kSignalStrength[] = "SignalStrength"; const char kSignalStrength[] = "SignalStrength";
} // namespace tether } // namespace tether
......
...@@ -222,6 +222,7 @@ ONC_EXPORT extern const char k8021X[]; ...@@ -222,6 +222,7 @@ ONC_EXPORT extern const char k8021X[];
namespace tether { namespace tether {
ONC_EXPORT extern const char kBatteryPercentage[]; ONC_EXPORT extern const char kBatteryPercentage[];
ONC_EXPORT extern const char kCarrier[]; ONC_EXPORT extern const char kCarrier[];
ONC_EXPORT extern const char kHasConnectedToHost[];
ONC_EXPORT extern const char kSignalStrength[]; ONC_EXPORT extern const char kSignalStrength[];
} // namespace tether } // namespace tether
......
...@@ -583,6 +583,7 @@ namespace networkingPrivate { ...@@ -583,6 +583,7 @@ namespace networkingPrivate {
dictionary TetherProperties { dictionary TetherProperties {
long? BatteryPercentage; long? BatteryPercentage;
DOMString? Carrier; DOMString? Carrier;
boolean HasConnectedToHost;
long? SignalStrength; long? SignalStrength;
}; };
......
...@@ -767,6 +767,7 @@ chrome.networkingPrivate.EthernetStateProperties; ...@@ -767,6 +767,7 @@ chrome.networkingPrivate.EthernetStateProperties;
* @typedef {{ * @typedef {{
* BatteryPercentage: (number|undefined), * BatteryPercentage: (number|undefined),
* Carrier: (string|undefined), * Carrier: (string|undefined),
* HasConnectedToHost: boolean,
* SignalStrength: (number|undefined) * SignalStrength: (number|undefined)
* }} * }}
* @see https://developer.chrome.com/extensions/networkingPrivate#type-TetherProperties * @see https://developer.chrome.com/extensions/networkingPrivate#type-TetherProperties
......
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