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
SetStatePrefExec(int32_t type)227 bool AccessibilitySettingsConfig::SetStatePrefExec(int32_t type)
228 {
229 bool ret = true;
230 std::string strValue;
231 if (type == STATE::ACCESSIBILITY) {
232 strValue = StateChange(enabled_);
233 pref_->PutString("accessible", strValue);
234 } else if (type == STATE::TOUCHGUIDE) {
235 strValue = StateChange(eventTouchGuideState_);
236 pref_->PutString("touchGuide", strValue);
237 } else if (type == STATE::GESTURE) {
238 strValue = StateChange(gesturesSimulation_);
239 pref_->PutString("gesture", strValue);
240 } else if (type == STATE::KEYEVENT) {
241 strValue = StateChange(filteringKeyEvents_);
242 pref_->PutString("keyEventObserver", strValue);
243 } else if (type == STATE::CAPTION) {
244 strValue = StateChange(isCaptionState_);
245 pref_->PutString("CaptionState", strValue);
246 } else if (type == STATE::SCREENMAGNIFIER) {
247 strValue = StateChange(isScreenMagnificationState_);
248 pref_->PutString("ScreenMagnification", strValue);
249 } else if (type == STATE::SHORTKEY) {
250 strValue = StateChange(isShortKeyState_);
251 pref_->PutString("ShortKey", strValue);
252 } else if (type == STATE::MOUSEKEY) {
253 strValue = StateChange(isMouseKeyState_);
254 pref_->PutString("MouseKey", strValue);
255 } else if (type == STATE::HIGHCONTRASTTEXT) {
256 strValue = StateChange(highContrastTextState_);
257 pref_->PutString("highContrastText", strValue);
258 } else if (type == STATE::INVERTCOLORSTATE) {
259 strValue = StateChange(invertColorState_);
260 pref_->PutString("invertColor", strValue);
261 } else if (type == STATE::ANIMATIONOFF) {
262 strValue = StateChange(animationOffState_);
263 pref_->PutString("animationOff", strValue);
264 } else if (type == STATE::AUDIOMONO) {
265 std::string strValue = StateChange(audioMonoState_);
266 pref_->PutString("audioMono", strValue);
267 } else {
268 ret = false;
269 HILOG_ERROR("invalid parameter type = [%{public}d]", type);
270 }
271 return ret;
272 }
273
SetStatePref(int32_t type)274 bool AccessibilitySettingsConfig::SetStatePref(int32_t type)
275 {
276 HILOG_DEBUG("type = [%{public}d]", type);
277 if (!pref_) {
278 HILOG_ERROR("pref_ is null!");
279 return false;
280 }
281
282 bool ret = SetStatePrefExec(type);
283 if (ret) {
284 pref_->Flush();
285 }
286 return ret;
287 }
288
StateChange(bool state)289 std::string AccessibilitySettingsConfig::StateChange(bool state)
290 {
291 HILOG_DEBUG("state = [%{public}s]", state ? "True" : "False");
292 return state ? "on" : "off";
293 }
294
GetCaptionState() const295 bool AccessibilitySettingsConfig::GetCaptionState() const
296 {
297 return isCaptionState_;
298 }
299
GetScreenMagnificationState() const300 bool AccessibilitySettingsConfig::GetScreenMagnificationState() const
301 {
302 return isScreenMagnificationState_;
303 }
304
GetShortKeyState() const305 bool AccessibilitySettingsConfig::GetShortKeyState() const
306 {
307 return isShortKeyState_;
308 }
309
GetMouseKeyState() const310 bool AccessibilitySettingsConfig::GetMouseKeyState() const
311 {
312 return isMouseKeyState_;
313 }
314
GetMouseAutoClick() const315 int32_t AccessibilitySettingsConfig::GetMouseAutoClick() const
316 {
317 return mouseAutoClick_;
318 }
319
GetShortkeyTarget() const320 const std::string &AccessibilitySettingsConfig::GetShortkeyTarget() const
321 {
322 return shortkeyTarget_;
323 }
324
GetHighContrastTextState() const325 bool AccessibilitySettingsConfig::GetHighContrastTextState() const
326 {
327 return highContrastTextState_;
328 }
329
GetInvertColorState() const330 bool AccessibilitySettingsConfig::GetInvertColorState() const
331 {
332 return invertColorState_;
333 }
334
GetAnimationOffState() const335 bool AccessibilitySettingsConfig::GetAnimationOffState() const
336 {
337 return animationOffState_;
338 }
339
GetAudioMonoState() const340 bool AccessibilitySettingsConfig::GetAudioMonoState() const
341 {
342 return audioMonoState_;
343 }
344
GetDaltonizationColorFilter() const345 uint32_t AccessibilitySettingsConfig::GetDaltonizationColorFilter() const
346 {
347 return daltonizationColorFilter_;
348 }
349
GetContentTimeout() const350 uint32_t AccessibilitySettingsConfig::GetContentTimeout() const
351 {
352 return contentTimeout_;
353 }
354
GetBrightnessDiscount() const355 float AccessibilitySettingsConfig::GetBrightnessDiscount() const
356 {
357 return brightnessDiscount_;
358 }
359
GetAudioBalance() const360 float AccessibilitySettingsConfig::GetAudioBalance() const
361 {
362 return audioBalance_;
363 }
364
GetEnabledState() const365 bool AccessibilitySettingsConfig::GetEnabledState() const
366 {
367 return enabled_;
368 }
369
GetTouchGuideState() const370 bool AccessibilitySettingsConfig::GetTouchGuideState() const
371 {
372 return eventTouchGuideState_;
373 }
374
GetGestureState() const375 bool AccessibilitySettingsConfig::GetGestureState() const
376 {
377 return gesturesSimulation_;
378 }
379
GetKeyEventObserverState() const380 bool AccessibilitySettingsConfig::GetKeyEventObserverState() const
381 {
382 return filteringKeyEvents_;
383 }
384
GetCaptionProperty() const385 const AccessibilityConfig::CaptionProperty &AccessibilitySettingsConfig::GetCaptionProperty() const
386 {
387 return captionProperty_;
388 };
389
GetConfigState()390 uint32_t AccessibilitySettingsConfig::GetConfigState()
391 {
392 HILOG_DEBUG();
393 uint32_t state = 0;
394 if (isCaptionState_) {
395 state |= STATE_CAPTION_ENABLED;
396 }
397
398 if (isScreenMagnificationState_) {
399 state |= STATE_SCREENMAGNIFIER_ENABLED;
400 }
401
402 if (isMouseKeyState_) {
403 state |= STATE_MOUSEKEY_ENABLED;
404 }
405
406 if (isShortKeyState_) {
407 state |= STATE_SHORTKEY_ENABLED;
408 }
409
410 if (highContrastTextState_) {
411 state |= STATE_HIGHCONTRAST_ENABLED;
412 }
413
414 if (invertColorState_) {
415 state |= STATE_INVETRTCOLOR_ENABLED;
416 }
417
418 if (animationOffState_) {
419 state |= STATE_ANIMATIONOFF_ENABLED;
420 }
421
422 if (audioMonoState_) {
423 state |= STATE_AUDIOMONO_ENABLED;
424 }
425 return state;
426 }
427
InitCaption()428 void AccessibilitySettingsConfig::InitCaption()
429 {
430 HILOG_DEBUG();
431 if (!pref_) {
432 HILOG_ERROR("Input Parameter is nullptr");
433 return;
434 }
435
436 std::string strValue = pref_->GetString("CaptionState", "");
437 HILOG_DEBUG(" pref_->GetString() = %{public}s.", strValue.c_str());
438 if (!std::strcmp(strValue.c_str(), "on")) {
439 isCaptionState_ = true;
440 } else {
441 isCaptionState_ = false;
442 }
443
444 std::string FONTFAMILY = pref_->GetString("fontFamily", "default");
445 HILOG_DEBUG("fontFamily = %{public}s.", FONTFAMILY.c_str());
446
447 int32_t FONTSCALE = static_cast<int32_t>(pref_->GetInt("fontScale", 0));
448 HILOG_DEBUG("fontScale = %{public}d.", FONTSCALE);
449
450 uint32_t FONTCOLOR = static_cast<uint32_t>(pref_->GetInt("fontColor", DEFAULT_COLOR));
451 HILOG_DEBUG("fontColor = 0x%{public}x.", FONTCOLOR);
452
453 std::string FONTEDGETYPE = pref_->GetString("fontEdgeType", "none");
454 HILOG_DEBUG("FONTEDGETYPE = 0x%{public}s.", FONTEDGETYPE.c_str());
455
456 uint32_t BACKGROUNDCOLOR = static_cast<uint32_t>(pref_->GetInt("backgroundColor", DEFAULT_COLOR));
457 HILOG_DEBUG("BACKGROUNDCOLOR = 0x%{public}x.", BACKGROUNDCOLOR);
458
459 uint32_t WINDOWCOLOR = static_cast<uint32_t>(pref_->GetInt("windowColor", DEFAULT_COLOR));
460 HILOG_DEBUG("WINDOWCOLOR = 0x%{public}x.", WINDOWCOLOR);
461
462 captionProperty_.SetFontFamily(FONTFAMILY);
463 captionProperty_.SetFontScale(FONTSCALE);
464 captionProperty_.SetFontColor(FONTCOLOR);
465 captionProperty_.SetFontEdgeType(FONTEDGETYPE);
466 captionProperty_.SetBackgroundColor(BACKGROUNDCOLOR);
467 captionProperty_.SetWindowColor(WINDOWCOLOR);
468 }
469
InitSetting()470 void AccessibilitySettingsConfig::InitSetting()
471 {
472 HILOG_DEBUG();
473 if (!pref_) {
474 HILOG_ERROR("Input Parameter is nullptr");
475 return;
476 }
477
478 std::string strValue = pref_->GetString("ScreenMagnification", "");
479 isScreenMagnificationState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
480
481 strValue = pref_->GetString("MouseKey", "");
482 isMouseKeyState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
483
484 strValue = pref_->GetString("ShortKey", "");
485 isShortKeyState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
486
487 strValue = pref_->GetString("animationOff", "");
488 animationOffState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
489
490 strValue = pref_->GetString("invertColor", "");
491 invertColorState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
492
493 strValue = pref_->GetString("highContrastText", "");
494 highContrastTextState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
495
496 strValue = pref_->GetString("audioMono", "");
497 audioMonoState_ = std::strcmp(strValue.c_str(), "on") ? false : true;
498
499 shortkeyTarget_ = pref_->GetString("ShortkeyTarget", "none");
500 mouseAutoClick_ = static_cast<int32_t>(pref_->GetInt("MouseAutoClick", -1));
501 daltonizationColorFilter_ = static_cast<uint32_t>(pref_->GetInt("daltonizationColorFilter", 0));
502 contentTimeout_ = static_cast<uint32_t>(pref_->GetInt("contentTimeout", 0));
503 brightnessDiscount_ = static_cast<float>(pref_->GetFloat("brightnessDiscount", 1.0));
504 audioBalance_ = static_cast<float>(pref_->GetFloat("audioBalance", 0));
505 }
506
InitCapability()507 void AccessibilitySettingsConfig::InitCapability()
508 {
509 HILOG_DEBUG();
510 if (!pref_) {
511 HILOG_ERROR("Input Parameter is nullptr");
512 return;
513 }
514
515 std::string strValue = pref_->GetString("accessible", "");
516 HILOG_DEBUG("accessible = %{public}s", strValue.c_str());
517 if (!std::strcmp(strValue.c_str(), "on")) {
518 enabled_ = true;
519 } else {
520 enabled_ = false;
521 }
522
523 strValue = pref_->GetString("touchGuide", "");
524 HILOG_DEBUG("touchGuide = %{public}s", strValue.c_str());
525 if (!std::strcmp(strValue.c_str(), "on")) {
526 eventTouchGuideState_ = true;
527 } else {
528 eventTouchGuideState_ = false;
529 }
530
531 strValue = pref_->GetString("gesture", "");
532 HILOG_DEBUG("gesture = %{public}s", strValue.c_str());
533 if (!std::strcmp(strValue.c_str(), "on")) {
534 gesturesSimulation_ = true;
535 } else {
536 gesturesSimulation_ = false;
537 }
538
539 strValue = pref_->GetString("keyEventObserver", "");
540 HILOG_DEBUG("keyEventObserver = %{public}s", strValue.c_str());
541 if (!std::strcmp(strValue.c_str(), "on")) {
542 filteringKeyEvents_ = true;
543 } else {
544 filteringKeyEvents_ = false;
545 }
546 }
547
InitEnabledList()548 void AccessibilitySettingsConfig::InitEnabledList()
549 {
550 HILOG_DEBUG();
551 if (!pref_) {
552 HILOG_ERROR("Input Parameter is nullptr");
553 return;
554 }
555
556 std::string strValue = pref_->GetString("BundleName/AbilityName/Capabilities", "");
557 HILOG_DEBUG("Capabilities = %{public}s", strValue.c_str());
558
559 StringToVector(strValue, enabledAbilityInfos_);
560 }
561
Init()562 void AccessibilitySettingsConfig::Init()
563 {
564 HILOG_INFO();
565 int errCode = -1;
566
567 pref_ = NativePreferences::PreferencesHelper::GetPreferences(PREF_PATH + std::to_string(accountId_) + ".xml",
568 errCode);
569 if (errCode) {
570 Utils::RecordUnavailableEvent(A11yUnavailableEvent::READ_EVENT, A11yError::ERROR_READ_FAILED);
571 HILOG_ERROR("GetPreferences failed! errCode(%{public}d).", errCode);
572 return;
573 }
574
575 InitCaption();
576 InitSetting();
577 }
578
VectorToString(const std::vector<std::string> & vectorVal,std::string & stringOut)579 void AccessibilitySettingsConfig::VectorToString(const std::vector<std::string> &vectorVal, std::string &stringOut)
580 {
581 HILOG_DEBUG();
582 int32_t i = 0;
583 for (auto& var : vectorVal) {
584 if (i > 0) {
585 stringOut = stringOut + ',';
586 }
587 stringOut = stringOut + var.c_str();
588 i++;
589 }
590 HILOG_DEBUG("stringOUT = %{public}s .", stringOut.c_str());
591 }
592
StringToVector(const std::string & stringIn,std::vector<std::string> & vectorResult)593 void AccessibilitySettingsConfig::StringToVector(const std::string &stringIn, std::vector<std::string> &vectorResult)
594 {
595 HILOG_DEBUG();
596 int32_t strLength = static_cast<int32_t>(stringIn.size());
597 std::vector<int32_t> position;
598
599 if (strLength == 0) {
600 return;
601 }
602
603 for (int32_t j = 0; j < strLength; j++) {
604 if (stringIn[j] == ',') {
605 position.push_back(j);
606 }
607 }
608
609 int32_t wrodCount = static_cast<int32_t>(position.size());
610 if ((wrodCount == 0) && (strLength > 0)) {
611 vectorResult.push_back(stringIn);
612 } else {
613 int32_t startWrod = 0;
614 int32_t length = 0;
615 for (int32_t i = 0; i <= wrodCount; i++) {
616 if (i == 0) {
617 length = position[i];
618 vectorResult.push_back(stringIn.substr(startWrod, length)); // First string
619 } else if (i < wrodCount) {
620 startWrod = position[i - 1] + 1;
621 length = position[i] - position[i - 1] - 1;
622 vectorResult.push_back(stringIn.substr(startWrod, length)); // Second string to last-1 string
623 } else {
624 startWrod = position[i - 1] + 1;
625 length = strLength - position[i - 1] - 1;
626 vectorResult.push_back(stringIn.substr(startWrod, length)); // Last string
627 }
628 }
629 }
630 HILOG_DEBUG("strLength = %{public}d, wrodCount = %{public}d, stringIn : %{public}s",
631 strLength, wrodCount, stringIn.c_str());
632 for (auto& var : vectorResult) {
633 HILOG_DEBUG("vectorResult = %{public}s ", var.c_str());
634 }
635 }
636
GetEnabledAbilityInfos()637 const std::vector<std::string> &AccessibilitySettingsConfig::GetEnabledAbilityInfos()
638 {
639 HILOG_DEBUG();
640 return enabledAbilityInfos_;
641 }
642
UpdateEnabledAbilities(const std::vector<std::string> & vecvalue)643 void AccessibilitySettingsConfig::UpdateEnabledAbilities(const std::vector<std::string> &vecvalue)
644 {
645 HILOG_DEBUG();
646 enabledAbilityInfos_ = vecvalue;
647 if (!pref_) {
648 HILOG_ERROR("pref_ is null!");
649 return;
650 }
651 std::string stringOut = "";
652 VectorToString(enabledAbilityInfos_, stringOut);
653 pref_->PutString("BundleName/AbilityName/Capabilities", stringOut);
654 pref_->Flush();
655 }
656
ClearData()657 void AccessibilitySettingsConfig::ClearData()
658 {
659 HILOG_DEBUG();
660 int errCode = -1;
661 errCode = NativePreferences::PreferencesHelper::DeletePreferences(PREF_PATH + std::to_string(accountId_) + ".xml");
662 if (errCode) {
663 HILOG_ERROR("DeletePreferences failed!");
664 }
665
666 pref_ = nullptr;
667 }
668 } // namespace Accessibility
669 } // namespace OHOS