From b78353db821a8709cc489859c16a9dcf7515938b Mon Sep 17 00:00:00 2001 From: Katherine Lai Date: Fri, 4 Mar 2022 18:53:58 +0000 Subject: floss: Add GetProfileConnectionState adapter API Bug: 196885239 Tag: #floss Test: Connected earbuds and confirmed API output with btclient Change-Id: I48664528d3850c1bf2c4d8fb99b56337e94f7538 --- system/gd/rust/linux/stack/src/bluetooth.rs | 16 ++++++++++++++++ system/gd/rust/linux/stack/src/bluetooth_media.rs | 16 +++++++++++++++- system/gd/rust/linux/stack/src/uuid.rs | 6 +++++- 3 files changed, 36 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 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; @@ -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 { 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 c26d25cc9a..2b907ff245 100644 --- a/system/gd/rust/linux/stack/src/bluetooth_media.rs +++ b/system/gd/rust/linux/stack/src/bluetooth_media.rs @@ -14,7 +14,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; @@ -228,6 +228,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) -> 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 { + 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}", -- cgit v1.2.3