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

Commit fbf2c67d authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi Committed by Abhishek Pandit-Subedi
Browse files

floss: Handle SDP profile callbacks in stack

Bug: 189497381
Tag: #floss
Test: build only
Change-Id: I7d4987b038e149d0d57f7eb9947de5e90897422d
parent d6878ea5
Loading
Loading
Loading
Loading
+54 −6
Original line number Diff line number Diff line
@@ -3,10 +3,13 @@
use bt_topshim::btif::{
    BaseCallbacks, BaseCallbacksDispatcher, BluetoothInterface, BluetoothProperty, BtBondState,
    BtDiscoveryState, BtPropertyType, BtSspVariant, BtState, BtStatus, BtTransport, RawAddress,
    Uuid128Bit,
    Uuid, Uuid128Bit,
};
use bt_topshim::{
    profiles::hid_host::{HHCallbacksDispatcher, HidHost},
    profiles::sdp::{BtSdpRecord, Sdp, SdpCallbacks, SdpCallbacksDispatcher},
    topstack,
};
use bt_topshim::profiles::hid_host::{HHCallbacksDispatcher, HidHost};
use bt_topshim::topstack;

use btif_macros::{btif_callback, btif_callbacks_dispatcher};

@@ -190,6 +193,7 @@ pub struct Bluetooth {
    local_address: Option<RawAddress>,
    properties: HashMap<BtPropertyType, BluetoothProperty>,
    found_devices: HashMap<String, BluetoothDeviceContext>,
    sdp: Option<Sdp>,
    state: BtState,
    tx: Sender<Message>,
}
@@ -213,17 +217,32 @@ impl Bluetooth {
            local_address: None,
            properties: HashMap::new(),
            found_devices: HashMap::new(),
            sdp: None,
            state: BtState::Off,
            tx,
        }
    }

    pub fn init_profiles(&mut self) {
        let hhtx = self.tx.clone();
        self.hh = Some(HidHost::new(&self.intf.lock().unwrap()));
        self.hh.as_mut().unwrap().initialize(HHCallbacksDispatcher {
            dispatch: Box::new(move |_cb| {
                // TODO("Implement the callbacks");
                debug!("received HH callback");
            dispatch: Box::new(move |cb| {
                let txl = hhtx.clone();
                topstack::get_runtime().spawn(async move {
                    let _ = txl.send(Message::HidHost(cb)).await;
                });
            }),
        });

        let sdptx = self.tx.clone();
        self.sdp = Some(Sdp::new(&self.intf.lock().unwrap()));
        self.sdp.as_mut().unwrap().initialize(SdpCallbacksDispatcher {
            dispatch: Box::new(move |cb| {
                let txl = sdptx.clone();
                topstack::get_runtime().spawn(async move {
                    let _ = txl.send(Message::Sdp(cb)).await;
                });
            }),
        });
    }
@@ -286,6 +305,19 @@ pub(crate) trait BtifBluetoothCallbacks {
    );
}

#[btif_callbacks_dispatcher(Bluetooth, dispatch_sdp_callbacks, SdpCallbacks)]
pub(crate) trait BtifSdpCallbacks {
    #[btif_callback(SdpSearch)]
    fn sdp_search(
        &mut self,
        status: BtStatus,
        address: RawAddress,
        uuid: Uuid,
        count: i32,
        records: Vec<BtSdpRecord>,
    );
}

pub fn get_bt_dispatcher(tx: Sender<Message>) -> BaseCallbacksDispatcher {
    BaseCallbacksDispatcher {
        dispatch: Box::new(move |cb| {
@@ -623,3 +655,19 @@ impl IBluetooth for Bluetooth {
        }
    }
}

impl BtifSdpCallbacks for Bluetooth {
    fn sdp_search(
        &mut self,
        status: BtStatus,
        address: RawAddress,
        uuid: Uuid,
        _count: i32,
        _records: Vec<BtSdpRecord>,
    ) {
        debug!(
            "Sdp search result found: Status({:?}) Address({:?}) Uuid({:?})",
            status, address, uuid
        );
    }
}
+20 −8
Original line number Diff line number Diff line
@@ -10,20 +10,21 @@ pub mod bluetooth;
pub mod bluetooth_gatt;
pub mod bluetooth_media;

use bt_topshim::btif::BaseCallbacks;
use bt_topshim::profiles::a2dp::A2dpCallbacks;
use bt_topshim::profiles::avrcp::AvrcpCallbacks;
use bt_topshim::profiles::gatt::GattClientCallbacks;
use bt_topshim::profiles::gatt::GattServerCallbacks;

use log::debug;
use std::sync::{Arc, Mutex};

use tokio::sync::mpsc::channel;
use tokio::sync::mpsc::{Receiver, Sender};

use crate::bluetooth::Bluetooth;
use crate::bluetooth_gatt::BluetoothGatt;
use crate::bluetooth_media::BluetoothMedia;
use bt_topshim::{
    btif::BaseCallbacks,
    profiles::{
        a2dp::A2dpCallbacks, avrcp::AvrcpCallbacks, gatt::GattClientCallbacks,
        gatt::GattServerCallbacks, hid_host::HHCallbacks, sdp::SdpCallbacks,
    },
};

/// Represents a Bluetooth address.
// TODO: Add support for LE random addresses.
@@ -35,6 +36,8 @@ pub enum Message {
    Base(BaseCallbacks),
    GattClient(GattClientCallbacks),
    GattServer(GattServerCallbacks),
    HidHost(HHCallbacks),
    Sdp(SdpCallbacks),
    BluetoothCallbackDisconnected(u32),
}

@@ -81,7 +84,16 @@ impl Stack {

                Message::GattServer(m) => {
                    // TODO(b/193685149): dispatch GATT server callbacks.
                    println!("Unhandled Message::GattServer: {:?}", m);
                    debug!("Unhandled Message::GattServer: {:?}", m);
                }

                Message::HidHost(_h) => {
                    // TODO(abps) - Handle hid host callbacks
                    debug!("Received HH callback");
                }

                Message::Sdp(s) => {
                    bluetooth.lock().unwrap().dispatch_sdp_callbacks(s);
                }

                Message::BluetoothCallbackDisconnected(id) => {