Loading system/gd/rust/linux/service/src/iface_bluetooth_media.rs +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ impl IBluetoothMediaCallback for BluetoothMediaCallbackDBus { bits_per_sample: i32, channel_mode: i32, hfp_cap: i32, name: String, ) { dbus_generated!() } Loading system/gd/rust/linux/service/src/main.rs +2 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,8 @@ fn main() -> Result<(), Box<dyn Error>> { { intf.lock().unwrap().initialize(get_bt_dispatcher(tx.clone()), args); bluetooth_media.lock().unwrap().set_adapter(bluetooth.clone()); let mut bluetooth = bluetooth.lock().unwrap(); bluetooth.init_profiles(); bluetooth.enable(); Loading system/gd/rust/linux/stack/src/bluetooth_media.rs +30 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ use tokio::sync::mpsc::Sender; use tokio::task::JoinHandle; use tokio::time::{sleep, Duration}; use crate::bluetooth::{Bluetooth, BluetoothDevice, IBluetooth}; use crate::Message; const DEFAULT_PROFILE_DISCOVERY_TIMEOUT_SEC: u64 = 5; Loading Loading @@ -69,6 +70,7 @@ pub trait IBluetoothMediaCallback { bits_per_sample: i32, channel_mode: i32, hfp_cap: i32, name: String, ); /// Loading @@ -93,6 +95,7 @@ pub struct BluetoothMedia { callbacks: Arc<Mutex<Vec<(u32, Box<dyn IBluetoothMediaCallback + Send>)>>>, callback_last_id: u32, tx: Sender<Message>, adapter: Option<Arc<Mutex<Box<Bluetooth>>>>, a2dp: Option<A2dp>, avrcp: Option<Avrcp>, a2dp_states: HashMap<RawAddress, BtavConnectionState>, Loading @@ -111,6 +114,7 @@ impl BluetoothMedia { callbacks: Arc::new(Mutex::new(vec![])), callback_last_id: 0, tx, adapter: None, a2dp: None, avrcp: None, a2dp_states: HashMap::new(), Loading @@ -122,6 +126,10 @@ impl BluetoothMedia { } } pub fn set_adapter(&mut self, adapter: Arc<Mutex<Box<Bluetooth>>>) { self.adapter = Some(adapter); } pub fn dispatch_a2dp_callbacks(&mut self, cb: A2dpCallbacks) { match cb { A2dpCallbacks::ConnectionState(addr, state) => { Loading Loading @@ -248,6 +256,7 @@ impl BluetoothMedia { callbacks: Arc<Mutex<Vec<(u32, Box<dyn IBluetoothMediaCallback + Send>)>>>, cap: A2dpCodecConfig, hfp_cap: HfpCodecCapability, name: String, is_delayed: bool, ) -> bool { // Closure used to lock and trigger the device added callbacks. Loading @@ -259,6 +268,7 @@ impl BluetoothMedia { cap.bits_per_sample, cap.channel_mode, hfp_cap.bits(), name.clone(), ); } }; Loading Loading @@ -300,6 +310,7 @@ impl BluetoothMedia { .find(|cap| A2dpCodecIndex::SrcSbc == A2dpCodecIndex::from(cap.codec_type)) }); let cur_hfp_cap = self.hfp_caps.get(&addr); let name = self.adapter_get_remote_name(addr); match (cur_a2dp_cap, cur_hfp_cap) { (None, None) => warn!( "[{}]: Try to add a device without a2dp and hfp capability.", Loading @@ -312,6 +323,7 @@ impl BluetoothMedia { self.callbacks.clone(), *cap, *hfp_cap, name, false, ); } Loading @@ -324,7 +336,7 @@ impl BluetoothMedia { let hfp_cap = cur_hfp_cap.unwrap_or(&HfpCodecCapability::UNSUPPORTED).clone(); let task = topstack::get_runtime().spawn(async move { sleep(Duration::from_secs(DEFAULT_PROFILE_DISCOVERY_TIMEOUT_SEC)).await; if dedup_added_cb(device_added_tasks, addr, callbacks, cap, hfp_cap, true) { if dedup_added_cb(device_added_tasks, addr, callbacks, cap, hfp_cap, name, true) { warn!( "[{}]: Add a device with only hfp or a2dp capability after timeout.", addr.to_string() Loading Loading @@ -358,6 +370,23 @@ impl BluetoothMedia { } } fn adapter_get_remote_name(&self, addr: RawAddress) -> String { let device = BluetoothDevice::new( addr.to_string(), // get_remote_name needs a BluetoothDevice just for its address, the // name field is unused so construct one with a fake name. "Classic Device".to_string(), ); if let Some(adapter) = &self.adapter { match adapter.lock().unwrap().get_remote_name(device).as_str() { "" => addr.to_string(), name => name.into(), } } else { addr.to_string() } } pub fn get_hfp_connection_state(&self) -> u32 { for state in self.hfp_states.values() { return BthfConnectionState::to_u32(state).unwrap_or(0); Loading Loading
system/gd/rust/linux/service/src/iface_bluetooth_media.rs +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ impl IBluetoothMediaCallback for BluetoothMediaCallbackDBus { bits_per_sample: i32, channel_mode: i32, hfp_cap: i32, name: String, ) { dbus_generated!() } Loading
system/gd/rust/linux/service/src/main.rs +2 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,8 @@ fn main() -> Result<(), Box<dyn Error>> { { intf.lock().unwrap().initialize(get_bt_dispatcher(tx.clone()), args); bluetooth_media.lock().unwrap().set_adapter(bluetooth.clone()); let mut bluetooth = bluetooth.lock().unwrap(); bluetooth.init_profiles(); bluetooth.enable(); Loading
system/gd/rust/linux/stack/src/bluetooth_media.rs +30 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ use tokio::sync::mpsc::Sender; use tokio::task::JoinHandle; use tokio::time::{sleep, Duration}; use crate::bluetooth::{Bluetooth, BluetoothDevice, IBluetooth}; use crate::Message; const DEFAULT_PROFILE_DISCOVERY_TIMEOUT_SEC: u64 = 5; Loading Loading @@ -69,6 +70,7 @@ pub trait IBluetoothMediaCallback { bits_per_sample: i32, channel_mode: i32, hfp_cap: i32, name: String, ); /// Loading @@ -93,6 +95,7 @@ pub struct BluetoothMedia { callbacks: Arc<Mutex<Vec<(u32, Box<dyn IBluetoothMediaCallback + Send>)>>>, callback_last_id: u32, tx: Sender<Message>, adapter: Option<Arc<Mutex<Box<Bluetooth>>>>, a2dp: Option<A2dp>, avrcp: Option<Avrcp>, a2dp_states: HashMap<RawAddress, BtavConnectionState>, Loading @@ -111,6 +114,7 @@ impl BluetoothMedia { callbacks: Arc::new(Mutex::new(vec![])), callback_last_id: 0, tx, adapter: None, a2dp: None, avrcp: None, a2dp_states: HashMap::new(), Loading @@ -122,6 +126,10 @@ impl BluetoothMedia { } } pub fn set_adapter(&mut self, adapter: Arc<Mutex<Box<Bluetooth>>>) { self.adapter = Some(adapter); } pub fn dispatch_a2dp_callbacks(&mut self, cb: A2dpCallbacks) { match cb { A2dpCallbacks::ConnectionState(addr, state) => { Loading Loading @@ -248,6 +256,7 @@ impl BluetoothMedia { callbacks: Arc<Mutex<Vec<(u32, Box<dyn IBluetoothMediaCallback + Send>)>>>, cap: A2dpCodecConfig, hfp_cap: HfpCodecCapability, name: String, is_delayed: bool, ) -> bool { // Closure used to lock and trigger the device added callbacks. Loading @@ -259,6 +268,7 @@ impl BluetoothMedia { cap.bits_per_sample, cap.channel_mode, hfp_cap.bits(), name.clone(), ); } }; Loading Loading @@ -300,6 +310,7 @@ impl BluetoothMedia { .find(|cap| A2dpCodecIndex::SrcSbc == A2dpCodecIndex::from(cap.codec_type)) }); let cur_hfp_cap = self.hfp_caps.get(&addr); let name = self.adapter_get_remote_name(addr); match (cur_a2dp_cap, cur_hfp_cap) { (None, None) => warn!( "[{}]: Try to add a device without a2dp and hfp capability.", Loading @@ -312,6 +323,7 @@ impl BluetoothMedia { self.callbacks.clone(), *cap, *hfp_cap, name, false, ); } Loading @@ -324,7 +336,7 @@ impl BluetoothMedia { let hfp_cap = cur_hfp_cap.unwrap_or(&HfpCodecCapability::UNSUPPORTED).clone(); let task = topstack::get_runtime().spawn(async move { sleep(Duration::from_secs(DEFAULT_PROFILE_DISCOVERY_TIMEOUT_SEC)).await; if dedup_added_cb(device_added_tasks, addr, callbacks, cap, hfp_cap, true) { if dedup_added_cb(device_added_tasks, addr, callbacks, cap, hfp_cap, name, true) { warn!( "[{}]: Add a device with only hfp or a2dp capability after timeout.", addr.to_string() Loading Loading @@ -358,6 +370,23 @@ impl BluetoothMedia { } } fn adapter_get_remote_name(&self, addr: RawAddress) -> String { let device = BluetoothDevice::new( addr.to_string(), // get_remote_name needs a BluetoothDevice just for its address, the // name field is unused so construct one with a fake name. "Classic Device".to_string(), ); if let Some(adapter) = &self.adapter { match adapter.lock().unwrap().get_remote_name(device).as_str() { "" => addr.to_string(), name => name.into(), } } else { addr.to_string() } } pub fn get_hfp_connection_state(&self) -> u32 { for state in self.hfp_states.values() { return BthfConnectionState::to_u32(state).unwrap_or(0); Loading