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

Commit c2535e94 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi
Browse files

floss: Check floss enabled on startup

Manager should check that Floss is enabled on startup before trying
enabling previously enabled adapters.

Bug: 225415253
Test: Procedure described in b/225415253#comment3
Tag: #floss
Change-Id: Ic96dc1c0abc9ddbafd9c8a2e675c56de6cf9c52e
parent f6f3671e
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -61,6 +61,11 @@ impl BluetoothManager {
    pub(crate) fn callback_disconnected(&mut self, id: u32) {
        self.callbacks.remove(&id);
    }

    pub(crate) fn get_floss_enabled_internal(&mut self) -> bool {
        let enabled = self.manager_context.floss_enabled.load(Ordering::Relaxed);
        enabled
    }
}

impl IBluetoothManager for BluetoothManager {
@@ -115,8 +120,7 @@ impl IBluetoothManager for BluetoothManager {
    }

    fn get_floss_enabled(&mut self) -> bool {
        let enabled = self.manager_context.floss_enabled.load(Ordering::Relaxed);
        enabled
        self.get_floss_enabled_internal()
    }

    fn set_floss_enabled(&mut self, enabled: bool) {
+18 −12
Original line number Diff line number Diff line
@@ -190,6 +190,8 @@ pub async fn mainloop(
    });

    let init_tx = context.tx.clone();
    let floss_enabled = bluetooth_manager.lock().unwrap().get_floss_enabled_internal();

    tokio::spawn(async move {
        // Get a list of active pid files to determine initial adapter status
        let files = config_util::list_pid_files(PID_DIR);
@@ -203,20 +205,24 @@ pub async fn mainloop(
                .unwrap();
        }

        // Initialize adapter states based on saved config
        // Initialize adapter states based on saved config only if floss is enabled.
        if floss_enabled {
            let hci_devices = config_util::list_hci_devices();
            for device in hci_devices.iter() {
                let is_enabled = config_util::is_hci_n_enabled(*device);
                if is_enabled {
                    let _ = init_tx
                        .send_timeout(
                        Message::AdapterStateChange(AdapterStateActions::StartBluetooth(*device)),
                            Message::AdapterStateChange(AdapterStateActions::StartBluetooth(
                                *device,
                            )),
                            TX_SEND_TIMEOUT_DURATION,
                        )
                        .await
                        .unwrap();
                }
            }
        }
    });

    // Set up a PID file listener to emit PID inotify messages