hfp_profile_config/
hfp_profile_config_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_hfpprofileconfig::Config as FidlConfig;
3use fuchsia_inspect::Node;
4use fuchsia_runtime::{take_startup_handle, HandleInfo, HandleType};
5#[derive(Debug)]
6pub struct Config {
7    pub attach_phone_number_to_voice_tag: bool,
8    pub controller_encoding_cvsd: bool,
9    pub controller_encoding_msbc: bool,
10    pub echo_canceling_and_noise_reduction: bool,
11    pub enhanced_call_controls: bool,
12    pub enhanced_voice_recognition: bool,
13    pub enhanced_voice_recognition_with_text: bool,
14    pub in_band_ringtone: bool,
15    pub offload_type: String,
16    pub reject_incoming_voice_call: bool,
17    pub three_way_calling: bool,
18    pub voice_recognition: bool,
19    pub wide_band_speech: bool,
20}
21impl Config {
22    pub fn take_from_startup_handle() -> Self {
23        let config_vmo: zx::Vmo =
24            take_startup_handle(HandleInfo::new(HandleType::ComponentConfigVmo, 0))
25                .expect("Config VMO handle must be provided and cannot already have been taken.")
26                .into();
27        let config_size =
28            config_vmo.get_content_size().expect("must be able to read config vmo content size");
29        assert_ne!(config_size, 0, "config vmo must be non-empty");
30        let config_bytes =
31            config_vmo.read_to_vec(0, config_size).expect("must be able to read config vmo");
32        let checksum_length = u16::from_le_bytes([config_bytes[0], config_bytes[1]]) as usize;
33        let fidl_start = 2 + checksum_length;
34        let observed_checksum = &config_bytes[2..fidl_start];
35        let expected_checksum = vec![
36            0x53, 0xda, 0x30, 0x9e, 0x28, 0x16, 0x79, 0x5b, 0xd7, 0x13, 0x34, 0xf3, 0x69, 0xd9,
37            0x93, 0xc6, 0x6b, 0xe4, 0xb4, 0x64, 0x33, 0x20, 0x52, 0xbb, 0x5f, 0x2e, 0x96, 0x72,
38            0xc9, 0x36, 0xec, 0x3c,
39        ];
40        assert_eq!(
41            observed_checksum, expected_checksum,
42            "checksum from config VMO does not match expected checksum"
43        );
44        let fidl_config: FidlConfig = unpersist(&config_bytes[fidl_start..])
45            .expect("must be able to parse bytes as config FIDL");
46        Self {
47            attach_phone_number_to_voice_tag: fidl_config.attach_phone_number_to_voice_tag,
48            controller_encoding_cvsd: fidl_config.controller_encoding_cvsd,
49            controller_encoding_msbc: fidl_config.controller_encoding_msbc,
50            echo_canceling_and_noise_reduction: fidl_config.echo_canceling_and_noise_reduction,
51            enhanced_call_controls: fidl_config.enhanced_call_controls,
52            enhanced_voice_recognition: fidl_config.enhanced_voice_recognition,
53            enhanced_voice_recognition_with_text: fidl_config.enhanced_voice_recognition_with_text,
54            in_band_ringtone: fidl_config.in_band_ringtone,
55            offload_type: fidl_config.offload_type,
56            reject_incoming_voice_call: fidl_config.reject_incoming_voice_call,
57            three_way_calling: fidl_config.three_way_calling,
58            voice_recognition: fidl_config.voice_recognition,
59            wide_band_speech: fidl_config.wide_band_speech,
60        }
61    }
62    pub fn record_inspect(&self, inspector_node: &Node) {
63        inspector_node
64            .record_bool("attach_phone_number_to_voice_tag", self.attach_phone_number_to_voice_tag);
65        inspector_node.record_bool("controller_encoding_cvsd", self.controller_encoding_cvsd);
66        inspector_node.record_bool("controller_encoding_msbc", self.controller_encoding_msbc);
67        inspector_node.record_bool(
68            "echo_canceling_and_noise_reduction",
69            self.echo_canceling_and_noise_reduction,
70        );
71        inspector_node.record_bool("enhanced_call_controls", self.enhanced_call_controls);
72        inspector_node.record_bool("enhanced_voice_recognition", self.enhanced_voice_recognition);
73        inspector_node.record_bool(
74            "enhanced_voice_recognition_with_text",
75            self.enhanced_voice_recognition_with_text,
76        );
77        inspector_node.record_bool("in_band_ringtone", self.in_band_ringtone);
78        inspector_node.record_string("offload_type", &self.offload_type);
79        inspector_node.record_bool("reject_incoming_voice_call", self.reject_incoming_voice_call);
80        inspector_node.record_bool("three_way_calling", self.three_way_calling);
81        inspector_node.record_bool("voice_recognition", self.voice_recognition);
82        inspector_node.record_bool("wide_band_speech", self.wide_band_speech);
83    }
84}