Loading system/gd/rust/linux/stack/src/bluetooth_media.rs +31 −6 Original line number Diff line number Diff line Loading @@ -8,7 +8,8 @@ use bt_topshim::profiles::a2dp::{ }; use bt_topshim::profiles::avrcp::{Avrcp, AvrcpCallbacks, AvrcpCallbacksDispatcher}; use bt_topshim::profiles::hfp::{ BthfConnectionState, Hfp, HfpCallbacks, HfpCallbacksDispatcher, HfpCodecCapability, BthfAudioState, BthfConnectionState, Hfp, HfpCallbacks, HfpCallbacksDispatcher, HfpCodecCapability, }; use bt_topshim::topstack; Loading Loading @@ -194,10 +195,10 @@ impl BluetoothMedia { } match state { BthfConnectionState::Connected => { info!("HFP connected."); info!("{} HFP connected.", addr.to_string()); } BthfConnectionState::SlcConnected => { info!("HFP SLC connected."); info!("{} HFP SLC connected.", addr.to_string()); // TODO: Coordinate with A2DP. Should only trigger once. self.for_all_callbacks(|callback| { callback.on_bluetooth_audio_device_added( Loading @@ -210,13 +211,37 @@ impl BluetoothMedia { }); } BthfConnectionState::Disconnected => { info!("HFP disconnected."); info!("{} HFP disconnected.", addr.to_string()); } BthfConnectionState::Connecting => { info!("HFP connecting."); info!("{} HFP connecting.", addr.to_string()); } BthfConnectionState::Disconnecting => { info!("HFP disconnecting."); info!("{} HFP disconnecting.", addr.to_string()); } } self.hfp_states.insert(addr, state); } HfpCallbacks::AudioState(state, addr) => { if self.hfp_states.get(&addr).is_none() || BthfConnectionState::SlcConnected != *self.hfp_states.get(&addr).unwrap() { warn!("{} not connected or SLC not ready", addr.to_string()); return; } match state { BthfAudioState::Connected => { info!("{} HFP audio connected.", addr.to_string()); } BthfAudioState::Disconnected => { info!("{} HFP audio disconnected.", addr.to_string()); } BthfAudioState::Connecting => { info!("{} HFP audio connecting.", addr.to_string()); } BthfAudioState::Disconnecting => { info!("{} HFP audio disconnecting.", addr.to_string()); } } } Loading system/gd/rust/topshim/hfp/hfp_shim.cc +7 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,11 @@ static void connection_state_cb(bluetooth::headset::bthf_connection_state_t stat rusty::hfp_connection_state_callback(state, raddr); } static void audio_state_cb(bluetooth::headset::bthf_audio_state_t state, RawAddress* addr) { RustRawAddress raddr = rusty::CopyToRustAddress(*addr); rusty::hfp_audio_state_callback(state, raddr); } } // namespace internal class DBusHeadsetCallbacks : public headset::Callbacks { Loading @@ -54,6 +59,8 @@ class DBusHeadsetCallbacks : public headset::Callbacks { void AudioStateCallback(headset::bthf_audio_state_t state, RawAddress* bd_addr) override { LOG_INFO("AudioStateCallback %u from %s", state, bd_addr->ToString().c_str()); topshim::rust::internal::audio_state_cb(state, bd_addr); switch (state) { case headset::bthf_audio_state_t::BTHF_AUDIO_STATE_CONNECTED: // This triggers a +CIEV command to set the call status for HFP Loading system/gd/rust/topshim/src/profiles/hfp.rs +25 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,21 @@ impl From<u32> for BthfConnectionState { } } #[derive(Debug, FromPrimitive, PartialEq, PartialOrd)] #[repr(u32)] pub enum BthfAudioState { Disconnected = 0, Connecting, Connected, Disconnecting, } impl From<u32> for BthfAudioState { fn from(item: u32) -> Self { BthfAudioState::from_u32(item).unwrap() } } bitflags! { pub struct HfpCodecCapability: i32 { const UNSUPPORTED = 0b00; Loading Loading @@ -53,6 +68,7 @@ pub mod ffi { } extern "Rust" { fn hfp_connection_state_callback(state: u32, addr: RustRawAddress); fn hfp_audio_state_callback(state: u32, addr: RustRawAddress); } } Loading @@ -71,6 +87,7 @@ impl Into<RawAddress> for ffi::RustRawAddress { #[derive(Debug)] pub enum HfpCallbacks { ConnectionState(BthfConnectionState, RawAddress), AudioState(BthfAudioState, RawAddress), } pub struct HfpCallbacksDispatcher { Loading @@ -87,6 +104,14 @@ cb_variant!( } ); cb_variant!( HfpCb, hfp_audio_state_callback -> HfpCallbacks::AudioState, u32 -> BthfAudioState, ffi::RustRawAddress -> RawAddress, { let _1 = _1.into(); } ); pub struct Hfp { internal: cxx::UniquePtr<ffi::HfpIntf>, _is_init: bool, Loading Loading
system/gd/rust/linux/stack/src/bluetooth_media.rs +31 −6 Original line number Diff line number Diff line Loading @@ -8,7 +8,8 @@ use bt_topshim::profiles::a2dp::{ }; use bt_topshim::profiles::avrcp::{Avrcp, AvrcpCallbacks, AvrcpCallbacksDispatcher}; use bt_topshim::profiles::hfp::{ BthfConnectionState, Hfp, HfpCallbacks, HfpCallbacksDispatcher, HfpCodecCapability, BthfAudioState, BthfConnectionState, Hfp, HfpCallbacks, HfpCallbacksDispatcher, HfpCodecCapability, }; use bt_topshim::topstack; Loading Loading @@ -194,10 +195,10 @@ impl BluetoothMedia { } match state { BthfConnectionState::Connected => { info!("HFP connected."); info!("{} HFP connected.", addr.to_string()); } BthfConnectionState::SlcConnected => { info!("HFP SLC connected."); info!("{} HFP SLC connected.", addr.to_string()); // TODO: Coordinate with A2DP. Should only trigger once. self.for_all_callbacks(|callback| { callback.on_bluetooth_audio_device_added( Loading @@ -210,13 +211,37 @@ impl BluetoothMedia { }); } BthfConnectionState::Disconnected => { info!("HFP disconnected."); info!("{} HFP disconnected.", addr.to_string()); } BthfConnectionState::Connecting => { info!("HFP connecting."); info!("{} HFP connecting.", addr.to_string()); } BthfConnectionState::Disconnecting => { info!("HFP disconnecting."); info!("{} HFP disconnecting.", addr.to_string()); } } self.hfp_states.insert(addr, state); } HfpCallbacks::AudioState(state, addr) => { if self.hfp_states.get(&addr).is_none() || BthfConnectionState::SlcConnected != *self.hfp_states.get(&addr).unwrap() { warn!("{} not connected or SLC not ready", addr.to_string()); return; } match state { BthfAudioState::Connected => { info!("{} HFP audio connected.", addr.to_string()); } BthfAudioState::Disconnected => { info!("{} HFP audio disconnected.", addr.to_string()); } BthfAudioState::Connecting => { info!("{} HFP audio connecting.", addr.to_string()); } BthfAudioState::Disconnecting => { info!("{} HFP audio disconnecting.", addr.to_string()); } } } Loading
system/gd/rust/topshim/hfp/hfp_shim.cc +7 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,11 @@ static void connection_state_cb(bluetooth::headset::bthf_connection_state_t stat rusty::hfp_connection_state_callback(state, raddr); } static void audio_state_cb(bluetooth::headset::bthf_audio_state_t state, RawAddress* addr) { RustRawAddress raddr = rusty::CopyToRustAddress(*addr); rusty::hfp_audio_state_callback(state, raddr); } } // namespace internal class DBusHeadsetCallbacks : public headset::Callbacks { Loading @@ -54,6 +59,8 @@ class DBusHeadsetCallbacks : public headset::Callbacks { void AudioStateCallback(headset::bthf_audio_state_t state, RawAddress* bd_addr) override { LOG_INFO("AudioStateCallback %u from %s", state, bd_addr->ToString().c_str()); topshim::rust::internal::audio_state_cb(state, bd_addr); switch (state) { case headset::bthf_audio_state_t::BTHF_AUDIO_STATE_CONNECTED: // This triggers a +CIEV command to set the call status for HFP Loading
system/gd/rust/topshim/src/profiles/hfp.rs +25 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,21 @@ impl From<u32> for BthfConnectionState { } } #[derive(Debug, FromPrimitive, PartialEq, PartialOrd)] #[repr(u32)] pub enum BthfAudioState { Disconnected = 0, Connecting, Connected, Disconnecting, } impl From<u32> for BthfAudioState { fn from(item: u32) -> Self { BthfAudioState::from_u32(item).unwrap() } } bitflags! { pub struct HfpCodecCapability: i32 { const UNSUPPORTED = 0b00; Loading Loading @@ -53,6 +68,7 @@ pub mod ffi { } extern "Rust" { fn hfp_connection_state_callback(state: u32, addr: RustRawAddress); fn hfp_audio_state_callback(state: u32, addr: RustRawAddress); } } Loading @@ -71,6 +87,7 @@ impl Into<RawAddress> for ffi::RustRawAddress { #[derive(Debug)] pub enum HfpCallbacks { ConnectionState(BthfConnectionState, RawAddress), AudioState(BthfAudioState, RawAddress), } pub struct HfpCallbacksDispatcher { Loading @@ -87,6 +104,14 @@ cb_variant!( } ); cb_variant!( HfpCb, hfp_audio_state_callback -> HfpCallbacks::AudioState, u32 -> BthfAudioState, ffi::RustRawAddress -> RawAddress, { let _1 = _1.into(); } ); pub struct Hfp { internal: cxx::UniquePtr<ffi::HfpIntf>, _is_init: bool, Loading