session_manager_config/
session_manager_config_rust_config_lib_source.rs
1use fidl::unpersist;
2use fidl_cf_sc_internal_sessionmanagerconfig::Config as FidlConfig;
3use fuchsia_inspect::Node;
4use fuchsia_runtime::{take_startup_handle, HandleInfo, HandleType};
5#[derive(Debug)]
6pub struct Config {
7 pub autolaunch: bool,
8 pub session_url: String,
9 pub suspend_enabled: bool,
10}
11impl Config {
12 pub fn take_from_startup_handle() -> Self {
13 let config_vmo: zx::Vmo =
14 take_startup_handle(HandleInfo::new(HandleType::ComponentConfigVmo, 0))
15 .expect("Config VMO handle must be provided and cannot already have been taken.")
16 .into();
17 let config_size =
18 config_vmo.get_content_size().expect("must be able to read config vmo content size");
19 assert_ne!(config_size, 0, "config vmo must be non-empty");
20 let config_bytes =
21 config_vmo.read_to_vec(0, config_size).expect("must be able to read config vmo");
22 let checksum_length = u16::from_le_bytes([config_bytes[0], config_bytes[1]]) as usize;
23 let fidl_start = 2 + checksum_length;
24 let observed_checksum = &config_bytes[2..fidl_start];
25 let expected_checksum = vec![
26 0xd7, 0x0f, 0x8b, 0x49, 0x3a, 0xd0, 0xea, 0x30, 0x79, 0x81, 0x0c, 0x1f, 0x69, 0x52,
27 0xdd, 0xb1, 0x38, 0x84, 0x29, 0xc1, 0x66, 0x04, 0x87, 0xee, 0xc1, 0x73, 0x8d, 0x9d,
28 0xbe, 0x6a, 0xd4, 0xc5,
29 ];
30 assert_eq!(
31 observed_checksum, expected_checksum,
32 "checksum from config VMO does not match expected checksum"
33 );
34 let fidl_config: FidlConfig = unpersist(&config_bytes[fidl_start..])
35 .expect("must be able to parse bytes as config FIDL");
36 Self {
37 autolaunch: fidl_config.autolaunch,
38 session_url: fidl_config.session_url,
39 suspend_enabled: fidl_config.suspend_enabled,
40 }
41 }
42 pub fn record_inspect(&self, inspector_node: &Node) {
43 inspector_node.record_bool("autolaunch", self.autolaunch);
44 inspector_node.record_string("session_url", &self.session_url);
45 inspector_node.record_bool("suspend_enabled", self.suspend_enabled);
46 }
47}