Index: chromeos/network/network_state_handler.cc |
diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc |
index d1fe75c1ebad0dac0bd732bcc7960573fac3f965..f0d363aaa26c6bd2be2851b1f715c36b45eebcd5 100644 |
--- a/chromeos/network/network_state_handler.cc |
+++ b/chromeos/network/network_state_handler.cc |
@@ -126,9 +126,7 @@ NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( |
std::string technology = GetTechnologyForType(type); |
if (technology == kTypeTether) { |
- bool is_tether_enabled = base::CommandLine::ForCurrentProcess()->HasSwitch( |
- chromeos::switches::kEnableTether); |
- return is_tether_enabled ? TECHNOLOGY_ENABLED : TECHNOLOGY_UNAVAILABLE; |
+ return tether_state_; |
} |
TechnologyState state; |
@@ -154,6 +152,13 @@ void NetworkStateHandler::SetTechnologyEnabled( |
const network_handler::ErrorCallback& error_callback) { |
std::vector<std::string> technologies = GetTechnologiesForType(type); |
for (const std::string& technology : technologies) { |
+ if (technology == kTypeTether) { |
+ // Tether does not exist in Shill, so call SetTetherTechnologyState() and |
Ryan Hansberry
2017/04/20 01:38:35
The comment suggests that SetTetherTechnologyState
Kyle Horimoto
2017/04/20 02:16:08
Done.
|
+ // skip the below interactions with |shill_property_handler_|. |
+ tether_state_ = enabled ? TECHNOLOGY_ENABLED : TECHNOLOGY_AVAILABLE; |
+ continue; |
+ } |
+ |
if (!shill_property_handler_->IsTechnologyAvailable(technology)) |
continue; |
NET_LOG_USER("SetTechnologyEnabled", |
@@ -165,11 +170,53 @@ void NetworkStateHandler::SetTechnologyEnabled( |
NotifyDeviceListChanged(); |
} |
+void NetworkStateHandler::SetTetherTechnologyState( |
+ TechnologyState technology_state) { |
+ if (tether_state_ == technology_state) |
+ return; |
+ |
+ tether_state_ = technology_state; |
+ |
+ // Signal Device/Technology state changed. |
+ NotifyDeviceListChanged(); |
+} |
+ |
+void NetworkStateHandler::SetTetherScanState(bool is_scanning) { |
+ DeviceState* tether_device_state = |
+ GetModifiableDeviceState(kTetherDevicePath); |
+ DCHECK(tether_device_state); |
+ |
+ bool was_scanning = tether_device_state->scanning(); |
+ tether_device_state->set_scanning(is_scanning); |
+ |
+ if (was_scanning && !is_scanning) { |
+ // If a scan was in progress but has completed, notify observers. |
+ NotifyScanCompleted(tether_device_state); |
+ } |
+} |
+ |
void NetworkStateHandler::SetProhibitedTechnologies( |
const std::vector<std::string>& prohibited_technologies, |
const network_handler::ErrorCallback& error_callback) { |
- shill_property_handler_->SetProhibitedTechnologies(prohibited_technologies, |
- error_callback); |
+ // Make a copy of |prohibited_technologies| since the list may be edited |
+ // within this function. |
+ std::vector<std::string> prohibited_technologies_copy = |
+ prohibited_technologies; |
+ |
+ for (auto it = prohibited_technologies_copy.begin(); |
+ it < prohibited_technologies_copy.end(); ++it) { |
+ if (*it == kTypeTether) { |
+ // If tethering is prohibited, set |tether_state_| and remove tethering |
Ryan Hansberry
2017/04/20 01:38:35
Tether*
Kyle Horimoto
2017/04/20 02:16:08
Done.
|
+ // from the list before passing it to |shill_property_handler_| below. |
+ // Shill does not have a concept of tether networks, so it cannot |
+ // prohibit that technology type. |
+ tether_state_ = TECHNOLOGY_PROHIBITED; |
+ it = prohibited_technologies_copy.erase(it); |
+ } |
+ } |
+ |
+ shill_property_handler_->SetProhibitedTechnologies( |
+ prohibited_technologies_copy, error_callback); |
// Signal Device/Technology state changed. |
NotifyDeviceListChanged(); |
} |
@@ -323,9 +370,14 @@ const NetworkState* NetworkStateHandler::FirstNetworkByType( |
std::string NetworkStateHandler::FormattedHardwareAddressForType( |
const NetworkTypePattern& type) const { |
const NetworkState* network = ConnectedNetworkByType(type); |
+ if (network && network->type() == kTypeTether) { |
+ // If this is a tether network, get the MAC address corresponding to that |
+ // network instead. |
+ network = GetNetworkStateFromGuid(network->tether_guid()); |
Ryan Hansberry
2017/04/20 01:38:35
Just return empty string here instead.
Kyle Horimoto
2017/04/20 02:16:08
I don't think we should - we should return the MAC
Ryan Hansberry
2017/04/20 16:53:54
But we know at this point that the network does no
Kyle Horimoto
2017/04/20 19:38:46
stevenjb@, can you comment on this?
stevenjb
2017/04/20 20:01:10
Why wouldn't a tether network show the MAC address
Ryan Hansberry
2017/04/20 21:27:02
If that's the case, then we should return the mac_
Kyle Horimoto
2017/04/20 21:28:45
That's what I'm already doing ;)
|
+ } |
const DeviceState* device = network ? GetDeviceState(network->device_path()) |
: GetDeviceStateByType(type); |
- if (!device) |
+ if (!device || device->mac_address().empty()) |
return std::string(); |
return network_util::FormattedMacAddress(device->mac_address()); |
} |
@@ -431,6 +483,7 @@ void NetworkStateHandler::AddTetherNetworkState(const std::string& guid, |
DCHECK(!guid.empty()); |
DCHECK(battery_percentage >= 0 && battery_percentage <= 100); |
DCHECK(signal_strength >= 0 && signal_strength <= 100); |
+ DCHECK(tether_state_ == TECHNOLOGY_ENABLED); |
// If the network already exists, do nothing. |
if (GetNetworkStateFromGuid(guid)) { |
@@ -463,6 +516,8 @@ bool NetworkStateHandler::UpdateTetherNetworkProperties( |
const std::string& carrier, |
int battery_percentage, |
int signal_strength) { |
+ DCHECK(tether_state_ == TECHNOLOGY_ENABLED); |
+ |
NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); |
if (!tether_network_state) |
return false; |
@@ -494,6 +549,8 @@ void NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) { |
bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( |
const std::string& tether_network_guid, |
const std::string& wifi_network_guid) { |
+ DCHECK(tether_state_ == TECHNOLOGY_ENABLED); |
+ |
NetworkState* tether_network = |
GetModifiableNetworkStateFromGuid(tether_network_guid); |
if (!tether_network) { |
@@ -693,6 +750,17 @@ void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, |
ManagedStateList* managed_list = GetManagedList(type); |
NET_LOG_DEBUG("UpdateManagedList: " + ManagedState::TypeToString(type), |
base::StringPrintf("%" PRIuS, entries.GetSize())); |
+ |
+ // Create a copy of |entries| since it may be edited below. |
+ base::ListValue entries_copy(entries); |
+ if (type == ManagedState::ManagedType::MANAGED_TYPE_DEVICE) { |
+ // If a device list update is received from Shill, the list supplied will |
+ // never contain an entry for tether networks since Shill does not recognize |
+ // tether networks as a device type. Before processing the list, add an |
+ // entry for the tether device type with the constant tether device path. |
+ entries_copy.Append(base::MakeUnique<base::Value>(kTetherDevicePath)); |
+ } |
+ |
// Create a map of existing entries. Assumes all entries in |managed_list| |
// are unique. |
std::map<std::string, std::unique_ptr<ManagedState>> managed_map; |
@@ -705,7 +773,7 @@ void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, |
managed_list->clear(); |
// Updates managed_list and request updates for new entries. |
std::set<std::string> list_entries; |
- for (auto& iter : entries) { |
+ for (auto& iter : entries_copy) { |
std::string path; |
iter.GetAsString(&path); |
if (path.empty() || path == shill::kFlimflamServicePath) { |
@@ -718,7 +786,17 @@ void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type, |
NET_LOG_ERROR("Duplicate entry in list", path); |
continue; |
} |
- managed_list->push_back(ManagedState::Create(type, path)); |
+ std::unique_ptr<ManagedState> state = ManagedState::Create(type, path); |
+ if (type == ManagedState::ManagedType::MANAGED_TYPE_DEVICE && |
+ path == kTetherDevicePath) { |
+ // If adding the tether DeviceState, set appropriate properties since |
+ // it will never receive a properties update from Shill. |
+ state->set_update_received(); |
+ state->set_update_requested(false); |
+ state->set_name(kTetherDeviceName); |
+ state->set_type(kTypeTether); |
+ } |
+ managed_list->push_back(std::move(state)); |
} else { |
managed_list->push_back(std::move(found->second)); |
managed_map.erase(found); |
@@ -1275,6 +1353,8 @@ std::vector<std::string> NetworkStateHandler::GetTechnologiesForType( |
technologies.emplace_back(shill::kTypeBluetooth); |
if (type.MatchesType(shill::kTypeVPN)) |
technologies.emplace_back(shill::kTypeVPN); |
+ if (type.MatchesType(kTypeTether)) |
+ technologies.emplace_back(kTypeTether); |
CHECK_GT(technologies.size(), 0ul); |
return technologies; |