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

Commit 15e3f645 authored by Ying Hsu's avatar Ying Hsu Committed by Gerrit Code Review
Browse files

Merge "floss: Disable scanning interface when adapter is off" into main

parents 217b5159 70c5f20b
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -684,6 +684,8 @@ impl Bluetooth {
    }

    pub fn init_profiles(&mut self) {
        self.bluetooth_gatt.lock().unwrap().enable(true);

        let sdptx = self.tx.clone();
        self.sdp = Some(Sdp::new(&self.intf.lock().unwrap()));
        self.sdp.as_mut().unwrap().initialize(SdpCallbacksDispatcher {
@@ -1898,7 +1900,11 @@ impl IBluetooth for Bluetooth {
    }

    fn disable(&mut self) -> bool {
        self.intf.lock().unwrap().disable() == 0
        let success = self.intf.lock().unwrap().disable() == 0;
        if success {
            self.bluetooth_gatt.lock().unwrap().enable(false);
        }
        success
    }

    fn cleanup(&mut self) {
+18 −0
Original line number Diff line number Diff line
@@ -1403,6 +1403,7 @@ pub struct BluetoothGatt {
    small_rng: SmallRng,

    gatt_async: Arc<tokio::sync::Mutex<GattAsyncIntf>>,
    enabled: bool,
}

impl BluetoothGatt {
@@ -1436,6 +1437,7 @@ impl BluetoothGatt {
                async_helper_msft_adv_monitor_remove,
                async_helper_msft_adv_monitor_enable,
            })),
            enabled: false,
        }
    }

@@ -1530,6 +1532,10 @@ impl BluetoothGatt {
        });
    }

    pub fn enable(&mut self, enabled: bool) {
        self.enabled = enabled;
    }

    /// Remove a scanner callback and unregisters all scanners associated with that callback.
    pub fn remove_scanner_callback(&mut self, callback_id: u32) -> bool {
        let affected_scanner_ids: Vec<u8> = self
@@ -1641,6 +1647,10 @@ impl BluetoothGatt {
    /// The resume_scan method is used to resume scanning after system suspension.
    /// It assumes that scanner.filter has already had the filter data.
    fn resume_scan(&mut self, scanner_id: u8) -> BtStatus {
        if !self.enabled {
            return BtStatus::Fail;
        }

        let scan_suspend_mode = self.get_scan_suspend_mode();
        if scan_suspend_mode != SuspendMode::Normal && scan_suspend_mode != SuspendMode::Resuming {
            return BtStatus::Busy;
@@ -2004,6 +2014,10 @@ impl IBluetoothGatt for BluetoothGatt {
        settings: Option<ScanSettings>,
        filter: Option<ScanFilter>,
    ) -> BtStatus {
        if !self.enabled {
            return BtStatus::Fail;
        }

        let scan_suspend_mode = self.get_scan_suspend_mode();
        if scan_suspend_mode != SuspendMode::Normal && scan_suspend_mode != SuspendMode::Resuming {
            return BtStatus::Busy;
@@ -2036,6 +2050,10 @@ impl IBluetoothGatt for BluetoothGatt {
    }

    fn stop_scan(&mut self, scanner_id: u8) -> BtStatus {
        if !self.enabled {
            return BtStatus::Fail;
        }

        let scan_suspend_mode = self.get_scan_suspend_mode();
        if scan_suspend_mode != SuspendMode::Normal && scan_suspend_mode != SuspendMode::Suspending
        {