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 = {
: properties.Name);
assertEq(expectedBatteryPercentage, properties.Tether.BatteryPercentage);
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);
}
};
......
......@@ -366,6 +366,9 @@ TEST_F(NetworkConfigurationHandlerTest, GetProperties_TetherNetwork) {
NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED);
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(
kTetherGuid, "TetherNetworkName", "TetherNetworkCarrier",
100 /* battery_percentage */, 100 /* signal_strength */);
......@@ -380,6 +383,7 @@ TEST_F(NetworkConfigurationHandlerTest, GetProperties_TetherNetwork) {
"\"State\": \"\",\n "
"\"Tether.BatteryPercentage\": 100,\n "
"\"Tether.Carrier\": \"TetherNetworkCarrier\",\n "
"\"Tether.HasConnectedToHost\": false,\n "
"\"Tether.SignalStrength\": 100,\n "
"\"Type\": \"wifi-tether\"\n"
"}\n";
......
......@@ -267,6 +267,8 @@ void NetworkState::GetStateProperties(base::DictionaryValue* dictionary) const {
dictionary->SetIntegerWithoutPathExpansion(kTetherBatteryPercentage,
battery_percentage());
dictionary->SetStringWithoutPathExpansion(kTetherCarrier, carrier());
dictionary->SetBooleanWithoutPathExpansion(kTetherHasConnectedToHost,
tether_has_connected_to_host());
dictionary->SetIntegerWithoutPathExpansion(kTetherSignalStrength,
signal_strength());
}
......
......@@ -114,6 +114,12 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState {
}
const std::string& carrier() const { return 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_; }
void set_tether_guid(const std::string& guid) { tether_guid_ = guid; }
......@@ -229,6 +235,12 @@ class CHROMEOS_EXPORT NetworkState : public ManagedState {
// Tether properties.
std::string carrier_;
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
// provides proxy configuration. crbug.com/241775
......
......@@ -531,6 +531,9 @@ void NetworkStateHandler::AddTetherNetworkState(const std::string& guid,
tether_network_state->set_connectable(true);
tether_network_state->set_carrier(carrier);
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_list_.push_back(std::move(tether_network_state));
......
......@@ -262,6 +262,7 @@ TEST_F(NetworkStateTest, TetherProperties) {
network_state_.set_type(kTypeTether);
network_state_.set_carrier("Project Fi");
network_state_.set_battery_percentage(85);
network_state_.set_tether_has_connected_to_host(true);
network_state_.set_signal_strength(75);
base::DictionaryValue dictionary;
......@@ -277,6 +278,11 @@ TEST_F(NetworkStateTest, TetherProperties) {
kTetherBatteryPercentage, &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;
EXPECT_TRUE(
dictionary.GetStringWithoutPathExpansion(kTetherCarrier, &carrier));
......
......@@ -172,6 +172,7 @@ const OncFieldSignature tether_fields[] = {{NULL}};
const OncFieldSignature tether_with_state_fields[] = {
{::onc::tether::kBatteryPercentage, &kIntegerSignature},
{::onc::tether::kCarrier, &kStringSignature},
{::onc::tether::kHasConnectedToHost, &kBoolSignature},
{::onc::tether::kSignalStrength, &kIntegerSignature},
{NULL}};
......
......@@ -114,6 +114,7 @@ const FieldTranslationEntry vpn_fields[] = {
const FieldTranslationEntry tether_fields[] = {
{::onc::tether::kBatteryPercentage, kTetherBatteryPercentage},
{::onc::tether::kCarrier, kTetherCarrier},
{::onc::tether::kHasConnectedToHost, kTetherHasConnectedToHost},
{::onc::tether::kSignalStrength, kTetherSignalStrength},
{NULL}};
......
......@@ -1008,19 +1008,19 @@ bool Validator::ValidateCertificate(base::DictionaryValue* result) {
bool Validator::ValidateTether(base::DictionaryValue* result) {
using namespace ::onc::tether;
int batteryPercentage;
int battery_percentage;
if (!result->GetIntegerWithoutPathExpansion(kBatteryPercentage,
&batteryPercentage) ||
batteryPercentage < 0 || batteryPercentage > 100) {
&battery_percentage) ||
battery_percentage < 0 || battery_percentage > 100) {
// Battery percentage must be present and within [0, 100].
error_or_warning_found_ = true;
return false;
}
int signalStrength;
int signal_strength;
if (!result->GetIntegerWithoutPathExpansion(kSignalStrength,
&signalStrength) ||
signalStrength < 0 || signalStrength > 100) {
&signal_strength) ||
signal_strength < 0 || signal_strength > 100) {
// Signal strength must be present and within [0, 100].
error_or_warning_found_ = true;
return false;
......@@ -1034,8 +1034,12 @@ bool Validator::ValidateTether(base::DictionaryValue* result) {
return false;
}
// No required fields.
return true;
bool all_required_exist = RequireField(*result, kHasConnectedToHost);
if (!all_required_exist) {
error_or_warning_found_ = true;
}
return !error_on_missing_field_ || all_required_exist;
}
std::string Validator::MessageHeader() {
......
......@@ -564,6 +564,10 @@ INSTANTIATE_TEST_CASE_P(
&kNetworkWithStateSignature,
true),
ExpectBothNotValid("", "")),
std::make_pair(OncParams("tether-missing-has-connected-to-host",
&kNetworkWithStateSignature,
true),
ExpectBothNotValid("", "")),
std::make_pair(OncParams("tether-missing-signal-strength",
&kNetworkWithStateSignature,
true),
......
......@@ -9,6 +9,7 @@ namespace chromeos {
const char kTypeTether[] = "wifi-tether";
const char kTetherBatteryPercentage[] = "Tether.BatteryPercentage";
const char kTetherCarrier[] = "Tether.Carrier";
const char kTetherHasConnectedToHost[] = "Tether.HasConnectedToHost";
const char kTetherSignalStrength[] = "Tether.SignalStrength";
const char kTetherDevicePath[] = "tether-device-path";
const char kTetherDeviceName[] = "tether-name";
......
......@@ -20,6 +20,7 @@ CHROMEOS_EXPORT extern const char kTypeTether[];
// Properties associated with tether networks.
CHROMEOS_EXPORT extern const char kTetherBatteryPercentage[];
CHROMEOS_EXPORT extern const char kTetherCarrier[];
CHROMEOS_EXPORT extern const char kTetherHasConnectedToHost[];
CHROMEOS_EXPORT extern const char kTetherSignalStrength[];
// The device path used for the tether DeviceState.
......
......@@ -383,6 +383,7 @@
"Type": "Tether",
"Tether": {
"Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": 75
}
},
......@@ -393,6 +394,7 @@
"Tether": {
"BatteryPercentage": -1,
"Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": 75
}
},
......@@ -403,6 +405,7 @@
"Tether": {
"BatteryPercentage": 101,
"Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": 75
}
},
......@@ -412,16 +415,28 @@
"Type": "Tether",
"Tether": {
"BatteryPercentage": 85,
"HasConnectedToHost": true,
"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": {
"GUID": "guid",
"Name": "name",
"Type": "Tether",
"Tether": {
"BatteryPercentage": 85,
"Carrier": "Project Fi"
"Carrier": "Project Fi",
"HasConnectedToHost": true,
}
},
"tether-negative-signal-strength": {
......@@ -431,6 +446,7 @@
"Tether": {
"BatteryPercentage": 85,
"Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": -1
}
},
......@@ -441,6 +457,7 @@
"Tether": {
"BatteryPercentage": 85,
"Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": 101
}
},
......
......@@ -3,5 +3,6 @@
"Name": "Tether Network",
"Tether.BatteryPercentage": 85,
"Tether.Carrier": "Project Fi",
"Tether.HasConnectedToHost": true,
"Tether.SignalStrength": 75
}
......@@ -4,6 +4,7 @@
"Tether": {
"BatteryPercentage": 85,
"Carrier": "Project Fi",
"HasConnectedToHost": true,
"SignalStrength": 75
}
}
......@@ -1456,6 +1456,12 @@ a phone.
* The name of the cellular carrier when the hotspot is provided by a
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**
* (optional, read-only) - **integer**
* The current signal strength for the hotspot's connection in the range
......
......@@ -197,6 +197,7 @@ const char k8021X[] = "8021X";
namespace tether {
const char kBatteryPercentage[] = "BatteryPercentage";
const char kCarrier[] = "Carrier";
const char kHasConnectedToHost[] = "HasConnectedToHost";
const char kSignalStrength[] = "SignalStrength";
} // namespace tether
......
......@@ -222,6 +222,7 @@ ONC_EXPORT extern const char k8021X[];
namespace tether {
ONC_EXPORT extern const char kBatteryPercentage[];
ONC_EXPORT extern const char kCarrier[];
ONC_EXPORT extern const char kHasConnectedToHost[];
ONC_EXPORT extern const char kSignalStrength[];
} // namespace tether
......
......@@ -583,6 +583,7 @@ namespace networkingPrivate {
dictionary TetherProperties {
long? BatteryPercentage;
DOMString? Carrier;
boolean HasConnectedToHost;
long? SignalStrength;
};
......
......@@ -767,6 +767,7 @@ chrome.networkingPrivate.EthernetStateProperties;
* @typedef {{
* BatteryPercentage: (number|undefined),
* Carrier: (string|undefined),
* HasConnectedToHost: boolean,
* SignalStrength: (number|undefined)
* }}
* @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