settings/display/
display_configuration.rs

1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! This file contains a number of enums and structs that are used as an
6//! internal representation of the configuration data found in
7//! `/config/data/display_configuration.json`.
8
9use serde::{Deserialize, Serialize};
10use settings_common::config::default_settings::DefaultSetting;
11use settings_common::inspect::config_logger::InspectConfigLogger;
12use std::rc::Rc;
13use std::sync::Mutex;
14
15/// Possible theme modes that can be found in
16/// `/config/data/display_configuration.json`.
17#[derive(PartialEq, Debug, Clone, Copy, Serialize, Deserialize)]
18pub enum ConfigurationThemeMode {
19    Auto,
20}
21
22/// Possible theme types that can be found in
23/// `/config/data/display_configuration.json`.
24#[derive(PartialEq, Debug, Clone, Copy, Serialize, Deserialize)]
25pub enum ConfigurationThemeType {
26    Light,
27}
28
29/// Internal representation of the display configuration stored in
30/// `/config/data/display_configuration.json`.
31#[derive(PartialEq, Debug, Clone, Deserialize)]
32pub struct DisplayConfiguration {
33    pub theme: ThemeConfiguration,
34}
35
36/// Internal representation of the theme portion of the configuration stored in
37/// `/config/data/display_configuration.json`.
38#[derive(PartialEq, Debug, Clone, Deserialize)]
39pub struct ThemeConfiguration {
40    pub theme_mode: Vec<ConfigurationThemeMode>,
41    pub theme_type: ConfigurationThemeType,
42}
43
44pub fn build_display_default_settings(
45    config_logger: Rc<Mutex<InspectConfigLogger>>,
46) -> DefaultSetting<DisplayConfiguration, &'static str> {
47    DefaultSetting::new(None, "/config/data/display_configuration.json", config_logger)
48}
49
50#[cfg(test)]
51mod test {
52    use super::*;
53    use fuchsia_inspect::component;
54
55    #[fuchsia::test(allow_stalls = false)]
56    async fn test_display_configuration() {
57        let config_logger =
58            Rc::new(Mutex::new(InspectConfigLogger::new(component::inspector().root())));
59        let default_value = build_display_default_settings(config_logger)
60            .load_default_value()
61            .expect("Invalid display configuration")
62            .expect("Unable to parse configuration");
63
64        assert_eq!(default_value.theme.theme_mode, vec![ConfigurationThemeMode::Auto]);
65        assert_eq!(default_value.theme.theme_type, ConfigurationThemeType::Light);
66    }
67}