• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ACCESSIBILITY_CONFIG_H
17 #define ACCESSIBILITY_CONFIG_H
18 
19 #include <memory>
20 #include "accessibility_caption.h"
21 #include "accessibility_singleton.h"
22 
23 namespace OHOS {
24 namespace AccessibilityConfig {
25 enum CONFIG_ID : int32_t {
26     CONFIG_HIGH_CONTRAST_TEXT = 0,
27     CONFIG_INVERT_COLOR,
28     CONFIG_DALTONIZATION_COLOR_FILTER,
29     CONFIG_CONTENT_TIMEOUT,
30     CONFIG_ANIMATION_OFF,
31     CONFIG_BRIGHTNESS_DISCOUNT,
32     CONFIG_AUDIO_MONO,
33     CONFIG_AUDIO_BALANCE,
34     CONFIG_MOUSE_KEY,
35     CONFIG_SHORT_KEY,
36     CONFIG_CAPTION_STATE,
37     CONFIG_CAPTION_STYLE,
38     CONFIG_SCREEN_MAGNIFICATION,
39     CONFIG_SHORT_KEY_TARGET,
40     CONFIG_MOUSE_AUTOCLICK,
41     CONFIG_ID_MAX,
42 };
43 
44 enum DALTONIZATION_TYPE : uint32_t {
45     Normal = 0,
46     Protanomaly,
47     Deuteranomaly,
48     Tritanomaly,
49 };
50 
51 struct ConfigValue {
52     bool highContrastText;
53     bool invertColor;
54     bool animationOff;
55     bool screenMagnifier;
56     bool audioMono;
57     bool mouseKey;
58     bool shortkey;
59     bool captionState;
60     DALTONIZATION_TYPE daltonizationColorFilter;
61     uint32_t contentTimeout;
62     int32_t mouseAutoClick;
63     float brightnessDiscount;
64     float audioBalance;
65     std::string shortkey_target;
66     CaptionProperty captionStyle;
67 };
68 
69 class AccessibilityConfigObserver {
70 public:
71     /**
72      * @brief Destruct
73      */
74     virtual ~AccessibilityConfigObserver() = default;
75 
76     /**
77      * @brief Called when the config value changed.
78      * @param id the id of config.
79      * @param value the value of config.
80      */
81     virtual void OnConfigChanged(const CONFIG_ID id, const ConfigValue &value) = 0;
82 };
83 
84 class AccessibilityEnableAbilityListsObserver {
85 public:
86     /**
87      * @brief Destruct
88      */
89     virtual ~AccessibilityEnableAbilityListsObserver() = default;
90 
91     /**
92      * @brief Called when the enable ability lists changed.
93      */
94     virtual void OnEnableAbilityListsStateChanged() = 0;
95 };
96 
97 class AccessibilityConfig {
98     ACCESSIBILITY_DECLARE_SINGLETON(AccessibilityConfig)
99 public:
100     /**
101      * @brief Initialize the run context.
102      * @return Return true if successfully, else return false.
103      */
104     bool InitializeContext();
105 
106     /**
107      * @brief Subscribes to accessibility config value.
108      * @param id  the config id which is observed.
109      * @param observer Indicates the observer for listening to accessibility
110      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
111      */
112     Accessibility::RetError SubscribeConfigObserver(const CONFIG_ID id,
113         const std::shared_ptr<AccessibilityConfigObserver> &observer, const bool retFlag = true);
114 
115     /**
116      * @brief Unsubscribe the accessibility config value observer.
117      * @param id  the id which is observed.
118      * @param observer Indicates the registered accessibility config observer.
119      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
120      */
121     Accessibility::RetError UnsubscribeConfigObserver(const CONFIG_ID id,
122         const std::shared_ptr<AccessibilityConfigObserver> &observer);
123 
124     /**
125      * @brief Subscribes the observer of enable Ability lists
126      * @param observer Indicates the observer for listening to enable Ability lists
127      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
128      */
129     Accessibility::RetError SubscribeEnableAbilityListsObserver(
130         const std::shared_ptr<AccessibilityEnableAbilityListsObserver> &observer);
131 
132     /**
133      * @brief Unsubscribe the observer of enable Ability lists
134      * @param observer Indicates the observer for listening to enable Ability lists
135      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
136      */
137     Accessibility::RetError UnsubscribeEnableAbilityListsObserver(
138         const std::shared_ptr<AccessibilityEnableAbilityListsObserver> &observer);
139 
140     /**
141      * @brief Enabled specified abilities
142      * @param name The string formatted by 'bundleName/abilityName'.
143      * @param capabilities The capabilities you permit.
144      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
145      */
146     Accessibility::RetError EnableAbility(const std::string &name, const uint32_t capabilities);
147 
148     /**
149      * @brief Disabled specified ability
150      * @param name The string formatted by 'bundleName/abilityName'.
151      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
152      */
153     Accessibility::RetError DisableAbility(const std::string &name);
154 
155     /**
156      * @brief Set whether to enable the magnification function
157      * @param state true:enable magnification function; false:disable magnification function
158      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
159      */
160     Accessibility::RetError SetScreenMagnificationState(const bool state);
161 
162     /**
163      * @brief Set whether to enable the function of using short key to open accessibility ability
164      * @param state true:enable short key function; false:disable short key function
165      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
166      */
167     Accessibility::RetError SetShortKeyState(const bool state);
168 
169     /**
170      * @brief Set whether to enable the mouse key function
171      * @param state true:enable mouse key function; false:disable mouse key function
172      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
173      */
174     Accessibility::RetError SetMouseKeyState(const bool state);
175 
176     /**
177      * @brief Set whether to enable the caption function
178      * @param state true:enable caption function; false:disable caption function
179      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
180      */
181     Accessibility::RetError SetCaptionsState(const bool state);
182 
183     /**
184      * @brief Set caption properties
185      * @param caption caption properties
186      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
187      */
188     Accessibility::RetError SetCaptionsProperty(const CaptionProperty &caption);
189 
190     /**
191      * @brief Set the time for the cursor to stop for the mouse to automatically perform the click action
192      * @param time The valid time is 1000ms~5000ms, otherwise the automatic mouse click action will not be enabled
193      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
194      */
195     Accessibility::RetError SetMouseAutoClick(const int32_t time);
196 
197     /**
198      * @brief Set the name of the accessibility ability to be opened by the short key
199      * @param name name The string formatted by 'bundleName/abilityName'
200      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
201      */
202     Accessibility::RetError SetShortkeyTarget(const std::string &name);
203 
204     /**
205      * @brief Set whether to enable the high-contrast text function
206      * @param state true:enable high-contrast text function; false:disable high-contrast text function
207      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
208      */
209     Accessibility::RetError SetHighContrastTextState(bool state);
210 
211     /**
212      * @brief Set whether to enable the invert color function
213      * @param state true:enable invert color function; false:disable invert color function
214      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
215      */
216     Accessibility::RetError SetInvertColorState(const bool state);
217 
218     /**
219      * @brief Set daltonization color filter
220      * @param type Daltonization color filter type
221      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
222      */
223     Accessibility::RetError SetDaltonizationColorFilter(const DALTONIZATION_TYPE type);
224 
225     /**
226      * @brief Set content duration
227      * @param timer duration
228      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
229      */
230     Accessibility::RetError SetContentTimeout(const uint32_t timer);
231 
232     /**
233      * @brief Set whether to turn off animation
234      * @param state true:turn off animation; false:turn on animation
235      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
236      */
237     Accessibility::RetError SetAnimationOffState(const bool state);
238 
239     /**
240      * @brief Set brightness discount
241      * @param brightness The discount of brightness
242      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
243      */
244     Accessibility::RetError SetBrightnessDiscount(const float brightness);
245 
246     /**
247      * @brief Set whether to enable audio mono
248      * @param state true:enable audio mono; false:disable audio mono
249      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
250      */
251     Accessibility::RetError SetAudioMonoState(const bool state);
252 
253     /**
254      * @brief Set audio balance
255      * @param balance The balance of audio
256      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
257      */
258     Accessibility::RetError SetAudioBalance(const float balance);
259 
260     /**
261      * @brief Get the status of whether the magnification function is enabled
262      * @param state(out) true:the magnification function is enabled; false:the magnification function is disabled
263      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
264      */
265     Accessibility::RetError GetScreenMagnificationState(bool &state) const;
266 
267     /**
268      * @brief Get the status of whether the use of short key to open accessibility ability is enabled
269      * @param state(out) true:the short key is enabled; false:the short key is disabled
270      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
271      */
272     Accessibility::RetError GetShortKeyState(bool &state) const;
273 
274     /**
275      * @brief Get the status of whether the mouse key function is enabled
276      * @param state(out) true:the mouse key function is enabled; false:the mouse key function is disabled
277      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
278      */
279     Accessibility::RetError GetMouseKeyState(bool &state) const;
280 
281     /**
282      * @brief Get the status of whether the caption function is enabled
283      * @param state(out) true:the caption function is enabled; false:the caption function is disabled
284      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
285      */
286     Accessibility::RetError GetCaptionsState(bool &state) const;
287 
288     /**
289      * @brief Get caption properties
290      * @param caption(out) caption properties
291      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
292      */
293     Accessibility::RetError GetCaptionsProperty(CaptionProperty &caption) const;
294 
295     /**
296      * @brief Get the time for the cursor to stop for the mouse to automatically perform the click action
297      * @param time(out) the time for the cursor to stop for the mouse to automatically perform the click action
298      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
299      */
300     Accessibility::RetError GetMouseAutoClick(int32_t &time) const;
301 
302     /**
303      * @brief Get the name of the accessibility ability to be opened by the short key
304      * @param name(out) The string formatted by 'bundleName/abilityName'
305      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
306      */
307     Accessibility::RetError GetShortkeyTarget(std::string &name) const;
308 
309     /**
310      * @brief Get the status of whether the invert color function is enabled
311      * @param state(out) true:the invert color function is enabled; false:the invert color function is disabled
312      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
313      */
314     Accessibility::RetError GetInvertColorState(bool &state) const;
315 
316     /**
317      * @brief Get the status of whether the high-contrast text function is enabled
318      * @param state(out) true:the high-contrast text function is enabled;
319      *                   false:the high-contrast text function is disabled
320      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
321      */
322     Accessibility::RetError GetHighContrastTextState(bool &state) const;
323 
324     /**
325      * @brief Get daltonization color filter
326      * @param type(out) Daltonization color filter type
327      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
328      */
329     Accessibility::RetError GetDaltonizationColorFilter(DALTONIZATION_TYPE &type) const;
330 
331     /**
332      * @brief Get content duration
333      * @param timer(out) duration
334      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
335      */
336     Accessibility::RetError GetContentTimeout(uint32_t &timer) const;
337 
338     /**
339      * @brief Get the status of whether animation is disabled
340      * @param state(out) true:animation is disabled; false:animation is enabled
341      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
342      */
343     Accessibility::RetError GetAnimationOffState(bool &state) const;
344 
345     /**
346      * @brief Get brightness discount parameter
347      * @param brightness(out) The discount parameter of brightness
348      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
349      */
350     Accessibility::RetError GetBrightnessDiscount(float &brightness) const;
351 
352     /**
353      * @brief Get the status of whether the audio mono is enabled
354      * @param state(out) true:audio mono is enabled; false:audio mono is disabled
355      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
356      */
357     Accessibility::RetError GetAudioMonoState(bool &state) const;
358 
359     /**
360      * @brief Get the value of the audio balance
361      * @param balance(out) The value of the audio balance
362      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
363      */
364     Accessibility::RetError GetAudioBalance(float &balance) const;
365 
366 private:
367     class Impl;
368     std::unique_ptr<Impl> pImpl_;
369 };
370 } // namespace AccessibilityConfig
371 } // namespace OHOS
372 #endif // ACCESSIBILITY_CONFIG_H
373