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

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

Merge "floss: Hook AudioState callback" am: 2ae28d78 am: 13d51e40

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

Change-Id: I4fb9f534727dfa909ba35e6288d14370ba85b0b1
parents ebcc7401 13d51e40
Loading
Loading
Loading
Loading
+31 −6
Original line number Diff line number Diff line
@@ -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;
@@ -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(
@@ -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());
                    }
                }
            }
+7 −0
Original line number Diff line number Diff line
@@ -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 {
@@ -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
+25 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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);
    }
}

@@ -71,6 +87,7 @@ impl Into<RawAddress> for ffi::RustRawAddress {
#[derive(Debug)]
pub enum HfpCallbacks {
    ConnectionState(BthfConnectionState, RawAddress),
    AudioState(BthfAudioState, RawAddress),
}

pub struct HfpCallbacksDispatcher {
@@ -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,