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

Commit 0854c643 authored by howardchung's avatar howardchung
Browse files

Floss: Export BluetoothAdmin to DBUS

Export the folloing APIs to org.chromium.bluetooth

node /org/chromium/bluetooth/hci0/admin {
  interface org.chromium.bluetooth.BluetoothAdmin {
    methods:
      GetAllowedServices(out aay out);
      GetDevicePolicyEffect(in  a{sv} device,
                            out a{sv} out);
      IsServiceAllowed(in  ay uuid,
                       out b out);
      SetAllowedServices(in  aay services,
                         out b out);
    signals:
    properties:
  };

Bug: 239470589
Test: test it with the following procedures.
service allowed list was set by gdbus call.
1. check classic HS, Classic KB and LE Mouse can function.
2. set allowed list to a single random UUID, and check none of the
   above device can function.
3. set allowed list to A2DP+HFP, and check audio is functioning but the
   other two stay non-functioning.
4. set allowed list to HID, and check HID devices are functioning but no
   audio from the HS.
5. set allowed list to empty, and check all of the above devices are
   functioning.
Tag: #floss

Change-Id: Id6e04193666a51883a4f32920df28cf0ab3cbb3f
parent 7bdb3e58
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
use btstack::bluetooth_admin::{IBluetoothAdmin, PolicyEffect};

use dbus::arg::RefArg;
use dbus_macros::{dbus_method, dbus_propmap, generate_dbus_exporter};

use dbus_projection::dbus_generated;

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

use bt_topshim::btif::Uuid128Bit;

use btstack::bluetooth::BluetoothDevice;

struct IBluetoothAdminDBus {}

#[dbus_propmap(PolicyEffect)]
pub struct PolicyEffectDBus {
    pub service_blocked: Vec<Uuid128Bit>,
}

#[generate_dbus_exporter(export_bluetooth_admin_dbus_intf, "org.chromium.bluetooth.BluetoothAdmin")]
impl IBluetoothAdmin for IBluetoothAdminDBus {
    #[dbus_method("IsServiceAllowed")]
    fn is_service_allowed(&self, uuid: Uuid128Bit) -> bool {
        dbus_generated!()
    }

    #[dbus_method("SetAllowedServices")]
    fn set_allowed_services(&mut self, services: Vec<Uuid128Bit>) -> bool {
        dbus_generated!()
    }

    #[dbus_method("GetAllowedServices")]
    fn get_allowed_services(&self) -> Vec<Uuid128Bit> {
        dbus_generated!()
    }

    #[dbus_method("GetDevicePolicyEffect")]
    fn get_device_policy_effect(&self, device: BluetoothDevice) -> Option<PolicyEffect> {
        dbus_generated!()
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ mod dbus_arg;
mod iface_battery_manager;
mod iface_battery_provider_manager;
mod iface_bluetooth;
mod iface_bluetooth_admin;
mod iface_bluetooth_gatt;
mod iface_bluetooth_media;

@@ -248,6 +249,12 @@ fn main() -> Result<(), Box<dyn Error>> {
            disconnect_watcher.clone(),
        );

        let admin_iface = iface_bluetooth_admin::export_bluetooth_admin_dbus_intf(
            conn.clone(),
            &mut cr.lock().unwrap(),
            disconnect_watcher.clone(),
        );

        // Create mixin object for Bluetooth + Suspend interfaces.
        let mixin = Box::new(iface_bluetooth::BluetoothMixin {
            adapter: bluetooth.clone(),
@@ -267,6 +274,7 @@ fn main() -> Result<(), Box<dyn Error>> {
            &[gatt_iface],
            bluetooth_gatt.clone(),
        );

        cr.lock().unwrap().insert(
            make_object_name(adapter_index, "media"),
            &[media_iface],
@@ -283,6 +291,12 @@ fn main() -> Result<(), Box<dyn Error>> {
            battery_manager.clone(),
        );

        cr.lock().unwrap().insert(
            make_object_name(adapter_index, "admin"),
            &[admin_iface],
            bluetooth_admin.clone(),
        );

        // Hold locks and initialize all interfaces. This must be done AFTER DBus is
        // initialized so DBus can properly enforce user policies.
        {