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

Commit 5b3c6ac8 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "floss: Add GetProfileConnectionState adapter API" am: ab46d5fc

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

Change-Id: I986312b7db9a456e2e32d788ca57990820b936eb
parents f9cfb9e1 ab46d5fc
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use crate::{console_red, console_yellow, print_error, print_info};
use bt_topshim::btif::BtTransport;
use btstack::bluetooth::{BluetoothDevice, IBluetooth};
use btstack::bluetooth_gatt::IBluetoothGatt;
use btstack::uuid::UuidHelper;
use btstack::uuid::{Profile, UuidHelper};
use manager_service::iface_bluetooth_manager::IBluetoothManager;

const INDENT_CHAR: &str = " ";
@@ -273,6 +273,13 @@ impl CommandHandler {
                    let cod = adapter_dbus.get_bluetooth_class();
                    let multi_adv_supported = adapter_dbus.is_multi_advertisement_supported();
                    let le_ext_adv_supported = adapter_dbus.is_le_extended_advertising_supported();
                    let uuid_helper = UuidHelper::new();
                    let enabled_profiles = uuid_helper.get_enabled_profiles();
                    let connected_profiles: Vec<Profile> = enabled_profiles
                        .iter()
                        .filter(|&&prof| adapter_dbus.get_profile_connection_state(prof) > 0)
                        .cloned()
                        .collect();
                    print_info!("Address: {}", address);
                    print_info!("Name: {}", name);
                    print_info!("State: {}", if enabled { "enabled" } else { "disabled" });
@@ -281,6 +288,7 @@ impl CommandHandler {
                    print_info!("Class: {:#06x}", cod);
                    print_info!("IsMultiAdvertisementSupported: {}", multi_adv_supported);
                    print_info!("IsLeExtendedAdvertisingSupported: {}", le_ext_adv_supported);
                    print_info!("Connected profiles: {:?}", connected_profiles);
                    print_info!(
                        "Uuids: {}",
                        DisplayList(
+7 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ use btstack::bluetooth_gatt::{
    IScannerCallback, LePhy, ScanFilter, ScanSettings,
};

use btstack::uuid::Profile;
use dbus::arg::{AppendAll, RefArg};
use dbus::nonblock::SyncConnection;

@@ -42,6 +43,7 @@ impl_dbus_arg_enum!(GattStatus);
impl_dbus_arg_enum!(GattWriteType);
impl_dbus_arg_enum!(LePhy);
impl_dbus_arg_enum!(GattWriteRequestStatus);
impl_dbus_arg_enum!(Profile);

// Represents Uuid128Bit as an array in D-Bus.
impl DBusArg for Uuid128Bit {
@@ -386,6 +388,11 @@ impl IBluetooth for BluetoothDBus {
        dbus_generated!()
    }

    #[dbus_method("GetProfileConnectionState")]
    fn get_profile_connection_state(&self, profile: Profile) -> u32 {
        dbus_generated!()
    }

    #[dbus_method("GetRemoteUuids")]
    fn get_remote_uuids(&self, device: BluetoothDevice) -> Vec<Uuid128Bit> {
        dbus_generated!()
+7 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ use bt_topshim::btif::{BtSspVariant, BtTransport, Uuid128Bit};
use btstack::bluetooth::{
    BluetoothDevice, IBluetooth, IBluetoothCallback, IBluetoothConnectionCallback,
};
use btstack::uuid::Profile;
use btstack::RPCProxy;

use dbus::arg::RefArg;
@@ -64,6 +65,7 @@ impl IBluetoothCallback for BluetoothCallbackDBus {

impl_dbus_arg_enum!(BtTransport);
impl_dbus_arg_enum!(BtSspVariant);
impl_dbus_arg_enum!(Profile);

#[allow(dead_code)]
struct BluetoothConnectionCallbackDBus {}
@@ -235,6 +237,11 @@ impl IBluetooth for IBluetoothDBus {
        dbus_generated!()
    }

    #[dbus_method("GetProfileConnectionState")]
    fn get_profile_connection_state(&self, _profile: Profile) -> u32 {
        dbus_generated!()
    }

    #[dbus_method("GetRemoteUuids")]
    fn get_remote_uuids(&self, _device: BluetoothDevice) -> Vec<Uuid128Bit> {
        dbus_generated!()
+16 −0
Original line number Diff line number Diff line
@@ -125,6 +125,9 @@ pub trait IBluetooth {
    /// Gets the connection state of a single device.
    fn get_connection_state(&self, device: BluetoothDevice) -> u32;

    /// Gets the connection state of a specific profile.
    fn get_profile_connection_state(&self, profile: Profile) -> u32;

    /// Returns the cached UUIDs of a remote device.
    fn get_remote_uuids(&self, device: BluetoothDevice) -> Vec<Uuid128Bit>;

@@ -1086,6 +1089,19 @@ impl IBluetooth for Bluetooth {
        self.intf.lock().unwrap().get_connection_state(&addr.unwrap())
    }

    fn get_profile_connection_state(&self, profile: Profile) -> u32 {
        match profile {
            Profile::A2dpSink | Profile::A2dpSource => {
                self.bluetooth_media.lock().unwrap().get_a2dp_connection_state()
            }
            Profile::Hfp | Profile::HfpAg => {
                self.bluetooth_media.lock().unwrap().get_hfp_connection_state()
            }
            // TODO: (b/223431229) Profile::Hid and Profile::Hogp
            _ => 0,
        }
    }

    fn get_remote_uuids(&self, device: BluetoothDevice) -> Vec<Uuid128Bit> {
        match self.get_remote_device_property(&device, &BtPropertyType::Uuids) {
            Some(BluetoothProperty::Uuids(uuids)) => {
+15 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ use bt_topshim::profiles::hfp::{
use bt_topshim::topstack;

use log::{info, warn};

use num_traits::cast::ToPrimitive;
use std::collections::HashMap;
use std::convert::TryFrom;
use std::sync::Arc;
@@ -253,6 +253,20 @@ impl BluetoothMedia {
            f(&callback.1);
        }
    }

    pub fn get_hfp_connection_state(&self) -> u32 {
        for state in self.hfp_states.values() {
            return BthfConnectionState::to_u32(state).unwrap_or(0);
        }
        0
    }

    pub fn get_a2dp_connection_state(&self) -> u32 {
        for state in self.a2dp_states.values() {
            return BtavConnectionState::to_u32(state).unwrap_or(0);
        }
        0
    }
}

fn get_a2dp_dispatcher(tx: Sender<Message>) -> A2dpCallbacksDispatcher {
Loading