1885b47fbSopenharmony_ci/* 2885b47fbSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3885b47fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4885b47fbSopenharmony_ci * you may not use this file except in compliance with the License. 5885b47fbSopenharmony_ci * You may obtain a copy of the License at 6885b47fbSopenharmony_ci * 7885b47fbSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8885b47fbSopenharmony_ci * 9885b47fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10885b47fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11885b47fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12885b47fbSopenharmony_ci * See the License for the specific language governing permissions and 13885b47fbSopenharmony_ci * limitations under the License. 14885b47fbSopenharmony_ci */ 15885b47fbSopenharmony_ci 16885b47fbSopenharmony_ci#include "accessibility_settings_config.h" 17885b47fbSopenharmony_ci#include "hilog_wrapper.h" 18885b47fbSopenharmony_ci#include "system_ability_definition.h" 19885b47fbSopenharmony_ci#include "utils.h" 20885b47fbSopenharmony_ci#include "accessibility_setting_provider.h" 21885b47fbSopenharmony_ci 22885b47fbSopenharmony_cinamespace OHOS { 23885b47fbSopenharmony_cinamespace Accessibility { 24885b47fbSopenharmony_cinamespace { 25885b47fbSopenharmony_ci constexpr uint32_t DEFAULT_COLOR = 0xff000000; 26885b47fbSopenharmony_ci const int32_t DEFAULT_SCALE = 100; 27885b47fbSopenharmony_ci const int32_t SHORT_KEY_TIMEOUT_AFTER_USE = 1000; // ms 28885b47fbSopenharmony_ci const int32_t SHORT_KEY_TIMEOUT_BEFORE_USE = 3000; // ms 29885b47fbSopenharmony_ci const std::string ACCESSIBILITY = "accessibility"; 30885b47fbSopenharmony_ci const std::string TOUCH_GUIDE_STATE = "touch_guide_state"; 31885b47fbSopenharmony_ci const std::string GESTURE_KEY = "gesture_state"; 32885b47fbSopenharmony_ci const std::string CAPTION_KEY = "caption_state"; 33885b47fbSopenharmony_ci const std::string KEYEVENT_OBSERVER = "keyevent_observer"; 34885b47fbSopenharmony_ci const std::string SCREEN_MAGNIFICATION_KEY = "accessibility_display_magnification_enabled"; 35885b47fbSopenharmony_ci const std::string SCREEN_MAGNIFICATION_TYPE = "accessibility_magnification_capability"; 36885b47fbSopenharmony_ci const std::string MOUSEKEY = "mousekey"; 37885b47fbSopenharmony_ci const std::string HIGH_CONTRAST_TEXT_KEY = "high_text_contrast_enabled"; 38885b47fbSopenharmony_ci const std::string DALTONIZATION_STATE = "accessibility_display_daltonizer_enabled"; 39885b47fbSopenharmony_ci const std::string INVERT_COLOR_KEY = "accessibility_display_inversion_enabled"; 40885b47fbSopenharmony_ci const std::string ANIMATION_OFF_KEY = "animation_off"; 41885b47fbSopenharmony_ci const std::string AUDIO_MONO_KEY = "master_mono"; 42885b47fbSopenharmony_ci const std::string IGNORE_REPEAT_CLICK_SWITCH = "ignore_repeat_click_switch"; 43885b47fbSopenharmony_ci const std::string SHORTCUT_ENABLED = "accessibility_shortcut_enabled"; 44885b47fbSopenharmony_ci const std::string SHORTCUT_SERVICE = "accessibility_shortcut_target_service"; 45885b47fbSopenharmony_ci const std::string CLICK_RESPONCE_TIME = "click_response_time"; 46885b47fbSopenharmony_ci const std::string IGNORE_REPEAT_CLICK_TIME = "ignore_repeat_click_time"; 47885b47fbSopenharmony_ci const std::string DALTONIZATION_COLOR_FILTER_KEY = "accessibility_display_daltonizer"; 48885b47fbSopenharmony_ci const std::string CONTENT_TIMEOUT_KEY = "accessibility_content_timeout"; 49885b47fbSopenharmony_ci const std::string BRIGHTNESS_DISCOUNT_KEY = "accessibility_brightness_discount"; 50885b47fbSopenharmony_ci const std::string AUDIO_BALANCE_KEY = "master_balance"; 51885b47fbSopenharmony_ci const std::string FONT_FAMILY = "accessibility_font_family"; 52885b47fbSopenharmony_ci const std::string FONT_COLOR = "accessibility_font_color"; 53885b47fbSopenharmony_ci const std::string FONT_EDGE_TYPE = "accessibility_font_edge_type"; 54885b47fbSopenharmony_ci const std::string BACKGROUND_COLOR = "accessibility_background_color"; 55885b47fbSopenharmony_ci const std::string WINDOW_COLOR = "accessibility_window_color"; 56885b47fbSopenharmony_ci const std::string FONT_SCALE = "accessibility_font_scale"; 57885b47fbSopenharmony_ci const std::string ENABLED_ACCESSIBILITY_SERVICES = "enabled_accessibility_services"; 58885b47fbSopenharmony_ci const std::string SHORTCUT_ENABLED_ON_LOCK_SCREEN = "accessibility_shortcut_enabled_on_lock_screen"; // HMOS key 59885b47fbSopenharmony_ci const std::string SHORTCUT_ON_LOCK_SCREEN = "accessibility_shortcut_on_lock_screen"; // AOS key 60885b47fbSopenharmony_ci const std::string SHORTCUT_TIMEOUT = "accessibility_shortcut_timeout"; 61885b47fbSopenharmony_ci const std::string ACCESSIBILITY_CLONE_FLAG = "accessibility_config_clone"; 62885b47fbSopenharmony_ci const std::string SCREENREADER_TAG = "screenreader"; 63885b47fbSopenharmony_ci const std::string INVERT_COLOR_AOS_TAG = "ColorInversion"; 64885b47fbSopenharmony_ci const std::string INVERT_COLOR_HMOS_TAG = "INVERT_COLOR"; 65885b47fbSopenharmony_ci const std::string AUDIO_MONO_HMOS_TAG = "AUDIO_MONO"; 66885b47fbSopenharmony_ci const std::string HIGH_CONTRAST_TEXT_HMOS_TAG = "HIGH_CONTRAST_TEXT"; 67885b47fbSopenharmony_ci const std::string SCREEN_READER_BUNDLE_ABILITY_NAME = "com.huawei.hmos.screenreader/AccessibilityExtAbility"; 68885b47fbSopenharmony_ci const std::string ACCESSIBILITY_SCREENREADER_ENABLED = "accessibility_screenreader_enabled"; 69885b47fbSopenharmony_ci constexpr int DOUBLE_CLICK_RESPONSE_TIME_MEDIUM = 300; 70885b47fbSopenharmony_ci constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORT = 400; 71885b47fbSopenharmony_ci constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_MEDIUM = 700; 72885b47fbSopenharmony_ci constexpr int DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG = 1000; 73885b47fbSopenharmony_ci constexpr int DISPLAY_DALTONIZER_GREEN = 12; 74885b47fbSopenharmony_ci constexpr int DISPLAY_DALTONIZER_RED = 11; 75885b47fbSopenharmony_ci constexpr int DISPLAY_DALTONIZER_BLUE = 13; 76885b47fbSopenharmony_ci constexpr int INVALID_MASTER_MONO_VALUE = -1; 77885b47fbSopenharmony_ci constexpr int AUDIO_BALANCE_STEP = 5; 78885b47fbSopenharmony_ci constexpr float INVALID_MASTER_BALANCE_VALUE = 2.0; 79885b47fbSopenharmony_ci constexpr int INVALID_SHORTCUT_ON_LOCK_SCREEN_STATE = 2; 80885b47fbSopenharmony_ci constexpr float EPS = 1e-6; 81885b47fbSopenharmony_ci} // namespace 82885b47fbSopenharmony_ciAccessibilitySettingsConfig::AccessibilitySettingsConfig(int32_t id) 83885b47fbSopenharmony_ci{ 84885b47fbSopenharmony_ci HILOG_DEBUG("id = [%{public}d]", id); 85885b47fbSopenharmony_ci accountId_ = id; 86885b47fbSopenharmony_ci} 87885b47fbSopenharmony_ci 88885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetEnabled(const bool state) 89885b47fbSopenharmony_ci{ 90885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 91885b47fbSopenharmony_ci auto ret = SetConfigState(ACCESSIBILITY, state); 92885b47fbSopenharmony_ci if (ret != RET_OK) { 93885b47fbSopenharmony_ci HILOG_ERROR("set accessibility failed"); 94885b47fbSopenharmony_ci return ret; 95885b47fbSopenharmony_ci } 96885b47fbSopenharmony_ci enabled_ = state; 97885b47fbSopenharmony_ci return ret; 98885b47fbSopenharmony_ci} 99885b47fbSopenharmony_ci 100885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetTouchGuideState(const bool state) 101885b47fbSopenharmony_ci{ 102885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 103885b47fbSopenharmony_ci auto ret = SetConfigState(TOUCH_GUIDE_STATE, state); 104885b47fbSopenharmony_ci if (ret != RET_OK) { 105885b47fbSopenharmony_ci HILOG_ERROR("set eventTouchGuideState_ failed"); 106885b47fbSopenharmony_ci return ret; 107885b47fbSopenharmony_ci } 108885b47fbSopenharmony_ci eventTouchGuideState_ = state; 109885b47fbSopenharmony_ci return ret; 110885b47fbSopenharmony_ci} 111885b47fbSopenharmony_ci 112885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetGestureState(const bool state) 113885b47fbSopenharmony_ci{ 114885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 115885b47fbSopenharmony_ci auto ret = SetConfigState(GESTURE_KEY, state); 116885b47fbSopenharmony_ci if (ret != RET_OK) { 117885b47fbSopenharmony_ci HILOG_ERROR("set gesturesSimulation_ failed"); 118885b47fbSopenharmony_ci return ret; 119885b47fbSopenharmony_ci } 120885b47fbSopenharmony_ci gesturesSimulation_ = state; 121885b47fbSopenharmony_ci return ret; 122885b47fbSopenharmony_ci} 123885b47fbSopenharmony_ci 124885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetKeyEventObserverState(const bool state) 125885b47fbSopenharmony_ci{ 126885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 127885b47fbSopenharmony_ci auto ret = SetConfigState(KEYEVENT_OBSERVER, state); 128885b47fbSopenharmony_ci if (ret != RET_OK) { 129885b47fbSopenharmony_ci HILOG_ERROR("set filteringKeyEvents_ failed"); 130885b47fbSopenharmony_ci return ret; 131885b47fbSopenharmony_ci } 132885b47fbSopenharmony_ci filteringKeyEvents_ = state; 133885b47fbSopenharmony_ci return ret; 134885b47fbSopenharmony_ci} 135885b47fbSopenharmony_ci 136885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetCaptionState(const bool state) 137885b47fbSopenharmony_ci{ 138885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 139885b47fbSopenharmony_ci auto ret = SetConfigState(CAPTION_KEY, state); 140885b47fbSopenharmony_ci if (ret != RET_OK) { 141885b47fbSopenharmony_ci HILOG_ERROR("set isCaptionState_ failed"); 142885b47fbSopenharmony_ci return ret; 143885b47fbSopenharmony_ci } 144885b47fbSopenharmony_ci isCaptionState_ = state; 145885b47fbSopenharmony_ci return ret; 146885b47fbSopenharmony_ci} 147885b47fbSopenharmony_ci 148885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetScreenMagnificationState(const bool state) 149885b47fbSopenharmony_ci{ 150885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 151885b47fbSopenharmony_ci isScreenMagnificationState_ = state; 152885b47fbSopenharmony_ci return RET_OK; 153885b47fbSopenharmony_ci} 154885b47fbSopenharmony_ci 155885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetScreenMagnificationType(const uint32_t type) 156885b47fbSopenharmony_ci{ 157885b47fbSopenharmony_ci HILOG_DEBUG("screenMagnificationType = [%{public}u]", type); 158885b47fbSopenharmony_ci screenMagnificationType_ = type; 159885b47fbSopenharmony_ci return RET_OK; 160885b47fbSopenharmony_ci} 161885b47fbSopenharmony_ci 162885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetShortKeyState(const bool state) 163885b47fbSopenharmony_ci{ 164885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 165885b47fbSopenharmony_ci auto ret = SetConfigState(SHORTCUT_ENABLED, state); 166885b47fbSopenharmony_ci if (ret != RET_OK) { 167885b47fbSopenharmony_ci HILOG_ERROR("set isShortKeyState_ failed"); 168885b47fbSopenharmony_ci return ret; 169885b47fbSopenharmony_ci } 170885b47fbSopenharmony_ci isShortKeyState_ = state; 171885b47fbSopenharmony_ci return ret; 172885b47fbSopenharmony_ci} 173885b47fbSopenharmony_ci 174885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetShortKeyOnLockScreenState(const bool state) 175885b47fbSopenharmony_ci{ 176885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 177885b47fbSopenharmony_ci auto ret = SetConfigState(SHORTCUT_ENABLED_ON_LOCK_SCREEN, state); 178885b47fbSopenharmony_ci if (ret != RET_OK) { 179885b47fbSopenharmony_ci HILOG_ERROR("set isShortKeyEnabledOnLockScreen_ failed"); 180885b47fbSopenharmony_ci return ret; 181885b47fbSopenharmony_ci } 182885b47fbSopenharmony_ci isShortKeyEnabledOnLockScreen_ = state; 183885b47fbSopenharmony_ci return ret; 184885b47fbSopenharmony_ci} 185885b47fbSopenharmony_ci 186885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetShortKeyTimeout(const int32_t time) 187885b47fbSopenharmony_ci{ 188885b47fbSopenharmony_ci HILOG_DEBUG("time = [%{public}u]", time); 189885b47fbSopenharmony_ci if (!datashare_) { 190885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 191885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 192885b47fbSopenharmony_ci } 193885b47fbSopenharmony_ci 194885b47fbSopenharmony_ci auto ret = datashare_->PutIntValue(SHORTCUT_TIMEOUT, static_cast<int32_t>(time)); 195885b47fbSopenharmony_ci if (ret != RET_OK) { 196885b47fbSopenharmony_ci HILOG_ERROR("set shortKeyTimeout_ failed"); 197885b47fbSopenharmony_ci return ret; 198885b47fbSopenharmony_ci } 199885b47fbSopenharmony_ci shortKeyTimeout_ = time; 200885b47fbSopenharmony_ci return ret; 201885b47fbSopenharmony_ci} 202885b47fbSopenharmony_ci 203885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetStartFromAtoHosState(const bool state) 204885b47fbSopenharmony_ci{ 205885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 206885b47fbSopenharmony_ci if (!datashare_) { 207885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 208885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 209885b47fbSopenharmony_ci } 210885b47fbSopenharmony_ci return datashare_->PutBoolValue("AccessibilityStartFromAtoHos", state); 211885b47fbSopenharmony_ci} 212885b47fbSopenharmony_ci 213885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetMouseKeyState(const bool state) 214885b47fbSopenharmony_ci{ 215885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 216885b47fbSopenharmony_ci auto ret = SetConfigState(MOUSEKEY, state); 217885b47fbSopenharmony_ci if (ret != RET_OK) { 218885b47fbSopenharmony_ci HILOG_ERROR("set isMouseKeyState_ failed"); 219885b47fbSopenharmony_ci return ret; 220885b47fbSopenharmony_ci } 221885b47fbSopenharmony_ci isMouseKeyState_ = state; 222885b47fbSopenharmony_ci return ret; 223885b47fbSopenharmony_ci} 224885b47fbSopenharmony_ci 225885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetMouseAutoClick(const int32_t time) 226885b47fbSopenharmony_ci{ 227885b47fbSopenharmony_ci HILOG_DEBUG("time = [%{public}d]", time); 228885b47fbSopenharmony_ci if (!datashare_) { 229885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 230885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 231885b47fbSopenharmony_ci } 232885b47fbSopenharmony_ci 233885b47fbSopenharmony_ci auto ret = datashare_->PutIntValue("MouseAutoClick", time); 234885b47fbSopenharmony_ci if (ret != RET_OK) { 235885b47fbSopenharmony_ci HILOG_ERROR("set mouseAutoClick_ failed"); 236885b47fbSopenharmony_ci return ret; 237885b47fbSopenharmony_ci } 238885b47fbSopenharmony_ci mouseAutoClick_ = time; 239885b47fbSopenharmony_ci return ret; 240885b47fbSopenharmony_ci} 241885b47fbSopenharmony_ci 242885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetShortkeyTarget(const std::string &name) 243885b47fbSopenharmony_ci{ 244885b47fbSopenharmony_ci HILOG_DEBUG("name = [%{public}s]", name.c_str()); 245885b47fbSopenharmony_ci if (!datashare_) { 246885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 247885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 248885b47fbSopenharmony_ci } 249885b47fbSopenharmony_ci 250885b47fbSopenharmony_ci auto ret = datashare_->PutStringValue("ShortkeyTarget", name); 251885b47fbSopenharmony_ci if (ret != RET_OK) { 252885b47fbSopenharmony_ci HILOG_ERROR("set shortkeyTarget_ failed"); 253885b47fbSopenharmony_ci return ret; 254885b47fbSopenharmony_ci } 255885b47fbSopenharmony_ci shortkeyTarget_ = name; 256885b47fbSopenharmony_ci return ret; 257885b47fbSopenharmony_ci} 258885b47fbSopenharmony_ci 259885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetShortkeyMultiTarget(const std::vector<std::string> &name) 260885b47fbSopenharmony_ci{ 261885b47fbSopenharmony_ci HILOG_DEBUG(); 262885b47fbSopenharmony_ci std::set<std::string> targets; 263885b47fbSopenharmony_ci std::copy_if(name.begin(), name.end(), std::inserter(targets, targets.end()), 264885b47fbSopenharmony_ci [&targets](const std::string &target) { 265885b47fbSopenharmony_ci targets.insert(target); 266885b47fbSopenharmony_ci return true; 267885b47fbSopenharmony_ci }); 268885b47fbSopenharmony_ci std::lock_guard<ffrt::mutex> lock(interfaceMutex_); 269885b47fbSopenharmony_ci if (!datashare_) { 270885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 271885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 272885b47fbSopenharmony_ci } 273885b47fbSopenharmony_ci 274885b47fbSopenharmony_ci std::string stringOut = ""; 275885b47fbSopenharmony_ci Utils::VectorToString(std::vector<std::string>(targets.begin(), targets.end()), stringOut); 276885b47fbSopenharmony_ci auto ret = datashare_->PutStringValue(SHORTCUT_SERVICE, stringOut); 277885b47fbSopenharmony_ci if (ret != RET_OK) { 278885b47fbSopenharmony_ci HILOG_ERROR("set shortkeyMultiTarget_ failed"); 279885b47fbSopenharmony_ci return ret; 280885b47fbSopenharmony_ci } 281885b47fbSopenharmony_ci shortkeyMultiTarget_ = std::vector<std::string>(targets.begin(), targets.end()); 282885b47fbSopenharmony_ci return ret; 283885b47fbSopenharmony_ci} 284885b47fbSopenharmony_ci 285885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetShortkeyMultiTargetInPkgRemove(const std::string &name) 286885b47fbSopenharmony_ci{ 287885b47fbSopenharmony_ci HILOG_DEBUG(); 288885b47fbSopenharmony_ci std::lock_guard<ffrt::mutex> lock(interfaceMutex_); 289885b47fbSopenharmony_ci if (!datashare_) { 290885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 291885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 292885b47fbSopenharmony_ci } 293885b47fbSopenharmony_ci RetError rtn = RET_OK; 294885b47fbSopenharmony_ci 295885b47fbSopenharmony_ci for (auto iter = shortkeyMultiTarget_.begin(); iter != shortkeyMultiTarget_.end(); ++iter) { 296885b47fbSopenharmony_ci if (*iter == name) { 297885b47fbSopenharmony_ci shortkeyMultiTarget_.erase(iter); 298885b47fbSopenharmony_ci std::string stringOut = ""; 299885b47fbSopenharmony_ci Utils::VectorToString(shortkeyMultiTarget_, stringOut); 300885b47fbSopenharmony_ci rtn = datashare_->PutStringValue(SHORTCUT_SERVICE, stringOut); 301885b47fbSopenharmony_ci break; 302885b47fbSopenharmony_ci } 303885b47fbSopenharmony_ci } 304885b47fbSopenharmony_ci if (rtn != RET_OK) { 305885b47fbSopenharmony_ci HILOG_ERROR("set shortkeyMultiTarget_ failed"); 306885b47fbSopenharmony_ci shortkeyMultiTarget_.push_back(name); 307885b47fbSopenharmony_ci } 308885b47fbSopenharmony_ci return rtn; 309885b47fbSopenharmony_ci} 310885b47fbSopenharmony_ci 311885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetHighContrastTextState(const bool state) 312885b47fbSopenharmony_ci{ 313885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 314885b47fbSopenharmony_ci auto ret = SetConfigState(HIGH_CONTRAST_TEXT_KEY, state); 315885b47fbSopenharmony_ci if (ret != RET_OK) { 316885b47fbSopenharmony_ci HILOG_ERROR("set highContrastTextState_ failed"); 317885b47fbSopenharmony_ci return ret; 318885b47fbSopenharmony_ci } 319885b47fbSopenharmony_ci highContrastTextState_ = state; 320885b47fbSopenharmony_ci return ret; 321885b47fbSopenharmony_ci} 322885b47fbSopenharmony_ci 323885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetInvertColorState(const bool state) 324885b47fbSopenharmony_ci{ 325885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 326885b47fbSopenharmony_ci auto ret = SetConfigState(INVERT_COLOR_KEY, state); 327885b47fbSopenharmony_ci if (ret != RET_OK) { 328885b47fbSopenharmony_ci HILOG_ERROR("set invertColorState_ failed"); 329885b47fbSopenharmony_ci return ret; 330885b47fbSopenharmony_ci } 331885b47fbSopenharmony_ci invertColorState_ = state; 332885b47fbSopenharmony_ci return ret; 333885b47fbSopenharmony_ci} 334885b47fbSopenharmony_ci 335885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetAnimationOffState(const bool state) 336885b47fbSopenharmony_ci{ 337885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 338885b47fbSopenharmony_ci auto ret = SetConfigState(ANIMATION_OFF_KEY, state); 339885b47fbSopenharmony_ci if (ret != RET_OK) { 340885b47fbSopenharmony_ci HILOG_ERROR("set animationOffState_ failed"); 341885b47fbSopenharmony_ci return ret; 342885b47fbSopenharmony_ci } 343885b47fbSopenharmony_ci animationOffState_ = state; 344885b47fbSopenharmony_ci return ret; 345885b47fbSopenharmony_ci} 346885b47fbSopenharmony_ci 347885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetAudioMonoState(const bool state) 348885b47fbSopenharmony_ci{ 349885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 350885b47fbSopenharmony_ci auto ret = SetConfigState(AUDIO_MONO_KEY, state); 351885b47fbSopenharmony_ci if (ret != RET_OK) { 352885b47fbSopenharmony_ci HILOG_ERROR("set audioMonoState_ failed"); 353885b47fbSopenharmony_ci return ret; 354885b47fbSopenharmony_ci } 355885b47fbSopenharmony_ci audioMonoState_ = state; 356885b47fbSopenharmony_ci return ret; 357885b47fbSopenharmony_ci} 358885b47fbSopenharmony_ci 359885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetDaltonizationState(const bool state) 360885b47fbSopenharmony_ci{ 361885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 362885b47fbSopenharmony_ci auto ret = SetConfigState(DALTONIZATION_STATE, state); 363885b47fbSopenharmony_ci if (ret != RET_OK) { 364885b47fbSopenharmony_ci HILOG_ERROR("set daltonizationState_ failed"); 365885b47fbSopenharmony_ci return ret; 366885b47fbSopenharmony_ci } 367885b47fbSopenharmony_ci daltonizationState_ = state; 368885b47fbSopenharmony_ci return ret; 369885b47fbSopenharmony_ci} 370885b47fbSopenharmony_ci 371885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetDaltonizationColorFilter(const uint32_t filter) 372885b47fbSopenharmony_ci{ 373885b47fbSopenharmony_ci HILOG_DEBUG("filter = [%{public}u]", filter); 374885b47fbSopenharmony_ci if (!datashare_) { 375885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 376885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 377885b47fbSopenharmony_ci } 378885b47fbSopenharmony_ci 379885b47fbSopenharmony_ci uint32_t daltonizationColorFilter = filter; 380885b47fbSopenharmony_ci if (filter == DISPLAY_DALTONIZER_GREEN) { 381885b47fbSopenharmony_ci daltonizationColorFilter = AccessibilityConfig::Deuteranomaly; 382885b47fbSopenharmony_ci } else if (filter == DISPLAY_DALTONIZER_RED) { 383885b47fbSopenharmony_ci daltonizationColorFilter = AccessibilityConfig::Protanomaly; 384885b47fbSopenharmony_ci } else if (filter == DISPLAY_DALTONIZER_BLUE) { 385885b47fbSopenharmony_ci daltonizationColorFilter = AccessibilityConfig::Tritanomaly; 386885b47fbSopenharmony_ci } 387885b47fbSopenharmony_ci auto ret = datashare_->PutIntValue(DALTONIZATION_COLOR_FILTER_KEY, static_cast<int32_t>(daltonizationColorFilter)); 388885b47fbSopenharmony_ci if (ret != RET_OK) { 389885b47fbSopenharmony_ci HILOG_ERROR("set daltonizationColorFilter_ failed"); 390885b47fbSopenharmony_ci return ret; 391885b47fbSopenharmony_ci } 392885b47fbSopenharmony_ci daltonizationColorFilter_ = daltonizationColorFilter; 393885b47fbSopenharmony_ci return ret; 394885b47fbSopenharmony_ci} 395885b47fbSopenharmony_ci 396885b47fbSopenharmony_ci 397885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetContentTimeout(const uint32_t time) 398885b47fbSopenharmony_ci{ 399885b47fbSopenharmony_ci HILOG_DEBUG("time = [%{public}u]", time); 400885b47fbSopenharmony_ci if (!datashare_) { 401885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 402885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 403885b47fbSopenharmony_ci } 404885b47fbSopenharmony_ci 405885b47fbSopenharmony_ci auto ret = datashare_->PutIntValue(CONTENT_TIMEOUT_KEY, static_cast<int32_t>(time)); 406885b47fbSopenharmony_ci if (ret != RET_OK) { 407885b47fbSopenharmony_ci HILOG_ERROR("set contentTimeout_ failed"); 408885b47fbSopenharmony_ci return ret; 409885b47fbSopenharmony_ci } 410885b47fbSopenharmony_ci contentTimeout_ = time; 411885b47fbSopenharmony_ci return ret; 412885b47fbSopenharmony_ci} 413885b47fbSopenharmony_ci 414885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetBrightnessDiscount(const float discount) 415885b47fbSopenharmony_ci{ 416885b47fbSopenharmony_ci HILOG_DEBUG("discount = [%{public}f]", discount); 417885b47fbSopenharmony_ci if (!datashare_) { 418885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 419885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 420885b47fbSopenharmony_ci } 421885b47fbSopenharmony_ci 422885b47fbSopenharmony_ci auto ret = datashare_->PutFloatValue(BRIGHTNESS_DISCOUNT_KEY, discount); 423885b47fbSopenharmony_ci if (ret != RET_OK) { 424885b47fbSopenharmony_ci HILOG_ERROR("set brightnessDiscount_ failed"); 425885b47fbSopenharmony_ci return ret; 426885b47fbSopenharmony_ci } 427885b47fbSopenharmony_ci brightnessDiscount_ = discount; 428885b47fbSopenharmony_ci return ret; 429885b47fbSopenharmony_ci} 430885b47fbSopenharmony_ci 431885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetAudioBalance(const float balance) 432885b47fbSopenharmony_ci{ 433885b47fbSopenharmony_ci HILOG_DEBUG("balance = [%{public}f]", balance); 434885b47fbSopenharmony_ci if (!datashare_) { 435885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 436885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 437885b47fbSopenharmony_ci } 438885b47fbSopenharmony_ci 439885b47fbSopenharmony_ci float audioBalance = round(balance * AUDIO_BALANCE_STEP) / AUDIO_BALANCE_STEP; 440885b47fbSopenharmony_ci auto ret = datashare_->PutFloatValue(AUDIO_BALANCE_KEY, audioBalance); 441885b47fbSopenharmony_ci if (ret != RET_OK) { 442885b47fbSopenharmony_ci HILOG_ERROR("set audioBalance_ failed"); 443885b47fbSopenharmony_ci return ret; 444885b47fbSopenharmony_ci } 445885b47fbSopenharmony_ci audioBalance_ = audioBalance; 446885b47fbSopenharmony_ci return ret; 447885b47fbSopenharmony_ci} 448885b47fbSopenharmony_ci 449885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetClickResponseTime(const uint32_t time) 450885b47fbSopenharmony_ci{ 451885b47fbSopenharmony_ci HILOG_DEBUG("clickResponseTime = [%{public}u]", time); 452885b47fbSopenharmony_ci if (!datashare_) { 453885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 454885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 455885b47fbSopenharmony_ci } 456885b47fbSopenharmony_ci 457885b47fbSopenharmony_ci uint32_t clickResponseTime = time; 458885b47fbSopenharmony_ci if (time == DOUBLE_CLICK_RESPONSE_TIME_MEDIUM) { 459885b47fbSopenharmony_ci clickResponseTime = AccessibilityConfig::ResponseDelayMedium; 460885b47fbSopenharmony_ci } else if (time > DOUBLE_CLICK_RESPONSE_TIME_MEDIUM) { 461885b47fbSopenharmony_ci clickResponseTime = AccessibilityConfig::ResponseDelayLong; 462885b47fbSopenharmony_ci } 463885b47fbSopenharmony_ci auto ret = datashare_->PutIntValue(CLICK_RESPONCE_TIME, clickResponseTime); 464885b47fbSopenharmony_ci if (ret != RET_OK) { 465885b47fbSopenharmony_ci HILOG_ERROR("set clickResponseTime_ failed"); 466885b47fbSopenharmony_ci return ret; 467885b47fbSopenharmony_ci } 468885b47fbSopenharmony_ci clickResponseTime_ = clickResponseTime; 469885b47fbSopenharmony_ci return ret; 470885b47fbSopenharmony_ci} 471885b47fbSopenharmony_ci 472885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetIgnoreRepeatClickState(const bool state) 473885b47fbSopenharmony_ci{ 474885b47fbSopenharmony_ci HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False"); 475885b47fbSopenharmony_ci auto ret = SetConfigState(IGNORE_REPEAT_CLICK_SWITCH, state); 476885b47fbSopenharmony_ci if (ret != RET_OK) { 477885b47fbSopenharmony_ci HILOG_ERROR("set ignoreRepeatClickState_ failed"); 478885b47fbSopenharmony_ci return ret; 479885b47fbSopenharmony_ci } 480885b47fbSopenharmony_ci ignoreRepeatClickState_ = state; 481885b47fbSopenharmony_ci return ret; 482885b47fbSopenharmony_ci} 483885b47fbSopenharmony_ci 484885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetIgnoreRepeatClickTime(const uint32_t time) 485885b47fbSopenharmony_ci{ 486885b47fbSopenharmony_ci HILOG_DEBUG("ignoreRepeatClickTime = [%{public}u]", time); 487885b47fbSopenharmony_ci if (!datashare_) { 488885b47fbSopenharmony_ci HILOG_ERROR("helper is nullptr"); 489885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 490885b47fbSopenharmony_ci } 491885b47fbSopenharmony_ci 492885b47fbSopenharmony_ci uint32_t ignoreRepeatClickTime = time; 493885b47fbSopenharmony_ci if (time == DOUBLE_IGNORE_REPEAT_CLICK_TIME_SHORT) { 494885b47fbSopenharmony_ci ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutShort; 495885b47fbSopenharmony_ci } else if (time == DOUBLE_IGNORE_REPEAT_CLICK_TIME_MEDIUM) { 496885b47fbSopenharmony_ci ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutMedium; 497885b47fbSopenharmony_ci } else if (time == DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG) { 498885b47fbSopenharmony_ci ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutLong; 499885b47fbSopenharmony_ci } else if (time > DOUBLE_IGNORE_REPEAT_CLICK_TIME_LONG) { 500885b47fbSopenharmony_ci ignoreRepeatClickTime = AccessibilityConfig::RepeatClickTimeoutLongest; 501885b47fbSopenharmony_ci } 502885b47fbSopenharmony_ci auto ret = datashare_->PutIntValue(IGNORE_REPEAT_CLICK_TIME, ignoreRepeatClickTime); 503885b47fbSopenharmony_ci if (ret != RET_OK) { 504885b47fbSopenharmony_ci HILOG_ERROR("set ignoreRepeatClickTime_ failed"); 505885b47fbSopenharmony_ci return ret; 506885b47fbSopenharmony_ci } 507885b47fbSopenharmony_ci ignoreRepeatClickTime_ = ignoreRepeatClickTime; 508885b47fbSopenharmony_ci return ret; 509885b47fbSopenharmony_ci} 510885b47fbSopenharmony_ci 511885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetCaptionProperty(const AccessibilityConfig::CaptionProperty& caption) 512885b47fbSopenharmony_ci{ 513885b47fbSopenharmony_ci HILOG_DEBUG(); 514885b47fbSopenharmony_ci captionProperty_ = caption; 515885b47fbSopenharmony_ci if (!datashare_) { 516885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 517885b47fbSopenharmony_ci } 518885b47fbSopenharmony_ci 519885b47fbSopenharmony_ci datashare_->PutStringValue(FONT_FAMILY, captionProperty_.GetFontFamily()); 520885b47fbSopenharmony_ci datashare_->PutIntValue(FONT_COLOR, static_cast<int32_t>(captionProperty_.GetFontColor())); 521885b47fbSopenharmony_ci datashare_->PutStringValue(FONT_EDGE_TYPE, captionProperty_.GetFontEdgeType()); 522885b47fbSopenharmony_ci datashare_->PutIntValue(BACKGROUND_COLOR, static_cast<int32_t>(captionProperty_.GetBackgroundColor())); 523885b47fbSopenharmony_ci datashare_->PutIntValue(WINDOW_COLOR, static_cast<int32_t>(captionProperty_.GetWindowColor())); 524885b47fbSopenharmony_ci datashare_->PutIntValue(FONT_SCALE, captionProperty_.GetFontScale()); 525885b47fbSopenharmony_ci return RET_OK; 526885b47fbSopenharmony_ci} 527885b47fbSopenharmony_ci 528885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetCaptionState() const 529885b47fbSopenharmony_ci{ 530885b47fbSopenharmony_ci return isCaptionState_; 531885b47fbSopenharmony_ci} 532885b47fbSopenharmony_ci 533885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetScreenMagnificationState() const 534885b47fbSopenharmony_ci{ 535885b47fbSopenharmony_ci return isScreenMagnificationState_; 536885b47fbSopenharmony_ci} 537885b47fbSopenharmony_ci 538885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetShortKeyState() const 539885b47fbSopenharmony_ci{ 540885b47fbSopenharmony_ci return isShortKeyState_; 541885b47fbSopenharmony_ci} 542885b47fbSopenharmony_ci 543885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetShortKeyOnLockScreenState() const 544885b47fbSopenharmony_ci{ 545885b47fbSopenharmony_ci return isShortKeyEnabledOnLockScreen_; 546885b47fbSopenharmony_ci} 547885b47fbSopenharmony_ci 548885b47fbSopenharmony_ciint32_t AccessibilitySettingsConfig::GetShortKeyTimeout() const 549885b47fbSopenharmony_ci{ 550885b47fbSopenharmony_ci return shortKeyTimeout_; 551885b47fbSopenharmony_ci} 552885b47fbSopenharmony_ci 553885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetMouseKeyState() const 554885b47fbSopenharmony_ci{ 555885b47fbSopenharmony_ci return isMouseKeyState_; 556885b47fbSopenharmony_ci} 557885b47fbSopenharmony_ci 558885b47fbSopenharmony_ciint32_t AccessibilitySettingsConfig::GetMouseAutoClick() const 559885b47fbSopenharmony_ci{ 560885b47fbSopenharmony_ci return mouseAutoClick_; 561885b47fbSopenharmony_ci} 562885b47fbSopenharmony_ci 563885b47fbSopenharmony_ciconst std::string &AccessibilitySettingsConfig::GetShortkeyTarget() const 564885b47fbSopenharmony_ci{ 565885b47fbSopenharmony_ci return shortkeyTarget_; 566885b47fbSopenharmony_ci} 567885b47fbSopenharmony_ci 568885b47fbSopenharmony_ciconst std::vector<std::string> AccessibilitySettingsConfig::GetShortkeyMultiTarget() 569885b47fbSopenharmony_ci{ 570885b47fbSopenharmony_ci std::lock_guard<ffrt::mutex> lock(interfaceMutex_); 571885b47fbSopenharmony_ci std::vector<std::string> rtnVec = shortkeyMultiTarget_; 572885b47fbSopenharmony_ci return rtnVec; 573885b47fbSopenharmony_ci} 574885b47fbSopenharmony_ci 575885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetHighContrastTextState() const 576885b47fbSopenharmony_ci{ 577885b47fbSopenharmony_ci return highContrastTextState_; 578885b47fbSopenharmony_ci} 579885b47fbSopenharmony_ci 580885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetInvertColorState() const 581885b47fbSopenharmony_ci{ 582885b47fbSopenharmony_ci return invertColorState_; 583885b47fbSopenharmony_ci} 584885b47fbSopenharmony_ci 585885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetAnimationOffState() const 586885b47fbSopenharmony_ci{ 587885b47fbSopenharmony_ci return animationOffState_; 588885b47fbSopenharmony_ci} 589885b47fbSopenharmony_ci 590885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetAudioMonoState() const 591885b47fbSopenharmony_ci{ 592885b47fbSopenharmony_ci return audioMonoState_; 593885b47fbSopenharmony_ci} 594885b47fbSopenharmony_ci 595885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetDaltonizationState() const 596885b47fbSopenharmony_ci{ 597885b47fbSopenharmony_ci return daltonizationState_; 598885b47fbSopenharmony_ci} 599885b47fbSopenharmony_ci 600885b47fbSopenharmony_ciuint32_t AccessibilitySettingsConfig::GetDaltonizationColorFilter() const 601885b47fbSopenharmony_ci{ 602885b47fbSopenharmony_ci return daltonizationColorFilter_; 603885b47fbSopenharmony_ci} 604885b47fbSopenharmony_ci 605885b47fbSopenharmony_ciuint32_t AccessibilitySettingsConfig::GetContentTimeout() const 606885b47fbSopenharmony_ci{ 607885b47fbSopenharmony_ci return contentTimeout_; 608885b47fbSopenharmony_ci} 609885b47fbSopenharmony_ci 610885b47fbSopenharmony_cifloat AccessibilitySettingsConfig::GetBrightnessDiscount() const 611885b47fbSopenharmony_ci{ 612885b47fbSopenharmony_ci return brightnessDiscount_; 613885b47fbSopenharmony_ci} 614885b47fbSopenharmony_ci 615885b47fbSopenharmony_cifloat AccessibilitySettingsConfig::GetAudioBalance() const 616885b47fbSopenharmony_ci{ 617885b47fbSopenharmony_ci return audioBalance_; 618885b47fbSopenharmony_ci} 619885b47fbSopenharmony_ci 620885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetEnabledState() const 621885b47fbSopenharmony_ci{ 622885b47fbSopenharmony_ci return enabled_; 623885b47fbSopenharmony_ci} 624885b47fbSopenharmony_ci 625885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetTouchGuideState() const 626885b47fbSopenharmony_ci{ 627885b47fbSopenharmony_ci return eventTouchGuideState_; 628885b47fbSopenharmony_ci} 629885b47fbSopenharmony_ci 630885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetGestureState() const 631885b47fbSopenharmony_ci{ 632885b47fbSopenharmony_ci return gesturesSimulation_; 633885b47fbSopenharmony_ci} 634885b47fbSopenharmony_ci 635885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetKeyEventObserverState() const 636885b47fbSopenharmony_ci{ 637885b47fbSopenharmony_ci return filteringKeyEvents_; 638885b47fbSopenharmony_ci} 639885b47fbSopenharmony_ci 640885b47fbSopenharmony_ciconst AccessibilityConfig::CaptionProperty &AccessibilitySettingsConfig::GetCaptionProperty() const 641885b47fbSopenharmony_ci{ 642885b47fbSopenharmony_ci return captionProperty_; 643885b47fbSopenharmony_ci}; 644885b47fbSopenharmony_ci 645885b47fbSopenharmony_ciuint32_t AccessibilitySettingsConfig::GetClickResponseTime() const 646885b47fbSopenharmony_ci{ 647885b47fbSopenharmony_ci return clickResponseTime_; 648885b47fbSopenharmony_ci} 649885b47fbSopenharmony_ci 650885b47fbSopenharmony_ciuint32_t AccessibilitySettingsConfig::GetScreenMagnificationType() const 651885b47fbSopenharmony_ci{ 652885b47fbSopenharmony_ci return screenMagnificationType_; 653885b47fbSopenharmony_ci} 654885b47fbSopenharmony_ci 655885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetIgnoreRepeatClickState() const 656885b47fbSopenharmony_ci{ 657885b47fbSopenharmony_ci return ignoreRepeatClickState_; 658885b47fbSopenharmony_ci} 659885b47fbSopenharmony_ci 660885b47fbSopenharmony_ciuint32_t AccessibilitySettingsConfig::GetIgnoreRepeatClickTime() const 661885b47fbSopenharmony_ci{ 662885b47fbSopenharmony_ci return ignoreRepeatClickTime_; 663885b47fbSopenharmony_ci} 664885b47fbSopenharmony_ci 665885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetEnabledAccessibilityServices(const std::vector<std::string> &services) 666885b47fbSopenharmony_ci{ 667885b47fbSopenharmony_ci std::lock_guard<ffrt::mutex> lock(interfaceMutex_); 668885b47fbSopenharmony_ci enabledAccessibilityServices_ = services; 669885b47fbSopenharmony_ci if (datashare_ == nullptr) { 670885b47fbSopenharmony_ci HILOG_WARN("datashare_ is null."); 671885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 672885b47fbSopenharmony_ci } 673885b47fbSopenharmony_ci std::string stringOut = ""; 674885b47fbSopenharmony_ci Utils::VectorToString(enabledAccessibilityServices_, stringOut); 675885b47fbSopenharmony_ci return datashare_->PutStringValue(ENABLED_ACCESSIBILITY_SERVICES, stringOut); 676885b47fbSopenharmony_ci} 677885b47fbSopenharmony_ci 678885b47fbSopenharmony_ciconst std::vector<std::string> AccessibilitySettingsConfig::GetEnabledAccessibilityServices() 679885b47fbSopenharmony_ci{ 680885b47fbSopenharmony_ci std::lock_guard<ffrt::mutex> lock(interfaceMutex_); 681885b47fbSopenharmony_ci std::vector<std::string> rtnVec = enabledAccessibilityServices_; 682885b47fbSopenharmony_ci return rtnVec; 683885b47fbSopenharmony_ci} 684885b47fbSopenharmony_ci 685885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::AddEnabledAccessibilityService(const std::string &serviceName) 686885b47fbSopenharmony_ci{ 687885b47fbSopenharmony_ci std::lock_guard<ffrt::mutex> lock(interfaceMutex_); 688885b47fbSopenharmony_ci auto iter = std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(), serviceName); 689885b47fbSopenharmony_ci if (iter != enabledAccessibilityServices_.end()) { 690885b47fbSopenharmony_ci return RET_OK; 691885b47fbSopenharmony_ci } 692885b47fbSopenharmony_ci 693885b47fbSopenharmony_ci if (!datashare_) { 694885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 695885b47fbSopenharmony_ci } 696885b47fbSopenharmony_ci enabledAccessibilityServices_.push_back(serviceName); 697885b47fbSopenharmony_ci std::string stringOut = ""; 698885b47fbSopenharmony_ci Utils::VectorToString(enabledAccessibilityServices_, stringOut); 699885b47fbSopenharmony_ci return datashare_->PutStringValue(ENABLED_ACCESSIBILITY_SERVICES, stringOut); 700885b47fbSopenharmony_ci} 701885b47fbSopenharmony_ci 702885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::RemoveEnabledAccessibilityService(const std::string &serviceName) 703885b47fbSopenharmony_ci{ 704885b47fbSopenharmony_ci std::lock_guard<ffrt::mutex> lock(interfaceMutex_); 705885b47fbSopenharmony_ci auto iter = std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(), serviceName); 706885b47fbSopenharmony_ci if (iter == enabledAccessibilityServices_.end()) { 707885b47fbSopenharmony_ci return RET_OK; 708885b47fbSopenharmony_ci } 709885b47fbSopenharmony_ci 710885b47fbSopenharmony_ci if (!datashare_) { 711885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 712885b47fbSopenharmony_ci } 713885b47fbSopenharmony_ci enabledAccessibilityServices_.erase(iter); 714885b47fbSopenharmony_ci std::string stringOut = ""; 715885b47fbSopenharmony_ci Utils::VectorToString(enabledAccessibilityServices_, stringOut); 716885b47fbSopenharmony_ci return datashare_->PutStringValue(ENABLED_ACCESSIBILITY_SERVICES, stringOut); 717885b47fbSopenharmony_ci} 718885b47fbSopenharmony_ci 719885b47fbSopenharmony_cibool AccessibilitySettingsConfig::GetStartFromAtoHosState() 720885b47fbSopenharmony_ci{ 721885b47fbSopenharmony_ci HILOG_DEBUG(); 722885b47fbSopenharmony_ci if (!datashare_) { 723885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 724885b47fbSopenharmony_ci } 725885b47fbSopenharmony_ci 726885b47fbSopenharmony_ci bool value = true; 727885b47fbSopenharmony_ci value = datashare_->GetBoolValue("AccessibilityStartFromAtoHos", true); 728885b47fbSopenharmony_ci return value; 729885b47fbSopenharmony_ci} 730885b47fbSopenharmony_ci 731885b47fbSopenharmony_ciuint32_t AccessibilitySettingsConfig::GetConfigState() 732885b47fbSopenharmony_ci{ 733885b47fbSopenharmony_ci HILOG_DEBUG(); 734885b47fbSopenharmony_ci uint32_t state = 0; 735885b47fbSopenharmony_ci if (isCaptionState_) { 736885b47fbSopenharmony_ci state |= STATE_CAPTION_ENABLED; 737885b47fbSopenharmony_ci } 738885b47fbSopenharmony_ci 739885b47fbSopenharmony_ci if (isScreenMagnificationState_) { 740885b47fbSopenharmony_ci state |= STATE_SCREENMAGNIFIER_ENABLED; 741885b47fbSopenharmony_ci } 742885b47fbSopenharmony_ci 743885b47fbSopenharmony_ci if (isMouseKeyState_) { 744885b47fbSopenharmony_ci state |= STATE_MOUSEKEY_ENABLED; 745885b47fbSopenharmony_ci } 746885b47fbSopenharmony_ci 747885b47fbSopenharmony_ci if (isShortKeyState_) { 748885b47fbSopenharmony_ci state |= STATE_SHORTKEY_ENABLED; 749885b47fbSopenharmony_ci } 750885b47fbSopenharmony_ci 751885b47fbSopenharmony_ci if (highContrastTextState_) { 752885b47fbSopenharmony_ci state |= STATE_HIGHCONTRAST_ENABLED; 753885b47fbSopenharmony_ci } 754885b47fbSopenharmony_ci 755885b47fbSopenharmony_ci if (daltonizationState_) { 756885b47fbSopenharmony_ci state |= STATE_DALTONIZATION_STATE_ENABLED; 757885b47fbSopenharmony_ci } 758885b47fbSopenharmony_ci 759885b47fbSopenharmony_ci if (invertColorState_) { 760885b47fbSopenharmony_ci state |= STATE_INVETRTCOLOR_ENABLED; 761885b47fbSopenharmony_ci } 762885b47fbSopenharmony_ci 763885b47fbSopenharmony_ci if (animationOffState_) { 764885b47fbSopenharmony_ci state |= STATE_ANIMATIONOFF_ENABLED; 765885b47fbSopenharmony_ci } 766885b47fbSopenharmony_ci 767885b47fbSopenharmony_ci if (audioMonoState_) { 768885b47fbSopenharmony_ci state |= STATE_AUDIOMONO_ENABLED; 769885b47fbSopenharmony_ci } 770885b47fbSopenharmony_ci 771885b47fbSopenharmony_ci if (ignoreRepeatClickState_) { 772885b47fbSopenharmony_ci state |= STATE_IGNORE_REPEAT_CLICK_ENABLED; 773885b47fbSopenharmony_ci } 774885b47fbSopenharmony_ci return state; 775885b47fbSopenharmony_ci} 776885b47fbSopenharmony_ci 777885b47fbSopenharmony_civoid AccessibilitySettingsConfig::InitCaption() 778885b47fbSopenharmony_ci{ 779885b47fbSopenharmony_ci HILOG_DEBUG(); 780885b47fbSopenharmony_ci if (datashare_ == nullptr) { 781885b47fbSopenharmony_ci return; 782885b47fbSopenharmony_ci } 783885b47fbSopenharmony_ci 784885b47fbSopenharmony_ci std::string strValue = datashare_->GetStringValue(CAPTION_KEY, ""); 785885b47fbSopenharmony_ci HILOG_DEBUG(" pref_->GetString() = %{public}s.", strValue.c_str()); 786885b47fbSopenharmony_ci if (!std::strcmp(strValue.c_str(), "on")) { 787885b47fbSopenharmony_ci isCaptionState_ = true; 788885b47fbSopenharmony_ci } else { 789885b47fbSopenharmony_ci isCaptionState_ = false; 790885b47fbSopenharmony_ci } 791885b47fbSopenharmony_ci 792885b47fbSopenharmony_ci std::string fontFamliy = datashare_->GetStringValue(FONT_FAMILY, "default"); 793885b47fbSopenharmony_ci HILOG_DEBUG("fontFamily = %{public}s.", fontFamliy.c_str()); 794885b47fbSopenharmony_ci 795885b47fbSopenharmony_ci int32_t fontScale = static_cast<int32_t>(datashare_->GetIntValue(FONT_SCALE, DEFAULT_SCALE)); 796885b47fbSopenharmony_ci HILOG_DEBUG("fontScale = %{public}d.", fontScale); 797885b47fbSopenharmony_ci 798885b47fbSopenharmony_ci uint32_t fontColor = static_cast<uint32_t>(datashare_->GetIntValue(FONT_COLOR, DEFAULT_COLOR)); 799885b47fbSopenharmony_ci HILOG_DEBUG("fontColor = 0x%{public}x.", fontColor); 800885b47fbSopenharmony_ci 801885b47fbSopenharmony_ci std::string fontEdgeType = datashare_->GetStringValue(FONT_EDGE_TYPE, "none"); 802885b47fbSopenharmony_ci HILOG_DEBUG("fontEdgeType = 0x%{public}s.", fontEdgeType.c_str()); 803885b47fbSopenharmony_ci 804885b47fbSopenharmony_ci uint32_t backgroundColor = static_cast<uint32_t>(datashare_->GetIntValue(BACKGROUND_COLOR, DEFAULT_COLOR)); 805885b47fbSopenharmony_ci HILOG_DEBUG("backgroundColor = 0x%{public}x.", backgroundColor); 806885b47fbSopenharmony_ci 807885b47fbSopenharmony_ci uint32_t windowColor = static_cast<uint32_t>(datashare_->GetIntValue(WINDOW_COLOR, DEFAULT_COLOR)); 808885b47fbSopenharmony_ci HILOG_DEBUG("windowColor = 0x%{public}x.", windowColor); 809885b47fbSopenharmony_ci 810885b47fbSopenharmony_ci captionProperty_.SetFontFamily(fontFamliy); 811885b47fbSopenharmony_ci captionProperty_.SetFontScale(fontScale); 812885b47fbSopenharmony_ci captionProperty_.SetFontColor(fontColor); 813885b47fbSopenharmony_ci captionProperty_.SetFontEdgeType(fontEdgeType); 814885b47fbSopenharmony_ci captionProperty_.SetBackgroundColor(backgroundColor); 815885b47fbSopenharmony_ci captionProperty_.SetWindowColor(windowColor); 816885b47fbSopenharmony_ci} 817885b47fbSopenharmony_ci 818885b47fbSopenharmony_civoid AccessibilitySettingsConfig::InitShortKeyConfig() 819885b47fbSopenharmony_ci{ 820885b47fbSopenharmony_ci isShortKeyState_ = datashare_->GetBoolValue(SHORTCUT_ENABLED, true); 821885b47fbSopenharmony_ci int isShortKeyEnabledOnLockScreen = datashare_->GetIntValue(SHORTCUT_ENABLED_ON_LOCK_SCREEN, 822885b47fbSopenharmony_ci INVALID_SHORTCUT_ON_LOCK_SCREEN_STATE); 823885b47fbSopenharmony_ci int isShortKeyOnLockScreen = datashare_->GetIntValue(SHORTCUT_ON_LOCK_SCREEN, 824885b47fbSopenharmony_ci INVALID_SHORTCUT_ON_LOCK_SCREEN_STATE); 825885b47fbSopenharmony_ci shortKeyTimeout_ = static_cast<int32_t>(datashare_->GetIntValue(SHORTCUT_TIMEOUT, SHORT_KEY_TIMEOUT_BEFORE_USE)); 826885b47fbSopenharmony_ci bool shortKeyOnLockScreenAutoOn = false; 827885b47fbSopenharmony_ci 828885b47fbSopenharmony_ci if (shortKeyTimeout_ == 1) { 829885b47fbSopenharmony_ci SetShortKeyTimeout(SHORT_KEY_TIMEOUT_AFTER_USE); 830885b47fbSopenharmony_ci if (isShortKeyOnLockScreen == INVALID_SHORTCUT_ON_LOCK_SCREEN_STATE) { 831885b47fbSopenharmony_ci shortKeyOnLockScreenAutoOn = true; 832885b47fbSopenharmony_ci SetShortKeyOnLockScreenState(true); 833885b47fbSopenharmony_ci } 834885b47fbSopenharmony_ci } else if (shortKeyTimeout_ == 0) { 835885b47fbSopenharmony_ci SetShortKeyTimeout(SHORT_KEY_TIMEOUT_BEFORE_USE); 836885b47fbSopenharmony_ci } 837885b47fbSopenharmony_ci 838885b47fbSopenharmony_ci if (isShortKeyOnLockScreen != INVALID_SHORTCUT_ON_LOCK_SCREEN_STATE) { 839885b47fbSopenharmony_ci SetShortKeyOnLockScreenState(isShortKeyOnLockScreen == 1); 840885b47fbSopenharmony_ci } else if (!shortKeyOnLockScreenAutoOn) { 841885b47fbSopenharmony_ci SetShortKeyOnLockScreenState(isShortKeyEnabledOnLockScreen == 1); 842885b47fbSopenharmony_ci } 843885b47fbSopenharmony_ci 844885b47fbSopenharmony_ci auto ret = datashare_->PutIntValue(SHORTCUT_ON_LOCK_SCREEN, INVALID_SHORTCUT_ON_LOCK_SCREEN_STATE); 845885b47fbSopenharmony_ci if (ret != RET_OK) { 846885b47fbSopenharmony_ci HILOG_ERROR("reset shortcut on lock screen failed"); 847885b47fbSopenharmony_ci } 848885b47fbSopenharmony_ci} 849885b47fbSopenharmony_ci 850885b47fbSopenharmony_civoid AccessibilitySettingsConfig::InitSetting() 851885b47fbSopenharmony_ci{ 852885b47fbSopenharmony_ci HILOG_DEBUG(); 853885b47fbSopenharmony_ci if (datashare_ == nullptr) { 854885b47fbSopenharmony_ci return; 855885b47fbSopenharmony_ci } 856885b47fbSopenharmony_ci 857885b47fbSopenharmony_ci InitShortKeyConfig(); 858885b47fbSopenharmony_ci CloneAudioState(); 859885b47fbSopenharmony_ci isScreenMagnificationState_ = datashare_->GetBoolValue(SCREEN_MAGNIFICATION_KEY, false); 860885b47fbSopenharmony_ci isMouseKeyState_= datashare_->GetBoolValue(MOUSEKEY, false); 861885b47fbSopenharmony_ci animationOffState_ = datashare_->GetBoolValue(ANIMATION_OFF_KEY, false); 862885b47fbSopenharmony_ci invertColorState_ = datashare_->GetBoolValue(INVERT_COLOR_KEY, false); 863885b47fbSopenharmony_ci highContrastTextState_ = datashare_->GetBoolValue(HIGH_CONTRAST_TEXT_KEY, false); 864885b47fbSopenharmony_ci daltonizationState_ = datashare_->GetBoolValue(DALTONIZATION_STATE, false); 865885b47fbSopenharmony_ci audioMonoState_ = datashare_->GetBoolValue(AUDIO_MONO_KEY, false); 866885b47fbSopenharmony_ci ignoreRepeatClickState_ = datashare_->GetBoolValue(IGNORE_REPEAT_CLICK_SWITCH, false); 867885b47fbSopenharmony_ci 868885b47fbSopenharmony_ci shortkeyTarget_ = datashare_->GetStringValue("ShortkeyTarget", "none"); 869885b47fbSopenharmony_ci 870885b47fbSopenharmony_ci std::string tmpString = datashare_->GetStringValue(SHORTCUT_SERVICE, SCREEN_READER_BUNDLE_ABILITY_NAME); 871885b47fbSopenharmony_ci shortkeyMultiTarget_ = {}; 872885b47fbSopenharmony_ci Utils::StringToVector(tmpString, shortkeyMultiTarget_); 873885b47fbSopenharmony_ci 874885b47fbSopenharmony_ci bool isScreenReaderEnabledOriginal = 875885b47fbSopenharmony_ci (std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(), 876885b47fbSopenharmony_ci SCREEN_READER_BUNDLE_ABILITY_NAME) != enabledAccessibilityServices_.end()); 877885b47fbSopenharmony_ci tmpString = datashare_->GetStringValue(ENABLED_ACCESSIBILITY_SERVICES, ""); 878885b47fbSopenharmony_ci enabledAccessibilityServices_ = {}; 879885b47fbSopenharmony_ci Utils::StringToVector(tmpString, enabledAccessibilityServices_); 880885b47fbSopenharmony_ci CloneShortkeyService(isScreenReaderEnabledOriginal); 881885b47fbSopenharmony_ci 882885b47fbSopenharmony_ci mouseAutoClick_ = static_cast<int32_t>(datashare_->GetIntValue("MouseAutoClick", -1)); 883885b47fbSopenharmony_ci daltonizationColorFilter_ = static_cast<uint32_t>(datashare_->GetIntValue(DALTONIZATION_COLOR_FILTER_KEY, 0)); 884885b47fbSopenharmony_ci SetDaltonizationColorFilter(daltonizationColorFilter_); 885885b47fbSopenharmony_ci contentTimeout_ = static_cast<uint32_t>(datashare_->GetIntValue(CONTENT_TIMEOUT_KEY, 0)); 886885b47fbSopenharmony_ci brightnessDiscount_ = static_cast<float>(datashare_->GetFloatValue(BRIGHTNESS_DISCOUNT_KEY, 1.0)); 887885b47fbSopenharmony_ci audioBalance_ = static_cast<float>(datashare_->GetFloatValue(AUDIO_BALANCE_KEY, 0)); 888885b47fbSopenharmony_ci SetAudioBalance(audioBalance_); 889885b47fbSopenharmony_ci screenMagnificationType_ = static_cast<uint32_t>(datashare_->GetIntValue(SCREEN_MAGNIFICATION_TYPE, 0)); 890885b47fbSopenharmony_ci clickResponseTime_ = static_cast<uint32_t>(datashare_->GetIntValue(CLICK_RESPONCE_TIME, 0)); 891885b47fbSopenharmony_ci SetClickResponseTime(clickResponseTime_); 892885b47fbSopenharmony_ci ignoreRepeatClickTime_ = static_cast<uint32_t>(datashare_->GetIntValue(IGNORE_REPEAT_CLICK_TIME, 0)); 893885b47fbSopenharmony_ci SetIgnoreRepeatClickTime(ignoreRepeatClickTime_); 894885b47fbSopenharmony_ci} 895885b47fbSopenharmony_ci 896885b47fbSopenharmony_civoid AccessibilitySettingsConfig::InitCapability() 897885b47fbSopenharmony_ci{ 898885b47fbSopenharmony_ci HILOG_DEBUG(); 899885b47fbSopenharmony_ci if (datashare_ == nullptr) { 900885b47fbSopenharmony_ci return; 901885b47fbSopenharmony_ci } 902885b47fbSopenharmony_ci 903885b47fbSopenharmony_ci enabled_ = datashare_->GetBoolValue(ACCESSIBILITY, false); 904885b47fbSopenharmony_ci eventTouchGuideState_ = datashare_->GetBoolValue(TOUCH_GUIDE_STATE, false); 905885b47fbSopenharmony_ci gesturesSimulation_ = datashare_->GetBoolValue(GESTURE_KEY, false); 906885b47fbSopenharmony_ci filteringKeyEvents_ = datashare_->GetBoolValue(KEYEVENT_OBSERVER, false); 907885b47fbSopenharmony_ci} 908885b47fbSopenharmony_ci 909885b47fbSopenharmony_ciRetError AccessibilitySettingsConfig::SetConfigState(const std::string& key, bool value) 910885b47fbSopenharmony_ci{ 911885b47fbSopenharmony_ci if (!datashare_) { 912885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 913885b47fbSopenharmony_ci } 914885b47fbSopenharmony_ci return datashare_->PutBoolValue(key, value); 915885b47fbSopenharmony_ci} 916885b47fbSopenharmony_ci 917885b47fbSopenharmony_civoid AccessibilitySettingsConfig::Init() 918885b47fbSopenharmony_ci{ 919885b47fbSopenharmony_ci HILOG_DEBUG(); 920885b47fbSopenharmony_ci datashare_ = std::make_shared<AccessibilityDatashareHelper>(DATASHARE_TYPE::SECURE, accountId_); 921885b47fbSopenharmony_ci if (datashare_ == nullptr) { 922885b47fbSopenharmony_ci return; 923885b47fbSopenharmony_ci } 924885b47fbSopenharmony_ci datashare_->Initialize(POWER_MANAGER_SERVICE_ID); 925885b47fbSopenharmony_ci InitCaption(); 926885b47fbSopenharmony_ci InitSetting(); 927885b47fbSopenharmony_ci 928885b47fbSopenharmony_ci systemDatashare_ = std::make_shared<AccessibilityDatashareHelper>(DATASHARE_TYPE::SYSTEM, accountId_); 929885b47fbSopenharmony_ci if (systemDatashare_ == nullptr) { 930885b47fbSopenharmony_ci return; 931885b47fbSopenharmony_ci } 932885b47fbSopenharmony_ci systemDatashare_->Initialize(POWER_MANAGER_SERVICE_ID); 933885b47fbSopenharmony_ci} 934885b47fbSopenharmony_ci 935885b47fbSopenharmony_civoid AccessibilitySettingsConfig::ClearData() 936885b47fbSopenharmony_ci{ 937885b47fbSopenharmony_ci HILOG_DEBUG(); 938885b47fbSopenharmony_ci} 939885b47fbSopenharmony_ci 940885b47fbSopenharmony_civoid AccessibilitySettingsConfig::CloneAudioState() 941885b47fbSopenharmony_ci{ 942885b47fbSopenharmony_ci HILOG_DEBUG(); 943885b47fbSopenharmony_ci if (systemDatashare_ == nullptr) { 944885b47fbSopenharmony_ci return; 945885b47fbSopenharmony_ci } 946885b47fbSopenharmony_ci 947885b47fbSopenharmony_ci RetError ret = RET_OK; 948885b47fbSopenharmony_ci int32_t monoValue = static_cast<int32_t>(systemDatashare_->GetIntValue(AUDIO_MONO_KEY, INVALID_MASTER_MONO_VALUE)); 949885b47fbSopenharmony_ci if (monoValue != INVALID_MASTER_MONO_VALUE) { 950885b47fbSopenharmony_ci SetAudioMonoState(monoValue == 1); 951885b47fbSopenharmony_ci ret = systemDatashare_->PutIntValue(AUDIO_MONO_KEY, INVALID_MASTER_MONO_VALUE); 952885b47fbSopenharmony_ci if (ret != RET_OK) { 953885b47fbSopenharmony_ci HILOG_ERROR("reset monoValue in system table failed"); 954885b47fbSopenharmony_ci } 955885b47fbSopenharmony_ci } 956885b47fbSopenharmony_ci 957885b47fbSopenharmony_ci float audioBalance = static_cast<float>(systemDatashare_->GetFloatValue(AUDIO_BALANCE_KEY, 958885b47fbSopenharmony_ci INVALID_MASTER_BALANCE_VALUE)); 959885b47fbSopenharmony_ci if (abs(audioBalance - INVALID_MASTER_BALANCE_VALUE) > EPS) { 960885b47fbSopenharmony_ci SetAudioBalance(audioBalance); 961885b47fbSopenharmony_ci ret = systemDatashare_->PutFloatValue(AUDIO_BALANCE_KEY, INVALID_MASTER_BALANCE_VALUE); 962885b47fbSopenharmony_ci if (ret != RET_OK) { 963885b47fbSopenharmony_ci HILOG_ERROR("reset audioBalance in system table failed"); 964885b47fbSopenharmony_ci } 965885b47fbSopenharmony_ci } 966885b47fbSopenharmony_ci} 967885b47fbSopenharmony_ci 968885b47fbSopenharmony_ciuint32_t AccessibilitySettingsConfig::GetShortKeyService(std::vector<std::string> &services) 969885b47fbSopenharmony_ci{ 970885b47fbSopenharmony_ci uint32_t serviceFlag = 0; 971885b47fbSopenharmony_ci 972885b47fbSopenharmony_ci auto screenReader = std::find_if(services.begin(), services.end(), [&](const std::string& service) { 973885b47fbSopenharmony_ci return service.find(SCREENREADER_TAG) != std::string::npos; 974885b47fbSopenharmony_ci }); 975885b47fbSopenharmony_ci serviceFlag = screenReader != services.end() ? STATE_EXPLORATION_ENABLED : serviceFlag; 976885b47fbSopenharmony_ci 977885b47fbSopenharmony_ci auto invertColor = std::find_if(services.begin(), services.end(), [&](const std::string& service) { 978885b47fbSopenharmony_ci return service.find(INVERT_COLOR_AOS_TAG) != std::string::npos || 979885b47fbSopenharmony_ci service.find(INVERT_COLOR_HMOS_TAG) != std::string::npos; 980885b47fbSopenharmony_ci }); 981885b47fbSopenharmony_ci serviceFlag = invertColor != services.end() ? (serviceFlag | STATE_INVETRTCOLOR_ENABLED) : serviceFlag; 982885b47fbSopenharmony_ci 983885b47fbSopenharmony_ci auto audioMono = std::find_if(services.begin(), services.end(), [&](const std::string& service) { 984885b47fbSopenharmony_ci return service.find(AUDIO_MONO_HMOS_TAG) != std::string::npos; 985885b47fbSopenharmony_ci }); 986885b47fbSopenharmony_ci serviceFlag = audioMono != services.end() ? (serviceFlag | STATE_AUDIOMONO_ENABLED) : serviceFlag; 987885b47fbSopenharmony_ci 988885b47fbSopenharmony_ci auto highContrastText = std::find_if(services.begin(), services.end(), [&](const std::string& service) { 989885b47fbSopenharmony_ci return service.find(HIGH_CONTRAST_TEXT_HMOS_TAG) != std::string::npos; 990885b47fbSopenharmony_ci }); 991885b47fbSopenharmony_ci serviceFlag = highContrastText != services.end() ? (serviceFlag | STATE_HIGHCONTRAST_ENABLED) : serviceFlag; 992885b47fbSopenharmony_ci 993885b47fbSopenharmony_ci return serviceFlag; 994885b47fbSopenharmony_ci} 995885b47fbSopenharmony_ci 996885b47fbSopenharmony_civoid AccessibilitySettingsConfig::CloneShortkeyService(bool isScreenReaderEnabled) 997885b47fbSopenharmony_ci{ 998885b47fbSopenharmony_ci std::vector<std::string> tmpVec = GetShortkeyMultiTarget(); 999885b47fbSopenharmony_ci uint32_t shortkeyServiceFlag = GetShortKeyService(tmpVec); 1000885b47fbSopenharmony_ci std::vector<std::string> shortkeyService; 1001885b47fbSopenharmony_ci if (shortkeyServiceFlag & STATE_EXPLORATION_ENABLED) { 1002885b47fbSopenharmony_ci shortkeyService.push_back(SCREEN_READER_BUNDLE_ABILITY_NAME); 1003885b47fbSopenharmony_ci } 1004885b47fbSopenharmony_ci if (shortkeyServiceFlag & STATE_INVETRTCOLOR_ENABLED) { 1005885b47fbSopenharmony_ci shortkeyService.push_back(INVERT_COLOR_HMOS_TAG); 1006885b47fbSopenharmony_ci } 1007885b47fbSopenharmony_ci if (shortkeyServiceFlag & STATE_AUDIOMONO_ENABLED) { 1008885b47fbSopenharmony_ci shortkeyService.push_back(AUDIO_MONO_HMOS_TAG); 1009885b47fbSopenharmony_ci } 1010885b47fbSopenharmony_ci if (shortkeyServiceFlag & STATE_HIGHCONTRAST_ENABLED) { 1011885b47fbSopenharmony_ci shortkeyService.push_back(HIGH_CONTRAST_TEXT_HMOS_TAG); 1012885b47fbSopenharmony_ci } 1013885b47fbSopenharmony_ci SetShortkeyMultiTarget(shortkeyService); 1014885b47fbSopenharmony_ci 1015885b47fbSopenharmony_ci tmpVec = GetEnabledAccessibilityServices(); 1016885b47fbSopenharmony_ci shortkeyServiceFlag = GetShortKeyService(tmpVec); 1017885b47fbSopenharmony_ci std::vector<std::string> enabledShortkeyService; 1018885b47fbSopenharmony_ci if ((shortkeyServiceFlag & STATE_EXPLORATION_ENABLED) || (isScreenReaderEnabled == true)) { 1019885b47fbSopenharmony_ci enabledShortkeyService.push_back(SCREEN_READER_BUNDLE_ABILITY_NAME); 1020885b47fbSopenharmony_ci } 1021885b47fbSopenharmony_ci SetEnabledAccessibilityServices(enabledShortkeyService); 1022885b47fbSopenharmony_ci} 1023885b47fbSopenharmony_ci 1024885b47fbSopenharmony_civoid AccessibilitySettingsConfig::OnDataClone() 1025885b47fbSopenharmony_ci{ 1026885b47fbSopenharmony_ci HILOG_INFO(); 1027885b47fbSopenharmony_ci InitSetting(); 1028885b47fbSopenharmony_ci 1029885b47fbSopenharmony_ci std::shared_ptr<AccessibilitySettingProvider> service = 1030885b47fbSopenharmony_ci AccessibilitySettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID); 1031885b47fbSopenharmony_ci if (service == nullptr) { 1032885b47fbSopenharmony_ci HILOG_ERROR("service is nullptr"); 1033885b47fbSopenharmony_ci return; 1034885b47fbSopenharmony_ci } 1035885b47fbSopenharmony_ci bool isScreenReaderEnabled = 1036885b47fbSopenharmony_ci (std::find(enabledAccessibilityServices_.begin(), enabledAccessibilityServices_.end(), 1037885b47fbSopenharmony_ci SCREEN_READER_BUNDLE_ABILITY_NAME) != enabledAccessibilityServices_.end()); 1038885b47fbSopenharmony_ci if (isScreenReaderEnabled) { 1039885b47fbSopenharmony_ci ErrCode ret = service->PutBoolValue(ACCESSIBILITY_SCREENREADER_ENABLED, true, true); 1040885b47fbSopenharmony_ci HILOG_INFO("set screenReader state, ret = %{public}d", ret); 1041885b47fbSopenharmony_ci } 1042885b47fbSopenharmony_ci service->PutBoolValue(ACCESSIBILITY_CLONE_FLAG, false); 1043885b47fbSopenharmony_ci} 1044885b47fbSopenharmony_ci} // namespace Accessibility 1045885b47fbSopenharmony_ci} // namespace OHOS