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

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

floss: Log pretty UUID in DBus debugging log

It was printed as "array of u8" so was hard to read.

This patch also removes the RefArgToRust impl for Uuid because it's not
used. This is only needed for those underlying types that are used as
DBusType.

Bug: 342337056
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: manual Toggle BT, verify the log
Flag: EXEMPT, Floss-only changes
Change-Id: Iac9352b9bb1eb21455c12033c852f8dda0699963
parent 9e99e3c8
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -112,17 +112,6 @@ impl_dbus_arg_from_into!(Uuid, Vec<u8>);
impl_dbus_arg_enum!(BthhReportType);
impl_dbus_arg_enum!(BtAdapterRole);

impl RefArgToRust for Uuid {
    type RustType = Vec<u8>;

    fn ref_arg_to_rust(
        arg: &(dyn dbus::arg::RefArg + 'static),
        name: String,
    ) -> Result<Self::RustType, Box<dyn std::error::Error>> {
        <Vec<u8> as RefArgToRust>::ref_arg_to_rust(arg, name)
    }
}

impl_dbus_arg_enum!(BtSdpType);

#[dbus_propmap(BtSdpHeaderOverlay)]
+20 −8
Original line number Diff line number Diff line
@@ -41,16 +41,28 @@ use std::sync::{Arc, Mutex};
use crate::dbus_arg::{DBusArg, DBusArgError, DirectDBus, RefArgToRust};

// Represents Uuid as an array in D-Bus.
impl_dbus_arg_from_into!(Uuid, Vec<u8>);
impl DBusArg for Uuid {
    type DBusType = Vec<u8>;
    fn from_dbus(
        data: Vec<u8>,
        _conn: Option<Arc<SyncConnection>>,
        _remote: Option<dbus::strings::BusName<'static>>,
        _disconnect_watcher: Option<Arc<Mutex<dbus_projection::DisconnectWatcher>>>,
    ) -> Result<Uuid, Box<dyn std::error::Error>> {
        Ok(Uuid::try_from(data.clone()).or_else(|_| {
            Err(format!(
                "Invalid Uuid: first 4 bytes={:?}",
                data.iter().take(4).collect::<Vec<_>>()
            ))
        })?)
    }

impl RefArgToRust for Uuid {
    type RustType = Vec<u8>;
    fn to_dbus(data: Uuid) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
        Ok(data.try_into()?)
    }

    fn ref_arg_to_rust(
        arg: &(dyn dbus::arg::RefArg + 'static),
        name: String,
    ) -> Result<Self::RustType, Box<dyn std::error::Error>> {
        <Vec<u8> as RefArgToRust>::ref_arg_to_rust(arg, name)
    fn log(data: &Uuid) -> String {
        format!("{}", data)
    }
}