Loading system/gd/rust/linux/service/src/iface_bluetooth_media.rs +6 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,12 @@ impl IBluetoothMedia for IBluetoothMediaDBus { #[dbus_method("StopAudioRequest")] fn stop_audio_request(&mut self) {} #[dbus_method("StartScoCall")] fn start_sco_call(&mut self, device: String) {} #[dbus_method("StopScoCall")] fn stop_sco_call(&mut self, device: String) {} #[dbus_method("GetPresentationPosition")] fn get_presentation_position(&mut self) -> PresentationPosition { PresentationPosition { Loading system/gd/rust/linux/stack/src/bluetooth_media.rs +51 −5 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ use bt_topshim::profiles::hfp::{ use bt_topshim::topstack; use log::warn; use log::{info, warn}; use std::collections::HashMap; use std::convert::TryFrom; Loading Loading @@ -47,6 +47,9 @@ pub trait IBluetoothMedia { fn start_audio_request(&mut self); fn stop_audio_request(&mut self); fn get_presentation_position(&mut self) -> PresentationPosition; fn start_sco_call(&mut self, device: String); fn stop_sco_call(&mut self, device: String); } pub trait IBluetoothMediaCallback { Loading Loading @@ -127,6 +130,7 @@ impl BluetoothMedia { continue; } // TODO: Coordinate with HFP. Should only trigger once. self.for_all_callbacks(|callback| { callback.on_bluetooth_audio_device_added( addr.to_string(), Loading Loading @@ -190,12 +194,29 @@ impl BluetoothMedia { } match state { BthfConnectionState::Connected => { // TODO: Integrate with A2dp info!("HFP connected."); } BthfConnectionState::SlcConnected => { info!("HFP SLC connected."); // TODO: Coordinate with A2DP. Should only trigger once. self.for_all_callbacks(|callback| { callback.on_bluetooth_audio_device_added( addr.to_string(), 0, 0, 0, HfpCodecCapability::CVSD.bits(), ); }); } BthfConnectionState::Disconnected => { info!("HFP disconnected."); } BthfConnectionState::Connecting => { info!("HFP connecting."); } BthfConnectionState::Connecting => {} BthfConnectionState::Disconnected => {} BthfConnectionState::Disconnecting => { // TODO: Integrate with A2dp info!("HFP disconnecting."); } } } Loading Loading @@ -334,6 +355,31 @@ impl IBluetoothMedia for BluetoothMedia { self.a2dp.as_mut().unwrap().stop_audio_request(); } fn start_sco_call(&mut self, device: String) { if let Some(addr) = RawAddress::from_string(device.clone()) { info!("Start sco call for {}", device); match self.hfp.as_mut().unwrap().connect_audio(addr) { 0 => { info!("SCO connect_audio status success."); } x => { warn!("SCO connect_audio status failed: {}", x); } }; } else { warn!("Can't start sco call with: {}", device); } } fn stop_sco_call(&mut self, device: String) { if let Some(addr) = RawAddress::from_string(device.clone()) { info!("Stop sco call for {}", device); self.hfp.as_mut().unwrap().disconnect_audio(addr); } else { warn!("Can't stop sco call with: {}", device); } } fn get_presentation_position(&mut self) -> PresentationPosition { let position = self.a2dp.as_mut().unwrap().get_presentation_position(); PresentationPosition { Loading system/gd/rust/topshim/hfp/hfp_shim.cc +10 −0 Original line number Diff line number Diff line Loading @@ -167,11 +167,21 @@ int HfpIntf::connect(RustRawAddress bt_addr) { return intf_->Connect(&addr); } int HfpIntf::connect_audio(RustRawAddress bt_addr) { RawAddress addr = internal::from_rust_address(bt_addr); return intf_->ConnectAudio(&addr); } int HfpIntf::disconnect(RustRawAddress bt_addr) { RawAddress addr = internal::from_rust_address(bt_addr); return intf_->Disconnect(&addr); } int HfpIntf::disconnect_audio(RustRawAddress bt_addr) { RawAddress addr = internal::from_rust_address(bt_addr); return intf_->DisconnectAudio(&addr); } void HfpIntf::cleanup() {} std::unique_ptr<HfpIntf> GetHfpProfile(const unsigned char* btif) { Loading system/gd/rust/topshim/hfp/hfp_shim.h +2 −0 Original line number Diff line number Diff line Loading @@ -34,7 +34,9 @@ class HfpIntf { int init(); int connect(RustRawAddress bt_addr); int connect_audio(RustRawAddress bt_addr); int disconnect(RustRawAddress bt_addr); int disconnect_audio(RustRawAddress bt_addr); void cleanup(); private: Loading system/gd/rust/topshim/src/profiles/hfp.rs +11 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ pub enum BthfConnectionState { Disconnected = 0, Connecting, Connected, SlcConnected, Disconnecting, } Loading Loading @@ -44,7 +45,9 @@ pub mod ffi { fn init(self: Pin<&mut HfpIntf>) -> i32; fn connect(self: Pin<&mut HfpIntf>, bt_addr: RustRawAddress) -> i32; fn connect_audio(self: Pin<&mut HfpIntf>, bt_addr: RustRawAddress) -> i32; fn disconnect(self: Pin<&mut HfpIntf>, bt_addr: RustRawAddress) -> i32; fn disconnect_audio(self: Pin<&mut HfpIntf>, bt_addr: RustRawAddress) -> i32; fn cleanup(self: Pin<&mut HfpIntf>); } Loading Loading @@ -114,10 +117,18 @@ impl Hfp { self.internal.pin_mut().connect(addr.into()); } pub fn connect_audio(&mut self, addr: RawAddress) -> i32 { self.internal.pin_mut().connect_audio(addr.into()) } pub fn disconnect(&mut self, addr: RawAddress) { self.internal.pin_mut().disconnect(addr.into()); } pub fn disconnect_audio(&mut self, addr: RawAddress) -> i32 { self.internal.pin_mut().disconnect_audio(addr.into()) } pub fn cleanup(&mut self) -> bool { self.internal.pin_mut().cleanup(); true Loading Loading
system/gd/rust/linux/service/src/iface_bluetooth_media.rs +6 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,12 @@ impl IBluetoothMedia for IBluetoothMediaDBus { #[dbus_method("StopAudioRequest")] fn stop_audio_request(&mut self) {} #[dbus_method("StartScoCall")] fn start_sco_call(&mut self, device: String) {} #[dbus_method("StopScoCall")] fn stop_sco_call(&mut self, device: String) {} #[dbus_method("GetPresentationPosition")] fn get_presentation_position(&mut self) -> PresentationPosition { PresentationPosition { Loading
system/gd/rust/linux/stack/src/bluetooth_media.rs +51 −5 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ use bt_topshim::profiles::hfp::{ use bt_topshim::topstack; use log::warn; use log::{info, warn}; use std::collections::HashMap; use std::convert::TryFrom; Loading Loading @@ -47,6 +47,9 @@ pub trait IBluetoothMedia { fn start_audio_request(&mut self); fn stop_audio_request(&mut self); fn get_presentation_position(&mut self) -> PresentationPosition; fn start_sco_call(&mut self, device: String); fn stop_sco_call(&mut self, device: String); } pub trait IBluetoothMediaCallback { Loading Loading @@ -127,6 +130,7 @@ impl BluetoothMedia { continue; } // TODO: Coordinate with HFP. Should only trigger once. self.for_all_callbacks(|callback| { callback.on_bluetooth_audio_device_added( addr.to_string(), Loading Loading @@ -190,12 +194,29 @@ impl BluetoothMedia { } match state { BthfConnectionState::Connected => { // TODO: Integrate with A2dp info!("HFP connected."); } BthfConnectionState::SlcConnected => { info!("HFP SLC connected."); // TODO: Coordinate with A2DP. Should only trigger once. self.for_all_callbacks(|callback| { callback.on_bluetooth_audio_device_added( addr.to_string(), 0, 0, 0, HfpCodecCapability::CVSD.bits(), ); }); } BthfConnectionState::Disconnected => { info!("HFP disconnected."); } BthfConnectionState::Connecting => { info!("HFP connecting."); } BthfConnectionState::Connecting => {} BthfConnectionState::Disconnected => {} BthfConnectionState::Disconnecting => { // TODO: Integrate with A2dp info!("HFP disconnecting."); } } } Loading Loading @@ -334,6 +355,31 @@ impl IBluetoothMedia for BluetoothMedia { self.a2dp.as_mut().unwrap().stop_audio_request(); } fn start_sco_call(&mut self, device: String) { if let Some(addr) = RawAddress::from_string(device.clone()) { info!("Start sco call for {}", device); match self.hfp.as_mut().unwrap().connect_audio(addr) { 0 => { info!("SCO connect_audio status success."); } x => { warn!("SCO connect_audio status failed: {}", x); } }; } else { warn!("Can't start sco call with: {}", device); } } fn stop_sco_call(&mut self, device: String) { if let Some(addr) = RawAddress::from_string(device.clone()) { info!("Stop sco call for {}", device); self.hfp.as_mut().unwrap().disconnect_audio(addr); } else { warn!("Can't stop sco call with: {}", device); } } fn get_presentation_position(&mut self) -> PresentationPosition { let position = self.a2dp.as_mut().unwrap().get_presentation_position(); PresentationPosition { Loading
system/gd/rust/topshim/hfp/hfp_shim.cc +10 −0 Original line number Diff line number Diff line Loading @@ -167,11 +167,21 @@ int HfpIntf::connect(RustRawAddress bt_addr) { return intf_->Connect(&addr); } int HfpIntf::connect_audio(RustRawAddress bt_addr) { RawAddress addr = internal::from_rust_address(bt_addr); return intf_->ConnectAudio(&addr); } int HfpIntf::disconnect(RustRawAddress bt_addr) { RawAddress addr = internal::from_rust_address(bt_addr); return intf_->Disconnect(&addr); } int HfpIntf::disconnect_audio(RustRawAddress bt_addr) { RawAddress addr = internal::from_rust_address(bt_addr); return intf_->DisconnectAudio(&addr); } void HfpIntf::cleanup() {} std::unique_ptr<HfpIntf> GetHfpProfile(const unsigned char* btif) { Loading
system/gd/rust/topshim/hfp/hfp_shim.h +2 −0 Original line number Diff line number Diff line Loading @@ -34,7 +34,9 @@ class HfpIntf { int init(); int connect(RustRawAddress bt_addr); int connect_audio(RustRawAddress bt_addr); int disconnect(RustRawAddress bt_addr); int disconnect_audio(RustRawAddress bt_addr); void cleanup(); private: Loading
system/gd/rust/topshim/src/profiles/hfp.rs +11 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ pub enum BthfConnectionState { Disconnected = 0, Connecting, Connected, SlcConnected, Disconnecting, } Loading Loading @@ -44,7 +45,9 @@ pub mod ffi { fn init(self: Pin<&mut HfpIntf>) -> i32; fn connect(self: Pin<&mut HfpIntf>, bt_addr: RustRawAddress) -> i32; fn connect_audio(self: Pin<&mut HfpIntf>, bt_addr: RustRawAddress) -> i32; fn disconnect(self: Pin<&mut HfpIntf>, bt_addr: RustRawAddress) -> i32; fn disconnect_audio(self: Pin<&mut HfpIntf>, bt_addr: RustRawAddress) -> i32; fn cleanup(self: Pin<&mut HfpIntf>); } Loading Loading @@ -114,10 +117,18 @@ impl Hfp { self.internal.pin_mut().connect(addr.into()); } pub fn connect_audio(&mut self, addr: RawAddress) -> i32 { self.internal.pin_mut().connect_audio(addr.into()) } pub fn disconnect(&mut self, addr: RawAddress) { self.internal.pin_mut().disconnect(addr.into()); } pub fn disconnect_audio(&mut self, addr: RawAddress) -> i32 { self.internal.pin_mut().disconnect_audio(addr.into()) } pub fn cleanup(&mut self) -> bool { self.internal.pin_mut().cleanup(); true Loading