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

Commit 3296f566 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "floss: Add IBluetoothQA interface" am: 0ce39f61 am: d4ee765a

parents 7c31605b d4ee765a
Loading
Loading
Loading
Loading
+40 −4
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ use crate::callbacks::BtGattCallback;
use crate::ClientContext;
use crate::{console_red, console_yellow, print_error, print_info};
use bt_topshim::btif::BtTransport;
use btstack::bluetooth::{BluetoothDevice, IBluetooth};
use btstack::bluetooth::{BluetoothDevice, IBluetooth, IBluetoothQA};
use btstack::bluetooth_gatt::IBluetoothGatt;
use btstack::uuid::{Profile, UuidHelper, UuidWrapper};
use manager_service::iface_bluetooth_manager::IBluetoothManager;
@@ -85,10 +85,11 @@ fn build_commands() -> HashMap<String, CommandOption> {
    command_options.insert(
        String::from("adapter"),
        CommandOption {
            rules: vec![String::from("adapter <enable|disable|show>")],
            rules: vec![String::from("adapter <enable|disable|show|discoverable|connectable>")],
            description: String::from(
                "Enable/Disable/Show default bluetooth adapter. (e.g. adapter enable)\n
                 Discoverable On/Off (e.g. adapter discoverable on)",
                 Discoverable On/Off (e.g. adapter discoverable on)\n
                 Connectable On/Off (e.g. adapter connectable on)",
            ),
            function_pointer: CommandHandler::cmd_adapter,
        },
@@ -272,7 +273,7 @@ impl CommandHandler {
        }

        let default_adapter = self.context.lock().unwrap().default_adapter;
        enforce_arg_len(args, 1, "adapter <enable|disable|show|discoverable>", || {
        enforce_arg_len(args, 1, "adapter <enable|disable|show|discoverable|connectable>", || {
            match &args[0][0..] {
                "enable" => {
                    self.context.lock().unwrap().manager_dbus.start(default_adapter);
@@ -293,9 +294,11 @@ impl CommandHandler {
                    };
                    let context = self.context.lock().unwrap();
                    let adapter_dbus = context.adapter_dbus.as_ref().unwrap();
                    let qa_dbus = context.qa_dbus.as_ref().unwrap();
                    let name = adapter_dbus.get_name();
                    let uuids = adapter_dbus.get_uuids();
                    let is_discoverable = adapter_dbus.get_discoverable();
                    let is_connectable = qa_dbus.get_connectable();
                    let discoverable_timeout = adapter_dbus.get_discoverable_timeout();
                    let cod = adapter_dbus.get_bluetooth_class();
                    let multi_adv_supported = adapter_dbus.is_multi_advertisement_supported();
@@ -312,6 +315,7 @@ impl CommandHandler {
                    print_info!("State: {}", if enabled { "enabled" } else { "disabled" });
                    print_info!("Discoverable: {}", is_discoverable);
                    print_info!("DiscoverableTimeout: {}s", discoverable_timeout);
                    print_info!("Connectable: {}", is_connectable);
                    print_info!("Class: {:#06x}", cod);
                    print_info!("IsMultiAdvertisementSupported: {}", multi_adv_supported);
                    print_info!("IsLeExtendedAdvertisingSupported: {}", le_ext_adv_supported);
@@ -357,6 +361,38 @@ impl CommandHandler {
                    }
                    _ => println!("Invalid argument for adapter discoverable '{}'", args[1]),
                },
                "connectable" => match &args[1][0..] {
                    "on" => {
                        let ret = self
                            .context
                            .lock()
                            .unwrap()
                            .qa_dbus
                            .as_mut()
                            .unwrap()
                            .set_connectable(true);
                        print_info!(
                            "Set connectable on {}",
                            if ret { "succeeded" } else { "failed" }
                        );
                    }
                    "off" => {
                        let ret = self
                            .context
                            .lock()
                            .unwrap()
                            .qa_dbus
                            .as_mut()
                            .unwrap()
                            .set_connectable(false);
                        print_info!(
                            "Set connectable off {}",
                            if ret { "succeeded" } else { "failed" }
                        );
                    }
                    _ => println!("Invalid argument for adapter connectable '{}'", args[1]),
                },

                _ => {
                    println!("Invalid argument '{}'", args[0]);
                }
+31 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ use bt_topshim::profiles::gatt::GattStatus;
use bt_topshim::profiles::socket::SocketType;

use btstack::bluetooth::{
    BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback,
    BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback, IBluetoothQA,
};
use btstack::bluetooth_gatt::{
    BluetoothGattCharacteristic, BluetoothGattDescriptor, BluetoothGattService,
@@ -433,6 +433,36 @@ impl IBluetooth for BluetoothDBus {
    }
}

pub(crate) struct BluetoothQADBus {
    client_proxy: ClientDBusProxy,
}

impl BluetoothQADBus {
    pub(crate) fn new(conn: Arc<SyncConnection>, index: i32) -> BluetoothQADBus {
        BluetoothQADBus {
            client_proxy: ClientDBusProxy::new(
                conn.clone(),
                String::from("org.chromium.bluetooth"),
                make_object_path(index, "adapter"),
                String::from("org.chromium.bluetooth.BluetoothQA"),
            ),
        }
    }
}

#[generate_dbus_interface_client]
impl IBluetoothQA for BluetoothQADBus {
    #[dbus_method("GetConnectable")]
    fn get_connectable(&self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("SetConnectable")]
    fn set_connectable(&mut self, mode: bool) -> bool {
        dbus_generated!()
    }
}

#[dbus_propmap(AdapterWithEnabled)]
pub struct AdapterWithEnabledDbus {
    hci_interface: i32,
+8 −1
Original line number Diff line number Diff line
@@ -11,7 +11,9 @@ use crate::callbacks::{
    BtCallback, BtConnectionCallback, BtManagerCallback, ScannerCallback, SuspendCallback,
};
use crate::command_handler::CommandHandler;
use crate::dbus_iface::{BluetoothDBus, BluetoothGattDBus, BluetoothManagerDBus, SuspendDBus};
use crate::dbus_iface::{
    BluetoothDBus, BluetoothGattDBus, BluetoothManagerDBus, BluetoothQADBus, SuspendDBus,
};
use crate::editor::AsyncEditor;
use bt_topshim::topstack;
use btstack::bluetooth::{BluetoothDevice, IBluetooth};
@@ -67,6 +69,9 @@ pub(crate) struct ClientContext {
    /// Proxy for adapter interface. Only exists when the default adapter is enabled.
    pub(crate) adapter_dbus: Option<BluetoothDBus>,

    /// Proxy for adapter QA interface. Only exists when the default adapter is enabled.
    pub(crate) qa_dbus: Option<BluetoothQADBus>,

    /// Proxy for GATT interface.
    pub(crate) gatt_dbus: Option<BluetoothGattDBus>,

@@ -109,6 +114,7 @@ impl ClientContext {
            gatt_client_id: None,
            manager_dbus,
            adapter_dbus: None,
            qa_dbus: None,
            gatt_dbus: None,
            suspend_dbus: None,
            fg: tx,
@@ -145,6 +151,7 @@ impl ClientContext {

        let dbus = BluetoothDBus::new(conn.clone(), idx);
        self.adapter_dbus = Some(dbus);
        self.qa_dbus = Some(BluetoothQADBus::new(conn.clone(), idx));

        let gatt_dbus = BluetoothGattDBus::new(conn.clone(), idx);
        self.gatt_dbus = Some(gatt_dbus);
+23 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use bt_topshim::profiles::socket::SocketType;

use btstack::bluetooth::{
    Bluetooth, BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback,
    IBluetoothQA,
};
use btstack::socket_manager::{
    BluetoothServerSocket, BluetoothSocket, BluetoothSocketManager, CallbackId,
@@ -51,6 +52,7 @@ impl_dbus_arg_from_into!(BtStatus, u32);
/// what is listed in the `generate_dbus_exporter` invocation.
pub struct BluetoothMixin {
    pub adapter: Arc<Mutex<Box<Bluetooth>>>,
    pub qa: Arc<Mutex<Box<Bluetooth>>>,
    pub suspend: Arc<Mutex<Box<Suspend>>>,
    pub socket_mgr: Arc<Mutex<Box<BluetoothSocketManager>>>,
}
@@ -562,3 +564,24 @@ impl ISuspendCallback for SuspendCallbackDBus {
        dbus_generated!()
    }
}

#[allow(dead_code)]
struct IBluetoothQADBus {}

#[generate_dbus_exporter(
    export_bluetooth_qa_dbus_intf,
    "org.chromium.bluetooth.BluetoothQA",
    BluetoothMixin,
    qa
)]
impl IBluetoothQA for IBluetoothQADBus {
    #[dbus_method("GetConnectable")]
    fn get_connectable(&self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("SetConnectable")]
    fn set_connectable(&mut self, mode: bool) -> bool {
        dbus_generated!()
    }
}
+7 −1
Original line number Diff line number Diff line
@@ -178,6 +178,11 @@ fn main() -> Result<(), Box<dyn Error>> {
            &mut cr.lock().unwrap(),
            disconnect_watcher.clone(),
        );
        let qa_iface = iface_bluetooth::export_bluetooth_qa_dbus_intf(
            conn.clone(),
            &mut cr.lock().unwrap(),
            disconnect_watcher.clone(),
        );
        let socket_mgr_iface = iface_bluetooth::export_socket_mgr_intf(
            conn.clone(),
            &mut cr.lock().unwrap(),
@@ -205,13 +210,14 @@ fn main() -> Result<(), Box<dyn Error>> {
        // Create mixin object for Bluetooth + Suspend interfaces.
        let mixin = Box::new(iface_bluetooth::BluetoothMixin {
            adapter: bluetooth.clone(),
            qa: bluetooth.clone(),
            suspend: suspend.clone(),
            socket_mgr: bt_sock_mgr.clone(),
        });

        cr.lock().unwrap().insert(
            make_object_name(adapter_index, "adapter"),
            &[adapter_iface, socket_mgr_iface, suspend_iface],
            &[adapter_iface, qa_iface, socket_mgr_iface, suspend_iface],
            mixin,
        );

Loading