internal fix

PiperOrigin-RevId: 589025655
This commit is contained in:
Hai Shang
2023-12-07 23:21:12 -08:00
committed by Copybara-Service
parent d710bff241
commit dde1588871
2 changed files with 47 additions and 7 deletions
@@ -247,6 +247,48 @@ TEST_F(BleTest, CanStartDiscovery) {
env_.Stop();
}
TEST_F(BleTest, HandleDupeFindingsFromDiscovery) {
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
Ble ble_a{radio_a};
Ble ble_b{radio_b};
radio_a.Enable();
radio_b.Enable();
std::string service_id(kServiceID);
ByteArray advertisement_bytes{std::string(kAdvertisementString)};
std::string fast_advertisement_service_uuid(kFastAdvertisementServiceUuid);
// expecting two discoveries from the same peripheral.
CountDownLatch discovery_latch(2);
// Expecting the peripheral lost will trigger lost_cb.
CountDownLatch lost_latch(1);
ble_b.StartAdvertising(service_id, advertisement_bytes,
fast_advertisement_service_uuid);
EXPECT_TRUE(ble_a.StartScanning(
service_id, fast_advertisement_service_uuid,
DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&discovery_latch](
BlePeripheral& peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { discovery_latch.CountDown(); },
.peripheral_lost_cb =
[&lost_latch](BlePeripheral& peripheral,
const std::string& service_id) {
lost_latch.CountDown();
},
}));
ble_b.StartAdvertising(service_id, advertisement_bytes,
fast_advertisement_service_uuid);
EXPECT_TRUE(discovery_latch.Await(kWaitDuration).result());
ble_b.StopAdvertising(service_id);
EXPECT_TRUE(lost_latch.Await(kWaitDuration).result());
EXPECT_TRUE(ble_a.StopScanning(service_id));
env_.Stop();
}
TEST_F(BleTest, CanStartAndStopLegacyAdvertising) {
env_.Start();
BluetoothRadio radio_a;
+5 -7
View File
@@ -49,13 +49,11 @@ bool BleMedium::StartScanning(
auto pair = peripherals_.emplace(
&peripheral, absl::make_unique<ScanningInfo>());
auto& context = *pair.first->second;
if (pair.second) {
context.peripheral = BlePeripheral(&peripheral);
discovered_peripheral_callback_.peripheral_discovered_cb(
context.peripheral, service_id,
context.peripheral.GetAdvertisementBytes(service_id),
fast_advertisement);
}
context.peripheral = BlePeripheral(&peripheral);
discovered_peripheral_callback_.peripheral_discovered_cb(
context.peripheral, service_id,
context.peripheral.GetAdvertisementBytes(service_id),
fast_advertisement);
},
.peripheral_lost_cb =
[this](api::BlePeripheral& peripheral,