diff --git a/connections/implementation/injected_bluetooth_device_store.cc b/connections/implementation/injected_bluetooth_device_store.cc index 5765164f..c9c6151e 100644 --- a/connections/implementation/injected_bluetooth_device_store.cc +++ b/connections/implementation/injected_bluetooth_device_store.cc @@ -46,7 +46,14 @@ class InjectedBluetoothDevice : public api::BluetoothDevice { // api::BluetoothDevice: std::string GetName() const override { return name_; } - std::string GetMacAddress() const override { return mac_address_; } + MacAddress GetAddress() const override { + if (mac_address_.empty()) { + return MacAddress(); + } + MacAddress address; + MacAddress::FromString(mac_address_, address); + return address; + } private: const std::string name_; diff --git a/internal/platform/implementation/apple/Tests/bluetooth_adapter_v2_test.mm b/internal/platform/implementation/apple/Tests/bluetooth_adapter_v2_test.mm index 598ab7fc..8d2c9c0d 100644 --- a/internal/platform/implementation/apple/Tests/bluetooth_adapter_v2_test.mm +++ b/internal/platform/implementation/apple/Tests/bluetooth_adapter_v2_test.mm @@ -62,11 +62,6 @@ XCTAssertFalse(_adapter.SetName("TestName", true)); } -- (void)testGetMacAddress { - // Currently hardcoded to return "". - XCTAssertEqual(_adapter.GetMacAddress(), ""); -} - - (void)testGetAddress { // Currently hardcoded to return an empty MacAddress. nearby::MacAddress emptyAddress; diff --git a/internal/platform/implementation/apple/bluetooth_adapter_v2.h b/internal/platform/implementation/apple/bluetooth_adapter_v2.h index 0413bd43..878a316e 100644 --- a/internal/platform/implementation/apple/bluetooth_adapter_v2.h +++ b/internal/platform/implementation/apple/bluetooth_adapter_v2.h @@ -84,8 +84,6 @@ class BluetoothAdapter : public api::BluetoothAdapter { bool SetName(absl::string_view name, bool persist) override; // Returns BT MAC address assigned to this adapter. - std::string GetMacAddress() const override; - MacAddress GetAddress() const override; }; diff --git a/internal/platform/implementation/apple/bluetooth_adapter_v2.mm b/internal/platform/implementation/apple/bluetooth_adapter_v2.mm index 365ee8bd..1461c764 100644 --- a/internal/platform/implementation/apple/bluetooth_adapter_v2.mm +++ b/internal/platform/implementation/apple/bluetooth_adapter_v2.mm @@ -64,10 +64,6 @@ bool BluetoothAdapter::SetName(absl::string_view name, bool persist) { } // TODO(b/290385712): Implement. -std::string BluetoothAdapter::GetMacAddress() const { - return ""; -} - MacAddress BluetoothAdapter::GetAddress() const { return MacAddress(); } diff --git a/internal/platform/implementation/bluetooth_adapter.h b/internal/platform/implementation/bluetooth_adapter.h index 83af1ad6..b1d27842 100644 --- a/internal/platform/implementation/bluetooth_adapter.h +++ b/internal/platform/implementation/bluetooth_adapter.h @@ -66,21 +66,7 @@ class BluetoothAdapter { virtual bool SetName(absl::string_view name) = 0; virtual bool SetName(absl::string_view name, bool persist) = 0; - // Returns BT MAC address assigned to this adapter. - ABSL_DEPRECATED("Use GetAddress() instead.") - virtual std::string GetMacAddress() const = 0; - - // Implementation for migration only. Once subclasses implement this, the - // above GetMacAddress() can be removed. - virtual MacAddress GetAddress() const { - std::string mac_address = GetMacAddress(); - if (mac_address.empty()) { - return MacAddress(); - } - MacAddress address; - MacAddress::FromString(mac_address, address); - return address; - } + virtual MacAddress GetAddress() const = 0; }; } // namespace api diff --git a/internal/platform/implementation/bluetooth_classic.h b/internal/platform/implementation/bluetooth_classic.h index fa811ce2..53241c23 100644 --- a/internal/platform/implementation/bluetooth_classic.h +++ b/internal/platform/implementation/bluetooth_classic.h @@ -40,21 +40,7 @@ class BluetoothDevice { // https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getName() virtual std::string GetName() const = 0; - // Returns BT MAC address assigned to this device. - ABSL_DEPRECATED("Use GetAddress() instead.") - virtual std::string GetMacAddress() const = 0; - - // Implementation for migration only. Once subclasses implement this, the - // above GetMacAddress() can be removed. - virtual MacAddress GetAddress() const { - std::string mac_address = GetMacAddress(); - if (mac_address.empty()) { - return MacAddress(); - } - MacAddress address; - MacAddress::FromString(mac_address, address); - return address; - } + virtual MacAddress GetAddress() const = 0; }; // https://developer.android.com/reference/android/bluetooth/BluetoothSocket.html. diff --git a/internal/platform/implementation/g3/BUILD b/internal/platform/implementation/g3/BUILD index 8bdea2ea..375ed63a 100644 --- a/internal/platform/implementation/g3/BUILD +++ b/internal/platform/implementation/g3/BUILD @@ -140,6 +140,7 @@ cc_test( ":g3", "//internal/platform:base", "//internal/platform:cancellation_flag", + "//internal/platform:mac_address", "//internal/platform:test_util", "//internal/platform:uuid", "//internal/platform/implementation:comm", diff --git a/internal/platform/implementation/g3/ble_test.cc b/internal/platform/implementation/g3/ble_test.cc index 545567b2..c37bb9f1 100644 --- a/internal/platform/implementation/g3/ble_test.cc +++ b/internal/platform/implementation/g3/ble_test.cc @@ -25,6 +25,7 @@ #include "internal/platform/implementation/ble.h" #include "internal/platform/implementation/bluetooth_adapter.h" #include "internal/platform/implementation/g3/bluetooth_adapter.h" +#include "internal/platform/mac_address.h" #include "internal/platform/uuid.h" namespace nearby { @@ -47,7 +48,7 @@ class MockBluetoothAdapter : public BluetoothAdapter { MOCK_METHOD(bool, SetName, (absl::string_view name, bool persist), (override)); MOCK_METHOD(std::string, GetName, (), (const, override)); - MOCK_METHOD(std::string, GetMacAddress, (), (const, override)); + MOCK_METHOD(MacAddress, GetAddress, (), (const, override)); MOCK_METHOD(bool, SetScanMode, (api::BluetoothAdapter::ScanMode scan_mode), (override)); MOCK_METHOD(api::BluetoothAdapter::ScanMode, GetScanMode, (), diff --git a/internal/platform/implementation/g3/bluetooth_adapter.cc b/internal/platform/implementation/g3/bluetooth_adapter.cc index 76c0a845..38d12424 100644 --- a/internal/platform/implementation/g3/bluetooth_adapter.cc +++ b/internal/platform/implementation/g3/bluetooth_adapter.cc @@ -37,10 +37,6 @@ BluetoothDevice::BluetoothDevice(BluetoothAdapter* adapter) std::string BluetoothDevice::GetName() const { return adapter_.GetName(); } -std::string BluetoothDevice::GetMacAddress() const { - return GetAddress().ToString(); -} - MacAddress BluetoothDevice::GetAddress() const { return adapter_.GetAddress(); } BluetoothAdapter::BluetoothAdapter() { diff --git a/internal/platform/implementation/g3/bluetooth_adapter.h b/internal/platform/implementation/g3/bluetooth_adapter.h index eb67fe7c..5810250b 100644 --- a/internal/platform/implementation/g3/bluetooth_adapter.h +++ b/internal/platform/implementation/g3/bluetooth_adapter.h @@ -39,7 +39,6 @@ class BluetoothDevice : public api::BluetoothDevice { // https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getName() std::string GetName() const override; - std::string GetMacAddress() const override; MacAddress GetAddress() const override; BluetoothAdapter& GetAdapter() { return adapter_; } @@ -88,7 +87,6 @@ class BluetoothAdapter : public api::BluetoothAdapter { ABSL_LOCKS_EXCLUDED(mutex_); // Returns BT MAC address assigned to this adapter. - std::string GetMacAddress() const override { return mac_address_.ToString(); } MacAddress GetAddress() const override { return mac_address_; } BluetoothDevice& GetDevice() { return device_; } diff --git a/internal/platform/implementation/windows/BUILD b/internal/platform/implementation/windows/BUILD index 25cb2405..52e9334c 100644 --- a/internal/platform/implementation/windows/BUILD +++ b/internal/platform/implementation/windows/BUILD @@ -414,6 +414,7 @@ cc_test( ":windows", "//internal/platform:base", "//internal/platform:logging", + "//internal/platform:mac_address", "//internal/platform/implementation:comm", "//internal/platform/implementation:platform", "//internal/platform/implementation:types", diff --git a/internal/platform/implementation/windows/ble_test.cc b/internal/platform/implementation/windows/ble_test.cc index eb79fea9..870534c9 100644 --- a/internal/platform/implementation/windows/ble_test.cc +++ b/internal/platform/implementation/windows/ble_test.cc @@ -28,6 +28,7 @@ #include "absl/synchronization/notification.h" #include "internal/platform/implementation/ble.h" #include "internal/platform/implementation/windows/bluetooth_adapter.h" +#include "internal/platform/mac_address.h" #include "internal/platform/uuid.h" namespace nearby { @@ -50,7 +51,7 @@ class MockBluetoothAdapter : public BluetoothAdapter { MOCK_METHOD(bool, SetName, (absl::string_view name), (override)); MOCK_METHOD(bool, SetName, (absl::string_view name, bool persist), (override)); - MOCK_METHOD(std::string, GetMacAddress, (), (const, override)); + MOCK_METHOD(MacAddress, GetAddress, (), (const, override)); }; } // namespace diff --git a/internal/platform/implementation/windows/bluetooth_adapter.cc b/internal/platform/implementation/windows/bluetooth_adapter.cc index 54bded1f..eb74da9f 100644 --- a/internal/platform/implementation/windows/bluetooth_adapter.cc +++ b/internal/platform/implementation/windows/bluetooth_adapter.cc @@ -841,14 +841,6 @@ MacAddress BluetoothAdapter::GetAddress() const { return mac_address; } -std::string BluetoothAdapter::GetMacAddress() const { - MacAddress address = GetAddress(); - if (!address.IsSet()) { - return ""; - } - return address.ToString(); -} - std::string BluetoothAdapter::GetNameFromRegistry(PHKEY hKey) const { DWORD local_name_size = 0; DWORD value_type; diff --git a/internal/platform/implementation/windows/bluetooth_adapter.h b/internal/platform/implementation/windows/bluetooth_adapter.h index 8e1afdc3..975f1da7 100644 --- a/internal/platform/implementation/windows/bluetooth_adapter.h +++ b/internal/platform/implementation/windows/bluetooth_adapter.h @@ -83,8 +83,6 @@ class BluetoothAdapter : public api::BluetoothAdapter { bool SetName(absl::string_view name, bool persist) override; // Returns BT MAC address assigned to this adapter. - std::string GetMacAddress() const override; - MacAddress GetAddress() const override; // Returns bluetooth device name from registry diff --git a/internal/platform/implementation/windows/bluetooth_adapter_test.cc b/internal/platform/implementation/windows/bluetooth_adapter_test.cc index b1daa9df..79bf7888 100644 --- a/internal/platform/implementation/windows/bluetooth_adapter_test.cc +++ b/internal/platform/implementation/windows/bluetooth_adapter_test.cc @@ -144,9 +144,9 @@ TEST(BluetoothAdapter, DISABLED_SetName_Exceeded) { EXPECT_EQ(bluetooth_adapter.GetName(), original_bluetooth_device_name); } -TEST(BluetoothAdapter, DISABLED_GetMacAddress) { +TEST(BluetoothAdapter, DISABLED_GetAddress) { BluetoothAdapter bluetooth_adapter; - EXPECT_TRUE(!bluetooth_adapter.GetMacAddress().empty()); + EXPECT_TRUE(bluetooth_adapter.GetAddress().IsSet()); } TEST(BluetoothAdapter, DISABLED_SetOnScanModeChanged) { diff --git a/internal/platform/implementation/windows/bluetooth_classic_device.cc b/internal/platform/implementation/windows/bluetooth_classic_device.cc index d8567483..f8ec99cd 100644 --- a/internal/platform/implementation/windows/bluetooth_classic_device.cc +++ b/internal/platform/implementation/windows/bluetooth_classic_device.cc @@ -72,10 +72,6 @@ BluetoothDevice::BluetoothDevice( } // Returns BT MAC address assigned to this device. -std::string BluetoothDevice::GetMacAddress() const { - return mac_address_.ToString(); -} - MacAddress BluetoothDevice::GetAddress() const { return mac_address_; } // Checks cache first, will check uncached if no result. diff --git a/internal/platform/implementation/windows/bluetooth_classic_device.h b/internal/platform/implementation/windows/bluetooth_classic_device.h index 220ec709..5a087d2e 100644 --- a/internal/platform/implementation/windows/bluetooth_classic_device.h +++ b/internal/platform/implementation/windows/bluetooth_classic_device.h @@ -70,7 +70,6 @@ class BluetoothDevice : public api::BluetoothDevice { std::string GetName() const override { return name_; } // Returns BT MAC address assigned to this device. - std::string GetMacAddress() const override; MacAddress GetAddress() const override; std::string GetId() { return id_; } diff --git a/internal/platform/implementation/windows/bluetooth_classic_medium.cc b/internal/platform/implementation/windows/bluetooth_classic_medium.cc index 4bc81575..24f89c52 100644 --- a/internal/platform/implementation/windows/bluetooth_classic_medium.cc +++ b/internal/platform/implementation/windows/bluetooth_classic_medium.cc @@ -293,7 +293,7 @@ api::BluetoothDevice* BluetoothClassicMedium::GetRemoteDevice( std::unique_ptr BluetoothClassicMedium::CreatePairing( api::BluetoothDevice& remote_device) { VLOG(1) << __func__ << ": Start to createPairing with device: " - << remote_device.GetMacAddress(); + << remote_device.GetAddress().ToString(); try { winrt::Windows::Devices::Bluetooth::BluetoothDevice bluetooth_device = winrt::Windows::Devices::Bluetooth::BluetoothDevice::