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

Commit c9d59d49 authored by En-Shuo Hsu's avatar En-Shuo Hsu Committed by Automerger Merge Worker
Browse files

Merge "floss: Establish SCO connection with Floss" am: 25bc7082 am: 2c883172 am: 283d95d1

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1920078

Change-Id: I96cd38688fe86bdde419805cbb14c7f3550f57d9
parents 1b905b11 283d95d1
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;
@@ -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 {
@@ -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(),
@@ -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.");
                    }
                }
            }
@@ -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 {
+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