settings_media_buttons/
lib.rs

1// Copyright 2025 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 fidl_fuchsia_ui_input::MediaButtonsEvent;
6
7/// Setting service internal representation of hw media buttons. Used to send
8/// OnButton events in the service.
9#[derive(PartialEq, Eq, Copy, Clone, Debug)]
10pub struct MediaButtons {
11    pub mic_mute: Option<bool>,
12    pub camera_disable: Option<bool>,
13}
14
15impl MediaButtons {
16    fn new() -> Self {
17        Self { mic_mute: None, camera_disable: None }
18    }
19
20    pub fn set_mic_mute(&mut self, mic_mute: Option<bool>) {
21        self.mic_mute = mic_mute;
22    }
23
24    pub fn set_camera_disable(&mut self, camera_disable: Option<bool>) {
25        self.camera_disable = camera_disable;
26    }
27}
28
29impl From<MediaButtonsEvent> for MediaButtons {
30    fn from(event: MediaButtonsEvent) -> Self {
31        let mut buttons = MediaButtons::new();
32
33        if let Some(mic_mute) = event.mic_mute {
34            buttons.set_mic_mute(Some(mic_mute));
35        }
36        if let Some(camera_disable) = event.camera_disable {
37            buttons.set_camera_disable(Some(camera_disable));
38        }
39
40        buttons
41    }
42}
43
44#[derive(PartialEq, Clone, Debug)]
45pub enum Event {
46    OnButton(MediaButtons),
47}
48
49impl From<MediaButtons> for Event {
50    fn from(button_types: MediaButtons) -> Self {
51        Self::OnButton(button_types)
52    }
53}
54
55// Only used for tests
56/// Builder to simplify construction of fidl_fuchsia_ui_input::MediaButtonsEvent.
57/// # Example usage:
58/// ```
59/// MediaButtonsEventBuilder::new().set_mic_mute(true).build();
60/// ```
61pub struct MediaButtonsEventBuilder {
62    mic_mute: bool,
63    camera_disable: bool,
64}
65
66impl MediaButtonsEventBuilder {
67    #[allow(clippy::new_without_default)]
68    pub fn new() -> Self {
69        // Create with defaults.
70        Self { mic_mute: false, camera_disable: false }
71    }
72
73    pub fn build(self) -> MediaButtonsEvent {
74        MediaButtonsEvent {
75            mic_mute: Some(self.mic_mute),
76            pause: Some(false),
77            camera_disable: Some(self.camera_disable),
78            ..Default::default()
79        }
80    }
81
82    pub fn set_mic_mute(mut self, mic_mute: bool) -> Self {
83        self.mic_mute = mic_mute;
84        self
85    }
86
87    pub fn set_camera_disable(mut self, camera_disable: bool) -> Self {
88        self.camera_disable = camera_disable;
89        self
90    }
91}