Commit 93db395f authored by Michael Hansen's avatar Michael Hansen Committed by Commit Bot

[Nearby] Invalidate surfaces on Bluetooth status changes.

Invalidate send and receive surfaces to make sure we start or stop
advertising based on changes to Bluetooth "powered" or "present" state.

Bug: b:166174379
Change-Id: I252c65d9f27594e0e6e83ad233d9f051bb25700e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391586
Commit-Queue: Michael Hansen <hansenmichael@google.com>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805374}
parent db10024c
...@@ -935,6 +935,8 @@ bool NearbySharingServiceImpl::HasAvailableConnectionMediums() { ...@@ -935,6 +935,8 @@ bool NearbySharingServiceImpl::HasAvailableConnectionMediums() {
void NearbySharingServiceImpl::AdapterPresentChanged( void NearbySharingServiceImpl::AdapterPresentChanged(
device::BluetoothAdapter* adapter, device::BluetoothAdapter* adapter,
bool present) { bool present) {
NS_LOG(VERBOSE) << "Bluetooth present changed: " << present;
InvalidateSurfaceState();
if (!present) if (!present)
StopFastInitiationAdvertising(); StopFastInitiationAdvertising();
} }
...@@ -942,6 +944,8 @@ void NearbySharingServiceImpl::AdapterPresentChanged( ...@@ -942,6 +944,8 @@ void NearbySharingServiceImpl::AdapterPresentChanged(
void NearbySharingServiceImpl::AdapterPoweredChanged( void NearbySharingServiceImpl::AdapterPoweredChanged(
device::BluetoothAdapter* adapter, device::BluetoothAdapter* adapter,
bool powered) { bool powered) {
NS_LOG(VERBOSE) << "Bluetooth powered changed: " << powered;
InvalidateSurfaceState();
if (!powered) if (!powered)
StopFastInitiationAdvertising(); StopFastInitiationAdvertising();
} }
......
...@@ -424,6 +424,18 @@ class NearbySharingServiceImplTest : public testing::Test { ...@@ -424,6 +424,18 @@ class NearbySharingServiceImplTest : public testing::Test {
bool IsBluetoothPresent() { return is_bluetooth_present_; } bool IsBluetoothPresent() { return is_bluetooth_present_; }
bool IsBluetoothPowered() { return is_bluetooth_powered_; } bool IsBluetoothPowered() { return is_bluetooth_powered_; }
void SetBluetoothIsPresent(bool present) {
is_bluetooth_present_ = present;
adapter_observer_->AdapterPresentChanged(mock_bluetooth_adapter_.get(),
present);
}
void SetBluetoothIsPowered(bool powered) {
is_bluetooth_powered_ = powered;
adapter_observer_->AdapterPoweredChanged(mock_bluetooth_adapter_.get(),
powered);
}
void AddAdapterObserver(device::BluetoothAdapter::Observer* observer) { void AddAdapterObserver(device::BluetoothAdapter::Observer* observer) {
DCHECK(!adapter_observer_); DCHECK(!adapter_observer_);
adapter_observer_ = observer; adapter_observer_ = observer;
...@@ -1116,6 +1128,40 @@ TEST_F(NearbySharingServiceImplTest, ...@@ -1116,6 +1128,40 @@ TEST_F(NearbySharingServiceImplTest,
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering()); EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
} }
TEST_F(NearbySharingServiceImplTest,
BluetoothBecomesNotPresentStopDiscovering) {
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_BLUETOOTH);
MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback;
EXPECT_EQ(
NearbySharingService::StatusCodes::kOk,
service_->RegisterSendSurface(&transfer_callback, &discovery_callback,
SendSurfaceState::kForeground));
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
SetBluetoothIsPresent(false);
EXPECT_FALSE(fake_nearby_connections_manager_->IsDiscovering());
SetBluetoothIsPresent(true);
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
}
TEST_F(NearbySharingServiceImplTest,
BluetoothBecomesNotPoweredStopDiscovering) {
SetConnectionType(net::NetworkChangeNotifier::CONNECTION_BLUETOOTH);
MockTransferUpdateCallback transfer_callback;
MockShareTargetDiscoveredCallback discovery_callback;
EXPECT_EQ(
NearbySharingService::StatusCodes::kOk,
service_->RegisterSendSurface(&transfer_callback, &discovery_callback,
SendSurfaceState::kForeground));
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
SetBluetoothIsPowered(false);
EXPECT_FALSE(fake_nearby_connections_manager_->IsDiscovering());
SetBluetoothIsPowered(true);
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
}
TEST_F(NearbySharingServiceImplTest, TEST_F(NearbySharingServiceImplTest,
RegisterSendSurfaceAlreadyReceivingNotDiscovering) { RegisterSendSurfaceAlreadyReceivingNotDiscovering) {
NiceMock<MockTransferUpdateCallback> callback; NiceMock<MockTransferUpdateCallback> callback;
......
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