diff options
author | smbarber <smbarber@chromium.org> | 2016-03-22 12:36:51 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-22 19:39:21 +0000 |
commit | 5593ae4f2f4792363f4a0cbcc968b80529fd3a1e (patch) | |
tree | 36414a6c5454d3596bde04c87d5d3181fe6fdfac /device | |
parent | 813d605e717ff246ea1bf65e11db6fbb4cf8679e (diff) | |
download | chromium_src-5593ae4f2f4792363f4a0cbcc968b80529fd3a1e.zip chromium_src-5593ae4f2f4792363f4a0cbcc968b80529fd3a1e.tar.gz chromium_src-5593ae4f2f4792363f4a0cbcc968b80529fd3a1e.tar.bz2 |
Add GetUUIDs to device::BluetoothAdapter for BlueZ
Add GetUUIDs to device::BluetoothAdapter so that a client
can get the list of services registered on the adapter. This
can include standard profiles (e.g. A2DP) or UUIDs associated
with listening RFCOMM or L2CAP sockets.
BUG=b:26275233
R=rkc@chromium.org, scheib@chromium.org
Review URL: https://codereview.chromium.org/1781143002
Cr-Commit-Position: refs/heads/master@{#382641}
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_adapter.h | 6 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_android.cc | 5 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_android.h | 1 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_bluez.cc | 12 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_bluez.h | 1 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_mac.h | 1 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_mac.mm | 5 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_unittest.cc | 3 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_win.cc | 5 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_win.h | 1 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_bluez_unittest.cc | 35 | ||||
-rw-r--r-- | device/bluetooth/dbus/fake_bluetooth_adapter_client.cc | 10 | ||||
-rw-r--r-- | device/bluetooth/dbus/fake_bluetooth_adapter_client.h | 5 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_adapter.h | 1 |
14 files changed, 91 insertions, 0 deletions
diff --git a/device/bluetooth/bluetooth_adapter.h b/device/bluetooth/bluetooth_adapter.h index 5dcf12f..80bd176 100644 --- a/device/bluetooth/bluetooth_adapter.h +++ b/device/bluetooth/bluetooth_adapter.h @@ -202,6 +202,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter DiscoverySessionCallback; typedef std::vector<BluetoothDevice*> DeviceList; typedef std::vector<const BluetoothDevice*> ConstDeviceList; + typedef std::vector<BluetoothUUID> UUIDList; typedef base::Callback<void(scoped_refptr<BluetoothSocket>)> CreateServiceCallback; typedef base::Callback<void(const std::string& message)> @@ -328,6 +329,11 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter virtual BluetoothDevice* GetDevice(const std::string& address); virtual const BluetoothDevice* GetDevice(const std::string& address) const; + // Returns a list of UUIDs for services registered on this adapter. + // This may include UUIDs from standard profiles (e.g. A2DP) as well + // as those created by CreateRfcommService and CreateL2capService. + virtual UUIDList GetUUIDs() const = 0; + // Possible priorities for AddPairingDelegate(), low is intended for // permanent UI and high is intended for interactive UI or applications. enum PairingDelegatePriority { diff --git a/device/bluetooth/bluetooth_adapter_android.cc b/device/bluetooth/bluetooth_adapter_android.cc index fc19a81..b3891a4 100644 --- a/device/bluetooth/bluetooth_adapter_android.cc +++ b/device/bluetooth/bluetooth_adapter_android.cc @@ -102,6 +102,11 @@ bool BluetoothAdapterAndroid::IsDiscovering() const { j_adapter_.obj()); } +BluetoothAdapter::UUIDList BluetoothAdapterAndroid::GetUUIDs() const { + NOTIMPLEMENTED(); + return UUIDList(); +} + void BluetoothAdapterAndroid::CreateRfcommService( const BluetoothUUID& uuid, const ServiceOptions& options, diff --git a/device/bluetooth/bluetooth_adapter_android.h b/device/bluetooth/bluetooth_adapter_android.h index 8ebb49c..66df14f 100644 --- a/device/bluetooth/bluetooth_adapter_android.h +++ b/device/bluetooth/bluetooth_adapter_android.h @@ -64,6 +64,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterAndroid final const base::Closure& callback, const ErrorCallback& error_callback) override; bool IsDiscovering() const override; + UUIDList GetUUIDs() const override; void CreateRfcommService( const BluetoothUUID& uuid, const ServiceOptions& options, diff --git a/device/bluetooth/bluetooth_adapter_bluez.cc b/device/bluetooth/bluetooth_adapter_bluez.cc index 4424b02..91345fc 100644 --- a/device/bluetooth/bluetooth_adapter_bluez.cc +++ b/device/bluetooth/bluetooth_adapter_bluez.cc @@ -328,6 +328,18 @@ bool BluetoothAdapterBlueZ::IsDiscovering() const { return properties->discovering.value(); } +BluetoothAdapterBlueZ::UUIDList BluetoothAdapterBlueZ::GetUUIDs() const { + bluez::BluetoothAdapterClient::Properties* properties = + bluez::BluezDBusManager::Get() + ->GetBluetoothAdapterClient() + ->GetProperties(object_path_); + DCHECK(properties); + + std::vector<std::string> uuids = properties->uuids.value(); + + return UUIDList(uuids.begin(), uuids.end()); +} + void BluetoothAdapterBlueZ::CreateRfcommService( const BluetoothUUID& uuid, const ServiceOptions& options, diff --git a/device/bluetooth/bluetooth_adapter_bluez.h b/device/bluetooth/bluetooth_adapter_bluez.h index 3d402d4..de52c89 100644 --- a/device/bluetooth/bluetooth_adapter_bluez.h +++ b/device/bluetooth/bluetooth_adapter_bluez.h @@ -79,6 +79,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ // BluetoothAdapter: void Shutdown() override; + UUIDList GetUUIDs() const override; std::string GetAddress() const override; std::string GetName() const override; void SetName(const std::string& name, diff --git a/device/bluetooth/bluetooth_adapter_mac.h b/device/bluetooth/bluetooth_adapter_mac.h index 7bd221d..b632741 100644 --- a/device/bluetooth/bluetooth_adapter_mac.h +++ b/device/bluetooth/bluetooth_adapter_mac.h @@ -65,6 +65,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterMac const base::Closure& callback, const ErrorCallback& error_callback) override; bool IsDiscovering() const override; + UUIDList GetUUIDs() const override; void CreateRfcommService( const BluetoothUUID& uuid, const ServiceOptions& options, diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm index 2c431a4..78c9ee9 100644 --- a/device/bluetooth/bluetooth_adapter_mac.mm +++ b/device/bluetooth/bluetooth_adapter_mac.mm @@ -165,6 +165,11 @@ bool BluetoothAdapterMac::IsDiscovering() const { return is_discovering; } +BluetoothAdapter::UUIDList BluetoothAdapterMac::GetUUIDs() const { + NOTIMPLEMENTED(); + return UUIDList(); +} + void BluetoothAdapterMac::CreateRfcommService( const BluetoothUUID& uuid, const ServiceOptions& options, diff --git a/device/bluetooth/bluetooth_adapter_unittest.cc b/device/bluetooth/bluetooth_adapter_unittest.cc index 55bffb7..feba430 100644 --- a/device/bluetooth/bluetooth_adapter_unittest.cc +++ b/device/bluetooth/bluetooth_adapter_unittest.cc @@ -70,6 +70,9 @@ class TestBluetoothAdapter : public BluetoothAdapter { void StartDiscoverySession(const DiscoverySessionCallback& callback, const ErrorCallback& error_callback) override {} + + UUIDList GetUUIDs() const override { return UUIDList(); } + void CreateRfcommService( const BluetoothUUID& uuid, const ServiceOptions& options, diff --git a/device/bluetooth/bluetooth_adapter_win.cc b/device/bluetooth/bluetooth_adapter_win.cc index c946091..33e1501 100644 --- a/device/bluetooth/bluetooth_adapter_win.cc +++ b/device/bluetooth/bluetooth_adapter_win.cc @@ -158,6 +158,11 @@ void BluetoothAdapterWin::DiscoveryStopped() { MaybePostStartDiscoveryTask(); } +BluetoothAdapter::UUIDList BluetoothAdapterWin::GetUUIDs() const { + NOTIMPLEMENTED(); + return UUIDList(); +} + void BluetoothAdapterWin::CreateRfcommService( const BluetoothUUID& uuid, const ServiceOptions& options, diff --git a/device/bluetooth/bluetooth_adapter_win.h b/device/bluetooth/bluetooth_adapter_win.h index bb8f16b..8781c66 100644 --- a/device/bluetooth/bluetooth_adapter_win.h +++ b/device/bluetooth/bluetooth_adapter_win.h @@ -59,6 +59,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterWin const base::Closure& callback, const ErrorCallback& error_callback) override; bool IsDiscovering() const override; + UUIDList GetUUIDs() const override; void CreateRfcommService( const BluetoothUUID& uuid, const ServiceOptions& options, diff --git a/device/bluetooth/bluetooth_bluez_unittest.cc b/device/bluetooth/bluetooth_bluez_unittest.cc index 5186bdc..780a0be 100644 --- a/device/bluetooth/bluetooth_bluez_unittest.cc +++ b/device/bluetooth/bluetooth_bluez_unittest.cc @@ -170,6 +170,11 @@ class TestPairingDelegate : public BluetoothDevice::PairingDelegate { class BluetoothBlueZTest : public testing::Test { public: + static const char kGapUuid[]; + static const char kGattUuid[]; + static const char kPnpUuid[]; + static const char kHeadsetUuid[]; + void SetUp() override { scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = bluez::BluezDBusManager::GetSetterForTesting(); @@ -373,6 +378,14 @@ class BluetoothBlueZTest : public testing::Test { } } }; +const char BluetoothBlueZTest::kGapUuid[] = + "00001800-0000-1000-8000-00805f9b34fb"; +const char BluetoothBlueZTest::kGattUuid[] = + "00001801-0000-1000-8000-00805f9b34fb"; +const char BluetoothBlueZTest::kPnpUuid[] = + "00001200-0000-1000-8000-00805f9b34fb"; +const char BluetoothBlueZTest::kHeadsetUuid[] = + "00001112-0000-1000-8000-00805f9b34fb"; TEST_F(BluetoothBlueZTest, AlreadyPresent) { GetAdapter(); @@ -612,6 +625,28 @@ TEST_F(BluetoothBlueZTest, ChangeAdapterNameWhenNotPresent) { EXPECT_EQ("", adapter_->GetName()); } +TEST_F(BluetoothBlueZTest, GetUUIDs) { + std::vector<std::string> adapterUuids; + GetAdapter(); + + adapterUuids.push_back(kGapUuid); + adapterUuids.push_back(kGattUuid); + adapterUuids.push_back(kPnpUuid); + adapterUuids.push_back(kHeadsetUuid); + + fake_bluetooth_adapter_client_->SetUUIDs(adapterUuids); + + BluetoothAdapter::UUIDList uuids = adapter_->GetUUIDs(); + + ASSERT_EQ(4U, uuids.size()); + // Check that the UUIDs match those from above - in order, GAP, GATT, PnP, and + // headset. + EXPECT_EQ(uuids[0], BluetoothUUID("1800")); + EXPECT_EQ(uuids[1], BluetoothUUID("1801")); + EXPECT_EQ(uuids[2], BluetoothUUID("1200")); + EXPECT_EQ(uuids[3], BluetoothUUID("1112")); +} + TEST_F(BluetoothBlueZTest, BecomeDiscoverable) { GetAdapter(); ASSERT_FALSE(adapter_->IsDiscoverable()); diff --git a/device/bluetooth/dbus/fake_bluetooth_adapter_client.cc b/device/bluetooth/dbus/fake_bluetooth_adapter_client.cc index f928768..9083b6b 100644 --- a/device/bluetooth/dbus/fake_bluetooth_adapter_client.cc +++ b/device/bluetooth/dbus/fake_bluetooth_adapter_client.cc @@ -269,6 +269,16 @@ void FakeBluetoothAdapterClient::SetSecondVisible(bool visible) { } } +void FakeBluetoothAdapterClient::SetUUIDs( + const std::vector<std::string>& uuids) { + properties_->uuids.ReplaceValue(uuids); +} + +void FakeBluetoothAdapterClient::SetSecondUUIDs( + const std::vector<std::string>& uuids) { + second_properties_->uuids.ReplaceValue(uuids); +} + void FakeBluetoothAdapterClient::OnPropertyChanged( const std::string& property_name) { if (property_name == properties_->powered.name() && diff --git a/device/bluetooth/dbus/fake_bluetooth_adapter_client.h b/device/bluetooth/dbus/fake_bluetooth_adapter_client.h index 0dced89..702bf23 100644 --- a/device/bluetooth/dbus/fake_bluetooth_adapter_client.h +++ b/device/bluetooth/dbus/fake_bluetooth_adapter_client.h @@ -5,6 +5,7 @@ #ifndef DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_ #define DEVICE_BLUETOOTH_DBUS_FAKE_BLUETOOTH_ADAPTER_CLIENT_H_ +#include <string> #include <vector> #include "base/bind.h" @@ -72,6 +73,10 @@ class DEVICE_BLUETOOTH_EXPORT FakeBluetoothAdapterClient void SetVisible(bool visible); void SetSecondVisible(bool visible); + // Set adapter UUIDs + void SetUUIDs(const std::vector<std::string>& uuids); + void SetSecondUUIDs(const std::vector<std::string>& uuids); + // Object path, name and addresses of the adapters we emulate. static const char kAdapterPath[]; static const char kAdapterName[]; diff --git a/device/bluetooth/test/mock_bluetooth_adapter.h b/device/bluetooth/test/mock_bluetooth_adapter.h index 1bdb215..e4cef59 100644 --- a/device/bluetooth/test/mock_bluetooth_adapter.h +++ b/device/bluetooth/test/mock_bluetooth_adapter.h @@ -76,6 +76,7 @@ class MockBluetoothAdapter : public BluetoothAdapter { MOCK_METHOD1(GetDevice, BluetoothDevice*(const std::string& address)); MOCK_CONST_METHOD1(GetDevice, const BluetoothDevice*(const std::string& address)); + MOCK_CONST_METHOD0(GetUUIDs, UUIDList()); MOCK_METHOD2(AddPairingDelegate, void(BluetoothDevice::PairingDelegate* pairing_delegate, enum PairingDelegatePriority priority)); |