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 <gtest/gtest.h>
17 #include "ability_info.h"
18 #include "a11y_element_info.h"
19 #include "a11y_display_manager.h"
20 #include "a11y_event_info.h"
21 #include "a11y_ut_helper.h"
22 #include "a11y_window_manager.h"
23 #include "accessible_ability_manager_service.h"
24 #include "hilog_wrapper.h"
25 #include "iservice_registry.h"
26 #include "system_ability_definition.h"
27 #include "utils.h"
28
29 namespace OHOS {
30 namespace A11y {
31 namespace {
32 constexpr int32_t ACCOUNT_ID = 100;
33 } // namespace
34
35 const bool REGISTER_RESULT =
36 SystemAbility::MakeAndRegisterAbility(&Singleton<A11yManagerService>::GetInstance());
37
A11yManagerService()38 A11yManagerService::A11yManagerService()
39 : SystemAbility(A11y_MANAGER_SERVICE_ID, true)
40 {
41 }
42
~A11yManagerService()43 A11yManagerService::~A11yManagerService()
44 {
45 }
46
OnStart()47 void A11yManagerService::OnStart()
48 {
49 GTEST_LOG_(INFO) << "###A11yManagerService::OnStart";
50 runner_ = AppExecFwk::EventRunner::Create("A11yManagerService", AppExecFwk::ThreadMode::FFRT);
51 handler_ = std::make_shared<AAMSEventHandler>(runner_);
52 Singleton<A11yWindowManager>::GetInstance().RegisterWindowListener(handler_);
53 Singleton<A11yCommonEvent>::GetInstance().SubscriberEvent(handler_);
54 }
55
OnStop()56 void A11yManagerService::OnStop()
57 {
58 Singleton<A11yCommonEvent>::GetInstance().UnSubscriberEvent();
59 Singleton<A11yWindowManager>::GetInstance().DeregisterWindowListener();
60 runner_.reset();
61 handler_.reset();
62 }
63
OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)64 void A11yManagerService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
65 {
66 (void)systemAbilityId;
67 (void)deviceId;
68 }
69
OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId)70 void A11yManagerService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
71 {
72 (void)systemAbilityId;
73 (void)deviceId;
74 }
75
Dump(int fd, const std::vector<std::u16string>& args)76 int A11yManagerService::Dump(int fd, const std::vector<std::u16string>& args)
77 {
78 (void)fd;
79 (void)args;
80 return 0;
81 }
82
SendEvent(const A11yEventInfo& uiEvent, const int32_t flag)83 RetError A11yManagerService::SendEvent(const A11yEventInfo& uiEvent, const int32_t flag)
84 {
85 HILOG_INFO("A11yManagerService::SendEvent successfully");
86 EventType uTeventType = uiEvent.GetEventType();
87 A11yAbilityHelper::GetInstance().SetGestureId(uiEvent.GetGestureType());
88 A11yAbilityHelper::GetInstance().SetEventTypeVector(uTeventType);
89 A11yAbilityHelper::GetInstance().SetEventWindowId(uiEvent.GetWindowId());
90 A11yAbilityHelper::GetInstance().SetEventWindowChangeType(uiEvent.GetWindowChangeTypes());
91 GTEST_LOG_(INFO) << "###A11yManagerService::SendEvent GetGestureType="
92 << (int32_t)uiEvent.GetGestureType();
93 GTEST_LOG_(INFO) << "###A11yManagerService::SendEvent uTeventType=0x" << std::hex
94 << (int32_t)uTeventType;
95
96 handler_->PostTask(std::bind([=]() -> void {
97 HILOG_DEBUG("start");
98 A11yAbilityHelper::GetInstance().AddSendEventTimes();
99 }), "TASK_SEND_EVENT");
100 return RET_OK;
101 }
102
RegisterStateObserver( const sptr<IA11yManagerStateObserver>& callback)103 uint32_t A11yManagerService::RegisterStateObserver(
104 const sptr<IA11yManagerStateObserver>& callback)
105 {
106 (void)callback;
107 return 0;
108 }
109
GetAbilityList(const uint32_t abilityTypes, const int32_t stateType, std::vector<A11yAbilityInfo> &infos)110 RetError A11yManagerService::GetAbilityList(const uint32_t abilityTypes, const int32_t stateType,
111 std::vector<A11yAbilityInfo> &infos)
112 {
113 (void)abilityTypes;
114 (void)stateType;
115 (void)infos;
116 return RET_OK;
117 }
118
RegisterElementOperator( const int32_t windowId, const sptr<IA11yElementOperator>& operation, bool isApp)119 RetError A11yManagerService::RegisterElementOperator(
120 const int32_t windowId, const sptr<IA11yElementOperator>& operation, bool isApp)
121 {
122 (void)windowId;
123 (void)operation;
124 (void)isApp;
125 return RET_OK;
126 }
127
RegisterElementOperator(Registration parameter, const sptr<IA11yElementOperator> &operation, bool isApp)128 RetError A11yManagerService::RegisterElementOperator(Registration parameter,
129 const sptr<IA11yElementOperator> &operation, bool isApp)
130 {
131 (void)parameter;
132 (void)operation;
133 (void)isApp;
134 return RET_OK;
135 }
136
DeregisterElementOperator(int32_t windowId)137 RetError A11yManagerService::DeregisterElementOperator(int32_t windowId)
138 {
139 (void)windowId;
140 return RET_OK;
141 }
142
DeregisterElementOperator(int32_t windowId, int32_t treeId)143 RetError A11yManagerService::DeregisterElementOperator(int32_t windowId, int32_t treeId)
144 {
145 (void)windowId;
146 (void)treeId;
147 return RET_OK;
148 }
149
GetCurrentAccountData()150 sptr<A11yAccountData> A11yManagerService::GetCurrentAccountData()
151 {
152 bool needNullFlag = A11yAbilityHelper::GetInstance().GetNeedAccountDataNullFlag();
153 if (needNullFlag) {
154 return nullptr;
155 }
156
157 auto accountData = a11yAccountsData_.GetCurrentAccountData(ACCOUNT_ID);
158 accountData->Init();
159 return accountData;
160 }
161
GetAccountData(int32_t accountId)162 sptr<A11yAccountData> A11yManagerService::GetAccountData(int32_t accountId)
163 {
164 return a11yAccountsData_.GetAccountData(accountId);
165 }
166
GetCaptionProperty(A11yConfig::CaptionProperty &caption)167 RetError A11yManagerService::GetCaptionProperty(A11yConfig::CaptionProperty &caption)
168 {
169 (void)caption;
170 return RET_OK;
171 }
172
SetCaptionProperty(const A11yConfig::CaptionProperty& caption)173 RetError A11yManagerService::SetCaptionProperty(const A11yConfig::CaptionProperty& caption)
174 {
175 (void)caption;
176 return RET_OK;
177 }
178
SetCaptionState(const bool state)179 RetError A11yManagerService::SetCaptionState(const bool state)
180 {
181 (void)state;
182 return RET_OK;
183 }
184
GetEnabledState()185 bool A11yManagerService::GetEnabledState()
186 {
187 return true;
188 }
189
GetCaptionState(bool &state)190 RetError A11yManagerService::GetCaptionState(bool &state)
191 {
192 state = true;
193 return RET_OK;
194 }
195
GetTouchGuideState()196 bool A11yManagerService::GetTouchGuideState()
197 {
198 return true;
199 }
200
GetGestureState()201 bool A11yManagerService::GetGestureState()
202 {
203 return true;
204 }
205
GetKeyEventObserverState()206 bool A11yManagerService::GetKeyEventObserverState()
207 {
208 return true;
209 }
210
EnableAbility(const std::string &name, const uint32_t capabilities)211 RetError A11yManagerService::EnableAbility(const std::string &name, const uint32_t capabilities)
212 {
213 (void)name;
214 (void)capabilities;
215 return RET_OK;
216 }
217
GetEnabledAbilities(std::vector<std::string> &enabledAbilities)218 RetError A11yManagerService::GetEnabledAbilities(std::vector<std::string> &enabledAbilities)
219 {
220 (void)enabledAbilities;
221 return RET_OK;
222 }
223
RegisterCaptionObserver( const sptr<IA11yManagerCaptionObserver>& callback)224 uint32_t A11yManagerService::RegisterCaptionObserver(
225 const sptr<IA11yManagerCaptionObserver>& callback)
226 {
227 (void)callback;
228 return NO_ERROR;
229 }
230
SetCurtainScreenUsingStatus(bool isEnable)231 RetError A11yManagerService::SetCurtainScreenUsingStatus(bool isEnable)
232 {
233 (void)isEnable;
234 return RET_OK;
235 }
236
DisableAbility(const std::string &name)237 RetError A11yManagerService::DisableAbility(const std::string &name)
238 {
239 (void)name;
240 return RET_OK;
241 }
242
EnableUITestAbility(const sptr<IRemoteObject>& obj)243 RetError A11yManagerService::EnableUITestAbility(const sptr<IRemoteObject>& obj)
244 {
245 (void)obj;
246 return RET_OK;
247 }
248
DisableUITestAbility()249 RetError A11yManagerService::DisableUITestAbility()
250 {
251 return RET_OK;
252 }
253
GetActiveWindow()254 int32_t A11yManagerService::GetActiveWindow()
255 {
256 return 0;
257 }
258
SetScreenMagnificationState(const bool state)259 RetError A11yManagerService::SetScreenMagnificationState(const bool state)
260 {
261 (void)state;
262 return RET_OK;
263 }
264
UpdateAllSetting()265 void A11yManagerService::UpdateAllSetting()
266 {
267 return;
268 }
269
UpdateInputFilter()270 void A11yManagerService::UpdateInputFilter()
271 {
272 return;
273 }
274
UpdateShortKeyRegister()275 void A11yManagerService::UpdateShortKeyRegister()
276 {
277 return;
278 }
279
SetShortKeyState(const bool state)280 RetError A11yManagerService::SetShortKeyState(const bool state)
281 {
282 (void)state;
283 return RET_OK;
284 }
285
SetMouseKeyState(const bool state)286 RetError A11yManagerService::SetMouseKeyState(const bool state)
287 {
288 (void)state;
289 return RET_OK;
290 }
291
SetMouseAutoClick(const int32_t time)292 RetError A11yManagerService::SetMouseAutoClick(const int32_t time)
293 {
294 (void)time;
295 return RET_OK;
296 }
297
SetShortkeyTarget(const std::string &name)298 RetError A11yManagerService::SetShortkeyTarget(const std::string &name)
299 {
300 (void)name;
301 return RET_OK;
302 }
303
SetShortkeyMultiTarget(const std::vector<std::string> &name)304 RetError A11yManagerService::SetShortkeyMultiTarget(const std::vector<std::string> &name)
305 {
306 (void)name;
307 return RET_OK;
308 }
309
SetHighContrastTextState(const bool state)310 RetError A11yManagerService::SetHighContrastTextState(const bool state)
311 {
312 (void)state;
313 return RET_OK;
314 }
315
SetDaltonizationState(const bool state)316 RetError A11yManagerService::SetDaltonizationState(const bool state)
317 {
318 (void)state;
319 return RET_OK;
320 }
321
SetInvertColorState(const bool state)322 RetError A11yManagerService::SetInvertColorState(const bool state)
323 {
324 (void)state;
325 return RET_OK;
326 }
327
SetAnimationOffState(const bool state)328 RetError A11yManagerService::SetAnimationOffState(const bool state)
329 {
330 (void)state;
331 return RET_OK;
332 }
333
SetAudioMonoState(const bool state)334 RetError A11yManagerService::SetAudioMonoState(const bool state)
335 {
336 (void)state;
337 return RET_OK;
338 }
339
SetDaltonizationColorFilter(const uint32_t filter)340 RetError A11yManagerService::SetDaltonizationColorFilter(const uint32_t filter)
341 {
342 (void)filter;
343 return RET_OK;
344 }
345
SetContentTimeout(const uint32_t time)346 RetError A11yManagerService::SetContentTimeout(const uint32_t time)
347 {
348 (void)time;
349 return RET_OK;
350 }
351
SetBrightnessDiscount(const float discount)352 RetError A11yManagerService::SetBrightnessDiscount(const float discount)
353 {
354 (void)discount;
355 return RET_OK;
356 }
357
SetAudioBalance(const float balance)358 RetError A11yManagerService::SetAudioBalance(const float balance)
359 {
360 (void)balance;
361 return RET_OK;
362 }
363
SetClickResponseTime(const uint32_t time)364 RetError A11yManagerService::SetClickResponseTime(const uint32_t time)
365 {
366 (void)time;
367 return RET_OK;
368 }
369
SetIgnoreRepeatClickState(const bool state)370 RetError A11yManagerService::SetIgnoreRepeatClickState(const bool state)
371 {
372 (void)state;
373 return RET_OK;
374 }
375
SetIgnoreRepeatClickTime(const uint32_t time)376 RetError A11yManagerService::SetIgnoreRepeatClickTime(const uint32_t time)
377 {
378 (void)time;
379 return RET_OK;
380 }
381
GetScreenMagnificationState(bool &state)382 RetError A11yManagerService::GetScreenMagnificationState(bool &state)
383 {
384 state = true;
385 return RET_OK;
386 }
387
GetShortKeyState(bool &state)388 RetError A11yManagerService::GetShortKeyState(bool &state)
389 {
390 state = true;
391 return RET_OK;
392 }
393
GetMouseKeyState(bool &state)394 RetError A11yManagerService::GetMouseKeyState(bool &state)
395 {
396 state = true;
397 return RET_OK;
398 }
399
GetMouseAutoClick(int32_t &time)400 RetError A11yManagerService::GetMouseAutoClick(int32_t &time)
401 {
402 time = 0;
403 return RET_OK;
404 }
405
GetShortkeyTarget(std::string &name)406 RetError A11yManagerService::GetShortkeyTarget(std::string &name)
407 {
408 name = "";
409 return RET_OK;
410 }
411
GetShortkeyMultiTarget(std::vector<std::string> &name)412 RetError A11yManagerService::GetShortkeyMultiTarget(std::vector<std::string> &name)
413 {
414 std::vector<std::string> vecName {};
415 name = vecName;
416 return RET_OK;
417 }
418
GetHighContrastTextState(bool &state)419 RetError A11yManagerService::GetHighContrastTextState(bool &state)
420 {
421 state = true;
422 return RET_OK;
423 }
424
GetDaltonizationState(bool &state)425 RetError A11yManagerService::GetDaltonizationState(bool &state)
426 {
427 state = true;
428 return RET_OK;
429 }
430
GetInvertColorState(bool &state)431 RetError A11yManagerService::GetInvertColorState(bool &state)
432 {
433 state = true;
434 return RET_OK;
435 }
436
GetAnimationOffState(bool &state)437 RetError A11yManagerService::GetAnimationOffState(bool &state)
438 {
439 state = true;
440 return RET_OK;
441 }
442
GetAudioMonoState(bool &state)443 RetError A11yManagerService::GetAudioMonoState(bool &state)
444 {
445 state = true;
446 return RET_OK;
447 }
448
GetDaltonizationColorFilter(uint32_t &type)449 RetError A11yManagerService::GetDaltonizationColorFilter(uint32_t &type)
450 {
451 type = 0;
452 return RET_OK;
453 }
454
GetContentTimeout(uint32_t &timer)455 RetError A11yManagerService::GetContentTimeout(uint32_t &timer)
456 {
457 timer = 0;
458 return RET_OK;
459 }
460
GetBrightnessDiscount(float &brightness)461 RetError A11yManagerService::GetBrightnessDiscount(float &brightness)
462 {
463 brightness = 0.0f;
464 return RET_OK;
465 }
466
GetAudioBalance(float &balance)467 RetError A11yManagerService::GetAudioBalance(float &balance)
468 {
469 balance = 0.0f;
470 return RET_OK;
471 }
472
GetClickResponseTime(uint32_t &time)473 RetError A11yManagerService::GetClickResponseTime(uint32_t &time)
474 {
475 time = 0;
476 return RET_OK;
477 }
478
GetIgnoreRepeatClickState(bool &state)479 RetError A11yManagerService::GetIgnoreRepeatClickState(bool &state)
480 {
481 state = true;
482 return RET_OK;
483 }
484
GetIgnoreRepeatClickTime(uint32_t &time)485 RetError A11yManagerService::GetIgnoreRepeatClickTime(uint32_t &time)
486 {
487 time = 0;
488 return RET_OK;
489 }
490
GetAllConfigs(A11yConfigData &configData)491 void A11yManagerService::GetAllConfigs(A11yConfigData &configData)
492 {
493 (void)configData;
494 }
495
RegisterEnableAbilityListsObserver( const sptr<IA11yEnableAbilityListsObserver> &observer)496 void A11yManagerService::RegisterEnableAbilityListsObserver(
497 const sptr<IA11yEnableAbilityListsObserver> &observer)
498 {
499 (void)observer;
500 }
501
RegisterConfigObserver( const sptr<IA11yManagerConfigObserver> &callback)502 uint32_t A11yManagerService::RegisterConfigObserver(
503 const sptr<IA11yManagerConfigObserver> &callback)
504 {
505 (void)callback;
506 return NO_ERROR;
507 }
508
UpdateA11yManagerService()509 void A11yManagerService::UpdateA11yManagerService()
510 {
511 }
512
GetBundleMgrProxy()513 sptr<AppExecFwk::IBundleMgr> A11yManagerService::GetBundleMgrProxy()
514 {
515 return nullptr;
516 }
517
SetKeyEventFilter(const sptr<KeyEventFilter> &keyEventFilter)518 void A11yManagerService::SetKeyEventFilter(const sptr<KeyEventFilter> &keyEventFilter)
519 {
520 HILOG_DEBUG();
521 keyEventFilter_ = keyEventFilter;
522 }
523
EnableShortKeyTargetAbility(const std::string &name)524 bool A11yManagerService::EnableShortKeyTargetAbility(const std::string &name)
525 {
526 A11yAbilityHelper::GetInstance().SetShortKeyTargetAbilityState(true);
527 return true;
528 }
529
OnShortKeyProcess()530 void A11yManagerService::OnShortKeyProcess()
531 {
532 A11yAbilityHelper::GetInstance().SetShortKeyTargetAbilityState(true);
533 }
534
AddedUser(int32_t accountId)535 void A11yManagerService::AddedUser(int32_t accountId)
536 {
537 HILOG_DEBUG();
538 A11yAbilityHelper::GetInstance().AddUserId(accountId);
539 }
RemovedUser(int32_t accountId)540 void A11yManagerService::RemovedUser(int32_t accountId)
541 {
542 HILOG_DEBUG();
543 A11yAbilityHelper::GetInstance().RemoveUserId(accountId);
544 }
SwitchedUser(int32_t accountId)545 void A11yManagerService::SwitchedUser(int32_t accountId)
546 {
547 HILOG_DEBUG();
548 A11yAbilityHelper::GetInstance().SetCurrentUserId(accountId);
549 }
PackageChanged(const std::string &bundleName)550 void A11yManagerService::PackageChanged(const std::string &bundleName)
551 {
552 HILOG_DEBUG();
553 A11yAbilityHelper::GetInstance().ChangePackage(true);
554 }
PackageRemoved(const std::string &bundleName)555 void A11yManagerService::PackageRemoved(const std::string &bundleName)
556 {
557 HILOG_DEBUG();
558 A11yAbilityHelper::GetInstance().RemovePackage(bundleName);
559 }
PackageAdd(const std::string &bundleName)560 void A11yManagerService::PackageAdd(const std::string &bundleName)
561 {
562 HILOG_DEBUG();
563 A11yAbilityHelper::GetInstance().AddPackage(bundleName);
564 }
565
GetRealWindowAndElementId(int32_t& windowId, int64_t& elementId)566 void A11yManagerService::GetRealWindowAndElementId(int32_t& windowId, int64_t& elementId)
567 {
568 }
569
GetSceneBoardInnerWinId(int32_t windowId, int64_t elementId, int32_t& innerWid)570 void A11yManagerService::GetSceneBoardInnerWinId(int32_t windowId, int64_t elementId, int32_t& innerWid)
571 {
572 }
573
ExecuteActionOnA11yFocused(const ActionType &action)574 bool A11yManagerService::ExecuteActionOnA11yFocused(const ActionType &action)
575 {
576 return true;
577 }
578
FindFocusedElement(A11yElementInfo &elementInfo)579 bool A11yManagerService::FindFocusedElement(A11yElementInfo &elementInfo)
580 {
581 return true;
582 }
583
GetFocusedWindowId(int32_t &focusedWindowId)584 RetError A11yManagerService::GetFocusedWindowId(int32_t &focusedWindowId)
585 {
586 focusedWindowId = 1;
587 return RET_OK;
588 }
589
SetTouchEventInjector(const sptr<TouchEventInjector> &touchEventInjector)590 void A11yManagerService::SetTouchEventInjector(const sptr<TouchEventInjector> &touchEventInjector)
591 {
592 HILOG_DEBUG();
593 touchEventInjector_ = touchEventInjector;
594 }
595
InsertWindowIdEventPair(int32_t windowId, const A11yEventInfo &event)596 void A11yManagerService::InsertWindowIdEventPair(int32_t windowId, const A11yEventInfo &event)
597 {
598 (void)windowId;
599 (void)event;
600 }
601
CheckWindowRegister(int32_t windowId)602 bool A11yManagerService::CheckWindowRegister(int32_t windowId)
603 {
604 (void)windowId;
605 return true;
606 }
607
PostDelayUnloadTask()608 void A11yManagerService::PostDelayUnloadTask()
609 {
610 }
611
SetFocusWindowId(const int32_t focusWindowId)612 void A11yManagerService::SetFocusWindowId(const int32_t focusWindowId)
613 {
614 (void)focusWindowId;
615 }
616
SetFocusElementId(const int64_t focusElementId)617 void A11yManagerService::SetFocusElementId(const int64_t focusElementId)
618 {
619 (void)focusElementId;
620 }
621
GetTreeIdBySplitElementId(const int64_t elementId)622 int32_t A11yManagerService::GetTreeIdBySplitElementId(const int64_t elementId)
623 {
624 (void)elementId;
625 return 0;
626 }
627
RemoveRequestId(int32_t requestId)628 void A11yManagerService::RemoveRequestId(int32_t requestId)
629 {
630 (void)requestId;
631 }
632
AddRequestId(int32_t windowId, int32_t treeId, int32_t requestId, sptr<IA11yElementOperatorCallback> callback)633 void A11yManagerService::AddRequestId(int32_t windowId, int32_t treeId, int32_t requestId,
634 sptr<IA11yElementOperatorCallback> callback)
635 {
636 (void)windowId;
637 (void)treeId;
638 (void)requestId;
639 (void)callback;
640 }
641
GetRootParentId(int32_t windowId, int32_t treeId)642 int64_t A11yManagerService::GetRootParentId(int32_t windowId, int32_t treeId)
643 {
644 (void)windowId;
645 (void)treeId;
646 return 0;
647 }
648
GetAllTreeId(int32_t windowId, std::vector<int32_t> &treeIds)649 RetError A11yManagerService::GetAllTreeId(int32_t windowId, std::vector<int32_t> &treeIds)
650 {
651 (void)windowId;
652 (void)treeIds;
653 return RET_OK;
654 }
655
OnDataClone()656 void A11yManagerService::OnDataClone()
657 {
658 }
659 } // namespace A11y
660 } // namespace OHOS