diff --git a/internal/platform/implementation/linux/bluetooth_classic_device.cc b/internal/platform/implementation/linux/bluetooth_classic_device.cc index b940d62d..aa0c5373 100644 --- a/internal/platform/implementation/linux/bluetooth_classic_device.cc +++ b/internal/platform/implementation/linux/bluetooth_classic_device.cc @@ -17,6 +17,7 @@ #include #include "absl/strings/string_view.h" +#include "internal/platform/bluetooth_utils.h" #include "internal/platform/implementation/linux/bluetooth_classic_device.h" #include "internal/platform/implementation/linux/bluez.h" #include "internal/platform/implementation/linux/dbus.h" @@ -36,6 +37,7 @@ BluetoothDevice::BluetoothDevice(sdbus::IConnection &system_bus, } try { last_known_address_ = Address(); + unique_id_ = BluetoothUtils::ToNumber(last_known_address_); } catch (const sdbus::Error &e) { DBUS_LOG_PROPERTY_GET_ERROR(this, "Address", e); } diff --git a/internal/platform/implementation/linux/bluetooth_classic_device.h b/internal/platform/implementation/linux/bluetooth_classic_device.h index 0226056f..e29920e9 100644 --- a/internal/platform/implementation/linux/bluetooth_classic_device.h +++ b/internal/platform/implementation/linux/bluetooth_classic_device.h @@ -24,6 +24,7 @@ #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" #include "internal/base/observer_list.h" +#include "internal/platform/implementation/ble_v2.h" #include "internal/platform/implementation/bluetooth_classic.h" #include "internal/platform/implementation/linux/generated/dbus/bluez/device_client.h" @@ -32,8 +33,11 @@ namespace linux { // https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html. class BluetoothDevice : public api::BluetoothDevice, - public sdbus::ProxyInterfaces { + public sdbus::ProxyInterfaces, + public api::ble_v2::BlePeripheral { public: + using UniqueId = std::uint64_t; + BluetoothDevice(const BluetoothDevice &) = delete; BluetoothDevice(BluetoothDevice &&) = delete; BluetoothDevice &operator=(const BluetoothDevice &) = delete; @@ -42,12 +46,16 @@ class BluetoothDevice sdbus::ObjectPath device_object_path); ~BluetoothDevice() override { unregisterProxy(); } + // BluetoothDevice methods // https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getName() std::string GetName() const override; - // Returns BT MAC address assigned to this device. std::string GetMacAddress() const override; + // BlePeripheral methods + std::string GetAddress() const override { return GetMacAddress(); } + UniqueId GetUniqueId() const override { return unique_id_; }; + bool ConnectToProfile(absl::string_view service_uuid); void set_pair_reply_callback( @@ -72,6 +80,7 @@ class BluetoothDevice absl::Mutex pair_callback_lock_; absl::AnyInvocable on_pair_reply_cb_ = DefaultCallback(); + UniqueId unique_id_; mutable absl::Mutex properties_mutex_; mutable std::string last_known_name_ ABSL_GUARDED_BY(properties_mutex_);