Commit d16b1553 authored by Regan Hsu's avatar Regan Hsu Committed by Commit Bot

[CrOS PhoneHub] CrosNetworkConfig observers notified on scan completed.

Previously, the enable hotspot button stays "connecting" indefinitely.
This is because CrosNetworkConfig::OnDeviceListChanged() is not called
immediately when a tether scan state completes. This CL corrects that.

Fixed: 1146611
Bug: 1106937
Change-Id: Ieafc1fdd0f03343861aaf6dca5233b863dd69cbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2531898
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826409}
parent d5a2e2f0
...@@ -516,20 +516,17 @@ TEST_F(TetherControllerImplTest, AttemptConnectFeatureOffNoNetwork) { ...@@ -516,20 +516,17 @@ TEST_F(TetherControllerImplTest, AttemptConnectFeatureOffNoNetwork) {
// Tether is scanning, connection should be connecting still. // Tether is scanning, connection should be connecting still.
SetTetherScanState(true); SetTetherScanState(true);
EnableTetherDevice();
EXPECT_EQ(GetStatus(), TetherController::Status::kConnecting); EXPECT_EQ(GetStatus(), TetherController::Status::kConnecting);
DisconnectTetherDevice(); DisconnectTetherDevice();
// Tether stops scanning, attempt ends and connection should become // Tether stops scanning, attempt ends and connection should become
// unavailable. // unavailable.
SetTetherScanState(false); SetTetherScanState(false);
EnableTetherDevice();
EXPECT_EQ(GetNumObserverScanFailed(), 1U); EXPECT_EQ(GetNumObserverScanFailed(), 1U);
EXPECT_EQ(GetStatus(), TetherController::Status::kConnectionUnavailable); EXPECT_EQ(GetStatus(), TetherController::Status::kConnectionUnavailable);
// Tether starts scanning after connection attempt ended. // Tether starts scanning after connection attempt ended.
SetTetherScanState(true); SetTetherScanState(true);
EnableTetherDevice();
EXPECT_EQ(GetNumObserverScanFailed(), 1U); EXPECT_EQ(GetNumObserverScanFailed(), 1U);
EXPECT_EQ(GetStatus(), TetherController::Status::kConnectionUnavailable); EXPECT_EQ(GetStatus(), TetherController::Status::kConnectionUnavailable);
} }
......
...@@ -339,6 +339,9 @@ void NetworkStateHandler::SetTetherScanState(bool is_scanning) { ...@@ -339,6 +339,9 @@ void NetworkStateHandler::SetTetherScanState(bool is_scanning) {
if (was_scanning && !is_scanning) { if (was_scanning && !is_scanning) {
// If a scan was in progress but has completed, notify observers. // If a scan was in progress but has completed, notify observers.
NotifyScanCompleted(tether_device_state); NotifyScanCompleted(tether_device_state);
} else if (!was_scanning && is_scanning) {
// If a scan was started, notify observers.
NotifyScanStarted(tether_device_state);
} }
} }
...@@ -2033,6 +2036,13 @@ void NetworkStateHandler::NotifyScanCompleted(const DeviceState* device) { ...@@ -2033,6 +2036,13 @@ void NetworkStateHandler::NotifyScanCompleted(const DeviceState* device) {
observer.ScanCompleted(device); observer.ScanCompleted(device);
} }
void NetworkStateHandler::NotifyScanStarted(const DeviceState* device) {
SCOPED_NET_LOG_IF_SLOW();
NET_LOG(EVENT) << "NOTIFY: ScanStarted for: " << device->path();
for (auto& observer : observers_)
observer.ScanStarted(device);
}
void NetworkStateHandler::LogPropertyUpdated(const ManagedState* state, void NetworkStateHandler::LogPropertyUpdated(const ManagedState* state,
const std::string& key, const std::string& key,
const base::Value& value) { const base::Value& value) {
......
...@@ -571,6 +571,9 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkStateHandler ...@@ -571,6 +571,9 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkStateHandler
// Called to ask observers to scan for networks. // Called to ask observers to scan for networks.
void NotifyScanRequested(const NetworkTypePattern& type); void NotifyScanRequested(const NetworkTypePattern& type);
// Called whenever Device.Scanning state transitions to true.
void NotifyScanStarted(const DeviceState* device);
// Called whenever Device.Scanning state transitions to false. // Called whenever Device.Scanning state transitions to false.
void NotifyScanCompleted(const DeviceState* device); void NotifyScanCompleted(const DeviceState* device);
......
...@@ -36,6 +36,8 @@ void NetworkStateHandlerObserver::DevicePropertiesUpdated( ...@@ -36,6 +36,8 @@ void NetworkStateHandlerObserver::DevicePropertiesUpdated(
void NetworkStateHandlerObserver::ScanRequested( void NetworkStateHandlerObserver::ScanRequested(
const NetworkTypePattern& type) {} const NetworkTypePattern& type) {}
void NetworkStateHandlerObserver::ScanStarted(const DeviceState* device) {}
void NetworkStateHandlerObserver::ScanCompleted(const DeviceState* device) {} void NetworkStateHandlerObserver::ScanCompleted(const DeviceState* device) {}
void NetworkStateHandlerObserver::HostnameChanged(const std::string& hostname) { void NetworkStateHandlerObserver::HostnameChanged(const std::string& hostname) {
......
...@@ -66,6 +66,9 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkStateHandlerObserver { ...@@ -66,6 +66,9 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkStateHandlerObserver {
// A scan for a given network type has been requested. // A scan for a given network type has been requested.
virtual void ScanRequested(const NetworkTypePattern& type); virtual void ScanRequested(const NetworkTypePattern& type);
// A scan for |device| started.
virtual void ScanStarted(const DeviceState* device);
// A scan for |device| completed. // A scan for |device| completed.
virtual void ScanCompleted(const DeviceState* device); virtual void ScanCompleted(const DeviceState* device);
......
...@@ -2628,6 +2628,14 @@ void CrosNetworkConfig::DevicePropertiesUpdated(const DeviceState* device) { ...@@ -2628,6 +2628,14 @@ void CrosNetworkConfig::DevicePropertiesUpdated(const DeviceState* device) {
DeviceListChanged(); DeviceListChanged();
} }
void CrosNetworkConfig::ScanCompleted(const DeviceState* device) {
DeviceListChanged();
}
void CrosNetworkConfig::ScanStarted(const DeviceState* device) {
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);
......
...@@ -150,6 +150,8 @@ class CrosNetworkConfig : public mojom::CrosNetworkConfig, ...@@ -150,6 +150,8 @@ class CrosNetworkConfig : public mojom::CrosNetworkConfig,
void NetworkPropertiesUpdated(const NetworkState* network) override; void NetworkPropertiesUpdated(const NetworkState* network) override;
void DevicePropertiesUpdated(const DeviceState* device) override; void DevicePropertiesUpdated(const DeviceState* device) override;
void OnShuttingDown() override; void OnShuttingDown() override;
void ScanStarted(const DeviceState* device) override;
void ScanCompleted(const DeviceState* device) override;
// NetworkCertificateHandler::Observer // NetworkCertificateHandler::Observer
void OnCertificatesChanged() override; void OnCertificatesChanged() override;
......
...@@ -1315,6 +1315,24 @@ TEST_F(CrosNetworkConfigTest, DeviceListChanged) { ...@@ -1315,6 +1315,24 @@ TEST_F(CrosNetworkConfigTest, DeviceListChanged) {
// disabling state, next when it's actually disabled, and lastly when // disabling state, next when it's actually disabled, and lastly when
// Device::available_managed_network_path_ changes. // Device::available_managed_network_path_ changes.
EXPECT_EQ(3, observer()->device_state_list_changed()); EXPECT_EQ(3, observer()->device_state_list_changed());
// Enable Tethering
helper().network_state_handler()->SetTetherTechnologyState(
NetworkStateHandler::TechnologyState::TECHNOLOGY_ENABLED);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(4, observer()->device_state_list_changed());
// Tests that observers are notified of device state list change
// when a tether scan begins for a device.
helper().network_state_handler()->SetTetherScanState(true);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(5, observer()->device_state_list_changed());
// Tests that observers are notified of device state list change
// when a tether scan completes.
helper().network_state_handler()->SetTetherScanState(false);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(6, observer()->device_state_list_changed());
} }
TEST_F(CrosNetworkConfigTest, ActiveNetworksChanged) { TEST_F(CrosNetworkConfigTest, ActiveNetworksChanged) {
......
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