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

Commit b6f11254 authored by Jeremy Wu's avatar Jeremy Wu
Browse files

Floss: add le_audio to profile policy

This is only enabled when the chrome flag
|CrOSLateBootBluetoothAudioLEAudioOnly| is enabled.

Bug: 317682584
Test: m Bluetooth
Change-Id: I70d59200ff6ab7ef2fb9fb4cdf16dbcd18e60348
parent d3b63c7f
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -13,6 +13,10 @@ use crate::{ClientContext, GattRequest};
use bt_topshim::btif::{BtBondState, BtPropertyType, BtSspVariant, BtStatus, Uuid128Bit};
use bt_topshim::profiles::gatt::{AdvertisingStatus, GattStatus, LePhy};
use bt_topshim::profiles::hfp::HfpCodecId;
use bt_topshim::profiles::le_audio::{
    BtLeAudioDirection, BtLeAudioGroupNodeStatus, BtLeAudioGroupStatus, BtLeAudioGroupStreamStatus,
    BtLeAudioUnicastMonitorModeStatus,
};
use bt_topshim::profiles::sdp::BtSdpRecord;
use btstack::battery_manager::{BatterySet, IBatteryManagerCallback};
use btstack::bluetooth::{
@@ -1386,6 +1390,33 @@ fn timestamp_to_string(ts_in_us: u64) -> String {
}

impl IBluetoothMediaCallback for MediaCallback {
    // TODO(b/333341411): implement callbacks for client as necessary
    fn on_lea_group_connected(&mut self, _group_id: i32, _name: String) {}
    fn on_lea_group_disconnected(&mut self, _group_id: i32) {}
    fn on_lea_group_status(&mut self, _group_id: i32, _status: BtLeAudioGroupStatus) {}
    fn on_lea_group_node_status(
        &mut self,
        _addr: String,
        _group_id: i32,
        _status: BtLeAudioGroupNodeStatus,
    ) {
    }
    fn on_lea_audio_conf(
        &mut self,
        _direction: u8,
        _group_id: i32,
        _snk_audio_location: u32,
        _src_audio_location: u32,
        _avail_cont: u16,
    ) {
    }
    fn on_lea_unicast_monitor_mode_status(
        &mut self,
        _direction: BtLeAudioDirection,
        _status: BtLeAudioUnicastMonitorModeStatus,
    ) {
    }
    fn on_lea_group_stream_status(&mut self, _group_id: i32, _status: BtLeAudioGroupStreamStatus) {}
    fn on_bluetooth_audio_device_added(&mut self, _device: BluetoothAudioDevice) {}
    fn on_bluetooth_audio_device_removed(&mut self, _addr: String) {}
    fn on_absolute_volume_supported_changed(&mut self, _supported: bool) {}
+154 −0
Original line number Diff line number Diff line
@@ -12,6 +12,11 @@ use bt_topshim::profiles::avrcp::PlayerMetadata;
use bt_topshim::profiles::gatt::{AdvertisingStatus, GattStatus, LeDiscMode, LePhy};
use bt_topshim::profiles::hfp::{EscoCodingFormat, HfpCodecBitId, HfpCodecFormat};
use bt_topshim::profiles::hid_host::BthhReportType;
use bt_topshim::profiles::le_audio::{
    BtLeAudioContentType, BtLeAudioDirection, BtLeAudioGroupNodeStatus, BtLeAudioGroupStatus,
    BtLeAudioGroupStreamStatus, BtLeAudioSource, BtLeAudioUnicastMonitorModeStatus, BtLeAudioUsage,
    BtLePcmConfig,
};
use bt_topshim::profiles::sdp::{
    BtSdpDipRecord, BtSdpHeaderOverlay, BtSdpMasRecord, BtSdpMnsRecord, BtSdpMpsRecord,
    BtSdpOpsRecord, BtSdpPceRecord, BtSdpPseRecord, BtSdpRecord, BtSdpSapRecord, BtSdpType,
@@ -85,6 +90,14 @@ impl_dbus_arg_enum!(BtPropertyType);
impl_dbus_arg_enum!(BtSspVariant);
impl_dbus_arg_enum!(BtStatus);
impl_dbus_arg_enum!(BtTransport);
impl_dbus_arg_from_into!(BtLeAudioUsage, i32);
impl_dbus_arg_from_into!(BtLeAudioContentType, i32);
impl_dbus_arg_from_into!(BtLeAudioSource, i32);
impl_dbus_arg_from_into!(BtLeAudioGroupStatus, i32);
impl_dbus_arg_from_into!(BtLeAudioGroupNodeStatus, i32);
impl_dbus_arg_from_into!(BtLeAudioUnicastMonitorModeStatus, i32);
impl_dbus_arg_from_into!(BtLeAudioDirection, i32);
impl_dbus_arg_from_into!(BtLeAudioGroupStreamStatus, i32);
impl_dbus_arg_enum!(GattStatus);
impl_dbus_arg_enum!(GattWriteRequestStatus);
impl_dbus_arg_enum!(GattWriteType);
@@ -575,6 +588,14 @@ struct PlayerMetadataDBus {
    length_us: i64,
}

#[dbus_propmap(BtLePcmConfig)]
pub struct BtLePcmConfigDBus {
    data_interval_us: u32,
    sample_rate: u32,
    bits_per_sample: u8,
    channels_count: u8,
}

struct IBluetoothCallbackDBus {}

impl RPCProxy for IBluetoothCallbackDBus {}
@@ -2609,6 +2630,26 @@ impl IBluetoothMedia for BluetoothMediaDBus {
        dbus_generated!()
    }

    #[dbus_method("ConnectLeaGroupByMemberAddress")]
    fn connect_lea_group_by_member_address(&mut self, address: String) {
        dbus_generated!()
    }

    #[dbus_method("DisconnectLeaGroupByMemberAddress")]
    fn disconnect_lea_group_by_member_address(&mut self, address: String) {
        dbus_generated!()
    }

    #[dbus_method("ConnectLea")]
    fn connect_lea(&mut self, address: String) {
        dbus_generated!()
    }

    #[dbus_method("DisconnectLea")]
    fn disconnect_lea(&mut self, address: String) {
        dbus_generated!()
    }

    #[dbus_method("SetActiveDevice")]
    fn set_active_device(&mut self, address: String) {
        dbus_generated!()
@@ -2708,6 +2749,79 @@ impl IBluetoothMedia for BluetoothMediaDBus {
    fn trigger_debug_dump(&mut self) {
        dbus_generated!()
    }

    #[dbus_method("GroupSetActive")]
    fn group_set_active(&mut self, group_id: i32) {
        dbus_generated!()
    }

    #[dbus_method("HostStartAudioRequest")]
    fn host_start_audio_request(&mut self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("HostStopAudioRequest")]
    fn host_stop_audio_request(&mut self) {
        dbus_generated!()
    }

    #[dbus_method("PeerStartAudioRequest")]
    fn peer_start_audio_request(&mut self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("PeerStopAudioRequest")]
    fn peer_stop_audio_request(&mut self) {
        dbus_generated!()
    }

    #[dbus_method("GetHostPcmConfig")]
    fn get_host_pcm_config(&mut self) -> BtLePcmConfig {
        dbus_generated!()
    }

    #[dbus_method("GetPeerPcmConfig")]
    fn get_peer_pcm_config(&mut self) -> BtLePcmConfig {
        dbus_generated!()
    }

    #[dbus_method("GetHostStreamStarted")]
    fn get_host_stream_started(&mut self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("GetPeerStreamStarted")]
    fn get_peer_stream_started(&mut self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("SourceMetadataChanged")]
    fn source_metadata_changed(
        &mut self,
        usage: BtLeAudioUsage,
        content_type: BtLeAudioContentType,
        gain: f64,
    ) -> bool {
        dbus_generated!()
    }

    #[dbus_method("SinkMetadataChanged")]
    fn sink_metadata_changed(&mut self, source: BtLeAudioSource, gain: f64) -> bool {
        dbus_generated!()
    }

    #[dbus_method("GetUnicastMonitorModeStatus")]
    fn get_unicast_monitor_mode_status(
        &mut self,
        direction: BtLeAudioDirection,
    ) -> BtLeAudioUnicastMonitorModeStatus {
        dbus_generated!()
    }

    #[dbus_method("GetGroupStreamStatus")]
    fn get_group_stream_status(&mut self, group_id: i32) -> BtLeAudioGroupStreamStatus {
        dbus_generated!()
    }
}

struct IBluetoothMediaCallbackDBus {}
@@ -2750,6 +2864,46 @@ impl IBluetoothMediaCallback for IBluetoothMediaCallbackDBus {
        pkt_status_in_binary: String,
    ) {
    }

    #[dbus_method("OnLeaGroupConnected")]
    fn on_lea_group_connected(&mut self, group_id: i32, name: String) {}

    #[dbus_method("OnLeaGroupDisconnected")]
    fn on_lea_group_disconnected(&mut self, group_id: i32) {}

    #[dbus_method("OnLeaGroupStatus")]
    fn on_lea_group_status(&mut self, group_id: i32, status: BtLeAudioGroupStatus) {}

    #[dbus_method("OnLeaGroupNodeStatus")]
    fn on_lea_group_node_status(
        &mut self,
        addr: String,
        group_id: i32,
        status: BtLeAudioGroupNodeStatus,
    ) {
    }

    #[dbus_method("OnLeaAudioConf")]
    fn on_lea_audio_conf(
        &mut self,
        direction: u8,
        group_id: i32,
        snk_audio_location: u32,
        src_audio_location: u32,
        avail_cont: u16,
    ) {
    }

    #[dbus_method("OnLeaUnicastMonitorModeStatus")]
    fn on_lea_unicast_monitor_mode_status(
        &mut self,
        direction: BtLeAudioDirection,
        status: BtLeAudioUnicastMonitorModeStatus,
    ) {
    }

    #[dbus_method("OnLeaGroupStreamStatus")]
    fn on_lea_group_stream_status(&mut self, group_id: i32, status: BtLeAudioGroupStreamStatus) {}
}

pub(crate) struct BatteryManagerDBusRPC {
+165 −0
Original line number Diff line number Diff line
@@ -4,6 +4,11 @@ use bt_topshim::profiles::a2dp::{
};
use bt_topshim::profiles::avrcp::PlayerMetadata;
use bt_topshim::profiles::hfp::{HfpCodecBitId, HfpCodecFormat};
use bt_topshim::profiles::le_audio::{
    BtLeAudioContentType, BtLeAudioDirection, BtLeAudioGroupNodeStatus, BtLeAudioGroupStatus,
    BtLeAudioGroupStreamStatus, BtLeAudioSource, BtLeAudioUnicastMonitorModeStatus, BtLeAudioUsage,
    BtLePcmConfig,
};
use btstack::bluetooth_media::{BluetoothAudioDevice, IBluetoothMedia, IBluetoothMediaCallback};
use btstack::RPCProxy;

@@ -47,8 +52,24 @@ pub struct BluetoothAudioDeviceDBus {
    absolute_volume: bool,
}

#[dbus_propmap(BtLePcmConfig)]
pub struct BtLePcmConfigDBus {
    data_interval_us: u32,
    sample_rate: u32,
    bits_per_sample: u8,
    channels_count: u8,
}

impl_dbus_arg_from_into!(HfpCodecBitId, i32);
impl_dbus_arg_from_into!(HfpCodecFormat, i32);
impl_dbus_arg_from_into!(BtLeAudioUsage, i32);
impl_dbus_arg_from_into!(BtLeAudioContentType, i32);
impl_dbus_arg_from_into!(BtLeAudioSource, i32);
impl_dbus_arg_from_into!(BtLeAudioGroupStatus, i32);
impl_dbus_arg_from_into!(BtLeAudioGroupNodeStatus, i32);
impl_dbus_arg_from_into!(BtLeAudioUnicastMonitorModeStatus, i32);
impl_dbus_arg_from_into!(BtLeAudioDirection, i32);
impl_dbus_arg_from_into!(BtLeAudioGroupStreamStatus, i32);
impl_dbus_arg_enum!(A2dpCodecIndex);
impl_dbus_arg_from_into!(A2dpCodecSampleRate, i32);
impl_dbus_arg_from_into!(A2dpCodecBitsPerSample, i32);
@@ -100,6 +121,57 @@ impl IBluetoothMediaCallback for BluetoothMediaCallbackDBus {
    ) {
        dbus_generated!()
    }

    #[dbus_method("OnLeaGroupConnected")]
    fn on_lea_group_connected(&mut self, group_id: i32, name: String) {
        dbus_generated!()
    }

    #[dbus_method("OnLeaGroupDisconnected")]
    fn on_lea_group_disconnected(&mut self, group_id: i32) {
        dbus_generated!()
    }

    #[dbus_method("OnLeaGroupStatus")]
    fn on_lea_group_status(&mut self, group_id: i32, status: BtLeAudioGroupStatus) {
        dbus_generated!()
    }

    #[dbus_method("OnLeaGroupNodeStatus")]
    fn on_lea_group_node_status(
        &mut self,
        addr: String,
        group_id: i32,
        status: BtLeAudioGroupNodeStatus,
    ) {
        dbus_generated!()
    }

    #[dbus_method("OnLeaAudioConf")]
    fn on_lea_audio_conf(
        &mut self,
        direction: u8,
        group_id: i32,
        snk_audio_location: u32,
        src_audio_location: u32,
        avail_cont: u16,
    ) {
        dbus_generated!()
    }

    #[dbus_method("OnLeaUnicastMonitorModeStatus")]
    fn on_lea_unicast_monitor_mode_status(
        &mut self,
        direction: BtLeAudioDirection,
        status: BtLeAudioUnicastMonitorModeStatus,
    ) {
        dbus_generated!()
    }

    #[dbus_method("OnLeaGroupStreamStatus")]
    fn on_lea_group_stream_status(&mut self, group_id: i32, status: BtLeAudioGroupStreamStatus) {
        dbus_generated!()
    }
}

#[allow(dead_code)]
@@ -198,6 +270,26 @@ impl IBluetoothMedia for IBluetoothMediaDBus {
        dbus_generated!()
    }

    #[dbus_method("ConnectLeaGroupByMemberAddress")]
    fn connect_lea_group_by_member_address(&mut self, address: String) {
        dbus_generated!()
    }

    #[dbus_method("DisconnectLeaGroupByMemberAddress")]
    fn disconnect_lea_group_by_member_address(&mut self, address: String) {
        dbus_generated!()
    }

    #[dbus_method("ConnectLea")]
    fn connect_lea(&mut self, address: String) {
        dbus_generated!()
    }

    #[dbus_method("DisconnectLea")]
    fn disconnect_lea(&mut self, address: String) {
        dbus_generated!()
    }

    #[dbus_method("SetActiveDevice")]
    fn set_active_device(&mut self, address: String) {
        dbus_generated!()
@@ -297,4 +389,77 @@ impl IBluetoothMedia for IBluetoothMediaDBus {
    fn trigger_debug_dump(&mut self) {
        dbus_generated!()
    }

    #[dbus_method("GroupSetActive")]
    fn group_set_active(&mut self, group_id: i32) {
        dbus_generated!()
    }

    #[dbus_method("HostStartAudioRequest")]
    fn host_start_audio_request(&mut self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("HostStopAudioRequest")]
    fn host_stop_audio_request(&mut self) {
        dbus_generated!()
    }

    #[dbus_method("PeerStartAudioRequest")]
    fn peer_start_audio_request(&mut self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("PeerStopAudioRequest")]
    fn peer_stop_audio_request(&mut self) {
        dbus_generated!()
    }

    #[dbus_method("GetHostPcmConfig")]
    fn get_host_pcm_config(&mut self) -> BtLePcmConfig {
        dbus_generated!()
    }

    #[dbus_method("GetPeerPcmConfig")]
    fn get_peer_pcm_config(&mut self) -> BtLePcmConfig {
        dbus_generated!()
    }

    #[dbus_method("GetHostStreamStarted")]
    fn get_host_stream_started(&mut self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("GetPeerStreamStarted")]
    fn get_peer_stream_started(&mut self) -> bool {
        dbus_generated!()
    }

    #[dbus_method("SourceMetadataChanged")]
    fn source_metadata_changed(
        &mut self,
        usage: BtLeAudioUsage,
        content_type: BtLeAudioContentType,
        gain: f64,
    ) -> bool {
        dbus_generated!()
    }

    #[dbus_method("SinkMetadataChanged")]
    fn sink_metadata_changed(&mut self, source: BtLeAudioSource, gain: f64) -> bool {
        dbus_generated!()
    }

    #[dbus_method("GetUnicastMonitorModeStatus")]
    fn get_unicast_monitor_mode_status(
        &mut self,
        direction: BtLeAudioDirection,
    ) -> BtLeAudioUnicastMonitorModeStatus {
        dbus_generated!()
    }

    #[dbus_method("GetGroupStreamStatus")]
    fn get_group_stream_status(&mut self, group_id: i32) -> BtLeAudioGroupStreamStatus {
        dbus_generated!()
    }
}
+50 −9
Original line number Diff line number Diff line
@@ -660,7 +660,7 @@ impl Bluetooth {
                self.hh.as_mut().unwrap().activate_hogp(false);
            }

            Profile::A2dpSource | Profile::Hfp | Profile::AvrcpTarget => {
            Profile::A2dpSource | Profile::Hfp | Profile::AvrcpTarget | Profile::LeAudio => {
                self.bluetooth_media.lock().unwrap().disable_profile(profile);
            }
            // Ignore profiles that we don't connect.
@@ -682,7 +682,7 @@ impl Bluetooth {
                self.hh.as_mut().unwrap().activate_hogp(true);
            }

            Profile::A2dpSource | Profile::Hfp | Profile::AvrcpTarget => {
            Profile::A2dpSource | Profile::Hfp | Profile::AvrcpTarget | Profile::LeAudio => {
                self.bluetooth_media.lock().unwrap().enable_profile(profile);
            }
            // Ignore profiles that we don't connect.
@@ -700,7 +700,7 @@ impl Bluetooth {

            Profile::Hogp => Some(self.hh.as_ref().unwrap().is_hogp_activated),

            Profile::A2dpSource | Profile::Hfp | Profile::AvrcpTarget => {
            Profile::A2dpSource | Profile::Hfp | Profile::AvrcpTarget | Profile::LeAudio => {
                self.bluetooth_media.lock().unwrap().is_profile_enabled(profile)
            }
            // Ignore profiles that we don't connect.
@@ -1156,6 +1156,15 @@ impl Bluetooth {
                                    .collect(),
                            ));
                        }
                        if result.service_data.len() > 0 {
                            props.push(BluetoothProperty::Uuids(
                                result
                                    .service_data
                                    .keys()
                                    .map(|v| UuidHelper::from_string(v).unwrap().into())
                                    .collect(),
                            ));
                        }
                        props.push(BluetoothProperty::RemoteRssi(result.rssi));
                        props.push(BluetoothProperty::RemoteAddrType(
                            (result.addr_type as u32).into(),
@@ -2714,7 +2723,8 @@ impl IBluetooth for Bluetooth {

        // Check all remote uuids to see if they match enabled profiles and connect them.
        let mut has_enabled_uuids = false;
        let mut has_media_profile = false;
        let mut has_classic_media_profile = false;
        let mut has_le_media_profile = false;
        let mut has_supported_profile = false;
        let uuids = self.get_remote_uuids(device.clone());
        for uuid in uuids.iter() {
@@ -2749,11 +2759,25 @@ impl IBluetooth for Bluetooth {
                                }
                            }

                            // TODO(b/317682584): implement policy to connect to LEA, VC, and CSIS
                            Profile::LeAudio if !has_le_media_profile => {
                                has_le_media_profile = true;
                                let txl = self.tx.clone();
                                let address = device.address.clone();
                                topstack::get_runtime().spawn(async move {
                                    let _ = txl
                                        .send(Message::Media(
                                            MediaActions::ConnectLeaGroupByMemberAddress(address),
                                        ))
                                        .await;
                                });
                            }

                            Profile::A2dpSink | Profile::A2dpSource | Profile::Hfp
                                if !has_media_profile =>
                                if !has_classic_media_profile =>
                            {
                                has_supported_profile = true;
                                has_media_profile = true;
                                has_classic_media_profile = true;
                                let txl = self.tx.clone();
                                let address = device.address.clone();
                                topstack::get_runtime().spawn(async move {
@@ -2836,7 +2860,8 @@ impl IBluetooth for Bluetooth {
        }

        let uuids = self.get_remote_uuids(device.clone());
        let mut has_media_profile = false;
        let mut has_classic_media_profile = false;
        let mut has_le_media_profile = false;
        for uuid in uuids.iter() {
            match UuidHelper::is_known_profile(uuid) {
                Some(p) => {
@@ -2858,13 +2883,29 @@ impl IBluetooth for Bluetooth {
                                );
                            }

                            // TODO(b/317682584): implement policy to disconnect from LEA, VC, and CSIS
                            Profile::LeAudio if !has_le_media_profile => {
                                has_le_media_profile = true;
                                let txl = self.tx.clone();
                                let address = device.address.clone();
                                topstack::get_runtime().spawn(async move {
                                    let _ = txl
                                        .send(Message::Media(
                                            MediaActions::DisconnectLeaGroupByMemberAddress(
                                                address,
                                            ),
                                        ))
                                        .await;
                                });
                            }

                            Profile::A2dpSink
                            | Profile::A2dpSource
                            | Profile::Hfp
                            | Profile::AvrcpController
                                if !has_media_profile =>
                                if !has_classic_media_profile =>
                            {
                                has_media_profile = true;
                                has_classic_media_profile = true;
                                let txl = self.tx.clone();
                                let address = device.address.clone();
                                topstack::get_runtime().spawn(async move {
+755 −14

File changed.

Preview size limit exceeded, changes collapsed.

Loading