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

Commit acd6de38 authored by Ying Hsu's avatar Ying Hsu Committed by Ying Hsu
Browse files

Floss: Add dumpsys command

This patch allows developers to get diagnostics information
from Fluoride's dump interface.
It helps on debugging LE audio connection information and parameters
negotiated with remote devices.

Bug: 327542410
Tag: #floss
Test: btclient -c dumpsys
Test: m com.android.btservices
Floag: EXEMPT, floss only change
Change-Id: I1957ea81b0b4bdab0297b5182c0920dbd53ee059
parent 1077361f
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -389,6 +389,14 @@ fn build_commands() -> HashMap<String, CommandOption> {
            function_pointer: _noop,
        },
    );
    command_options.insert(
        String::from("dumpsys"),
        CommandOption {
            rules: vec![String::from("dumpsys")],
            description: String::from("Get diagnostic output."),
            function_pointer: CommandHandler::cmd_dumpsys,
        },
    );
    command_options
}

@@ -2341,6 +2349,17 @@ impl CommandHandler {

        Ok(())
    }

    fn cmd_dumpsys(&mut self, _args: &Vec<String>) -> CommandResult {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
        }

        let contents = self.lock_context().adapter_dbus.as_mut().unwrap().get_dumpsys();
        println!("{}", contents);

        Ok(())
    }
}

#[cfg(test)]
+5 −0
Original line number Diff line number Diff line
@@ -1035,6 +1035,11 @@ impl IBluetooth for BluetoothDBus {
    fn is_dual_mode_audio_sink_device(&self, device: BluetoothDevice) -> bool {
        dbus_generated!()
    }

    #[dbus_method("GetDumpsys")]
    fn get_dumpsys(&self) -> String {
        dbus_generated!()
    }
}

pub(crate) struct BluetoothQALegacyDBus {
+5 −0
Original line number Diff line number Diff line
@@ -770,6 +770,11 @@ impl IBluetooth for IBluetoothDBus {
    fn is_dual_mode_audio_sink_device(&self, device: BluetoothDevice) -> bool {
        dbus_generated!()
    }

    #[dbus_method("GetDumpsys", DBusLog::Disable)]
    fn get_dumpsys(&self) -> String {
        dbus_generated!()
    }
}

impl_dbus_arg_enum!(SocketType);
+2 −1
Original line number Diff line number Diff line
@@ -16,14 +16,15 @@ env_logger = "0.8.3"
itertools = "0.10.5"
lazy_static = "1.4"
log = "0.4.14"
log-panics = "2.1.0"
nix = "0.23"
num-derive = "0.3"
num-traits = "0.2"
rand = { version = "0.8.3", features = ["small_rng"] }
serde_json = "1.0"
syslog = "6"
tempfile = "3.10"
tokio = { version = "1", features = ['bytes', 'fs', 'io-util', 'libc', 'macros', 'mio', 'net', 'num_cpus', 'rt', 'rt-multi-thread', 'sync', 'time', 'tokio-macros'] }
log-panics = "2.1.0"

[lib]
path = "src/lib.rs"
+15 −0
Original line number Diff line number Diff line
@@ -34,10 +34,12 @@ use std::convert::TryInto;
use std::fs::File;
use std::hash::Hash;
use std::io::Write;
use std::os::fd::AsRawFd;
use std::process;
use std::sync::{Arc, Condvar, Mutex};
use std::time::Duration;
use std::time::Instant;
use tempfile::NamedTempFile;
use tokio::sync::mpsc::Sender;
use tokio::task::JoinHandle;
use tokio::time;
@@ -262,6 +264,9 @@ pub trait IBluetooth {
    /// Returns whether the remote device is a dual mode audio sink device (supports both classic and
    /// LE Audio sink roles).
    fn is_dual_mode_audio_sink_device(&self, device: BluetoothDevice) -> bool;

    /// Gets diagnostic output.
    fn get_dumpsys(&self) -> String;
}

/// Adapter API for Bluetooth qualification and verification.
@@ -2998,6 +3003,16 @@ impl IBluetooth for Bluetooth {
            is_dual_mode(self.get_remote_uuids(BluetoothDevice::new(*addr, "".to_string())))
        })
    }

    fn get_dumpsys(&self) -> String {
        NamedTempFile::new()
            .and_then(|file| {
                let fd = file.as_raw_fd();
                self.intf.lock().unwrap().dump(fd);
                std::fs::read_to_string(file.path())
            })
            .unwrap_or_default()
    }
}

impl BtifSdpCallbacks for Bluetooth {
Loading