mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Fix crash in BleV2MediumTest::StartScanningTmp
This fixes flakiness in the tests. PiperOrigin-RevId: 551009093
This commit is contained in:
committed by
Copybara-Service
parent
ae69b8ff4e
commit
dfdb5a6405
@@ -89,7 +89,7 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
MutexLock lock(&mutex_);
|
||||
if (!peripherals_.contains(&peripheral)) {
|
||||
NEARBY_LOGS(INFO) << "Peripheral impl=" << &peripheral
|
||||
<< " is not existed; adds it to the map.";
|
||||
<< " does not exist; add it to the map.";
|
||||
peripherals_.insert(&peripheral);
|
||||
}
|
||||
|
||||
@@ -134,25 +134,24 @@ std::unique_ptr<api::ble_v2::BleMedium::ScanningSession>
|
||||
BleV2Medium::StartScanningTmp(
|
||||
const Uuid& service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanningCallback callback) {
|
||||
// auto scan_callback = std::move(callback.advertisement_found_cb);
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
if (impl_->StartScanning(
|
||||
service_uuid, tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanCallback{
|
||||
.advertisement_found_cb =
|
||||
[this, &callback](api::ble_v2::BlePeripheral& peripheral,
|
||||
BleAdvertisementData advertisement_data) {
|
||||
[this,
|
||||
found_callback = std::move(callback.advertisement_found_cb)](
|
||||
api::ble_v2::BlePeripheral& peripheral,
|
||||
BleAdvertisementData advertisement_data) mutable {
|
||||
MutexLock lock(&mutex_);
|
||||
if (!peripherals_.contains(&peripheral)) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "There is no need to callback due to peripheral "
|
||||
"impl="
|
||||
<< &peripheral << ", which already exists.";
|
||||
<< "Peripheral impl=" << &peripheral
|
||||
<< " does not exist; add it to the map.";
|
||||
peripherals_.insert(&peripheral);
|
||||
}
|
||||
callback.advertisement_found_cb(peripheral,
|
||||
advertisement_data);
|
||||
found_callback(peripheral, advertisement_data);
|
||||
},
|
||||
})) {
|
||||
callback.start_scanning_result(absl::OkStatus());
|
||||
|
||||
Reference in New Issue
Block a user