Loading system/gd/rust/linux/stack/src/bluetooth.rs +9 −4 Original line number Diff line number Diff line Loading @@ -638,6 +638,14 @@ impl Bluetooth { .collect() } /// Gets the bond state of a single device with its address. pub fn get_bond_state_by_addr(&self, addr: &String) -> BtBondState { match self.bonded_devices.get(addr) { Some(device) => device.bond_state.clone(), None => BtBondState::NotBonded, } } /// Check whether found devices are still fresh. If they're outside the /// freshness window, send a notification to clear the device from clients. fn trigger_freshness_check(&mut self) { Loading Loading @@ -1575,10 +1583,7 @@ impl IBluetooth for Bluetooth { } fn get_bond_state(&self, device: BluetoothDevice) -> BtBondState { match self.bonded_devices.get(&device.address) { Some(device) => device.bond_state.clone(), None => BtBondState::NotBonded, } self.get_bond_state_by_addr(&device.address) } fn set_pin(&self, device: BluetoothDevice, accept: bool, pin_code: Vec<u8>) -> bool { Loading system/gd/rust/linux/stack/src/bluetooth_media.rs +37 −1 Original line number Diff line number Diff line //! Anything related to audio and media API. use bt_topshim::btif::{ BluetoothInterface, BtConnectionDirection, BtStatus, DisplayAddress, RawAddress, BluetoothInterface, BtBondState, BtConnectionDirection, BtStatus, DisplayAddress, RawAddress, ToggleableProfile, }; use bt_topshim::profiles::a2dp::{ Loading Loading @@ -990,6 +990,42 @@ impl BluetoothMedia { guard.insert(addr, Some((task, first_conn_ts))); } DeviceConnectionStates::FullyConnected => { // Rejecting the unbonded connection after we finished our profile // reconnectinglogic to avoid a collision. if let Some(adapter) = &self.adapter { if BtBondState::Bonded != adapter.lock().unwrap().get_bond_state_by_addr(&addr.to_string()) { warn!( "[{}]: Rejecting a unbonded device's attempt to connect to media profiles", DisplayAddress(addr)); let fallback_tasks = self.fallback_tasks.clone(); let device_states = self.device_states.clone(); let txl = self.tx.clone(); let task = topstack::get_runtime().spawn(async move { { device_states .lock() .unwrap() .insert(addr, DeviceConnectionStates::Disconnecting); fallback_tasks.lock().unwrap().insert(addr, None); } debug!( "[{}]: Device connection state: {:?}.", DisplayAddress(addr), DeviceConnectionStates::Disconnecting ); let _ = txl .send(Message::Media(MediaActions::Disconnect(addr.to_string()))) .await; }); guard.insert(addr, Some((task, first_conn_ts))); return; } } let cur_a2dp_caps = self.a2dp_caps.get(&addr); let cur_hfp_cap = self.hfp_cap.get(&addr); let name = self.adapter_get_remote_name(addr); Loading Loading
system/gd/rust/linux/stack/src/bluetooth.rs +9 −4 Original line number Diff line number Diff line Loading @@ -638,6 +638,14 @@ impl Bluetooth { .collect() } /// Gets the bond state of a single device with its address. pub fn get_bond_state_by_addr(&self, addr: &String) -> BtBondState { match self.bonded_devices.get(addr) { Some(device) => device.bond_state.clone(), None => BtBondState::NotBonded, } } /// Check whether found devices are still fresh. If they're outside the /// freshness window, send a notification to clear the device from clients. fn trigger_freshness_check(&mut self) { Loading Loading @@ -1575,10 +1583,7 @@ impl IBluetooth for Bluetooth { } fn get_bond_state(&self, device: BluetoothDevice) -> BtBondState { match self.bonded_devices.get(&device.address) { Some(device) => device.bond_state.clone(), None => BtBondState::NotBonded, } self.get_bond_state_by_addr(&device.address) } fn set_pin(&self, device: BluetoothDevice, accept: bool, pin_code: Vec<u8>) -> bool { Loading
system/gd/rust/linux/stack/src/bluetooth_media.rs +37 −1 Original line number Diff line number Diff line //! Anything related to audio and media API. use bt_topshim::btif::{ BluetoothInterface, BtConnectionDirection, BtStatus, DisplayAddress, RawAddress, BluetoothInterface, BtBondState, BtConnectionDirection, BtStatus, DisplayAddress, RawAddress, ToggleableProfile, }; use bt_topshim::profiles::a2dp::{ Loading Loading @@ -990,6 +990,42 @@ impl BluetoothMedia { guard.insert(addr, Some((task, first_conn_ts))); } DeviceConnectionStates::FullyConnected => { // Rejecting the unbonded connection after we finished our profile // reconnectinglogic to avoid a collision. if let Some(adapter) = &self.adapter { if BtBondState::Bonded != adapter.lock().unwrap().get_bond_state_by_addr(&addr.to_string()) { warn!( "[{}]: Rejecting a unbonded device's attempt to connect to media profiles", DisplayAddress(addr)); let fallback_tasks = self.fallback_tasks.clone(); let device_states = self.device_states.clone(); let txl = self.tx.clone(); let task = topstack::get_runtime().spawn(async move { { device_states .lock() .unwrap() .insert(addr, DeviceConnectionStates::Disconnecting); fallback_tasks.lock().unwrap().insert(addr, None); } debug!( "[{}]: Device connection state: {:?}.", DisplayAddress(addr), DeviceConnectionStates::Disconnecting ); let _ = txl .send(Message::Media(MediaActions::Disconnect(addr.to_string()))) .await; }); guard.insert(addr, Some((task, first_conn_ts))); return; } } let cur_a2dp_caps = self.a2dp_caps.get(&addr); let cur_hfp_cap = self.hfp_cap.get(&addr); let name = self.adapter_get_remote_name(addr); Loading