From dd943af8e90b32e9c4ca6304bf734e793bf7184f Mon Sep 17 00:00:00 2001 From: Crisrael Lucero Date: Thu, 20 Nov 2025 13:48:05 -0800 Subject: [PATCH] Change GetAddress() to GetMacAddress() in BluetoothAdapter PiperOrigin-RevId: 834896610 --- .../injected_bluetooth_device_store.cc | 4 ++-- internal/platform/bluetooth_adapter.h | 4 ++-- internal/platform/bluetooth_classic.cc | 14 +++++++------- .../apple/Tests/bluetooth_adapter_v2_test.mm | 4 ++-- .../implementation/apple/bluetooth_adapter_v2.h | 2 +- .../implementation/apple/bluetooth_adapter_v2.mm | 2 +- .../platform/implementation/bluetooth_adapter.h | 2 +- .../platform/implementation/bluetooth_classic.h | 2 +- internal/platform/implementation/g3/ble_test.cc | 2 +- .../implementation/g3/bluetooth_adapter.cc | 4 +++- .../platform/implementation/g3/bluetooth_adapter.h | 4 ++-- .../implementation/g3/bluetooth_classic.cc | 2 +- .../platform/implementation/windows/ble_test.cc | 2 +- .../implementation/windows/bluetooth_adapter.cc | 2 +- .../implementation/windows/bluetooth_adapter.h | 2 +- .../windows/bluetooth_adapter_test.cc | 4 ++-- .../windows/bluetooth_classic_device.cc | 2 +- .../windows/bluetooth_classic_device.h | 2 +- .../windows/bluetooth_classic_medium.cc | 6 +++--- internal/platform/medium_environment.cc | 4 ++-- 20 files changed, 36 insertions(+), 34 deletions(-) diff --git a/connections/implementation/injected_bluetooth_device_store.cc b/connections/implementation/injected_bluetooth_device_store.cc index c9c6151e..99481d20 100644 --- a/connections/implementation/injected_bluetooth_device_store.cc +++ b/connections/implementation/injected_bluetooth_device_store.cc @@ -46,7 +46,7 @@ class InjectedBluetoothDevice : public api::BluetoothDevice { // api::BluetoothDevice: std::string GetName() const override { return name_; } - MacAddress GetAddress() const override { + MacAddress GetMacAddress() const override { if (mac_address_.empty()) { return MacAddress(); } @@ -106,7 +106,7 @@ BluetoothDevice InjectedBluetoothDeviceStore::CreateInjectedBluetoothDevice( bool InjectedBluetoothDeviceStore::IsInjectedDevice(MacAddress mac_address) { for (const auto& device : devices_) { - if (device->GetAddress() == mac_address) { + if (device->GetMacAddress() == mac_address) { return true; } } diff --git a/internal/platform/bluetooth_adapter.h b/internal/platform/bluetooth_adapter.h index 6709524d..a08c1ded 100644 --- a/internal/platform/bluetooth_adapter.h +++ b/internal/platform/bluetooth_adapter.h @@ -37,7 +37,7 @@ class BluetoothDevice final { // https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getName() std::string GetName() const { return impl_->GetName(); } - MacAddress GetAddress() const { return impl_->GetAddress(); } + MacAddress GetAddress() const { return impl_->GetMacAddress(); } api::BluetoothDevice& GetImpl() { return *impl_; } bool IsValid() const { return impl_ != nullptr; } @@ -80,7 +80,7 @@ class BluetoothAdapter final { // https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#getName() // Returns an empty string on error std::string GetName() const { return impl_->GetName(); } - MacAddress GetAddress() const { return impl_->GetAddress(); } + MacAddress GetAddress() const { return impl_->GetMacAddress(); } // https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#setName(java.lang.String) bool SetName(absl::string_view name) { diff --git a/internal/platform/bluetooth_classic.cc b/internal/platform/bluetooth_classic.cc index 94e4551e..9ad171eb 100644 --- a/internal/platform/bluetooth_classic.cc +++ b/internal/platform/bluetooth_classic.cc @@ -125,13 +125,13 @@ bool BluetoothClassicMedium::StartDiscovery(DiscoveryCallback callback) { .device_lost_cb = [this](api::BluetoothDevice& device) { VLOG(1) << "BT .device_lost_cb for " - << device.GetAddress().ToString(); + << device.GetMacAddress().ToString(); MutexLock lock(&mutex_); if (!discovery_enabled_) return; auto item = devices_.extract(&device); if (!item) { LOG(WARNING) << "Removing unknown device: " - << device.GetAddress().ToString(); + << device.GetMacAddress().ToString(); return; } auto& context = *item.mapped(); @@ -182,7 +182,7 @@ void BluetoothClassicMedium::RemoveObserver(Observer* observer) { // api::BluetoothClassicMedium::Observer methods void BluetoothClassicMedium::DeviceAdded(api::BluetoothDevice& device) { VLOG(1) << "BT DeviceAdded; name=" << device.GetName() - << ", address=" << device.GetAddress().ToString(); + << ", address=" << device.GetMacAddress().ToString(); BluetoothDevice bt_device(&device); for (auto* observer : observer_list_.GetObservers()) { observer->DeviceAdded(bt_device); @@ -190,7 +190,7 @@ void BluetoothClassicMedium::DeviceAdded(api::BluetoothDevice& device) { } void BluetoothClassicMedium::DeviceRemoved(api::BluetoothDevice& device) { VLOG(1) << "BT DeviceRemoved; name=" << device.GetName() - << ", address=" << device.GetAddress().ToString(); + << ", address=" << device.GetMacAddress().ToString(); BluetoothDevice bt_device(&device); for (auto* observer : observer_list_.GetObservers()) { observer->DeviceRemoved(bt_device); @@ -199,7 +199,7 @@ void BluetoothClassicMedium::DeviceRemoved(api::BluetoothDevice& device) { void BluetoothClassicMedium::DeviceAddressChanged( api::BluetoothDevice& device, absl::string_view old_address) { VLOG(1) << "BT DeviceAddressChanged; name=" << device.GetName() - << ", address=" << device.GetAddress().ToString() + << ", address=" << device.GetMacAddress().ToString() << ", old_address=" << old_address; BluetoothDevice bt_device(&device); for (auto* observer : observer_list_.GetObservers()) { @@ -209,7 +209,7 @@ void BluetoothClassicMedium::DeviceAddressChanged( void BluetoothClassicMedium::DevicePairedChanged(api::BluetoothDevice& device, bool new_paired_status) { VLOG(1) << "BT DevicePairedChanged; name=" << device.GetName() - << ", address=" << device.GetAddress().ToString() + << ", address=" << device.GetMacAddress().ToString() << ", status=" << new_paired_status; BluetoothDevice bt_device(&device); for (auto* observer : observer_list_.GetObservers()) { @@ -219,7 +219,7 @@ void BluetoothClassicMedium::DevicePairedChanged(api::BluetoothDevice& device, void BluetoothClassicMedium::DeviceConnectedStateChanged( api::BluetoothDevice& device, bool connected) { VLOG(1) << "BT DeviceConnectedStateChanged: name=" << device.GetName() - << ", address=" << device.GetAddress().ToString() + << ", address=" << device.GetMacAddress().ToString() << ", connected=" << connected; BluetoothDevice bt_device(&device); for (auto* observer : observer_list_.GetObservers()) { 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 8d2c9c0d..4cc5a309 100644 --- a/internal/platform/implementation/apple/Tests/bluetooth_adapter_v2_test.mm +++ b/internal/platform/implementation/apple/Tests/bluetooth_adapter_v2_test.mm @@ -62,10 +62,10 @@ XCTAssertFalse(_adapter.SetName("TestName", true)); } -- (void)testGetAddress { +- (void)testGetMacAddress { // Currently hardcoded to return an empty MacAddress. nearby::MacAddress emptyAddress; - XCTAssertEqual(_adapter.GetAddress(), emptyAddress); + XCTAssertEqual(_adapter.GetMacAddress(), emptyAddress); } @end diff --git a/internal/platform/implementation/apple/bluetooth_adapter_v2.h b/internal/platform/implementation/apple/bluetooth_adapter_v2.h index 878a316e..6ecd609a 100644 --- a/internal/platform/implementation/apple/bluetooth_adapter_v2.h +++ b/internal/platform/implementation/apple/bluetooth_adapter_v2.h @@ -84,7 +84,7 @@ class BluetoothAdapter : public api::BluetoothAdapter { bool SetName(absl::string_view name, bool persist) override; // Returns BT MAC address assigned to this adapter. - MacAddress GetAddress() const override; + MacAddress GetMacAddress() const override; }; } // namespace apple diff --git a/internal/platform/implementation/apple/bluetooth_adapter_v2.mm b/internal/platform/implementation/apple/bluetooth_adapter_v2.mm index 1461c764..b7df2e63 100644 --- a/internal/platform/implementation/apple/bluetooth_adapter_v2.mm +++ b/internal/platform/implementation/apple/bluetooth_adapter_v2.mm @@ -64,7 +64,7 @@ bool BluetoothAdapter::SetName(absl::string_view name, bool persist) { } // TODO(b/290385712): Implement. -MacAddress BluetoothAdapter::GetAddress() const { +MacAddress BluetoothAdapter::GetMacAddress() const { return MacAddress(); } diff --git a/internal/platform/implementation/bluetooth_adapter.h b/internal/platform/implementation/bluetooth_adapter.h index b1d27842..988f604f 100644 --- a/internal/platform/implementation/bluetooth_adapter.h +++ b/internal/platform/implementation/bluetooth_adapter.h @@ -66,7 +66,7 @@ class BluetoothAdapter { virtual bool SetName(absl::string_view name) = 0; virtual bool SetName(absl::string_view name, bool persist) = 0; - virtual MacAddress GetAddress() const = 0; + virtual MacAddress GetMacAddress() const = 0; }; } // namespace api diff --git a/internal/platform/implementation/bluetooth_classic.h b/internal/platform/implementation/bluetooth_classic.h index 53241c23..d5c38095 100644 --- a/internal/platform/implementation/bluetooth_classic.h +++ b/internal/platform/implementation/bluetooth_classic.h @@ -40,7 +40,7 @@ class BluetoothDevice { // https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getName() virtual std::string GetName() const = 0; - virtual MacAddress GetAddress() const = 0; + virtual MacAddress GetMacAddress() const = 0; }; // https://developer.android.com/reference/android/bluetooth/BluetoothSocket.html. diff --git a/internal/platform/implementation/g3/ble_test.cc b/internal/platform/implementation/g3/ble_test.cc index c37bb9f1..55060007 100644 --- a/internal/platform/implementation/g3/ble_test.cc +++ b/internal/platform/implementation/g3/ble_test.cc @@ -48,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(MacAddress, GetAddress, (), (const, override)); + MOCK_METHOD(MacAddress, GetMacAddress, (), (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 38d12424..51365c48 100644 --- a/internal/platform/implementation/g3/bluetooth_adapter.cc +++ b/internal/platform/implementation/g3/bluetooth_adapter.cc @@ -37,7 +37,9 @@ BluetoothDevice::BluetoothDevice(BluetoothAdapter* adapter) std::string BluetoothDevice::GetName() const { return adapter_.GetName(); } -MacAddress BluetoothDevice::GetAddress() const { return adapter_.GetAddress(); } +MacAddress BluetoothDevice::GetMacAddress() const { + return adapter_.GetMacAddress(); +} BluetoothAdapter::BluetoothAdapter() { std::uint64_t raw_mac_addr = Prng().NextInt64() & kMacAddressMask; diff --git a/internal/platform/implementation/g3/bluetooth_adapter.h b/internal/platform/implementation/g3/bluetooth_adapter.h index 5810250b..3a3dd66b 100644 --- a/internal/platform/implementation/g3/bluetooth_adapter.h +++ b/internal/platform/implementation/g3/bluetooth_adapter.h @@ -39,7 +39,7 @@ class BluetoothDevice : public api::BluetoothDevice { // https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getName() std::string GetName() const override; - MacAddress GetAddress() const override; + MacAddress GetMacAddress() const override; BluetoothAdapter& GetAdapter() { return adapter_; } private: @@ -87,7 +87,7 @@ class BluetoothAdapter : public api::BluetoothAdapter { ABSL_LOCKS_EXCLUDED(mutex_); // Returns BT MAC address assigned to this adapter. - MacAddress GetAddress() const override { return mac_address_; } + MacAddress GetMacAddress() const override { return mac_address_; } BluetoothDevice& GetDevice() { return device_; } diff --git a/internal/platform/implementation/g3/bluetooth_classic.cc b/internal/platform/implementation/g3/bluetooth_classic.cc index 0095fb99..ec780d33 100644 --- a/internal/platform/implementation/g3/bluetooth_classic.cc +++ b/internal/platform/implementation/g3/bluetooth_classic.cc @@ -180,7 +180,7 @@ std::unique_ptr BluetoothClassicMedium::ConnectToService( // supported in tests. api::BluetoothDevice* device = MediumEnvironment::Instance().FindBluetoothDevice( - remote_device.GetAddress()); + remote_device.GetMacAddress()); if (device == nullptr) { LOG(ERROR) << "G3 ConnectToService [peer]: device=" << &remote_device << " not found"; diff --git a/internal/platform/implementation/windows/ble_test.cc b/internal/platform/implementation/windows/ble_test.cc index 870534c9..97042d91 100644 --- a/internal/platform/implementation/windows/ble_test.cc +++ b/internal/platform/implementation/windows/ble_test.cc @@ -51,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(MacAddress, GetAddress, (), (const, override)); + MOCK_METHOD(MacAddress, GetMacAddress, (), (const, override)); }; } // namespace diff --git a/internal/platform/implementation/windows/bluetooth_adapter.cc b/internal/platform/implementation/windows/bluetooth_adapter.cc index eb74da9f..02b38cb3 100644 --- a/internal/platform/implementation/windows/bluetooth_adapter.cc +++ b/internal/platform/implementation/windows/bluetooth_adapter.cc @@ -821,7 +821,7 @@ BluetoothAdapter::GetGenericBluetoothAdapterInstanceID() const { } // Returns BT MAC address assigned to this adapter. -MacAddress BluetoothAdapter::GetAddress() const { +MacAddress BluetoothAdapter::GetMacAddress() const { if (windows_bluetooth_adapter_ == nullptr) { LOG(ERROR) << __func__ << ": No Bluetooth adapter on this device."; return MacAddress(); diff --git a/internal/platform/implementation/windows/bluetooth_adapter.h b/internal/platform/implementation/windows/bluetooth_adapter.h index 975f1da7..4ef4d9b8 100644 --- a/internal/platform/implementation/windows/bluetooth_adapter.h +++ b/internal/platform/implementation/windows/bluetooth_adapter.h @@ -83,7 +83,7 @@ class BluetoothAdapter : public api::BluetoothAdapter { bool SetName(absl::string_view name, bool persist) override; // Returns BT MAC address assigned to this adapter. - MacAddress GetAddress() const override; + MacAddress GetMacAddress() const override; // Returns bluetooth device name from registry std::string GetNameFromRegistry(PHKEY hKey) const; diff --git a/internal/platform/implementation/windows/bluetooth_adapter_test.cc b/internal/platform/implementation/windows/bluetooth_adapter_test.cc index 79bf7888..6d4d6dc5 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_GetAddress) { +TEST(BluetoothAdapter, DISABLED_GetMacAddress) { BluetoothAdapter bluetooth_adapter; - EXPECT_TRUE(bluetooth_adapter.GetAddress().IsSet()); + EXPECT_TRUE(bluetooth_adapter.GetMacAddress().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 f8ec99cd..c796c1e6 100644 --- a/internal/platform/implementation/windows/bluetooth_classic_device.cc +++ b/internal/platform/implementation/windows/bluetooth_classic_device.cc @@ -72,7 +72,7 @@ BluetoothDevice::BluetoothDevice( } // Returns BT MAC address assigned to this device. -MacAddress BluetoothDevice::GetAddress() const { return mac_address_; } +MacAddress BluetoothDevice::GetMacAddress() const { return mac_address_; } // Checks cache first, will check uncached if no result. RfcommDeviceService BluetoothDevice::GetRfcommServiceForIdAsync( diff --git a/internal/platform/implementation/windows/bluetooth_classic_device.h b/internal/platform/implementation/windows/bluetooth_classic_device.h index 5a087d2e..ba321edf 100644 --- a/internal/platform/implementation/windows/bluetooth_classic_device.h +++ b/internal/platform/implementation/windows/bluetooth_classic_device.h @@ -70,7 +70,7 @@ class BluetoothDevice : public api::BluetoothDevice { std::string GetName() const override { return name_; } // Returns BT MAC address assigned to this device. - MacAddress GetAddress() const override; + MacAddress GetMacAddress() 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 24f89c52..7dbaf96a 100644 --- a/internal/platform/implementation/windows/bluetooth_classic_medium.cc +++ b/internal/platform/implementation/windows/bluetooth_classic_medium.cc @@ -173,7 +173,7 @@ std::unique_ptr BluetoothClassicMedium::ConnectToService( } BluetoothDevice* remote_device_to_connect_ = - GetRemoteDeviceInternal(remote_device.GetAddress()); + GetRemoteDeviceInternal(remote_device.GetMacAddress()); if (remote_device_to_connect_ == nullptr || remote_device_to_connect_->GetId().empty()) { @@ -293,11 +293,11 @@ api::BluetoothDevice* BluetoothClassicMedium::GetRemoteDevice( std::unique_ptr BluetoothClassicMedium::CreatePairing( api::BluetoothDevice& remote_device) { VLOG(1) << __func__ << ": Start to createPairing with device: " - << remote_device.GetAddress().ToString(); + << remote_device.GetMacAddress().ToString(); try { winrt::Windows::Devices::Bluetooth::BluetoothDevice bluetooth_device = winrt::Windows::Devices::Bluetooth::BluetoothDevice:: - FromBluetoothAddressAsync(remote_device.GetAddress().address()) + FromBluetoothAddressAsync(remote_device.GetMacAddress().address()) .get(); winrt::Windows::Devices::Enumeration::DeviceInformationCustomPairing custom_pairing = diff --git a/internal/platform/medium_environment.cc b/internal/platform/medium_environment.cc index 02d4c815..24d65303 100644 --- a/internal/platform/medium_environment.cc +++ b/internal/platform/medium_environment.cc @@ -240,8 +240,8 @@ api::BluetoothDevice* MediumEnvironment::FindBluetoothDevice( for (auto& item : bluetooth_mediums_) { auto* adapter = item.second.adapter; if (!adapter) continue; - LOG(INFO) << " Adapter: " << adapter->GetAddress().ToString(); - if (adapter->GetAddress() == mac_address) { + LOG(INFO) << " Adapter: " << adapter->GetMacAddress().ToString(); + if (adapter->GetMacAddress() == mac_address) { device = bluetooth_adapters_[adapter]; break; }