scene_manager_structured_config/
scene_manager_structured_config_rust_config_lib_source.rsuse fidl::unpersist;
use fidl_cf_sc_internal_scenemanagerstructuredconfig::Config as FidlConfig;
use fuchsia_inspect::{ArrayProperty, Node};
use fuchsia_runtime::{take_startup_handle, HandleInfo, HandleType};
#[derive(Debug)]
pub struct Config {
pub display_pixel_density: String,
pub display_rotation: u64,
pub idle_threshold_ms: u64,
pub supported_input_devices: Vec<String>,
pub suspend_enabled: bool,
pub viewing_distance: String,
}
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![
0x23, 0x13, 0xc4, 0x24, 0x44, 0xf8, 0xdd, 0xbd, 0xd9, 0x2c, 0xb2, 0xe9, 0x5f, 0x83,
0xff, 0x11, 0xfc, 0xd8, 0x7b, 0xc8, 0x10, 0xca, 0x41, 0x4c, 0x64, 0x23, 0x15, 0xf6,
0x91, 0x8e, 0x86, 0x80,
];
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 {
display_pixel_density: fidl_config.display_pixel_density,
display_rotation: fidl_config.display_rotation,
idle_threshold_ms: fidl_config.idle_threshold_ms,
supported_input_devices: fidl_config.supported_input_devices,
suspend_enabled: fidl_config.suspend_enabled,
viewing_distance: fidl_config.viewing_distance,
}
}
pub fn record_inspect(&self, inspector_node: &Node) {
inspector_node.record_string("display_pixel_density", &self.display_pixel_density);
inspector_node.record_uint("display_rotation", self.display_rotation);
inspector_node.record_uint("idle_threshold_ms", self.idle_threshold_ms);
let arr = inspector_node
.create_string_array("supported_input_devices", self.supported_input_devices.len());
for i in 0..self.supported_input_devices.len() {
arr.set(i, &self.supported_input_devices[i]);
}
inspector_node.record(arr);
inspector_node.record_bool("suspend_enabled", self.suspend_enabled);
inspector_node.record_string("viewing_distance", &self.viewing_distance);
}
}