Commit b592eaee authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Use network_config.mojo in NetworkStateListDetailedView

This includes mojo support for:
* ip address
* mac address
* RequestScan()

Bug: 862420
Change-Id: I7070ec82f898ca01f94de72ecfbe608f5e803ff1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1627894Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664481}
parent 652f0ba0
...@@ -12,15 +12,14 @@ ...@@ -12,15 +12,14 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/model/system_tray_model.h" #include "ash/system/model/system_tray_model.h"
#include "ash/system/network/tray_network_state_model.h"
#include "ash/system/tray/system_menu_button.h" #include "ash/system/tray/system_menu_button.h"
#include "ash/system/tray/tri_view.h" #include "ash/system/tray/tri_view.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chromeos/network/device_state.h"
#include "chromeos/network/network_connect.h" #include "chromeos/network/network_connect.h"
#include "chromeos/network/network_state.h" #include "net/base/ip_address.h"
#include "chromeos/network/network_state_handler.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h" #include "ui/views/bubble/bubble_dialog_delegate_view.h"
...@@ -30,11 +29,12 @@ ...@@ -30,11 +29,12 @@
#include "ui/views/layout/layout_manager.h" #include "ui/views/layout/layout_manager.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
using chromeos::DeviceState; using chromeos::network_config::mojom::ConnectionStateType;
using chromeos::NetworkHandler; using chromeos::network_config::mojom::DeviceStateProperties;
using chromeos::NetworkState; using chromeos::network_config::mojom::DeviceStateType;
using chromeos::NetworkStateHandler; using chromeos::network_config::mojom::NetworkStateProperties;
using chromeos::NetworkTypePattern; using chromeos::network_config::mojom::NetworkStatePropertiesPtr;
using chromeos::network_config::mojom::NetworkType;
namespace ash { namespace ash {
namespace tray { namespace tray {
...@@ -60,9 +60,22 @@ bool IsSecondaryUser() { ...@@ -60,9 +60,22 @@ bool IsSecondaryUser() {
!session_controller->IsUserPrimary(); !session_controller->IsUserPrimary();
} }
bool IsWifiEnabled() { bool NetworkTypeIsConfigurable(NetworkType type) {
return NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled( switch (type) {
chromeos::NetworkTypePattern::WiFi()); case NetworkType::kVPN:
case NetworkType::kWiFi:
case NetworkType::kWiMAX:
return true;
case NetworkType::kAll:
case NetworkType::kCellular:
case NetworkType::kEthernet:
case NetworkType::kMobile:
case NetworkType::kTether:
case NetworkType::kWireless:
return false;
}
NOTREACHED();
return false;
} }
} // namespace } // namespace
...@@ -183,6 +196,7 @@ NetworkStateListDetailedView::NetworkStateListDetailedView( ...@@ -183,6 +196,7 @@ NetworkStateListDetailedView::NetworkStateListDetailedView(
: TrayDetailedView(delegate), : TrayDetailedView(delegate),
list_type_(list_type), list_type_(list_type),
login_(login), login_(login),
model_(Shell::Get()->system_tray_model()->network_state_model()),
info_button_(nullptr), info_button_(nullptr),
settings_button_(nullptr), settings_button_(nullptr),
info_bubble_(nullptr) {} info_bubble_(nullptr) {}
...@@ -239,32 +253,38 @@ void NetworkStateListDetailedView::HandleViewClicked(views::View* view) { ...@@ -239,32 +253,38 @@ void NetworkStateListDetailedView::HandleViewClicked(views::View* view) {
if (!IsNetworkEntry(view, &guid)) if (!IsNetworkEntry(view, &guid))
return; return;
const NetworkState* network = model_->cros_network_config()->GetNetworkState(
NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( guid, base::BindOnce(&NetworkStateListDetailedView::HandleViewClickedImpl,
guid); weak_ptr_factory_.GetWeakPtr()));
bool can_connect = network && !network->IsConnectingOrConnected(); }
void NetworkStateListDetailedView::HandleViewClickedImpl(
NetworkStatePropertiesPtr network) {
if (network) { if (network) {
if (network->IsDefaultCellular()) // Attempt a network connection if the network is not connected and:
can_connect = false; // Default Cellular network is not connectable. // * The network is connectable or
if (!network->connectable() && IsSecondaryUser()) { // * The active user is primary and the network is configurable
// Secondary users can only connect to fully configured networks. bool can_connect =
can_connect = false; network->connection_state == ConnectionStateType::kNotConnected &&
(network->connectable ||
(!IsSecondaryUser() && NetworkTypeIsConfigurable(network->type)));
if (can_connect) {
Shell::Get()->metrics()->RecordUserMetricsAction(
list_type_ == LIST_TYPE_VPN
? UMA_STATUS_AREA_CONNECT_TO_VPN
: UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK);
chromeos::NetworkConnect::Get()->ConnectToNetworkId(network->guid);
return;
} }
} }
if (can_connect) { // If the network is no longer available or not connectable or configurable,
Shell::Get()->metrics()->RecordUserMetricsAction( // show the Settings UI.
list_type_ == LIST_TYPE_VPN
? UMA_STATUS_AREA_CONNECT_TO_VPN
: UMA_STATUS_AREA_CONNECT_TO_CONFIGURED_NETWORK);
chromeos::NetworkConnect::Get()->ConnectToNetworkId(network->guid());
return;
}
Shell::Get()->metrics()->RecordUserMetricsAction( Shell::Get()->metrics()->RecordUserMetricsAction(
list_type_ == LIST_TYPE_VPN list_type_ == LIST_TYPE_VPN
? UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS ? UMA_STATUS_AREA_SHOW_VPN_CONNECTION_DETAILS
: UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS); : UMA_STATUS_AREA_SHOW_NETWORK_CONNECTION_DETAILS);
Shell::Get()->system_tray_model()->client()->ShowNetworkSettings( Shell::Get()->system_tray_model()->client()->ShowNetworkSettings(
network ? network->guid() : std::string()); network ? network->guid : std::string());
} }
void NetworkStateListDetailedView::CreateExtraTitleRowButtons() { void NetworkStateListDetailedView::CreateExtraTitleRowButtons() {
...@@ -296,8 +316,7 @@ void NetworkStateListDetailedView::UpdateHeaderButtons() { ...@@ -296,8 +316,7 @@ void NetworkStateListDetailedView::UpdateHeaderButtons() {
if (login_ == LoginStatus::NOT_LOGGED_IN) { if (login_ == LoginStatus::NOT_LOGGED_IN) {
// When not logged in, only enable the settings button if there is a // When not logged in, only enable the settings button if there is a
// default (i.e. connected or connecting) network to show settings for. // default (i.e. connected or connecting) network to show settings for.
settings_button_->SetEnabled( settings_button_->SetEnabled(model_->default_network());
!!NetworkHandler::Get()->network_state_handler()->DefaultNetwork());
} else { } else {
// Otherwise, enable if showing settings is allowed. There are situations // Otherwise, enable if showing settings is allowed. There are situations
// (supervised user creation flow) when the session is started but UI flow // (supervised user creation flow) when the session is started but UI flow
...@@ -319,11 +338,14 @@ void NetworkStateListDetailedView::UpdateScanningBar() { ...@@ -319,11 +338,14 @@ void NetworkStateListDetailedView::UpdateScanningBar() {
if (!is_wifi_enabled && network_scan_repeating_timer_.IsRunning()) if (!is_wifi_enabled && network_scan_repeating_timer_.IsRunning())
network_scan_repeating_timer_.Stop(); network_scan_repeating_timer_.Stop();
const bool scanning_bar_visible = bool scanning_bar_visible = false;
is_wifi_enabled && if (is_wifi_enabled) {
NetworkHandler::Get()->network_state_handler()->GetScanningByType( const DeviceStateProperties* wifi = model_->GetDevice(NetworkType::kWiFi);
NetworkTypePattern::WiFi() | NetworkTypePattern::Tether()); const DeviceStateProperties* tether =
model_->GetDevice(NetworkType::kTether);
scanning_bar_visible =
(wifi && wifi->scanning) || (tether && tether->scanning);
}
ShowProgress(-1, scanning_bar_visible); ShowProgress(-1, scanning_bar_visible);
} }
...@@ -353,23 +375,28 @@ void NetworkStateListDetailedView::OnInfoBubbleDestroyed() { ...@@ -353,23 +375,28 @@ void NetworkStateListDetailedView::OnInfoBubbleDestroyed() {
} }
views::View* NetworkStateListDetailedView::CreateNetworkInfoView() { views::View* NetworkStateListDetailedView::CreateNetworkInfoView() {
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); std::string ipv4_address, ipv6_address;
const NetworkStateProperties* network = model_->default_network();
std::string ip_address, ipv6_address; const DeviceStateProperties* device =
const NetworkState* network = handler->DefaultNetwork(); network ? model_->GetDevice(network->type) : nullptr;
if (network) { if (device) {
ip_address = network->GetIpAddress(); net::IPAddress ipv4(device->ipv4_address.data(),
const DeviceState* device = handler->GetDeviceState(network->device_path()); device->ipv4_address.size());
if (device) ipv4_address = ipv4.ToString();
ipv6_address = device->GetIpAddressByType(shill::kTypeIPv6); net::IPAddress ipv6(device->ipv6_address.data(),
device->ipv6_address.size());
ipv6_address = ipv6.ToString();
} }
std::string ethernet_address, wifi_address; std::string ethernet_address, wifi_address;
if (list_type_ == LIST_TYPE_NETWORK) { if (list_type_ == LIST_TYPE_NETWORK) {
ethernet_address = handler->FormattedHardwareAddressForType( const DeviceStateProperties* ethernet =
NetworkTypePattern::Ethernet()); model_->GetDevice(NetworkType::kEthernet);
wifi_address = if (ethernet)
handler->FormattedHardwareAddressForType(NetworkTypePattern::WiFi()); ethernet_address = ethernet->mac_address;
const DeviceStateProperties* wifi = model_->GetDevice(NetworkType::kWiFi);
if (wifi)
wifi_address = wifi->mac_address;
} }
base::string16 bubble_text; base::string16 bubble_text;
...@@ -383,7 +410,7 @@ views::View* NetworkStateListDetailedView::CreateNetworkInfoView() { ...@@ -383,7 +410,7 @@ views::View* NetworkStateListDetailedView::CreateNetworkInfoView() {
} }
}; };
add_line(ip_address, IDS_ASH_STATUS_TRAY_IP_ADDRESS); add_line(ipv4_address, IDS_ASH_STATUS_TRAY_IP_ADDRESS);
add_line(ipv6_address, IDS_ASH_STATUS_TRAY_IPV6_ADDRESS); add_line(ipv6_address, IDS_ASH_STATUS_TRAY_IPV6_ADDRESS);
add_line(ethernet_address, IDS_ASH_STATUS_TRAY_ETHERNET_ADDRESS); add_line(ethernet_address, IDS_ASH_STATUS_TRAY_ETHERNET_ADDRESS);
add_line(wifi_address, IDS_ASH_STATUS_TRAY_WIFI_ADDRESS); add_line(wifi_address, IDS_ASH_STATUS_TRAY_WIFI_ADDRESS);
...@@ -412,8 +439,13 @@ void NetworkStateListDetailedView::CallRequestScan() { ...@@ -412,8 +439,13 @@ void NetworkStateListDetailedView::CallRequestScan() {
return; return;
VLOG(1) << "Requesting Network Scan."; VLOG(1) << "Requesting Network Scan.";
NetworkHandler::Get()->network_state_handler()->RequestScan( model_->cros_network_config()->RequestNetworkScan(NetworkType::kWiFi);
NetworkTypePattern::WiFi() | NetworkTypePattern::Tether()); model_->cros_network_config()->RequestNetworkScan(NetworkType::kTether);
}
bool NetworkStateListDetailedView::IsWifiEnabled() {
return model_->GetDeviceState(NetworkType::kWiFi) ==
DeviceStateType::kEnabled;
} }
} // namespace tray } // namespace tray
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h"
namespace views { namespace views {
class Button; class Button;
...@@ -19,12 +20,12 @@ class Button; ...@@ -19,12 +20,12 @@ class Button;
namespace ash { namespace ash {
class TrayNetworkStateModel;
namespace tray { namespace tray {
// Exported for tests. // Exported for tests.
class ASH_EXPORT NetworkStateListDetailedView class ASH_EXPORT NetworkStateListDetailedView : public TrayDetailedView {
: public TrayDetailedView,
public base::SupportsWeakPtr<NetworkStateListDetailedView> {
public: public:
~NetworkStateListDetailedView() override; ~NetworkStateListDetailedView() override;
...@@ -63,6 +64,10 @@ class ASH_EXPORT NetworkStateListDetailedView ...@@ -63,6 +64,10 @@ class ASH_EXPORT NetworkStateListDetailedView
const ui::Event& event) override; const ui::Event& event) override;
void CreateExtraTitleRowButtons() override; void CreateExtraTitleRowButtons() override;
// Implementation of 'HandleViewClicked' once networks are received.
void HandleViewClickedImpl(
chromeos::network_config::mojom::NetworkStatePropertiesPtr network);
// Launches the WebUI settings in a browser and closes the system menu. // Launches the WebUI settings in a browser and closes the system menu.
void ShowSettings(); void ShowSettings();
...@@ -84,12 +89,16 @@ class ASH_EXPORT NetworkStateListDetailedView ...@@ -84,12 +89,16 @@ class ASH_EXPORT NetworkStateListDetailedView
// Request a network scan. // Request a network scan.
void CallRequestScan(); void CallRequestScan();
bool IsWifiEnabled();
// Type of list (all networks or vpn) // Type of list (all networks or vpn)
ListType list_type_; ListType list_type_;
// Track login state. // Track login state.
LoginStatus login_; LoginStatus login_;
TrayNetworkStateModel* model_;
views::Button* info_button_; views::Button* info_button_;
views::Button* settings_button_; views::Button* settings_button_;
...@@ -99,6 +108,8 @@ class ASH_EXPORT NetworkStateListDetailedView ...@@ -99,6 +108,8 @@ class ASH_EXPORT NetworkStateListDetailedView
// Timer for starting and stopping network scans. // Timer for starting and stopping network scans.
base::RepeatingTimer network_scan_repeating_timer_; base::RepeatingTimer network_scan_repeating_timer_;
base::WeakPtrFactory<NetworkStateListDetailedView> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(NetworkStateListDetailedView); DISALLOW_COPY_AND_ASSIGN(NetworkStateListDetailedView);
}; };
......
...@@ -231,9 +231,7 @@ const char kRoamingRequired[] = "required"; ...@@ -231,9 +231,7 @@ const char kRoamingRequired[] = "required";
const char FakeShillManagerClient::kFakeEthernetNetworkGuid[] = "eth1_guid"; const char FakeShillManagerClient::kFakeEthernetNetworkGuid[] = "eth1_guid";
FakeShillManagerClient::FakeShillManagerClient() FakeShillManagerClient::FakeShillManagerClient()
: interactive_delay_(0), : cellular_technology_(shill::kNetworkTechnologyGsm) {
cellular_technology_(shill::kNetworkTechnologyGsm),
weak_ptr_factory_(this) {
ParseCommandLineSwitch(); ParseCommandLineSwitch();
} }
...@@ -298,7 +296,7 @@ void FakeShillManagerClient::RequestScan(const std::string& type, ...@@ -298,7 +296,7 @@ void FakeShillManagerClient::RequestScan(const std::string& type,
FROM_HERE, FROM_HERE,
base::BindOnce(&FakeShillManagerClient::ScanCompleted, base::BindOnce(&FakeShillManagerClient::ScanCompleted,
weak_ptr_factory_.GetWeakPtr(), device_path), weak_ptr_factory_.GetWeakPtr(), device_path),
base::TimeDelta::FromSeconds(interactive_delay_)); interactive_delay_);
} }
void FakeShillManagerClient::EnableTechnology( void FakeShillManagerClient::EnableTechnology(
...@@ -318,7 +316,7 @@ void FakeShillManagerClient::EnableTechnology( ...@@ -318,7 +316,7 @@ void FakeShillManagerClient::EnableTechnology(
FROM_HERE, FROM_HERE,
base::BindOnce(&FakeShillManagerClient::SetTechnologyEnabled, base::BindOnce(&FakeShillManagerClient::SetTechnologyEnabled,
weak_ptr_factory_.GetWeakPtr(), type, callback, true), weak_ptr_factory_.GetWeakPtr(), type, callback, true),
base::TimeDelta::FromSeconds(interactive_delay_)); interactive_delay_);
} }
void FakeShillManagerClient::DisableTechnology( void FakeShillManagerClient::DisableTechnology(
...@@ -337,7 +335,7 @@ void FakeShillManagerClient::DisableTechnology( ...@@ -337,7 +335,7 @@ void FakeShillManagerClient::DisableTechnology(
FROM_HERE, FROM_HERE,
base::BindOnce(&FakeShillManagerClient::SetTechnologyEnabled, base::BindOnce(&FakeShillManagerClient::SetTechnologyEnabled,
weak_ptr_factory_.GetWeakPtr(), type, callback, false), weak_ptr_factory_.GetWeakPtr(), type, callback, false),
base::TimeDelta::FromSeconds(interactive_delay_)); interactive_delay_);
} }
void FakeShillManagerClient::ConfigureService( void FakeShillManagerClient::ConfigureService(
...@@ -637,10 +635,14 @@ void FakeShillManagerClient::SortManagerServices(bool notify) { ...@@ -637,10 +635,14 @@ void FakeShillManagerClient::SortManagerServices(bool notify) {
} }
} }
int FakeShillManagerClient::GetInteractiveDelay() const { base::TimeDelta FakeShillManagerClient::GetInteractiveDelay() const {
return interactive_delay_; return interactive_delay_;
} }
void FakeShillManagerClient::SetInteractiveDelay(base::TimeDelta delay) {
interactive_delay_ = delay;
}
void FakeShillManagerClient::SetBestServiceToConnect( void FakeShillManagerClient::SetBestServiceToConnect(
const std::string& service_path) { const std::string& service_path) {
best_service_ = service_path; best_service_ = service_path;
...@@ -1143,7 +1145,7 @@ bool FakeShillManagerClient::ParseOption(const std::string& arg0, ...@@ -1143,7 +1145,7 @@ bool FakeShillManagerClient::ParseOption(const std::string& arg0,
int seconds = 3; int seconds = 3;
if (!arg1.empty()) if (!arg1.empty())
base::StringToInt(arg1, &seconds); base::StringToInt(arg1, &seconds);
interactive_delay_ = seconds; interactive_delay_ = base::TimeDelta::FromSeconds(seconds);
return true; return true;
} else if (arg0 == "sim_lock") { } else if (arg0 == "sim_lock") {
bool locked = (arg1 == "1"); bool locked = (arg1 == "1");
......
...@@ -88,7 +88,8 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillManagerClient ...@@ -88,7 +88,8 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillManagerClient
const std::string& state) override; const std::string& state) override;
void SortManagerServices(bool notify) override; void SortManagerServices(bool notify) override;
void SetupDefaultEnvironment() override; void SetupDefaultEnvironment() override;
int GetInteractiveDelay() const override; base::TimeDelta GetInteractiveDelay() const override;
void SetInteractiveDelay(base::TimeDelta delay) override;
void SetBestServiceToConnect(const std::string& service_path) override; void SetBestServiceToConnect(const std::string& service_path) override;
const NetworkThrottlingStatus& GetNetworkThrottlingStatus() override; const NetworkThrottlingStatus& GetNetworkThrottlingStatus() override;
bool GetFastTransitionStatus() override; bool GetFastTransitionStatus() override;
...@@ -127,8 +128,8 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillManagerClient ...@@ -127,8 +128,8 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillManagerClient
// Dictionary of technology -> list of property dictionaries // Dictionary of technology -> list of property dictionaries
base::DictionaryValue stub_geo_networks_; base::DictionaryValue stub_geo_networks_;
// Seconds to delay interactive actions // Delay for interactive actions
int interactive_delay_; base::TimeDelta interactive_delay_;
// Initial state for fake services. // Initial state for fake services.
std::map<std::string, std::string> shill_initial_state_map_; std::map<std::string, std::string> shill_initial_state_map_;
...@@ -159,7 +160,7 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillManagerClient ...@@ -159,7 +160,7 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillManagerClient
// Note: This should remain the last member so it'll be destroyed and // Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed. // invalidate its weak pointers before any other members are destroyed.
base::WeakPtrFactory<FakeShillManagerClient> weak_ptr_factory_; base::WeakPtrFactory<FakeShillManagerClient> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(FakeShillManagerClient); DISALLOW_COPY_AND_ASSIGN(FakeShillManagerClient);
}; };
......
...@@ -40,7 +40,7 @@ void CallSortManagerServices() { ...@@ -40,7 +40,7 @@ void CallSortManagerServices() {
ShillManagerClient::Get()->GetTestInterface()->SortManagerServices(true); ShillManagerClient::Get()->GetTestInterface()->SortManagerServices(true);
} }
int GetInteractiveDelay() { base::TimeDelta GetInteractiveDelay() {
return ShillManagerClient::Get()->GetTestInterface()->GetInteractiveDelay(); return ShillManagerClient::Get()->GetTestInterface()->GetInteractiveDelay();
} }
...@@ -187,7 +187,7 @@ void FakeShillServiceClient::Connect(const dbus::ObjectPath& service_path, ...@@ -187,7 +187,7 @@ void FakeShillServiceClient::Connect(const dbus::ObjectPath& service_path,
FROM_HERE, FROM_HERE,
base::BindOnce(&FakeShillServiceClient::ContinueConnect, base::BindOnce(&FakeShillServiceClient::ContinueConnect,
weak_ptr_factory_.GetWeakPtr(), service_path.value()), weak_ptr_factory_.GetWeakPtr(), service_path.value()),
base::TimeDelta::FromSeconds(GetInteractiveDelay())); GetInteractiveDelay());
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
} }
...@@ -207,7 +207,7 @@ void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path, ...@@ -207,7 +207,7 @@ void FakeShillServiceClient::Disconnect(const dbus::ObjectPath& service_path,
weak_ptr_factory_.GetWeakPtr(), service_path, weak_ptr_factory_.GetWeakPtr(), service_path,
shill::kStateProperty, base::Value(shill::kStateIdle), shill::kStateProperty, base::Value(shill::kStateIdle),
base::DoNothing(), error_callback), base::DoNothing(), error_callback),
base::TimeDelta::FromSeconds(GetInteractiveDelay())); GetInteractiveDelay());
callback.Run(); callback.Run();
} }
...@@ -236,7 +236,7 @@ void FakeShillServiceClient::ActivateCellularModem( ...@@ -236,7 +236,7 @@ void FakeShillServiceClient::ActivateCellularModem(
base::BindOnce(&FakeShillServiceClient::SetCellularActivated, base::BindOnce(&FakeShillServiceClient::SetCellularActivated,
weak_ptr_factory_.GetWeakPtr(), service_path, weak_ptr_factory_.GetWeakPtr(), service_path,
error_callback), error_callback),
base::TimeDelta::FromSeconds(GetInteractiveDelay())); GetInteractiveDelay());
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/component_export.h" #include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h"
#include "chromeos/dbus/dbus_method_call_status.h" #include "chromeos/dbus/dbus_method_call_status.h"
#include "chromeos/dbus/shill/shill_client_helper.h" #include "chromeos/dbus/shill/shill_client_helper.h"
...@@ -91,8 +92,11 @@ class COMPONENT_EXPORT(SHILL_CLIENT) ShillManagerClient { ...@@ -91,8 +92,11 @@ class COMPONENT_EXPORT(SHILL_CLIENT) ShillManagerClient {
// or states provided by the command line. // or states provided by the command line.
virtual void SetupDefaultEnvironment() = 0; virtual void SetupDefaultEnvironment() = 0;
// Returns the interactive delay specified on the command line, 0 for none. // Returns the interactive delay (specified by the command line or a test).
virtual int GetInteractiveDelay() const = 0; virtual base::TimeDelta GetInteractiveDelay() const = 0;
// Sets the interactive delay for testing.
virtual void SetInteractiveDelay(base::TimeDelta delay) = 0;
// Sets the 'best' service to connect to on a ConnectToBestServices call. // Sets the 'best' service to connect to on a ConnectToBestServices call.
virtual void SetBestServiceToConnect(const std::string& service_path) = 0; virtual void SetBestServiceToConnect(const std::string& service_path) = 0;
......
...@@ -72,8 +72,17 @@ void NetworkStateTestHelper::ResetDevicesAndServices() { ...@@ -72,8 +72,17 @@ void NetworkStateTestHelper::ResetDevicesAndServices() {
// A Wifi device should always exist and default to enabled. // A Wifi device should always exist and default to enabled.
manager_test_->AddTechnology(shill::kTypeWifi, true /* enabled */); manager_test_->AddTechnology(shill::kTypeWifi, true /* enabled */);
device_test_->AddDevice("/device/wifi1", shill::kTypeWifi, "wifi_device1"); const char* kDevicePath = "/device/wifi1";
device_test_->AddDevice(kDevicePath, shill::kTypeWifi, "wifi_device1");
// Set initial IPConfigs for the wifi device. The IPConfigs are set up in
// FakeShillManagerClient::SetupDefaultEnvironment() and do not get cleared.
base::ListValue ip_configs;
ip_configs.AppendString("ipconfig_v4_path");
ip_configs.AppendString("ipconfig_v6_path");
device_test_->SetDeviceProperty(kDevicePath, shill::kIPConfigsProperty,
ip_configs,
/*notify_changed=*/false);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
......
...@@ -20,6 +20,7 @@ static_library("network_config") { ...@@ -20,6 +20,7 @@ static_library("network_config") {
"//components/device_event_log", "//components/device_event_log",
"//components/onc", "//components/onc",
"//components/proxy_config", "//components/proxy_config",
"//net",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
] ]
} }
......
...@@ -9,11 +9,13 @@ ...@@ -9,11 +9,13 @@
#include "chromeos/network/network_state.h" #include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_type_pattern.h" #include "chromeos/network/network_type_pattern.h"
#include "chromeos/network/network_util.h"
#include "chromeos/network/onc/onc_translation_tables.h" #include "chromeos/network/onc/onc_translation_tables.h"
#include "chromeos/network/proxy/ui_proxy_config_service.h" #include "chromeos/network/proxy/ui_proxy_config_service.h"
#include "chromeos/services/network_config/public/cpp/cros_network_config_util.h" #include "chromeos/services/network_config/public/cpp/cros_network_config_util.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config_mojom_traits.h" #include "chromeos/services/network_config/public/mojom/cros_network_config_mojom_traits.h"
#include "components/device_event_log/device_event_log.h" #include "components/device_event_log/device_event_log.h"
#include "net/base/ip_address.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
namespace chromeos { namespace chromeos {
...@@ -244,6 +246,18 @@ mojom::DeviceStatePropertiesPtr DeviceStateToMojo( ...@@ -244,6 +246,18 @@ mojom::DeviceStatePropertiesPtr DeviceStateToMojo(
auto result = mojom::DeviceStateProperties::New(); auto result = mojom::DeviceStateProperties::New();
result->type = type; result->type = type;
net::IPAddress ipv4_address;
if (ipv4_address.AssignFromIPLiteral(
device->GetIpAddressByType(shill::kTypeIPv4))) {
result->ipv4_address = ipv4_address.CopyBytesToVector();
}
net::IPAddress ipv6_address;
if (ipv6_address.AssignFromIPLiteral(
device->GetIpAddressByType(shill::kTypeIPv6))) {
result->ipv6_address = ipv6_address.CopyBytesToVector();
}
result->mac_address =
network_util::FormattedMacAddress(device->mac_address());
result->scanning = device->scanning(); result->scanning = device->scanning();
result->state = technology_state; result->state = technology_state;
result->managed_network_available = result->managed_network_available =
...@@ -398,6 +412,10 @@ void CrosNetworkConfig::SetNetworkTypeEnabledState( ...@@ -398,6 +412,10 @@ void CrosNetworkConfig::SetNetworkTypeEnabledState(
std::move(callback).Run(true); std::move(callback).Run(true);
} }
void CrosNetworkConfig::RequestNetworkScan(mojom::NetworkType type) {
network_state_handler_->RequestScan(MojoTypeToPattern(type));
}
// NetworkStateHandlerObserver // NetworkStateHandlerObserver
void CrosNetworkConfig::NetworkListChanged() { void CrosNetworkConfig::NetworkListChanged() {
observers_.ForAllPtrs([](mojom::CrosNetworkConfigObserver* observer) { observers_.ForAllPtrs([](mojom::CrosNetworkConfigObserver* observer) {
...@@ -429,8 +447,7 @@ void CrosNetworkConfig::ActiveNetworksChanged( ...@@ -429,8 +447,7 @@ void CrosNetworkConfig::ActiveNetworksChanged(
}); });
} }
void CrosNetworkConfig::ScanCompleted(const DeviceState* device) { void CrosNetworkConfig::DevicePropertiesUpdated(const DeviceState* device) {
// Scanning state of device may have updated.
DeviceListChanged(); DeviceListChanged();
} }
......
...@@ -35,13 +35,14 @@ class CrosNetworkConfig : public mojom::CrosNetworkConfig, ...@@ -35,13 +35,14 @@ class CrosNetworkConfig : public mojom::CrosNetworkConfig,
mojom::NetworkType type, mojom::NetworkType type,
bool enabled, bool enabled,
SetNetworkTypeEnabledStateCallback callback) override; SetNetworkTypeEnabledStateCallback callback) override;
void RequestNetworkScan(mojom::NetworkType type) override;
// NetworkStateHandlerObserver // NetworkStateHandlerObserver
void NetworkListChanged() override; void NetworkListChanged() override;
void DeviceListChanged() override; void DeviceListChanged() override;
void ActiveNetworksChanged( void ActiveNetworksChanged(
const std::vector<const NetworkState*>& active_networks) override; const std::vector<const NetworkState*>& active_networks) override;
void ScanCompleted(const DeviceState* device) override; void DevicePropertiesUpdated(const DeviceState* device) override;
void OnShuttingDown() override; void OnShuttingDown() override;
private: private:
......
...@@ -225,6 +225,15 @@ TEST_F(CrosNetworkConfigTest, GetDeviceStateList) { ...@@ -225,6 +225,15 @@ TEST_F(CrosNetworkConfigTest, GetDeviceStateList) {
EXPECT_EQ(mojom::NetworkType::kWiFi, devices[0]->type); EXPECT_EQ(mojom::NetworkType::kWiFi, devices[0]->type);
EXPECT_EQ(mojom::DeviceStateType::kEnabled, devices[0]->state); EXPECT_EQ(mojom::DeviceStateType::kEnabled, devices[0]->state);
// IP address match those set up in FakeShillManagerClient::
// SetupDefaultEnvironment(). TODO(stevenjb): Support setting
// expectations explicitly in NetworkStateTestHelper.
std::vector<uint8_t> ipv4_expected{100, 0, 0, 1};
EXPECT_EQ(ipv4_expected, devices[0]->ipv4_address);
std::vector<uint8_t> ipv6_expected{0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 1};
EXPECT_EQ(ipv6_expected, devices[0]->ipv6_address);
EXPECT_EQ(mojom::NetworkType::kEthernet, devices[1]->type); EXPECT_EQ(mojom::NetworkType::kEthernet, devices[1]->type);
EXPECT_EQ(mojom::DeviceStateType::kEnabled, devices[1]->state); EXPECT_EQ(mojom::DeviceStateType::kEnabled, devices[1]->state);
...@@ -275,6 +284,38 @@ TEST_F(CrosNetworkConfigTest, SetNetworkTypeEnabledState) { ...@@ -275,6 +284,38 @@ TEST_F(CrosNetworkConfigTest, SetNetworkTypeEnabledState) {
})); }));
} }
TEST_F(CrosNetworkConfigTest, RequestNetworkScan) {
class ScanningObserver : public CrosNetworkConfigTestObserver {
public:
explicit ScanningObserver(CrosNetworkConfig* cros_network_config)
: cros_network_config_(cros_network_config) {}
void OnDeviceStateListChanged() override {
cros_network_config_->GetDeviceStateList(base::BindOnce(
[](bool* wifi_scanning,
std::vector<mojom::DeviceStatePropertiesPtr> devices) {
for (auto& device : devices) {
if (device->type == mojom::NetworkType::kWiFi)
*wifi_scanning = device->scanning;
}
},
&wifi_scanning_));
}
CrosNetworkConfig* cros_network_config_;
bool wifi_scanning_ = false;
};
ScanningObserver observer(cros_network_config());
cros_network_config()->AddObserver(observer.GenerateInterfacePtr());
base::RunLoop().RunUntilIdle();
// Set a short delay so that the scan does not complete before the
// CrosNetworkConfig observer method gets fired.
helper().manager_test()->SetInteractiveDelay(
base::TimeDelta::FromMilliseconds(1));
cros_network_config()->RequestNetworkScan(mojom::NetworkType::kWiFi);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(observer.wifi_scanning_);
}
TEST_F(CrosNetworkConfigTest, NetworkListChanged) { TEST_F(CrosNetworkConfigTest, NetworkListChanged) {
SetupObserver(); SetupObserver();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
...@@ -216,6 +216,14 @@ struct NetworkStateProperties { ...@@ -216,6 +216,14 @@ struct NetworkStateProperties {
}; };
struct DeviceStateProperties { struct DeviceStateProperties {
// IP address for the primary network corresponding to the device type. If no
// network is in a connected state, or the address type is not available,
// these will be empty. When there are multiple IP addresses, only the first
// is provided.
array<uint8> ipv4_address;
array<uint8> ipv6_address;
// AA:BB formatted MAC address for the device. Use for display purposes only.
string mac_address;
// Set if the device is currently scanning. // Set if the device is currently scanning.
bool scanning = false; bool scanning = false;
// The SIM lock status if Type = Cellular and a SIM is present. // The SIM lock status if Type = Cellular and a SIM is present.
...@@ -260,6 +268,10 @@ interface CrosNetworkConfig { ...@@ -260,6 +268,10 @@ interface CrosNetworkConfig {
// CrosNetworkConfigObserver::OnDeviceStateListChanged() can be used to be // CrosNetworkConfigObserver::OnDeviceStateListChanged() can be used to be
// notified when the enabled state changes. // notified when the enabled state changes.
SetNetworkTypeEnabledState(NetworkType type, bool enabled) => (bool success); SetNetworkTypeEnabledState(NetworkType type, bool enabled) => (bool success);
// Requests a scan for new networks. If the list updates,
// CrosNetworkConfigObserver::OnNetworkStateListChanged() will be signaled.
RequestNetworkScan(NetworkType type);
}; };
interface CrosNetworkConfigObserver { interface CrosNetworkConfigObserver {
......
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