Loading system/gd/rust/linux/client/src/command_handler.rs +10 −4 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ use crate::callbacks::{BtGattCallback, BtGattServerCallback}; use crate::ClientContext; use crate::{console_red, console_yellow, print_error, print_info}; use bt_topshim::btif::{BtConnectionState, BtStatus, BtTransport}; use bt_topshim::profiles::gatt::LePhy; use bt_topshim::profiles::{gatt::LePhy, ProfileConnectionState}; use btstack::bluetooth::{BluetoothDevice, IBluetooth, IBluetoothQA}; use btstack::bluetooth_gatt::{GattWriteType, IBluetoothGatt, ScanSettings, ScanType}; use btstack::socket_manager::{IBluetoothSocketManager, SocketResult}; Loading Loading @@ -401,10 +401,16 @@ impl CommandHandler { let le_ext_adv_supported = adapter_dbus.is_le_extended_advertising_supported(); let wbs_supported = adapter_dbus.is_wbs_supported(); let supported_profiles = UuidHelper::get_supported_profiles(); let connected_profiles: Vec<Profile> = supported_profiles let connected_profiles: Vec<(Profile, ProfileConnectionState)> = supported_profiles .iter() .filter(|&&prof| adapter_dbus.get_profile_connection_state(prof) > 0) .cloned() .map(|&prof| { if let Some(uuid) = UuidHelper::get_profile_uuid(&prof) { (prof, adapter_dbus.get_profile_connection_state(uuid.clone())) } else { (prof, ProfileConnectionState::Disconnected) } }) .filter(|(_prof, state)| state != &ProfileConnectionState::Disconnected) .collect(); print_info!("Address: {}", address); print_info!("Name: {}", name); Loading system/gd/rust/linux/client/src/dbus_iface.rs +3 −3 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use bt_topshim::btif::{ }; use bt_topshim::profiles::gatt::{AdvertisingStatus, GattStatus, LePhy}; use bt_topshim::profiles::socket::SocketType; use bt_topshim::profiles::ProfileConnectionState; use btstack::bluetooth::{ BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback, IBluetoothQA, Loading @@ -29,7 +30,6 @@ use btstack::{RPCProxy, SuspendMode}; use btstack::suspend::{ISuspend, ISuspendCallback, SuspendType}; use btstack::uuid::Profile; use dbus::arg::RefArg; use dbus::nonblock::SyncConnection; Loading Loading @@ -69,7 +69,7 @@ impl_dbus_arg_enum!(GattStatus); impl_dbus_arg_enum!(GattWriteRequestStatus); impl_dbus_arg_enum!(GattWriteType); impl_dbus_arg_enum!(LePhy); impl_dbus_arg_enum!(Profile); impl_dbus_arg_enum!(ProfileConnectionState); impl_dbus_arg_enum!(ScanType); impl_dbus_arg_enum!(SocketType); impl_dbus_arg_enum!(SuspendMode); Loading Loading @@ -572,7 +572,7 @@ impl IBluetooth for BluetoothDBus { } #[dbus_method("GetProfileConnectionState")] fn get_profile_connection_state(&self, profile: Profile) -> u32 { fn get_profile_connection_state(&self, profile: Uuid128Bit) -> ProfileConnectionState { dbus_generated!() } Loading system/gd/rust/linux/service/src/iface_bluetooth.rs +3 −3 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ use bt_topshim::btif::{ BtTransport, Uuid, Uuid128Bit, }; use bt_topshim::profiles::socket::SocketType; use bt_topshim::profiles::ProfileConnectionState; use btstack::bluetooth::{ Bluetooth, BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback, Loading @@ -13,7 +14,6 @@ use btstack::socket_manager::{ IBluetoothSocketManager, IBluetoothSocketManagerCallbacks, SocketId, SocketResult, }; use btstack::suspend::{ISuspend, ISuspendCallback, Suspend, SuspendType}; use btstack::uuid::Profile; use btstack::RPCProxy; use dbus::arg::RefArg; Loading Loading @@ -117,7 +117,7 @@ impl_dbus_arg_enum!(BtDeviceType); impl_dbus_arg_enum!(BtPropertyType); impl_dbus_arg_enum!(BtSspVariant); impl_dbus_arg_enum!(BtTransport); impl_dbus_arg_enum!(Profile); impl_dbus_arg_enum!(ProfileConnectionState); #[allow(dead_code)] struct BluetoothConnectionCallbackDBus {} Loading Loading @@ -340,7 +340,7 @@ impl IBluetooth for IBluetoothDBus { } #[dbus_method("GetProfileConnectionState")] fn get_profile_connection_state(&self, profile: Profile) -> u32 { fn get_profile_connection_state(&self, profile: Uuid128Bit) -> ProfileConnectionState { dbus_generated!() } Loading system/gd/rust/linux/stack/src/bluetooth.rs +15 −10 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ use bt_topshim::{ HHCallbacksDispatcher, HidHost, }, profiles::sdp::{BtSdpRecord, Sdp, SdpCallbacks, SdpCallbacksDispatcher}, profiles::ProfileConnectionState, topstack, }; Loading Loading @@ -174,7 +175,7 @@ pub trait IBluetooth { fn get_connection_state(&self, device: BluetoothDevice) -> BtConnectionState; /// Gets the connection state of a specific profile. fn get_profile_connection_state(&self, profile: Profile) -> u32; fn get_profile_connection_state(&self, profile: Uuid128Bit) -> ProfileConnectionState; /// Returns the cached UUIDs of a remote device. fn get_remote_uuids(&self, device: BluetoothDevice) -> Vec<Uuid128Bit>; Loading Loading @@ -1693,8 +1694,9 @@ impl IBluetooth for Bluetooth { self.intf.lock().unwrap().get_connection_state(&addr.unwrap()) } fn get_profile_connection_state(&self, profile: Profile) -> u32 { match profile { fn get_profile_connection_state(&self, profile: Uuid128Bit) -> ProfileConnectionState { if let Some(known) = UuidHelper::is_known_profile(&profile) { match known { Profile::A2dpSink | Profile::A2dpSource => { self.bluetooth_media.lock().unwrap().get_a2dp_connection_state() } Loading @@ -1702,7 +1704,10 @@ impl IBluetooth for Bluetooth { self.bluetooth_media.lock().unwrap().get_hfp_connection_state() } // TODO: (b/223431229) Profile::Hid and Profile::Hogp _ => 0, _ => ProfileConnectionState::Disconnected, } } else { ProfileConnectionState::Disconnected } } Loading system/gd/rust/linux/stack/src/bluetooth_media.rs +62 −9 Original line number Diff line number Diff line Loading @@ -15,11 +15,11 @@ use bt_topshim::profiles::hfp::{ BthfAudioState, BthfConnectionState, Hfp, HfpCallbacks, HfpCallbacksDispatcher, HfpCodecCapability, }; use bt_topshim::profiles::ProfileConnectionState; use bt_topshim::{metrics, topstack}; use bt_utils::uinput::UInput; use log::{debug, info, warn}; use num_traits::cast::ToPrimitive; use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; use std::sync::Arc; Loading Loading @@ -806,18 +806,71 @@ impl BluetoothMedia { } } pub fn get_hfp_connection_state(&self) -> u32 { pub fn get_hfp_connection_state(&self) -> ProfileConnectionState { if self.hfp_audio_state.values().any(|state| *state == BthfAudioState::Connected) { ProfileConnectionState::Active } else { let mut winning_state = ProfileConnectionState::Disconnected; for state in self.hfp_states.values() { return BthfConnectionState::to_u32(state).unwrap_or(0); // Grab any state higher than the current state. match state { // Any SLC completed state means the profile is connected. BthfConnectionState::SlcConnected => { winning_state = ProfileConnectionState::Connected; } // Connecting or Connected are both counted as connecting for profile state // since it's not a complete connection. BthfConnectionState::Connecting | BthfConnectionState::Connected if winning_state != ProfileConnectionState::Connected => { winning_state = ProfileConnectionState::Connecting; } BthfConnectionState::Disconnecting if winning_state == ProfileConnectionState::Disconnected => { winning_state = ProfileConnectionState::Disconnecting; } _ => (), } } winning_state } 0 } pub fn get_a2dp_connection_state(&self) -> u32 { pub fn get_a2dp_connection_state(&self) -> ProfileConnectionState { if self.a2dp_audio_state.values().any(|state| *state == BtavAudioState::Started) { ProfileConnectionState::Active } else { let mut winning_state = ProfileConnectionState::Disconnected; for state in self.a2dp_states.values() { return BtavConnectionState::to_u32(state).unwrap_or(0); // Grab any state higher than the current state. match state { BtavConnectionState::Connected => { winning_state = ProfileConnectionState::Connected; } BtavConnectionState::Connecting if winning_state != ProfileConnectionState::Connected => { winning_state = ProfileConnectionState::Connecting; } BtavConnectionState::Disconnecting if winning_state == ProfileConnectionState::Disconnected => { winning_state = ProfileConnectionState::Disconnecting; } _ => (), } } winning_state } 0 } } Loading Loading
system/gd/rust/linux/client/src/command_handler.rs +10 −4 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ use crate::callbacks::{BtGattCallback, BtGattServerCallback}; use crate::ClientContext; use crate::{console_red, console_yellow, print_error, print_info}; use bt_topshim::btif::{BtConnectionState, BtStatus, BtTransport}; use bt_topshim::profiles::gatt::LePhy; use bt_topshim::profiles::{gatt::LePhy, ProfileConnectionState}; use btstack::bluetooth::{BluetoothDevice, IBluetooth, IBluetoothQA}; use btstack::bluetooth_gatt::{GattWriteType, IBluetoothGatt, ScanSettings, ScanType}; use btstack::socket_manager::{IBluetoothSocketManager, SocketResult}; Loading Loading @@ -401,10 +401,16 @@ impl CommandHandler { let le_ext_adv_supported = adapter_dbus.is_le_extended_advertising_supported(); let wbs_supported = adapter_dbus.is_wbs_supported(); let supported_profiles = UuidHelper::get_supported_profiles(); let connected_profiles: Vec<Profile> = supported_profiles let connected_profiles: Vec<(Profile, ProfileConnectionState)> = supported_profiles .iter() .filter(|&&prof| adapter_dbus.get_profile_connection_state(prof) > 0) .cloned() .map(|&prof| { if let Some(uuid) = UuidHelper::get_profile_uuid(&prof) { (prof, adapter_dbus.get_profile_connection_state(uuid.clone())) } else { (prof, ProfileConnectionState::Disconnected) } }) .filter(|(_prof, state)| state != &ProfileConnectionState::Disconnected) .collect(); print_info!("Address: {}", address); print_info!("Name: {}", name); Loading
system/gd/rust/linux/client/src/dbus_iface.rs +3 −3 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use bt_topshim::btif::{ }; use bt_topshim::profiles::gatt::{AdvertisingStatus, GattStatus, LePhy}; use bt_topshim::profiles::socket::SocketType; use bt_topshim::profiles::ProfileConnectionState; use btstack::bluetooth::{ BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback, IBluetoothQA, Loading @@ -29,7 +30,6 @@ use btstack::{RPCProxy, SuspendMode}; use btstack::suspend::{ISuspend, ISuspendCallback, SuspendType}; use btstack::uuid::Profile; use dbus::arg::RefArg; use dbus::nonblock::SyncConnection; Loading Loading @@ -69,7 +69,7 @@ impl_dbus_arg_enum!(GattStatus); impl_dbus_arg_enum!(GattWriteRequestStatus); impl_dbus_arg_enum!(GattWriteType); impl_dbus_arg_enum!(LePhy); impl_dbus_arg_enum!(Profile); impl_dbus_arg_enum!(ProfileConnectionState); impl_dbus_arg_enum!(ScanType); impl_dbus_arg_enum!(SocketType); impl_dbus_arg_enum!(SuspendMode); Loading Loading @@ -572,7 +572,7 @@ impl IBluetooth for BluetoothDBus { } #[dbus_method("GetProfileConnectionState")] fn get_profile_connection_state(&self, profile: Profile) -> u32 { fn get_profile_connection_state(&self, profile: Uuid128Bit) -> ProfileConnectionState { dbus_generated!() } Loading
system/gd/rust/linux/service/src/iface_bluetooth.rs +3 −3 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ use bt_topshim::btif::{ BtTransport, Uuid, Uuid128Bit, }; use bt_topshim::profiles::socket::SocketType; use bt_topshim::profiles::ProfileConnectionState; use btstack::bluetooth::{ Bluetooth, BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback, Loading @@ -13,7 +14,6 @@ use btstack::socket_manager::{ IBluetoothSocketManager, IBluetoothSocketManagerCallbacks, SocketId, SocketResult, }; use btstack::suspend::{ISuspend, ISuspendCallback, Suspend, SuspendType}; use btstack::uuid::Profile; use btstack::RPCProxy; use dbus::arg::RefArg; Loading Loading @@ -117,7 +117,7 @@ impl_dbus_arg_enum!(BtDeviceType); impl_dbus_arg_enum!(BtPropertyType); impl_dbus_arg_enum!(BtSspVariant); impl_dbus_arg_enum!(BtTransport); impl_dbus_arg_enum!(Profile); impl_dbus_arg_enum!(ProfileConnectionState); #[allow(dead_code)] struct BluetoothConnectionCallbackDBus {} Loading Loading @@ -340,7 +340,7 @@ impl IBluetooth for IBluetoothDBus { } #[dbus_method("GetProfileConnectionState")] fn get_profile_connection_state(&self, profile: Profile) -> u32 { fn get_profile_connection_state(&self, profile: Uuid128Bit) -> ProfileConnectionState { dbus_generated!() } Loading
system/gd/rust/linux/stack/src/bluetooth.rs +15 −10 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ use bt_topshim::{ HHCallbacksDispatcher, HidHost, }, profiles::sdp::{BtSdpRecord, Sdp, SdpCallbacks, SdpCallbacksDispatcher}, profiles::ProfileConnectionState, topstack, }; Loading Loading @@ -174,7 +175,7 @@ pub trait IBluetooth { fn get_connection_state(&self, device: BluetoothDevice) -> BtConnectionState; /// Gets the connection state of a specific profile. fn get_profile_connection_state(&self, profile: Profile) -> u32; fn get_profile_connection_state(&self, profile: Uuid128Bit) -> ProfileConnectionState; /// Returns the cached UUIDs of a remote device. fn get_remote_uuids(&self, device: BluetoothDevice) -> Vec<Uuid128Bit>; Loading Loading @@ -1693,8 +1694,9 @@ impl IBluetooth for Bluetooth { self.intf.lock().unwrap().get_connection_state(&addr.unwrap()) } fn get_profile_connection_state(&self, profile: Profile) -> u32 { match profile { fn get_profile_connection_state(&self, profile: Uuid128Bit) -> ProfileConnectionState { if let Some(known) = UuidHelper::is_known_profile(&profile) { match known { Profile::A2dpSink | Profile::A2dpSource => { self.bluetooth_media.lock().unwrap().get_a2dp_connection_state() } Loading @@ -1702,7 +1704,10 @@ impl IBluetooth for Bluetooth { self.bluetooth_media.lock().unwrap().get_hfp_connection_state() } // TODO: (b/223431229) Profile::Hid and Profile::Hogp _ => 0, _ => ProfileConnectionState::Disconnected, } } else { ProfileConnectionState::Disconnected } } Loading
system/gd/rust/linux/stack/src/bluetooth_media.rs +62 −9 Original line number Diff line number Diff line Loading @@ -15,11 +15,11 @@ use bt_topshim::profiles::hfp::{ BthfAudioState, BthfConnectionState, Hfp, HfpCallbacks, HfpCallbacksDispatcher, HfpCodecCapability, }; use bt_topshim::profiles::ProfileConnectionState; use bt_topshim::{metrics, topstack}; use bt_utils::uinput::UInput; use log::{debug, info, warn}; use num_traits::cast::ToPrimitive; use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; use std::sync::Arc; Loading Loading @@ -806,18 +806,71 @@ impl BluetoothMedia { } } pub fn get_hfp_connection_state(&self) -> u32 { pub fn get_hfp_connection_state(&self) -> ProfileConnectionState { if self.hfp_audio_state.values().any(|state| *state == BthfAudioState::Connected) { ProfileConnectionState::Active } else { let mut winning_state = ProfileConnectionState::Disconnected; for state in self.hfp_states.values() { return BthfConnectionState::to_u32(state).unwrap_or(0); // Grab any state higher than the current state. match state { // Any SLC completed state means the profile is connected. BthfConnectionState::SlcConnected => { winning_state = ProfileConnectionState::Connected; } // Connecting or Connected are both counted as connecting for profile state // since it's not a complete connection. BthfConnectionState::Connecting | BthfConnectionState::Connected if winning_state != ProfileConnectionState::Connected => { winning_state = ProfileConnectionState::Connecting; } BthfConnectionState::Disconnecting if winning_state == ProfileConnectionState::Disconnected => { winning_state = ProfileConnectionState::Disconnecting; } _ => (), } } winning_state } 0 } pub fn get_a2dp_connection_state(&self) -> u32 { pub fn get_a2dp_connection_state(&self) -> ProfileConnectionState { if self.a2dp_audio_state.values().any(|state| *state == BtavAudioState::Started) { ProfileConnectionState::Active } else { let mut winning_state = ProfileConnectionState::Disconnected; for state in self.a2dp_states.values() { return BtavConnectionState::to_u32(state).unwrap_or(0); // Grab any state higher than the current state. match state { BtavConnectionState::Connected => { winning_state = ProfileConnectionState::Connected; } BtavConnectionState::Connecting if winning_state != ProfileConnectionState::Connected => { winning_state = ProfileConnectionState::Connecting; } BtavConnectionState::Disconnecting if winning_state == ProfileConnectionState::Disconnected => { winning_state = ProfileConnectionState::Disconnecting; } _ => (), } } winning_state } 0 } } Loading