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

Commit 298cadc6 authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

Enable stack automatically when btadapterd starts

Enable and disable is already handled by btmanagerd by starting and
exiting btadapterd daemon, so btadapterd does not need to expose enable
and disable interfaces but making assumption that it needs to enable the
stack when it starts and disable when exits.

Bug: 186492781
Tag: #floss
Test: manual - Run btadapterd and observe that the stack is enabled.

Change-Id: I614ec12df1d41043ee98c31569557e2c45f52556
parent d6077220
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -51,11 +51,13 @@ impl IBluetooth for IBluetoothDBus {
    #[dbus_method("RegisterCallback")]
    fn register_callback(&mut self, callback: Box<dyn IBluetoothCallback + Send>) {}

    #[dbus_method("Enable")]
    // Not exposed over D-Bus. The stack is automatically enabled when the daemon starts.
    fn enable(&mut self) -> bool {
        false
    }
    #[dbus_method("Disable")]

    // Not exposed over D-Bus. The stack is automatically disabled when the daemon exits.
    // TODO(b/189495858): Handle shutdown properly when SIGTERM is received.
    fn disable(&mut self) -> bool {
        false
    }
+5 −3
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ use dbus_tokio::connection;
use futures::future;

use btstack::bluetooth::get_bt_dispatcher;
use btstack::bluetooth::Bluetooth;
use btstack::bluetooth::{Bluetooth, IBluetooth};
use btstack::bluetooth_gatt::BluetoothGatt;
use btstack::Stack;

@@ -36,6 +36,10 @@ fn main() -> Result<(), Box<dyn Error>> {
    let bluetooth = Arc::new(Mutex::new(Bluetooth::new(tx.clone(), intf.clone())));
    let bluetooth_gatt = Arc::new(Mutex::new(BluetoothGatt::new(intf.clone())));

    intf.lock().unwrap().initialize(get_bt_dispatcher(tx), vec![]);
    bluetooth.lock().unwrap().init_profiles();
    bluetooth.lock().unwrap().enable();

    topstack::get_runtime().block_on(async {
        // Connect to D-Bus system bus.
        let (resource, conn) = connection::new_system_sync()?;
@@ -59,8 +63,6 @@ fn main() -> Result<(), Box<dyn Error>> {
            }),
        )));

        intf.lock().unwrap().initialize(get_bt_dispatcher(tx), vec![]);

        // Run the stack main dispatch loop.
        topstack::get_runtime().spawn(Stack::dispatch(rx, bluetooth.clone()));