Remove unused methods.

PiperOrigin-RevId: 756053350
This commit is contained in:
Francis Tsui
2025-05-07 16:36:04 -07:00
committed by Copybara-Service
parent 4beed5b72a
commit 59e527dbe3
17 changed files with 57 additions and 263 deletions
@@ -164,12 +164,6 @@ class BleMedium : public api::ble_v2::BleMedium {
// This is currently always false for all Apple hardware.
bool IsExtendedAdvertisementsAvailable() override;
// A peripheral cannot be retreived via MAC address on Apple platforms.
//
// This always returns false and does not call the callback.
bool GetRemotePeripheral(const std::string &mac_address,
api::ble_v2::BleMedium::GetRemotePeripheralCallback callback) override;
// Returns true if `id` refers to a known BLE peripheral and calls `callback` with a reference to
// said peripheral that is only guaranteed to be available for the duration of the callback.
// Otherwise, does not call the callback and returns false.
@@ -536,13 +536,6 @@ bool BleMedium::IsExtendedAdvertisementsAvailable() {
return [medium_ supportsExtendedAdvertisements];
}
bool BleMedium::GetRemotePeripheral(const std::string &mac_address,
api::ble_v2::BleMedium::GetRemotePeripheralCallback callback) {
// Apple does not expose MAC address information, so we cannot retreive a peripheral via MAC
// address.
return false;
}
bool BleMedium::GetRemotePeripheral(api::ble_v2::BlePeripheral::UniqueId unique_id,
api::ble_v2::BleMedium::GetRemotePeripheralCallback callback) {
// If the unique_id is 0, that means it's the local/empty peripheral. We must return "true"
+1 -9
View File
@@ -117,7 +117,7 @@ class BlePeripheral {
void* GetPlatformData() const { return platform_data_; }
bool IsSet() const { return unique_id_ != 0 || address_.IsSet(); }
bool IsSet() const { return GetUniqueId() != 0 || !GetAddress().empty(); }
private:
UniqueId unique_id_ = 0;
@@ -623,14 +623,6 @@ class BleMedium {
// Requests if support extended advertisement.
virtual bool IsExtendedAdvertisementsAvailable() = 0;
// Calls `callback` and returns true if `mac_address` is a valid BLE address.
// Otherwise, does not call the callback and returns false.
//
// This method is not available on Apple platforms and will always return
// false, ignoring the callback.
virtual bool GetRemotePeripheral(const std::string& mac_address,
GetRemotePeripheralCallback callback) = 0;
// Calls `callback` and returns true if `id` refers to a known BLE peripheral.
// Otherwise, does not call the callback and returns false.
virtual bool GetRemotePeripheral(BlePeripheral::UniqueId id,
@@ -349,36 +349,6 @@ bool BleV2Medium::IsExtendedAdvertisementsAvailable() {
return is_extended_advertisements_available_;
}
bool BleV2Medium::GetRemotePeripheral(const std::string& mac_address,
GetRemotePeripheralCallback callback) {
NEARBY_LOGS(INFO) << "GetRemotePeripheral, address= " << mac_address;
absl::MutexLock lock(&mutex_);
for (auto& item : remote_peripherals_) {
auto* peripheral = item.second.get();
if (peripheral->GetAddress() == mac_address) {
callback(*peripheral);
return true;
}
}
BleV2Medium* remote_medium = dynamic_cast<BleV2Medium*>(
MediumEnvironment::Instance().FindBleV2Medium(mac_address));
if (remote_medium == nullptr) {
return false;
}
api::ble_v2::BlePeripheral::UniqueId id =
remote_medium->GetPeripheral().GetUniqueId();
BluetoothAdapter& adapter = remote_medium->GetAdapter();
MacAddress address;
if (!MacAddress::FromString(adapter.GetMacAddress(), address)) {
return false;
}
remote_peripherals_[id] =
std::make_unique<api::ble_v2::BlePeripheral>(id, address);
remote_peripherals_[id]->SetPlatformData(&adapter);
callback(*remote_peripherals_[id]);
return true;
}
bool BleV2Medium::GetRemotePeripheral(api::ble_v2::BlePeripheral::UniqueId id,
GetRemotePeripheralCallback callback) {
absl::MutexLock lock(&mutex_);
@@ -194,9 +194,6 @@ class BleV2Medium : public api::ble_v2::BleMedium {
api::ble_v2::BlePeripheral& GetPeripheral() { return peripheral_; }
bool GetRemotePeripheral(const std::string& mac_address,
GetRemotePeripheralCallback callback) override;
bool GetRemotePeripheral(api::ble_v2::BlePeripheral::UniqueId id,
GetRemotePeripheralCallback callback) override;
@@ -1299,26 +1299,6 @@ void BleV2Medium::AdvertisementFoundHandler(
}
}
bool BleV2Medium::GetRemotePeripheral(const std::string& mac_address,
GetRemotePeripheralCallback callback) {
MacAddress bluetooth_address;
if (!MacAddress::FromString(mac_address, bluetooth_address)) {
LOG(WARNING) << __func__ << ": Invalid MAC address: " << mac_address;
return false;
}
api::ble_v2::BlePeripheral* peripheral = nullptr;
{
absl::MutexLock lock(&mutex_);
peripheral = GetOrCreatePeripheral(bluetooth_address);
}
if (peripheral != nullptr && peripheral->IsSet()) {
callback(*peripheral);
return true;
}
return false;
}
bool BleV2Medium::GetRemotePeripheral(api::ble_v2::BlePeripheral::UniqueId id,
GetRemotePeripheralCallback callback) {
MacAddress bluetooth_address;
@@ -80,10 +80,6 @@ class BleV2Medium : public api::ble_v2::BleMedium {
CancellationFlag* cancellation_flag) override ABSL_LOCKS_EXCLUDED(mutex_);
bool IsExtendedAdvertisementsAvailable() override;
bool GetRemotePeripheral(const std::string& mac_address,
GetRemotePeripheralCallback callback) override
ABSL_LOCKS_EXCLUDED(mutex_);
bool GetRemotePeripheral(api::ble_v2::BlePeripheral::UniqueId id,
GetRemotePeripheralCallback callback) override
ABSL_LOCKS_EXCLUDED(mutex_);