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

Commit d11eff66 authored by Ying Hsu's avatar Ying Hsu
Browse files

floss: Add dispatchers for GattAdvInbandCallbacks and GattAdvCallbacks

Floss daemon registers dispatchers to handle GattAdvInbandCallbacks
and GattAdvCallbacks from libbluetooth.

Bug: 233128394
Tag: #floss
Test: build.py --target test
Test: build aosp_oriole-userdebug
Change-Id: I37c0bf647e82229df8047215b6795a6aab932009
parent 43943a21
Loading
Loading
Loading
Loading
+26 −3
Original line number Diff line number Diff line
@@ -5,9 +5,10 @@ use btif_macros::{btif_callback, btif_callbacks_dispatcher};
use bt_topshim::bindings::root::bluetooth::Uuid;
use bt_topshim::btif::{BluetoothInterface, RawAddress, Uuid128Bit};
use bt_topshim::profiles::gatt::{
    BtGattDbElement, BtGattNotifyParams, BtGattReadParams, Gatt, GattClientCallbacks,
    GattClientCallbacksDispatcher, GattScannerCallbacks, GattScannerCallbacksDispatcher,
    GattServerCallbacksDispatcher, GattStatus,
    BtGattDbElement, BtGattNotifyParams, BtGattReadParams, Gatt, GattAdvCallbacksDispatcher,
    GattAdvInbandCallbacksDispatcher, GattClientCallbacks, GattClientCallbacksDispatcher,
    GattScannerCallbacks, GattScannerCallbacksDispatcher, GattServerCallbacksDispatcher,
    GattStatus,
};
use bt_topshim::topstack;

@@ -823,10 +824,32 @@ impl BluetoothGatt {
            }),
        };

        let tx_clone = tx.clone();
        let gatt_adv_inband_callbacks_dispatcher = GattAdvInbandCallbacksDispatcher {
            dispatch: Box::new(move |cb| {
                let tx_clone = tx_clone.clone();
                topstack::get_runtime().spawn(async move {
                    let _ = tx_clone.send(Message::LeAdvInband(cb)).await;
                });
            }),
        };

        let tx_clone = tx.clone();
        let gatt_adv_callbacks_dispatcher = GattAdvCallbacksDispatcher {
            dispatch: Box::new(move |cb| {
                let tx_clone = tx_clone.clone();
                topstack::get_runtime().spawn(async move {
                    let _ = tx_clone.send(Message::LeAdv(cb)).await;
                });
            }),
        };

        self.gatt.as_mut().unwrap().initialize(
            gatt_client_callbacks_dispatcher,
            gatt_server_callbacks_dispatcher,
            gatt_scanner_callbacks_dispatcher,
            gatt_adv_inband_callbacks_dispatcher,
            gatt_adv_callbacks_dispatcher,
        );
    }

+15 −3
Original line number Diff line number Diff line
@@ -27,9 +27,9 @@ use crate::suspend::Suspend;
use bt_topshim::{
    btif::BaseCallbacks,
    profiles::{
        a2dp::A2dpCallbacks, avrcp::AvrcpCallbacks, gatt::GattClientCallbacks,
        gatt::GattScannerCallbacks, gatt::GattServerCallbacks, hfp::HfpCallbacks,
        hid_host::HHCallbacks, sdp::SdpCallbacks,
        a2dp::A2dpCallbacks, avrcp::AvrcpCallbacks, gatt::GattAdvCallbacks,
        gatt::GattAdvInbandCallbacks, gatt::GattClientCallbacks, gatt::GattScannerCallbacks,
        gatt::GattServerCallbacks, hfp::HfpCallbacks, hid_host::HHCallbacks, sdp::SdpCallbacks,
    },
};

