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

Commit 0006f833 authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

Floss: Set up handling of D-Bus methods early in btmanagerd

Setting up the D-Bus method handler needs to be done before exporting
interfaces, so that when the InterfacesAdded signals are sent, we are
ready to handle D-Bus method calls immediately.

This uses the same principle as the fix in btadapterd:
https://r.android.com/2105568.

Bug: 263432564
Tag: #floss
Test: Build Floss on Linux

Change-Id: Ia99e7400a47cde5fc5e0f037ea4c6950b4a7e875
parent b54e2bef
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -113,6 +113,19 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let disconnect_watcher = Arc::new(Mutex::new(DisconnectWatcher::new()));
    disconnect_watcher.lock().unwrap().setup_watch(conn.clone()).await;

    // We add the Crossroads instance to the connection so that incoming method calls will be
    // handled.
    // This must be done before exporting interfaces so that clients that rely on InterfacesAdded
    // signal can rely on us being ready to handle methods on those exported interfaces.
    let cr_clone = cr.clone();
    conn.start_receive(
        MatchRule::new_method_call(),
        Box::new(move |msg, conn| {
            cr_clone.lock().unwrap().handle_message(msg, conn).unwrap();
            true
        }),
    );

    // Let's add the "/org/chromium/bluetooth/Manager" path, which implements
    // the org.chromium.bluetooth.Manager interface, to the crossroads instance.
    let iface = bluetooth_manager_dbus::export_bluetooth_manager_dbus_intf(
@@ -137,16 +150,6 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {

    cr.lock().unwrap().insert("/org/chromium/bluetooth/Manager", &[iface, iface_exp], mixin);

    // We add the Crossroads instance to the connection so that incoming method calls will be handled.
    let cr_clone = cr.clone();
    conn.start_receive(
        MatchRule::new_method_call(),
        Box::new(move |msg, conn| {
            cr_clone.lock().unwrap().handle_message(msg, conn).unwrap();
            true
        }),
    );

    let mut powerd_suspend_manager = PowerdSuspendManager::new(conn.clone(), cr);

    tokio::spawn(async move {