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

Commit d5c5d8ed authored by Hsin-chen Chuang's avatar Hsin-chen Chuang
Browse files

floss: btclient: Add MPS SDP record on telephony enabled

Bug: 264820755
Tag: #floss
Test: MPS/SDR/SDP/CTH/SD/BV-01-I

Change-Id: I2df5c5cb224b1f16f5e268eb28a2e1fe90db74e6
parent e635328c
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -253,7 +253,12 @@ impl IBluetoothCallback for BtCallback {
    ) {
    }

    fn on_sdp_record_created(&self, _record: BtSdpRecord, _handle: i32) {}
    fn on_sdp_record_created(&self, record: BtSdpRecord, handle: i32) {
        print_info!("SDP record handle={} created", handle);
        if let BtSdpRecord::Mps(_) = record {
            self.context.lock().unwrap().mps_sdp_handle = Some(handle);
        }
    }
}

impl RPCProxy for BtCallback {
+24 −8
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ use crate::ClientContext;
use crate::{console_red, console_yellow, print_error, print_info};
use bt_topshim::btif::{BtConnectionState, BtStatus, BtTransport};
use bt_topshim::profiles::hid_host::BthhReportType;
use bt_topshim::profiles::sdp::{BtSdpMpsRecord, BtSdpRecord};
use bt_topshim::profiles::{gatt::LePhy, ProfileConnectionState};
use btstack::bluetooth::{BluetoothDevice, IBluetooth, IBluetoothQA};
use btstack::bluetooth_gatt::{GattWriteType, IBluetoothGatt, ScanSettings, ScanType};
@@ -1655,14 +1656,29 @@ impl CommandHandler {
                    .unwrap()
                    .set_battery_level(level);
            }
            "enable" | "disable" => {
                self.context
                    .lock()
                    .unwrap()
                    .telephony_dbus
            "enable" => {
                let mut context = self.lock_context();
                context.telephony_dbus.as_mut().unwrap().set_phone_ops_enabled(true);
                if context.mps_sdp_handle.is_none() {
                    let success = context
                        .adapter_dbus
                        .as_mut()
                        .unwrap()
                    .set_phone_ops_enabled(get_arg(args, 0)? == "enable");
                        .create_sdp_record(BtSdpRecord::Mps(BtSdpMpsRecord::default()));
                    if !success {
                        return Err(format!("Failed to create SDP record").into());
                    }
                }
            }
            "disable" => {
                let mut context = self.lock_context();
                context.telephony_dbus.as_mut().unwrap().set_phone_ops_enabled(false);
                if let Some(handle) = context.mps_sdp_handle.take() {
                    let success = context.adapter_dbus.as_mut().unwrap().remove_sdp_record(handle);
                    if !success {
                        return Err(format!("Failed to remove SDP record").into());
                    }
                }
            }
            "incoming-call" => {
                let success = self
+21 −2
Original line number Diff line number Diff line
@@ -7,8 +7,9 @@ use bt_topshim::btif::{
use bt_topshim::profiles::gatt::{AdvertisingStatus, GattStatus, LePhy};
use bt_topshim::profiles::hid_host::BthhReportType;
use bt_topshim::profiles::sdp::{
    BtSdpDipRecord, BtSdpHeaderOverlay, BtSdpMasRecord, BtSdpMnsRecord, BtSdpOpsRecord,
    BtSdpPceRecord, BtSdpPseRecord, BtSdpRecord, BtSdpSapRecord, BtSdpType, SupportedFormatsList,
    BtSdpDipRecord, BtSdpHeaderOverlay, BtSdpMasRecord, BtSdpMnsRecord, BtSdpMpsRecord,
    BtSdpOpsRecord, BtSdpPceRecord, BtSdpPseRecord, BtSdpRecord, BtSdpSapRecord, BtSdpType,
    SupportedDependencies, SupportedFormatsList, SupportedScenarios,
};
use bt_topshim::profiles::socket::SocketType;
use bt_topshim::profiles::ProfileConnectionState;
@@ -181,6 +182,17 @@ struct BtSdpDipRecordDBus {
    primary_record: bool,
}

impl_dbus_arg_from_into!(SupportedScenarios, Vec<u8>);
impl_dbus_arg_from_into!(SupportedDependencies, Vec<u8>);

#[dbus_propmap(BtSdpMpsRecord)]
pub struct BtSdpMpsRecordDBus {
    hdr: BtSdpHeaderOverlay,
    supported_scenarios_mpsd: SupportedScenarios,
    supported_scenarios_mpmd: SupportedScenarios,
    supported_dependencies: SupportedDependencies,
}

fn read_propmap_value<T: 'static + DirectDBus>(
    propmap: &dbus::arg::PropMap,
    key: &str,
@@ -278,6 +290,10 @@ impl DBusArg for BtSdpRecord {
                let arg_0 = parse_propmap_value::<BtSdpDipRecord>(&data, "0")?;
                BtSdpRecord::Dip(arg_0)
            }
            BtSdpType::Mps => {
                let arg_0 = parse_propmap_value::<BtSdpMpsRecord>(&data, "0")?;
                BtSdpRecord::Mps(arg_0)
            }
        };
        Ok(record)
    }
@@ -314,6 +330,9 @@ impl DBusArg for BtSdpRecord {
            BtSdpRecord::Dip(dip_record) => {
                write_propmap_value::<BtSdpDipRecord>(&mut map, dip_record, &String::from("0"))?
            }
            BtSdpRecord::Mps(mps_record) => {
                write_propmap_value::<BtSdpMpsRecord>(&mut map, mps_record, &String::from("0"))?
            }
        }
        Ok(map)
    }
+4 −0
Original line number Diff line number Diff line
@@ -127,6 +127,9 @@ pub(crate) struct ClientContext {

    /// The schedule when a socket is connected.
    socket_test_schedule: Option<SocketSchedule>,

    /// The handle of the SDP record for MPS (Multi-Profile Specification).
    mps_sdp_handle: Option<i32>,
}

impl ClientContext {
@@ -170,6 +173,7 @@ impl ClientContext {
            is_restricted,
            gatt_client_context: GattClientContext::new(),
            socket_test_schedule: None,
            mps_sdp_handle: None,
        }
    }

+21 −2
Original line number Diff line number Diff line
@@ -8,8 +8,9 @@ use bt_topshim::profiles::ProfileConnectionState;
use bt_topshim::profiles::hid_host::BthhReportType;

use bt_topshim::profiles::sdp::{
    BtSdpDipRecord, BtSdpHeaderOverlay, BtSdpMasRecord, BtSdpMnsRecord, BtSdpOpsRecord,
    BtSdpPceRecord, BtSdpPseRecord, BtSdpRecord, BtSdpSapRecord, BtSdpType, SupportedFormatsList,
    BtSdpDipRecord, BtSdpHeaderOverlay, BtSdpMasRecord, BtSdpMnsRecord, BtSdpMpsRecord,
    BtSdpOpsRecord, BtSdpPceRecord, BtSdpPseRecord, BtSdpRecord, BtSdpSapRecord, BtSdpType,
    SupportedDependencies, SupportedFormatsList, SupportedScenarios,
};

use btstack::bluetooth::{
@@ -228,6 +229,17 @@ struct BtSdpDipRecordDBus {
    primary_record: bool,
}

impl_dbus_arg_from_into!(SupportedScenarios, Vec<u8>);
impl_dbus_arg_from_into!(SupportedDependencies, Vec<u8>);

#[dbus_propmap(BtSdpMpsRecord)]
pub struct BtSdpMpsRecordDBus {
    hdr: BtSdpHeaderOverlay,
    supported_scenarios_mpsd: SupportedScenarios,
    supported_scenarios_mpmd: SupportedScenarios,
    supported_dependencies: SupportedDependencies,
}

fn read_propmap_value<T: 'static + DirectDBus>(
    propmap: &dbus::arg::PropMap,
    key: &str,
@@ -325,6 +337,10 @@ impl DBusArg for BtSdpRecord {
                let arg_0 = parse_propmap_value::<BtSdpDipRecord>(&data, "0")?;
                BtSdpRecord::Dip(arg_0)
            }
            BtSdpType::Mps => {
                let arg_0 = parse_propmap_value::<BtSdpMpsRecord>(&data, "0")?;
                BtSdpRecord::Mps(arg_0)
            }
        };
        Ok(record)
    }
@@ -361,6 +377,9 @@ impl DBusArg for BtSdpRecord {
            BtSdpRecord::Dip(dip_record) => {
                write_propmap_value::<BtSdpDipRecord>(&mut map, dip_record, &String::from("0"))?
            }
            BtSdpRecord::Mps(mps_record) => {
                write_propmap_value::<BtSdpMpsRecord>(&mut map, mps_record, &String::from("0"))?
            }
        }
        Ok(map)
    }
Loading