@@ -42,6 +42,8 @@ pub enum Message {
    GattClient(GattClientCallbacks),
    GattServer(GattServerCallbacks),
    LeScanner(GattScannerCallbacks),
    LeAdvInband(GattAdvInbandCallbacks),
    LeAdv(GattAdvCallbacks),
    HidHost(HHCallbacks),
    Hfp(HfpCallbacks),
    Sdp(SdpCallbacks),
@@ -120,6 +122,16 @@ impl Stack {
                    bluetooth_gatt.lock().unwrap().dispatch_le_scanner_callbacks(m);
                }

                Message::LeAdvInband(m) => {
                    // TODO(b/233128394)
                    debug!("Received LeAdvInband message: {:?}", m);
                }

                Message::LeAdv(m) => {
                    // TODO(b/233128394)
                    debug!("Received LeAdv message: {:?}", m);
                }

                Message::Hfp(hf) => {
                    bluetooth_media.lock().unwrap().dispatch_hfp_callbacks(hf);
                }
+12 −1
Original line number Diff line number Diff line
@@ -5,7 +5,8 @@ use bt_topshim::profiles::gatt::{
    AdvertiseParameters, Gatt, GattFilterParam, PeriodicAdvertisingParameters,
};
use bt_topshim::profiles::gatt::{
    GattClientCallbacksDispatcher, GattScannerCallbacksDispatcher, GattServerCallbacksDispatcher,
    GattAdvCallbacksDispatcher, GattAdvInbandCallbacksDispatcher, GattClientCallbacksDispatcher,
    GattScannerCallbacksDispatcher, GattServerCallbacksDispatcher,
};
use bt_topshim_facade_protobuf::empty::Empty;
//use bt_topshim_facade_protobuf::facade::{
@@ -67,6 +68,16 @@ impl GattServiceImpl {
                    println!("received Gatt scanner callback: {:?}", cb);
                }),
            },
            GattAdvInbandCallbacksDispatcher {
                dispatch: Box::new(move |cb| {
                    println!("received Gatt advertiser inband callback: {:?}", cb);
                }),
            },
            GattAdvCallbacksDispatcher {
                dispatch: Box::new(move |cb| {
                    println!("received Gatt advertising callback: {:?}", cb);
                }),
            },
        );

        create_gatt_service(me)
+19 −1
Original line number Diff line number Diff line
@@ -1607,6 +1607,8 @@ impl Gatt {
        gatt_client_callbacks_dispatcher: GattClientCallbacksDispatcher,
        gatt_server_callbacks_dispatcher: GattServerCallbacksDispatcher,
        gatt_scanner_callbacks_dispatcher: GattScannerCallbacksDispatcher,
        gatt_adv_inband_callbacks_dispatcher: GattAdvInbandCallbacksDispatcher,
        gatt_adv_callbacks_dispatcher: GattAdvCallbacksDispatcher,
    ) -> bool {
        // Register dispatcher
        if get_dispatchers()
@@ -1633,6 +1635,22 @@ impl Gatt {
            panic!("Tried to set dispatcher for GattScannerCallbacks but it already existed");
        }

        if get_dispatchers()
            .lock()
            .unwrap()
            .set::<GDAdvInbandCb>(Arc::new(Mutex::new(gatt_adv_inband_callbacks_dispatcher)))
        {
            panic!("Tried to set dispatcher for GattAdvInbandCallbacks but it already existed");
        }

        if get_dispatchers()
            .lock()
            .unwrap()
            .set::<GDAdvCb>(Arc::new(Mutex::new(gatt_adv_callbacks_dispatcher)))
        {
            panic!("Tried to set dispatcher for GattAdvCallbacks but it already existed");
        }

        let mut gatt_client_callbacks = Box::new(btgatt_client_callbacks_t {
            register_client_cb: Some(gc_register_client_cb),
            open_cb: Some(gc_open_cb),
@@ -1685,7 +1703,7 @@ impl Gatt {
        });

        let mut callbacks = Box::new(btgatt_callbacks_t {
            size: 4 * 8,
            size: std::mem::size_of::<btgatt_callbacks_t>(),
            client: &mut *gatt_client_callbacks,
            server: &mut *gatt_server_callbacks,
            scanner: &mut *gatt_scanner_callbacks,