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

Commit d0a5c394 authored by Joseph Hwang's avatar Joseph Hwang
Browse files

floss: check msft supported

The start_scan() and stop_scan() should check whether the MSFT
extension is supported before doing add/remove/enable operations.

Bug: 270629001
Tag: #floss
Test: ./build.py --target test
Test: Manual test on a ChromeOS device not supporting the MSFT
extension, e.g., octopus/blooglet
  localhost # btclient
  bluetooth> le-scan register-scanner
  bluetooth> le-scan start-scan 1
  bluetooth> le-scan stop-scan 1
The btadapterd should not crash. The btclient should not output
messages like
  main/shim/le_scanning_manager.cc - MsftAdvMonitorEnable: in shim layer

Change-Id: I41fca51eb6418332e03df052164893a3105cd7eb
parent e3545c86
Loading
Loading
Loading
Loading
+41 −34
Original line number Diff line number Diff line
@@ -1696,8 +1696,10 @@ impl IBluetoothGatt for BluetoothGatt {
            let mut gatt_async = gatt_async.lock().await;

            // Add and enable the monitor filter only when the MSFT extension is supported.
            if let (true, Some(filter)) = (is_msft_supported, filter) {
                let monitor_handle = match gatt_async.msft_adv_monitor_add((&filter).into()).await {
            if is_msft_supported {
                if let Some(filter) = filter {
                    let monitor_handle =
                        match gatt_async.msft_adv_monitor_add((&filter).into()).await {
                            Ok((handle, 0)) => handle,
                            _ => {
                                log::error!("Error adding advertisement monitor");
@@ -1726,6 +1728,7 @@ impl IBluetoothGatt for BluetoothGatt {
                    // the state machine to avoid calling enable/disable if it's already at that state
                    log::error!("Error updating Advertisement Monitor enable");
                }
            }

            gatt_async.update_scan().await;
        });
@@ -1755,6 +1758,7 @@ impl IBluetoothGatt for BluetoothGatt {
            .any(|(_uuid, scanner)| scanner.is_active && scanner.filter.is_none());

        let gatt_async = self.gatt_async.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
            // cannot be interleaved with other GATT async operations.
@@ -1762,6 +1766,8 @@ impl IBluetoothGatt for BluetoothGatt {
            // at the end of this block.
            let mut gatt_async = gatt_async.lock().await;

            // Remove and disable the monitor only when the MSFT extension is supported.
            if is_msft_supported {
                if let Some(handle) = monitor_handle {
                    let _res = gatt_async.msft_adv_monitor_remove(handle).await;
                }
@@ -1773,6 +1779,7 @@ impl IBluetoothGatt for BluetoothGatt {
                {
                    log::error!("Error updating Advertisement Monitor enable");
                }
            }

            gatt_async.update_scan().await;
        });