• 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 #include "accessible_ability_manager_service.h"
22 #include "accessibility_account_data.h"
23 #include "parameters.h"
24 #include "accessibility_notification_helper.h"
25 
26 namespace OHOS {
27 namespace Accessibility {
28 namespace {
29     constexpr uint32_t DEFAULT_COLOR = 0xff000000;
30     const int32_t DEFAULT_FONT_SCALE = 100;
31     const int32_t SHORT_KEY_TIMEOUT_AFTER_USE = 1000; // ms
32     const int32_t SHORT_KEY_TIMEOUT_BEFORE_USE = 3000; // ms
33     const int32_t DEFAULT_ACCOUNT_ID = 100;
34     const char* ACCESSIBILITY = "accessibility";
35     const char* TOUCH_GUIDE_STATE = "touch_guide_state";
36     const char* GESTURE_KEY = "gesture_state";
37     const char* CAPTION_KEY = "caption_state";
38     const char* KEYEVENT_OBSERVER = "keyevent_observer";
39     const char* SCREEN_MAGNIFICATION_KEY = "accessibility_display_magnification_enabled";
40     const char* SCREEN_MAGNIFICATION_TYPE = "accessibility_magnification_capability";
41     const char* SCREEN_MAGNIFICATION_MODE = "accessibility_magnification_mode";
42     const char* SCREEN_MAGNIFICATION_SCALE = "accessibility_display_magnification_scale";
43     const char* MOUSEKEY = "mousekey";
44     const char* HIGH_CONTRAST_TEXT_KEY = "high_text_contrast_enabled";
45     const char* DALTONIZATION_STATE = "accessibility_display_daltonizer_enabled";
46     const char* INVERT_COLOR_KEY = "accessibility_display_inversion_enabled";
47     const char* ANIMATION_OFF_KEY = "animation_off";
48     const char* AUDIO_MONO_KEY = "master_mono";
49     const char* IGNORE_REPEAT_CLICK_SWITCH = "ignore_repeat_click_switch";
50     const char* SHORTCUT_ENABLED = "accessibility_shortcut_enabled";
51     const char* SHORTCUT_SERVICE = "accessibility_shortcut_target_service";
52     const char* CLICK_RESPONCE_TIME = "click_response_time";
53     const char* IGNORE_REPEAT_CLICK_TIME = "ignore_repeat_click_time";
54     const char* DALTONIZATION_COLOR_FILTER_KEY = "accessibility_display_daltonizer";
55     const char* CONTENT_TIMEOUT_KEY = "accessibility_content_timeout";
56     const char* BRIGHTNESS_DISCOUNT_KEY = "accessibility_brightness_discount";
57     const char* AUDIO_BALANCE_KEY = "master_balance";
58     const char* FONT_FAMILY = "accessibility_font_family";
59     const char* FONT_COLOR = "accessibility_font_color";
60     const char* FONT_EDGE_TYPE = "accessibility_font_edge_type";
61     const char* BACKGROUND_COLOR = "accessibility_background_color";
62     const char* WINDOW_COLOR = "accessibility_window_color";
63     const char* FONT_SCALE = "accessibility_font_scale";
64     const char* ENABLED_ACCESSIBILITY_SERVICES = "enabled_accessibility_services";
65     const char* SHORTCUT_ENABLED_ON_LOCK_SCREEN = "accessibility_shortcut_enabled_on_lock_screen";
66     const char* SHORTCUT_ON_LOCK_SCREEN = "accessibility_shortcut_on_lock_screen"; // AOS key
67     const char* SHORTCUT_TIMEOUT = "accessibility_shortcut_timeout";
68     const char* ACCESSIBILITY_CLONE_FLAG = "accessibility_config_clone";
69     const char* SCREENREADER_TAG = "screenreader";
70     const char* INVERT_COLOR_AOS_TAG = "ColorInversion";
71     const char* INVERT_COLOR_TAG = "INVERT_COLOR";
72     const char* AUDIO_MONO_TAG = "AUDIO_MONO";
73     const char* HIGH_CONTRAST_TEXT_TAG = "HIGH_CONTRAST_TEXT";
74     const char* SCREEN_READER_BUNDLE_ABILITY_NAME = "com.ohos.screenreader/AccessibilityExtAbility";
75     const char* ACCESSIBILITY_SCREENREADER_ENABLED = "accessibility_screenreader_enabled";
76     const char* ACCESSIBILITY_PRIVACY_CLONE_OR_UPGRADE = "accessibility_privacy_clone_or_upgrade";
77     const char* IGNORE_REPEAT_CLICK_RECONFIRM = "accessibility_ignore_repeat_click_reconfirm";
78     const char* ZOOM_GESTURE_ENABLED_RECONFIRM = "accessibility_zoom_gesture_enabled_reconfirm";
79     const char* GRAPHIC_ANIMATION_SCALE_NAME = "persist.sys.graphic.animationscale";
80     const char* ARKUI_ANIMATION_SCALE_NAME = "persist.sys.arkui.animationscale";
81     const char* FLASH_REMINDER_SWITCH_KEY = "accessibility_flash_reminder_switch";
82     const char* FLASH_REMINDER_ENABLED = "accessibility_reminder_function_enabled";
83     const char* VOICE_RECOGNITION_KEY = "accessibility_sound_recognition_switch";
84     const char* VOICE_RECOGNITION_TYPES = "accessibility_sound_recognition_enabled";
85     const char* IGNORE_REPEAT_CLICK_TIMESTAMP = "accessibility_ignore_repeat_click_timestamp";
86     const char* RECOVERY_IGNORE_REPEAT_CLICK_DATE = "recovery_ignore_repeat_click_switch_date";
87     const char* IGNORE_REPEATED_CLICK_CACHE_FLAG = "accessibility_ignore_repeat_click_cache_flag";
88     constexpr int DOUBLE_CLICK_RESPONSE_TIME_MEDIUM = 300;
89     constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORTEST = 100;
90     constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORT = 400;
91     constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_MEDIUM = 700;
92     constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG = 1000;
93     constexpr int DISPLAY_DALTONIZER_INVALID = -1;
94     constexpr int DISPLAY_DALTONIZER_GREEN = 12;
95     constexpr int DISPLAY_DALTONIZER_RED = 11;
96     constexpr int DISPLAY_DALTONIZER_BLUE = 13;
97     constexpr int INVALID_MASTER_MONO_VALUE = -1;
98     constexpr int AUDIO_BALANCE_STEP = 5;
99     constexpr float INVALID_MASTER_BALANCE_VALUE = 2.0;
100     constexpr int INVALID_SHORTCUT_ON_LOCK_SCREEN_STATE = 2;
101     constexpr uint32_t IGNORE_REPEAT_CLICK_SHORTEST = 0;
102     constexpr uint32_t IGNORE_REPEAT_CLICK_SHORT = 1;
103     constexpr float DEFAULT_MAGNIFICATION_SCALE = 2.0;
104     bool g_ignoreRepeatClickOnceFlag = false;
105 } // namespace
AccessibilitySettingsConfig(int32_t id)106 AccessibilitySettingsConfig::AccessibilitySettingsConfig(int32_t id)
107 {
108     HILOG_DEBUG("id = [%{public}d]", id);
109     accountId_ = id;
110 }
111 
SetEnabled(const bool state)112 RetError AccessibilitySettingsConfig::SetEnabled(const bool state)
113 {
114     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
115     auto ret = SetConfigState(ACCESSIBILITY, state);
116     if (ret != RET_OK) {
117         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetEnabled");
118         HILOG_ERROR("set accessibility failed");
119         return ret;
120     }
121     enabled_ = state;
122     return ret;
123 }
124 
SetTouchGuideState(const bool state)125 RetError AccessibilitySettingsConfig::SetTouchGuideState(const bool state)
126 {
127     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
128     auto ret = SetConfigState(TOUCH_GUIDE_STATE, state);
129     if (ret != RET_OK) {
130         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetTouchGuideState");
131         HILOG_ERROR("set eventTouchGuideState_ failed");
132         return ret;
133     }
134     eventTouchGuideState_ = state;
135     return ret;
136 }
137 
SetGestureState(const bool state)138 RetError AccessibilitySettingsConfig::SetGestureState(const bool state)
139 {
140     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
141     auto ret = SetConfigState(GESTURE_KEY, state);
142     if (ret != RET_OK) {
143         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetGestureState");
144         HILOG_ERROR("set gesturesSimulation_ failed");
145         return ret;
146     }
147     gesturesSimulation_ = state;
148     return ret;
149 }
150 
SetKeyEventObserverState(const bool state)151 RetError AccessibilitySettingsConfig::SetKeyEventObserverState(const bool state)
152 {
153     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
154     auto ret = SetConfigState(KEYEVENT_OBSERVER, state);
155     if (ret != RET_OK) {
156         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetKeyEventObserverState");
157         HILOG_ERROR("set filteringKeyEvents_ failed");
158         return ret;
159     }
160     filteringKeyEvents_ = state;
161     return ret;
162 }
163 
SetCaptionState(const bool state)164 RetError AccessibilitySettingsConfig::SetCaptionState(const bool state)
165 {
166     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
167     auto ret = SetConfigState(CAPTION_KEY, state);
168     if (ret != RET_OK) {
169         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetCaptionState");
170         HILOG_ERROR("set isCaptionState_ failed");
171         return ret;
172     }
173     isCaptionState_ = state;
174     return ret;
175 }
176 
SetScreenMagnificationState(const bool state)177 RetError AccessibilitySettingsConfig::SetScreenMagnificationState(const bool state)
178 {
179     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
180     auto ret = SetConfigState(SCREEN_MAGNIFICATION_KEY, state);
181     if (ret != RET_OK) {
182         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetScreenMagnificationState");
183         HILOG_ERROR("set SetScreenMagnificationState failed");
184         return ret;
185     }
186     SetMagnificationState(state);
187     return ret;
188 }
189 
SetMagnificationState(const bool state)190 RetError AccessibilitySettingsConfig::SetMagnificationState(const bool state)
191 {
192     isScreenMagnificationState_ = state;
193     return RET_OK;
194 }
195 
SetScreenMagnificationType(const uint32_t type)196 RetError AccessibilitySettingsConfig::SetScreenMagnificationType(const uint32_t type)
197 {
198     HILOG_DEBUG("screenMagnificationType = [%{public}u]", type);
199     screenMagnificationType_ = type;
200     return RET_OK;
201 }
202 
SetScreenMagnificationMode(const uint32_t mode)203 RetError AccessibilitySettingsConfig::SetScreenMagnificationMode(const uint32_t mode)
204 {
205     HILOG_DEBUG("screenMagnificationMode = [%{public}u]", mode);
206     screenMagnificationMode_ = mode;
207     return RET_OK;
208 }
209 
SetScreenMagnificationScale(const float scale)210 RetError AccessibilitySettingsConfig::SetScreenMagnificationScale(const float scale)
211 {
212     HILOG_DEBUG("screenMagnificationScale = [%{public}f]", scale);
213     screenMagnificationScale_ = scale;
214     return RET_OK;
215 }
216 
SetShortKeyState(const bool state)217 RetError AccessibilitySettingsConfig::SetShortKeyState(const bool state)
218 {
219     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
220     auto ret = SetConfigState(SHORTCUT_ENABLED, state);
221     if (ret != RET_OK) {
222         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetShortKeyState");
223         HILOG_ERROR("set isShortKeyState_ failed");
224         return ret;
225     }
226     isShortKeyState_ = state;
227     return ret;
228 }
229 
SetShortKeyOnLockScreenState(const bool state)230 RetError AccessibilitySettingsConfig::SetShortKeyOnLockScreenState(const bool state)
231 {
232     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
233     auto ret = SetConfigState(SHORTCUT_ENABLED_ON_LOCK_SCREEN, state);
234     if (ret != RET_OK) {
235         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetShortKeyOnLockScreenState");
236         HILOG_ERROR("set isShortKeyEnabledOnLockScreen_ failed");
237     }
238     return ret;
239 }
240 
SetShortKeyTimeout(const int32_t time)241 RetError AccessibilitySettingsConfig::SetShortKeyTimeout(const int32_t time)
242 {
243     HILOG_DEBUG("time = [%{public}u]", time);
244     if (!datashare_) {
245         HILOG_ERROR("helper is nullptr");
246         return RET_ERR_NULLPTR;
247     }
248 
249     auto ret = datashare_->PutIntValue(SHORTCUT_TIMEOUT, static_cast<int32_t>(time));
250     if (ret != RET_OK) {
251         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetShortKeyTimeout");
252         HILOG_ERROR("set shortKeyTimeout_ failed");
253         return ret;
254     }
255     shortKeyTimeout_ = time;
256     return ret;
257 }
258 
SetStartToHosState(const bool state)259 RetError AccessibilitySettingsConfig::SetStartToHosState(const bool state)
260 {
261     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
262     if (!datashare_) {
263         HILOG_ERROR("helper is nullptr");
264         return RET_ERR_NULLPTR;
265     }
266     auto ret = datashare_->PutBoolValue("AccessibilityStartToHos", state);
267     if (ret != RET_OK) {
268         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetStartToHosState");
269         HILOG_ERROR("set startToHosState failed");
270     }
271     return ret;
272 }
273 
SetMouseKeyState(const bool state)274 RetError AccessibilitySettingsConfig::SetMouseKeyState(const bool state)
275 {
276     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
277     auto ret = SetConfigState(MOUSEKEY, state);
278     if (ret != RET_OK) {
279         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetMouseKeyState");
280         HILOG_ERROR("set isMouseKeyState_ failed");
281         return ret;
282     }
283     isMouseKeyState_ = state;
284     return ret;
285 }
286 
SetMouseAutoClick(const int32_t time)287 RetError AccessibilitySettingsConfig::SetMouseAutoClick(const int32_t time)
288 {
289     HILOG_DEBUG("time = [%{public}d]", time);
290     if (!datashare_) {
291         HILOG_ERROR("helper is nullptr");
292         return RET_ERR_NULLPTR;
293     }
294 
295     auto ret = datashare_->PutIntValue("MouseAutoClick", time);
296     if (ret != RET_OK) {
297         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetMouseAutoClick");
298         HILOG_ERROR("set mouseAutoClick_ failed");
299         return ret;
300     }
301     mouseAutoClick_ = time;
302     return ret;
303 }
304 
SetShortkeyTarget(const std::string & name)305 RetError AccessibilitySettingsConfig::SetShortkeyTarget(const std::string &name)
306 {
307     HILOG_DEBUG("name = [%{public}s]", name.c_str());
308     if (!datashare_) {
309         HILOG_ERROR("helper is nullptr");
310         return RET_ERR_NULLPTR;
311     }
312 
313     auto ret = datashare_->PutStringValue("ShortkeyTarget", name);
314     if (ret != RET_OK) {
315         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetShortkeyTarget");
316         HILOG_ERROR("set shortkeyTarget_ failed");
317         return ret;
318     }
319     shortkeyTarget_ = name;
320     return ret;
321 }
322 
SetShortkeyMultiTarget(const std::vector<std::string> & name)323 RetError AccessibilitySettingsConfig::SetShortkeyMultiTarget(const std::vector<std::string> &name)
324 {
325     HILOG_DEBUG();
326     std::set<std::string> targets;
327     std::copy_if(name.begin(), name.end(), std::inserter(targets, targets.end()),
328         [&targets](const std::string &target) {
329             if (targets.find(target) == targets.end()) {
330                 targets.insert(target);
331                 return true;
332             }
333             return false;
334         });
335     std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
336     if (!datashare_) {
337         HILOG_ERROR("helper is nullptr");
338         return RET_ERR_NULLPTR;
339     }
340 
341     std::string stringOut = "";
342     Utils::VectorToString(std::vector<std::string>(targets.begin(), targets.end()), stringOut);
343     auto ret = datashare_->PutStringValue(SHORTCUT_SERVICE, stringOut);
344     if (ret != RET_OK) {
345         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetShortkeyMultiTarget");
346         HILOG_ERROR("set shortkeyMultiTarget_ failed");
347         return ret;
348     }
349     shortkeyMultiTarget_ = std::vector<std::string>(targets.begin(), targets.end());
350     return ret;
351 }
352 
SetShortkeyMultiTargetInPkgRemove(const std::string & name)353 RetError AccessibilitySettingsConfig::SetShortkeyMultiTargetInPkgRemove(const std::string &name)
354 {
355     HILOG_DEBUG();
356     std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
357     if (!datashare_) {
358         HILOG_ERROR("helper is nullptr");
359         return RET_ERR_NULLPTR;
360     }
361     RetError rtn = RET_OK;
362 
363     for (auto iter = shortkeyMultiTarget_.begin(); iter != shortkeyMultiTarget_.end(); ++iter) {
364         if (*iter == name) {
365             shortkeyMultiTarget_.erase(iter);
366             std::string stringOut = "";
367             Utils::VectorToString(shortkeyMultiTarget_, stringOut);
368             rtn = datashare_->PutStringValue(SHORTCUT_SERVICE, stringOut);
369             break;
370         }
371     }
372     if (rtn != RET_OK) {
373         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetShortkeyMultiTargetInPkgRemove");
374         HILOG_ERROR("set shortkeyMultiTarget_ failed");
375         shortkeyMultiTarget_.push_back(name);
376     }
377     return rtn;
378 }
379 
SetHighContrastTextState(const bool state)380 RetError AccessibilitySettingsConfig::SetHighContrastTextState(const bool state)
381 {
382     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
383     auto ret = SetConfigState(HIGH_CONTRAST_TEXT_KEY, state);
384     if (ret != RET_OK) {
385         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetHighContrastTextState");
386         HILOG_ERROR("set highContrastTextState_ failed");
387         return ret;
388     }
389     highContrastTextState_ = state;
390     return ret;
391 }
392 
SetInvertColorState(const bool state)393 RetError AccessibilitySettingsConfig::SetInvertColorState(const bool state)
394 {
395     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
396     auto ret = SetConfigState(INVERT_COLOR_KEY, state);
397     if (ret != RET_OK) {
398         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetInvertColorState");
399         HILOG_ERROR("set invertColorState_ failed");
400         return ret;
401     }
402     invertColorState_ = state;
403     return ret;
404 }
405 
SetAnimationOffState(const bool state)406 RetError AccessibilitySettingsConfig::SetAnimationOffState(const bool state)
407 {
408     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
409     auto ret = SetConfigState(ANIMATION_OFF_KEY, state);
410     if (ret != RET_OK) {
411         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetAnimationOffState");
412         HILOG_ERROR("set animationOffState_ failed");
413         return ret;
414     }
415     animationOffState_ = state;
416     return ret;
417 }
418 
SetAudioMonoState(const bool state)419 RetError AccessibilitySettingsConfig::SetAudioMonoState(const bool state)
420 {
421     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
422     auto ret = SetConfigState(AUDIO_MONO_KEY, state);
423     if (ret != RET_OK) {
424         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetAudioMonoState");
425         HILOG_ERROR("set audioMonoState_ failed");
426         return ret;
427     }
428     audioMonoState_ = state;
429     return ret;
430 }
431 
SetDaltonizationState(const bool state)432 RetError AccessibilitySettingsConfig::SetDaltonizationState(const bool state)
433 {
434     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
435     auto ret = SetConfigState(DALTONIZATION_STATE, state);
436     if (ret != RET_OK) {
437         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetDaltonizationState");
438         HILOG_ERROR("set daltonizationState_ failed");
439         return ret;
440     }
441     daltonizationState_ = state;
442     return ret;
443 }
444 
SetDaltonizationColorFilter(const uint32_t filter)445 RetError AccessibilitySettingsConfig::SetDaltonizationColorFilter(const uint32_t filter)
446 {
447     HILOG_DEBUG("filter = [%{public}u]", filter);
448     if (!datashare_) {
449         HILOG_ERROR("helper is nullptr");
450         return RET_ERR_NULLPTR;
451     }
452 
453     uint32_t daltonizationColorFilter = filter;
454     if (filter == DISPLAY_DALTONIZER_GREEN) {
455         daltonizationColorFilter = AccessibilityConfig::Deuteranomaly;
456     } else if (filter == DISPLAY_DALTONIZER_RED) {
457         daltonizationColorFilter = AccessibilityConfig::Protanomaly;
458     } else if (filter == DISPLAY_DALTONIZER_BLUE) {
459         daltonizationColorFilter = AccessibilityConfig::Tritanomaly;
460     } else if (filter == static_cast<uint32_t>(DISPLAY_DALTONIZER_INVALID)) {
461         daltonizationColorFilter = 0;
462     }
463     auto ret = datashare_->PutIntValue(DALTONIZATION_COLOR_FILTER_KEY, static_cast<int32_t>(daltonizationColorFilter));
464     if (ret != RET_OK) {
465         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetDaltonizationColorFilter");
466         HILOG_ERROR("set daltonizationColorFilter_ failed");
467         return ret;
468     }
469     daltonizationColorFilter_ = daltonizationColorFilter;
470     return ret;
471 }
472 
473 
SetContentTimeout(const uint32_t time)474 RetError AccessibilitySettingsConfig::SetContentTimeout(const uint32_t time)
475 {
476     HILOG_DEBUG("time = [%{public}u]", time);
477     if (!datashare_) {
478         HILOG_ERROR("helper is nullptr");
479         return RET_ERR_NULLPTR;
480     }
481 
482     auto ret = datashare_->PutIntValue(CONTENT_TIMEOUT_KEY, static_cast<int32_t>(time));
483     if (ret != RET_OK) {
484         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetContentTimeout");
485         HILOG_ERROR("set contentTimeout_ failed");
486         return ret;
487     }
488     contentTimeout_ = time;
489     return ret;
490 }
491 
SetBrightnessDiscount(const float discount)492 RetError AccessibilitySettingsConfig::SetBrightnessDiscount(const float discount)
493 {
494     HILOG_DEBUG("discount = [%{public}f]", discount);
495     if (!datashare_) {
496         HILOG_ERROR("helper is nullptr");
497         return RET_ERR_NULLPTR;
498     }
499 
500     auto ret = datashare_->PutFloatValue(BRIGHTNESS_DISCOUNT_KEY, discount);
501     if (ret != RET_OK) {
502         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetBrightnessDiscount");
503         HILOG_ERROR("set brightnessDiscount_ failed");
504         return ret;
505     }
506     brightnessDiscount_ = discount;
507     return ret;
508 }
509 
SetAudioBalance(const float balance)510 RetError AccessibilitySettingsConfig::SetAudioBalance(const float balance)
511 {
512     HILOG_DEBUG("balance = [%{public}f]", balance);
513     if (!datashare_) {
514         HILOG_ERROR("helper is nullptr");
515         return RET_ERR_NULLPTR;
516     }
517 
518     float audioBalance = round(balance * AUDIO_BALANCE_STEP) / AUDIO_BALANCE_STEP;
519     auto ret = datashare_->PutFloatValue(AUDIO_BALANCE_KEY, audioBalance);
520     if (ret != RET_OK) {
521         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetAudioBalance");
522         HILOG_ERROR("set audioBalance_ failed");
523         return ret;
524     }
525     audioBalance_ = audioBalance;
526     return ret;
527 }
528 
SetClickResponseTime(const uint32_t time)529 RetError AccessibilitySettingsConfig::SetClickResponseTime(const uint32_t time)
530 {
531     HILOG_DEBUG("clickResponseTime = [%{public}u]", time);
532     if (!datashare_) {
533         HILOG_ERROR("helper is nullptr");
534         return RET_ERR_NULLPTR;
535     }
536 
537     uint32_t clickResponseTime = time;
538     if (time == DOUBLE_CLICK_RESPONSE_TIME_MEDIUM) {
539         clickResponseTime = AccessibilityConfig::ResponseDelayMedium;
540     } else if (time > DOUBLE_CLICK_RESPONSE_TIME_MEDIUM) {
541         clickResponseTime = AccessibilityConfig::ResponseDelayLong;
542     }
543     auto ret = datashare_->PutIntValue(CLICK_RESPONCE_TIME, clickResponseTime);
544     if (ret != RET_OK) {
545         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetClickResponseTime");
546         HILOG_ERROR("set clickResponseTime_ failed");
547         return ret;
548     }
549     clickResponseTime_ = clickResponseTime;
550     return ret;
551 }
552 
SetIgnoreRepeatClickState(const bool state)553 RetError AccessibilitySettingsConfig::SetIgnoreRepeatClickState(const bool state)
554 {
555     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
556     auto ret = SetConfigState(IGNORE_REPEAT_CLICK_SWITCH, state);
557     if (ret != RET_OK) {
558         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetIgnoreRepeatClickState");
559         HILOG_ERROR("set ignoreRepeatClickState_ failed");
560         return ret;
561     }
562     if (state) {
563         uint64_t nowTime = IgnoreRepeatClickNotification::GetWallTimeMs();
564         ret = datashare_->PutUnsignedLongValue(IGNORE_REPEAT_CLICK_TIMESTAMP, nowTime);
565         IgnoreRepeatClickNotification::RegisterTimers(nowTime);
566     } else {
567         ret = datashare_->PutUnsignedLongValue(IGNORE_REPEAT_CLICK_TIMESTAMP, 0);
568         IgnoreRepeatClickNotification::DestoryTimers();
569         IgnoreRepeatClickNotification::CancelNotification();
570     }
571     ignoreRepeatClickState_ = state;
572     return ret;
573 }
574 
SetIgnoreRepeatClickReconfirm(const bool state)575 RetError AccessibilitySettingsConfig::SetIgnoreRepeatClickReconfirm(const bool state)
576 {
577     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
578     auto ret = SetConfigState(IGNORE_REPEAT_CLICK_RECONFIRM, state);
579     if (ret != RET_OK) {
580         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetIgnoreRepeatClickReconfirm");
581         HILOG_ERROR("set ignoreRepeatClickReconfirm failed");
582         return ret;
583     }
584     return ret;
585 }
586 
SetZoomGestureEnabledReconfirm(const bool state)587 RetError AccessibilitySettingsConfig::SetZoomGestureEnabledReconfirm(const bool state)
588 {
589     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
590     auto ret = SetConfigState(ZOOM_GESTURE_ENABLED_RECONFIRM, state);
591     if (ret != RET_OK) {
592         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetZoomGestureEnabledReconfirm");
593         HILOG_ERROR("set zoomGestureEnabledReconfirm failed");
594         return ret;
595     }
596     return ret;
597 }
598 
SetColorModeState(const A11yDarkModeType & type)599 RetError AccessibilitySettingsConfig::SetColorModeState(const A11yDarkModeType &type)
600 {
601     uint32_t darkModeValue = static_cast<uint32_t>(type);
602     HILOG_DEBUG("name = [%{public}d]", darkModeValue);
603     if (!systemDatashare_) {
604         HILOG_ERROR("systemDatashare_ is nullptr");
605         return RET_ERR_NULLPTR;
606     }
607 
608     auto ret = systemDatashare_->PutStringValue("settings.uiappearance.darkmode_mode",
609         std::to_string(darkModeValue), true);
610     if (ret != RET_OK) {
611         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetColorModeState");
612         HILOG_ERROR("set SetColorModeState failed");
613     }
614     return ret;
615 }
616 
SetIgnoreRepeatClickTime(const uint32_t time)617 RetError AccessibilitySettingsConfig::SetIgnoreRepeatClickTime(const uint32_t time)
618 {
619     HILOG_DEBUG("ignoreRepeatClickTime = [%{public}u]", time);
620     if (!datashare_) {
621         HILOG_ERROR("helper is nullptr");
622         return RET_ERR_NULLPTR;
623     }
624 
625     uint32_t ignoreRepeatClickTime = time;
626     if (time == DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORTEST) {
627         ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutShortest;
628     } else if (time == DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORT) {
629         ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutShort;
630     } else if (time == DOUBLE_IGNORE_REPEAT_CLICK_TIME_MEDIUM) {
631         ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutMedium;
632     } else if (time == DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG) {
633         ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutLong;
634     } else if (time > DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG) {
635         ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutLongest;
636     }
637     auto ret = datashare_->PutIntValue(IGNORE_REPEAT_CLICK_TIME, ignoreRepeatClickTime);
638     if (ret != RET_OK) {
639         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetIgnoreRepeatClickTime");
640         HILOG_ERROR("set ignoreRepeatClickTime_ failed");
641         return ret;
642     }
643     ignoreRepeatClickTime_ = ignoreRepeatClickTime;
644     return ret;
645 }
646 
SetCaptionProperty(const AccessibilityConfig::CaptionProperty & caption)647 RetError AccessibilitySettingsConfig::SetCaptionProperty(const AccessibilityConfig::CaptionProperty& caption)
648 {
649     HILOG_DEBUG();
650     captionProperty_ = caption;
651     if (!datashare_) {
652         return RET_ERR_NULLPTR;
653     }
654 
655     auto fontFamilyRet = datashare_->PutStringValue(FONT_FAMILY, captionProperty_.GetFontFamily());
656     if (fontFamilyRet != RET_OK) {
657         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetCaptionProperty.fontFamily");
658     }
659     auto fontColorRet = datashare_->PutIntValue(FONT_COLOR, static_cast<int32_t>(captionProperty_.GetFontColor()));
660     if (fontColorRet != RET_OK) {
661         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetCaptionProperty.fontColor");
662     }
663     auto fontEdgeTypeRet = datashare_->PutStringValue(FONT_EDGE_TYPE, captionProperty_.GetFontEdgeType());
664     if (fontEdgeTypeRet != RET_OK) {
665         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetCaptionProperty.fontEdgeType");
666     }
667     auto backgroundColorRet = datashare_->PutIntValue(BACKGROUND_COLOR, static_cast<int32_t>(
668         captionProperty_.GetBackgroundColor()));
669     if (backgroundColorRet != RET_OK) {
670         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetCaptionProperty.backgroundColor");
671     }
672     auto windowColorRet = datashare_->PutIntValue(WINDOW_COLOR, static_cast<int32_t>(
673         captionProperty_.GetWindowColor()));
674     if (windowColorRet != RET_OK) {
675         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetCaptionProperty.windowColor");
676     }
677     auto fontScaleRet = datashare_->PutIntValue(FONT_SCALE, captionProperty_.GetFontScale());
678     if (fontScaleRet != RET_OK) {
679         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetCaptionProperty.fontScale");
680     }
681     return RET_OK;
682 }
683 
GetCaptionState() const684 bool AccessibilitySettingsConfig::GetCaptionState() const
685 {
686     return isCaptionState_;
687 }
688 
GetScreenMagnificationState() const689 bool AccessibilitySettingsConfig::GetScreenMagnificationState() const
690 {
691     return isScreenMagnificationState_;
692 }
693 
GetShortKeyState() const694 bool AccessibilitySettingsConfig::GetShortKeyState() const
695 {
696     return isShortKeyState_;
697 }
698 
GetShortKeyOnLockScreenState() const699 bool AccessibilitySettingsConfig::GetShortKeyOnLockScreenState() const
700 {
701     if (!datashare_) {
702         HILOG_ERROR("datashare is nullptr!");
703         return false;
704     }
705     return datashare_->GetBoolValue(SHORTCUT_ENABLED_ON_LOCK_SCREEN, false);
706 }
707 
GetShortKeyTimeout() const708 int32_t AccessibilitySettingsConfig::GetShortKeyTimeout() const
709 {
710     return shortKeyTimeout_;
711 }
712 
GetMouseKeyState() const713 bool AccessibilitySettingsConfig::GetMouseKeyState() const
714 {
715     return isMouseKeyState_;
716 }
717 
GetMouseAutoClick() const718 int32_t AccessibilitySettingsConfig::GetMouseAutoClick() const
719 {
720     return mouseAutoClick_;
721 }
722 
GetShortkeyTarget() const723 const std::string &AccessibilitySettingsConfig::GetShortkeyTarget() const
724 {
725     return shortkeyTarget_;
726 }
727 
GetShortkeyMultiTarget()728 const std::vector<std::string> AccessibilitySettingsConfig::GetShortkeyMultiTarget()
729 {
730     std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
731     std::vector<std::string> rtnVec = shortkeyMultiTarget_;
732     return rtnVec;
733 }
734 
GetHighContrastTextState() const735 bool AccessibilitySettingsConfig::GetHighContrastTextState() const
736 {
737     return highContrastTextState_;
738 }
739 
GetInvertColorState() const740 bool AccessibilitySettingsConfig::GetInvertColorState() const
741 {
742     return invertColorState_;
743 }
744 
GetAnimationOffState() const745 bool AccessibilitySettingsConfig::GetAnimationOffState() const
746 {
747     return animationOffState_;
748 }
749 
GetAudioMonoState() const750 bool AccessibilitySettingsConfig::GetAudioMonoState() const
751 {
752     return audioMonoState_;
753 }
754 
GetDaltonizationState() const755 bool AccessibilitySettingsConfig::GetDaltonizationState() const
756 {
757     return daltonizationState_;
758 }
759 
GetDaltonizationColorFilter() const760 uint32_t AccessibilitySettingsConfig::GetDaltonizationColorFilter() const
761 {
762     return daltonizationColorFilter_;
763 }
764 
GetContentTimeout() const765 uint32_t AccessibilitySettingsConfig::GetContentTimeout() const
766 {
767     return contentTimeout_;
768 }
769 
GetBrightnessDiscount() const770 float AccessibilitySettingsConfig::GetBrightnessDiscount() const
771 {
772     return brightnessDiscount_;
773 }
774 
GetAudioBalance() const775 float AccessibilitySettingsConfig::GetAudioBalance() const
776 {
777     return audioBalance_;
778 }
779 
GetEnabledState() const780 bool AccessibilitySettingsConfig::GetEnabledState() const
781 {
782     return enabled_;
783 }
784 
GetTouchGuideState() const785 bool AccessibilitySettingsConfig::GetTouchGuideState() const
786 {
787     return eventTouchGuideState_;
788 }
789 
GetGestureState() const790 bool AccessibilitySettingsConfig::GetGestureState() const
791 {
792     return gesturesSimulation_;
793 }
794 
GetKeyEventObserverState() const795 bool AccessibilitySettingsConfig::GetKeyEventObserverState() const
796 {
797     return filteringKeyEvents_;
798 }
799 
GetCaptionProperty() const800 const AccessibilityConfig::CaptionProperty &AccessibilitySettingsConfig::GetCaptionProperty() const
801 {
802     return captionProperty_;
803 };
804 
GetClickResponseTime() const805 uint32_t AccessibilitySettingsConfig::GetClickResponseTime() const
806 {
807     return clickResponseTime_;
808 }
809 
GetScreenMagnificationType() const810 uint32_t AccessibilitySettingsConfig::GetScreenMagnificationType() const
811 {
812     return screenMagnificationType_;
813 }
814 
GetScreenMagnificationMode() const815 uint32_t AccessibilitySettingsConfig::GetScreenMagnificationMode() const
816 {
817     return screenMagnificationMode_;
818 }
819 
GetScreenMagnificationScale() const820 float AccessibilitySettingsConfig::GetScreenMagnificationScale() const
821 {
822     return screenMagnificationScale_;
823 }
824 
GetIgnoreRepeatClickState() const825 bool AccessibilitySettingsConfig::GetIgnoreRepeatClickState() const
826 {
827     return ignoreRepeatClickState_;
828 }
829 
GetIgnoreRepeatClickTime() const830 uint32_t AccessibilitySettingsConfig::GetIgnoreRepeatClickTime() const
831 {
832     return ignoreRepeatClickTime_;
833 }
834 
SetEnabledAccessibilityServices(const std::vector<std::string> & services)835 RetError AccessibilitySettingsConfig::SetEnabledAccessibilityServices(const std::vector<std::string> &services)
836 {
837     std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
838     enabledAccessibilityServices_ = services;
839     if (datashare_ == nullptr) {
840         HILOG_WARN("datashare_ is null.");
841         return RET_ERR_NULLPTR;
842     }
843     std::string stringOut = "";
844     Utils::VectorToString(enabledAccessibilityServices_, stringOut);
845     auto ret = datashare_->PutStringValue(ENABLED_ACCESSIBILITY_SERVICES, stringOut);
846     if (ret != RET_OK) {
847         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "SetEnabledAccessibilityServices");
848         HILOG_ERROR("set enabledAccessibilityServices failed");
849     }
850     return ret;
851 }
852 
GetEnabledAccessibilityServices()853 const std::vector<std::string> AccessibilitySettingsConfig::GetEnabledAccessibilityServices()
854 {
855     std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
856     std::vector<std::string> rtnVec = enabledAccessibilityServices_;
857     return rtnVec;
858 }
859 
AddEnabledAccessibilityService(const std::string & serviceName)860 RetError AccessibilitySettingsConfig::AddEnabledAccessibilityService(const std::string &serviceName)
861 {
862     std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
863     auto iter = std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(), serviceName);
864     if (iter != enabledAccessibilityServices_.end()) {
865         return RET_OK;
866     }
867 
868     if (!datashare_) {
869         return RET_ERR_NULLPTR;
870     }
871     enabledAccessibilityServices_.push_back(serviceName);
872     std::string stringOut = "";
873     Utils::VectorToString(enabledAccessibilityServices_, stringOut);
874     return datashare_->PutStringValue(ENABLED_ACCESSIBILITY_SERVICES, stringOut);
875 }
876 
RemoveEnabledAccessibilityService(const std::string & serviceName)877 RetError AccessibilitySettingsConfig::RemoveEnabledAccessibilityService(const std::string &serviceName)
878 {
879     std::lock_guard<ffrt::mutex> lock(interfaceMutex_);
880     auto iter = std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(), serviceName);
881     if (iter == enabledAccessibilityServices_.end()) {
882         return RET_OK;
883     }
884 
885     if (!datashare_) {
886         return RET_ERR_NULLPTR;
887     }
888     enabledAccessibilityServices_.erase(iter);
889     std::string stringOut = "";
890     Utils::VectorToString(enabledAccessibilityServices_, stringOut);
891     return datashare_->PutStringValue(ENABLED_ACCESSIBILITY_SERVICES, stringOut);
892 }
893 
GetStartToHosState()894 bool AccessibilitySettingsConfig::GetStartToHosState()
895 {
896     HILOG_DEBUG();
897     if (!datashare_) {
898         return RET_ERR_NULLPTR;
899     }
900 
901     bool value = true;
902     value = datashare_->GetBoolValue("AccessibilityStartToHos", true);
903     return value;
904 }
905 
GetConfigState()906 uint32_t AccessibilitySettingsConfig::GetConfigState()
907 {
908     HILOG_DEBUG();
909     uint32_t state = 0;
910     if (isCaptionState_) {
911         state |= STATE_CAPTION_ENABLED;
912     }
913 
914     if (isScreenMagnificationState_) {
915         state |= STATE_SCREENMAGNIFIER_ENABLED;
916     }
917 
918     if (isMouseKeyState_) {
919         state |= STATE_MOUSEKEY_ENABLED;
920     }
921 
922     if (isShortKeyState_) {
923         state |= STATE_SHORTKEY_ENABLED;
924     }
925 
926     if (highContrastTextState_) {
927         state |= STATE_HIGHCONTRAST_ENABLED;
928     }
929 
930     if (daltonizationState_) {
931         state |= STATE_DALTONIZATION_STATE_ENABLED;
932     }
933 
934     if (invertColorState_) {
935         state |= STATE_INVETRTCOLOR_ENABLED;
936     }
937 
938     if (animationOffState_) {
939         state |= STATE_ANIMATIONOFF_ENABLED;
940     }
941 
942     if (audioMonoState_) {
943         state |= STATE_AUDIOMONO_ENABLED;
944     }
945 
946     if (ignoreRepeatClickState_) {
947         state |= STATE_IGNORE_REPEAT_CLICK_ENABLED;
948     }
949     return state;
950 }
951 
InitCaption()952 void AccessibilitySettingsConfig::InitCaption()
953 {
954     HILOG_DEBUG();
955     if (datashare_ == nullptr) {
956         return;
957     }
958 
959     std::string strValue = datashare_->GetStringValue(CAPTION_KEY, "");
960     HILOG_DEBUG(" pref_->GetString() = %{public}s.", strValue.c_str());
961     if (!std::strcmp(strValue.c_str(), "on")) {
962         isCaptionState_ = true;
963     } else {
964         isCaptionState_ = false;
965     }
966 
967     std::string fontFamliy = datashare_->GetStringValue(FONT_FAMILY, "default");
968     HILOG_DEBUG("fontFamily = %{public}s.", fontFamliy.c_str());
969 
970     int32_t fontScale =  static_cast<int32_t>(datashare_->GetIntValue(FONT_SCALE, DEFAULT_FONT_SCALE));
971     HILOG_DEBUG("fontScale = %{public}d.", fontScale);
972 
973     uint32_t fontColor = static_cast<uint32_t>(datashare_->GetIntValue(FONT_COLOR, DEFAULT_COLOR));
974     HILOG_DEBUG("fontColor = 0x%{public}x.", fontColor);
975 
976     std::string fontEdgeType = datashare_->GetStringValue(FONT_EDGE_TYPE, "none");
977     HILOG_DEBUG("fontEdgeType = 0x%{public}s.", fontEdgeType.c_str());
978 
979     uint32_t backgroundColor = static_cast<uint32_t>(datashare_->GetIntValue(BACKGROUND_COLOR, DEFAULT_COLOR));
980     HILOG_DEBUG("backgroundColor = 0x%{public}x.", backgroundColor);
981 
982     uint32_t windowColor = static_cast<uint32_t>(datashare_->GetIntValue(WINDOW_COLOR, DEFAULT_COLOR));
983     HILOG_DEBUG("windowColor = 0x%{public}x.", windowColor);
984 
985     captionProperty_.SetFontFamily(fontFamliy);
986     captionProperty_.SetFontScale(fontScale);
987     captionProperty_.SetFontColor(fontColor);
988     captionProperty_.SetFontEdgeType(fontEdgeType);
989     captionProperty_.SetBackgroundColor(backgroundColor);
990     captionProperty_.SetWindowColor(windowColor);
991 }
992 
InitShortKeyConfig()993 void AccessibilitySettingsConfig::InitShortKeyConfig()
994 {
995     isShortKeyState_ = datashare_->GetBoolValue(SHORTCUT_ENABLED, true);
996     bool isShortKeyEnabledOnLockScreen = datashare_->GetBoolValue(SHORTCUT_ENABLED_ON_LOCK_SCREEN, false);
997     int isShortKeyOnLockScreen = datashare_->GetIntValue(SHORTCUT_ON_LOCK_SCREEN,
998         INVALID_SHORTCUT_ON_LOCK_SCREEN_STATE);
999     shortKeyTimeout_ = static_cast<int32_t>(datashare_->GetIntValue(SHORTCUT_TIMEOUT, SHORT_KEY_TIMEOUT_BEFORE_USE));
1000     bool shortKeyOnLockScreenAutoOn = false;
1001 
1002     if (shortKeyTimeout_ == 1) {
1003         SetShortKeyTimeout(SHORT_KEY_TIMEOUT_AFTER_USE);
1004         if (isShortKeyOnLockScreen == INVALID_SHORTCUT_ON_LOCK_SCREEN_STATE) {
1005             shortKeyOnLockScreenAutoOn = true;
1006             SetShortKeyOnLockScreenState(true);
1007         }
1008     } else if (shortKeyTimeout_ == 0) {
1009         SetShortKeyTimeout(SHORT_KEY_TIMEOUT_BEFORE_USE);
1010     }
1011 
1012     if (isShortKeyOnLockScreen != INVALID_SHORTCUT_ON_LOCK_SCREEN_STATE) {
1013         SetShortKeyOnLockScreenState(isShortKeyOnLockScreen == 1);
1014     } else if (!shortKeyOnLockScreenAutoOn) {
1015         SetShortKeyOnLockScreenState(isShortKeyEnabledOnLockScreen);
1016     }
1017 
1018     auto ret = datashare_->PutIntValue(SHORTCUT_ON_LOCK_SCREEN, INVALID_SHORTCUT_ON_LOCK_SCREEN_STATE);
1019     HILOG_INFO("reset shortcut on lock screen ret = %{public}d", ret);
1020 
1021     shortkeyTarget_ = datashare_->GetStringValue("ShortkeyTarget", "none");
1022 
1023     std::string tmpString = datashare_->GetStringValue(SHORTCUT_SERVICE, SCREEN_READER_BUNDLE_ABILITY_NAME);
1024     shortkeyMultiTarget_ = {};
1025     Utils::StringToVector(tmpString, shortkeyMultiTarget_);
1026 
1027     bool isScreenReaderEnabledOriginal =
1028         (std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(),
1029         SCREEN_READER_BUNDLE_ABILITY_NAME) != enabledAccessibilityServices_.end());
1030     tmpString = datashare_->GetStringValue(ENABLED_ACCESSIBILITY_SERVICES, "");
1031     enabledAccessibilityServices_ = {};
1032     Utils::StringToVector(tmpString, enabledAccessibilityServices_);
1033     CloneShortkeyService(isScreenReaderEnabledOriginal);
1034 }
1035 
InitPrivacySpaceConfig()1036 void AccessibilitySettingsConfig::InitPrivacySpaceConfig()
1037 {
1038     // Initialization of the private space after cloning or upgrade
1039     std::shared_ptr<AccessibilitySettingProvider> service = AccessibilitySettingProvider::GetInstance(
1040         POWER_MANAGER_SERVICE_ID);
1041     if (service == nullptr) {
1042         HILOG_ERROR("service is nullptr");
1043         return;
1044     }
1045     bool cloneOrUpgradeFlag = false;
1046     service->GetBoolValue(ACCESSIBILITY_PRIVACY_CLONE_OR_UPGRADE, cloneOrUpgradeFlag);
1047     if (cloneOrUpgradeFlag && (accountId_ != DEFAULT_ACCOUNT_ID)) {
1048         SetDefaultShortcutKeyService();
1049         SetIgnoreRepeatClickReconfirm(ignoreRepeatClickState_);
1050         SetZoomGestureEnabledReconfirm(isScreenMagnificationState_);
1051         service->PutBoolValue(ACCESSIBILITY_PRIVACY_CLONE_OR_UPGRADE, false);
1052     }
1053 }
1054 
InitAnimationOffConfig()1055 void AccessibilitySettingsConfig::InitAnimationOffConfig()
1056 {
1057     animationOffState_ = datashare_->GetBoolValue(ANIMATION_OFF_KEY, false);
1058     std::string graphicState = system::GetParameter(GRAPHIC_ANIMATION_SCALE_NAME, "1");
1059     std::string arkuiState = system::GetParameter(ARKUI_ANIMATION_SCALE_NAME, "1");
1060     bool state = (graphicState == "0" && arkuiState == "0");
1061     if (animationOffState_) {
1062         system::SetParameter(GRAPHIC_ANIMATION_SCALE_NAME, "0");
1063         system::SetParameter(ARKUI_ANIMATION_SCALE_NAME, "0");
1064     } else if (!animationOffState_ && state) {
1065         system::SetParameter(GRAPHIC_ANIMATION_SCALE_NAME, "1");
1066         system::SetParameter(ARKUI_ANIMATION_SCALE_NAME, "1");
1067     }
1068 }
1069 
HandleIgnoreRepeatClickState()1070 void AccessibilitySettingsConfig::HandleIgnoreRepeatClickState()
1071 {
1072     uint64_t recoveryDate = datashare_->GetUnsignedLongValue(RECOVERY_IGNORE_REPEAT_CLICK_DATE, 0);
1073     if (ignoreRepeatClickState_ && recoveryDate == 0 &&
1074         (ignoreRepeatClickTime_ == IGNORE_REPEAT_CLICK_SHORTEST ||
1075             ignoreRepeatClickTime_ == IGNORE_REPEAT_CLICK_SHORT)) {
1076         ignoreRepeatClickState_ = false;
1077         SetIgnoreRepeatClickState(false);
1078         recoveryDate = IgnoreRepeatClickNotification::GetWallTimeMs();
1079         datashare_->PutUnsignedLongValue(RECOVERY_IGNORE_REPEAT_CLICK_DATE, recoveryDate);
1080         HILOG_INFO("recovery ignore repeat click %{public}" PRIu64, recoveryDate);
1081     }
1082 
1083     if (ignoreRepeatClickState_) {
1084         IgnoreRepeatClickNotification::PublishIgnoreRepeatClickReminder();
1085         uint64_t timeStamp = datashare_->GetUnsignedLongValue(IGNORE_REPEAT_CLICK_TIMESTAMP, 0);
1086         if (timeStamp == 0) {
1087             timeStamp = IgnoreRepeatClickNotification::GetWallTimeMs();
1088             datashare_->PutUnsignedLongValue(IGNORE_REPEAT_CLICK_TIMESTAMP, timeStamp);
1089         }
1090         if (timeStamp > 0) {
1091             IgnoreRepeatClickNotification::RegisterTimers(timeStamp);
1092         }
1093         if (g_ignoreRepeatClickOnceFlag) {
1094             IgnoreRepeatClickNotification::PublishIgnoreRepeatClickReminder();
1095         } else {
1096             g_ignoreRepeatClickOnceFlag = true;
1097         }
1098     }
1099 }
1100 
HandleIgnoreRepeatClickCache()1101 void AccessibilitySettingsConfig::HandleIgnoreRepeatClickCache()
1102 {
1103     bool value = false;
1104     value = datashare_->GetBoolValue(IGNORE_REPEATED_CLICK_CACHE_FLAG, false);
1105     if (value) {
1106         ignoreRepeatClickState_ = true;
1107         datashare_->PutBoolValue(IGNORE_REPEAT_CLICK_SWITCH, true);
1108         datashare_->PutBoolValue(IGNORE_REPEATED_CLICK_CACHE_FLAG, false);
1109     } else {
1110         ignoreRepeatClickState_ = datashare_->GetBoolValue(IGNORE_REPEAT_CLICK_SWITCH, false);
1111     }
1112 }
1113 
InitSetting()1114 void AccessibilitySettingsConfig::InitSetting()
1115 {
1116     HILOG_DEBUG();
1117     if (datashare_ == nullptr) {
1118         return;
1119     }
1120 
1121     InitShortKeyConfig();
1122     InitPrivacySpaceConfig();
1123     InitAnimationOffConfig();
1124     CloneAudioState();
1125     isScreenMagnificationState_ = datashare_->GetBoolValue(SCREEN_MAGNIFICATION_KEY, false);
1126     isMouseKeyState_= datashare_->GetBoolValue(MOUSEKEY, false);
1127     invertColorState_ = datashare_->GetBoolValue(INVERT_COLOR_KEY, false);
1128     highContrastTextState_ = datashare_->GetBoolValue(HIGH_CONTRAST_TEXT_KEY, false);
1129     daltonizationState_ = datashare_->GetBoolValue(DALTONIZATION_STATE, false);
1130     audioMonoState_ = datashare_->GetBoolValue(AUDIO_MONO_KEY, false);
1131     HandleIgnoreRepeatClickCache();
1132     mouseAutoClick_ = static_cast<int32_t>(datashare_->GetIntValue("MouseAutoClick", -1));
1133     daltonizationColorFilter_ = static_cast<uint32_t>(datashare_->GetIntValue(DALTONIZATION_COLOR_FILTER_KEY, 0));
1134     SetDaltonizationColorFilter(daltonizationColorFilter_);
1135     contentTimeout_ = static_cast<uint32_t>(datashare_->GetIntValue(CONTENT_TIMEOUT_KEY, 0));
1136     brightnessDiscount_ = static_cast<float>(datashare_->GetFloatValue(BRIGHTNESS_DISCOUNT_KEY, 1.0));
1137     audioBalance_ = static_cast<float>(datashare_->GetFloatValue(AUDIO_BALANCE_KEY, 0));
1138     SetAudioBalance(audioBalance_);
1139     screenMagnificationType_ = static_cast<uint32_t>(
1140         datashare_->GetIntValue(SCREEN_MAGNIFICATION_TYPE, FULL_SCREEN_MAGNIFICATION));
1141     screenMagnificationMode_ = static_cast<uint32_t>(
1142         datashare_->GetIntValue(SCREEN_MAGNIFICATION_MODE, FULL_SCREEN_MAGNIFICATION));
1143     screenMagnificationScale_ = static_cast<float>(
1144         datashare_->GetFloatValue(SCREEN_MAGNIFICATION_SCALE, DEFAULT_MAGNIFICATION_SCALE));
1145     clickResponseTime_ = static_cast<uint32_t>(datashare_->GetIntValue(CLICK_RESPONCE_TIME, 0));
1146     SetClickResponseTime(clickResponseTime_);
1147     ignoreRepeatClickTime_ = static_cast<uint32_t>(datashare_->GetIntValue(IGNORE_REPEAT_CLICK_TIME, 0));
1148     SetIgnoreRepeatClickTime(ignoreRepeatClickTime_);
1149     datashare_->GetStringValue(FLASH_REMINDER_SWITCH_KEY, "0");
1150     datashare_->GetStringValue(FLASH_REMINDER_ENABLED, "DEFAULT");
1151     datashare_->GetBoolValue(VOICE_RECOGNITION_KEY, false);
1152     datashare_->GetStringValue(VOICE_RECOGNITION_TYPES, "DEFAULT");
1153     HandleIgnoreRepeatClickState();
1154 }
1155 
InitCapability()1156 void AccessibilitySettingsConfig::InitCapability()
1157 {
1158     HILOG_DEBUG();
1159     if (datashare_ == nullptr) {
1160         return;
1161     }
1162 
1163     enabled_ = datashare_->GetBoolValue(ACCESSIBILITY, false);
1164     eventTouchGuideState_ = datashare_->GetBoolValue(TOUCH_GUIDE_STATE, false);
1165     gesturesSimulation_ = datashare_->GetBoolValue(GESTURE_KEY, false);
1166     filteringKeyEvents_ = datashare_->GetBoolValue(KEYEVENT_OBSERVER, false);
1167 }
1168 
SetConfigState(const std::string & key,bool value)1169 RetError AccessibilitySettingsConfig::SetConfigState(const std::string& key, bool value)
1170 {
1171     if (!datashare_) {
1172         return RET_ERR_NULLPTR;
1173     }
1174     auto ret = datashare_->PutBoolValue(key, value);
1175     if (ret != RET_OK) {
1176         HILOG_ERROR("set configState failed");
1177     }
1178     return ret;
1179 }
1180 
Init()1181 void AccessibilitySettingsConfig::Init()
1182 {
1183     HILOG_DEBUG();
1184     datashare_ = std::make_shared<AccessibilityDatashareHelper>(DATASHARE_TYPE::SECURE, accountId_);
1185     if (datashare_ == nullptr) {
1186         return;
1187     }
1188     RetError ret = datashare_->Initialize(POWER_MANAGER_SERVICE_ID);
1189     InitCaption();
1190     InitSetting();
1191 
1192     systemDatashare_ = std::make_shared<AccessibilityDatashareHelper>(DATASHARE_TYPE::SYSTEM, accountId_);
1193     if (systemDatashare_ == nullptr) {
1194         return;
1195     }
1196     RetError systemRet = systemDatashare_->Initialize(POWER_MANAGER_SERVICE_ID);
1197     if (ret == RET_OK && systemRet == RET_OK) {
1198         isInitialized_ = true;
1199     }
1200 }
1201 
ClearData()1202 void AccessibilitySettingsConfig::ClearData()
1203 {
1204     HILOG_DEBUG();
1205 }
1206 
CloneAudioState()1207 void AccessibilitySettingsConfig::CloneAudioState()
1208 {
1209     HILOG_DEBUG();
1210     if (systemDatashare_ == nullptr) {
1211         return;
1212     }
1213 
1214     RetError ret = RET_OK;
1215     int32_t monoValue = static_cast<int32_t>(systemDatashare_->GetIntValue(AUDIO_MONO_KEY, INVALID_MASTER_MONO_VALUE));
1216     if (monoValue != INVALID_MASTER_MONO_VALUE) {
1217         SetAudioMonoState(monoValue == 1);
1218         ret = systemDatashare_->PutIntValue(AUDIO_MONO_KEY, INVALID_MASTER_MONO_VALUE);
1219         if (ret != RET_OK) {
1220             Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "CloneAudioState.monoValue");
1221             HILOG_ERROR("reset monoValue in system table failed");
1222         }
1223     }
1224 
1225     float audioBalance = static_cast<float>(systemDatashare_->GetFloatValue(AUDIO_BALANCE_KEY,
1226         INVALID_MASTER_BALANCE_VALUE));
1227     if (abs(audioBalance - INVALID_MASTER_BALANCE_VALUE) > EPS) {
1228         SetAudioBalance(audioBalance);
1229         ret = systemDatashare_->PutFloatValue(AUDIO_BALANCE_KEY, INVALID_MASTER_BALANCE_VALUE);
1230         if (ret != RET_OK) {
1231             Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "CloneAudioState.audioBalance");
1232             HILOG_ERROR("reset audioBalance in system table failed");
1233         }
1234     }
1235 }
1236 
GetShortKeyService(std::vector<std::string> & services)1237 uint32_t AccessibilitySettingsConfig::GetShortKeyService(std::vector<std::string> &services)
1238 {
1239     uint32_t serviceFlag = 0;
1240 
1241     auto screenReader = std::find_if(services.begin(), services.end(), [&](const std::string& service) {
1242         return service.find(SCREENREADER_TAG) != std::string::npos;
1243     });
1244     serviceFlag = screenReader != services.end() ? STATE_EXPLORATION_ENABLED : serviceFlag;
1245 
1246     auto invertColor = std::find_if(services.begin(), services.end(), [&](const std::string& service) {
1247         return service.find(INVERT_COLOR_AOS_TAG) != std::string::npos ||
1248             service.find(INVERT_COLOR_TAG) != std::string::npos;
1249     });
1250     serviceFlag = invertColor != services.end() ? (serviceFlag | STATE_INVETRTCOLOR_ENABLED) : serviceFlag;
1251 
1252     auto audioMono = std::find_if(services.begin(), services.end(), [&](const std::string& service) {
1253         return service.find(AUDIO_MONO_TAG) != std::string::npos;
1254     });
1255     serviceFlag = audioMono != services.end() ? (serviceFlag | STATE_AUDIOMONO_ENABLED) : serviceFlag;
1256 
1257     auto highContrastText = std::find_if(services.begin(), services.end(), [&](const std::string& service) {
1258         return service.find(HIGH_CONTRAST_TEXT_TAG) != std::string::npos;
1259     });
1260     serviceFlag = highContrastText != services.end() ? (serviceFlag | STATE_HIGHCONTRAST_ENABLED) : serviceFlag;
1261 
1262     return serviceFlag;
1263 }
1264 
CloneShortkeyService(bool isScreenReaderEnabled)1265 void AccessibilitySettingsConfig::CloneShortkeyService(bool isScreenReaderEnabled)
1266 {
1267     std::vector<std::string> tmpVec = GetShortkeyMultiTarget();
1268     uint32_t shortkeyServiceFlag = GetShortKeyService(tmpVec);
1269     std::vector<std::string> shortkeyService;
1270     if (shortkeyServiceFlag & STATE_EXPLORATION_ENABLED) {
1271         shortkeyService.push_back(SCREEN_READER_BUNDLE_ABILITY_NAME);
1272     }
1273     if (shortkeyServiceFlag & STATE_INVETRTCOLOR_ENABLED) {
1274         shortkeyService.push_back(INVERT_COLOR_TAG);
1275     }
1276     if (shortkeyServiceFlag & STATE_AUDIOMONO_ENABLED) {
1277         shortkeyService.push_back(AUDIO_MONO_TAG);
1278     }
1279     if (shortkeyServiceFlag & STATE_HIGHCONTRAST_ENABLED) {
1280         shortkeyService.push_back(HIGH_CONTRAST_TEXT_TAG);
1281     }
1282     SetShortkeyMultiTarget(shortkeyService);
1283 
1284     tmpVec = GetEnabledAccessibilityServices();
1285     shortkeyServiceFlag = GetShortKeyService(tmpVec);
1286     std::vector<std::string> enabledShortkeyService;
1287     if ((shortkeyServiceFlag & STATE_EXPLORATION_ENABLED) || (isScreenReaderEnabled == true)) {
1288         enabledShortkeyService.push_back(SCREEN_READER_BUNDLE_ABILITY_NAME);
1289     }
1290     SetEnabledAccessibilityServices(enabledShortkeyService);
1291 }
1292 
SetDefaultShortcutKeyService()1293 void AccessibilitySettingsConfig::SetDefaultShortcutKeyService()
1294 {
1295     HILOG_DEBUG();
1296 
1297     if (GetShortkeyMultiTarget().empty()) {
1298         HILOG_INFO("set default shortcut key service.");
1299         std::vector<std::string> defaultService;
1300         defaultService.push_back(SCREEN_READER_BUNDLE_ABILITY_NAME);
1301         SetShortkeyMultiTarget(defaultService);
1302     }
1303 }
1304 
OnDataClone()1305 void AccessibilitySettingsConfig::OnDataClone()
1306 {
1307     HILOG_INFO();
1308     if (ignoreRepeatClickState_) {
1309         IgnoreRepeatClickNotification::CancelNotification();
1310     }
1311 
1312     InitSetting();
1313     SetDefaultShortcutKeyService();
1314     SetIgnoreRepeatClickReconfirm(ignoreRepeatClickState_);
1315     SetZoomGestureEnabledReconfirm(isScreenMagnificationState_);
1316 
1317     bool isShortkeyEnabled = GetShortKeyState();
1318     bool isShortkeyEnabledOnLockScreen = GetShortKeyOnLockScreenState();
1319     SetShortKeyState(!isShortkeyEnabled);
1320     SetShortKeyState(isShortkeyEnabled);
1321     SetShortKeyOnLockScreenState(!isShortkeyEnabledOnLockScreen);
1322     SetShortKeyOnLockScreenState(isShortkeyEnabledOnLockScreen);
1323     Singleton<AccessibleAbilityManagerService>::GetInstance().UpdateShortKeyRegister();
1324 
1325     std::shared_ptr<AccessibilitySettingProvider> service =
1326         AccessibilitySettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID);
1327     if (service == nullptr) {
1328         HILOG_ERROR("service is nullptr");
1329         return;
1330     }
1331     bool isScreenReaderEnabled =
1332         (std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(),
1333         SCREEN_READER_BUNDLE_ABILITY_NAME) != enabledAccessibilityServices_.end());
1334     if (isScreenReaderEnabled) {
1335         ErrCode ret = service->PutBoolValue(ACCESSIBILITY_SCREENREADER_ENABLED, true, true);
1336         sptr<AccessibilityAccountData> accountData =
1337             Singleton<AccessibleAbilityManagerService>::GetInstance().GetCurrentAccountData();
1338         accountData->screenReaderState_ = true;
1339         Utils::RecordDatashareInteraction(A11yDatashareValueType::UPDATE, "OnDataClone.screenReader");
1340         HILOG_INFO("set screenReader state, ret = %{public}d", ret);
1341     }
1342     service->PutBoolValue(ACCESSIBILITY_PRIVACY_CLONE_OR_UPGRADE, true);
1343     service->PutBoolValue(ACCESSIBILITY_CLONE_FLAG, false);
1344 }
1345 
GetInitializeState()1346 bool AccessibilitySettingsConfig::GetInitializeState()
1347 {
1348     return isInitialized_;
1349 }
1350 
SetInitializeState(bool isInitialized)1351 void AccessibilitySettingsConfig::SetInitializeState(bool isInitialized)
1352 {
1353     isInitialized_ = isInitialized;
1354 }
1355 
1356 } // namespace Accessibility
1357 } // namespace OHOS