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

Commit e923d43e authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi
Browse files

floss: Implement Get/Set Bluetooth Class

This implements a getter + setter exposed over dbus for the adapters
class of device.

Bug: 196885232
Tag: #floss
Test: btclient + adapter show
Change-Id: If98623430a815dce88fbe78470195ff2f9c4e542
parent 7b479d71
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -264,9 +264,18 @@ impl CommandHandler {
                };
                let name = self.context.lock().unwrap().adapter_dbus.as_ref().unwrap().get_name();
                let uuids = self.context.lock().unwrap().adapter_dbus.as_ref().unwrap().get_uuids();
                let cod = self
                    .context
                    .lock()
                    .unwrap()
                    .adapter_dbus
                    .as_ref()
                    .unwrap()
                    .get_bluetooth_class();
                print_info!("Address: {}", address);
                print_info!("Name: {}", name);
                print_info!("State: {}", if enabled { "enabled" } else { "disabled" });
                print_info!("Class: {:#06x}", cod);
                print_info!(
                    "Uuids: {}",
                    DisplayList(
+8 −0
Original line number Diff line number Diff line
@@ -301,6 +301,14 @@ impl IBluetooth for BluetoothDBus {
        self.client_proxy.method("SetName", (name,))
    }

    fn get_bluetooth_class(&self) -> u32 {
        self.client_proxy.method("GetBluetoothClass", ())
    }

    fn set_bluetooth_class(&self, cod: u32) -> bool {
        self.client_proxy.method("SetBluetoothClass", (cod,))
    }

    fn start_discovery(&self) -> bool {
        self.client_proxy.method("StartDiscovery", ())
    }
+10 −0
Original line number Diff line number Diff line
@@ -120,6 +120,16 @@ impl IBluetooth for IBluetoothDBus {
        true
    }

    #[dbus_method("GetBluetoothClass")]
    fn get_bluetooth_class(&self) -> u32 {
        0
    }

    #[dbus_method("SetBluetoothClass")]
    fn set_bluetooth_class(&self, cod: u32) -> bool {
        true
    }

    #[dbus_method("StartDiscovery")]
    fn start_discovery(&self) -> bool {
        true
+23 −0
Original line number Diff line number Diff line
@@ -61,6 +61,12 @@ pub trait IBluetooth {
    /// Sets the local adapter name.
    fn set_name(&self, name: String) -> bool;

    /// Gets the bluetooth class.
    fn get_bluetooth_class(&self) -> u32;

    /// Sets the bluetooth class.
    fn set_bluetooth_class(&self, cod: u32) -> bool;

    /// Starts BREDR Inquiry.
    fn start_discovery(&self) -> bool;

@@ -429,6 +435,9 @@ impl BtifBluetoothCallbacks for Bluetooth {
        } else {
            // Trigger properties update
            self.intf.lock().unwrap().get_adapter_properties();

            // Also need to manually request some properties
            self.intf.lock().unwrap().get_adapter_property(BtPropertyType::ClassOfDevice);
        }
    }

@@ -763,6 +772,20 @@ impl IBluetooth for Bluetooth {
        self.intf.lock().unwrap().set_adapter_property(BluetoothProperty::BdName(name)) == 0
    }

    fn get_bluetooth_class(&self) -> u32 {
        match self.properties.get(&BtPropertyType::ClassOfDevice) {
            Some(prop) => match prop {
                BluetoothProperty::ClassOfDevice(cod) => cod.clone(),
                _ => 0,
            },
            _ => 0,
        }
    }

    fn set_bluetooth_class(&self, cod: u32) -> bool {
        self.intf.lock().unwrap().set_adapter_property(BluetoothProperty::ClassOfDevice(cod)) == 0
    }

    fn start_discovery(&self) -> bool {
        self.intf.lock().unwrap().start_discovery() == 0
    }