• 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 #include "accessibility_settings_config.h"
17 #include "hilog_wrapper.h"
18 #include "system_ability_definition.h"
19 #include "utils.h"
20 #include "accessibility_setting_provider.h"
21 
22 namespace OHOS {
23 namespace Accessibility {
24 namespace {
25     constexpr uint32_t DEFAULT_COLOR = 0xff000000;
26     const int32_t DEFAULT_SCALE = 100;
27     const int32_t SHORT_KEY_TIMEOUT_AFTER_USE = 1000; // ms
28     const int32_t SHORT_KEY_TIMEOUT_BEFORE_USE = 3000; // ms
29     const std::string ACCESSIBILITY = "accessibility";
30     const std::string TOUCH_GUIDE_STATE = "touch_guide_state";
31     const std::string GESTURE_KEY = "gesture_state";
32     const std::string CAPTION_KEY = "caption_state";
33     const std::string KEYEVENT_OBSERVER = "keyevent_observer";
34     const std::string SCREEN_MAGNIFICATION_KEY = "accessibility_display_magnification_enabled";
35     const std::string SCREEN_MAGNIFICATION_TYPE = "accessibility_magnification_capability";
36     const std::string MOUSEKEY = "mousekey";
37     const std::string HIGH_CONTRAST_TEXT_KEY = "high_text_contrast_enabled";
38     const std::string DALTONIZATION_STATE = "accessibility_display_daltonizer_enabled";
39     const std::string INVERT_COLOR_KEY = "accessibility_display_inversion_enabled";
40     const std::string ANIMATION_OFF_KEY = "animation_off";
41     const std::string AUDIO_MONO_KEY = "master_mono";
42     const std::string IGNORE_REPEAT_CLICK_SWITCH = "ignore_repeat_click_switch";
43     const std::string SHORTCUT_ENABLED = "accessibility_shortcut_enabled";
44     const std::string SHORTCUT_SERVICE = "accessibility_shortcut_target_service";
45     const std::string CLICK_RESPONCE_TIME = "click_response_time";
46     const std::string IGNORE_REPEAT_CLICK_TIME = "ignore_repeat_click_time";
47     const std::string DALTONIZATION_COLOR_FILTER_KEY = "accessibility_display_daltonizer";
48     const std::string CONTENT_TIMEOUT_KEY = "accessibility_content_timeout";
49     const std::string BRIGHTNESS_DISCOUNT_KEY = "accessibility_brightness_discount";
50     const std::string AUDIO_BALANCE_KEY = "master_balance";
51     const std::string FONT_FAMILY = "accessibility_font_family";
52     const std::string FONT_COLOR = "accessibility_font_color";
53     const std::string FONT_EDGE_TYPE = "accessibility_font_edge_type";
54     const std::string BACKGROUND_COLOR = "accessibility_background_color";
55     const std::string WINDOW_COLOR = "accessibility_window_color";
56     const std::string FONT_SCALE = "accessibility_font_scale";
57     const std::string ENABLED_ACCESSIBILITY_SERVICES = "enabled_accessibility_services";
58     const std::string SHORTCUT_ENABLED_ON_LOCK_SCREEN = "accessibility_shortcut_enabled_on_lock_screen";
59     const std::string SHORTCUT_TIMEOUT = "accessibility_shortcut_timeout";
60     const std::string ACCESSIBILITY_CLONE_FLAG = "accessibility_config_clone";
61     const std::string SCREENREADER_TAG = "screenreader";
62     const std::string SCREEN_READER_BUNDLE_ABILITY_NAME = "com.huawei.hmos.screenreader/AccessibilityExtAbility";
63     constexpr int DOUBLE_CLICK_RESPONSE_TIME_MEDIUM = 300;
64     constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORT = 400;
65     constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_MEDIUM = 700;
66     constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG = 1000;
67     constexpr int DISPLAY_DALTONIZER_GREEN = 12;
68     constexpr int DISPLAY_DALTONIZER_RED = 11;
69     constexpr int DISPLAY_DALTONIZER_BLUE = 13;
70 } // namespace
AccessibilitySettingsConfig(int32_t id)71 AccessibilitySettingsConfig::AccessibilitySettingsConfig(int32_t id)
72 {
73     HILOG_DEBUG("id = [%{public}d]", id);
74     accountId_ = id;
75 }
76 
SetEnabled(const bool state)77 RetError AccessibilitySettingsConfig::SetEnabled(const bool state)
78 {
79     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
80     enabled_ = state;
81     return SetConfigState(ACCESSIBILITY, state);
82 }
83 
SetTouchGuideState(const bool state)84 RetError AccessibilitySettingsConfig::SetTouchGuideState(const bool state)
85 {
86     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
87     eventTouchGuideState_ = state;
88     return SetConfigState(TOUCH_GUIDE_STATE, state);
89 }
90 
SetGestureState(const bool state)91 RetError AccessibilitySettingsConfig::SetGestureState(const bool state)
92 {
93     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
94     gesturesSimulation_ = state;
95     return SetConfigState(GESTURE_KEY, state);
96 }
97 
SetKeyEventObserverState(const bool state)98 RetError AccessibilitySettingsConfig::SetKeyEventObserverState(const bool state)
99 {
100     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
101     filteringKeyEvents_ = state;
102     return SetConfigState(KEYEVENT_OBSERVER, state);
103 }
104 
SetCaptionState(const bool state)105 RetError AccessibilitySettingsConfig::SetCaptionState(const bool state)
106 {
107     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
108     isCaptionState_ = state;
109     return SetConfigState(CAPTION_KEY, state);
110 }
111 
SetScreenMagnificationState(const bool state)112 RetError AccessibilitySettingsConfig::SetScreenMagnificationState(const bool state)
113 {
114     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
115     isScreenMagnificationState_ = state;
116     return RET_OK;
117 }
118 
SetScreenMagnificationType(const uint32_t type)119 RetError AccessibilitySettingsConfig::SetScreenMagnificationType(const uint32_t type)
120 {
121     HILOG_DEBUG("screenMagnificationType = [%{public}u]", type);
122     screenMagnificationType_ = type;
123     return RET_OK;
124 }
125 
SetShortKeyState(const bool state)126 RetError AccessibilitySettingsConfig::SetShortKeyState(const bool state)
127 {
128     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
129     isShortKeyState_ = state;
130     return SetConfigState(SHORTCUT_ENABLED, state);
131 }
132 
SetShortKeyOnLockScreenState(const bool state)133 RetError AccessibilitySettingsConfig::SetShortKeyOnLockScreenState(const bool state)
134 {
135     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
136     isShortKeyEnabledOnLockScreen_ = state;
137     return SetConfigState(SHORTCUT_ENABLED_ON_LOCK_SCREEN, state);
138 }
139 
SetShortKeyTimeout(const int32_t time)140 RetError AccessibilitySettingsConfig::SetShortKeyTimeout(const int32_t time)
141 {
142     HILOG_DEBUG("time = [%{public}u]", time);
143     shortKeyTimeout_ = time;
144     if (!datashare_) {
145         return RET_ERR_NULLPTR;
146     }
147 
148     return datashare_->PutIntValue(SHORTCUT_TIMEOUT, static_cast<int32_t>(time));
149 }
150 
SetStartFromAtoHosState(const bool state)151 RetError AccessibilitySettingsConfig::SetStartFromAtoHosState(const bool state)
152 {
153     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
154     if (!datashare_) {
155         return RET_ERR_NULLPTR;
156     }
157     return datashare_->PutBoolValue("AccessibilityStartFromAtoHos", state);
158 }
159 
SetMouseKeyState(const bool state)160 RetError AccessibilitySettingsConfig::SetMouseKeyState(const bool state)
161 {
162     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
163     isMouseKeyState_ = state;
164     return SetConfigState(MOUSEKEY, state);
165 }
166 
SetMouseAutoClick(const int32_t time)167 RetError AccessibilitySettingsConfig::SetMouseAutoClick(const int32_t time)
168 {
169     HILOG_DEBUG("time = [%{public}d]", time);
170     if (!datashare_) {
171         return RET_ERR_NULLPTR;
172     }
173     mouseAutoClick_ = time;
174     return datashare_->PutIntValue("MouseAutoClick", time);
175 }
176 
SetShortkeyTarget(const std::string & name)177 RetError AccessibilitySettingsConfig::SetShortkeyTarget(const std::string &name)
178 {
179     HILOG_DEBUG("name = [%{public}s]", name.c_str());
180     if (!datashare_) {
181         return RET_ERR_NULLPTR;
182     }
183 
184     shortkeyTarget_ = name;
185     return datashare_->PutStringValue("ShortkeyTarget", name);
186 }
187 
SetShortkeyMultiTarget(const std::vector<std::string> & name)188 RetError AccessibilitySettingsConfig::SetShortkeyMultiTarget(const std::vector<std::string> &name)
189 {
190     HILOG_DEBUG();
191     std::set<std::string> targets;
192     std::for_each(name.begin(), name.end(), [&](const std::string &target) {
193         if (targets.find(target) == targets.end()) {
194             targets.insert(target);
195         }
196     });
197     std::lock_guard<std::mutex> lock(interfaceMutex_);
198     shortkeyMultiTarget_ = std::vector<std::string>(targets.begin(), targets.end());
199     if (!datashare_) {
200         return RET_ERR_NULLPTR;
201     }
202 
203     std::string stringOut = "";
204     Utils::VectorToString(shortkeyMultiTarget_, stringOut);
205     return datashare_->PutStringValue(SHORTCUT_SERVICE, stringOut);
206 }
207 
SetShortkeyMultiTargetInPkgRemove(const std::string & name)208 RetError AccessibilitySettingsConfig::SetShortkeyMultiTargetInPkgRemove(const std::string &name)
209 {
210     HILOG_DEBUG();
211     if (!datashare_) {
212         return RET_ERR_NULLPTR;
213     }
214     RetError rtn = RET_OK;
215 
216     for (auto iter = shortkeyMultiTarget_.begin(); iter != shortkeyMultiTarget_.end(); ++iter) {
217         if (*iter == name) {
218             shortkeyMultiTarget_.erase(iter);
219             std::string stringOut = "";
220             Utils::VectorToString(shortkeyMultiTarget_, stringOut);
221             rtn = datashare_->PutStringValue(SHORTCUT_SERVICE, stringOut);
222             break;
223         }
224     }
225     return rtn;
226 }
227 
SetHighContrastTextState(const bool state)228 RetError AccessibilitySettingsConfig::SetHighContrastTextState(const bool state)
229 {
230     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
231     highContrastTextState_ = state;
232     return SetConfigState(HIGH_CONTRAST_TEXT_KEY, state);
233 }
234 
SetInvertColorState(const bool state)235 RetError AccessibilitySettingsConfig::SetInvertColorState(const bool state)
236 {
237     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
238     invertColorState_ = state;
239     return SetConfigState(INVERT_COLOR_KEY, state);
240 }
241 
SetAnimationOffState(const bool state)242 RetError AccessibilitySettingsConfig::SetAnimationOffState(const bool state)
243 {
244     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
245     animationOffState_ = state;
246     return SetConfigState(ANIMATION_OFF_KEY, state);
247 }
248 
SetAudioMonoState(const bool state)249 RetError AccessibilitySettingsConfig::SetAudioMonoState(const bool state)
250 {
251     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
252     audioMonoState_ = state;
253     return SetConfigState(AUDIO_MONO_KEY, state);
254 }
255 
SetDaltonizationState(const bool state)256 RetError AccessibilitySettingsConfig::SetDaltonizationState(const bool state)
257 {
258     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
259     daltonizationState_ = state;
260     return SetConfigState(DALTONIZATION_STATE, state);
261 }
262 
SetDaltonizationColorFilter(const uint32_t filter)263 RetError AccessibilitySettingsConfig::SetDaltonizationColorFilter(const uint32_t filter)
264 {
265     HILOG_DEBUG("filter = [%{public}u]", filter);
266     daltonizationColorFilter_ = filter;
267     if (!datashare_) {
268         return RET_ERR_NULLPTR;
269     }
270 
271     return datashare_->PutIntValue(DALTONIZATION_COLOR_FILTER_KEY, static_cast<int32_t>(filter));
272 }
273 
274 
SetContentTimeout(const uint32_t time)275 RetError AccessibilitySettingsConfig::SetContentTimeout(const uint32_t time)
276 {
277     HILOG_DEBUG("time = [%{public}u]", time);
278     contentTimeout_ = time;
279     if (!datashare_) {
280         return RET_ERR_NULLPTR;
281     }
282 
283     return datashare_->PutIntValue(CONTENT_TIMEOUT_KEY, static_cast<int32_t>(time));
284 }
285 
SetBrightnessDiscount(const float discount)286 RetError AccessibilitySettingsConfig::SetBrightnessDiscount(const float discount)
287 {
288     HILOG_DEBUG("discount = [%{public}f]", discount);
289     brightnessDiscount_ = discount;
290     if (!datashare_) {
291         return RET_ERR_NULLPTR;
292     }
293 
294     return datashare_->PutFloatValue(BRIGHTNESS_DISCOUNT_KEY, discount);
295 }
296 
SetAudioBalance(const float balance)297 RetError AccessibilitySettingsConfig::SetAudioBalance(const float balance)
298 {
299     HILOG_DEBUG("balance = [%{public}f]", balance);
300     audioBalance_ = balance;
301     if (!datashare_) {
302         return RET_ERR_NULLPTR;
303     }
304 
305     return datashare_->PutFloatValue(AUDIO_BALANCE_KEY, balance);
306 }
307 
SetClickResponseTime(const uint32_t time)308 RetError AccessibilitySettingsConfig::SetClickResponseTime(const uint32_t time)
309 {
310     HILOG_DEBUG("clickResponseTime = [%{public}u]", time);
311     clickResponseTime_ = time;
312     if (!datashare_) {
313         return RET_ERR_NULLPTR;
314     }
315 
316     return datashare_->PutIntValue(CLICK_RESPONCE_TIME, time);
317 }
318 
SetIgnoreRepeatClickState(const bool state)319 RetError AccessibilitySettingsConfig::SetIgnoreRepeatClickState(const bool state)
320 {
321     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
322     ignoreRepeatClickState_ = state;
323     return SetConfigState(IGNORE_REPEAT_CLICK_SWITCH, state);
324 }
325 
SetIgnoreRepeatClickTime(const uint32_t time)326 RetError AccessibilitySettingsConfig::SetIgnoreRepeatClickTime(const uint32_t time)
327 {
328     HILOG_DEBUG("ignoreRepeatClickTime = [%{public}u]", time);
329     ignoreRepeatClickTime_ = time;
330     if (!datashare_) {
331         return RET_ERR_NULLPTR;
332     }
333     return datashare_->PutIntValue(IGNORE_REPEAT_CLICK_TIME, time);
334 }
335 
SetCaptionProperty(const AccessibilityConfig::CaptionProperty & caption)336 RetError AccessibilitySettingsConfig::SetCaptionProperty(const AccessibilityConfig::CaptionProperty& caption)
337 {
338     HILOG_DEBUG();
339     captionProperty_ = caption;
340     if (!datashare_) {
341         return RET_ERR_NULLPTR;
342     }
343 
344     datashare_->PutStringValue(FONT_FAMILY, captionProperty_.GetFontFamily());
345     datashare_->PutIntValue(FONT_COLOR, static_cast<int32_t>(captionProperty_.GetFontColor()));
346     datashare_->PutStringValue(FONT_EDGE_TYPE, captionProperty_.GetFontEdgeType());
347     datashare_->PutIntValue(BACKGROUND_COLOR, static_cast<int32_t>(captionProperty_.GetBackgroundColor()));
348     datashare_->PutIntValue(WINDOW_COLOR, static_cast<int32_t>(captionProperty_.GetWindowColor()));
349     datashare_->PutIntValue(FONT_SCALE, captionProperty_.GetFontScale());
350     return RET_OK;
351 }
352 
GetCaptionState() const353 bool AccessibilitySettingsConfig::GetCaptionState() const
354 {
355     return isCaptionState_;
356 }
357 
GetScreenMagnificationState() const358 bool AccessibilitySettingsConfig::GetScreenMagnificationState() const
359 {
360     return isScreenMagnificationState_;
361 }
362 
GetShortKeyState() const363 bool AccessibilitySettingsConfig::GetShortKeyState() const
364 {
365     return isShortKeyState_;
366 }
367 
GetShortKeyOnLockScreenState() const368 bool AccessibilitySettingsConfig::GetShortKeyOnLockScreenState() const
369 {
370     return isShortKeyEnabledOnLockScreen_;
371 }
372 
GetShortKeyTimeout() const373 int32_t AccessibilitySettingsConfig::GetShortKeyTimeout() const
374 {
375     return shortKeyTimeout_;
376 }
377 
GetMouseKeyState() const378 bool AccessibilitySettingsConfig::GetMouseKeyState() const
379 {
380     return isMouseKeyState_;
381 }
382 
GetMouseAutoClick() const383 int32_t AccessibilitySettingsConfig::GetMouseAutoClick() const
384 {
385     return mouseAutoClick_;
386 }
387 
GetShortkeyTarget() const388 const std::string &AccessibilitySettingsConfig::GetShortkeyTarget() const
389 {
390     return shortkeyTarget_;
391 }
392 
GetShortkeyMultiTarget()393 const std::vector<std::string> AccessibilitySettingsConfig::GetShortkeyMultiTarget()
394 {
395     std::lock_guard<std::mutex> lock(interfaceMutex_);
396     std::vector<std::string> rtnVec = shortkeyMultiTarget_;
397     return rtnVec;
398 }
399 
GetHighContrastTextState() const400 bool AccessibilitySettingsConfig::GetHighContrastTextState() const
401 {
402     return highContrastTextState_;
403 }
404 
GetInvertColorState() const405 bool AccessibilitySettingsConfig::GetInvertColorState() const
406 {
407     return invertColorState_;
408 }
409 
GetAnimationOffState() const410 bool AccessibilitySettingsConfig::GetAnimationOffState() const
411 {
412     return animationOffState_;
413 }
414 
GetAudioMonoState() const415 bool AccessibilitySettingsConfig::GetAudioMonoState() const
416 {
417     return audioMonoState_;
418 }
419 
GetDaltonizationState() const420 bool AccessibilitySettingsConfig::GetDaltonizationState() const
421 {
422     return daltonizationState_;
423 }
424 
GetDaltonizationColorFilter() const425 uint32_t AccessibilitySettingsConfig::GetDaltonizationColorFilter() const
426 {
427     return daltonizationColorFilter_;
428 }
429 
GetContentTimeout() const430 uint32_t AccessibilitySettingsConfig::GetContentTimeout() const
431 {
432     return contentTimeout_;
433 }
434 
GetBrightnessDiscount() const435 float AccessibilitySettingsConfig::GetBrightnessDiscount() const
436 {
437     return brightnessDiscount_;
438 }
439 
GetAudioBalance() const440 float AccessibilitySettingsConfig::GetAudioBalance() const
441 {
442     return audioBalance_;
443 }
444 
GetEnabledState() const445 bool AccessibilitySettingsConfig::GetEnabledState() const
446 {
447     return enabled_;
448 }
449 
GetTouchGuideState() const450 bool AccessibilitySettingsConfig::GetTouchGuideState() const
451 {
452     return eventTouchGuideState_;
453 }
454 
GetGestureState() const455 bool AccessibilitySettingsConfig::GetGestureState() const
456 {
457     return gesturesSimulation_;
458 }
459 
GetKeyEventObserverState() const460 bool AccessibilitySettingsConfig::GetKeyEventObserverState() const
461 {
462     return filteringKeyEvents_;
463 }
464 
GetCaptionProperty() const465 const AccessibilityConfig::CaptionProperty &AccessibilitySettingsConfig::GetCaptionProperty() const
466 {
467     return captionProperty_;
468 };
469 
GetClickResponseTime() const470 uint32_t AccessibilitySettingsConfig::GetClickResponseTime() const
471 {
472     return clickResponseTime_;
473 }
474 
GetScreenMagnificationType() const475 uint32_t AccessibilitySettingsConfig::GetScreenMagnificationType() const
476 {
477     return screenMagnificationType_;
478 }
479 
GetIgnoreRepeatClickState() const480 bool AccessibilitySettingsConfig::GetIgnoreRepeatClickState() const
481 {
482     return ignoreRepeatClickState_;
483 }
484 
GetIgnoreRepeatClickTime() const485 uint32_t AccessibilitySettingsConfig::GetIgnoreRepeatClickTime() const
486 {
487     return ignoreRepeatClickTime_;
488 }
489 
GetEnabledAccessibilityServices()490 const std::vector<std::string> AccessibilitySettingsConfig::GetEnabledAccessibilityServices()
491 {
492     std::lock_guard<std::mutex> lock(interfaceMutex_);
493     std::vector<std::string> rtnVec = enabledAccessibilityServices_;
494     return rtnVec;
495 }
496 
AddEnabledAccessibilityService(const std::string & serviceName)497 RetError AccessibilitySettingsConfig::AddEnabledAccessibilityService(const std::string &serviceName)
498 {
499     std::lock_guard<std::mutex> lock(interfaceMutex_);
500     auto iter = std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(), serviceName);
501     if (iter != enabledAccessibilityServices_.end()) {
502         return RET_OK;
503     }
504 
505     if (!datashare_) {
506         return RET_ERR_NULLPTR;
507     }
508     enabledAccessibilityServices_.push_back(serviceName);
509     std::string stringOut = "";
510     Utils::VectorToString(enabledAccessibilityServices_, stringOut);
511     return datashare_->PutStringValue(ENABLED_ACCESSIBILITY_SERVICES, stringOut);
512 }
513 
RemoveEnabledAccessibilityService(const std::string & serviceName)514 RetError AccessibilitySettingsConfig::RemoveEnabledAccessibilityService(const std::string &serviceName)
515 {
516     std::lock_guard<std::mutex> lock(interfaceMutex_);
517     auto iter = std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(), serviceName);
518     if (iter == enabledAccessibilityServices_.end()) {
519         return RET_OK;
520     }
521 
522     if (!datashare_) {
523         return RET_ERR_NULLPTR;
524     }
525     enabledAccessibilityServices_.erase(iter);
526     std::string stringOut = "";
527     Utils::VectorToString(enabledAccessibilityServices_, stringOut);
528     return datashare_->PutStringValue(ENABLED_ACCESSIBILITY_SERVICES, stringOut);
529 }
530 
GetStartFromAtoHosState()531 bool AccessibilitySettingsConfig::GetStartFromAtoHosState()
532 {
533     HILOG_DEBUG();
534     if (!datashare_) {
535         return RET_ERR_NULLPTR;
536     }
537 
538     bool value = true;
539     value = datashare_->GetBoolValue("AccessibilityStartFromAtoHos", true);
540     return value;
541 }
542 
GetConfigState()543 uint32_t AccessibilitySettingsConfig::GetConfigState()
544 {
545     HILOG_DEBUG();
546     uint32_t state = 0;
547     if (isCaptionState_) {
548         state |= STATE_CAPTION_ENABLED;
549     }
550 
551     if (isScreenMagnificationState_) {
552         state |= STATE_SCREENMAGNIFIER_ENABLED;
553     }
554 
555     if (isMouseKeyState_) {
556         state |= STATE_MOUSEKEY_ENABLED;
557     }
558 
559     if (isShortKeyState_) {
560         state |= STATE_SHORTKEY_ENABLED;
561     }
562 
563     if (highContrastTextState_) {
564         state |= STATE_HIGHCONTRAST_ENABLED;
565     }
566 
567     if (daltonizationState_) {
568         state |= STATE_DALTONIZATION_STATE_ENABLED;
569     }
570 
571     if (invertColorState_) {
572         state |= STATE_INVETRTCOLOR_ENABLED;
573     }
574 
575     if (animationOffState_) {
576         state |= STATE_ANIMATIONOFF_ENABLED;
577     }
578 
579     if (audioMonoState_) {
580         state |= STATE_AUDIOMONO_ENABLED;
581     }
582 
583     if (ignoreRepeatClickState_) {
584         state |= STATE_IGNORE_REPEAT_CLICK_ENABLED;
585     }
586     return state;
587 }
588 
InitCaption()589 void AccessibilitySettingsConfig::InitCaption()
590 {
591     HILOG_DEBUG();
592     if (datashare_ == nullptr) {
593         return;
594     }
595 
596     std::string strValue = datashare_->GetStringValue(CAPTION_KEY, "");
597     HILOG_DEBUG(" pref_->GetString() = %{public}s.", strValue.c_str());
598     if (!std::strcmp(strValue.c_str(), "on")) {
599         isCaptionState_ = true;
600     } else {
601         isCaptionState_ = false;
602     }
603 
604     std::string fontFamliy = datashare_->GetStringValue(FONT_FAMILY, "default");
605     HILOG_DEBUG("fontFamily = %{public}s.", fontFamliy.c_str());
606 
607     int32_t fontScale =  static_cast<int32_t>(datashare_->GetIntValue(FONT_SCALE, DEFAULT_SCALE));
608     HILOG_DEBUG("fontScale = %{public}d.", fontScale);
609 
610     uint32_t fontColor = static_cast<uint32_t>(datashare_->GetIntValue(FONT_COLOR, DEFAULT_COLOR));
611     HILOG_DEBUG("fontColor = 0x%{public}x.", fontColor);
612 
613     std::string fontEdgeType = datashare_->GetStringValue(FONT_EDGE_TYPE, "none");
614     HILOG_DEBUG("fontEdgeType = 0x%{public}s.", fontEdgeType.c_str());
615 
616     uint32_t backgroundColor = static_cast<uint32_t>(datashare_->GetIntValue(BACKGROUND_COLOR, DEFAULT_COLOR));
617     HILOG_DEBUG("backgroundColor = 0x%{public}x.", backgroundColor);
618 
619     uint32_t windowColor = static_cast<uint32_t>(datashare_->GetIntValue(WINDOW_COLOR, DEFAULT_COLOR));
620     HILOG_DEBUG("windowColor = 0x%{public}x.", windowColor);
621 
622     captionProperty_.SetFontFamily(fontFamliy);
623     captionProperty_.SetFontScale(fontScale);
624     captionProperty_.SetFontColor(fontColor);
625     captionProperty_.SetFontEdgeType(fontEdgeType);
626     captionProperty_.SetBackgroundColor(backgroundColor);
627     captionProperty_.SetWindowColor(windowColor);
628 }
629 
InitSetting()630 void AccessibilitySettingsConfig::InitSetting()
631 {
632     HILOG_DEBUG();
633     if (datashare_ == nullptr) {
634         return;
635     }
636 
637     isScreenMagnificationState_ = datashare_->GetBoolValue(SCREEN_MAGNIFICATION_KEY, false);
638     isMouseKeyState_= datashare_->GetBoolValue(MOUSEKEY, false);
639     isShortKeyState_ = datashare_->GetBoolValue(SHORTCUT_ENABLED, true);
640     isShortKeyEnabledOnLockScreen_ = datashare_->GetBoolValue(SHORTCUT_ENABLED_ON_LOCK_SCREEN, false);
641     shortKeyTimeout_ = static_cast<int32_t>(datashare_->GetIntValue(SHORTCUT_TIMEOUT, SHORT_KEY_TIMEOUT_BEFORE_USE));
642     animationOffState_ = datashare_->GetBoolValue(ANIMATION_OFF_KEY, false);
643     invertColorState_ = datashare_->GetBoolValue(INVERT_COLOR_KEY, false);
644     highContrastTextState_ = datashare_->GetBoolValue(HIGH_CONTRAST_TEXT_KEY, false);
645     daltonizationState_ = datashare_->GetBoolValue(DALTONIZATION_STATE, false);
646     audioMonoState_ = datashare_->GetBoolValue(AUDIO_MONO_KEY, false);
647     ignoreRepeatClickState_ = datashare_->GetBoolValue(IGNORE_REPEAT_CLICK_SWITCH, false);
648 
649     shortkeyTarget_ = datashare_->GetStringValue("ShortkeyTarget", "none");
650 
651     std::string tmpString = datashare_->GetStringValue(SHORTCUT_SERVICE, "");
652     Utils::StringToVector(tmpString, shortkeyMultiTarget_);
653 
654     tmpString = datashare_->GetStringValue(ENABLED_ACCESSIBILITY_SERVICES, "");
655     Utils::StringToVector(tmpString, enabledAccessibilityServices_);
656 
657     mouseAutoClick_ = static_cast<int32_t>(datashare_->GetIntValue("MouseAutoClick", -1));
658     daltonizationColorFilter_ = static_cast<uint32_t>(datashare_->GetIntValue(DALTONIZATION_COLOR_FILTER_KEY, 0));
659     contentTimeout_ = static_cast<uint32_t>(datashare_->GetIntValue(CONTENT_TIMEOUT_KEY, 0));
660     brightnessDiscount_ = static_cast<float>(datashare_->GetFloatValue(BRIGHTNESS_DISCOUNT_KEY, 1.0));
661     audioBalance_ = static_cast<float>(datashare_->GetFloatValue(AUDIO_BALANCE_KEY, 0));
662     screenMagnificationType_ = static_cast<uint32_t>(datashare_->GetIntValue(SCREEN_MAGNIFICATION_TYPE, 0));
663     clickResponseTime_ = static_cast<uint32_t>(datashare_->GetIntValue(CLICK_RESPONCE_TIME, 0));
664     ignoreRepeatClickTime_ = static_cast<uint32_t>(datashare_->GetIntValue(IGNORE_REPEAT_CLICK_TIME, 0));
665 }
666 
InitCapability()667 void AccessibilitySettingsConfig::InitCapability()
668 {
669     HILOG_DEBUG();
670     if (datashare_ == nullptr) {
671         return;
672     }
673 
674     enabled_ = datashare_->GetBoolValue(ACCESSIBILITY, false);
675     eventTouchGuideState_ = datashare_->GetBoolValue(TOUCH_GUIDE_STATE, false);
676     gesturesSimulation_ = datashare_->GetBoolValue(GESTURE_KEY, false);
677     filteringKeyEvents_ = datashare_->GetBoolValue(KEYEVENT_OBSERVER, false);
678 }
679 
SetConfigState(const std::string & key,bool value)680 RetError AccessibilitySettingsConfig::SetConfigState(const std::string& key, bool value)
681 {
682     if (!datashare_) {
683         return RET_ERR_NULLPTR;
684     }
685     return datashare_->PutBoolValue(key, value);
686 }
687 
Init()688 void AccessibilitySettingsConfig::Init()
689 {
690     HILOG_DEBUG();
691     datashare_ = std::make_shared<AccessibilityDatashareHelper>(DATASHARE_TYPE::SECURE, accountId_);
692     if (datashare_ == nullptr) {
693         return;
694     }
695     datashare_->Initialize(POWER_MANAGER_SERVICE_ID);
696     InitCaption();
697     InitSetting();
698 }
699 
ClearData()700 void AccessibilitySettingsConfig::ClearData()
701 {
702     HILOG_DEBUG();
703 }
704 
OnDataClone()705 void AccessibilitySettingsConfig::OnDataClone()
706 {
707     InitSetting();
708     if (clickResponseTime_ == DOUBLE_CLICK_RESPONSE_TIME_MEDIUM) {
709         SetClickResponseTime(AccessibilityConfig::ResponseDelayMedium);
710     } else if (clickResponseTime_ > DOUBLE_CLICK_RESPONSE_TIME_MEDIUM) {
711         SetClickResponseTime(AccessibilityConfig::ResponseDelayLong);
712     }
713     if (ignoreRepeatClickTime_ == DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORT) {
714         SetIgnoreRepeatClickTime(AccessibilityConfig::RepeatClickTimeoutShort);
715     } else if (ignoreRepeatClickTime_ == DOUBLE_IGNORE_REPEAT_CLICK_TIME_MEDIUM) {
716         SetIgnoreRepeatClickTime(AccessibilityConfig::RepeatClickTimeoutMedium);
717     } else if (ignoreRepeatClickTime_ == DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG) {
718         SetIgnoreRepeatClickTime(AccessibilityConfig::RepeatClickTimeoutLong);
719     } else if (ignoreRepeatClickTime_ > DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG) {
720         SetIgnoreRepeatClickTime(AccessibilityConfig::RepeatClickTimeoutLongest);
721     }
722     if (daltonizationColorFilter_ == DISPLAY_DALTONIZER_GREEN) {
723         SetDaltonizationColorFilter(AccessibilityConfig::Deuteranomaly);
724     } else if (daltonizationColorFilter_ == DISPLAY_DALTONIZER_RED) {
725         SetDaltonizationColorFilter(AccessibilityConfig::Protanomaly);
726     } else if (daltonizationColorFilter_ == DISPLAY_DALTONIZER_BLUE) {
727         SetDaltonizationColorFilter(AccessibilityConfig::Tritanomaly);
728     }
729     // 1->1000 0->3000
730     if (shortKeyTimeout_ == 1) {
731         shortKeyTimeout_ = SHORT_KEY_TIMEOUT_AFTER_USE;
732     } else {
733         shortKeyTimeout_ = SHORT_KEY_TIMEOUT_BEFORE_USE;
734     }
735 
736     auto cleanFunc = [] (std::vector<std::string> &services) -> int {
737         int count = 0;
738         for (auto iter = services.begin(); iter != services.end();) {
739             if (iter->find(SCREENREADER_TAG) != std::string::npos) {
740                 iter = services.erase(iter);
741                 count++;
742             } else {
743                 iter++;
744             }
745         }
746         return count;
747     };
748     std::vector<std::string> tmpVec = GetShortkeyMultiTarget();
749     if (cleanFunc(tmpVec) != 0) {
750         tmpVec.push_back(SCREEN_READER_BUNDLE_ABILITY_NAME);
751         SetShortkeyMultiTarget(tmpVec);
752     }
753 
754     tmpVec = GetEnabledAccessibilityServices();
755     if (cleanFunc(tmpVec) != 0) {
756         AddEnabledAccessibilityService(SCREEN_READER_BUNDLE_ABILITY_NAME);
757     }
758 
759     AccessibilitySettingProvider& provider = AccessibilitySettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID);
760     provider.PutBoolValue(ACCESSIBILITY_CLONE_FLAG, false);
761     HILOG_INFO();
762 }
763 } // namespace Accessibility
764 } // namespace OHOS