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

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

Merge "floss: Append remote device name" am: fb106200 am: 440404c7 am:...

Merge "floss: Append remote device name" am: fb106200 am: 440404c7 am: 44e7aa29 am: 26fa1ecc

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



Change-Id: Ie26d8c4a6a8359a97b196ae0e4f1c998eb432754
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents edc1ac4c 26fa1ecc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ impl IBluetoothMediaCallback for BluetoothMediaCallbackDBus {
        bits_per_sample: i32,
        channel_mode: i32,
        hfp_cap: i32,
        name: String,
    ) {
        dbus_generated!()
    }
+2 −0
Original line number Diff line number Diff line
@@ -80,6 +80,8 @@ fn main() -> Result<(), Box<dyn Error>> {
    {
        intf.lock().unwrap().initialize(get_bt_dispatcher(tx.clone()), args);

        bluetooth_media.lock().unwrap().set_adapter(bluetooth.clone());

        let mut bluetooth = bluetooth.lock().unwrap();
        bluetooth.init_profiles();
        bluetooth.enable();
+30 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ use tokio::sync::mpsc::Sender;
use tokio::task::JoinHandle;
use tokio::time::{sleep, Duration};

use crate::bluetooth::{Bluetooth, BluetoothDevice, IBluetooth};
use crate::Message;

const DEFAULT_PROFILE_DISCOVERY_TIMEOUT_SEC: u64 = 5;
@@ -69,6 +70,7 @@ pub trait IBluetoothMediaCallback {
        bits_per_sample: i32,
        channel_mode: i32,
        hfp_cap: i32,
        name: String,
    );

    ///
@@ -93,6 +95,7 @@ pub struct BluetoothMedia {
    callbacks: Arc<Mutex<Vec<(u32, Box<dyn IBluetoothMediaCallback + Send>)>>>,
    callback_last_id: u32,
    tx: Sender<Message>,
    adapter: Option<Arc<Mutex<Box<Bluetooth>>>>,
    a2dp: Option<A2dp>,
    avrcp: Option<Avrcp>,
    a2dp_states: HashMap<RawAddress, BtavConnectionState>,
@@ -111,6 +114,7 @@ impl BluetoothMedia {
            callbacks: Arc::new(Mutex::new(vec![])),
            callback_last_id: 0,
            tx,
            adapter: None,
            a2dp: None,
            avrcp: None,
            a2dp_states: HashMap::new(),
@@ -122,6 +126,10 @@ impl BluetoothMedia {
        }
    }

    pub fn set_adapter(&mut self, adapter: Arc<Mutex<Box<Bluetooth>>>) {
        self.adapter = Some(adapter);
    }

    pub fn dispatch_a2dp_callbacks(&mut self, cb: A2dpCallbacks) {
        match cb {
            A2dpCallbacks::ConnectionState(addr, state) => {
@@ -248,6 +256,7 @@ impl BluetoothMedia {
            callbacks: Arc<Mutex<Vec<(u32, Box<dyn IBluetoothMediaCallback + Send>)>>>,
            cap: A2dpCodecConfig,
            hfp_cap: HfpCodecCapability,
            name: String,
            is_delayed: bool,
        ) -> bool {
            // Closure used to lock and trigger the device added callbacks.
@@ -259,6 +268,7 @@ impl BluetoothMedia {
                        cap.bits_per_sample,
                        cap.channel_mode,
                        hfp_cap.bits(),
                        name.clone(),
                    );
                }
            };
@@ -300,6 +310,7 @@ impl BluetoothMedia {
                .find(|cap| A2dpCodecIndex::SrcSbc == A2dpCodecIndex::from(cap.codec_type))
        });
        let cur_hfp_cap = self.hfp_caps.get(&addr);
        let name = self.adapter_get_remote_name(addr);
        match (cur_a2dp_cap, cur_hfp_cap) {
            (None, None) => warn!(
                "[{}]: Try to add a device without a2dp and hfp capability.",
@@ -312,6 +323,7 @@ impl BluetoothMedia {
                    self.callbacks.clone(),
                    *cap,
                    *hfp_cap,
                    name,
                    false,
                );
            }
@@ -324,7 +336,7 @@ impl BluetoothMedia {
                    let hfp_cap = cur_hfp_cap.unwrap_or(&HfpCodecCapability::UNSUPPORTED).clone();
                    let task = topstack::get_runtime().spawn(async move {
                        sleep(Duration::from_secs(DEFAULT_PROFILE_DISCOVERY_TIMEOUT_SEC)).await;
                        if dedup_added_cb(device_added_tasks, addr, callbacks, cap, hfp_cap, true) {
                        if dedup_added_cb(device_added_tasks, addr, callbacks, cap, hfp_cap, name, true) {
                            warn!(
                                "[{}]: Add a device with only hfp or a2dp capability after timeout.",
                                addr.to_string()
@@ -358,6 +370,23 @@ impl BluetoothMedia {
        }
    }

    fn adapter_get_remote_name(&self, addr: RawAddress) -> String {
        let device = BluetoothDevice::new(
            addr.to_string(),
            // get_remote_name needs a BluetoothDevice just for its address, the
            // name field is unused so construct one with a fake name.
            "Classic Device".to_string(),
        );
        if let Some(adapter) = &self.adapter {
            match adapter.lock().unwrap().get_remote_name(device).as_str() {
                "" => addr.to_string(),
                name => name.into(),
            }
        } else {
            addr.to_string()
        }
    }

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