Loading system/gd/rust/linux/service/src/main.rs +11 −2 Original line number Diff line number Diff line Loading @@ -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())))); Loading Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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!() Loading system/gd/rust/linux/stack/src/bluetooth.rs +15 −3 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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 Loading Loading @@ -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); Loading Loading @@ -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); Loading @@ -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()); }); Loading system/gd/rust/linux/stack/src/bluetooth_qa.rs +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 Loading @@ -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; } } Loading system/gd/rust/linux/stack/src/lib.rs +7 −0 Original line number Diff line number Diff line Loading @@ -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}; Loading Loading @@ -128,6 +130,7 @@ pub enum Message { // Qualification Only QaAddMediaPlayer(String, bool), QaRfcommSendMsc(u8, String), QaOnDiscoverableModeChanged(BtDiscMode), } /// Represents suspend mode of a module. Loading Loading @@ -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; Loading Loading @@ -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); } } } } Loading Loading
system/gd/rust/linux/service/src/main.rs +11 −2 Original line number Diff line number Diff line Loading @@ -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())))); Loading Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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!() Loading
system/gd/rust/linux/stack/src/bluetooth.rs +15 −3 Original line number Diff line number Diff line Loading @@ -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) { Loading @@ -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 Loading Loading @@ -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); Loading Loading @@ -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); Loading @@ -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()); }); Loading
system/gd/rust/linux/stack/src/bluetooth_qa.rs +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 Loading @@ -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; } } Loading
system/gd/rust/linux/stack/src/lib.rs +7 −0 Original line number Diff line number Diff line Loading @@ -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}; Loading Loading @@ -128,6 +130,7 @@ pub enum Message { // Qualification Only QaAddMediaPlayer(String, bool), QaRfcommSendMsc(u8, String), QaOnDiscoverableModeChanged(BtDiscMode), } /// Represents suspend mode of a module. Loading Loading @@ -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; Loading Loading @@ -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); } } } } Loading