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_DALTONIZATION_STATE, 43 CONIFG_CLICK_RESPONSE_TIME, 44 CONFIG_IGNORE_REPEAT_CLICK_STATE, 45 CONFIG_IGNORE_REPEAT_CLICK_TIME, 46 CONFIG_SHORT_KEY_MULTI_TARGET, 47 CONFIG_ID_MAX, 48 }; 49 50 struct ConfigValue { 51 bool highContrastText; 52 bool invertColor; 53 bool animationOff; 54 bool screenMagnifier; 55 bool audioMono; 56 bool mouseKey; 57 bool shortkey; 58 bool captionState; 59 bool daltonizationState; 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 CLICK_RESPONSE_TIME clickResponseTime; 68 bool ignoreRepeatClickState; 69 IGNORE_REPEAT_CLICK_TIME ignoreRepeatClickTime; 70 std::vector<std::string> shortkeyMultiTarget; 71 }; 72 73 class AccessibilityConfigObserver { 74 public: 75 /** 76 * @brief Destruct 77 */ 78 virtual ~AccessibilityConfigObserver() = default; 79 80 /** 81 * @brief Called when the config value changed. 82 * @param id the id of config. 83 * @param value the value of config. 84 */ 85 virtual void OnConfigChanged(const CONFIG_ID id, const ConfigValue &value) = 0; 86 }; 87 88 class AccessibilityEnableAbilityListsObserver { 89 public: 90 /** 91 * @brief Destruct 92 */ 93 virtual ~AccessibilityEnableAbilityListsObserver() = default; 94 95 /** 96 * @brief Called when the enable ability lists changed. 97 */ 98 virtual void OnEnableAbilityListsStateChanged() = 0; 99 }; 100 101 class AccessibilityConfig { 102 ACCESSIBILITY_DECLARE_SINGLETON(AccessibilityConfig) 103 public: 104 /** 105 * @brief Initialize the run context. 106 * @return Return true if successfully, else return false. 107 */ 108 bool InitializeContext(); 109 110 /** 111 * @brief Subscribes to accessibility config value. 112 * @param id the config id which is observed. 113 * @param observer Indicates the observer for listening to accessibility 114 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 115 */ 116 Accessibility::RetError SubscribeConfigObserver(const CONFIG_ID id, 117 const std::shared_ptr<AccessibilityConfigObserver> &observer, const bool retFlag = true); 118 119 /** 120 * @brief Unsubscribe the accessibility config value observer. 121 * @param id the id which is observed. 122 * @param observer Indicates the registered accessibility config observer. 123 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 124 */ 125 Accessibility::RetError UnsubscribeConfigObserver(const CONFIG_ID id, 126 const std::shared_ptr<AccessibilityConfigObserver> &observer); 127 128 /** 129 * @brief Subscribes the observer of enable Ability lists 130 * @param observer Indicates the observer for listening to enable Ability lists 131 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 132 */ 133 Accessibility::RetError SubscribeEnableAbilityListsObserver( 134 const std::shared_ptr<AccessibilityEnableAbilityListsObserver> &observer); 135 136 /** 137 * @brief Unsubscribe the observer of enable Ability lists 138 * @param observer Indicates the observer for listening to enable Ability lists 139 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 140 */ 141 Accessibility::RetError UnsubscribeEnableAbilityListsObserver( 142 const std::shared_ptr<AccessibilityEnableAbilityListsObserver> &observer); 143 144 /** 145 * @brief Enabled specified abilities 146 * @param name The string formatted by 'bundleName/abilityName'. 147 * @param capabilities The capabilities you permit. 148 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 149 */ 150 Accessibility::RetError EnableAbility(const std::string &name, const uint32_t capabilities); 151 152 /** 153 * @brief Disabled specified ability 154 * @param name The string formatted by 'bundleName/abilityName'. 155 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 156 */ 157 Accessibility::RetError DisableAbility(const std::string &name); 158 159 /** 160 * @brief Set whether to enable the magnification function 161 * @param state true:enable magnification function; false:disable magnification function 162 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 163 */ 164 Accessibility::RetError SetScreenMagnificationState(const bool state); 165 166 /** 167 * @brief Set whether to enable the function of using short key to open accessibility ability 168 * @param state true:enable short key function; false:disable short key function 169 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 170 */ 171 Accessibility::RetError SetShortKeyState(const bool state); 172 173 /** 174 * @brief Set whether to enable the mouse key function 175 * @param state true:enable mouse key function; false:disable mouse key function 176 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 177 */ 178 Accessibility::RetError SetMouseKeyState(const bool state); 179 180 /** 181 * @brief Set whether to enable the caption function 182 * @param state true:enable caption function; false:disable caption function 183 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 184 */ 185 Accessibility::RetError SetCaptionsState(const bool state); 186 187 /** 188 * @brief Set caption properties 189 * @param caption caption properties 190 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 191 */ 192 Accessibility::RetError SetCaptionsProperty(const CaptionProperty &caption); 193 194 /** 195 * @brief Set the time for the cursor to stop for the mouse to automatically perform the click action 196 * @param time The valid time is 1000ms~5000ms, otherwise the automatic mouse click action will not be enabled 197 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 198 */ 199 Accessibility::RetError SetMouseAutoClick(const int32_t time); 200 201 /** 202 * @brief Set the name of the accessibility ability to be opened by the short key 203 * @param name name The string formatted by 'bundleName/abilityName' 204 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 205 */ 206 Accessibility::RetError SetShortkeyTarget(const std::string &name); 207 208 /** 209 * @brief Set the name of the multi accessibility ability to be opened by the short key 210 * @param name name The vector string formatted by 'bundleName/abilityName' 211 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 212 */ 213 Accessibility::RetError SetShortkeyMultiTarget(const std::vector<std::string> &name); 214 215 /** 216 * @brief Set whether to enable the high-contrast text function 217 * @param state true:enable high-contrast text function; false:disable high-contrast text function 218 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 219 */ 220 Accessibility::RetError SetHighContrastTextState(bool state); 221 222 /** 223 * @brief Set whether to enable the invert color function 224 * @param state true:enable invert color function; false:disable invert color function 225 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 226 */ 227 Accessibility::RetError SetInvertColorState(const bool state); 228 229 /** 230 * @brief Set whether to enable the daltonization 231 * @param state true:enable daltonization function; false:disable daltonization function 232 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 233 */ 234 Accessibility::RetError SetDaltonizationState(bool state); 235 236 /** 237 * @brief Set daltonization color filter 238 * @param type Daltonization color filter type 239 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 240 */ 241 Accessibility::RetError SetDaltonizationColorFilter(const DALTONIZATION_TYPE type); 242 243 /** 244 * @brief Set content duration 245 * @param timer duration 246 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 247 */ 248 Accessibility::RetError SetContentTimeout(const uint32_t timer); 249 250 /** 251 * @brief Set whether to turn off animation 252 * @param state true:turn off animation; false:turn on animation 253 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 254 */ 255 Accessibility::RetError SetAnimationOffState(const bool state); 256 257 /** 258 * @brief Set brightness discount 259 * @param brightness The discount of brightness 260 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 261 */ 262 Accessibility::RetError SetBrightnessDiscount(const float brightness); 263 264 /** 265 * @brief Set whether to enable audio mono 266 * @param state true:enable audio mono; false:disable audio mono 267 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 268 */ 269 Accessibility::RetError SetAudioMonoState(const bool state); 270 271 /** 272 * @brief Set audio balance 273 * @param balance The balance of audio 274 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 275 */ 276 Accessibility::RetError SetAudioBalance(const float balance); 277 278 /** 279 * @brief Set click response time 280 * @param time The value of the click response time 281 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 282 */ 283 Accessibility::RetError SetClickResponseTime(const CLICK_RESPONSE_TIME time); 284 285 /** 286 * @brief Set ignore repeat click state 287 * @param state The value of the ignore repeat click state 288 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 289 */ 290 Accessibility::RetError SetIgnoreRepeatClickState(const bool state); 291 292 /** 293 * @brief Set ignore repeat click time 294 * @param time The value of the ignore repeat click time 295 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 296 */ 297 Accessibility::RetError SetIgnoreRepeatClickTime(const IGNORE_REPEAT_CLICK_TIME time); 298 299 /** 300 * @brief Get the status of whether the magnification function is enabled 301 * @param state(out) true:the magnification function is enabled; false:the magnification function is disabled 302 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 303 */ 304 Accessibility::RetError GetScreenMagnificationState(bool &state) const; 305 306 /** 307 * @brief Get the status of whether the use of short key to open accessibility ability is enabled 308 * @param state(out) true:the short key is enabled; false:the short key is disabled 309 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 310 */ 311 Accessibility::RetError GetShortKeyState(bool &state) const; 312 313 /** 314 * @brief Get the status of whether the mouse key function is enabled 315 * @param state(out) true:the mouse key function is enabled; false:the mouse key function is disabled 316 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 317 */ 318 Accessibility::RetError GetMouseKeyState(bool &state) const; 319 320 /** 321 * @brief Get the status of whether the caption function is enabled 322 * @param state(out) true:the caption function is enabled; false:the caption function is disabled 323 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 324 */ 325 Accessibility::RetError GetCaptionsState(bool &state) const; 326 327 /** 328 * @brief Get caption properties 329 * @param caption(out) caption properties 330 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 331 */ 332 Accessibility::RetError GetCaptionsProperty(CaptionProperty &caption) const; 333 334 /** 335 * @brief Get the time for the cursor to stop for the mouse to automatically perform the click action 336 * @param time(out) the time for the cursor to stop for the mouse to automatically perform the click action 337 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 338 */ 339 Accessibility::RetError GetMouseAutoClick(int32_t &time) const; 340 341 /** 342 * @brief Get the name of the accessibility ability to be opened by the short key 343 * @param name(out) The string formatted by 'bundleName/abilityName' 344 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 345 */ 346 Accessibility::RetError GetShortkeyTarget(std::string &name) const; 347 348 /** 349 * @brief Get the name of the multi accessibility ability to be opened by the short key 350 * @param name(out) The vector string formatted by 'bundleName/abilityName' 351 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 352 */ 353 Accessibility::RetError GetShortkeyMultiTarget(std::vector<std::string> &name) const; 354 355 /** 356 * @brief Get the status of whether the invert color function is enabled 357 * @param state(out) true:the invert color function is enabled; false:the invert color function is disabled 358 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 359 */ 360 Accessibility::RetError GetInvertColorState(bool &state) const; 361 362 /** 363 * @brief Get the status of whether the high-contrast text function is enabled 364 * @param state(out) true:the high-contrast text function is enabled; 365 * false:the high-contrast text function is disabled 366 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 367 */ 368 Accessibility::RetError GetHighContrastTextState(bool &state) const; 369 370 /** 371 * @brief Get the status of whether the daltonization function is enabled 372 * @param state(out) true:the daltonization function is enabled; 373 * false:the daltonization is disabled 374 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 375 */ 376 Accessibility::RetError GetDaltonizationState(bool &state) const; 377 378 /** 379 * @brief Get daltonization color filter 380 * @param type(out) Daltonization color filter type 381 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 382 */ 383 Accessibility::RetError GetDaltonizationColorFilter(DALTONIZATION_TYPE &type) const; 384 385 /** 386 * @brief Get content duration 387 * @param timer(out) duration 388 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 389 */ 390 Accessibility::RetError GetContentTimeout(uint32_t &timer) const; 391 392 /** 393 * @brief Get the status of whether animation is disabled 394 * @param state(out) true:animation is disabled; false:animation is enabled 395 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 396 */ 397 Accessibility::RetError GetAnimationOffState(bool &state) const; 398 399 /** 400 * @brief Get brightness discount parameter 401 * @param brightness(out) The discount parameter of brightness 402 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 403 */ 404 Accessibility::RetError GetBrightnessDiscount(float &brightness) const; 405 406 /** 407 * @brief Get the status of whether the audio mono is enabled 408 * @param state(out) true:audio mono is enabled; false:audio mono is disabled 409 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 410 */ 411 Accessibility::RetError GetAudioMonoState(bool &state) const; 412 413 /** 414 * @brief Get the value of the audio balance 415 * @param balance(out) The value of the audio balance 416 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 417 */ 418 Accessibility::RetError GetAudioBalance(float &balance) const; 419 420 /** 421 * @brief Get the value of the click response time 422 * @param time(out) The value of the click response time 423 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 424 */ 425 Accessibility::RetError GetClickResponseTime(CLICK_RESPONSE_TIME &time) const; 426 427 /** 428 * @brief Get the value of the ignore repeat click state 429 * @param time(out) The value of the ignore repeat click state 430 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 431 */ 432 Accessibility::RetError GetIgnoreRepeatClickState(bool &state) const; 433 434 /** 435 * @brief Get the value of the ignore repeat click time 436 * @param time(out) The value of the ignore repeat click time 437 * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure. 438 */ 439 Accessibility::RetError GetIgnoreRepeatClickTime(IGNORE_REPEAT_CLICK_TIME &time) const; 440 441 private: 442 class Impl; 443 std::unique_ptr<Impl> pImpl_; 444 }; 445 } // namespace AccessibilityConfig 446 } // namespace OHOS 447 #endif // ACCESSIBILITY_CONFIG_H 448