Loading system/gd/rust/linux/mgmt/src/bluetooth_manager.rs +7 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,11 @@ impl BluetoothManager { } pub(crate) fn callback_hci_device_change(&mut self, hci: VirtualHciIndex, present: bool) { if present { warn!("Presence added: {}", hci); } else { warn!("Presence removed: {}", hci); } for (_, callback) in &mut self.callbacks { callback.on_hci_device_changed(hci.to_i32(), present); } Loading Loading @@ -178,6 +183,8 @@ impl IBluetoothManager for BluetoothManager { self.proxy .get_valid_adapters() .iter() // Don't present the queued device to the user. .filter(|a| !a.has_queued_present) .map(|a| AdapterWithEnabled { hci_interface: a.virt_hci.to_i32(), enabled: state_to_enabled(a.state), Loading system/gd/rust/linux/mgmt/src/state_machine.rs +39 −1 Original line number Diff line number Diff line Loading @@ -650,6 +650,13 @@ pub async fn mainloop( let action = context.state_machine.action_on_bluetooth_started(*pid, hci); cmd_timeout.lock().unwrap().handle_timeout_action(hci, action); if context.state_machine.has_queued_present(hci) { context.state_machine.modify_state(hci, |a: &mut AdapterState| { a.has_queued_present = false; }); bluetooth_manager.lock().unwrap().callback_hci_device_change(hci, true); } } AdapterStateActions::BluetoothStopped(i) => { hci = *i; Loading Loading @@ -715,7 +722,23 @@ pub async fn mainloop( AdapterChangeAction::DoNothing => (), }; bluetooth_manager.lock().unwrap().callback_hci_device_change(hci, *present); // If present switched to true and we're turning on the adapter, // defer the callback until the next BluetoothStarted or CommandTimeout // so the clients won't get an unexpected state change after present. let queue_present = *present && next_state == ProcessState::TurningOn; // Always modify_state to make sure it's reset on queue_present=false, // e.g., when a hci is removed while its presence is still queued. context.state_machine.modify_state(hci, |a: &mut AdapterState| { a.has_queued_present = queue_present; }); if !queue_present { bluetooth_manager .lock() .unwrap() .callback_hci_device_change(hci, *present); } } }; Loading Loading @@ -844,6 +867,13 @@ pub async fn mainloop( StateMachineTimeoutActions::Noop => (), _ => cmd_timeout.lock().unwrap().set_next(hci), } if context.state_machine.has_queued_present(hci) { context.state_machine.modify_state(hci, |a: &mut AdapterState| { a.has_queued_present = false; }); bluetooth_manager.lock().unwrap().callback_hci_device_change(hci, true); } } Message::SetDesiredDefaultAdapter(hci) => { Loading Loading @@ -1017,6 +1047,9 @@ pub struct AdapterState { /// Whether this hci device is listed as present. pub present: bool, /// Whether the 'present' notification is being deferred until adapter is ready. pub has_queued_present: bool, /// Whether this hci device is configured to be enabled. pub config_enabled: bool, Loading @@ -1032,6 +1065,7 @@ impl AdapterState { real_hci, virt_hci, present: false, has_queued_present: false, config_enabled: false, pid: 0, restart_count: 0, Loading Loading @@ -1240,6 +1274,10 @@ impl StateMachineInternal { }); } fn has_queued_present(&self, hci: VirtualHciIndex) -> bool { self.get_state(hci, |a: &AdapterState| Some(a.has_queued_present)).unwrap_or(false) } fn get_process_state(&self, hci: VirtualHciIndex) -> ProcessState { self.get_state(hci, move |a: &AdapterState| Some(a.state)).unwrap_or(ProcessState::Off) } Loading Loading
system/gd/rust/linux/mgmt/src/bluetooth_manager.rs +7 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,11 @@ impl BluetoothManager { } pub(crate) fn callback_hci_device_change(&mut self, hci: VirtualHciIndex, present: bool) { if present { warn!("Presence added: {}", hci); } else { warn!("Presence removed: {}", hci); } for (_, callback) in &mut self.callbacks { callback.on_hci_device_changed(hci.to_i32(), present); } Loading Loading @@ -178,6 +183,8 @@ impl IBluetoothManager for BluetoothManager { self.proxy .get_valid_adapters() .iter() // Don't present the queued device to the user. .filter(|a| !a.has_queued_present) .map(|a| AdapterWithEnabled { hci_interface: a.virt_hci.to_i32(), enabled: state_to_enabled(a.state), Loading
system/gd/rust/linux/mgmt/src/state_machine.rs +39 −1 Original line number Diff line number Diff line Loading @@ -650,6 +650,13 @@ pub async fn mainloop( let action = context.state_machine.action_on_bluetooth_started(*pid, hci); cmd_timeout.lock().unwrap().handle_timeout_action(hci, action); if context.state_machine.has_queued_present(hci) { context.state_machine.modify_state(hci, |a: &mut AdapterState| { a.has_queued_present = false; }); bluetooth_manager.lock().unwrap().callback_hci_device_change(hci, true); } } AdapterStateActions::BluetoothStopped(i) => { hci = *i; Loading Loading @@ -715,7 +722,23 @@ pub async fn mainloop( AdapterChangeAction::DoNothing => (), }; bluetooth_manager.lock().unwrap().callback_hci_device_change(hci, *present); // If present switched to true and we're turning on the adapter, // defer the callback until the next BluetoothStarted or CommandTimeout // so the clients won't get an unexpected state change after present. let queue_present = *present && next_state == ProcessState::TurningOn; // Always modify_state to make sure it's reset on queue_present=false, // e.g., when a hci is removed while its presence is still queued. context.state_machine.modify_state(hci, |a: &mut AdapterState| { a.has_queued_present = queue_present; }); if !queue_present { bluetooth_manager .lock() .unwrap() .callback_hci_device_change(hci, *present); } } }; Loading Loading @@ -844,6 +867,13 @@ pub async fn mainloop( StateMachineTimeoutActions::Noop => (), _ => cmd_timeout.lock().unwrap().set_next(hci), } if context.state_machine.has_queued_present(hci) { context.state_machine.modify_state(hci, |a: &mut AdapterState| { a.has_queued_present = false; }); bluetooth_manager.lock().unwrap().callback_hci_device_change(hci, true); } } Message::SetDesiredDefaultAdapter(hci) => { Loading Loading @@ -1017,6 +1047,9 @@ pub struct AdapterState { /// Whether this hci device is listed as present. pub present: bool, /// Whether the 'present' notification is being deferred until adapter is ready. pub has_queued_present: bool, /// Whether this hci device is configured to be enabled. pub config_enabled: bool, Loading @@ -1032,6 +1065,7 @@ impl AdapterState { real_hci, virt_hci, present: false, has_queued_present: false, config_enabled: false, pid: 0, restart_count: 0, Loading Loading @@ -1240,6 +1274,10 @@ impl StateMachineInternal { }); } fn has_queued_present(&self, hci: VirtualHciIndex) -> bool { self.get_state(hci, |a: &AdapterState| Some(a.has_queued_present)).unwrap_or(false) } fn get_process_state(&self, hci: VirtualHciIndex) -> ProcessState { self.get_state(hci, move |a: &AdapterState| Some(a.state)).unwrap_or(ProcessState::Off) } Loading