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

Commit 5e6052f9 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi Committed by Abhishek Pandit-Subedi
Browse files

floss: Add GetAdaptersAvailable api to manager

Clients need to know all available adapters and their enabled states
when they start-up (before they start getting the OnHciPresent/Enabled
callbacks). This change replaces ListHciDevices, which only lists the
present adapters, with GetAvailableAdapters, which lists present
adapters and their enabled states.

Bug: 189501676
Test: Verify with dbus-send
Change-Id: Ia7be953c94ed0d4d381e3580bc785f0fc47ac913
parent 34768972
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -13,7 +13,9 @@ use dbus_projection::{impl_dbus_arg_enum, DisconnectWatcher};

use dbus_macros::{dbus_method, dbus_propmap, generate_dbus_exporter};

use manager_service::iface_bluetooth_manager::{IBluetoothManager, IBluetoothManagerCallback};
use manager_service::iface_bluetooth_manager::{
    AdapterWithEnabled, IBluetoothManager, IBluetoothManagerCallback,
};

use num_traits::{FromPrimitive, ToPrimitive};

@@ -185,6 +187,12 @@ impl IBluetooth for BluetoothDBus {
    }
}

#[dbus_propmap(AdapterWithEnabled)]
pub struct AdapterWithEnabledDbus {
    hci_interface: i32,
    enabled: bool,
}

pub(crate) struct BluetoothManagerDBus {
    client_proxy: ClientDBusProxy,
}
@@ -242,8 +250,15 @@ impl IBluetoothManager for BluetoothManagerDBus {
        self.client_proxy.method_noreturn("SetFlossEnabled", (enabled,))
    }

    fn list_hci_devices(&mut self) -> Vec<i32> {
        self.client_proxy.method("ListHciDevices", ())
    fn get_available_adapters(&mut self) -> Vec<AdapterWithEnabled> {
        let props: Vec<dbus::arg::PropMap> = self.client_proxy.method("GetAvailableAdapters", ());
        <Vec<AdapterWithEnabled> as DBusArg>::from_dbus(
            props,
            self.client_proxy.conn.clone(),
            dbus::strings::BusName::new(":1.0").unwrap(), // unused
            Arc::new(Mutex::new(DisconnectWatcher::new())),
        )
        .unwrap()
    }
}

+13 −4
Original line number Diff line number Diff line
use log::{error, info};

use manager_service::iface_bluetooth_manager::{IBluetoothManager, IBluetoothManagerCallback};
use manager_service::iface_bluetooth_manager::{
    AdapterWithEnabled, IBluetoothManager, IBluetoothManagerCallback,
};

use std::collections::HashMap;
use std::process::Command;
@@ -134,8 +136,15 @@ impl IBluetoothManager for BluetoothManager {
        }
    }

    fn list_hci_devices(&mut self) -> Vec<i32> {
        let devices = config_util::list_hci_devices();
        devices
    fn get_available_adapters(&mut self) -> Vec<AdapterWithEnabled> {
        let adapters = config_util::list_hci_devices()
            .iter()
            .map(|hci_interface| {
                let enabled: bool = *self.cached_devices.get(&hci_interface).unwrap_or(&false);
                AdapterWithEnabled { hci_interface: *hci_interface, enabled }
            })
            .collect::<Vec<AdapterWithEnabled>>();

        adapters
    }
}
+14 −7
Original line number Diff line number Diff line
use dbus::arg::RefArg;
use dbus::nonblock::SyncConnection;
use dbus::strings::Path;

use dbus_macros::{dbus_method, dbus_proxy_obj, generate_dbus_exporter};

use dbus_macros::{dbus_method, dbus_propmap, dbus_proxy_obj, generate_dbus_exporter};
use dbus_projection::DisconnectWatcher;

use manager_service::iface_bluetooth_manager::{IBluetoothManager, IBluetoothManagerCallback};
use manager_service::iface_bluetooth_manager::{
    AdapterWithEnabled, IBluetoothManager, IBluetoothManagerCallback,
};
use manager_service::RPCProxy;

use crate::dbus_arg::DBusArg;
use crate::dbus_arg::{DBusArg, DBusArgError, RefArgToRust};

#[dbus_propmap(AdapterWithEnabled)]
pub struct AdapterWithEnabledDbus {
    hci_interface: i32,
    enabled: bool,
}

/// D-Bus projection of IBluetoothManager.
struct BluetoothManagerDBus {}
@@ -37,8 +44,8 @@ impl IBluetoothManager for BluetoothManagerDBus {
    #[dbus_method("SetFlossEnabled")]
    fn set_floss_enabled(&mut self, _enabled: bool) {}

    #[dbus_method("ListHciDevices")]
    fn list_hci_devices(&mut self) -> Vec<i32> {
    #[dbus_method("GetAvailableAdapters")]
    fn get_available_adapters(&mut self) -> Vec<AdapterWithEnabled> {
        vec![]
    }
}
+8 −2
Original line number Diff line number Diff line
use crate::RPCProxy;

#[derive(Debug, Default)]
pub struct AdapterWithEnabled {
    pub hci_interface: i32,
    pub enabled: bool,
}

/// Bluetooth stack management API.
pub trait IBluetoothManager {
    /// Starts the Bluetooth stack.
@@ -20,8 +26,8 @@ pub trait IBluetoothManager {
    /// Enables/disables Floss.
    fn set_floss_enabled(&mut self, enabled: bool);

    /// Returns the list of available HCI devices.
    fn list_hci_devices(&mut self) -> Vec<i32>;
    /// Returns a list of available HCI devices and if they are enabled.
    fn get_available_adapters(&mut self) -> Vec<AdapterWithEnabled>;
}

/// Interface of Bluetooth Manager callbacks.