diff options
-rw-r--r-- | system/gd/rust/linux/client/src/command_handler.rs | 10 | ||||
-rw-r--r-- | system/gd/rust/linux/client/src/dbus_iface.rs | 7 | ||||
-rw-r--r-- | system/gd/rust/linux/service/src/iface_bluetooth.rs | 7 | ||||
-rw-r--r-- | system/gd/rust/linux/stack/src/bluetooth.rs | 16 | ||||
-rw-r--r-- | system/gd/rust/linux/stack/src/bluetooth_media.rs | 16 | ||||
-rw-r--r-- | system/gd/rust/linux/stack/src/uuid.rs | 6 | ||||
-rw-r--r-- | system/gd/rust/topshim/src/profiles/a2dp.rs | 2 | ||||
-rw-r--r-- | system/gd/rust/topshim/src/profiles/hfp.rs | 2 |
8 files changed, 61 insertions, 5 deletions
diff --git a/system/gd/rust/linux/client/src/command_handler.rs b/system/gd/rust/linux/client/src/command_handler.rs index 99711c2edd..d10b005173 100644 --- a/system/gd/rust/linux/client/src/command_handler.rs +++ b/system/gd/rust/linux/client/src/command_handler.rs @@ -8,7 +8,7 @@ use crate::{console_red, console_yellow, print_error, print_info}; use bt_topshim::btif::BtTransport; use btstack::bluetooth::{BluetoothDevice, IBluetooth}; use btstack::bluetooth_gatt::IBluetoothGatt; -use btstack::uuid::UuidHelper; +use btstack::uuid::{Profile, UuidHelper}; use manager_service::iface_bluetooth_manager::IBluetoothManager; const INDENT_CHAR: &str = " "; @@ -273,6 +273,13 @@ impl CommandHandler { let cod = adapter_dbus.get_bluetooth_class(); let multi_adv_supported = adapter_dbus.is_multi_advertisement_supported(); let le_ext_adv_supported = adapter_dbus.is_le_extended_advertising_supported(); + let uuid_helper = UuidHelper::new(); + let enabled_profiles = uuid_helper.get_enabled_profiles(); + let connected_profiles: Vec<Profile> = enabled_profiles + .iter() + .filter(|&&prof| adapter_dbus.get_profile_connection_state(prof) > 0) + .cloned() + .collect(); print_info!("Address: {}", address); print_info!("Name: {}", name); print_info!("State: {}", if enabled { "enabled" } else { "disabled" }); @@ -281,6 +288,7 @@ impl CommandHandler { print_info!("Class: {:#06x}", cod); print_info!("IsMultiAdvertisementSupported: {}", multi_adv_supported); print_info!("IsLeExtendedAdvertisingSupported: {}", le_ext_adv_supported); + print_info!("Connected profiles: {:?}", connected_profiles); print_info!( "Uuids: {}", DisplayList( diff --git a/system/gd/rust/linux/client/src/dbus_iface.rs b/system/gd/rust/linux/client/src/dbus_iface.rs index 4d1ed89a3c..098963adda 100644 --- a/system/gd/rust/linux/client/src/dbus_iface.rs +++ b/system/gd/rust/linux/client/src/dbus_iface.rs @@ -12,6 +12,7 @@ use btstack::bluetooth_gatt::{ IScannerCallback, LePhy, ScanFilter, ScanSettings, }; +use btstack::uuid::Profile; use dbus::arg::{AppendAll, RefArg}; use dbus::nonblock::SyncConnection; @@ -42,6 +43,7 @@ impl_dbus_arg_enum!(GattStatus); impl_dbus_arg_enum!(GattWriteType); impl_dbus_arg_enum!(LePhy); impl_dbus_arg_enum!(GattWriteRequestStatus); +impl_dbus_arg_enum!(Profile); // Represents Uuid128Bit as an array in D-Bus. impl DBusArg for Uuid128Bit { @@ -386,6 +388,11 @@ impl IBluetooth for BluetoothDBus { dbus_generated!() } + #[dbus_method("GetProfileConnectionState")] + fn get_profile_connection_state(&self, profile: Profile) -> u32 { + dbus_generated!() + } + #[dbus_method("GetRemoteUuids")] fn get_remote_uuids(&self, device: BluetoothDevice) -> Vec<Uuid128Bit> { dbus_generated!() diff --git a/system/gd/rust/linux/service/src/iface_bluetooth.rs b/system/gd/rust/linux/service/src/iface_bluetooth.rs index 2447ccefb3..6ace31bf72 100644 --- a/system/gd/rust/linux/service/src/iface_bluetooth.rs +++ b/system/gd/rust/linux/service/src/iface_bluetooth.rs @@ -5,6 +5,7 @@ use bt_topshim::btif::{BtSspVariant, BtTransport, Uuid128Bit}; use btstack::bluetooth::{ BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback, }; +use btstack::uuid::Profile; use btstack::RPCProxy; use dbus::arg::RefArg; @@ -64,6 +65,7 @@ impl IBluetoothCallback for BluetoothCallbackDBus { impl_dbus_arg_enum!(BtTransport); impl_dbus_arg_enum!(BtSspVariant); +impl_dbus_arg_enum!(Profile); #[allow(dead_code)] struct BluetoothConnectionCallbackDBus {} @@ -235,6 +237,11 @@ impl IBluetooth for IBluetoothDBus { dbus_generated!() } + #[dbus_method("GetProfileConnectionState")] + fn get_profile_connection_state(&self, _profile: Profile) -> u32 { + dbus_generated!() + } + #[dbus_method("GetRemoteUuids")] fn get_remote_uuids(&self, _device: BluetoothDevice) -> Vec<Uuid128Bit> { dbus_generated!() diff --git a/system/gd/rust/linux/stack/src/bluetooth.rs b/system/gd/rust/linux/stack/src/bluetooth.rs index 49e9289e4d..6aa3529873 100644 --- a/system/gd/rust/linux/stack/src/bluetooth.rs +++ b/system/gd/rust/linux/stack/src/bluetooth.rs @@ -125,6 +125,9 @@ pub trait IBluetooth { /// Gets the connection state of a single device. fn get_connection_state(&self, device: BluetoothDevice) -> u32; + /// Gets the connection state of a specific profile. + fn get_profile_connection_state(&self, profile: Profile) -> u32; + /// Returns the cached UUIDs of a remote device. fn get_remote_uuids(&self, device: BluetoothDevice) -> Vec<Uuid128Bit>; @@ -1086,6 +1089,19 @@ impl IBluetooth for Bluetooth { self.intf.lock().unwrap().get_connection_state(&addr.unwrap()) } + fn get_profile_connection_state(&self, profile: Profile) -> u32 { + match profile { + Profile::A2dpSink | Profile::A2dpSource => { + self.bluetooth_media.lock().unwrap().get_a2dp_connection_state() + } + Profile::Hfp | Profile::HfpAg => { + self.bluetooth_media.lock().unwrap().get_hfp_connection_state() + } + // TODO: (b/223431229) Profile::Hid and Profile::Hogp + _ => 0, + } + } + fn get_remote_uuids(&self, device: BluetoothDevice) -> Vec<Uuid128Bit> { match self.get_remote_device_property(&device, &BtPropertyType::Uuids) { Some(BluetoothProperty::Uuids(uuids)) => { diff --git a/system/gd/rust/linux/stack/src/bluetooth_media.rs b/system/gd/rust/linux/stack/src/bluetooth_media.rs index 28a659a6cf..0f2488aa10 100644 --- a/system/gd/rust/linux/stack/src/bluetooth_media.rs +++ b/system/gd/rust/linux/stack/src/bluetooth_media.rs @@ -15,7 +15,7 @@ use bt_topshim::profiles::hfp::{ use bt_topshim::topstack; use log::{info, warn}; - +use num_traits::cast::ToPrimitive; use std::collections::HashMap; use std::convert::TryFrom; use std::sync::Arc; @@ -253,6 +253,20 @@ impl BluetoothMedia { f(&callback.1); } } + + pub fn get_hfp_connection_state(&self) -> u32 { + for state in self.hfp_states.values() { + return BthfConnectionState::to_u32(state).unwrap_or(0); + } + 0 + } + + pub fn get_a2dp_connection_state(&self) -> u32 { + for state in self.a2dp_states.values() { + return BtavConnectionState::to_u32(state).unwrap_or(0); + } + 0 + } } fn get_a2dp_dispatcher(tx: Sender<Message>) -> A2dpCallbacksDispatcher { diff --git a/system/gd/rust/linux/stack/src/uuid.rs b/system/gd/rust/linux/stack/src/uuid.rs index c1e2edfb59..010b804a62 100644 --- a/system/gd/rust/linux/stack/src/uuid.rs +++ b/system/gd/rust/linux/stack/src/uuid.rs @@ -36,7 +36,7 @@ pub const COORDINATED_SET: &str = "00001846-0000-1000-8000-00805F9B34FB"; pub const BASE_UUID: &str = "00000000-0000-1000-8000-00805F9B34FB"; /// List of profiles that with known uuids. -#[derive(Clone, Debug, Hash, PartialEq, PartialOrd, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, PartialOrd, Eq, FromPrimitive, ToPrimitive, Copy)] #[repr(u32)] pub enum Profile { A2dpSink, @@ -144,6 +144,10 @@ impl UuidHelper { self.profiles.get(uuid) } + pub fn get_enabled_profiles(&self) -> HashSet<Profile> { + self.enabled_profiles.clone() + } + /// Converts a UUID byte array into a formatted string. pub fn to_string(uuid: &Uuid128Bit) -> String { return String::from(format!("{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", diff --git a/system/gd/rust/topshim/src/profiles/a2dp.rs b/system/gd/rust/topshim/src/profiles/a2dp.rs index 7caa1b2345..d2c31a5589 100644 --- a/system/gd/rust/topshim/src/profiles/a2dp.rs +++ b/system/gd/rust/topshim/src/profiles/a2dp.rs @@ -5,7 +5,7 @@ use num_traits::cast::FromPrimitive; use std::sync::{Arc, Mutex}; use topshim_macros::cb_variant; -#[derive(Debug, FromPrimitive, PartialEq, PartialOrd)] +#[derive(Debug, FromPrimitive, ToPrimitive, PartialEq, PartialOrd)] #[repr(u32)] pub enum BtavConnectionState { Disconnected = 0, diff --git a/system/gd/rust/topshim/src/profiles/hfp.rs b/system/gd/rust/topshim/src/profiles/hfp.rs index 552dd3e22f..2248bbccf8 100644 --- a/system/gd/rust/topshim/src/profiles/hfp.rs +++ b/system/gd/rust/topshim/src/profiles/hfp.rs @@ -5,7 +5,7 @@ use num_traits::cast::FromPrimitive; use std::sync::{Arc, Mutex}; use topshim_macros::cb_variant; -#[derive(Debug, FromPrimitive, PartialEq, PartialOrd)] +#[derive(Debug, FromPrimitive, ToPrimitive, PartialEq, PartialOrd)] #[repr(u32)] pub enum BthfConnectionState { Disconnected = 0, |