Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3db1182 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi Committed by En-Shuo Hsu
Browse files

floss: Establish SCO connection with Floss

Add StartScoCall and StopScoCall for clients to start the sco data path.
Trigger the on_bluetooth_audio_device_added when HFP SLC is ready.

Bug: 213406997
Bug: 195344366
Tag: #floss
Test: Build and check log
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 char lines

Change-Id: I164a6a2109b08037ed1500b88d23542516b96e45
parent 3dcce006
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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 {
+51 −5
Original line number Diff line number Diff line
@@ -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;
@@ -48,6 +48,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 {
@@ -128,6 +131,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(),
@@ -191,12 +195,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.");
                    }
                }
            }
@@ -335,6 +356,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 {
+10 −0
Original line number Diff line number Diff line
@@ -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) {
+2 −0
Original line number Diff line number Diff line
@@ -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:
+11 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ pub enum BthfConnectionState {
    Disconnected = 0,
    Connecting,
    Connected,
    SlcConnected,
    Disconnecting,
}

@@ -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>);

    }
@@ -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