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.
45//! 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`.
89use std::rc::Rc;
10use std::sync::Mutex;
1112use serde::{Deserialize, Serialize};
1314use crate::config::default_settings::DefaultSetting;
15use crate::inspect::config_logger::InspectConfigLogger;
1617/// Possible theme modes that can be found in
18/// `/config/data/display_configuration.json`.
19#[derive(PartialEq, Debug, Clone, Copy, Serialize, Deserialize)]
20pub enum ConfigurationThemeMode {
21 Auto,
22}
2324/// Possible theme types that can be found in
25/// `/config/data/display_configuration.json`.
26#[derive(PartialEq, Debug, Clone, Copy, Serialize, Deserialize)]
27pub enum ConfigurationThemeType {
28 Light,
29}
3031/// Internal representation of the display configuration stored in
32/// `/config/data/display_configuration.json`.
33#[derive(PartialEq, Debug, Clone, Deserialize)]
34pub struct DisplayConfiguration {
35pub theme: ThemeConfiguration,
36}
3738/// Internal representation of the theme portion of the configuration stored in
39/// `/config/data/display_configuration.json`.
40#[derive(PartialEq, Debug, Clone, Deserialize)]
41pub struct ThemeConfiguration {
42pub theme_mode: Vec<ConfigurationThemeMode>,
43pub theme_type: ConfigurationThemeType,
44}
4546pub fn build_display_default_settings(
47 config_logger: Rc<Mutex<InspectConfigLogger>>,
48) -> DefaultSetting<DisplayConfiguration, &'static str> {
49 DefaultSetting::new(None, "/config/data/display_configuration.json", config_logger)
50}
5152#[cfg(test)]
53mod test {
54use super::*;
55use fuchsia_inspect::component;
5657#[fuchsia::test(allow_stalls = false)]
58async fn test_display_configuration() {
59let config_logger =
60 Rc::new(Mutex::new(InspectConfigLogger::new(component::inspector().root())));
61let default_value = build_display_default_settings(config_logger)
62 .load_default_value()
63 .expect("Invalid display configuration")
64 .expect("Unable to parse configuration");
6566assert_eq!(default_value.theme.theme_mode, vec![ConfigurationThemeMode::Auto]);
67assert_eq!(default_value.theme.theme_type, ConfigurationThemeType::Light);
68 }
69}