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

Use mojo API in NetworkSectionHeaderView

This also converts NetworkListView and VPNListView to use
TrayNetworkStateModel.

Bug: 862420
Change-Id: I54efc6823a59331c3d011f7af40d1fb05d27a20c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626256
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663094}
parent daad88b5
...@@ -12,11 +12,13 @@ ...@@ -12,11 +12,13 @@
#include "ash/session/session_controller_impl.h" #include "ash/session/session_controller_impl.h"
#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/network/network_icon.h" #include "ash/system/network/network_icon.h"
#include "ash/system/network/network_icon_animation.h" #include "ash/system/network/network_icon_animation.h"
#include "ash/system/network/network_info.h" #include "ash/system/network/network_info.h"
#include "ash/system/network/network_section_header_view.h" #include "ash/system/network/network_section_header_view.h"
#include "ash/system/network/network_state_list_detailed_view.h" #include "ash/system/network/network_state_list_detailed_view.h"
#include "ash/system/network/tray_network_state_model.h"
#include "ash/system/power/power_status.h" #include "ash/system/power/power_status.h"
#include "ash/system/tray/hover_highlight_view.h" #include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/tray_info_label.h" #include "ash/system/tray/tray_info_label.h"
...@@ -73,9 +75,8 @@ bool IsSecondaryUser() { ...@@ -73,9 +75,8 @@ bool IsSecondaryUser() {
NetworkListView::NetworkListView(DetailedViewDelegate* delegate, NetworkListView::NetworkListView(DetailedViewDelegate* delegate,
LoginStatus login) LoginStatus login)
: NetworkStateListDetailedView(delegate, LIST_TYPE_NETWORK, login) { : NetworkStateListDetailedView(delegate, LIST_TYPE_NETWORK, login),
BindCrosNetworkConfig(); model_(Shell::Get()->system_tray_model()->network_state_model()) {}
}
NetworkListView::~NetworkListView() { NetworkListView::~NetworkListView() {
network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
...@@ -83,9 +84,11 @@ NetworkListView::~NetworkListView() { ...@@ -83,9 +84,11 @@ NetworkListView::~NetworkListView() {
void NetworkListView::UpdateNetworkList() { void NetworkListView::UpdateNetworkList() {
CHECK(scroll_content()); CHECK(scroll_content());
DCHECK(cros_network_config_ptr_); model_->cros_network_config()->GetNetworkStateList(
cros_network_config_ptr_->GetDeviceStateList(base::BindOnce( NetworkFilter::New(FilterType::kVisible, NetworkType::kAll,
&NetworkListView::OnGetDeviceStateList, base::Unretained(this))); chromeos::network_config::mojom::kNoLimit),
base::BindOnce(&NetworkListView::OnGetNetworkStateList,
weak_ptr_factory_.GetWeakPtr()));
} }
bool NetworkListView::IsNetworkEntry(views::View* view, bool NetworkListView::IsNetworkEntry(views::View* view,
...@@ -102,34 +105,6 @@ const char* NetworkListView::GetClassName() const { ...@@ -102,34 +105,6 @@ const char* NetworkListView::GetClassName() const {
return "NetworkListView"; return "NetworkListView";
} }
void NetworkListView::BindCrosNetworkConfig() {
// Ensure binding is reset in case this is called after a failure.
cros_network_config_ptr_.reset();
service_manager::Connector* connector = Shell::Get()->connector();
if (!connector)
return;
connector->BindInterface(chromeos::network_config::mojom::kServiceName,
&cros_network_config_ptr_);
// If the connection is lost (e.g. due to a crash), attempt to rebind it.
cros_network_config_ptr_.set_connection_error_handler(base::BindOnce(
&NetworkListView::BindCrosNetworkConfig, base::Unretained(this)));
}
void NetworkListView::OnGetDeviceStateList(
std::vector<DeviceStatePropertiesPtr> devices) {
device_states_.clear();
for (auto& device : devices)
device_states_[device->type] = device->state;
cros_network_config_ptr_->GetNetworkStateList(
NetworkFilter::New(FilterType::kVisible, NetworkType::kAll,
chromeos::network_config::mojom::kNoLimit),
base::BindOnce(&NetworkListView::OnGetNetworkStateList,
base::Unretained(this)));
}
void NetworkListView::OnGetNetworkStateList( void NetworkListView::OnGetNetworkStateList(
std::vector<NetworkStatePropertiesPtr> networks) { std::vector<NetworkStatePropertiesPtr> networks) {
// |network_list_| contains all the info and is going to be cleared and // |network_list_| contains all the info and is going to be cleared and
...@@ -142,6 +117,8 @@ void NetworkListView::OnGetNetworkStateList( ...@@ -142,6 +117,8 @@ void NetworkListView::OnGetNetworkStateList(
network_list_.clear(); network_list_.clear();
vpn_connected_ = false; vpn_connected_ = false;
wifi_has_networks_ = false; wifi_has_networks_ = false;
mobile_has_networks_ = false;
tether_has_networks_ = false;
for (auto& network : networks) { for (auto& network : networks) {
ConnectionStateType connection_state = network->connection_state; ConnectionStateType connection_state = network->connection_state;
if (network->type == NetworkType::kVPN) { if (network->type == NetworkType::kVPN) {
...@@ -154,12 +131,20 @@ void NetworkListView::OnGetNetworkStateList( ...@@ -154,12 +131,20 @@ void NetworkListView::OnGetNetworkStateList(
network->cellular ? network->cellular->activation_state network->cellular ? network->cellular->activation_state
: ActivationStateType::kUnknown; : ActivationStateType::kUnknown;
if (network->type == NetworkType::kCellular && if (network->type == NetworkType::kCellular &&
GetDeviceState(NetworkType::kCellular) != DeviceStateType::kEnabled && model_->GetDeviceState(NetworkType::kCellular) !=
DeviceStateType::kEnabled &&
activation_state == ActivationStateType::kNoService) { activation_state == ActivationStateType::kNoService) {
continue; continue;
} }
if (network->type == NetworkType::kWiFi) if (network->type == NetworkType::kWiFi)
wifi_has_networks_ = true; wifi_has_networks_ = true;
// Real (non 'default') Cellular networks are always connectable.
if (network->type == NetworkType::kCellular && network->connectable)
mobile_has_networks_ = true;
if (network->type == NetworkType::kTether) {
mobile_has_networks_ = true;
tether_has_networks_ = true;
}
auto info = std::make_unique<NetworkInfo>(network->guid); auto info = std::make_unique<NetworkInfo>(network->guid);
info->label = network_icon::GetLabelForNetworkList(network.get()); info->label = network_icon::GetLabelForNetworkList(network.get());
...@@ -271,7 +256,8 @@ NetworkListView::UpdateNetworkListEntries() { ...@@ -271,7 +256,8 @@ NetworkListView::UpdateNetworkListEntries() {
std::unique_ptr<std::set<std::string>> new_cellular_guids = std::unique_ptr<std::set<std::string>> new_cellular_guids =
UpdateNetworkChildren(NetworkType::kMobile, index); UpdateNetworkChildren(NetworkType::kMobile, index);
int mobile_status_message = int mobile_status_message =
mobile_header_view_->UpdateToggleAndGetStatusMessage(); mobile_header_view_->UpdateToggleAndGetStatusMessage(
mobile_has_networks_, tether_has_networks_);
// |mobile_status_message| may be zero. Passing zero to UpdateInfoLabel // |mobile_status_message| may be zero. Passing zero to UpdateInfoLabel
// clears the label. // clears the label.
UpdateInfoLabel(mobile_status_message, index, &mobile_status_message_); UpdateInfoLabel(mobile_status_message, index, &mobile_status_message_);
...@@ -285,7 +271,7 @@ NetworkListView::UpdateNetworkListEntries() { ...@@ -285,7 +271,7 @@ NetworkListView::UpdateNetworkListEntries() {
wifi_header_view_ = new WifiSectionHeaderView(); wifi_header_view_ = new WifiSectionHeaderView();
bool wifi_enabled = bool wifi_enabled =
GetDeviceState(NetworkType::kWiFi) == DeviceStateType::kEnabled; model_->GetDeviceState(NetworkType::kWiFi) == DeviceStateType::kEnabled;
index = UpdateNetworkSectionHeader(NetworkType::kWiFi, wifi_enabled, index, index = UpdateNetworkSectionHeader(NetworkType::kWiFi, wifi_enabled, index,
wifi_header_view_, &wifi_separator_view_); wifi_header_view_, &wifi_separator_view_);
...@@ -323,10 +309,12 @@ NetworkListView::UpdateNetworkListEntries() { ...@@ -323,10 +309,12 @@ NetworkListView::UpdateNetworkListEntries() {
bool NetworkListView::ShouldMobileDataSectionBeShown() { bool NetworkListView::ShouldMobileDataSectionBeShown() {
// The section should always be shown if Cellular networks are available. // The section should always be shown if Cellular networks are available.
if (GetDeviceState(NetworkType::kCellular) != DeviceStateType::kUnavailable) if (model_->GetDeviceState(NetworkType::kCellular) !=
DeviceStateType::kUnavailable) {
return true; return true;
}
DeviceStateType tether_state = GetDeviceState(NetworkType::kTether); DeviceStateType tether_state = model_->GetDeviceState(NetworkType::kTether);
// Hide the section if both Cellular and Tether are UNAVAILABLE. // Hide the section if both Cellular and Tether are UNAVAILABLE.
if (tether_state == DeviceStateType::kUnavailable) if (tether_state == DeviceStateType::kUnavailable)
return false; return false;
...@@ -568,12 +556,5 @@ TriView* NetworkListView::CreateConnectionWarning() { ...@@ -568,12 +556,5 @@ TriView* NetworkListView::CreateConnectionWarning() {
return connection_warning; return connection_warning;
} }
DeviceStateType NetworkListView::GetDeviceState(NetworkType type) const {
auto iter = device_states_.find(type);
if (iter == device_states_.end())
return DeviceStateType::kUnavailable;
return iter->second;
}
} // namespace tray } // namespace tray
} // namespace ash } // namespace ash
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
#include "ash/system/network/network_state_list_detailed_view.h" #include "ash/system/network/network_state_list_detailed_view.h"
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/macros.h" #include "base/macros.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" #include "base/memory/weak_ptr.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h"
namespace views { namespace views {
class Separator; class Separator;
...@@ -27,6 +28,7 @@ namespace ash { ...@@ -27,6 +28,7 @@ namespace ash {
class HoverHighlightView; class HoverHighlightView;
class TrayInfoLabel; class TrayInfoLabel;
class TriView; class TriView;
class TrayNetworkStateModel;
namespace tray { namespace tray {
class NetworkSectionHeaderView; class NetworkSectionHeaderView;
...@@ -49,10 +51,6 @@ class NetworkListView : public NetworkStateListDetailedView, ...@@ -49,10 +51,6 @@ class NetworkListView : public NetworkStateListDetailedView,
const char* GetClassName() const override; const char* GetClassName() const override;
private: private:
void BindCrosNetworkConfig();
void OnGetDeviceStateList(
std::vector<chromeos::network_config::mojom::DeviceStatePropertiesPtr>
devices);
void OnGetNetworkStateList( void OnGetNetworkStateList(
std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr> std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>
networks); networks);
...@@ -131,8 +129,7 @@ class NetworkListView : public NetworkStateListDetailedView, ...@@ -131,8 +129,7 @@ class NetworkListView : public NetworkStateListDetailedView,
// otherwise false. // otherwise false.
bool NeedUpdateViewForNetwork(const NetworkInfo& info) const; bool NeedUpdateViewForNetwork(const NetworkInfo& info) const;
chromeos::network_config::mojom::DeviceStateType GetDeviceState( TrayNetworkStateModel* model_;
chromeos::network_config::mojom::NetworkType type) const;
bool needs_relayout_ = false; bool needs_relayout_ = false;
...@@ -145,14 +142,10 @@ class NetworkListView : public NetworkStateListDetailedView, ...@@ -145,14 +142,10 @@ class NetworkListView : public NetworkStateListDetailedView,
views::Separator* wifi_separator_view_ = nullptr; views::Separator* wifi_separator_view_ = nullptr;
TriView* connection_warning_ = nullptr; TriView* connection_warning_ = nullptr;
chromeos::network_config::mojom::CrosNetworkConfigPtr
cros_network_config_ptr_;
base::flat_map<chromeos::network_config::mojom::NetworkType,
chromeos::network_config::mojom::DeviceStateType>
device_states_;
bool vpn_connected_ = false; bool vpn_connected_ = false;
bool wifi_has_networks_ = false; bool wifi_has_networks_ = false;
bool tether_has_networks_ = false;
bool mobile_has_networks_ = false;
// An owned list of network info. // An owned list of network info.
std::vector<std::unique_ptr<NetworkInfo>> network_list_; std::vector<std::unique_ptr<NetworkInfo>> network_list_;
...@@ -168,6 +161,8 @@ class NetworkListView : public NetworkStateListDetailedView, ...@@ -168,6 +161,8 @@ class NetworkListView : public NetworkStateListDetailedView,
using NetworkInfoMap = std::map<std::string, std::unique_ptr<NetworkInfo>>; using NetworkInfoMap = std::map<std::string, std::unique_ptr<NetworkInfo>>;
NetworkInfoMap last_network_info_map_; NetworkInfoMap last_network_info_map_;
base::WeakPtrFactory<NetworkListView> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(NetworkListView); DISALLOW_COPY_AND_ASSIGN(NetworkListView);
}; };
......
...@@ -12,16 +12,21 @@ ...@@ -12,16 +12,21 @@
#include "ash/system/bluetooth/bluetooth_power_controller.h" #include "ash/system/bluetooth/bluetooth_power_controller.h"
#include "ash/system/model/system_tray_model.h" #include "ash/system/model/system_tray_model.h"
#include "ash/system/network/network_icon.h" #include "ash/system/network/network_icon.h"
#include "ash/system/network/tray_network_state_model.h"
#include "ash/system/unified/top_shortcut_button.h" #include "ash/system/unified/top_shortcut_button.h"
#include "base/bind.h" #include "base/bind.h"
#include "chromeos/network/device_state.h"
#include "chromeos/strings/grit/chromeos_strings.h" #include "chromeos/strings/grit/chromeos_strings.h"
#include "components/onc/onc_constants.h"
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
using chromeos::NetworkHandler; using chromeos::network_config::mojom::DeviceStateProperties;
using chromeos::NetworkStateHandler; using chromeos::network_config::mojom::DeviceStateType;
using chromeos::NetworkTypePattern; using chromeos::network_config::mojom::FilterType;
using chromeos::network_config::mojom::NetworkFilter;
using chromeos::network_config::mojom::NetworkStateProperties;
using chromeos::network_config::mojom::NetworkStatePropertiesPtr;
using chromeos::network_config::mojom::NetworkType;
namespace ash { namespace ash {
namespace tray { namespace tray {
...@@ -43,18 +48,28 @@ constexpr int kDisabledJoinIconAlpha = 0x1D; ...@@ -43,18 +48,28 @@ constexpr int kDisabledJoinIconAlpha = 0x1D;
const int64_t kBluetoothTimeoutDelaySeconds = 2; const int64_t kBluetoothTimeoutDelaySeconds = 2;
bool IsCellularSimLocked() { bool IsCellularSimLocked() {
const chromeos::DeviceState* cellular_device = const DeviceStateProperties* cellular_device =
NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType( Shell::Get()->system_tray_model()->network_state_model()->GetDevice(
NetworkTypePattern::Cellular()); NetworkType::kCellular);
return cellular_device && cellular_device->IsSimLocked(); return cellular_device &&
!cellular_device->sim_lock_status->lock_type.empty();
} }
void ShowCellularSettings() { void ShowCellularSettings() {
const chromeos::NetworkState* cellular_network = Shell::Get()
NetworkHandler::Get()->network_state_handler()->FirstNetworkByType( ->system_tray_model()
NetworkTypePattern::Cellular()); ->network_state_model()
->cros_network_config()
->GetNetworkStateList(
NetworkFilter::New(FilterType::kVisible, NetworkType::kCellular,
/*limit=*/1),
base::BindOnce([](std::vector<NetworkStatePropertiesPtr> networks) {
std::string guid;
if (networks.size() > 0)
guid = networks[0]->guid;
Shell::Get()->system_tray_model()->client()->ShowNetworkSettings( Shell::Get()->system_tray_model()->client()->ShowNetworkSettings(
cellular_network ? cellular_network->guid() : std::string()); guid);
}));
} }
bool IsSecondaryUser() { bool IsSecondaryUser() {
...@@ -67,7 +82,8 @@ bool IsSecondaryUser() { ...@@ -67,7 +82,8 @@ bool IsSecondaryUser() {
} // namespace } // namespace
NetworkSectionHeaderView::NetworkSectionHeaderView(int title_id) NetworkSectionHeaderView::NetworkSectionHeaderView(int title_id)
: title_id_(title_id) {} : title_id_(title_id),
model_(Shell::Get()->system_tray_model()->network_state_model()) {}
void NetworkSectionHeaderView::Init(bool enabled) { void NetworkSectionHeaderView::Init(bool enabled) {
InitializeLayout(); InitializeLayout();
...@@ -136,67 +152,62 @@ const char* MobileSectionHeaderView::GetClassName() const { ...@@ -136,67 +152,62 @@ const char* MobileSectionHeaderView::GetClassName() const {
return "MobileSectionHeaderView"; return "MobileSectionHeaderView";
} }
int MobileSectionHeaderView::UpdateToggleAndGetStatusMessage() { int MobileSectionHeaderView::UpdateToggleAndGetStatusMessage(
NetworkStateHandler* network_state_handler = bool mobile_has_networks,
NetworkHandler::Get()->network_state_handler(); bool tether_has_networks) {
NetworkStateHandler::TechnologyState cellular_state = DeviceStateType cellular_state =
network_state_handler->GetTechnologyState(NetworkTypePattern::Cellular()); model()->GetDeviceState(NetworkType::kCellular);
NetworkStateHandler::TechnologyState tether_state = DeviceStateType tether_state = model()->GetDeviceState(NetworkType::kTether);
network_state_handler->GetTechnologyState(NetworkTypePattern::Tether());
bool default_toggle_enabled = !IsSecondaryUser(); bool default_toggle_enabled = !IsSecondaryUser();
// If Cellular is available, toggle state and status message reflect Cellular. // If Cellular is available, toggle state and status message reflect Cellular.
if (cellular_state != NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) { if (cellular_state != DeviceStateType::kUnavailable) {
const chromeos::DeviceState* cellular_device = if (cellular_state == DeviceStateType::kUninitialized) {
network_state_handler->GetDeviceStateByType(
NetworkTypePattern::Cellular());
bool cellular_enabled =
cellular_state == NetworkStateHandler::TECHNOLOGY_ENABLED;
if (!cellular_device->IsSimAbsent()) {
SetToggleVisibility(true);
SetToggleState(default_toggle_enabled, cellular_enabled);
} else {
SetToggleVisibility(false); SetToggleVisibility(false);
}
if (!cellular_device ||
cellular_state == NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) {
return IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR; return IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR;
} }
if (cellular_device->scanning())
return IDS_ASH_STATUS_TRAY_MOBILE_SCANNING;
if (cellular_device->IsSimAbsent()) const DeviceStateProperties* cellular_device =
model()->GetDevice(NetworkType::kCellular);
if (cellular_device->sim_absent) {
SetToggleVisibility(false);
return IDS_ASH_STATUS_TRAY_SIM_CARD_MISSING; return IDS_ASH_STATUS_TRAY_SIM_CARD_MISSING;
}
bool cellular_enabled = cellular_state == DeviceStateType::kEnabled;
SetToggleVisibility(true);
SetToggleState(default_toggle_enabled, cellular_enabled);
if (cellular_device->IsSimLocked()) if (cellular_device->sim_lock_status &&
!cellular_device->sim_lock_status->lock_type.empty()) {
return IDS_ASH_STATUS_TRAY_SIM_CARD_LOCKED; return IDS_ASH_STATUS_TRAY_SIM_CARD_LOCKED;
}
if (cellular_device->scanning)
return IDS_ASH_STATUS_TRAY_MOBILE_SCANNING;
const chromeos::NetworkState* mobile_network = if (cellular_enabled && !mobile_has_networks) {
network_state_handler->FirstNetworkByType(NetworkTypePattern::Mobile()); // If no connectable Mobile network is available, show 'turn on
if (cellular_enabled &&
(!mobile_network || mobile_network->IsDefaultCellular())) {
// If no connectable Cellular network is available (see
// network_state_handler.h re: IsDefaultCellular), show 'turn on
// Bluetooth' if Tether is available but not initialized, otherwise // Bluetooth' if Tether is available but not initialized, otherwise
// show 'no networks'. // show 'no networks'.
if (tether_state == NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) if (tether_state == DeviceStateType::kUninitialized)
return IDS_ENABLE_BLUETOOTH; return IDS_ENABLE_BLUETOOTH;
return IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; return IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS;
} }
return 0; return 0;
} }
// When Cellular is not available, always show the toggle.
SetToggleVisibility(true);
// Tether is also unavailable (edge case). // Tether is also unavailable (edge case).
if (tether_state == NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) { if (tether_state == DeviceStateType::kUnavailable) {
SetToggleState(false /* toggle_enabled */, false /* is_on */); SetToggleState(false /* toggle_enabled */, false /* is_on */);
return IDS_ASH_STATUS_TRAY_NETWORK_MOBILE_DISABLED; return IDS_ASH_STATUS_TRAY_NETWORK_MOBILE_DISABLED;
} }
// Otherwise, toggle state and status message reflect Tether. // Otherwise, toggle state and status message reflect Tether.
if (tether_state == NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) { if (tether_state == DeviceStateType::kUninitialized) {
if (waiting_for_tether_initialize_) { if (waiting_for_tether_initialize_) {
SetToggleState(false /* toggle_enabled */, true /* is_on */); SetToggleState(false /* toggle_enabled */, true /* is_on */);
// "Initializing...". TODO(stevenjb): Rename the string to _MOBILE. // "Initializing...". TODO(stevenjb): Rename the string to _MOBILE.
...@@ -207,7 +218,7 @@ int MobileSectionHeaderView::UpdateToggleAndGetStatusMessage() { ...@@ -207,7 +218,7 @@ int MobileSectionHeaderView::UpdateToggleAndGetStatusMessage() {
} }
} }
bool tether_enabled = tether_state == NetworkStateHandler::TECHNOLOGY_ENABLED; bool tether_enabled = tether_state == DeviceStateType::kEnabled;
if (waiting_for_tether_initialize_) { if (waiting_for_tether_initialize_) {
waiting_for_tether_initialize_ = false; waiting_for_tether_initialize_ = false;
...@@ -215,9 +226,7 @@ int MobileSectionHeaderView::UpdateToggleAndGetStatusMessage() { ...@@ -215,9 +226,7 @@ int MobileSectionHeaderView::UpdateToggleAndGetStatusMessage() {
if (!tether_enabled) { if (!tether_enabled) {
// We enabled Bluetooth so Tether is now initialized, but it was not // We enabled Bluetooth so Tether is now initialized, but it was not
// enabled so enable it. // enabled so enable it.
network_state_handler->SetTechnologyEnabled( model()->SetNetworkTypeEnabledState(NetworkType::kTether, true);
NetworkTypePattern::Tether(), true /* enabled */,
chromeos::network_handler::ErrorCallback());
SetToggleState(default_toggle_enabled, true /* is_on */); SetToggleState(default_toggle_enabled, true /* is_on */);
// "Initializing...". TODO(stevenjb): Rename the string to _MOBILE. // "Initializing...". TODO(stevenjb): Rename the string to _MOBILE.
return IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR; return IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR;
...@@ -226,53 +235,44 @@ int MobileSectionHeaderView::UpdateToggleAndGetStatusMessage() { ...@@ -226,53 +235,44 @@ int MobileSectionHeaderView::UpdateToggleAndGetStatusMessage() {
// Ensure that the toggle state and status message match the tether state. // Ensure that the toggle state and status message match the tether state.
SetToggleState(default_toggle_enabled, tether_enabled /* is_on */); SetToggleState(default_toggle_enabled, tether_enabled /* is_on */);
if (tether_enabled && !network_state_handler->FirstNetworkByType( if (tether_enabled && !tether_has_networks)
NetworkTypePattern::Tether())) {
return IDS_ASH_STATUS_TRAY_NO_MOBILE_DEVICES_FOUND; return IDS_ASH_STATUS_TRAY_NO_MOBILE_DEVICES_FOUND;
}
return 0; return 0;
} }
void MobileSectionHeaderView::OnToggleToggled(bool is_on) { void MobileSectionHeaderView::OnToggleToggled(bool is_on) {
NetworkStateHandler* network_state_handler = DeviceStateType cellular_state =
NetworkHandler::Get()->network_state_handler(); model()->GetDeviceState(NetworkType::kCellular);
NetworkStateHandler::TechnologyState cellular_state =
network_state_handler->GetTechnologyState(NetworkTypePattern::Cellular());
// When Cellular is available, the toggle controls Cellular enabled state. // When Cellular is available, the toggle controls Cellular enabled state.
// (Tether may be enabled by turning on Bluetooth and turning on // (Tether may be enabled by turning on Bluetooth and turning on
// 'Get data connection' in the Settings > Mobile data subpage). // 'Get data connection' in the Settings > Mobile data subpage).
if (cellular_state != NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) { if (cellular_state != DeviceStateType::kUnavailable) {
if (is_on && IsCellularSimLocked()) { if (is_on && IsCellularSimLocked()) {
ShowCellularSettings(); ShowCellularSettings();
return; return;
} }
network_state_handler->SetTechnologyEnabled( model()->SetNetworkTypeEnabledState(NetworkType::kCellular, is_on);
NetworkTypePattern::Cellular(), is_on,
chromeos::network_handler::ErrorCallback());
return; return;
} }
NetworkStateHandler::TechnologyState tether_state = DeviceStateType tether_state = model()->GetDeviceState(NetworkType::kTether);
network_state_handler->GetTechnologyState(NetworkTypePattern::Tether());
// Tether is also unavailable (edge case). // Tether is also unavailable (edge case).
if (tether_state == NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) if (tether_state == DeviceStateType::kUnavailable)
return; return;
// If Tether is available but uninitialized, we expect Bluetooth to be off. // If Tether is available but uninitialized, we expect Bluetooth to be off.
// Enable Bluetooth so that Tether will be initialized. Ignore edge cases // Enable Bluetooth so that Tether will be initialized. Ignore edge cases
// (e.g. Bluetooth was disabled from a different UI). // (e.g. Bluetooth was disabled from a different UI).
if (tether_state == NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) { if (tether_state == DeviceStateType::kUninitialized) {
if (is_on && !waiting_for_tether_initialize_) if (is_on && !waiting_for_tether_initialize_)
EnableBluetooth(); EnableBluetooth();
return; return;
} }
// Otherwise the toggle controls the Tether enabled state. // Otherwise the toggle controls the Tether enabled state.
network_state_handler->SetTechnologyEnabled( model()->SetNetworkTypeEnabledState(NetworkType::kTether, is_on);
NetworkTypePattern::Tether(), is_on,
chromeos::network_handler::ErrorCallback());
} }
void MobileSectionHeaderView::EnableBluetooth() { void MobileSectionHeaderView::EnableBluetooth() {
...@@ -299,8 +299,7 @@ void MobileSectionHeaderView::OnEnableBluetoothTimeout() { ...@@ -299,8 +299,7 @@ void MobileSectionHeaderView::OnEnableBluetoothTimeout() {
WifiSectionHeaderView::WifiSectionHeaderView() WifiSectionHeaderView::WifiSectionHeaderView()
: NetworkSectionHeaderView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI) { : NetworkSectionHeaderView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI) {
bool enabled = bool enabled =
NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled( model()->GetDeviceState(NetworkType::kWiFi) == DeviceStateType::kEnabled;
NetworkTypePattern::WiFi());
NetworkSectionHeaderView::Init(enabled); NetworkSectionHeaderView::Init(enabled);
} }
...@@ -308,14 +307,15 @@ void WifiSectionHeaderView::SetToggleState(bool toggle_enabled, bool is_on) { ...@@ -308,14 +307,15 @@ void WifiSectionHeaderView::SetToggleState(bool toggle_enabled, bool is_on) {
join_button_->SetEnabled(toggle_enabled && is_on); join_button_->SetEnabled(toggle_enabled && is_on);
NetworkSectionHeaderView::SetToggleState(toggle_enabled, is_on); NetworkSectionHeaderView::SetToggleState(toggle_enabled, is_on);
} }
const char* WifiSectionHeaderView::GetClassName() const { const char* WifiSectionHeaderView::GetClassName() const {
return "WifiSectionHeaderView"; return "WifiSectionHeaderView";
} }
void WifiSectionHeaderView::OnToggleToggled(bool is_on) { void WifiSectionHeaderView::OnToggleToggled(bool is_on) {
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); model()->SetNetworkTypeEnabledState(NetworkType::kWiFi, is_on);
handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), is_on,
chromeos::network_handler::ErrorCallback());
} }
void WifiSectionHeaderView::AddExtraButtons(bool enabled) { void WifiSectionHeaderView::AddExtraButtons(bool enabled) {
const SkColor prominent_color = GetNativeTheme()->GetSystemColor( const SkColor prominent_color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_ProminentButtonColor); ui::NativeTheme::kColorId_ProminentButtonColor);
......
...@@ -10,12 +10,14 @@ ...@@ -10,12 +10,14 @@
#include "ash/system/tray/tri_view.h" #include "ash/system/tray/tri_view.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/network/network_state_handler.h"
#include "ui/views/controls/button/toggle_button.h" #include "ui/views/controls/button/toggle_button.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace ash { namespace ash {
class TrayNetworkStateModel;
namespace tray { namespace tray {
// A header row for sections in network detailed view which contains a title and // A header row for sections in network detailed view which contains a title and
...@@ -48,6 +50,7 @@ class NetworkSectionHeaderView : public views::View, ...@@ -48,6 +50,7 @@ class NetworkSectionHeaderView : public views::View,
// enabled/disable their respective technology, for example. // enabled/disable their respective technology, for example.
virtual void OnToggleToggled(bool is_on) = 0; virtual void OnToggleToggled(bool is_on) = 0;
TrayNetworkStateModel* model() { return model_; }
TriView* container() const { return container_; } TriView* container() const { return container_; }
// views::View: // views::View:
...@@ -64,6 +67,8 @@ class NetworkSectionHeaderView : public views::View, ...@@ -64,6 +67,8 @@ class NetworkSectionHeaderView : public views::View,
// accessible text on the section header toggle button. // accessible text on the section header toggle button.
const int title_id_; const int title_id_;
TrayNetworkStateModel* model_;
// View containing header row views, including title, toggle, and extra // View containing header row views, including title, toggle, and extra
// buttons. // buttons.
TriView* container_ = nullptr; TriView* container_ = nullptr;
...@@ -89,7 +94,8 @@ class MobileSectionHeaderView : public NetworkSectionHeaderView { ...@@ -89,7 +94,8 @@ class MobileSectionHeaderView : public NetworkSectionHeaderView {
// Updates mobile toggle state and returns the id of the status message // Updates mobile toggle state and returns the id of the status message
// that should be shown while connecting to a network. Returns zero when no // that should be shown while connecting to a network. Returns zero when no
// message should be shown. // message should be shown.
int UpdateToggleAndGetStatusMessage(); int UpdateToggleAndGetStatusMessage(bool mobile_has_networks,
bool tether_has_networks);
// views::View: // views::View:
const char* GetClassName() const override; const char* GetClassName() const override;
......
...@@ -55,6 +55,10 @@ class ASH_EXPORT TrayNetworkStateModel ...@@ -55,6 +55,10 @@ class ASH_EXPORT TrayNetworkStateModel
chromeos::network_config::mojom::NetworkType type, chromeos::network_config::mojom::NetworkType type,
bool enabled); bool enabled);
chromeos::network_config::mojom::CrosNetworkConfig* cros_network_config() {
return cros_network_config_ptr_.get();
}
const chromeos::network_config::mojom::NetworkStateProperties* const chromeos::network_config::mojom::NetworkStateProperties*
default_network() const { default_network() const {
return default_network_.get(); return default_network_.get();
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ash/system/network/network_icon.h" #include "ash/system/network/network_icon.h"
#include "ash/system/network/network_icon_animation.h" #include "ash/system/network/network_icon_animation.h"
#include "ash/system/network/network_icon_animation_observer.h" #include "ash/system/network/network_icon_animation_observer.h"
#include "ash/system/network/tray_network_state_model.h"
#include "ash/system/network/vpn_list.h" #include "ash/system/network/vpn_list.h"
#include "ash/system/tray/hover_highlight_view.h" #include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_menu_button.h" #include "ash/system/tray/system_menu_button.h"
...@@ -191,6 +192,8 @@ class VPNListNetworkEntry : public HoverHighlightView, ...@@ -191,6 +192,8 @@ class VPNListNetworkEntry : public HoverHighlightView,
views::LabelButton* disconnect_button_ = nullptr; views::LabelButton* disconnect_button_ = nullptr;
base::WeakPtrFactory<VPNListNetworkEntry> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry); DISALLOW_COPY_AND_ASSIGN(VPNListNetworkEntry);
}; };
...@@ -205,13 +208,9 @@ VPNListNetworkEntry::~VPNListNetworkEntry() { ...@@ -205,13 +208,9 @@ VPNListNetworkEntry::~VPNListNetworkEntry() {
} }
void VPNListNetworkEntry::NetworkIconChanged() { void VPNListNetworkEntry::NetworkIconChanged() {
chromeos::network_config::mojom::CrosNetworkConfig* cros_network_config = owner_->model()->cros_network_config()->GetNetworkState(
owner_->cros_network_config();
if (!cros_network_config)
return;
cros_network_config->GetNetworkState(
guid_, base::BindOnce(&VPNListNetworkEntry::OnGetNetworkState, guid_, base::BindOnce(&VPNListNetworkEntry::OnGetNetworkState,
base::Unretained(this))); weak_ptr_factory_.GetWeakPtr()));
} }
void VPNListNetworkEntry::ButtonPressed(Button* sender, void VPNListNetworkEntry::ButtonPressed(Button* sender,
...@@ -270,9 +269,9 @@ void VPNListNetworkEntry::UpdateFromNetworkState( ...@@ -270,9 +269,9 @@ void VPNListNetworkEntry::UpdateFromNetworkState(
} // namespace } // namespace
VPNListView::VPNListView(DetailedViewDelegate* delegate, LoginStatus login) VPNListView::VPNListView(DetailedViewDelegate* delegate, LoginStatus login)
: NetworkStateListDetailedView(delegate, LIST_TYPE_VPN, login) { : NetworkStateListDetailedView(delegate, LIST_TYPE_VPN, login),
model_(Shell::Get()->system_tray_model()->network_state_model()) {
Shell::Get()->vpn_list()->AddObserver(this); Shell::Get()->vpn_list()->AddObserver(this);
BindCrosNetworkConfig();
} }
VPNListView::~VPNListView() { VPNListView::~VPNListView() {
...@@ -280,12 +279,11 @@ VPNListView::~VPNListView() { ...@@ -280,12 +279,11 @@ VPNListView::~VPNListView() {
} }
void VPNListView::UpdateNetworkList() { void VPNListView::UpdateNetworkList() {
DCHECK(cros_network_config_ptr_); model_->cros_network_config()->GetNetworkStateList(
cros_network_config_ptr_->GetNetworkStateList(
NetworkFilter::New(FilterType::kVisible, NetworkType::kVPN, NetworkFilter::New(FilterType::kVisible, NetworkType::kVPN,
chromeos::network_config::mojom::kNoLimit), chromeos::network_config::mojom::kNoLimit),
base::BindOnce(&VPNListView::OnGetNetworkStateList, base::BindOnce(&VPNListView::OnGetNetworkStateList,
base::Unretained(this))); weak_ptr_factory_.GetWeakPtr()));
} }
void VPNListView::OnGetNetworkStateList(NetworkStateList networks) { void VPNListView::OnGetNetworkStateList(NetworkStateList networks) {
...@@ -372,21 +370,6 @@ const char* VPNListView::GetClassName() const { ...@@ -372,21 +370,6 @@ const char* VPNListView::GetClassName() const {
return "VPNListView"; return "VPNListView";
} }
void VPNListView::BindCrosNetworkConfig() {
// Ensure binding is reset in case this is called after a failure.
cros_network_config_ptr_.reset();
service_manager::Connector* connector = Shell::Get()->connector();
if (!connector)
return;
connector->BindInterface(chromeos::network_config::mojom::kServiceName,
&cros_network_config_ptr_);
// If the connection is lost (e.g. due to a crash), attempt to rebind it.
cros_network_config_ptr_.set_connection_error_handler(base::BindOnce(
&VPNListView::BindCrosNetworkConfig, base::Unretained(this)));
}
void VPNListView::AddNetwork(const NetworkStateProperties* network) { void VPNListView::AddNetwork(const NetworkStateProperties* network) {
views::View* entry(new VPNListNetworkEntry(this, network)); views::View* entry(new VPNListNetworkEntry(this, network));
scroll_content()->AddChildView(entry); scroll_content()->AddChildView(entry);
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#include "ash/system/network/network_state_list_detailed_view.h" #include "ash/system/network/network_state_list_detailed_view.h"
#include "ash/system/network/vpn_list.h" #include "ash/system/network/vpn_list.h"
#include "base/macros.h" #include "base/macros.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" #include "base/memory/weak_ptr.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom-forward.h"
class PrefRegistrySimple; class PrefRegistrySimple;
...@@ -20,6 +21,9 @@ class View; ...@@ -20,6 +21,9 @@ class View;
} }
namespace ash { namespace ash {
class TrayNetworkStateModel;
namespace tray { namespace tray {
// A list of VPN providers and networks that shows VPN providers and networks in // A list of VPN providers and networks that shows VPN providers and networks in
...@@ -52,9 +56,7 @@ class VPNListView : public NetworkStateListDetailedView, ...@@ -52,9 +56,7 @@ class VPNListView : public NetworkStateListDetailedView,
// VpnList::Observer: // VpnList::Observer:
void OnVPNProvidersChanged() override; void OnVPNProvidersChanged() override;
chromeos::network_config::mojom::CrosNetworkConfig* cros_network_config() { TrayNetworkStateModel* model() { return model_; }
return cros_network_config_ptr_.get();
}
// See Shell::RegisterProfilePrefs(). // See Shell::RegisterProfilePrefs().
static void RegisterProfilePrefs(PrefRegistrySimple* registry); static void RegisterProfilePrefs(PrefRegistrySimple* registry);
...@@ -65,7 +67,6 @@ class VPNListView : public NetworkStateListDetailedView, ...@@ -65,7 +67,6 @@ class VPNListView : public NetworkStateListDetailedView,
private: private:
using NetworkStateList = using NetworkStateList =
std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>; std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>;
void BindCrosNetworkConfig();
void OnGetNetworkStateList(NetworkStateList networks); void OnGetNetworkStateList(NetworkStateList networks);
// Adds a network to the list. // Adds a network to the list.
...@@ -94,8 +95,7 @@ class VPNListView : public NetworkStateListDetailedView, ...@@ -94,8 +95,7 @@ class VPNListView : public NetworkStateListDetailedView,
// Adds all available VPN providers and networks to the list. // Adds all available VPN providers and networks to the list.
void AddProvidersAndNetworks(const NetworkStateList& networks); void AddProvidersAndNetworks(const NetworkStateList& networks);
chromeos::network_config::mojom::CrosNetworkConfigPtr TrayNetworkStateModel* model_;
cros_network_config_ptr_;
// A mapping from each VPN provider's list entry to the provider. // A mapping from each VPN provider's list entry to the provider.
std::map<const views::View* const, VPNProvider> provider_view_map_; std::map<const views::View* const, VPNProvider> provider_view_map_;
...@@ -107,6 +107,8 @@ class VPNListView : public NetworkStateListDetailedView, ...@@ -107,6 +107,8 @@ class VPNListView : public NetworkStateListDetailedView,
// the topmost entry). // the topmost entry).
bool list_empty_ = true; bool list_empty_ = true;
base::WeakPtrFactory<VPNListView> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(VPNListView); DISALLOW_COPY_AND_ASSIGN(VPNListView);
}; };
......
...@@ -118,8 +118,7 @@ mojom::DeviceStateType GetMojoDeviceStateType( ...@@ -118,8 +118,7 @@ mojom::DeviceStateType GetMojoDeviceStateType(
} }
mojom::NetworkStatePropertiesPtr NetworkStateToMojo(const NetworkState* network, mojom::NetworkStatePropertiesPtr NetworkStateToMojo(const NetworkState* network,
bool technology_enabled, bool technology_enabled) {
const DeviceState* device) {
mojom::NetworkType type = ShillTypeToMojo(network->type()); mojom::NetworkType type = ShillTypeToMojo(network->type());
if (type == mojom::NetworkType::kAll) { if (type == mojom::NetworkType::kAll) {
NET_LOG(ERROR) << "Unexpected network type: " << network->type() NET_LOG(ERROR) << "Unexpected network type: " << network->type()
...@@ -161,10 +160,6 @@ mojom::NetworkStatePropertiesPtr NetworkStateToMojo(const NetworkState* network, ...@@ -161,10 +160,6 @@ mojom::NetworkStatePropertiesPtr NetworkStateToMojo(const NetworkState* network,
onc::kNetworkTechnologyTable); onc::kNetworkTechnologyTable);
cellular->roaming = network->IndicateRoaming(); cellular->roaming = network->IndicateRoaming();
cellular->signal_strength = network->signal_strength(); cellular->signal_strength = network->signal_strength();
if (device) {
cellular->scanning = device->scanning();
cellular->sim_absent = device->IsSimAbsent();
}
result->cellular = std::move(cellular); result->cellular = std::move(cellular);
break; break;
} }
...@@ -240,9 +235,8 @@ mojom::DeviceStatePropertiesPtr DeviceStateToMojo( ...@@ -240,9 +235,8 @@ mojom::DeviceStatePropertiesPtr DeviceStateToMojo(
result->state = technology_state; result->state = technology_state;
result->managed_network_available = result->managed_network_available =
!device->available_managed_network_path().empty(); !device->available_managed_network_path().empty();
result->sim_absent = device->IsSimAbsent();
if (device->sim_present()) { if (device->sim_present()) {
result->sim_present = true;
auto sim_lock_status = mojom::SIMLockStatus::New(); auto sim_lock_status = mojom::SIMLockStatus::New();
sim_lock_status->lock_type = device->sim_lock_type(); sim_lock_status->lock_type = device->sim_lock_type();
sim_lock_status->lock_enabled = device->sim_lock_enabled(); sim_lock_status->lock_enabled = device->sim_lock_enabled();
...@@ -422,6 +416,11 @@ void CrosNetworkConfig::ActiveNetworksChanged( ...@@ -422,6 +416,11 @@ void CrosNetworkConfig::ActiveNetworksChanged(
}); });
} }
void CrosNetworkConfig::ScanCompleted(const DeviceState* device) {
// Scanning state of device may have updated.
DeviceListChanged();
}
void CrosNetworkConfig::OnShuttingDown() { void CrosNetworkConfig::OnShuttingDown() {
if (network_state_handler_->HasObserver(this)) if (network_state_handler_->HasObserver(this))
network_state_handler_->RemoveObserver(this, FROM_HERE); network_state_handler_->RemoveObserver(this, FROM_HERE);
...@@ -433,9 +432,7 @@ mojom::NetworkStatePropertiesPtr CrosNetworkConfig::GetMojoNetworkState( ...@@ -433,9 +432,7 @@ mojom::NetworkStatePropertiesPtr CrosNetworkConfig::GetMojoNetworkState(
bool technology_enabled = network->Matches(NetworkTypePattern::VPN()) || bool technology_enabled = network->Matches(NetworkTypePattern::VPN()) ||
network_state_handler_->IsTechnologyEnabled( network_state_handler_->IsTechnologyEnabled(
NetworkTypePattern::Primitive(network->type())); NetworkTypePattern::Primitive(network->type()));
return NetworkStateToMojo( return NetworkStateToMojo(network, technology_enabled);
network, technology_enabled,
network_state_handler_->GetDeviceState(network->device_path()));
} }
} // namespace network_config } // namespace network_config
......
...@@ -41,6 +41,7 @@ class CrosNetworkConfig : public mojom::CrosNetworkConfig, ...@@ -41,6 +41,7 @@ class CrosNetworkConfig : public mojom::CrosNetworkConfig,
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 OnShuttingDown() override; void OnShuttingDown() override;
private: private:
......
...@@ -230,7 +230,7 @@ TEST_F(CrosNetworkConfigTest, GetDeviceStateList) { ...@@ -230,7 +230,7 @@ TEST_F(CrosNetworkConfigTest, GetDeviceStateList) {
mojom::DeviceStateProperties* cellular = devices[2].get(); mojom::DeviceStateProperties* cellular = devices[2].get();
EXPECT_EQ(mojom::NetworkType::kCellular, cellular->type); EXPECT_EQ(mojom::NetworkType::kCellular, cellular->type);
EXPECT_EQ(mojom::DeviceStateType::kEnabled, cellular->state); EXPECT_EQ(mojom::DeviceStateType::kEnabled, cellular->state);
EXPECT_TRUE(cellular->sim_present); EXPECT_FALSE(cellular->sim_absent);
ASSERT_TRUE(cellular->sim_lock_status); ASSERT_TRUE(cellular->sim_lock_status);
EXPECT_TRUE(cellular->sim_lock_status->lock_enabled); EXPECT_TRUE(cellular->sim_lock_status->lock_enabled);
EXPECT_EQ(shill::kSIMLockPin, cellular->sim_lock_status->lock_type); EXPECT_EQ(shill::kSIMLockPin, cellular->sim_lock_status->lock_type);
......
...@@ -110,6 +110,8 @@ struct CaptivePortalProvider { ...@@ -110,6 +110,8 @@ struct CaptivePortalProvider {
// The SIM card lock status for Cellular networks. // The SIM card lock status for Cellular networks.
struct SIMLockStatus { struct SIMLockStatus {
// True when a SIM is required and not present.
bool sim_absent = false;
// The status of SIM lock. Possible values are 'sim-pin', 'sim-puk' or empty. // The status of SIM lock. Possible values are 'sim-pin', 'sim-puk' or empty.
string lock_type; string lock_type;
// Whether SIM lock is enabled. // Whether SIM lock is enabled.
...@@ -125,10 +127,6 @@ struct CellularStateProperties { ...@@ -125,10 +127,6 @@ struct CellularStateProperties {
string network_technology; string network_technology;
// True when in a roaming state and the provider is not always roaming. // True when in a roaming state and the provider is not always roaming.
bool roaming = false; bool roaming = false;
// True while performing a scan for cellular netowkrs.
bool scanning = false;
// True when a SIM is required and not present.
bool sim_absent = false;
// The signal strength of the cellular connection. // The signal strength of the cellular connection.
int32 signal_strength; int32 signal_strength;
}; };
...@@ -202,12 +200,12 @@ struct NetworkStateProperties { ...@@ -202,12 +200,12 @@ struct NetworkStateProperties {
}; };
struct DeviceStateProperties { struct DeviceStateProperties {
// Set if the device is enabled. True 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 SIMPresent = True. // The SIM lock status if Type = Cellular and a SIM is present.
SIMLockStatus? sim_lock_status; SIMLockStatus? sim_lock_status;
// Set to the SIM present state if the device type is Cellular. // True when a SIM is required and not present.
bool sim_present = false; bool sim_absent = false;
DeviceStateType state; DeviceStateType state;
NetworkType type; NetworkType type;
// Whether or not any managed networks are available. // Whether or not any managed networks are available.
......
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