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