Fixed a bug in GATT client

PiperOrigin-RevId: 662666561
This commit is contained in:
Guogang Li
2024-08-13 15:05:47 -07:00
committed by Copybara-Service
parent a5efe8b924
commit cad1ef6bf3
@@ -1216,8 +1216,12 @@ void BleV2Medium::AdvertisementFoundHandler(
bool BleV2Medium::GetRemotePeripheral(const std::string& mac_address,
GetRemotePeripheralCallback callback) {
absl::MutexLock lock(&mutex_);
BleV2Peripheral* peripheral = GetOrCreatePeripheral(mac_address);
BleV2Peripheral* peripheral = nullptr;
{
absl::MutexLock lock(&mutex_);
BleV2Peripheral* peripheral = GetOrCreatePeripheral(mac_address);
}
if (peripheral != nullptr && peripheral->Ok()) {
callback(*peripheral);
return true;
@@ -1227,8 +1231,12 @@ bool BleV2Medium::GetRemotePeripheral(const std::string& mac_address,
bool BleV2Medium::GetRemotePeripheral(api::ble_v2::BlePeripheral::UniqueId id,
GetRemotePeripheralCallback callback) {
absl::MutexLock lock(&mutex_);
BleV2Peripheral* peripheral = GetPeripheral(id);
BleV2Peripheral* peripheral = nullptr;
{
absl::MutexLock lock(&mutex_);
BleV2Peripheral* peripheral = GetPeripheral(id);
}
if (peripheral == nullptr) {
NEARBY_LOGS(WARNING) << __func__ << ": No matched peripheral device.";
return false;