Skip to content

Commit

Permalink
bluetooth: Fix logic mistake in DeviceChanged
Browse files Browse the repository at this point in the history
Fixes an issue in which we always disconnected a device even if the connection
is still active.

BUG=615383

Review-Url: https://codereview.chromium.org/2016973003
Cr-Commit-Position: refs/heads/master@{#396877}
(cherry picked from commit bb0a85c)

Review URL: https://codereview.chromium.org/2032093002 .

Cr-Commit-Position: refs/branch-heads/2743@{crosswalk-project#191}
Cr-Branched-From: 2b3ae3b-refs/heads/master@{#394939}
  • Loading branch information
Giovanni Ortuño Urquidi committed Jun 2, 2016
1 parent 468e29b commit 13db17e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion content/browser/bluetooth/web_bluetooth_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void WebBluetoothServiceImpl::AdapterPresentChanged(
void WebBluetoothServiceImpl::DeviceChanged(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!device->IsGattConnected() || !device->IsConnected()) {
if (!device->IsGattConnected()) {
std::string device_id =
connected_devices_->CloseConnectionToDeviceWithAddress(
device->GetAddress());
Expand Down
5 changes: 3 additions & 2 deletions device/bluetooth/bluez/bluetooth_device_bluez.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ bool BluetoothDeviceBlueZ::IsConnected() const {
}

bool BluetoothDeviceBlueZ::IsGattConnected() const {
NOTIMPLEMENTED();
return false;
// Bluez uses the same attribute for GATT Connections and Classic BT
// Connections.
return IsConnected();
}

bool BluetoothDeviceBlueZ::IsConnectable() const {
Expand Down
6 changes: 6 additions & 0 deletions device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ TEST_F(BluetoothGattBlueZTest, GattConnection) {
adapter_->GetDevice(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress);
ASSERT_TRUE(device);
ASSERT_FALSE(device->IsConnected());
ASSERT_FALSE(device->IsGattConnected());
ASSERT_FALSE(gatt_conn_.get());
ASSERT_EQ(0, success_callback_count_);
ASSERT_EQ(0, error_callback_count_);
Expand All @@ -218,13 +219,15 @@ TEST_F(BluetoothGattBlueZTest, GattConnection) {
EXPECT_EQ(1, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
EXPECT_TRUE(device->IsConnected());
EXPECT_TRUE(device->IsGattConnected());
ASSERT_TRUE(gatt_conn_.get());
EXPECT_TRUE(gatt_conn_->IsConnected());
EXPECT_EQ(bluez::FakeBluetoothDeviceClient::kLowEnergyAddress,
gatt_conn_->GetDeviceAddress());

gatt_conn_->Disconnect();
EXPECT_FALSE(device->IsConnected());
EXPECT_FALSE(device->IsGattConnected());
EXPECT_FALSE(gatt_conn_->IsConnected());

device->CreateGattConnection(
Expand All @@ -236,6 +239,7 @@ TEST_F(BluetoothGattBlueZTest, GattConnection) {
EXPECT_EQ(2, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
EXPECT_TRUE(device->IsConnected());
EXPECT_TRUE(device->IsGattConnected());
ASSERT_TRUE(gatt_conn_.get());
EXPECT_TRUE(gatt_conn_->IsConnected());

Expand All @@ -247,6 +251,7 @@ TEST_F(BluetoothGattBlueZTest, GattConnection) {
EXPECT_EQ(3, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
EXPECT_FALSE(device->IsConnected());
EXPECT_FALSE(device->IsGattConnected());
ASSERT_TRUE(gatt_conn_.get());
EXPECT_FALSE(gatt_conn_->IsConnected());

Expand All @@ -259,6 +264,7 @@ TEST_F(BluetoothGattBlueZTest, GattConnection) {
EXPECT_EQ(4, success_callback_count_);
EXPECT_EQ(0, error_callback_count_);
EXPECT_TRUE(device->IsConnected());
EXPECT_TRUE(device->IsGattConnected());
EXPECT_TRUE(gatt_conn_->IsConnected());

fake_bluetooth_device_client_->RemoveDevice(
Expand Down

0 comments on commit 13db17e

Please sign in to comment.