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

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

Merge "floss: Change A2dp to accept RawAddress" am: 4ae7af1c am: 06388728

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

Change-Id: I33e7f0b8583e94c4100e3a5eb4776638c50feac9
parents 02fd1b46 06388728
Loading
Loading
Loading
Loading
+13 −14
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ pub trait IBluetoothMedia {
    /// clean up media stack
    fn cleanup(&mut self) -> bool;

    // TODO (b/204488289): Accept and validate RawAddress instead.
    fn connect(&mut self, device: String);
    fn set_active_device(&mut self, device: String);
    fn disconnect(&mut self, device: String);
@@ -268,14 +267,12 @@ impl IBluetoothMedia for BluetoothMedia {
    }

    fn connect(&mut self, device: String) {
        let addr = RawAddress::from_string(device.clone());
        if addr.is_none() {
        if let Some(addr) = RawAddress::from_string(device.clone()) {
            self.a2dp.as_mut().unwrap().connect(addr);
            self.hfp.as_mut().unwrap().connect(addr);
        } else {
            warn!("Invalid device string {}", device);
            return;
        }

        self.a2dp.as_mut().unwrap().connect(device);
        self.hfp.as_mut().unwrap().connect(addr.unwrap());
    }

    fn cleanup(&mut self) -> bool {
@@ -283,18 +280,20 @@ impl IBluetoothMedia for BluetoothMedia {
    }

    fn set_active_device(&mut self, device: String) {
        self.a2dp.as_mut().unwrap().set_active_device(device);
        if let Some(addr) = RawAddress::from_string(device.clone()) {
            self.a2dp.as_mut().unwrap().set_active_device(addr);
        } else {
            warn!("Invalid device string {}", device);
        }
    }

    fn disconnect(&mut self, device: String) {
        let addr = RawAddress::from_string(device.clone());
        if addr.is_none() {
        if let Some(addr) = RawAddress::from_string(device.clone()) {
            self.a2dp.as_mut().unwrap().disconnect(addr);
            self.hfp.as_mut().unwrap().disconnect(addr);
        } else {
            warn!("Invalid device string {}", device);
            return;
        }

        self.a2dp.as_mut().unwrap().disconnect(device);
        self.hfp.as_mut().unwrap().disconnect(addr.unwrap());
    }

    fn set_audio_config(
+13 −4
Original line number Diff line number Diff line
//! Media service facade

use bt_topshim::btif::BluetoothInterface;
use bt_topshim::btif::{BluetoothInterface, RawAddress};
use bt_topshim::profiles::a2dp::{
    A2dp, A2dpCallbacksDispatcher, A2dpSink, A2dpSinkCallbacksDispatcher,
};
@@ -82,9 +82,18 @@ impl MediaService for MediaServiceImpl {
    ) {
        let a2dp = self.btif_a2dp.clone();
        ctx.spawn(async move {
            a2dp.lock().unwrap().connect(req.address.clone());
            a2dp.lock().unwrap().set_active_device(req.address.clone());
            if let Some(addr) = RawAddress::from_string(req.address.clone()) {
                a2dp.lock().unwrap().connect(addr);
                a2dp.lock().unwrap().set_active_device(addr);
                sink.success(A2dpSourceConnectResponse::default()).await.unwrap();
            } else {
                sink.fail(RpcStatus::with_message(
                    RpcStatusCode::INVALID_ARGUMENT,
                    format!("Invalid Request Address: {}", req.address),
                ))
                .await
                .unwrap();
            }
        })
    }
}
+6 −21
Original line number Diff line number Diff line
@@ -293,31 +293,16 @@ impl A2dp {
        true
    }

    pub fn connect(&mut self, device: String) {
        let addr = RawAddress::from_string(device.clone());
        if addr.is_none() {
            eprintln!("Invalid device string {}", device);
            return;
        }
        self.internal.connect(addr.unwrap().into());
    pub fn connect(&mut self, addr: RawAddress) {
        self.internal.connect(addr.into());
    }

    pub fn set_active_device(&mut self, device: String) {
        let addr = RawAddress::from_string(device.clone());
        if addr.is_none() {
            eprintln!("Invalid device string {}", device);
            return;
        }
        self.internal.set_active_device(addr.unwrap().into());
    pub fn set_active_device(&mut self, addr: RawAddress) {
        self.internal.set_active_device(addr.into());
    }

    pub fn disconnect(&mut self, device: String) {
        let addr = RawAddress::from_string(device.clone());
        if addr.is_none() {
            eprintln!("Invalid device string {}", device);
            return;
        }
        self.internal.disconnect(addr.unwrap().into());
    pub fn disconnect(&mut self, addr: RawAddress) {
        self.internal.disconnect(addr.into());
    }

    pub fn set_audio_config(&self, sample_rate: i32, bits_per_sample: i32, channel_mode: i32) {