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

Commit 58da7062 authored by Hsin-chen Chuang's avatar Hsin-chen Chuang
Browse files

floss: btmanagerd: Treat TurningOff as enabled states

In TurningOff state the Start call is actually not actionable. Treating
it as enabled means we send out OnHciEnabledChanged after the internal
state has changed from TurningOff to Off. Thus clients could safely call
Start whenever they received the callback.

Bug: 301164021
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: Toggle BT quickly through UI, the swich won't auto disable

Change-Id: I2d9036ca4b9b23dc547027b2995b9afcf4be675f
parent 27bd31f4
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ pub enum ProcessState {
/// Check whether adapter is enabled by checking internal state.
pub fn state_to_enabled(state: ProcessState) -> bool {
    match state {
        ProcessState::On => true,
        ProcessState::On | ProcessState::TurningOff => true,
        _ => false,
    }
}
@@ -726,13 +726,13 @@ pub async fn mainloop(
                );

                // Only emit enabled event for certain transitions
                if next_state != prev_state
                    && (next_state == ProcessState::On || prev_state == ProcessState::On)
                {
                let prev_enabled = state_to_enabled(prev_state);
                let next_enabled = state_to_enabled(next_state);
                if prev_enabled != next_enabled {
                    bluetooth_manager
                        .lock()
                        .unwrap()
                        .callback_hci_enabled_change(hci, next_state == ProcessState::On);
                        .callback_hci_enabled_change(hci, next_enabled);
                }
            }