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

Commit 2af21fc9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "floss: Restore adapter state on start" am: 15b8a338

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2020936

Change-Id: I2d89651b85a82c84fb219a74b13201a35dd12eec
parents ecb0cfaf 15b8a338
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
use crate::bluetooth_manager::BluetoothManager;
use crate::config_util;
use bt_common::time::Alarm;
use log::{debug, error, info, warn};
use nix::sys::signal::{self, Signal};
@@ -135,7 +136,7 @@ fn hci_devices_inotify_async_fd() -> AsyncFd<inotify::Inotify> {
    let mut detector = inotify::Inotify::init().expect("cannot use inotify");
    detector
        .add_watch(
            crate::config_util::HCI_DEVICES_DIR,
            config_util::HCI_DEVICES_DIR,
            inotify::WatchMask::CREATE | inotify::WatchMask::DELETE,
        )
        .expect("failed to add watch");
@@ -144,7 +145,7 @@ fn hci_devices_inotify_async_fd() -> AsyncFd<inotify::Inotify> {

/// On startup, get and cache all hci devices by emitting the callback
fn startup_hci_devices(manager: &Arc<std::sync::Mutex<Box<BluetoothManager>>>) {
    let devices = crate::config_util::list_hci_devices();
    let devices = config_util::list_hci_devices();
    for device in devices {
        manager.lock().unwrap().callback_hci_device_change(device, true);
    }
@@ -188,10 +189,10 @@ pub async fn mainloop(
        }
    });

    // Get a list of active pid files to determine initial adapter status
    let init_tx = context.tx.clone();
    tokio::spawn(async move {
        let files = crate::config_util::list_pid_files(PID_DIR);
        // Get a list of active pid files to determine initial adapter status
        let files = config_util::list_pid_files(PID_DIR);
        for file in files {
            let _ = init_tx
                .send_timeout(
@@ -201,6 +202,21 @@ pub async fn mainloop(
                .await
                .unwrap();
        }

        // Initialize adapter states based on saved config
        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)),
                        TX_SEND_TIMEOUT_DURATION,
                    )
                    .await
                    .unwrap();
            }
        }
    });

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