OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/network/network_state_handler.h" | 5 #include "chromeos/network/network_state_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/guid.h" | 12 #include "base/guid.h" |
13 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/values.h" | 21 #include "base/values.h" |
22 #include "chromeos/chromeos_switches.h" | 22 #include "chromeos/chromeos_switches.h" |
23 #include "chromeos/network/device_state.h" | 23 #include "chromeos/network/device_state.h" |
| 24 #include "chromeos/network/network_connection_handler.h" |
24 #include "chromeos/network/network_event_log.h" | 25 #include "chromeos/network/network_event_log.h" |
| 26 #include "chromeos/network/network_handler_callbacks.h" |
25 #include "chromeos/network/network_state.h" | 27 #include "chromeos/network/network_state.h" |
26 #include "chromeos/network/network_state_handler_observer.h" | 28 #include "chromeos/network/network_state_handler_observer.h" |
27 #include "chromeos/network/tether_constants.h" | 29 #include "chromeos/network/tether_constants.h" |
28 #include "third_party/cros_system_api/dbus/service_constants.h" | 30 #include "third_party/cros_system_api/dbus/service_constants.h" |
29 | 31 |
30 namespace chromeos { | 32 namespace chromeos { |
31 | 33 |
32 namespace { | 34 namespace { |
33 | 35 |
34 bool ConnectionStateChanged(NetworkState* network, | 36 bool ConnectionStateChanged(NetworkState* network, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 device_event_log::LOG_TYPE_NETWORK, device_event_log::LOG_LEVEL_DEBUG, | 121 device_event_log::LOG_TYPE_NETWORK, device_event_log::LOG_LEVEL_DEBUG, |
120 base::StringPrintf("NetworkStateHandler::RemoveObserver: 0x%p", | 122 base::StringPrintf("NetworkStateHandler::RemoveObserver: 0x%p", |
121 observer)); | 123 observer)); |
122 } | 124 } |
123 | 125 |
124 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( | 126 NetworkStateHandler::TechnologyState NetworkStateHandler::GetTechnologyState( |
125 const NetworkTypePattern& type) const { | 127 const NetworkTypePattern& type) const { |
126 std::string technology = GetTechnologyForType(type); | 128 std::string technology = GetTechnologyForType(type); |
127 | 129 |
128 if (technology == kTypeTether) { | 130 if (technology == kTypeTether) { |
129 bool is_tether_enabled = base::CommandLine::ForCurrentProcess()->HasSwitch( | 131 return tether_technology_state_; |
130 chromeos::switches::kEnableTether); | |
131 return is_tether_enabled ? TECHNOLOGY_ENABLED : TECHNOLOGY_UNAVAILABLE; | |
132 } | 132 } |
133 | 133 |
134 TechnologyState state; | 134 TechnologyState state; |
135 if (shill_property_handler_->IsTechnologyEnabled(technology)) | 135 if (shill_property_handler_->IsTechnologyEnabled(technology)) |
136 state = TECHNOLOGY_ENABLED; | 136 state = TECHNOLOGY_ENABLED; |
137 else if (shill_property_handler_->IsTechnologyEnabling(technology)) | 137 else if (shill_property_handler_->IsTechnologyEnabling(technology)) |
138 state = TECHNOLOGY_ENABLING; | 138 state = TECHNOLOGY_ENABLING; |
139 else if (shill_property_handler_->IsTechnologyProhibited(technology)) | 139 else if (shill_property_handler_->IsTechnologyProhibited(technology)) |
140 state = TECHNOLOGY_PROHIBITED; | 140 state = TECHNOLOGY_PROHIBITED; |
141 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) | 141 else if (shill_property_handler_->IsTechnologyUninitialized(technology)) |
142 state = TECHNOLOGY_UNINITIALIZED; | 142 state = TECHNOLOGY_UNINITIALIZED; |
143 else if (shill_property_handler_->IsTechnologyAvailable(technology)) | 143 else if (shill_property_handler_->IsTechnologyAvailable(technology)) |
144 state = TECHNOLOGY_AVAILABLE; | 144 state = TECHNOLOGY_AVAILABLE; |
145 else | 145 else |
146 state = TECHNOLOGY_UNAVAILABLE; | 146 state = TECHNOLOGY_UNAVAILABLE; |
147 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state; | 147 VLOG(2) << "GetTechnologyState: " << type.ToDebugString() << " = " << state; |
148 return state; | 148 return state; |
149 } | 149 } |
150 | 150 |
151 void NetworkStateHandler::SetTechnologyEnabled( | 151 void NetworkStateHandler::SetTechnologyEnabled( |
152 const NetworkTypePattern& type, | 152 const NetworkTypePattern& type, |
153 bool enabled, | 153 bool enabled, |
154 const network_handler::ErrorCallback& error_callback) { | 154 const network_handler::ErrorCallback& error_callback) { |
155 std::vector<std::string> technologies = GetTechnologiesForType(type); | 155 std::vector<std::string> technologies = GetTechnologiesForType(type); |
156 for (const std::string& technology : technologies) { | 156 for (const std::string& technology : technologies) { |
| 157 if (technology == kTypeTether) { |
| 158 if (tether_technology_state_ != TECHNOLOGY_ENABLED && |
| 159 tether_technology_state_ != TECHNOLOGY_AVAILABLE) { |
| 160 NET_LOG(ERROR) << "SetTechnologyEnabled() called for the Tether " |
| 161 << "DeviceState, but the current state was not " |
| 162 << "TECHNOLOGY_ENABLED or TECHNOLOGY_AVAILABLE."; |
| 163 network_handler::RunErrorCallback( |
| 164 error_callback, kTetherDevicePath, |
| 165 NetworkConnectionHandler::kEnabledOrDisabledWhenNotAvailable, ""); |
| 166 continue; |
| 167 } |
| 168 |
| 169 // Tether does not exist in Shill, so set |tether_technology_state_| and |
| 170 // skip the below interactions with |shill_property_handler_|. |
| 171 tether_technology_state_ = |
| 172 enabled ? TECHNOLOGY_ENABLED : TECHNOLOGY_AVAILABLE; |
| 173 continue; |
| 174 } |
| 175 |
157 if (!shill_property_handler_->IsTechnologyAvailable(technology)) | 176 if (!shill_property_handler_->IsTechnologyAvailable(technology)) |
158 continue; | 177 continue; |
159 NET_LOG_USER("SetTechnologyEnabled", | 178 NET_LOG_USER("SetTechnologyEnabled", |
160 base::StringPrintf("%s:%d", technology.c_str(), enabled)); | 179 base::StringPrintf("%s:%d", technology.c_str(), enabled)); |
161 shill_property_handler_->SetTechnologyEnabled(technology, enabled, | 180 shill_property_handler_->SetTechnologyEnabled(technology, enabled, |
162 error_callback); | 181 error_callback); |
163 } | 182 } |
164 // Signal Device/Technology state changed. | 183 // Signal Device/Technology state changed. |
165 NotifyDeviceListChanged(); | 184 NotifyDeviceListChanged(); |
166 } | 185 } |
167 | 186 |
| 187 void NetworkStateHandler::SetTetherTechnologyState( |
| 188 TechnologyState technology_state) { |
| 189 if (tether_technology_state_ == technology_state) |
| 190 return; |
| 191 |
| 192 tether_technology_state_ = technology_state; |
| 193 EnsureTetherDeviceState(); |
| 194 |
| 195 // Signal Device/Technology state changed. |
| 196 NotifyDeviceListChanged(); |
| 197 } |
| 198 |
| 199 void NetworkStateHandler::SetTetherScanState(bool is_scanning) { |
| 200 DeviceState* tether_device_state = |
| 201 GetModifiableDeviceState(kTetherDevicePath); |
| 202 DCHECK(tether_device_state); |
| 203 |
| 204 bool was_scanning = tether_device_state->scanning(); |
| 205 tether_device_state->set_scanning(is_scanning); |
| 206 |
| 207 if (was_scanning && !is_scanning) { |
| 208 // If a scan was in progress but has completed, notify observers. |
| 209 NotifyScanCompleted(tether_device_state); |
| 210 } |
| 211 } |
| 212 |
168 void NetworkStateHandler::SetProhibitedTechnologies( | 213 void NetworkStateHandler::SetProhibitedTechnologies( |
169 const std::vector<std::string>& prohibited_technologies, | 214 const std::vector<std::string>& prohibited_technologies, |
170 const network_handler::ErrorCallback& error_callback) { | 215 const network_handler::ErrorCallback& error_callback) { |
171 shill_property_handler_->SetProhibitedTechnologies(prohibited_technologies, | 216 // Make a copy of |prohibited_technologies| since the list may be edited |
172 error_callback); | 217 // within this function. |
| 218 std::vector<std::string> prohibited_technologies_copy = |
| 219 prohibited_technologies; |
| 220 |
| 221 for (auto it = prohibited_technologies_copy.begin(); |
| 222 it < prohibited_technologies_copy.end(); ++it) { |
| 223 if (*it == kTypeTether) { |
| 224 // If Tether networks are prohibited, set |tether_technology_state_| and |
| 225 // remove |kTypeTether| from the list before passing it to |
| 226 // |shill_property_handler_| below. Shill does not have a concept of |
| 227 // Tether networks, so it cannot prohibit that technology type. |
| 228 tether_technology_state_ = TECHNOLOGY_PROHIBITED; |
| 229 it = prohibited_technologies_copy.erase(it); |
| 230 } |
| 231 } |
| 232 |
| 233 shill_property_handler_->SetProhibitedTechnologies( |
| 234 prohibited_technologies_copy, error_callback); |
173 // Signal Device/Technology state changed. | 235 // Signal Device/Technology state changed. |
174 NotifyDeviceListChanged(); | 236 NotifyDeviceListChanged(); |
175 } | 237 } |
176 | 238 |
177 const DeviceState* NetworkStateHandler::GetDeviceState( | 239 const DeviceState* NetworkStateHandler::GetDeviceState( |
178 const std::string& device_path) const { | 240 const std::string& device_path) const { |
179 const DeviceState* device = GetModifiableDeviceState(device_path); | 241 const DeviceState* device = GetModifiableDeviceState(device_path); |
180 if (device && !device->update_received()) | 242 if (device && !device->update_received()) |
181 return nullptr; | 243 return nullptr; |
182 return device; | 244 return device; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } | 355 } |
294 | 356 |
295 return connecting_network; | 357 return connecting_network; |
296 } | 358 } |
297 | 359 |
298 const NetworkState* NetworkStateHandler::FirstNetworkByType( | 360 const NetworkState* NetworkStateHandler::FirstNetworkByType( |
299 const NetworkTypePattern& type) { | 361 const NetworkTypePattern& type) { |
300 if (!network_list_sorted_) | 362 if (!network_list_sorted_) |
301 SortNetworkList(); // Sort to ensure visible networks are listed first. | 363 SortNetworkList(); // Sort to ensure visible networks are listed first. |
302 | 364 |
303 // If |type| matches tether networks and at least one tether network is | 365 // If |type| matches Tether networks and at least one Tether network is |
304 // present, return the first network (since it has been sorted already). | 366 // present, return the first network (since it has been sorted already). |
305 if (type.MatchesPattern(NetworkTypePattern::Tether()) && | 367 if (type.MatchesPattern(NetworkTypePattern::Tether()) && |
306 !tether_network_list_.empty()) { | 368 !tether_network_list_.empty()) { |
307 return tether_network_list_[0]->AsNetworkState(); | 369 return tether_network_list_[0]->AsNetworkState(); |
308 } | 370 } |
309 | 371 |
310 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { | 372 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { |
311 const NetworkState* network = (*iter)->AsNetworkState(); | 373 const NetworkState* network = (*iter)->AsNetworkState(); |
312 DCHECK(network); | 374 DCHECK(network); |
313 if (!network->update_received()) | 375 if (!network->update_received()) |
314 continue; | 376 continue; |
315 if (!network->visible()) | 377 if (!network->visible()) |
316 break; | 378 break; |
317 if (network->Matches(type)) | 379 if (network->Matches(type)) |
318 return network; | 380 return network; |
319 } | 381 } |
320 return nullptr; | 382 return nullptr; |
321 } | 383 } |
322 | 384 |
323 std::string NetworkStateHandler::FormattedHardwareAddressForType( | 385 std::string NetworkStateHandler::FormattedHardwareAddressForType( |
324 const NetworkTypePattern& type) const { | 386 const NetworkTypePattern& type) const { |
325 const NetworkState* network = ConnectedNetworkByType(type); | 387 const NetworkState* network = ConnectedNetworkByType(type); |
| 388 if (network && network->type() == kTypeTether) { |
| 389 // If this is a Tether network, get the MAC address corresponding to that |
| 390 // network instead. |
| 391 network = GetNetworkStateFromGuid(network->tether_guid()); |
| 392 } |
326 const DeviceState* device = network ? GetDeviceState(network->device_path()) | 393 const DeviceState* device = network ? GetDeviceState(network->device_path()) |
327 : GetDeviceStateByType(type); | 394 : GetDeviceStateByType(type); |
328 if (!device) | 395 if (!device || device->mac_address().empty()) |
329 return std::string(); | 396 return std::string(); |
330 return network_util::FormattedMacAddress(device->mac_address()); | 397 return network_util::FormattedMacAddress(device->mac_address()); |
331 } | 398 } |
332 | 399 |
333 void NetworkStateHandler::GetVisibleNetworkListByType( | 400 void NetworkStateHandler::GetVisibleNetworkListByType( |
334 const NetworkTypePattern& type, | 401 const NetworkTypePattern& type, |
335 NetworkStateList* list) { | 402 NetworkStateList* list) { |
336 GetNetworkListByType(type, false /* configured_only */, | 403 GetNetworkListByType(type, false /* configured_only */, |
337 true /* visible_only */, 0 /* no limit */, list); | 404 true /* visible_only */, 0 /* no limit */, list); |
338 } | 405 } |
(...skipping 15 matching lines...) Expand all Loading... |
354 SortNetworkList(); | 421 SortNetworkList(); |
355 | 422 |
356 if (type.MatchesPattern(NetworkTypePattern::Tether())) { | 423 if (type.MatchesPattern(NetworkTypePattern::Tether())) { |
357 GetTetherNetworkList(limit, list); | 424 GetTetherNetworkList(limit, list); |
358 } | 425 } |
359 | 426 |
360 int count = list->size(); | 427 int count = list->size(); |
361 | 428 |
362 if (type.Equals(NetworkTypePattern::Tether()) || | 429 if (type.Equals(NetworkTypePattern::Tether()) || |
363 (limit != 0 && count >= limit)) { | 430 (limit != 0 && count >= limit)) { |
364 // If only searching for tether networks, there is no need to continue | 431 // If only searching for Tether networks, there is no need to continue |
365 // searching through other network types; likewise, if the limit has already | 432 // searching through other network types; likewise, if the limit has already |
366 // been reached, there is no need to continue searching. | 433 // been reached, there is no need to continue searching. |
367 return; | 434 return; |
368 } | 435 } |
369 | 436 |
370 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { | 437 for (auto iter = network_list_.begin(); iter != network_list_.end(); ++iter) { |
371 const NetworkState* network = (*iter)->AsNetworkState(); | 438 const NetworkState* network = (*iter)->AsNetworkState(); |
372 DCHECK(network); | 439 DCHECK(network); |
373 if (!network->update_received() || !network->Matches(type)) | 440 if (!network->update_received() || !network->Matches(type)) |
374 continue; | 441 continue; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 | 492 |
426 void NetworkStateHandler::AddTetherNetworkState(const std::string& guid, | 493 void NetworkStateHandler::AddTetherNetworkState(const std::string& guid, |
427 const std::string& name, | 494 const std::string& name, |
428 const std::string& carrier, | 495 const std::string& carrier, |
429 int battery_percentage, | 496 int battery_percentage, |
430 int signal_strength) { | 497 int signal_strength) { |
431 DCHECK(!guid.empty()); | 498 DCHECK(!guid.empty()); |
432 DCHECK(battery_percentage >= 0 && battery_percentage <= 100); | 499 DCHECK(battery_percentage >= 0 && battery_percentage <= 100); |
433 DCHECK(signal_strength >= 0 && signal_strength <= 100); | 500 DCHECK(signal_strength >= 0 && signal_strength <= 100); |
434 | 501 |
| 502 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { |
| 503 NET_LOG(ERROR) << "AddTetherNetworkState() called when Tether networks " |
| 504 << "are not enabled. Cannot add NetworkState."; |
| 505 return; |
| 506 } |
| 507 |
435 // If the network already exists, do nothing. | 508 // If the network already exists, do nothing. |
436 if (GetNetworkStateFromGuid(guid)) { | 509 if (GetNetworkStateFromGuid(guid)) { |
437 NET_LOG(ERROR) << "AddTetherNetworkState: " << name | 510 NET_LOG(ERROR) << "AddTetherNetworkState: " << name |
438 << " called with existing guid:" << guid; | 511 << " called with existing guid:" << guid; |
439 return; | 512 return; |
440 } | 513 } |
441 | 514 |
442 // Use the GUID as the network's service path. | 515 // Use the GUID as the network's service path. |
443 std::unique_ptr<NetworkState> tether_network_state = | 516 std::unique_ptr<NetworkState> tether_network_state = |
444 base::MakeUnique<NetworkState>(guid /* path */); | 517 base::MakeUnique<NetworkState>(guid /* path */); |
(...skipping 11 matching lines...) Expand all Loading... |
456 | 529 |
457 tether_network_list_.push_back(std::move(tether_network_state)); | 530 tether_network_list_.push_back(std::move(tether_network_state)); |
458 NotifyNetworkListChanged(); | 531 NotifyNetworkListChanged(); |
459 } | 532 } |
460 | 533 |
461 bool NetworkStateHandler::UpdateTetherNetworkProperties( | 534 bool NetworkStateHandler::UpdateTetherNetworkProperties( |
462 const std::string& guid, | 535 const std::string& guid, |
463 const std::string& carrier, | 536 const std::string& carrier, |
464 int battery_percentage, | 537 int battery_percentage, |
465 int signal_strength) { | 538 int signal_strength) { |
| 539 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { |
| 540 NET_LOG(ERROR) << "UpdateTetherNetworkProperties() called when Tether " |
| 541 << "networks are not enabled. Cannot update."; |
| 542 return false; |
| 543 } |
| 544 |
466 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); | 545 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); |
467 if (!tether_network_state) | 546 if (!tether_network_state) |
468 return false; | 547 return false; |
469 | 548 |
470 tether_network_state->set_carrier(carrier); | 549 tether_network_state->set_carrier(carrier); |
471 tether_network_state->set_battery_percentage(battery_percentage); | 550 tether_network_state->set_battery_percentage(battery_percentage); |
472 tether_network_state->set_signal_strength(signal_strength); | 551 tether_network_state->set_signal_strength(signal_strength); |
473 | 552 |
474 NotifyNetworkListChanged(); | 553 NotifyNetworkListChanged(); |
475 return true; | 554 return true; |
(...skipping 11 matching lines...) Expand all Loading... |
487 tether_network_list_.erase(iter); | 566 tether_network_list_.erase(iter); |
488 NotifyNetworkListChanged(); | 567 NotifyNetworkListChanged(); |
489 return; | 568 return; |
490 } | 569 } |
491 } | 570 } |
492 } | 571 } |
493 | 572 |
494 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( | 573 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( |
495 const std::string& tether_network_guid, | 574 const std::string& tether_network_guid, |
496 const std::string& wifi_network_guid) { | 575 const std::string& wifi_network_guid) { |
| 576 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { |
| 577 NET_LOG(ERROR) << "AssociateTetherNetworkStateWithWifiNetwork() called " |
| 578 << "when Tether networks are not enabled. Cannot " |
| 579 << "associate."; |
| 580 return false; |
| 581 } |
| 582 |
497 NetworkState* tether_network = | 583 NetworkState* tether_network = |
498 GetModifiableNetworkStateFromGuid(tether_network_guid); | 584 GetModifiableNetworkStateFromGuid(tether_network_guid); |
499 if (!tether_network) { | 585 if (!tether_network) { |
500 NET_LOG(ERROR) << "Tether network does not exist: " << tether_network_guid; | 586 NET_LOG(ERROR) << "Tether network does not exist: " << tether_network_guid; |
501 return false; | 587 return false; |
502 } | 588 } |
503 if (!NetworkTypePattern::Tether().MatchesType(tether_network->type())) { | 589 if (!NetworkTypePattern::Tether().MatchesType(tether_network->type())) { |
504 NET_LOG(ERROR) << "Network is not a Tether network: " | 590 NET_LOG(ERROR) << "Network is not a Tether network: " |
505 << tether_network_guid; | 591 << tether_network_guid; |
506 return false; | 592 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
518 } | 604 } |
519 | 605 |
520 tether_network->set_tether_guid(wifi_network_guid); | 606 tether_network->set_tether_guid(wifi_network_guid); |
521 wifi_network->set_tether_guid(tether_network_guid); | 607 wifi_network->set_tether_guid(tether_network_guid); |
522 NotifyNetworkListChanged(); | 608 NotifyNetworkListChanged(); |
523 return true; | 609 return true; |
524 } | 610 } |
525 | 611 |
526 void NetworkStateHandler::SetTetherNetworkStateDisconnected( | 612 void NetworkStateHandler::SetTetherNetworkStateDisconnected( |
527 const std::string& guid) { | 613 const std::string& guid) { |
528 // TODO(khorimoto): Remove the tether network as the default network, and | 614 // TODO(khorimoto): Remove the Tether network as the default network, and |
529 // send a connection status change. | 615 // send a connection status change. |
530 SetTetherNetworkStateConnectionState(guid, shill::kStateDisconnect); | 616 SetTetherNetworkStateConnectionState(guid, shill::kStateDisconnect); |
531 } | 617 } |
532 | 618 |
533 void NetworkStateHandler::SetTetherNetworkStateConnecting( | 619 void NetworkStateHandler::SetTetherNetworkStateConnecting( |
534 const std::string& guid) { | 620 const std::string& guid) { |
535 // TODO(khorimoto): Set the tether network as the default network, and send | 621 // TODO(khorimoto): Set the Tether network as the default network, and send |
536 // a connection status change. | 622 // a connection status change. |
537 SetTetherNetworkStateConnectionState(guid, shill::kStateConfiguration); | 623 SetTetherNetworkStateConnectionState(guid, shill::kStateConfiguration); |
538 } | 624 } |
539 | 625 |
540 void NetworkStateHandler::SetTetherNetworkStateConnected( | 626 void NetworkStateHandler::SetTetherNetworkStateConnected( |
541 const std::string& guid) { | 627 const std::string& guid) { |
542 // Being connected implies that AssociateTetherNetworkStateWithWifiNetwork() | 628 // Being connected implies that AssociateTetherNetworkStateWithWifiNetwork() |
543 // was already called, so ensure that the association is still intact. | 629 // was already called, so ensure that the association is still intact. |
544 DCHECK(GetNetworkStateFromGuid(GetNetworkStateFromGuid(guid)->tether_guid()) | 630 DCHECK(GetNetworkStateFromGuid(GetNetworkStateFromGuid(guid)->tether_guid()) |
545 ->tether_guid() == guid); | 631 ->tether_guid() == guid); |
(...skipping 11 matching lines...) Expand all Loading... |
557 << "not found: " << guid; | 643 << "not found: " << guid; |
558 return; | 644 return; |
559 } | 645 } |
560 | 646 |
561 DCHECK(NetworkTypePattern::Tether().MatchesType(tether_network->type())); | 647 DCHECK(NetworkTypePattern::Tether().MatchesType(tether_network->type())); |
562 | 648 |
563 tether_network->set_connection_state(connection_state); | 649 tether_network->set_connection_state(connection_state); |
564 NotifyNetworkListChanged(); | 650 NotifyNetworkListChanged(); |
565 } | 651 } |
566 | 652 |
| 653 void NetworkStateHandler::EnsureTetherDeviceState() { |
| 654 bool should_be_present = |
| 655 tether_technology_state_ != TechnologyState::TECHNOLOGY_UNAVAILABLE; |
| 656 |
| 657 for (auto it = device_list_.begin(); it < device_list_.end(); ++it) { |
| 658 std::string path = (*it)->path(); |
| 659 if (path == kTetherDevicePath) { |
| 660 // If the Tether DeviceState is in the list and it should not be, remove |
| 661 // it and return. If it is in the list and it should be, the list is |
| 662 // already valid, so return without removing it. |
| 663 if (!should_be_present) |
| 664 device_list_.erase(it); |
| 665 return; |
| 666 } |
| 667 } |
| 668 |
| 669 if (!should_be_present) { |
| 670 // If the Tether DeviceState was not in the list and it should not be, the |
| 671 // list is already valid, so return. |
| 672 return; |
| 673 } |
| 674 |
| 675 // The Tether DeviceState is not present in the list, but it should be. Since |
| 676 // Tether networks are not recognized by Shill, they will never receive an |
| 677 // update, so set properties on the state here. |
| 678 std::unique_ptr<ManagedState> tether_device_state = ManagedState::Create( |
| 679 ManagedState::ManagedType::MANAGED_TYPE_DEVICE, kTetherDevicePath); |
| 680 tether_device_state->set_update_received(); |
| 681 tether_device_state->set_update_requested(false); |
| 682 tether_device_state->set_name(kTetherDeviceName); |
| 683 tether_device_state->set_type(kTypeTether); |
| 684 |
| 685 device_list_.push_back(std::move(tether_device_state)); |
| 686 } |
| 687 |
567 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { | 688 void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const { |
568 GetDeviceListByType(NetworkTypePattern::Default(), list); | 689 GetDeviceListByType(NetworkTypePattern::Default(), list); |
569 } | 690 } |
570 | 691 |
571 void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type, | 692 void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type, |
572 DeviceStateList* list) const { | 693 DeviceStateList* list) const { |
573 DCHECK(list); | 694 DCHECK(list); |
574 list->clear(); | 695 list->clear(); |
| 696 |
575 for (auto iter = device_list_.begin(); iter != device_list_.end(); ++iter) { | 697 for (auto iter = device_list_.begin(); iter != device_list_.end(); ++iter) { |
576 const DeviceState* device = (*iter)->AsDeviceState(); | 698 const DeviceState* device = (*iter)->AsDeviceState(); |
577 DCHECK(device); | 699 DCHECK(device); |
578 if (device->update_received() && device->Matches(type)) | 700 if (device->update_received() && device->Matches(type)) |
579 list->push_back(device); | 701 list->push_back(device); |
580 } | 702 } |
581 } | 703 } |
582 | 704 |
583 void NetworkStateHandler::RequestScan() const { | 705 void NetworkStateHandler::RequestScan() const { |
584 NET_LOG_USER("RequestScan", ""); | 706 NET_LOG_USER("RequestScan", ""); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 continue; | 841 continue; |
720 } | 842 } |
721 managed_list->push_back(ManagedState::Create(type, path)); | 843 managed_list->push_back(ManagedState::Create(type, path)); |
722 } else { | 844 } else { |
723 managed_list->push_back(std::move(found->second)); | 845 managed_list->push_back(std::move(found->second)); |
724 managed_map.erase(found); | 846 managed_map.erase(found); |
725 } | 847 } |
726 list_entries.insert(path); | 848 list_entries.insert(path); |
727 } | 849 } |
728 | 850 |
| 851 if (type == ManagedState::ManagedType::MANAGED_TYPE_DEVICE) { |
| 852 // Also move the Tether DeviceState if it exists. This will not happen as |
| 853 // part of the loop above since |entries| will never contain the Tether |
| 854 // path. |
| 855 auto iter = managed_map.find(kTetherDevicePath); |
| 856 if (iter != managed_map.end()) { |
| 857 managed_list->push_back(std::move(iter->second)); |
| 858 managed_map.erase(iter); |
| 859 } |
| 860 } |
| 861 |
729 if (type != ManagedState::ManagedType::MANAGED_TYPE_NETWORK) | 862 if (type != ManagedState::ManagedType::MANAGED_TYPE_NETWORK) |
730 return; | 863 return; |
731 | 864 |
732 // Remove associations Tether NetworkStates had with now removed Wi-Fi | 865 // Remove associations Tether NetworkStates had with now removed Wi-Fi |
733 // NetworkStates. | 866 // NetworkStates. |
734 for (auto& iter : managed_map) { | 867 for (auto& iter : managed_map) { |
735 if (!iter.second->Matches(NetworkTypePattern::WiFi())) | 868 if (!iter.second->Matches(NetworkTypePattern::WiFi())) |
736 continue; | 869 continue; |
737 | 870 |
738 NetworkState* tether_network = GetModifiableNetworkStateFromGuid( | 871 NetworkState* tether_network = GetModifiableNetworkStateFromGuid( |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 devices += ", "; | 1097 devices += ", "; |
965 devices += (*iter)->name(); | 1098 devices += (*iter)->name(); |
966 } | 1099 } |
967 NET_LOG_EVENT("DeviceList", devices); | 1100 NET_LOG_EVENT("DeviceList", devices); |
968 NotifyDeviceListChanged(); | 1101 NotifyDeviceListChanged(); |
969 } else { | 1102 } else { |
970 NOTREACHED(); | 1103 NOTREACHED(); |
971 } | 1104 } |
972 } | 1105 } |
973 | 1106 |
974 // TODO(khorimoto): Add sorting for the tether network list as well. | 1107 // TODO(khorimoto): Add sorting for the Tether network list as well. |
975 void NetworkStateHandler::SortNetworkList() { | 1108 void NetworkStateHandler::SortNetworkList() { |
976 // Note: usually active networks will precede inactive networks, however | 1109 // Note: usually active networks will precede inactive networks, however |
977 // this may briefly be untrue during state transitions (e.g. a network may | 1110 // this may briefly be untrue during state transitions (e.g. a network may |
978 // transition to idle before the list is updated). | 1111 // transition to idle before the list is updated). |
979 ManagedStateList active, non_wifi_visible, wifi_visible, hidden, new_networks; | 1112 ManagedStateList active, non_wifi_visible, wifi_visible, hidden, new_networks; |
980 for (ManagedStateList::iterator iter = network_list_.begin(); | 1113 for (ManagedStateList::iterator iter = network_list_.begin(); |
981 iter != network_list_.end(); ++iter) { | 1114 iter != network_list_.end(); ++iter) { |
982 NetworkState* network = (*iter)->AsNetworkState(); | 1115 NetworkState* network = (*iter)->AsNetworkState(); |
983 if (!network->update_received()) { | 1116 if (!network->update_received()) { |
984 new_networks.push_back(std::move(*iter)); | 1117 new_networks.push_back(std::move(*iter)); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 if (type.MatchesType(shill::kTypeWifi)) | 1401 if (type.MatchesType(shill::kTypeWifi)) |
1269 technologies.emplace_back(shill::kTypeWifi); | 1402 technologies.emplace_back(shill::kTypeWifi); |
1270 if (type.MatchesType(shill::kTypeWimax)) | 1403 if (type.MatchesType(shill::kTypeWimax)) |
1271 technologies.emplace_back(shill::kTypeWimax); | 1404 technologies.emplace_back(shill::kTypeWimax); |
1272 if (type.MatchesType(shill::kTypeCellular)) | 1405 if (type.MatchesType(shill::kTypeCellular)) |
1273 technologies.emplace_back(shill::kTypeCellular); | 1406 technologies.emplace_back(shill::kTypeCellular); |
1274 if (type.MatchesType(shill::kTypeBluetooth)) | 1407 if (type.MatchesType(shill::kTypeBluetooth)) |
1275 technologies.emplace_back(shill::kTypeBluetooth); | 1408 technologies.emplace_back(shill::kTypeBluetooth); |
1276 if (type.MatchesType(shill::kTypeVPN)) | 1409 if (type.MatchesType(shill::kTypeVPN)) |
1277 technologies.emplace_back(shill::kTypeVPN); | 1410 technologies.emplace_back(shill::kTypeVPN); |
| 1411 if (type.MatchesType(kTypeTether)) |
| 1412 technologies.emplace_back(kTypeTether); |
1278 | 1413 |
1279 CHECK_GT(technologies.size(), 0ul); | 1414 CHECK_GT(technologies.size(), 0ul); |
1280 return technologies; | 1415 return technologies; |
1281 } | 1416 } |
1282 | 1417 |
1283 } // namespace chromeos | 1418 } // namespace chromeos |
OLD | NEW |