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

Commit b34a984d authored by Manish Mandlik's avatar Manish Mandlik
Browse files

Floss: Add dbus method to enable devcoredump

Add a dbus method to enable or disable bluetooth devcoredump.

Bug: 203034370
Tag: #floss
Test: Change chrome flag and verify changes reflect in the
     '/sys/class/bluetooth/hci0/device/coredump_disabled' file
Change-Id: Ibe0805bfa5b71d5bd4ff0b10ace28e3d67eda66a
parent 067e37d9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -20,4 +20,9 @@ impl IBluetoothExperimental for BluetoothExperimentalDBus {
    fn set_ll_privacy(&mut self, enabled: bool) {
        dbus_generated!()
    }

    #[dbus_method("SetDevCoredump")]
    fn set_devcoredump(&mut self, enabled: bool) -> bool {
        dbus_generated!()
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -187,4 +187,9 @@ impl IBluetoothExperimental for BluetoothManager {
            return;
        }
    }

    fn set_devcoredump(&mut self, enabled: bool) -> bool {
        info!("Set floss devcoredump to {}", enabled);
        config_util::write_coredump_state_to_file(enabled)
    }
}
+34 −0
Original line number Diff line number Diff line
@@ -15,6 +15,12 @@ const BTMANAGERD_CONF: &str = "/var/lib/bluetooth/btmanagerd.json";
/// Folder to keep files which override floss configuration
const FLOSS_SYSPROPS_OVERRIDE_DIR: &str = "/var/lib/bluetooth/sysprops.conf.d";

/// File to store bluetooth devcoredump configuration. This file is used by the
/// udev rule to copy the devcoredump state to .../device/coredump_enabled sysfs
/// entry. It is also used by the user-space crash reporter to enable/disable
/// parsing of the devcoredump.
const FLOSS_COREDUMP_CONF_PATH: &str = "/var/run/bluetooth/coredump_disabled";

/// Key used for default adapter entry.
const DEFAULT_ADAPTER_KEY: &str = "default_adapter";

@@ -220,6 +226,34 @@ pub fn write_floss_ll_privacy_enabled(enabled: bool) -> std::io::Result<()> {
    std::fs::write(format!("{}/{}", FLOSS_SYSPROPS_OVERRIDE_DIR, "privacy_override.conf"), data)
}

pub fn set_adapter_coredump_state(enabled: bool) -> std::io::Result<()> {
    let data = format!("{}\n", !enabled as i32);

    for hci in list_hci_devices_string() {
        let path = format!("{}/{}/device/coredump_disabled", HCI_DEVICES_DIR, hci);

        std::fs::write(path, &data)?;
    }

    Ok(())
}

pub fn write_coredump_state_to_file(enabled: bool) -> bool {
    let data = format!("{}\n", !enabled as i32);

    if let Err(e) = std::fs::write(FLOSS_COREDUMP_CONF_PATH, data) {
        log::error!("Failed to write devcoredump state (error: {})", e);
        return false;
    }

    if let Err(e) = set_adapter_coredump_state(enabled) {
        log::error!("Failed to set devcoredump state (error: {})", e);
        return false;
    }

    true
}

#[cfg(test)]
mod tests {
    use super::*;
+3 −0
Original line number Diff line number Diff line
@@ -2,4 +2,7 @@
pub trait IBluetoothExperimental {
    /// Set LL privacy status
    fn set_ll_privacy(&mut self, enabled: bool);

    /// Set devcoredump status
    fn set_devcoredump(&mut self, enabled: bool) -> bool;
}