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

Commit eb36f214 authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

Floss: Also listen for BlueZ suspend API

For BlueZ to communicate with powerd, it is easier to use btmanagerd to
reuse protobuf and powerd state machine logic. This adds btmanagerd to
also listen to BlueZ emitting Suspend API-compliant object and relays
powerd events there. No special handling is needed for BlueZ with the
assumption that only one of BlueZ (bluetoothd) or Floss (btadapterd) can
run at a time.

Bug: 231741170
Tag: #floss
Test: Manual - Build Floss on Linux

Change-Id: I2edd1024c02b8120f2a8cfcc0efb3737bcfc7671
parent 5a618f68
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ const SUSPEND_IMMINENT_SIGNAL: &str = "SuspendImminent";
const SUSPEND_DONE_SIGNAL: &str = "SuspendDone";
const BTMANAGERD_NAME: &str = "Bluetooth Manager";
const DBUS_TIMEOUT: Duration = Duration::from_secs(2);
const BLUEZ_SERVICE: &str = "org.bluez";

#[derive(Debug)]
enum SuspendManagerMessage {
@@ -248,6 +249,30 @@ impl PowerdSuspendManager {
            )
            .await;

        // Watch events of bluez appearing or disappearing.
        // This is with the assumption that only one instance of btadapterd and bluez can be alive
        // at a time.
        let mut bluez_watcher = ServiceWatcher::new(self.conn.clone(), String::from(BLUEZ_SERVICE));
        let tx1 = self.tx.clone();
        let tx2 = self.tx.clone();
        bluez_watcher
            .start_watch_interface(
                String::from(ADAPTER_SUSPEND_INTERFACE),
                Box::new(move |path| {
                    let tx_clone = tx1.clone();
                    tokio::spawn(async move {
                        let _ = tx_clone.send(SuspendManagerMessage::AdapterFound(path)).await;
                    });
                }),
                Box::new(move || {
                    let tx_clone = tx2.clone();
                    tokio::spawn(async move {
                        let _ = tx_clone.send(SuspendManagerMessage::AdapterRemoved).await;
                    });
                }),
            )
            .await;

        // Watch for SuspendImminent signal from powerd.
        let mr = MatchRule::new_signal(POWERD_INTERFACE, SUSPEND_IMMINENT_SIGNAL)
            .with_sender(POWERD_SERVICE)