1use anyhow::Error;
6use fidl_fuchsia_feedback::{LastRebootInfoProviderMarker, RebootReason};
7use fuchsia_component::client::connect_to_protocol_sync;
8use log::{debug, info};
9
10const LRIP_FIDL_TIMEOUT: zx::MonotonicDuration = zx::MonotonicDuration::INFINITE;
12
13pub fn get_android_bootreason() -> Result<&'static str, Error> {
15 info!("Converting LastRebootInfo to an android-friendly bootreason.");
16 let reboot_info_proxy = connect_to_protocol_sync::<LastRebootInfoProviderMarker>()?;
17 let deadline = zx::MonotonicInstant::after(LRIP_FIDL_TIMEOUT);
18 let reboot_info = reboot_info_proxy.get(deadline)?;
19
20 match reboot_info.reason {
21 Some(RebootReason::Unknown) => return Ok("reboot,unknown"),
22 Some(RebootReason::Cold) => return Ok("reboot,cold"),
23 Some(RebootReason::BriefPowerLoss) => return Ok("reboot,powerloss"),
24 Some(RebootReason::Brownout) => return Ok("reboot,undervoltage"),
25 Some(RebootReason::KernelPanic) => return Ok("kernel_panic"),
26 Some(RebootReason::SystemOutOfMemory) => return Ok("kernel_panic,oom"),
27 Some(RebootReason::HardwareWatchdogTimeout) => return Ok("watchdog"),
28 Some(RebootReason::SoftwareWatchdogTimeout) => return Ok("watchdog,sw"),
29 Some(RebootReason::RootJobTermination) => return Ok("kernel_panic"),
30 Some(RebootReason::UserRequest) => return Ok("reboot,userrequested"),
31 Some(RebootReason::RetrySystemUpdate) => return Ok("reboot,ota"),
32 Some(RebootReason::HighTemperature) => return Ok("shutdown,thermal"),
33 Some(RebootReason::SessionFailure) => return Ok("kernel_panic"),
34 Some(RebootReason::SysmgrFailure) => return Ok("kernel_panic"),
35 Some(RebootReason::FactoryDataReset) => return Ok("reboot,factory_reset"),
36 Some(RebootReason::CriticalComponentFailure) => return Ok("kernel_panic"),
37 Some(RebootReason::ZbiSwap) => return Ok("reboot,normal"),
38 Some(RebootReason::SystemUpdate) => return Ok("reboot,ota"),
39 Some(RebootReason::NetstackMigration) => return Ok("reboot,normal"),
40 Some(RebootReason::__SourceBreaking { .. }) => return Ok("reboot,normal"),
41 None => return Ok("reboot,unknown"),
42 }
43}
44
45pub fn get_console_ramoops() -> Option<Vec<u8>> {
49 debug!("Getting console-ramoops contents");
50 Some("Fuchsia Console Ramoops\n".as_bytes().to_vec())
52}