diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2022-03-08 23:31:33 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-03-08 23:31:33 +0000 |
commit | ab46d5fcae86606634766904d719401a7b54278f (patch) | |
tree | cdc8ec21650c738f58866a14503258a382f0af62 /system/gd/rust/linux/stack/src | |
parent | 9e94c3584ac6e70fc2c189927ed58cb9924c4500 (diff) | |
parent | b78353db821a8709cc489859c16a9dcf7515938b (diff) |
Merge "floss: Add GetProfileConnectionState adapter API"
Diffstat (limited to 'system/gd/rust/linux/stack/src')
-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 |
3 files changed, 36 insertions, 2 deletions
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}", |