From 13db17e9c1703c1e7a84791817f616109e0fc5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giovanni=20Ortu=C3=B1o=20Urquidi?= Date: Thu, 2 Jun 2016 10:19:54 -0700 Subject: [PATCH] bluetooth: Fix logic mistake in DeviceChanged 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 bb0a85c376fc57c99d6b2e8df8af6ea5f8ab5775) Review URL: https://codereview.chromium.org/2032093002 . Cr-Commit-Position: refs/branch-heads/2743@{#191} Cr-Branched-From: 2b3ae3b8090361f8af5a611712fc1a5ab2de53cb-refs/heads/master@{#394939} --- content/browser/bluetooth/web_bluetooth_service_impl.cc | 2 +- device/bluetooth/bluez/bluetooth_device_bluez.cc | 5 +++-- device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/content/browser/bluetooth/web_bluetooth_service_impl.cc b/content/browser/bluetooth/web_bluetooth_service_impl.cc index 05f1ebad27304..2bacdc9e8d2a4 100644 --- a/content/browser/bluetooth/web_bluetooth_service_impl.cc +++ b/content/browser/bluetooth/web_bluetooth_service_impl.cc @@ -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()); diff --git a/device/bluetooth/bluez/bluetooth_device_bluez.cc b/device/bluetooth/bluez/bluetooth_device_bluez.cc index 9ed6bf1cc4005..713c14f0f2665 100644 --- a/device/bluetooth/bluez/bluetooth_device_bluez.cc +++ b/device/bluetooth/bluez/bluetooth_device_bluez.cc @@ -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 { diff --git a/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc b/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc index 1c1c110f5ec61..c5fa376674e42 100644 --- a/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc +++ b/device/bluetooth/bluez/bluetooth_gatt_bluez_unittest.cc @@ -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_); @@ -218,6 +219,7 @@ 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, @@ -225,6 +227,7 @@ TEST_F(BluetoothGattBlueZTest, GattConnection) { gatt_conn_->Disconnect(); EXPECT_FALSE(device->IsConnected()); + EXPECT_FALSE(device->IsGattConnected()); EXPECT_FALSE(gatt_conn_->IsConnected()); device->CreateGattConnection( @@ -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()); @@ -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()); @@ -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(