Commit 301854c9 authored by Tiansong Cui's avatar Tiansong Cui Committed by Commit Bot

[Chromecast][BLE] Remove connection state check on Disconnect

Device connection states might be out of sync between application
and Bluetooth stack. This could cause deadlock like in b/143964107.

There is no harm to remove this check because Bluetooth stack will
still check device connection state.

Bug: internal b/143964107
Test: Build and run, no longer able to reproduce the issue.
Change-Id: I7737752e29be0f6036ec75621c6dae92a5929a77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900001Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Commit-Queue: Tiansong Cui <tiansong@google.com>
Auto-Submit: Tiansong Cui <tiansong@google.com>
Cr-Commit-Position: refs/heads/master@{#713086}
parent 6f7ab896
......@@ -464,6 +464,12 @@ void GattClientManagerImpl::RunQueuedConnectRequest() {
LOG(ERROR) << "Disconnect failed";
// Clear pending disconnect request to avoid device be in a bad state.
gatt_client_->ClearPendingDisconnect(addr);
auto it = addr_to_device_.find(addr);
if (it != addr_to_device_.end()) {
it->second->SetConnected(false);
}
DisconnectAllComplete(false);
}
......
......@@ -256,10 +256,14 @@ TEST_F(GattClientManagerTest, RemoteDeviceConnect) {
EXPECT_FALSE(gatt_client_manager_->IsConnectedLeDevice(kTestAddr1));
EXPECT_EQ(kTestAddr1, device->addr());
// These should fail if we're not connected.
EXPECT_CALL(cb_, Run(false));
// Disconnect from an already disconnected device.
EXPECT_CALL(*gatt_client_, Disconnect(kTestAddr1)).WillOnce(Return(false));
EXPECT_CALL(*gatt_client_, ClearPendingDisconnect(kTestAddr1))
.WillOnce(Return(true));
EXPECT_CALL(cb_, Run(true));
device->Disconnect(cb_.Get());
// These should fail if we're not connected.
EXPECT_CALL(cb_, Run(false));
device->CreateBond(cb_.Get());
......
......@@ -97,11 +97,6 @@ void RemoteDeviceImpl::Disconnect(StatusCallback cb) {
EXEC_CB_AND_RET(cb, false);
}
if (!connected_) {
LOG(ERROR) << "Not connected";
EXEC_CB_AND_RET(cb, false);
}
disconnect_pending_ = true;
disconnect_cb_ = std::move(cb);
gatt_client_manager_->EnqueueConnectRequest(addr_, false);
......
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