Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60f87b20 authored by Hsin-chen Chuang's avatar Hsin-chen Chuang Committed by Gerrit Code Review
Browse files

Merge "floss: Fix racing in start/stop scan"

parents c4d784dc 75a56d59
Loading
Loading
Loading
Loading
+13 −14
Original line number Diff line number Diff line
@@ -1615,13 +1615,6 @@ impl BluetoothGatt {
        scanner_id: u8,
        filter: Option<ScanFilter>,
    ) -> BtStatus {
        let has_active_unfiltered_scanner = self
            .scanners
            .lock()
            .unwrap()
            .iter()
            .any(|(_uuid, scanner)| scanner.is_active && scanner.filter.is_none());

        let gatt_async = self.gatt_async.clone();
        let scanners = self.scanners.clone();
        let is_msft_supported = self.is_msft_supported();
@@ -1657,6 +1650,12 @@ impl BluetoothGatt {
                    log::debug!("Added adv monitor handle = {}", monitor_handle);
                }

                let has_active_unfiltered_scanner = scanners
                    .lock()
                    .unwrap()
                    .iter()
                    .any(|(_uuid, scanner)| scanner.is_active && scanner.filter.is_none());

                if !gatt_async
                    .msft_adv_monitor_enable(!has_active_unfiltered_scanner)
                    .await
@@ -1941,14 +1940,8 @@ impl IBluetoothGatt for BluetoothGatt {
            }
        };

        let has_active_unfiltered_scanner = self
            .scanners
            .lock()
            .unwrap()
            .iter()
            .any(|(_uuid, scanner)| scanner.is_active && scanner.filter.is_none());

        let gatt_async = self.gatt_async.clone();
        let scanners = self.scanners.clone();
        let is_msft_supported = self.is_msft_supported();
        tokio::spawn(async move {
            // The two operations below (monitor remove, update scan) happen one after another, and
@@ -1963,6 +1956,12 @@ impl IBluetoothGatt for BluetoothGatt {
                    let _res = gatt_async.msft_adv_monitor_remove(handle).await;
                }

                let has_active_unfiltered_scanner = scanners
                    .lock()
                    .unwrap()
                    .iter()
                    .any(|(_uuid, scanner)| scanner.is_active && scanner.filter.is_none());

                if !gatt_async
                    .msft_adv_monitor_enable(!has_active_unfiltered_scanner)
                    .await