settings/ingress/
fidl.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
5use crate::base::SettingType;
6use serde::Deserialize;
7
8/// [Interface] defines the FIDL interfaces supported by the settings service.
9#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
10pub enum Interface {
11    Accessibility,
12    Audio,
13    Display(display::InterfaceFlags),
14    DoNotDisturb,
15    FactoryReset,
16    Input,
17    Intl,
18    Keyboard,
19    Light,
20    NightMode,
21    Privacy,
22    Setup,
23}
24
25/// [InterfaceSpec] is the serializable type that defines the configuration for FIDL interfaces
26/// supported by the settings service. It's read in from configuration files to modify what
27/// interfaces the settings service provides.
28#[derive(Clone, Deserialize, PartialEq, Eq, Hash, Debug)]
29pub enum InterfaceSpec {
30    Accessibility,
31    Audio,
32    // Should ideally be a HashSet, but HashSet does not impl Hash.
33    Display(Vec<display::InterfaceSpec>),
34    DoNotDisturb,
35    FactoryReset,
36    Input,
37    Intl,
38    Keyboard,
39    Light,
40    NightMode,
41    Privacy,
42    Setup,
43}
44
45impl From<InterfaceSpec> for Interface {
46    fn from(spec: InterfaceSpec) -> Self {
47        match spec {
48            InterfaceSpec::Audio => Interface::Audio,
49            InterfaceSpec::Accessibility => Interface::Accessibility,
50            InterfaceSpec::Display(variants) => Interface::Display(variants.into()),
51            InterfaceSpec::DoNotDisturb => Interface::DoNotDisturb,
52            InterfaceSpec::FactoryReset => Interface::FactoryReset,
53            InterfaceSpec::Input => Interface::Input,
54            InterfaceSpec::Intl => Interface::Intl,
55            InterfaceSpec::Keyboard => Interface::Keyboard,
56            InterfaceSpec::Light => Interface::Light,
57            InterfaceSpec::NightMode => Interface::NightMode,
58            InterfaceSpec::Privacy => Interface::Privacy,
59            InterfaceSpec::Setup => Interface::Setup,
60        }
61    }
62}
63
64impl From<Interface> for SettingType {
65    fn from(spec: Interface) -> Self {
66        match spec {
67            Interface::Audio => SettingType::Audio,
68            Interface::Accessibility => SettingType::Accessibility,
69            Interface::Display(..) => SettingType::Display,
70            Interface::DoNotDisturb => SettingType::DoNotDisturb,
71            Interface::FactoryReset => SettingType::FactoryReset,
72            Interface::Input => SettingType::Input,
73            Interface::Intl => SettingType::Intl,
74            Interface::Keyboard => SettingType::Keyboard,
75            Interface::Light => SettingType::Light,
76            Interface::NightMode => SettingType::NightMode,
77            Interface::Privacy => SettingType::Privacy,
78            Interface::Setup => SettingType::Setup,
79        }
80    }
81}
82
83pub mod display {
84    use bitflags::bitflags;
85    use serde::Deserialize;
86
87    bitflags! {
88        /// The Display interface covers a number of feature spaces, each handled by a different
89        /// entity dependency. The flags below allow the scope of these features to be specified by
90        /// the interface.
91        #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
92        pub struct InterfaceFlags: u64 {
93            const BASE = 1 << 0;
94        }
95    }
96
97    #[derive(Copy, Clone, Deserialize, PartialEq, Eq, Hash, Debug)]
98    pub enum InterfaceSpec {
99        Base,
100    }
101
102    impl From<Vec<InterfaceSpec>> for InterfaceFlags {
103        fn from(variants: Vec<InterfaceSpec>) -> Self {
104            variants.into_iter().fold(InterfaceFlags::empty(), |flags, variant| {
105                flags
106                    | match variant {
107                        InterfaceSpec::Base => InterfaceFlags::BASE,
108                    }
109            })
110        }
111    }
112}