hfp_profile_config/
hfp_profile_config_rust_config_lib_source.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use fidl::unpersist;
use fidl_cf_sc_internal_hfpprofileconfig::Config as FidlConfig;
use fuchsia_inspect::Node;
use fuchsia_runtime::{take_startup_handle, HandleInfo, HandleType};
#[derive(Debug)]
pub struct Config {
    pub attach_phone_number_to_voice_tag: bool,
    pub controller_encoding_cvsd: bool,
    pub controller_encoding_msbc: bool,
    pub echo_canceling_and_noise_reduction: bool,
    pub enhanced_call_controls: bool,
    pub enhanced_voice_recognition: bool,
    pub enhanced_voice_recognition_with_text: bool,
    pub in_band_ringtone: bool,
    pub offload_type: String,
    pub reject_incoming_voice_call: bool,
    pub three_way_calling: bool,
    pub voice_recognition: bool,
    pub wide_band_speech: bool,
}
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![
            0x53, 0xda, 0x30, 0x9e, 0x28, 0x16, 0x79, 0x5b, 0xd7, 0x13, 0x34, 0xf3, 0x69, 0xd9,
            0x93, 0xc6, 0x6b, 0xe4, 0xb4, 0x64, 0x33, 0x20, 0x52, 0xbb, 0x5f, 0x2e, 0x96, 0x72,
            0xc9, 0x36, 0xec, 0x3c,
        ];
        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 {
            attach_phone_number_to_voice_tag: fidl_config.attach_phone_number_to_voice_tag,
            controller_encoding_cvsd: fidl_config.controller_encoding_cvsd,
            controller_encoding_msbc: fidl_config.controller_encoding_msbc,
            echo_canceling_and_noise_reduction: fidl_config.echo_canceling_and_noise_reduction,
            enhanced_call_controls: fidl_config.enhanced_call_controls,
            enhanced_voice_recognition: fidl_config.enhanced_voice_recognition,
            enhanced_voice_recognition_with_text: fidl_config.enhanced_voice_recognition_with_text,
            in_band_ringtone: fidl_config.in_band_ringtone,
            offload_type: fidl_config.offload_type,
            reject_incoming_voice_call: fidl_config.reject_incoming_voice_call,
            three_way_calling: fidl_config.three_way_calling,
            voice_recognition: fidl_config.voice_recognition,
            wide_band_speech: fidl_config.wide_band_speech,
        }
    }
    pub fn record_inspect(&self, inspector_node: &Node) {
        inspector_node
            .record_bool("attach_phone_number_to_voice_tag", self.attach_phone_number_to_voice_tag);
        inspector_node.record_bool("controller_encoding_cvsd", self.controller_encoding_cvsd);
        inspector_node.record_bool("controller_encoding_msbc", self.controller_encoding_msbc);
        inspector_node.record_bool(
            "echo_canceling_and_noise_reduction",
            self.echo_canceling_and_noise_reduction,
        );
        inspector_node.record_bool("enhanced_call_controls", self.enhanced_call_controls);
        inspector_node.record_bool("enhanced_voice_recognition", self.enhanced_voice_recognition);
        inspector_node.record_bool(
            "enhanced_voice_recognition_with_text",
            self.enhanced_voice_recognition_with_text,
        );
        inspector_node.record_bool("in_band_ringtone", self.in_band_ringtone);
        inspector_node.record_string("offload_type", &self.offload_type);
        inspector_node.record_bool("reject_incoming_voice_call", self.reject_incoming_voice_call);
        inspector_node.record_bool("three_way_calling", self.three_way_calling);
        inspector_node.record_bool("voice_recognition", self.voice_recognition);
        inspector_node.record_bool("wide_band_speech", self.wide_band_speech);
    }
}