mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Change GetAddress() to GetMacAddress() in BluetoothAdapter
PiperOrigin-RevId: 834896610
This commit is contained in:
committed by
Copybara-Service
parent
023db9bd33
commit
dd943af8e9
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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, (),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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_; }
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ std::unique_ptr<api::BluetoothSocket> 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";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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_; }
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ std::unique_ptr<api::BluetoothSocket> 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<api::BluetoothPairing> 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 =
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user