virtcon_config/
virtcon_config_rust_config_lib_source.rsuse fidl::unpersist;
use fidl_cf_sc_internal_virtconconfig::Config as FidlConfig;
use fuchsia_inspect::{ArithmeticArrayProperty, Node};
use fuchsia_runtime::{take_startup_handle, HandleInfo, HandleType};
#[derive(Debug)]
pub struct Config {
pub boot_animation: bool,
pub buffer_count: u32,
pub color_scheme: String,
pub disable: bool,
pub display_rotation: u32,
pub dpi: Vec<u32>,
pub font_size: String,
pub keep_log_visible: bool,
pub key_map: String,
pub keyrepeat: bool,
pub rounded_corners: bool,
pub scrollback_rows: u32,
}
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![
0x74, 0x6e, 0xae, 0x39, 0xee, 0xe2, 0xab, 0xf5, 0x23, 0xae, 0x2e, 0xfd, 0x27, 0x31,
0x55, 0x10, 0x56, 0xd5, 0xd8, 0xc2, 0x51, 0x64, 0x42, 0x84, 0x68, 0xd1, 0xea, 0x75,
0xf6, 0xaf, 0x96, 0xd7,
];
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 {
boot_animation: fidl_config.boot_animation,
buffer_count: fidl_config.buffer_count,
color_scheme: fidl_config.color_scheme,
disable: fidl_config.disable,
display_rotation: fidl_config.display_rotation,
dpi: fidl_config.dpi,
font_size: fidl_config.font_size,
keep_log_visible: fidl_config.keep_log_visible,
key_map: fidl_config.key_map,
keyrepeat: fidl_config.keyrepeat,
rounded_corners: fidl_config.rounded_corners,
scrollback_rows: fidl_config.scrollback_rows,
}
}
pub fn record_inspect(&self, inspector_node: &Node) {
inspector_node.record_bool("boot_animation", self.boot_animation);
inspector_node.record_uint("buffer_count", self.buffer_count as u64);
inspector_node.record_string("color_scheme", &self.color_scheme);
inspector_node.record_bool("disable", self.disable);
inspector_node.record_uint("display_rotation", self.display_rotation as u64);
let arr = inspector_node.create_uint_array("dpi", self.dpi.len());
for i in 0..self.dpi.len() {
arr.add(i, self.dpi[i] as u64);
}
inspector_node.record(arr);
inspector_node.record_string("font_size", &self.font_size);
inspector_node.record_bool("keep_log_visible", self.keep_log_visible);
inspector_node.record_string("key_map", &self.key_map);
inspector_node.record_bool("keyrepeat", self.keyrepeat);
inspector_node.record_bool("rounded_corners", self.rounded_corners);
inspector_node.record_uint("scrollback_rows", self.scrollback_rows as u64);
}
}