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

Commit b3f0c5fa authored by Archie Pusaka's avatar Archie Pusaka
Browse files

Floss: Add DBus logging for outbound traffic

Inbound and outbound DBus traffic should be logged if it's not noisy,
as it contains critical debugging information.

This CL enables logging the outbound traffic.

Bug: 298149797
Tag: #floss
Test: Manually observe bluetooth.log
Test: mma -j

Change-Id: I0792d3de2fe1d445fbd4f40180e5d50ca23430a0
parent 0943ce76
Loading
Loading
Loading
Loading
+47 −13
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ fn debug_output_to_file(gen: &proc_macro2::TokenStream, filename: String) {
///
/// `dbus_method_name`: String. The D-Bus method name.
/// `dbus_logging`: enum DBusLog, optional. Whether to enable logging and the log verbosity.
///                 Note that log is disabled by default for outgoing dbus messages, but enabled
///                 by default with verbose level for incoming messages.
#[proc_macro_attribute]
pub fn dbus_method(_attr: TokenStream, item: TokenStream) -> TokenStream {
    let ori_item: proc_macro2::TokenStream = item.clone().into();
@@ -715,6 +717,16 @@ pub fn dbus_propmap(attr: TokenStream, item: TokenStream) -> TokenStream {
}

/// Generates a DBusArg implementation of a Remote RPC proxy object.
///
/// Example:
///   `#[dbus_proxy_obj(FooCallback, "org.example.FooCallbackInterface")]`
///
/// In order to call the remote methods, declare them with the attribute #[dbus_method()].
///
/// # Args
///
/// `struct_ident`: A freeform name used to identify the object struct.
/// `dbus_iface_name`: Name of the interface where this object should be exported.
#[proc_macro_attribute]
pub fn dbus_proxy_obj(attr: TokenStream, item: TokenStream) -> TokenStream {
    let ori_item: proc_macro2::TokenStream = item.clone().into();
@@ -756,20 +768,26 @@ pub fn dbus_proxy_obj(attr: TokenStream, item: TokenStream) -> TokenStream {
                continue;
            }

            let attr_args = attr.parse_meta().unwrap();
            let dbus_method_name = if let Meta::List(meta_list) = attr_args {
                Some(meta_list.nested[0].clone())
            } else {
                None
            let meta_list = match attr.parse_meta().unwrap() {
                Meta::List(meta_list) => meta_list,
                _ => continue,
            };

            if dbus_method_name.is_none() {
                continue;
            }
            let dbus_method_name = meta_list.nested[0].clone();

            // logging is default to disabled if not specified
            let dbus_logging = if meta_list.nested.len() > 1 {
                meta_list.nested[1].clone()
            } else {
                let token = quote! { DBusLog::Disable };
                syn::parse2::<NestedMeta>(token).unwrap()
            };

            let method_sig = method.sig.clone();

            let mut method_args = quote! {};
            let mut args_debug = quote! {};
            let mut args_debug_format = String::new();

            for input in method.sig.inputs {
                if let FnArg::Typed(ref typed) = input {
@@ -779,10 +797,24 @@ pub fn dbus_proxy_obj(attr: TokenStream, item: TokenStream) -> TokenStream {
                        method_args = quote! {
                            #method_args DBusArg::to_dbus(#ident).unwrap(),
                        };

                        args_debug = quote! {
                            #args_debug &#ident,
                        };

                        if args_debug_format.len() != 0 {
                            args_debug_format.push_str(", ");
                        }
                        args_debug_format.push_str("{:?}");
                    }
                }
            }

            let debug = quote! {
                let args_formatted = format!(#args_debug_format, #args_debug);
                DBusLog::log(#dbus_logging, "dbus out", #dbus_iface_name, #dbus_method_name, args_formatted.as_str());
            };

            method_impls = quote! {
                #method_impls
                #[allow(unused_variables)]
@@ -791,6 +823,8 @@ pub fn dbus_proxy_obj(attr: TokenStream, item: TokenStream) -> TokenStream {
                    let objpath__ = self.objpath.clone();
                    let conn__ = self.conn.clone();

                    #debug

                    let proxy = dbus::nonblock::Proxy::new(
                        remote__,
                        objpath__,
+16 −4
Original line number Diff line number Diff line
@@ -110,7 +110,10 @@ impl IBluetoothCallback for BluetoothCallbackDBus {
    fn on_discovering_changed(&mut self, discovering: bool) {
        dbus_generated!()
    }
    #[dbus_method("OnSspRequest")]
    #[dbus_method(
        "OnSspRequest",
        DBusLog::Enable(DBusLogOptions::LogAll, DBusLogVerbosity::Verbose)
    )]
    fn on_ssp_request(
        &mut self,
        remote_device: BluetoothDevice,
@@ -128,7 +131,10 @@ impl IBluetoothCallback for BluetoothCallbackDBus {
    fn on_pin_display(&mut self, remote_device: BluetoothDevice, pincode: String) {
        dbus_generated!()
    }
    #[dbus_method("OnBondStateChanged")]
    #[dbus_method(
        "OnBondStateChanged",
        DBusLog::Enable(DBusLogOptions::LogAll, DBusLogVerbosity::Verbose)
    )]
    fn on_bond_state_changed(&mut self, status: u32, address: String, state: u32) {
        dbus_generated!()
    }
@@ -160,12 +166,18 @@ struct BluetoothConnectionCallbackDBus {}

#[dbus_proxy_obj(BluetoothConnectionCallback, "org.chromium.bluetooth.BluetoothConnectionCallback")]
impl IBluetoothConnectionCallback for BluetoothConnectionCallbackDBus {
    #[dbus_method("OnDeviceConnected")]
    #[dbus_method(
        "OnDeviceConnected",
        DBusLog::Enable(DBusLogOptions::LogAll, DBusLogVerbosity::Verbose)
    )]
    fn on_device_connected(&mut self, remote_device: BluetoothDevice) {
        dbus_generated!()
    }

    #[dbus_method("OnDeviceDisconnected")]
    #[dbus_method(
        "OnDeviceDisconnected",
        DBusLog::Enable(DBusLogOptions::LogAll, DBusLogVerbosity::Verbose)
    )]
    fn on_device_disconnected(&mut self, remote_device: BluetoothDevice) {
        dbus_generated!()
    }