• 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 "utils.h"
19 
20 namespace OHOS {
21 namespace Accessibility {
22 namespace {
23     const std::string PREF_PATH = "/data/service/el1/public/barrierfree/accessibility_ability_manager_service/";
24     constexpr uint32_t DEFAULT_COLOR = 0xff000000;
25 } // namespace
AccessibilitySettingsConfig(int32_t id)26 AccessibilitySettingsConfig::AccessibilitySettingsConfig(int32_t id)
27 {
28     HILOG_DEBUG("id = [%{public}d]", id);
29     accountId_ = id;
30 }
31 
SetEnabled(const bool state)32 bool AccessibilitySettingsConfig::SetEnabled(const bool state)
33 {
34     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
35     enabled_ = state;
36     return SetStatePref(STATE::ACCESSIBILITY);
37 }
38 
SetTouchGuideState(const bool state)39 bool AccessibilitySettingsConfig::SetTouchGuideState(const bool state)
40 {
41     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
42     eventTouchGuideState_ = state;
43     return SetStatePref(STATE::TOUCHGUIDE);
44 }
45 
SetGestureState(const bool state)46 bool AccessibilitySettingsConfig::SetGestureState(const bool state)
47 {
48     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
49     gesturesSimulation_ = state;
50     return SetStatePref(STATE::GESTURE);
51 }
52 
SetKeyEventObserverState(const bool state)53 bool AccessibilitySettingsConfig::SetKeyEventObserverState(const bool state)
54 {
55     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
56     filteringKeyEvents_ = state;
57     return SetStatePref(STATE::KEYEVENT);
58 }
59 
60 
SetCaptionState(const bool state)61 RetError AccessibilitySettingsConfig::SetCaptionState(const bool state)
62 {
63     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
64     isCaptionState_ = state;
65     return SetStatePref(STATE::CAPTION) ? RET_OK : RET_ERR_FAILED;
66 }
67 
SetScreenMagnificationState(const bool state)68 RetError AccessibilitySettingsConfig::SetScreenMagnificationState(const bool state)
69 {
70     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
71     isScreenMagnificationState_ = state;
72     return SetStatePref(STATE::SCREENMAGNIFIER) ? RET_OK : RET_ERR_FAILED;
73 }
74 
SetShortKeyState(const bool state)75 RetError AccessibilitySettingsConfig::SetShortKeyState(const bool state)
76 {
77     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
78     isShortKeyState_ = state;
79     return SetStatePref(STATE::SHORTKEY) ? RET_OK : RET_ERR_FAILED;
80 }
81 
SetMouseKeyState(const bool state)82 RetError AccessibilitySettingsConfig::SetMouseKeyState(const bool state)
83 {
84     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
85     isMouseKeyState_ = state;
86     return SetStatePref(STATE::MOUSEKEY) ? RET_OK : RET_ERR_FAILED;
87 }
88 
SetMouseAutoClick(const int32_t time)89 RetError AccessibilitySettingsConfig::SetMouseAutoClick(const int32_t time)
90 {
91     HILOG_DEBUG("time = [%{public}d]", time);
92     mouseAutoClick_ = time;
93     if (!pref_) {
94         HILOG_ERROR("pref_ is null!");
95         return RET_ERR_NULLPTR;
96     }
97 
98     pref_->PutInt("MouseAutoClick", mouseAutoClick_);
99     pref_->Flush();
100     return RET_OK;
101 }
102 
SetShortkeyTarget(const std::string & name)103 RetError AccessibilitySettingsConfig::SetShortkeyTarget(const std::string &name)
104 {
105     HILOG_DEBUG("name = [%{public}s]", name.c_str());
106     shortkeyTarget_ = name;
107     if (!pref_) {
108         HILOG_ERROR("pref_ is null!");
109         return RET_ERR_NULLPTR;
110     }
111 
112     pref_->PutString("ShortkeyTarget", shortkeyTarget_);
113     pref_->Flush();
114     return RET_OK;
115 }
116 
SetHighContrastTextState(const bool state)117 RetError AccessibilitySettingsConfig::SetHighContrastTextState(const bool state)
118 {
119     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
120     highContrastTextState_ = state;
121     return SetStatePref(STATE::HIGHCONTRASTTEXT) ? RET_OK : RET_ERR_FAILED;
122 }
123 
SetInvertColorState(const bool state)124 RetError AccessibilitySettingsConfig::SetInvertColorState(const bool state)
125 {
126     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
127     invertColorState_ = state;
128     return SetStatePref(STATE::INVERTCOLORSTATE) ? RET_OK : RET_ERR_FAILED;
129 }
130 
SetAnimationOffState(const bool state)131 RetError AccessibilitySettingsConfig::SetAnimationOffState(const bool state)
132 {
133     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
134     animationOffState_ = state;
135     return SetStatePref(STATE::ANIMATIONOFF) ? RET_OK : RET_ERR_FAILED;
136 }
137 
SetAudioMonoState(const bool state)138 RetError AccessibilitySettingsConfig::SetAudioMonoState(const bool state)
139 {
140     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
141     audioMonoState_ = state;
142     return SetStatePref(STATE::AUDIOMONO) ? RET_OK : RET_ERR_FAILED;
143 }
144 
SetDaltonizationColorFilter(const uint32_t filter)145 RetError AccessibilitySettingsConfig::SetDaltonizationColorFilter(const uint32_t filter)
146 {
147     HILOG_DEBUG("filter = [%{public}u]", filter);
148     daltonizationColorFilter_ = filter;
149     if (!pref_) {
150         HILOG_ERROR("pref_ is null!");
151         return RET_ERR_NULLPTR;
152     }
153 
154     pref_->PutInt("daltonizationColorFilter", static_cast<int32_t>(daltonizationColorFilter_));
155     pref_->Flush();
156     return RET_OK;
157 }
158 
SetContentTimeout(const uint32_t time)159 RetError AccessibilitySettingsConfig::SetContentTimeout(const uint32_t time)
160 {
161     HILOG_DEBUG("time = [%{public}u]", time);
162     contentTimeout_ = time;
163     if (!pref_) {
164         HILOG_ERROR("pref_ is null!");
165         return RET_ERR_NULLPTR;
166     }
167 
168     pref_->PutInt("contentTimeout", static_cast<int32_t>(contentTimeout_));
169     pref_->Flush();
170     return RET_OK;
171 }
172 
SetBrightnessDiscount(const float discount)173 RetError AccessibilitySettingsConfig::SetBrightnessDiscount(const float discount)
174 {
175     HILOG_DEBUG("discount = [%{public}f]", discount);
176     brightnessDiscount_ = discount;
177     if (!pref_) {
178         HILOG_ERROR("pref_ is null!");
179         return RET_ERR_NULLPTR;
180     }
181 
182     pref_->PutFloat("brightnessDiscount", brightnessDiscount_);
183     pref_->Flush();
184     return RET_OK;
185 }
186 
SetAudioBalance(const float balance)187 RetError AccessibilitySettingsConfig::SetAudioBalance(const float balance)
188 {
189     HILOG_DEBUG("balance = [%{public}f]", balance);
190     audioBalance_ = balance;
191     if (!pref_) {
192         HILOG_ERROR("pref_ is null!");
193         return RET_ERR_NULLPTR;
194     }
195 
196     pref_->PutFloat("audioBalance", audioBalance_);
197     pref_->Flush();
198     return RET_OK;
199 }
200 
SetCaptionProperty(const AccessibilityConfig::CaptionProperty & caption)201 RetError AccessibilitySettingsConfig::SetCaptionProperty(const AccessibilityConfig::CaptionProperty& caption)
202 {
203     HILOG_DEBUG();
204     captionProperty_ = caption;
205 
206     if (!pref_) {
207         HILOG_ERROR("pref_ is null!");
208         return RET_ERR_NULLPTR;
209     }
210     const std::string& FONTFAMILY = captionProperty_.GetFontFamily();
211     int32_t FONTSCALE = captionProperty_.GetFontScale();
212     uint32_t FONTCOLOR = captionProperty_.GetFontColor();
213     const std::string& FONTEDGETYPE = captionProperty_.GetFontEdgeType();
214     uint32_t BACKGROUNDCOLOR = captionProperty_.GetBackgroundColor();
215     uint32_t WINDOWCOLOR = captionProperty_.GetWindowColor();
216 
217     pref_->PutString("fontFamily", FONTFAMILY);
218     pref_->PutInt("fontColor", static_cast<int32_t>(FONTCOLOR));
219     pref_->PutString("fontEdgeType", FONTEDGETYPE);
220     pref_->PutInt("backgroundColor", static_cast<int32_t>(BACKGROUNDCOLOR));
221     pref_->PutInt("windowColor", static_cast<int32_t>(WINDOWCOLOR));
222     pref_->PutInt("fontScale", FONTSCALE);
223     pref_->Flush();
224     return RET_OK;
225 }
226 
SetStatePref(int32_t type)227 bool AccessibilitySettingsConfig::SetStatePref(int32_t type)
228 {
229     HILOG_DEBUG("type = [%{public}d]", type);
230     if (!pref_) {
231         HILOG_ERROR("pref_ is null!");
232         return false;
233     }
234 
235     std::string strValue = "";
236     switch (type) {
237         case STATE::ACCESSIBILITY:
238             strValue = StateChange(enabled_);
239             pref_->PutString("accessible", strValue);
240             break;
241         case STATE::TOUCHGUIDE:
242             strValue = StateChange(eventTouchGuideState_);
243             pref_->PutString("touchGuide", strValue);
244             break;
245         case STATE::GESTURE:
246             strValue = StateChange(gesturesSimulation_);
247             pref_->PutString("gesture", strValue);
248             break;
249         case STATE::KEYEVENT:
250             strValue = StateChange(filteringKeyEvents_);
251             pref_->PutString("keyEventObserver", strValue);
252             break;
253         case STATE::CAPTION:
254             strValue = StateChange(isCaptionState_);
255             pref_->PutString("CaptionState", strValue);
256             break;
257         case STATE::SCREENMAGNIFIER:
258             strValue = StateChange(isScreenMagnificationState_);
259             pref_->PutString("ScreenMagnification", strValue);
260             break;
261         case STATE::SHORTKEY:
262             strValue = StateChange(isShortKeyState_);
263             pref_->PutString("ShortKey", strValue);
264             break;
265         case STATE::MOUSEKEY:
266             strValue = StateChange(isMouseKeyState_);
267             pref_->PutString("MouseKey", strValue);
268             break;
269         case STATE::HIGHCONTRASTTEXT:
270             strValue = StateChange(highContrastTextState_);
271             pref_->PutString("highContrastText", strValue);
272             break;
273         case STATE::INVERTCOLORSTATE:
274             strValue = StateChange(invertColorState_);
275             pref_->PutString("invertColor", strValue);
276             break;
277         case STATE::ANIMATIONOFF:
278             strValue = StateChange(animationOffState_);
279             pref_->PutString("animationOff", strValue);
280             break;
281         case STATE::AUDIOMONO:
282             strValue = StateChange(audioMonoState_);
283             pref_->PutString("audioMono", strValue);
284             break;
285         default:
286             HILOG_ERROR("Invalid parameter.");
287             return false;
288     }
289     pref_->Flush();
290     return true;
291 }
292 
StateChange(bool state)293 std::string AccessibilitySettingsConfig::StateChange(bool state)
294 {
295     HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
296     return state ? "on" : "off";
297 }
298 
GetCaptionState() const299 bool AccessibilitySettingsConfig::GetCaptionState() const
300 {
301     return isCaptionState_;
302 }
303 
GetScreenMagnificationState() const304 bool AccessibilitySettingsConfig::GetScreenMagnificationState() const
305 {
306     return isScreenMagnificationState_;
307 }
308 
GetShortKeyState() const309 bool AccessibilitySettingsConfig::GetShortKeyState() const
310 {
311     return isShortKeyState_;
312 }
313 
GetMouseKeyState() const314 bool AccessibilitySettingsConfig::GetMouseKeyState() const
315 {
316     return isMouseKeyState_;
317 }
318 
GetMouseAutoClick() const319 int32_t AccessibilitySettingsConfig::GetMouseAutoClick() const
320 {
321     return mouseAutoClick_;
322 }
323 
GetShortkeyTarget() const324 const std::string &AccessibilitySettingsConfig::GetShortkeyTarget() const
325 {
326     return shortkeyTarget_;
327 }
328 
GetHighContrastTextState() const329 bool AccessibilitySettingsConfig::GetHighContrastTextState() const
330 {
331     return highContrastTextState_;
332 }
333 
GetInvertColorState() const334 bool AccessibilitySettingsConfig::GetInvertColorState() const
335 {
336     return invertColorState_;
337 }
338 
GetAnimationOffState() const339 bool AccessibilitySettingsConfig::GetAnimationOffState() const
340 {
341     return animationOffState_;
342 }
343 
GetAudioMonoState() const344 bool AccessibilitySettingsConfig::GetAudioMonoState() const
345 {
346     return audioMonoState_;
347 }
348 
GetDaltonizationColorFilter() const349 uint32_t AccessibilitySettingsConfig::GetDaltonizationColorFilter() const
350 {
351     return daltonizationColorFilter_;
352 }
353 
GetContentTimeout() const354 uint32_t AccessibilitySettingsConfig::GetContentTimeout() const
355 {
356     return contentTimeout_;
357 }
358 
GetBrightnessDiscount() const359 float AccessibilitySettingsConfig::GetBrightnessDiscount() const
360 {
361     return brightnessDiscount_;
362 }
363 
GetAudioBalance() const364 float AccessibilitySettingsConfig::GetAudioBalance() const
365 {
366     return audioBalance_;
367 }
368 
GetEnabledState() const369 bool AccessibilitySettingsConfig::GetEnabledState() const
370 {
371     return enabled_;
372 }
373 
GetTouchGuideState() const374 bool AccessibilitySettingsConfig::GetTouchGuideState() const
375 {
376     return eventTouchGuideState_;
377 }
378 
GetGestureState() const379 bool AccessibilitySettingsConfig::GetGestureState() const
380 {
381     return gesturesSimulation_;
382 }
383 
GetKeyEventObserverState() const384 bool AccessibilitySettingsConfig::GetKeyEventObserverState() const
385 {
386     return filteringKeyEvents_;
387 }
388 
GetCaptionProperty() const389 const AccessibilityConfig::CaptionProperty &AccessibilitySettingsConfig::GetCaptionProperty() const
390 {
391     return captionProperty_;
392 };
393 
GetConfigState()394 uint32_t AccessibilitySettingsConfig::GetConfigState()
395 {
396     HILOG_DEBUG();
397     uint32_t state = 0;
398     if (isCaptionState_) {
399         state |= STATE_CAPTION_ENABLED;
400     }
401 
402     if (isScreenMagnificationState_) {
403         state |= STATE_SCREENMAGNIFIER_ENABLED;
404     }
405 
406     if (isMouseKeyState_) {
407         state |= STATE_MOUSEKEY_ENABLED;
408     }
409 
410     if (isShortKeyState_) {
411         state |= STATE_SHORTKEY_ENABLED;
412     }
413 
414     if (highContrastTextState_) {
415         state |= STATE_HIGHCONTRAST_ENABLED;
416     }
417 
418     if (invertColorState_) {
419         state |= STATE_INVETRTCOLOR_ENABLED;
420     }
421 
422     if (animationOffState_) {
423         state |= STATE_ANIMATIONOFF_ENABLED;
424     }
425 
426     if (audioMonoState_) {
427         state |= STATE_AUDIOMONO_ENABLED;
428     }
429     return state;
430 }
431 
InitCaption()432 void AccessibilitySettingsConfig::InitCaption()
433 {
434     HILOG_DEBUG();
435     if (!pref_) {
436         HILOG_ERROR("Input Parameter is nullptr");
437         return;
438     }
439 
440     std::string strValue = pref_->GetString("CaptionState", "");
441     HILOG_DEBUG(" pref_->GetString() = %{public}s.", strValue.c_str());
442     if (!std::strcmp(strValue.c_str(), "on")) {
443         isCaptionState_ = true;
444     } else {
445         isCaptionState_ = false;
446     }
447 
448     std::string FONTFAMILY = pref_->GetString("fontFamily", "default");
449     HILOG_DEBUG("fontFamily = %{public}s.", FONTFAMILY.c_str());
450 
451     int32_t FONTSCALE =  static_cast<int32_t>(pref_->GetInt("fontScale", 0));
452     HILOG_DEBUG("fontScale = %{public}d.", FONTSCALE);
453 
454     uint32_t FONTCOLOR = static_cast<uint32_t>(pref_->GetInt("fontColor", DEFAULT_COLOR));
455     HILOG_DEBUG("fontColor = 0x%{public}x.", FONTCOLOR);
456 
457     std::string FONTEDGETYPE = pref_->GetString("fontEdgeType", "none");
458     HILOG_DEBUG("FONTEDGETYPE = 0x%{public}s.", FONTEDGETYPE.c_str());
459 
460     uint32_t BACKGROUNDCOLOR = static_cast<uint32_t>(pref_->GetInt("backgroundColor", DEFAULT_COLOR));
461     HILOG_DEBUG("BACKGROUNDCOLOR = 0x%{public}x.", BACKGROUNDCOLOR);
462 
463     uint32_t WINDOWCOLOR = static_cast<uint32_t>(pref_->GetInt("windowColor", DEFAULT_COLOR));
464     HILOG_DEBUG("WINDOWCOLOR = 0x%{public}x.", WINDOWCOLOR);
465 
466     captionProperty_.SetFontFamily(FONTFAMILY);
467     captionProperty_.SetFontScale(FONTSCALE);
468     captionProperty_.SetFontColor(FONTCOLOR);
469     captionProperty_.SetFontEdgeType(FONTEDGETYPE);
470     captionProperty_.SetBackgroundColor(BACKGROUNDCOLOR);
471     captionProperty_.SetWindowColor(WINDOWCOLOR);
472 }
473 
InitSetting()474 void AccessibilitySettingsConfig::InitSetting()
475 {
476     HILOG_DEBUG();
477     if (!pref_) {
478         HILOG_ERROR("Input Parameter is nullptr");
479         return;
480     }
481 
482     std::string strValue = pref_->GetString("ScreenMagnification", "");
483     isScreenMagnificationState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
484 
485     strValue = pref_->GetString("MouseKey", "");
486     isMouseKeyState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
487 
488     strValue = pref_->GetString("ShortKey", "");
489     isShortKeyState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
490 
491     strValue = pref_->GetString("animationOff", "");
492     animationOffState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
493 
494     strValue = pref_->GetString("invertColor", "");
495     invertColorState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
496 
497     strValue = pref_->GetString("highContrastText", "");
498     highContrastTextState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
499 
500     strValue = pref_->GetString("audioMono", "");
501     audioMonoState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
502 
503     shortkeyTarget_ = pref_->GetString("ShortkeyTarget", "none");
504     mouseAutoClick_ = static_cast<int32_t>(pref_->GetInt("MouseAutoClick", -1));
505     daltonizationColorFilter_ = static_cast<uint32_t>(pref_->GetInt("daltonizationColorFilter", 0));
506     contentTimeout_ = static_cast<uint32_t>(pref_->GetInt("contentTimeout", 0));
507     brightnessDiscount_ = static_cast<float>(pref_->GetFloat("brightnessDiscount", 1.0));
508     audioBalance_ = static_cast<float>(pref_->GetFloat("audioBalance", 0));
509 }
510 
InitCapability()511 void AccessibilitySettingsConfig::InitCapability()
512 {
513     HILOG_DEBUG();
514     if (!pref_) {
515         HILOG_ERROR("Input Parameter is nullptr");
516         return;
517     }
518 
519     std::string strValue = pref_->GetString("accessible", "");
520     HILOG_DEBUG("accessible = %{public}s", strValue.c_str());
521     if (!std::strcmp(strValue.c_str(), "on")) {
522         enabled_ = true;
523     } else {
524         enabled_ = false;
525     }
526 
527     strValue = pref_->GetString("touchGuide", "");
528     HILOG_DEBUG("touchGuide = %{public}s", strValue.c_str());
529     if (!std::strcmp(strValue.c_str(), "on")) {
530         eventTouchGuideState_ = true;
531     } else {
532         eventTouchGuideState_ = false;
533     }
534 
535     strValue = pref_->GetString("gesture", "");
536     HILOG_DEBUG("gesture = %{public}s", strValue.c_str());
537     if (!std::strcmp(strValue.c_str(), "on")) {
538         gesturesSimulation_ = true;
539     } else {
540         gesturesSimulation_ = false;
541     }
542 
543     strValue = pref_->GetString("keyEventObserver", "");
544     HILOG_DEBUG("keyEventObserver = %{public}s", strValue.c_str());
545     if (!std::strcmp(strValue.c_str(), "on")) {
546         filteringKeyEvents_ = true;
547     } else {
548         filteringKeyEvents_ = false;
549     }
550 }
551 
InitEnabledList()552 void AccessibilitySettingsConfig::InitEnabledList()
553 {
554     HILOG_DEBUG();
555     if (!pref_) {
556         HILOG_ERROR("Input Parameter is nullptr");
557         return;
558     }
559 
560     std::string strValue = pref_->GetString("BundleName/AbilityName/Capabilities", "");
561     HILOG_DEBUG("Capabilities = %{public}s", strValue.c_str());
562 
563     StringToVector(strValue, enabledAbilityInfos_);
564 }
565 
Init()566 void AccessibilitySettingsConfig::Init()
567 {
568     HILOG_INFO();
569     int errCode = -1;
570 
571     pref_ = NativePreferences::PreferencesHelper::GetPreferences(PREF_PATH + std::to_string(accountId_) + ".xml",
572                                                                  errCode);
573     if (errCode) {
574         Utils::RecordUnavailableEvent(A11yUnavailableEvent::READ_EVENT, A11yError::ERROR_READ_FAILED);
575         HILOG_ERROR("GetPreferences failed! account id (%{public}d), errCode(%{public}d).", accountId_, errCode);
576         return;
577     }
578 
579     InitCaption();
580     InitSetting();
581 }
582 
VectorToString(const std::vector<std::string> & vectorVal,std::string & stringOut)583 void AccessibilitySettingsConfig::VectorToString(const std::vector<std::string> &vectorVal, std::string &stringOut)
584 {
585     HILOG_DEBUG();
586     int32_t i = 0;
587     for (auto& var : vectorVal) {
588         if (i > 0) {
589             stringOut = stringOut + ',';
590         }
591         stringOut = stringOut + var.c_str();
592         i++;
593     }
594     HILOG_DEBUG("stringOUT = %{public}s .", stringOut.c_str());
595 }
596 
StringToVector(const std::string & stringIn,std::vector<std::string> & vectorResult)597 void AccessibilitySettingsConfig::StringToVector(const std::string &stringIn, std::vector<std::string> &vectorResult)
598 {
599     HILOG_DEBUG();
600     int32_t strLength = static_cast<int32_t>(stringIn.size());
601     std::vector<int32_t> position;
602 
603     if (strLength == 0) {
604         return;
605     }
606 
607     for (int32_t j = 0; j < strLength; j++) {
608         if (stringIn[j] == ',') {
609             position.push_back(j);
610         }
611     }
612 
613     int32_t wrodCount = static_cast<int32_t>(position.size());
614     if ((wrodCount == 0) && (strLength > 0)) {
615         vectorResult.push_back(stringIn);
616     } else {
617         int32_t startWrod = 0;
618         int32_t length = 0;
619         for (int32_t i = 0; i <= wrodCount; i++) {
620             if (i == 0) {
621                 length = position[i];
622                 vectorResult.push_back(stringIn.substr(startWrod, length)); // First string
623             } else if (i < wrodCount) {
624                 startWrod = position[i - 1] + 1;
625                 length = position[i] - position[i - 1] - 1;
626                 vectorResult.push_back(stringIn.substr(startWrod, length)); // Second string to last-1 string
627             } else {
628                 startWrod = position[i - 1] + 1;
629                 length = strLength - position[i - 1] - 1;
630                 vectorResult.push_back(stringIn.substr(startWrod, length)); // Last string
631             }
632         }
633     }
634     HILOG_DEBUG("strLength = %{public}d, wrodCount = %{public}d, stringIn : %{public}s",
635         strLength, wrodCount, stringIn.c_str());
636     for (auto& var : vectorResult) {
637         HILOG_DEBUG("vectorResult = %{public}s ", var.c_str());
638     }
639 }
640 
GetEnabledAbilityInfos()641 const std::vector<std::string> &AccessibilitySettingsConfig::GetEnabledAbilityInfos()
642 {
643     HILOG_DEBUG();
644     return enabledAbilityInfos_;
645 }
646 
UpdateEnabledAbilities(const std::vector<std::string> & vecvalue)647 void AccessibilitySettingsConfig::UpdateEnabledAbilities(const std::vector<std::string> &vecvalue)
648 {
649     HILOG_DEBUG();
650     enabledAbilityInfos_ = vecvalue;
651     if (!pref_) {
652         HILOG_ERROR("pref_ is null!");
653         return;
654     }
655     std::string stringOut = "";
656     VectorToString(enabledAbilityInfos_, stringOut);
657     pref_->PutString("BundleName/AbilityName/Capabilities", stringOut);
658     pref_->Flush();
659 }
660 
ClearData()661 void AccessibilitySettingsConfig::ClearData()
662 {
663     HILOG_DEBUG();
664     int errCode = -1;
665     errCode = NativePreferences::PreferencesHelper::DeletePreferences(PREF_PATH + std::to_string(accountId_) + ".xml");
666     if (errCode) {
667         HILOG_ERROR("DeletePreferences failed! account id (%{public}d)", accountId_);
668     }
669 
670     pref_ = nullptr;
671 }
672 } // namespace Accessibility
673 } // namespace OHOS