From 06296aa32423b3ffe26df53243f4e902b0f3414d Mon Sep 17 00:00:00 2001 From: Jesse Melhuish Date: Wed, 2 Mar 2022 20:24:43 +0000 Subject: floss: Adding remote device API methods. Adds Get* methods for remote device properties. Also adds property output when calling `device info`. Bug: 196887190 Tag: #floss Test: Built floss, verified methods can be called in btclient. Change-Id: I5d06a07223e213436eb4e031b8e5b3ec6f6803ff --- system/gd/rust/linux/stack/src/bluetooth.rs | 44 +++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'system/gd/rust/linux/stack/src') diff --git a/system/gd/rust/linux/stack/src/bluetooth.rs b/system/gd/rust/linux/stack/src/bluetooth.rs index e7bff62c5c..f2a610d83b 100644 --- a/system/gd/rust/linux/stack/src/bluetooth.rs +++ b/system/gd/rust/linux/stack/src/bluetooth.rs @@ -2,8 +2,8 @@ use bt_topshim::btif::{ BaseCallbacks, BaseCallbacksDispatcher, BluetoothInterface, BluetoothProperty, BtAclState, - BtBondState, BtDiscoveryState, BtHciErrorCode, BtPinCode, BtPropertyType, BtScanMode, - BtSspVariant, BtState, BtStatus, BtTransport, RawAddress, Uuid, Uuid128Bit, + BtBondState, BtDeviceType, BtDiscoveryState, BtHciErrorCode, BtPinCode, BtPropertyType, + BtScanMode, BtSspVariant, BtState, BtStatus, BtTransport, RawAddress, Uuid, Uuid128Bit, }; use bt_topshim::{ profiles::hid_host::{HHCallbacksDispatcher, HidHost}, @@ -122,6 +122,18 @@ pub trait IBluetooth { /// Confirm that a pairing should be completed on a bonding device. fn set_pairing_confirmation(&self, device: BluetoothDevice, accept: bool) -> bool; + /// Gets the name of the remote device. + fn get_remote_name(&self, device: BluetoothDevice) -> String; + + /// Gets the type of the remote device. + fn get_remote_type(&self, device: BluetoothDevice) -> BtDeviceType; + + /// Gets the alias of the remote device. + fn get_remote_alias(&self, device: BluetoothDevice) -> String; + + /// Gets the class of the remote device. + fn get_remote_class(&self, device: BluetoothDevice) -> u32; + /// Gets the connection state of a single device. fn get_connection_state(&self, device: BluetoothDevice) -> u32; @@ -1082,6 +1094,34 @@ impl IBluetooth for Bluetooth { ) == 0 } + fn get_remote_name(&self, device: BluetoothDevice) -> String { + match self.get_remote_device_property(&device, &BtPropertyType::BdName) { + Some(BluetoothProperty::BdName(name)) => return name.clone(), + _ => return "".to_string(), + } + } + + fn get_remote_type(&self, device: BluetoothDevice) -> BtDeviceType { + match self.get_remote_device_property(&device, &BtPropertyType::TypeOfDevice) { + Some(BluetoothProperty::TypeOfDevice(device_type)) => return device_type, + _ => return BtDeviceType::Unknown, + } + } + + fn get_remote_alias(&self, device: BluetoothDevice) -> String { + match self.get_remote_device_property(&device, &BtPropertyType::RemoteFriendlyName) { + Some(BluetoothProperty::RemoteFriendlyName(name)) => return name.clone(), + _ => "".to_string(), + } + } + + fn get_remote_class(&self, device: BluetoothDevice) -> u32 { + match self.get_remote_device_property(&device, &BtPropertyType::ClassOfDevice) { + Some(BluetoothProperty::ClassOfDevice(class)) => return class, + _ => 0, + } + } + fn get_connection_state(&self, device: BluetoothDevice) -> u32 { let addr = RawAddress::from_string(device.address.clone()); -- cgit v1.2.3