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

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

floss: Add device info command to client

Add a "device info" command to the client that will print information
about the devices. Trigger SDP when the "device found" callback is
called so that all found devices also have UUID information.

Bug: 196887189
Tag: #floss
Test: "btclient> device info" with found device
Change-Id: I0e976e1405cd94aa8050737358474854696d0c5f
parent 0734b40f
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -112,6 +112,13 @@ fn build_commands() -> HashMap<String, CommandOption> {
            function_pointer: CommandHandler::cmd_bond,
        },
    );
    command_options.insert(
        String::from("device"),
        CommandOption {
            description: String::from("Take action on a remote device. (i.e. info)"),
            function_pointer: CommandHandler::cmd_device,
        },
    );
    command_options.insert(
        String::from("discovery"),
        CommandOption {
@@ -325,6 +332,45 @@ impl CommandHandler {
        });
    }

    fn cmd_device(&mut self, args: &Vec<String>) {
        if !self.context.lock().unwrap().adapter_ready {
            self.adapter_not_ready();
            return;
        }

        enforce_arg_len(args, 2, "device <info> <address>", || match &args[0][0..] {
            "info" => {
                let device = BluetoothDevice {
                    address: String::from(&args[1]),
                    name: String::from("Classic Device"),
                };

                let uuids = self
                    .context
                    .lock()
                    .unwrap()
                    .adapter_dbus
                    .as_ref()
                    .unwrap()
                    .get_remote_uuids(device.clone());

                print_info!("Address: {}", &device.address);
                print_info!(
                    "Uuids: {}",
                    DisplayList(
                        uuids
                            .iter()
                            .map(|&x| DisplayUuid128Bit(x))
                            .collect::<Vec<DisplayUuid128Bit>>()
                    )
                );
            }
            _ => {
                println!("Invalid argument '{}'", args[0]);
            }
        });
    }

    fn cmd_gatt(&mut self, args: &Vec<String>) {
        if !self.context.lock().unwrap().adapter_ready {
            self.adapter_not_ready();
+4 −4
Original line number Diff line number Diff line
@@ -429,8 +429,8 @@ impl BtifBluetoothCallbacks for Bluetooth {
    }

    fn discovery_state(&mut self, state: BtDiscoveryState) {
        // Clear found devices when discovery session ends
        if &state == &BtDiscoveryState::Stopped {
        // Clear found devices when discovery session starts
        if !self.is_discovering && &state == &BtDiscoveryState::Started {
            self.found_devices.clear();
        }

@@ -705,13 +705,13 @@ impl IBluetooth for Bluetooth {

    fn get_remote_uuids(&self, device: BluetoothDevice) -> Vec<Uuid128Bit> {
        // Device must exist in either bonded or found list
        let device = self
        let found = self
            .bonded_devices
            .get(&device.address)
            .or_else(|| self.found_devices.get(&device.address));

        // Extract property from the device
        return device
        return found
            .and_then(|d| {
                if let Some(u) = d.properties.get(&BtPropertyType::Uuids) {
                    match u {