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

Commit f11d75ed authored by Katherine Lai's avatar Katherine Lai
Browse files

Floss: Clean up stack on shut down

When the adapter is shut down, we should also clean up the
instance to ensure all the modules get shut down.

This fixes a bug where the storage module wasn't getting shut
down leading to device info not being saved if bluetooth was
immediately toggled off afterward.

Bug: 288636142
Tag: #floss
Test: emerge-brya floss and confirm forget persists after BT off
Test: mma -j32
Change-Id: I37a7a16c861838c3a23bef005352709f45c1348b
parent 786c59a3
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -723,6 +723,11 @@ impl IBluetooth for BluetoothDBus {
        dbus_generated!()
    }

    fn init(&mut self, init_flags: Vec<String>) -> bool {
        // Not implemented by server
        true
    }

    fn enable(&mut self) -> bool {
        // Not implemented by server
        true
@@ -733,6 +738,10 @@ impl IBluetooth for BluetoothDBus {
        true
    }

    fn cleanup(&mut self) {
        // Not implemented by server
    }

    #[dbus_method("GetAddress")]
    fn get_address(&self) -> String {
        dbus_generated!()
+10 −1
Original line number Diff line number Diff line
@@ -440,17 +440,26 @@ impl IBluetooth for IBluetoothDBus {
        dbus_generated!()
    }

    // Not exposed over D-Bus. The stack is automatically initialized when the daemon starts.
    fn init(&mut self, init_flags: Vec<String>) -> bool {
        dbus_generated!()
    }

    // Not exposed over D-Bus. The stack is automatically enabled when the daemon starts.
    fn enable(&mut self) -> bool {
        dbus_generated!()
    }

    // 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 {
        dbus_generated!()
    }

    // Not exposed over D-Bus. The stack is automatically cleaned up when the daemon exits.
    fn cleanup(&mut self) {
        dbus_generated!()
    }

    #[dbus_method("GetAddress")]
    fn get_address(&self) -> String {
        dbus_generated!()
+2 −3
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ use btstack::{
    battery_manager::BatteryManager,
    battery_provider_manager::BatteryProviderManager,
    battery_service::BatteryService,
    bluetooth::{get_bt_dispatcher, Bluetooth, IBluetooth},
    bluetooth::{Bluetooth, IBluetooth},
    bluetooth_admin::BluetoothAdmin,
    bluetooth_gatt::BluetoothGatt,
    bluetooth_logging::BluetoothLogging,
@@ -382,13 +382,12 @@ fn main() -> Result<(), Box<dyn Error>> {
        // Hold locks and initialize all interfaces. This must be done AFTER DBus is
        // initialized so DBus can properly enforce user policies.
        {
            intf.lock().unwrap().initialize(get_bt_dispatcher(tx.clone()), init_flags);

            let adapter = bluetooth.clone();
            bluetooth_media.lock().unwrap().set_adapter(adapter.clone());
            bluetooth_admin.lock().unwrap().set_adapter(adapter.clone());

            let mut bluetooth = bluetooth.lock().unwrap();
            bluetooth.init(init_flags);
            bluetooth.init_profiles();
            bluetooth.enable();

+14 −0
Original line number Diff line number Diff line
@@ -79,6 +79,9 @@ pub trait IBluetooth {
    /// Removes registered callback.
    fn unregister_connection_callback(&mut self, callback_id: u32) -> bool;

    /// Inits the bluetooth interface. Should always be called before enable.
    fn init(&mut self, init_flags: Vec<String>) -> bool;

    /// Enables the adapter.
    ///
    /// Returns true if the request is accepted.
@@ -89,6 +92,9 @@ pub trait IBluetooth {
    /// Returns true if the request is accepted.
    fn disable(&mut self) -> bool;

    /// Cleans up the bluetooth interface. Should always be called after disable.
    fn cleanup(&mut self);

    /// Returns the Bluetooth address of the local adapter.
    fn get_address(&self) -> String;

@@ -1788,6 +1794,10 @@ impl IBluetooth for Bluetooth {
        self.connection_callbacks.remove_callback(callback_id)
    }

    fn init(&mut self, init_flags: Vec<String>) -> bool {
        self.intf.lock().unwrap().initialize(get_bt_dispatcher(self.tx.clone()), init_flags)
    }

    fn enable(&mut self) -> bool {
        self.intf.lock().unwrap().enable() == 0
    }
@@ -1796,6 +1806,10 @@ impl IBluetooth for Bluetooth {
        self.intf.lock().unwrap().disable() == 0
    }

    fn cleanup(&mut self) {
        self.intf.lock().unwrap().cleanup();
    }

    fn get_address(&self) -> String {
        match self.local_address {
            None => String::from(""),
+1 −0
Original line number Diff line number Diff line
@@ -196,6 +196,7 @@ impl Stack {
            match m.unwrap() {
                Message::Shutdown => {
                    bluetooth.lock().unwrap().disable();
                    bluetooth.lock().unwrap().cleanup();
                }

                Message::AdapterReady => {