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 #include "accessible_ability_manager_service.h"
22
23 namespace OHOS {
24 namespace Accessibility {
25 namespace {
26 constexpr uint32_t DEFAULT_COLOR = 0xff000000;
27 const int32_t DEFAULT_SCALE = 100;
28 const int32_t SHORT_KEY_TIMEOUT_AFTER_USE = 1000; // ms
29 const int32_t SHORT_KEY_TIMEOUT_BEFORE_USE = 3000; // ms
30 const int32_t DEFAULT_ACCOUNT_ID = 100;
31 const std::string ACCESSIBILITY = "accessibility";
32 const std::string TOUCH_GUIDE_STATE = "touch_guide_state";
33 const std::string GESTURE_KEY = "gesture_state";
34 const std::string CAPTION_KEY = "caption_state";
35 const std::string KEYEVENT_OBSERVER = "keyevent_observer";
36 const std::string SCREEN_MAGNIFICATION_KEY = "accessibility_display_magnification_enabled";
37 const std::string SCREEN_MAGNIFICATION_TYPE = "accessibility_magnification_capability";
38 const std::string MOUSEKEY = "mousekey";
39 const std::string HIGH_CONTRAST_TEXT_KEY = "high_text_contrast_enabled";
40 const std::string DALTONIZATION_STATE = "accessibility_display_daltonizer_enabled";
41 const std::string INVERT_COLOR_KEY = "accessibility_display_inversion_enabled";
42 const std::string ANIMATION_OFF_KEY = "animation_off";
43 const std::string AUDIO_MONO_KEY = "master_mono";
44 const std::string IGNORE_REPEAT_CLICK_SWITCH = "ignore_repeat_click_switch";
45 const std::string SHORTCUT_ENABLED = "accessibility_shortcut_enabled";
46 const std::string SHORTCUT_SERVICE = "accessibility_shortcut_target_service";
47 const std::string CLICK_RESPONCE_TIME = "click_response_time";
48 const std::string IGNORE_REPEAT_CLICK_TIME = "ignore_repeat_click_time";
49 const std::string DALTONIZATION_COLOR_FILTER_KEY = "accessibility_display_daltonizer";
50 const std::string CONTENT_TIMEOUT_KEY = "accessibility_content_timeout";
51 const std::string BRIGHTNESS_DISCOUNT_KEY = "accessibility_brightness_discount";
52 const std::string AUDIO_BALANCE_KEY = "master_balance";
53 const std::string FONT_FAMILY = "accessibility_font_family";
54 const std::string FONT_COLOR = "accessibility_font_color";
55 const std::string FONT_EDGE_TYPE = "accessibility_font_edge_type";
56 const std::string BACKGROUND_COLOR = "accessibility_background_color";
57 const std::string WINDOW_COLOR = "accessibility_window_color";
58 const std::string FONT_SCALE = "accessibility_font_scale";
59 const std::string ENABLED_ACCESSIBILITY_SERVICES = "enabled_accessibility_services";
60 const std::string SHORTCUT_ENABLED_ON_LOCK_SCREEN = "accessibility_shortcut_enabled_on_lock_screen";
61 const std::string SHORTCUT_TIMEOUT = "accessibility_shortcut_timeout";
62 const std::string ACCESSIBILITY_CLONE_FLAG = "accessibility_config_clone";
63 const std::string SCREENREADER_TAG = "screenreader";
64 const std::string INVERT_COLOR_AOS_TAG = "ColorInversion";
65 const std::string INVERT_COLOR_HMOS_TAG = "INVERT_COLOR";
66 const std::string AUDIO_MONO_HMOS_TAG = "AUDIO_MONO";
67 const std::string HIGH_CONTRAST_TEXT_HMOS_TAG = "HIGH_CONTRAST_TEXT";
68 const std::string SCREEN_READER_BUNDLE_ABILITY_NAME = "com.huawei.hmos.screenreader/AccessibilityExtAbility";
69 const std::string ACCESSIBILITY_SCREENREADER_ENABLED = "accessibility_screenreader_enabled";
70 const std::string ACCESSIBILITY_PRIVACY_CLONE_OR_UPGRADE = "accessibility_privacy_clone_or_upgrade";
71 constexpr int DOUBLE_CLICK_RESPONSE_TIME_MEDIUM = 300;
72 constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORTEST = 100;
73 constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORT = 400;
74 constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_MEDIUM = 700;
75 constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG = 1000;
76 constexpr int DISPLAY_DALTONIZER_INVALID = -1;
77 constexpr int DISPLAY_DALTONIZER_GREEN = 12;
78 constexpr int DISPLAY_DALTONIZER_RED = 11;
79 constexpr int DISPLAY_DALTONIZER_BLUE = 13;
80 constexpr int INVALID_MASTER_MONO_VALUE = -1;
81 constexpr int AUDIO_BALANCE_STEP = 5;
82 constexpr float INVALID_MASTER_BALANCE_VALUE = 2.0;
83 } // namespace
AccessibilitySettingsConfig(int32_t id)84 AccessibilitySettingsConfig::AccessibilitySettingsConfig(int32_t id)
85 {
86 HILOG_DEBUG("id = [%{public}d]", id);
87 accountId_ = id;
88 }
89
SetEnabled(const bool state)90 RetError AccessibilitySettingsConfig::SetEnabled(const bool state)
91 {
92 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
93 auto ret = SetConfigState(ACCESSIBILITY, state);
94 if (ret != RET_OK) {
95 HILOG_ERROR("set accessibility failed");
96 return ret;
97 }
98 enabled_ = state;
99 return ret;
100 }
101
SetTouchGuideState(const bool state)102 RetError AccessibilitySettingsConfig::SetTouchGuideState(const bool state)
103 {
104 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
105 auto ret = SetConfigState(TOUCH_GUIDE_STATE, state);
106 if (ret != RET_OK) {
107 HILOG_ERROR("set eventTouchGuideState_ failed");
108 return ret;
109 }
110 eventTouchGuideState_ = state;
111 return ret;
112 }
113
SetGestureState(const bool state)114 RetError AccessibilitySettingsConfig::SetGestureState(const bool state)
115 {
116 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
117 auto ret = SetConfigState(GESTURE_KEY, state);
118 if (ret != RET_OK) {
119 HILOG_ERROR("set gesturesSimulation_ failed");
120 return ret;
121 }
122 gesturesSimulation_ = state;
123 return ret;
124 }
125
SetKeyEventObserverState(const bool state)126 RetError AccessibilitySettingsConfig::SetKeyEventObserverState(const bool state)
127 {
128 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
129 auto ret = SetConfigState(KEYEVENT_OBSERVER, state);
130 if (ret != RET_OK) {
131 HILOG_ERROR("set filteringKeyEvents_ failed");
132 return ret;
133 }
134 filteringKeyEvents_ = state;
135 return ret;
136 }
137
SetCaptionState(const bool state)138 RetError AccessibilitySettingsConfig::SetCaptionState(const bool state)
139 {
140 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
141 auto ret = SetConfigState(CAPTION_KEY, state);
142 if (ret != RET_OK) {
143 HILOG_ERROR("set isCaptionState_ failed");
144 return ret;
145 }
146 isCaptionState_ = state;
147 return ret;
148 }
149
SetScreenMagnificationState(const bool state)150 RetError AccessibilitySettingsConfig::SetScreenMagnificationState(const bool state)
151 {
152 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
153 isScreenMagnificationState_ = state;
154 return RET_OK;
155 }
156
SetScreenMagnificationType(const uint32_t type)157 RetError AccessibilitySettingsConfig::SetScreenMagnificationType(const uint32_t type)
158 {
159 HILOG_DEBUG("screenMagnificationType = [%{public}u]", type);
160 screenMagnificationType_ = type;
161 return RET_OK;
162 }
163
SetShortKeyState(const bool state)164 RetError AccessibilitySettingsConfig::SetShortKeyState(const bool state)
165 {
166 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
167 auto ret = SetConfigState(SHORTCUT_ENABLED, state);
168 if (ret != RET_OK) {
169 HILOG_ERROR("set isShortKeyState_ failed");
170 return ret;
171 }
172 isShortKeyState_ = state;
173 return ret;
174 }
175
SetShortKeyOnLockScreenState(const bool state)176 RetError AccessibilitySettingsConfig::SetShortKeyOnLockScreenState(const bool state)
177 {
178 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
179 auto ret = SetConfigState(SHORTCUT_ENABLED_ON_LOCK_SCREEN, state);
180 if (ret != RET_OK) {
181 HILOG_ERROR("set isShortKeyEnabledOnLockScreen_ failed");
182 return ret;
183 }
184 isShortKeyEnabledOnLockScreen_ = state;
185 return ret;
186 }
187
SetShortKeyTimeout(const int32_t time)188 RetError AccessibilitySettingsConfig::SetShortKeyTimeout(const int32_t time)
189 {
190 HILOG_DEBUG("time = [%{public}u]", time);
191 if (!datashare_) {
192 HILOG_ERROR("helper is nullptr");
193 return RET_ERR_NULLPTR;
194 }
195
196 auto ret = datashare_->PutIntValue(SHORTCUT_TIMEOUT, static_cast<int32_t>(time));
197 if (ret != RET_OK) {
198 HILOG_ERROR("set shortKeyTimeout_ failed");
199 return ret;
200 }
201 shortKeyTimeout_ = time;
202 return ret;
203 }
204
SetStartToHosState(const bool state)205 RetError AccessibilitySettingsConfig::SetStartToHosState(const bool state)
206 {
207 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
208 if (!datashare_) {
209 HILOG_ERROR("helper is nullptr");
210 return RET_ERR_NULLPTR;
211 }
212 return datashare_->PutBoolValue("AccessibilityStartFromAtoHos", state);
213 }
214
SetMouseKeyState(const bool state)215 RetError AccessibilitySettingsConfig::SetMouseKeyState(const bool state)
216 {
217 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
218 auto ret = SetConfigState(MOUSEKEY, state);
219 if (ret != RET_OK) {
220 HILOG_ERROR("set isMouseKeyState_ failed");
221 return ret;
222 }
223 isMouseKeyState_ = state;
224 return ret;
225 }
226
SetMouseAutoClick(const int32_t time)227 RetError AccessibilitySettingsConfig::SetMouseAutoClick(const int32_t time)
228 {
229 HILOG_DEBUG("time = [%{public}d]", time);
230 if (!datashare_) {
231 HILOG_ERROR("helper is nullptr");
232 return RET_ERR_NULLPTR;
233 }
234
235 auto ret = datashare_->PutIntValue("MouseAutoClick", time);
236 if (ret != RET_OK) {
237 HILOG_ERROR("set mouseAutoClick_ failed");
238 return ret;
239 }
240 mouseAutoClick_ = time;
241 return ret;
242 }
243
SetShortkeyTarget(const std::string & name)244 RetError AccessibilitySettingsConfig::SetShortkeyTarget(const std::string &name)
245 {
246 HILOG_DEBUG("name = [%{public}s]", name.c_str());
247 if (!datashare_) {
248 HILOG_ERROR("helper is nullptr");
249 return RET_ERR_NULLPTR;
250 }
251
252 auto ret = datashare_->PutStringValue("ShortkeyTarget", name);
253 if (ret != RET_OK) {
254 HILOG_ERROR("set shortkeyTarget_ failed");
255 return ret;
256 }
257 shortkeyTarget_ = name;
258 return ret;
259 }
260
SetShortkeyMultiTarget(const std::vector<std::string> & name)261 RetError AccessibilitySettingsConfig::SetShortkeyMultiTarget(const std::vector<std::string> &name)
262 {
263 HILOG_DEBUG();
264 std::set<std::string> targets;
265 std::copy_if(name.begin(), name.end(), std::inserter(targets, targets.end()),
266 [&targets](const std::string &target) {
267 targets.insert(target);
268 return true;
269 });
270 std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
271 if (!datashare_) {
272 HILOG_ERROR("helper is nullptr");
273 return RET_ERR_NULLPTR;
274 }
275
276 std::string stringOut = "";
277 Utils::VectorToString(std::vector<std::string>(targets.begin(), targets.end()), stringOut);
278 auto ret = datashare_->PutStringValue(SHORTCUT_SERVICE, stringOut);
279 if (ret != RET_OK) {
280 HILOG_ERROR("set shortkeyMultiTarget_ failed");
281 return ret;
282 }
283 shortkeyMultiTarget_ = std::vector<std::string>(targets.begin(), targets.end());
284 return ret;
285 }
286
SetShortkeyMultiTargetInPkgRemove(const std::string & name)287 RetError AccessibilitySettingsConfig::SetShortkeyMultiTargetInPkgRemove(const std::string &name)
288 {
289 HILOG_DEBUG();
290 std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
291 if (!datashare_) {
292 HILOG_ERROR("helper is nullptr");
293 return RET_ERR_NULLPTR;
294 }
295 RetError rtn = RET_OK;
296
297 for (auto iter = shortkeyMultiTarget_.begin(); iter != shortkeyMultiTarget_.end(); ++iter) {
298 if (*iter == name) {
299 shortkeyMultiTarget_.erase(iter);
300 std::string stringOut = "";
301 Utils::VectorToString(shortkeyMultiTarget_, stringOut);
302 rtn = datashare_->PutStringValue(SHORTCUT_SERVICE, stringOut);
303 break;
304 }
305 }
306 if (rtn != RET_OK) {
307 HILOG_ERROR("set shortkeyMultiTarget_ failed");
308 shortkeyMultiTarget_.push_back(name);
309 }
310 return rtn;
311 }
312
SetHighContrastTextState(const bool state)313 RetError AccessibilitySettingsConfig::SetHighContrastTextState(const bool state)
314 {
315 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
316 auto ret = SetConfigState(HIGH_CONTRAST_TEXT_KEY, state);
317 if (ret != RET_OK) {
318 HILOG_ERROR("set highContrastTextState_ failed");
319 return ret;
320 }
321 highContrastTextState_ = state;
322 return ret;
323 }
324
SetInvertColorState(const bool state)325 RetError AccessibilitySettingsConfig::SetInvertColorState(const bool state)
326 {
327 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
328 auto ret = SetConfigState(INVERT_COLOR_KEY, state);
329 if (ret != RET_OK) {
330 HILOG_ERROR("set invertColorState_ failed");
331 return ret;
332 }
333 invertColorState_ = state;
334 return ret;
335 }
336
SetAnimationOffState(const bool state)337 RetError AccessibilitySettingsConfig::SetAnimationOffState(const bool state)
338 {
339 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
340 auto ret = SetConfigState(ANIMATION_OFF_KEY, state);
341 if (ret != RET_OK) {
342 HILOG_ERROR("set animationOffState_ failed");
343 return ret;
344 }
345 animationOffState_ = state;
346 return ret;
347 }
348
SetAudioMonoState(const bool state)349 RetError AccessibilitySettingsConfig::SetAudioMonoState(const bool state)
350 {
351 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
352 auto ret = SetConfigState(AUDIO_MONO_KEY, state);
353 if (ret != RET_OK) {
354 HILOG_ERROR("set audioMonoState_ failed");
355 return ret;
356 }
357 audioMonoState_ = state;
358 return ret;
359 }
360
SetDaltonizationState(const bool state)361 RetError AccessibilitySettingsConfig::SetDaltonizationState(const bool state)
362 {
363 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
364 auto ret = SetConfigState(DALTONIZATION_STATE, state);
365 if (ret != RET_OK) {
366 HILOG_ERROR("set daltonizationState_ failed");
367 return ret;
368 }
369 daltonizationState_ = state;
370 return ret;
371 }
372
SetDaltonizationColorFilter(const uint32_t filter)373 RetError AccessibilitySettingsConfig::SetDaltonizationColorFilter(const uint32_t filter)
374 {
375 HILOG_DEBUG("filter = [%{public}u]", filter);
376 if (!datashare_) {
377 HILOG_ERROR("helper is nullptr");
378 return RET_ERR_NULLPTR;
379 }
380
381 uint32_t daltonizationColorFilter = filter;
382 if (filter == DISPLAY_DALTONIZER_GREEN) {
383 daltonizationColorFilter = AccessibilityConfig::Deuteranomaly;
384 } else if (filter == DISPLAY_DALTONIZER_RED) {
385 daltonizationColorFilter = AccessibilityConfig::Protanomaly;
386 } else if (filter == DISPLAY_DALTONIZER_BLUE) {
387 daltonizationColorFilter = AccessibilityConfig::Tritanomaly;
388 } else if (filter == static_cast<uint32_t>(DISPLAY_DALTONIZER_INVALID)) {
389 daltonizationColorFilter = 0;
390 }
391 auto ret = datashare_->PutIntValue(DALTONIZATION_COLOR_FILTER_KEY, static_cast<int32_t>(daltonizationColorFilter));
392 if (ret != RET_OK) {
393 HILOG_ERROR("set daltonizationColorFilter_ failed");
394 return ret;
395 }
396 daltonizationColorFilter_ = daltonizationColorFilter;
397 return ret;
398 }
399
400
SetContentTimeout(const uint32_t time)401 RetError AccessibilitySettingsConfig::SetContentTimeout(const uint32_t time)
402 {
403 HILOG_DEBUG("time = [%{public}u]", time);
404 if (!datashare_) {
405 HILOG_ERROR("helper is nullptr");
406 return RET_ERR_NULLPTR;
407 }
408
409 auto ret = datashare_->PutIntValue(CONTENT_TIMEOUT_KEY, static_cast<int32_t>(time));
410 if (ret != RET_OK) {
411 HILOG_ERROR("set contentTimeout_ failed");
412 return ret;
413 }
414 contentTimeout_ = time;
415 return ret;
416 }
417
SetBrightnessDiscount(const float discount)418 RetError AccessibilitySettingsConfig::SetBrightnessDiscount(const float discount)
419 {
420 HILOG_DEBUG("discount = [%{public}f]", discount);
421 if (!datashare_) {
422 HILOG_ERROR("helper is nullptr");
423 return RET_ERR_NULLPTR;
424 }
425
426 auto ret = datashare_->PutFloatValue(BRIGHTNESS_DISCOUNT_KEY, discount);
427 if (ret != RET_OK) {
428 HILOG_ERROR("set brightnessDiscount_ failed");
429 return ret;
430 }
431 brightnessDiscount_ = discount;
432 return ret;
433 }
434
SetAudioBalance(const float balance)435 RetError AccessibilitySettingsConfig::SetAudioBalance(const float balance)
436 {
437 HILOG_DEBUG("balance = [%{public}f]", balance);
438 if (!datashare_) {
439 HILOG_ERROR("helper is nullptr");
440 return RET_ERR_NULLPTR;
441 }
442
443 float audioBalance = round(balance * AUDIO_BALANCE_STEP) / AUDIO_BALANCE_STEP;
444 auto ret = datashare_->PutFloatValue(AUDIO_BALANCE_KEY, audioBalance);
445 if (ret != RET_OK) {
446 HILOG_ERROR("set audioBalance_ failed");
447 return ret;
448 }
449 audioBalance_ = audioBalance;
450 return ret;
451 }
452
SetClickResponseTime(const uint32_t time)453 RetError AccessibilitySettingsConfig::SetClickResponseTime(const uint32_t time)
454 {
455 HILOG_DEBUG("clickResponseTime = [%{public}u]", time);
456 if (!datashare_) {
457 HILOG_ERROR("helper is nullptr");
458 return RET_ERR_NULLPTR;
459 }
460
461 uint32_t clickResponseTime = time;
462 if (time == DOUBLE_CLICK_RESPONSE_TIME_MEDIUM) {
463 clickResponseTime = AccessibilityConfig::ResponseDelayMedium;
464 } else if (time > DOUBLE_CLICK_RESPONSE_TIME_MEDIUM) {
465 clickResponseTime = AccessibilityConfig::ResponseDelayLong;
466 }
467 auto ret = datashare_->PutIntValue(CLICK_RESPONCE_TIME, clickResponseTime);
468 if (ret != RET_OK) {
469 HILOG_ERROR("set clickResponseTime_ failed");
470 return ret;
471 }
472 clickResponseTime_ = clickResponseTime;
473 return ret;
474 }
475
SetIgnoreRepeatClickState(const bool state)476 RetError AccessibilitySettingsConfig::SetIgnoreRepeatClickState(const bool state)
477 {
478 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
479 auto ret = SetConfigState(IGNORE_REPEAT_CLICK_SWITCH, state);
480 if (ret != RET_OK) {
481 HILOG_ERROR("set ignoreRepeatClickState_ failed");
482 return ret;
483 }
484 ignoreRepeatClickState_ = state;
485 return ret;
486 }
487
SetIgnoreRepeatClickTime(const uint32_t time)488 RetError AccessibilitySettingsConfig::SetIgnoreRepeatClickTime(const uint32_t time)
489 {
490 HILOG_DEBUG("ignoreRepeatClickTime = [%{public}u]", time);
491 if (!datashare_) {
492 HILOG_ERROR("helper is nullptr");
493 return RET_ERR_NULLPTR;
494 }
495
496 uint32_t ignoreRepeatClickTime = time;
497 if (time == DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORTEST) {
498 ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutShortest;
499 } else if (time == DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORT) {
500 ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutShort;
501 } else if (time == DOUBLE_IGNORE_REPEAT_CLICK_TIME_MEDIUM) {
502 ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutMedium;
503 } else if (time == DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG) {
504 ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutLong;
505 } else if (time > DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG) {
506 ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutLongest;
507 }
508 auto ret = datashare_->PutIntValue(IGNORE_REPEAT_CLICK_TIME, ignoreRepeatClickTime);
509 if (ret != RET_OK) {
510 HILOG_ERROR("set ignoreRepeatClickTime_ failed");
511 return ret;
512 }
513 ignoreRepeatClickTime_ = ignoreRepeatClickTime;
514 return ret;
515 }
516
SetCaptionProperty(const AccessibilityConfig::CaptionProperty & caption)517 RetError AccessibilitySettingsConfig::SetCaptionProperty(const AccessibilityConfig::CaptionProperty& caption)
518 {
519 HILOG_DEBUG();
520 captionProperty_ = caption;
521 if (!datashare_) {
522 return RET_ERR_NULLPTR;
523 }
524
525 datashare_->PutStringValue(FONT_FAMILY, captionProperty_.GetFontFamily());
526 datashare_->PutIntValue(FONT_COLOR, static_cast<int32_t>(captionProperty_.GetFontColor()));
527 datashare_->PutStringValue(FONT_EDGE_TYPE, captionProperty_.GetFontEdgeType());
528 datashare_->PutIntValue(BACKGROUND_COLOR, static_cast<int32_t>(captionProperty_.GetBackgroundColor()));
529 datashare_->PutIntValue(WINDOW_COLOR, static_cast<int32_t>(captionProperty_.GetWindowColor()));
530 datashare_->PutIntValue(FONT_SCALE, captionProperty_.GetFontScale());
531 return RET_OK;
532 }
533
GetCaptionState() const534 bool AccessibilitySettingsConfig::GetCaptionState() const
535 {
536 return isCaptionState_;
537 }
538
GetScreenMagnificationState() const539 bool AccessibilitySettingsConfig::GetScreenMagnificationState() const
540 {
541 return isScreenMagnificationState_;
542 }
543
GetShortKeyState() const544 bool AccessibilitySettingsConfig::GetShortKeyState() const
545 {
546 return isShortKeyState_;
547 }
548
GetShortKeyOnLockScreenState() const549 bool AccessibilitySettingsConfig::GetShortKeyOnLockScreenState() const
550 {
551 return isShortKeyEnabledOnLockScreen_;
552 }
553
GetShortKeyTimeout() const554 int32_t AccessibilitySettingsConfig::GetShortKeyTimeout() const
555 {
556 return shortKeyTimeout_;
557 }
558
GetMouseKeyState() const559 bool AccessibilitySettingsConfig::GetMouseKeyState() const
560 {
561 return isMouseKeyState_;
562 }
563
GetMouseAutoClick() const564 int32_t AccessibilitySettingsConfig::GetMouseAutoClick() const
565 {
566 return mouseAutoClick_;
567 }
568
GetShortkeyTarget() const569 const std::string &AccessibilitySettingsConfig::GetShortkeyTarget() const
570 {
571 return shortkeyTarget_;
572 }
573
GetShortkeyMultiTarget()574 const std::vector<std::string> AccessibilitySettingsConfig::GetShortkeyMultiTarget()
575 {
576 std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
577 std::vector<std::string> rtnVec = shortkeyMultiTarget_;
578 return rtnVec;
579 }
580
GetHighContrastTextState() const581 bool AccessibilitySettingsConfig::GetHighContrastTextState() const
582 {
583 return highContrastTextState_;
584 }
585
GetInvertColorState() const586 bool AccessibilitySettingsConfig::GetInvertColorState() const
587 {
588 return invertColorState_;
589 }
590
GetAnimationOffState() const591 bool AccessibilitySettingsConfig::GetAnimationOffState() const
592 {
593 return animationOffState_;
594 }
595
GetAudioMonoState() const596 bool AccessibilitySettingsConfig::GetAudioMonoState() const
597 {
598 return audioMonoState_;
599 }
600
GetDaltonizationState() const601 bool AccessibilitySettingsConfig::GetDaltonizationState() const
602 {
603 return daltonizationState_;
604 }
605
GetDaltonizationColorFilter() const606 uint32_t AccessibilitySettingsConfig::GetDaltonizationColorFilter() const
607 {
608 return daltonizationColorFilter_;
609 }
610
GetContentTimeout() const611 uint32_t AccessibilitySettingsConfig::GetContentTimeout() const
612 {
613 return contentTimeout_;
614 }
615
GetBrightnessDiscount() const616 float AccessibilitySettingsConfig::GetBrightnessDiscount() const
617 {
618 return brightnessDiscount_;
619 }
620
GetAudioBalance() const621 float AccessibilitySettingsConfig::GetAudioBalance() const
622 {
623 return audioBalance_;
624 }
625
GetEnabledState() const626 bool AccessibilitySettingsConfig::GetEnabledState() const
627 {
628 return enabled_;
629 }
630
GetTouchGuideState() const631 bool AccessibilitySettingsConfig::GetTouchGuideState() const
632 {
633 return eventTouchGuideState_;
634 }
635
GetGestureState() const636 bool AccessibilitySettingsConfig::GetGestureState() const
637 {
638 return gesturesSimulation_;
639 }
640
GetKeyEventObserverState() const641 bool AccessibilitySettingsConfig::GetKeyEventObserverState() const
642 {
643 return filteringKeyEvents_;
644 }
645
GetCaptionProperty() const646 const AccessibilityConfig::CaptionProperty &AccessibilitySettingsConfig::GetCaptionProperty() const
647 {
648 return captionProperty_;
649 };
650
GetClickResponseTime() const651 uint32_t AccessibilitySettingsConfig::GetClickResponseTime() const
652 {
653 return clickResponseTime_;
654 }
655
GetScreenMagnificationType() const656 uint32_t AccessibilitySettingsConfig::GetScreenMagnificationType() const
657 {
658 return screenMagnificationType_;
659 }
660
GetIgnoreRepeatClickState() const661 bool AccessibilitySettingsConfig::GetIgnoreRepeatClickState() const
662 {
663 return ignoreRepeatClickState_;
664 }
665
GetIgnoreRepeatClickTime() const666 uint32_t AccessibilitySettingsConfig::GetIgnoreRepeatClickTime() const
667 {
668 return ignoreRepeatClickTime_;
669 }
670
SetEnabledAccessibilityServices(const std::vector<std::string> & services)671 RetError AccessibilitySettingsConfig::SetEnabledAccessibilityServices(const std::vector<std::string> &services)
672 {
673 std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
674 enabledAccessibilityServices_ = services;
675 if (datashare_ == nullptr) {
676 HILOG_WARN("datashare_ is null.");
677 return RET_ERR_NULLPTR;
678 }
679 std::string stringOut = "";
680 Utils::VectorToString(enabledAccessibilityServices_, stringOut);
681 return datashare_->PutStringValue(ENABLED_ACCESSIBILITY_SERVICES, stringOut);
682 }
683
GetEnabledAccessibilityServices()684 const std::vector<std::string> AccessibilitySettingsConfig::GetEnabledAccessibilityServices()
685 {
686 std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
687 std::vector<std::string> rtnVec = enabledAccessibilityServices_;
688 return rtnVec;
689 }
690
AddEnabledAccessibilityService(const std::string & serviceName)691 RetError AccessibilitySettingsConfig::AddEnabledAccessibilityService(const std::string &serviceName)
692 {
693 std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
694 auto iter = std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(), serviceName);
695 if (iter != enabledAccessibilityServices_.end()) {
696 return RET_OK;
697 }
698
699 if (!datashare_) {
700 return RET_ERR_NULLPTR;
701 }
702 enabledAccessibilityServices_.push_back(serviceName);
703 std::string stringOut = "";
704 Utils::VectorToString(enabledAccessibilityServices_, stringOut);
705 return datashare_->PutStringValue(ENABLED_ACCESSIBILITY_SERVICES, stringOut);
706 }
707
RemoveEnabledAccessibilityService(const std::string & serviceName)708 RetError AccessibilitySettingsConfig::RemoveEnabledAccessibilityService(const std::string &serviceName)
709 {
710 std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
711 auto iter = std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(), serviceName);
712 if (iter == enabledAccessibilityServices_.end()) {
713 return RET_OK;
714 }
715
716 if (!datashare_) {
717 return RET_ERR_NULLPTR;
718 }
719 enabledAccessibilityServices_.erase(iter);
720 std::string stringOut = "";
721 Utils::VectorToString(enabledAccessibilityServices_, stringOut);
722 return datashare_->PutStringValue(ENABLED_ACCESSIBILITY_SERVICES, stringOut);
723 }
724
GetStartToHosState()725 bool AccessibilitySettingsConfig::GetStartToHosState()
726 {
727 HILOG_DEBUG();
728 if (!datashare_) {
729 return RET_ERR_NULLPTR;
730 }
731
732 bool value = true;
733 value = datashare_->GetBoolValue("AccessibilityStartFromAtoHos", true);
734 return value;
735 }
736
GetConfigState()737 uint32_t AccessibilitySettingsConfig::GetConfigState()
738 {
739 HILOG_DEBUG();
740 uint32_t state = 0;
741 if (isCaptionState_) {
742 state |= STATE_CAPTION_ENABLED;
743 }
744
745 if (isScreenMagnificationState_) {
746 state |= STATE_SCREENMAGNIFIER_ENABLED;
747 }
748
749 if (isMouseKeyState_) {
750 state |= STATE_MOUSEKEY_ENABLED;
751 }
752
753 if (isShortKeyState_) {
754 state |= STATE_SHORTKEY_ENABLED;
755 }
756
757 if (highContrastTextState_) {
758 state |= STATE_HIGHCONTRAST_ENABLED;
759 }
760
761 if (daltonizationState_) {
762 state |= STATE_DALTONIZATION_STATE_ENABLED;
763 }
764
765 if (invertColorState_) {
766 state |= STATE_INVETRTCOLOR_ENABLED;
767 }
768
769 if (animationOffState_) {
770 state |= STATE_ANIMATIONOFF_ENABLED;
771 }
772
773 if (audioMonoState_) {
774 state |= STATE_AUDIOMONO_ENABLED;
775 }
776
777 if (ignoreRepeatClickState_) {
778 state |= STATE_IGNORE_REPEAT_CLICK_ENABLED;
779 }
780 return state;
781 }
782
InitCaption()783 void AccessibilitySettingsConfig::InitCaption()
784 {
785 HILOG_DEBUG();
786 if (datashare_ == nullptr) {
787 return;
788 }
789
790 std::string strValue = datashare_->GetStringValue(CAPTION_KEY, "");
791 HILOG_DEBUG(" pref_->GetString() = %{public}s.", strValue.c_str());
792 if (!std::strcmp(strValue.c_str(), "on")) {
793 isCaptionState_ = true;
794 } else {
795 isCaptionState_ = false;
796 }
797
798 std::string fontFamliy = datashare_->GetStringValue(FONT_FAMILY, "default");
799 HILOG_DEBUG("fontFamily = %{public}s.", fontFamliy.c_str());
800
801 int32_t fontScale = static_cast<int32_t>(datashare_->GetIntValue(FONT_SCALE, DEFAULT_SCALE));
802 HILOG_DEBUG("fontScale = %{public}d.", fontScale);
803
804 uint32_t fontColor = static_cast<uint32_t>(datashare_->GetIntValue(FONT_COLOR, DEFAULT_COLOR));
805 HILOG_DEBUG("fontColor = 0x%{public}x.", fontColor);
806
807 std::string fontEdgeType = datashare_->GetStringValue(FONT_EDGE_TYPE, "none");
808 HILOG_DEBUG("fontEdgeType = 0x%{public}s.", fontEdgeType.c_str());
809
810 uint32_t backgroundColor = static_cast<uint32_t>(datashare_->GetIntValue(BACKGROUND_COLOR, DEFAULT_COLOR));
811 HILOG_DEBUG("backgroundColor = 0x%{public}x.", backgroundColor);
812
813 uint32_t windowColor = static_cast<uint32_t>(datashare_->GetIntValue(WINDOW_COLOR, DEFAULT_COLOR));
814 HILOG_DEBUG("windowColor = 0x%{public}x.", windowColor);
815
816 captionProperty_.SetFontFamily(fontFamliy);
817 captionProperty_.SetFontScale(fontScale);
818 captionProperty_.SetFontColor(fontColor);
819 captionProperty_.SetFontEdgeType(fontEdgeType);
820 captionProperty_.SetBackgroundColor(backgroundColor);
821 captionProperty_.SetWindowColor(windowColor);
822 }
823
InitShortKeyConfig()824 void AccessibilitySettingsConfig::InitShortKeyConfig()
825 {
826 isShortKeyState_ = datashare_->GetBoolValue(SHORTCUT_ENABLED, true);
827 bool isShortKeyEnabledOnLockScreen = datashare_->GetBoolValue(SHORTCUT_ENABLED_ON_LOCK_SCREEN, true);
828 shortKeyTimeout_ = static_cast<int32_t>(datashare_->GetIntValue(SHORTCUT_TIMEOUT, SHORT_KEY_TIMEOUT_BEFORE_USE));
829 // for AOS to HMOS
830 if (shortKeyTimeout_ == 1) {
831 SetShortKeyTimeout(SHORT_KEY_TIMEOUT_AFTER_USE);
832 } else if (shortKeyTimeout_ == 0) {
833 SetShortKeyTimeout(SHORT_KEY_TIMEOUT_BEFORE_USE);
834 }
835
836 shortkeyTarget_ = datashare_->GetStringValue("ShortkeyTarget", "none");
837
838 std::string tmpString = datashare_->GetStringValue(SHORTCUT_SERVICE, SCREEN_READER_BUNDLE_ABILITY_NAME);
839 shortkeyMultiTarget_ = {};
840 Utils::StringToVector(tmpString, shortkeyMultiTarget_);
841
842 bool isScreenReaderEnabledOriginal =
843 (std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(),
844 SCREEN_READER_BUNDLE_ABILITY_NAME) != enabledAccessibilityServices_.end());
845 tmpString = datashare_->GetStringValue(ENABLED_ACCESSIBILITY_SERVICES, "");
846 enabledAccessibilityServices_ = {};
847 Utils::StringToVector(tmpString, enabledAccessibilityServices_);
848 CloneShortkeyService(isScreenReaderEnabledOriginal);
849
850 // Initialization of the private space after cloning or upgrade
851 std::shared_ptr<AccessibilitySettingProvider> service = AccessibilitySettingProvider::GetInstance(
852 POWER_MANAGER_SERVICE_ID);
853 if (service == nullptr) {
854 HILOG_ERROR("service is nullptr");
855 return;
856 }
857 bool cloneOrUpgradeFlag = false;
858 service->GetBoolValue(ACCESSIBILITY_PRIVACY_CLONE_OR_UPGRADE, cloneOrUpgradeFlag);
859 if (cloneOrUpgradeFlag && (accountId_ != DEFAULT_ACCOUNT_ID)) {
860 if (isShortKeyState_) {
861 SetShortKeyOnLockScreenState(true);
862 } else {
863 SetShortKeyOnLockScreenState(false);
864 }
865 SetDefaultShortcutKeyService();
866 service->PutBoolValue(ACCESSIBILITY_PRIVACY_CLONE_OR_UPGRADE, false);
867 }
868 }
869
InitSetting()870 void AccessibilitySettingsConfig::InitSetting()
871 {
872 HILOG_DEBUG();
873 if (datashare_ == nullptr) {
874 return;
875 }
876
877 InitShortKeyConfig();
878 CloneAudioState();
879 isScreenMagnificationState_ = datashare_->GetBoolValue(SCREEN_MAGNIFICATION_KEY, false);
880 isMouseKeyState_= datashare_->GetBoolValue(MOUSEKEY, false);
881 animationOffState_ = datashare_->GetBoolValue(ANIMATION_OFF_KEY, false);
882 invertColorState_ = datashare_->GetBoolValue(INVERT_COLOR_KEY, false);
883 highContrastTextState_ = datashare_->GetBoolValue(HIGH_CONTRAST_TEXT_KEY, false);
884 daltonizationState_ = datashare_->GetBoolValue(DALTONIZATION_STATE, false);
885 audioMonoState_ = datashare_->GetBoolValue(AUDIO_MONO_KEY, false);
886 ignoreRepeatClickState_ = datashare_->GetBoolValue(IGNORE_REPEAT_CLICK_SWITCH, false);
887 mouseAutoClick_ = static_cast<int32_t>(datashare_->GetIntValue("MouseAutoClick", -1));
888 daltonizationColorFilter_ = static_cast<uint32_t>(datashare_->GetIntValue(DALTONIZATION_COLOR_FILTER_KEY, 0));
889 SetDaltonizationColorFilter(daltonizationColorFilter_);
890 contentTimeout_ = static_cast<uint32_t>(datashare_->GetIntValue(CONTENT_TIMEOUT_KEY, 0));
891 brightnessDiscount_ = static_cast<float>(datashare_->GetFloatValue(BRIGHTNESS_DISCOUNT_KEY, 1.0));
892 audioBalance_ = static_cast<float>(datashare_->GetFloatValue(AUDIO_BALANCE_KEY, 0));
893 SetAudioBalance(audioBalance_);
894 screenMagnificationType_ = static_cast<uint32_t>(datashare_->GetIntValue(SCREEN_MAGNIFICATION_TYPE, 0));
895 clickResponseTime_ = static_cast<uint32_t>(datashare_->GetIntValue(CLICK_RESPONCE_TIME, 0));
896 SetClickResponseTime(clickResponseTime_);
897 ignoreRepeatClickTime_ = static_cast<uint32_t>(datashare_->GetIntValue(IGNORE_REPEAT_CLICK_TIME, 0));
898 SetIgnoreRepeatClickTime(ignoreRepeatClickTime_);
899 }
900
InitCapability()901 void AccessibilitySettingsConfig::InitCapability()
902 {
903 HILOG_DEBUG();
904 if (datashare_ == nullptr) {
905 return;
906 }
907
908 enabled_ = datashare_->GetBoolValue(ACCESSIBILITY, false);
909 eventTouchGuideState_ = datashare_->GetBoolValue(TOUCH_GUIDE_STATE, false);
910 gesturesSimulation_ = datashare_->GetBoolValue(GESTURE_KEY, false);
911 filteringKeyEvents_ = datashare_->GetBoolValue(KEYEVENT_OBSERVER, false);
912 }
913
SetConfigState(const std::string & key,bool value)914 RetError AccessibilitySettingsConfig::SetConfigState(const std::string& key, bool value)
915 {
916 if (!datashare_) {
917 return RET_ERR_NULLPTR;
918 }
919 return datashare_->PutBoolValue(key, value);
920 }
921
Init()922 void AccessibilitySettingsConfig::Init()
923 {
924 HILOG_DEBUG();
925 datashare_ = std::make_shared<AccessibilityDatashareHelper>(DATASHARE_TYPE::SECURE, accountId_);
926 if (datashare_ == nullptr) {
927 return;
928 }
929 datashare_->Initialize(POWER_MANAGER_SERVICE_ID);
930 InitCaption();
931 InitSetting();
932
933 systemDatashare_ = std::make_shared<AccessibilityDatashareHelper>(DATASHARE_TYPE::SYSTEM, accountId_);
934 if (systemDatashare_ == nullptr) {
935 return;
936 }
937 systemDatashare_->Initialize(POWER_MANAGER_SERVICE_ID);
938 }
939
ClearData()940 void AccessibilitySettingsConfig::ClearData()
941 {
942 HILOG_DEBUG();
943 }
944
CloneAudioState()945 void AccessibilitySettingsConfig::CloneAudioState()
946 {
947 HILOG_DEBUG();
948 if (systemDatashare_ == nullptr) {
949 return;
950 }
951
952 RetError ret = RET_OK;
953 int32_t monoValue = static_cast<int32_t>(systemDatashare_->GetIntValue(AUDIO_MONO_KEY, INVALID_MASTER_MONO_VALUE));
954 if (monoValue != INVALID_MASTER_MONO_VALUE) {
955 SetAudioMonoState(monoValue == 1);
956 ret = systemDatashare_->PutIntValue(AUDIO_MONO_KEY, INVALID_MASTER_MONO_VALUE);
957 if (ret != RET_OK) {
958 HILOG_ERROR("reset monoValue in system table failed");
959 }
960 }
961
962 float audioBalance = static_cast<float>(systemDatashare_->GetFloatValue(AUDIO_BALANCE_KEY,
963 INVALID_MASTER_BALANCE_VALUE));
964 if (audioBalance != INVALID_MASTER_BALANCE_VALUE) {
965 SetAudioBalance(audioBalance);
966 ret = systemDatashare_->PutFloatValue(AUDIO_BALANCE_KEY, INVALID_MASTER_BALANCE_VALUE);
967 if (ret != RET_OK) {
968 HILOG_ERROR("reset audioBalance in system table failed");
969 }
970 }
971 }
972
GetShortKeyService(std::vector<std::string> & services)973 uint32_t AccessibilitySettingsConfig::GetShortKeyService(std::vector<std::string> &services)
974 {
975 uint32_t serviceFlag = 0;
976
977 auto screenReader = std::find_if(services.begin(), services.end(), [&](const std::string& service) {
978 return service.find(SCREENREADER_TAG) != std::string::npos;
979 });
980 serviceFlag = screenReader != services.end() ? STATE_EXPLORATION_ENABLED : serviceFlag;
981
982 auto invertColor = std::find_if(services.begin(), services.end(), [&](const std::string& service) {
983 return service.find(INVERT_COLOR_AOS_TAG) != std::string::npos ||
984 service.find(INVERT_COLOR_HMOS_TAG) != std::string::npos;
985 });
986 serviceFlag = invertColor != services.end() ? (serviceFlag | STATE_INVETRTCOLOR_ENABLED) : serviceFlag;
987
988 auto audioMono = std::find_if(services.begin(), services.end(), [&](const std::string& service) {
989 return service.find(AUDIO_MONO_HMOS_TAG) != std::string::npos;
990 });
991 serviceFlag = audioMono != services.end() ? (serviceFlag | STATE_AUDIOMONO_ENABLED) : serviceFlag;
992
993 auto highContrastText = std::find_if(services.begin(), services.end(), [&](const std::string& service) {
994 return service.find(HIGH_CONTRAST_TEXT_HMOS_TAG) != std::string::npos;
995 });
996 serviceFlag = highContrastText != services.end() ? (serviceFlag | STATE_HIGHCONTRAST_ENABLED) : serviceFlag;
997
998 return serviceFlag;
999 }
1000
CloneShortkeyService(bool isScreenReaderEnabled)1001 void AccessibilitySettingsConfig::CloneShortkeyService(bool isScreenReaderEnabled)
1002 {
1003 std::vector<std::string> tmpVec = GetShortkeyMultiTarget();
1004 uint32_t shortkeyServiceFlag = GetShortKeyService(tmpVec);
1005 std::vector<std::string> shortkeyService;
1006 if (shortkeyServiceFlag & STATE_EXPLORATION_ENABLED) {
1007 shortkeyService.push_back(SCREEN_READER_BUNDLE_ABILITY_NAME);
1008 }
1009 if (shortkeyServiceFlag & STATE_INVETRTCOLOR_ENABLED) {
1010 shortkeyService.push_back(INVERT_COLOR_HMOS_TAG);
1011 }
1012 if (shortkeyServiceFlag & STATE_AUDIOMONO_ENABLED) {
1013 shortkeyService.push_back(AUDIO_MONO_HMOS_TAG);
1014 }
1015 if (shortkeyServiceFlag & STATE_HIGHCONTRAST_ENABLED) {
1016 shortkeyService.push_back(HIGH_CONTRAST_TEXT_HMOS_TAG);
1017 }
1018 SetShortkeyMultiTarget(shortkeyService);
1019
1020 tmpVec = GetEnabledAccessibilityServices();
1021 shortkeyServiceFlag = GetShortKeyService(tmpVec);
1022 std::vector<std::string> enabledShortkeyService;
1023 if ((shortkeyServiceFlag & STATE_EXPLORATION_ENABLED) || (isScreenReaderEnabled == true)) {
1024 enabledShortkeyService.push_back(SCREEN_READER_BUNDLE_ABILITY_NAME);
1025 }
1026 SetEnabledAccessibilityServices(enabledShortkeyService);
1027 }
1028
SetDefaultShortcutKeyService()1029 void AccessibilitySettingsConfig::SetDefaultShortcutKeyService()
1030 {
1031 HILOG_DEBUG();
1032
1033 if (GetShortkeyMultiTarget().empty()) {
1034 HILOG_INFO("set default shortcut key service.");
1035 std::vector<std::string> defaultService;
1036 defaultService.push_back(SCREEN_READER_BUNDLE_ABILITY_NAME);
1037 SetShortkeyMultiTarget(defaultService);
1038 }
1039 }
1040
OnDataClone()1041 void AccessibilitySettingsConfig::OnDataClone()
1042 {
1043 HILOG_INFO();
1044
1045 bool isShortkeyEnabled = GetShortKeyState();
1046 bool isShortkeyEnabledOnLockScreen = GetShortKeyOnLockScreenState();
1047
1048 InitSetting();
1049 SetDefaultShortcutKeyService();
1050
1051 if (isShortKeyState_) {
1052 SetShortKeyOnLockScreenState(true);
1053 } else {
1054 SetShortKeyOnLockScreenState(false);
1055 }
1056
1057 if (isShortkeyEnabled != GetShortKeyState()) {
1058 SetShortKeyState(isShortkeyEnabled);
1059 SetShortKeyState(!isShortkeyEnabled);
1060 }
1061 if (isShortkeyEnabledOnLockScreen != GetShortKeyOnLockScreenState()) {
1062 SetShortKeyOnLockScreenState(isShortkeyEnabledOnLockScreen);
1063 SetShortKeyOnLockScreenState(!isShortkeyEnabledOnLockScreen);
1064 }
1065 Singleton<AccessibleAbilityManagerService>::GetInstance().UpdateShortKeyRegister();
1066
1067 std::shared_ptr<AccessibilitySettingProvider> service =
1068 AccessibilitySettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID);
1069 if (service == nullptr) {
1070 HILOG_ERROR("service is nullptr");
1071 return;
1072 }
1073 bool isScreenReaderEnabled =
1074 (std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(),
1075 SCREEN_READER_BUNDLE_ABILITY_NAME) != enabledAccessibilityServices_.end());
1076 if (isScreenReaderEnabled) {
1077 ErrCode ret = service->PutBoolValue(ACCESSIBILITY_SCREENREADER_ENABLED, true, true);
1078 HILOG_INFO("set screenReader state, ret = %{public}d", ret);
1079 }
1080 service->PutBoolValue(ACCESSIBILITY_PRIVACY_CLONE_OR_UPGRADE, true);
1081 service->PutBoolValue(ACCESSIBILITY_CLONE_FLAG, false);
1082 }
1083 } // namespace Accessibility
1084 } // namespace OHOS