brightness_manager_config/
brightness_manager_config_rust_config_lib_source.rsuse fidl::unpersist;
use fidl_cf_sc_internal_brightnessmanagerconfig::Config as FidlConfig;
use fuchsia_inspect::Node;
use fuchsia_runtime::{take_startup_handle, HandleInfo, HandleType};
#[derive(Debug)]
pub struct Config {
pub manage_display_power: bool,
pub power_off_delay_millis: u16,
pub power_on_delay_millis: u16,
}
impl Config {
pub fn take_from_startup_handle() -> Self {
let config_vmo: zx::Vmo =
take_startup_handle(HandleInfo::new(HandleType::ComponentConfigVmo, 0))
.expect("Config VMO handle must be provided and cannot already have been taken.")
.into();
let config_size =
config_vmo.get_content_size().expect("must be able to read config vmo content size");
assert_ne!(config_size, 0, "config vmo must be non-empty");
let config_bytes =
config_vmo.read_to_vec(0, config_size).expect("must be able to read config vmo");
let checksum_length = u16::from_le_bytes([config_bytes[0], config_bytes[1]]) as usize;
let fidl_start = 2 + checksum_length;
let observed_checksum = &config_bytes[2..fidl_start];
let expected_checksum = vec![
0xe0, 0xaa, 0x2e, 0x12, 0xcb, 0x94, 0x4e, 0xb0, 0x38, 0x64, 0x81, 0xdb, 0x40, 0x90,
0xf0, 0xe3, 0x0f, 0xa3, 0xf5, 0x1c, 0xcb, 0x9b, 0x0d, 0x21, 0x5c, 0x29, 0xd8, 0xb7,
0xc5, 0xeb, 0x11, 0xf9,
];
assert_eq!(
observed_checksum, expected_checksum,
"checksum from config VMO does not match expected checksum"
);
let fidl_config: FidlConfig = unpersist(&config_bytes[fidl_start..])
.expect("must be able to parse bytes as config FIDL");
Self {
manage_display_power: fidl_config.manage_display_power,
power_off_delay_millis: fidl_config.power_off_delay_millis,
power_on_delay_millis: fidl_config.power_on_delay_millis,
}
}
pub fn record_inspect(&self, inspector_node: &Node) {
inspector_node.record_bool("manage_display_power", self.manage_display_power);
inspector_node.record_uint("power_off_delay_millis", self.power_off_delay_millis as u64);
inspector_node.record_uint("power_on_delay_millis", self.power_on_delay_millis as u64);
}
}