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

Commit b9ecf52f authored by John Lai's avatar John Lai Committed by Automerger Merge Worker
Browse files

Merge "Floss: Caches the discoverable mode" am: 2c9707c9 am: 2f089fea

parents 4a423b0c 2f089fea
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -180,7 +180,8 @@ fn main() -> Result<(), Box<dyn Error>> {
        tx.clone(),
        bluetooth_admin.clone(),
    ))));
    let qa = Arc::new(Mutex::new(Box::new(BluetoothQA::new(tx.clone()))));
    let bluetooth_qa = Arc::new(Mutex::new(Box::new(BluetoothQA::new(tx.clone()))));

    let dis =
        Arc::new(Mutex::new(Box::new(DeviceInformation::new(bluetooth_gatt.clone(), tx.clone()))));

@@ -226,6 +227,7 @@ fn main() -> Result<(), Box<dyn Error>> {
            bt_sock_mgr.clone(),
            bluetooth_admin.clone(),
            dis.clone(),
            bluetooth_qa.clone(),
        ));

        // Set up the disconnect watcher to monitor client disconnects.
@@ -370,7 +372,11 @@ fn main() -> Result<(), Box<dyn Error>> {
            logging.clone(),
        );

        cr.lock().unwrap().insert(make_object_name(adapter_index, "qa"), &[qa_iface], qa.clone());
        cr.lock().unwrap().insert(
            make_object_name(adapter_index, "qa"),
            &[qa_iface],
            bluetooth_qa.clone(),
        );

        // Hold locks and initialize all interfaces. This must be done AFTER DBus is
        // initialized so DBus can properly enforce user policies.
@@ -410,6 +416,9 @@ fn main() -> Result<(), Box<dyn Error>> {
            }
        }

        // Initialize the bluetooth_qa
        bluetooth.lock().unwrap().cache_discoverable_mode_into_qa();

        // Serve clients forever.
        future::pending::<()>().await;
        unreachable!()
+15 −3
Original line number Diff line number Diff line
@@ -745,7 +745,7 @@ impl Bluetooth {
    }

    /// Returns adapter's discoverable mode.
    pub(crate) fn get_discoverable_mode(&self) -> BtDiscMode {
    pub fn get_discoverable_mode(&self) -> BtDiscMode {
        let off_mode = BtDiscMode::NonDiscoverable;

        match self.properties.get(&BtPropertyType::AdapterScanMode) {
@@ -761,6 +761,16 @@ impl Bluetooth {
        }
    }

    /// Caches the discoverable mode into BluetoothQA.
    pub fn cache_discoverable_mode_into_qa(&self) {
        let disc_mode = self.get_discoverable_mode();

        let txl = self.tx.clone();
        tokio::spawn(async move {
            let _ = txl.send(Message::QaOnDiscoverableModeChanged(disc_mode)).await;
        });
    }

    /// Returns all bonded and connected devices.
    pub(crate) fn get_bonded_and_connected_devices(&mut self) -> Vec<BluetoothDevice> {
        self.bonded_devices
@@ -1213,6 +1223,8 @@ impl BtifBluetoothCallbacks for Bluetooth {

        // Update local property cache
        for prop in properties {
            self.properties.insert(prop.get_type(), prop.clone());

            match &prop {
                BluetoothProperty::BdAddr(bdaddr) => {
                    self.update_local_address(&bdaddr);
@@ -1241,6 +1253,8 @@ impl BtifBluetoothCallbacks for Bluetooth {
                    });
                }
                BluetoothProperty::AdapterScanMode(mode) => {
                    self.cache_discoverable_mode_into_qa();

                    self.callbacks.for_all_callbacks(|callback| {
                        callback
                            .on_discoverable_changed(*mode == BtScanMode::ConnectableDiscoverable);
@@ -1249,8 +1263,6 @@ impl BtifBluetoothCallbacks for Bluetooth {
                _ => {}
            }

            self.properties.insert(prop.get_type(), prop.clone());

            self.callbacks.for_all_callbacks(|callback| {
                callback.on_adapter_property_changed(prop.get_type());
            });
+7 −1
Original line number Diff line number Diff line
//! Anything related to the Qualification API (IBluetoothQA).

use crate::Message;
use bt_topshim::btif::BtDiscMode;
use tokio::sync::mpsc::Sender;

/// Defines the Qualification API
@@ -11,11 +12,16 @@ pub trait IBluetoothQA {

pub struct BluetoothQA {
    tx: Sender<Message>,
    disc_mode: BtDiscMode,
}

impl BluetoothQA {
    pub fn new(tx: Sender<Message>) -> BluetoothQA {
        BluetoothQA { tx }
        BluetoothQA { tx, disc_mode: BtDiscMode::NonDiscoverable }
    }

    pub fn handle_discoverable_mode_changed(&mut self, mode: BtDiscMode) {
        self.disc_mode = mode;
    }
}

+7 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ pub mod socket_manager;
pub mod suspend;
pub mod uuid;

use bluetooth_qa::BluetoothQA;
use bt_topshim::btif::BtDiscMode;
use log::debug;
use num_derive::{FromPrimitive, ToPrimitive};
use std::sync::{Arc, Mutex};
@@ -128,6 +130,7 @@ pub enum Message {
    // Qualification Only
    QaAddMediaPlayer(String, bool),
    QaRfcommSendMsc(u8, String),
    QaOnDiscoverableModeChanged(BtDiscMode),
}

/// Represents suspend mode of a module.
@@ -164,6 +167,7 @@ impl Stack {
        bluetooth_socketmgr: Arc<Mutex<Box<BluetoothSocketManager>>>,
        bluetooth_admin: Arc<Mutex<Box<BluetoothAdmin>>>,
        bluetooth_dis: Arc<Mutex<Box<DeviceInformation>>>,
        bluetooth_qa: Arc<Mutex<Box<BluetoothQA>>>,
    ) {
        loop {
            let m = rx.recv().await;
@@ -357,6 +361,9 @@ impl Stack {
                Message::QaRfcommSendMsc(dlci, addr) => {
                    bluetooth_socketmgr.lock().unwrap().rfcomm_send_msc(dlci, addr);
                }
                Message::QaOnDiscoverableModeChanged(mode) => {
                    bluetooth_qa.lock().unwrap().handle_discoverable_mode_changed(mode);
                }
            }
        }
    }