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 "accessible_ability_manager_service_proxy.h"
17 #include "accessibility_ability_info_parcel.h"
18 #include "accessibility_caption_parcel.h"
19 #include "accessibility_event_info_parcel.h"
20 #include "accessibility_ipc_interface_code.h"
21 #include "hilog_wrapper.h"
22
23 namespace OHOS {
24 namespace Accessibility {
25
26 const int32_t ABILITY_SIZE_MAX = 10000;
27 const int32_t TREE_ID_MAX = 0x00001FFF;
28
AccessibleAbilityManagerServiceProxy(const sptr<IRemoteObject> & impl)29 AccessibleAbilityManagerServiceProxy::AccessibleAbilityManagerServiceProxy(const sptr<IRemoteObject> &impl)
30 : IRemoteProxy<IAccessibleAbilityManagerService>(impl)
31 {
32 HILOG_INFO("AccessibleAbilityManagerServiceProxy construct.");
33 }
34
~AccessibleAbilityManagerServiceProxy()35 AccessibleAbilityManagerServiceProxy::~AccessibleAbilityManagerServiceProxy()
36 {
37 HILOG_INFO("AccessibleAbilityManagerServiceProxy destruct.");
38 }
39
WriteInterfaceToken(MessageParcel & data)40 bool AccessibleAbilityManagerServiceProxy::WriteInterfaceToken(MessageParcel &data)
41 {
42 HILOG_DEBUG();
43 if (!data.WriteInterfaceToken(AccessibleAbilityManagerServiceProxy::GetDescriptor())) {
44 HILOG_ERROR("write interface token failed");
45 return false;
46 }
47 return true;
48 }
49
SendTransactCmd(AccessibilityInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)50 bool AccessibleAbilityManagerServiceProxy::SendTransactCmd(AccessibilityInterfaceCode code,
51 MessageParcel &data, MessageParcel &reply, MessageOption &option)
52 {
53 HILOG_DEBUG();
54
55 sptr<IRemoteObject> remoteServiceProxy= Remote();
56 if (remoteServiceProxy == nullptr) {
57 HILOG_ERROR("fail to send transact cmd %{public}d due to remote object", code);
58 return false;
59 }
60 int32_t resultServiceProxy =
61 remoteServiceProxy->SendRequest(static_cast<uint32_t>(code), data, reply, option);
62 if (resultServiceProxy != NO_ERROR) {
63 HILOG_ERROR("receive error transact code %{public}d in transact cmd %{public}d", resultServiceProxy, code);
64 return false;
65 }
66 return true;
67 }
68
SendEvent(const AccessibilityEventInfo & uiEvent,const int32_t flag)69 RetError AccessibleAbilityManagerServiceProxy::SendEvent(const AccessibilityEventInfo &uiEvent, const int32_t flag)
70 {
71 HILOG_DEBUG();
72 MessageParcel data;
73 MessageParcel reply;
74 MessageOption option(MessageOption::TF_ASYNC);
75 AccessibilityEventInfoParcel eventInfoParcel(uiEvent);
76
77 if (!WriteInterfaceToken(data)) {
78 HILOG_ERROR("fail, connection write Token");
79 return RET_ERR_IPC_FAILED;
80 }
81
82 if (!data.WriteParcelable(&eventInfoParcel)) {
83 HILOG_ERROR("fail, connection write parcelable AccessibilityEventInfo error");
84 return RET_ERR_IPC_FAILED;
85 }
86
87 if (!SendTransactCmd(AccessibilityInterfaceCode::SEND_EVENT, data, reply, option)) {
88 HILOG_ERROR("SendEvent fail");
89 return RET_ERR_IPC_FAILED;
90 }
91 return RET_OK;
92 }
93
SetCaptionProperty(const AccessibilityConfig::CaptionProperty & caption)94 RetError AccessibleAbilityManagerServiceProxy::SetCaptionProperty(const AccessibilityConfig::CaptionProperty &caption)
95 {
96 HILOG_DEBUG();
97 MessageParcel data;
98 MessageParcel reply;
99 MessageOption option;
100 CaptionPropertyParcel captionParcel(caption);
101
102 if (!WriteInterfaceToken(data)) {
103 HILOG_ERROR("fail, connection write Token");
104 return RET_ERR_IPC_FAILED;
105 }
106
107 if (!data.WriteParcelable(&captionParcel)) {
108 HILOG_ERROR("fail, connection write parcelable Caption Property ");
109 return RET_ERR_IPC_FAILED;
110 }
111
112 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_CAPTION_PROPERTY, data, reply, option)) {
113 HILOG_ERROR("SetCaptionProperty fail");
114 return RET_ERR_IPC_FAILED;
115 }
116 return static_cast<RetError>(reply.ReadInt32());
117 }
118
SetCaptionState(const bool state)119 RetError AccessibleAbilityManagerServiceProxy::SetCaptionState(const bool state)
120 {
121 HILOG_DEBUG();
122 MessageParcel data;
123 MessageParcel reply;
124 MessageOption option;
125
126 if (!WriteInterfaceToken(data)) {
127 HILOG_ERROR("SetCaptionState fail, connection write Token");
128 return RET_ERR_IPC_FAILED;
129 }
130
131 if (!data.WriteBool(state)) {
132 HILOG_ERROR("SetCaptionState fail, connection write parcelable Caption State ");
133 return RET_ERR_IPC_FAILED;
134 }
135
136 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_CAPTION_STATE, data, reply, option)) {
137 HILOG_ERROR("SetCaptionState fail");
138 return RET_ERR_IPC_FAILED;
139 }
140 return static_cast<RetError>(reply.ReadInt32());
141 }
142
RegisterStateObserver(const sptr<IAccessibleAbilityManagerStateObserver> & client)143 uint32_t AccessibleAbilityManagerServiceProxy::RegisterStateObserver(
144 const sptr<IAccessibleAbilityManagerStateObserver> &client)
145 {
146 HILOG_DEBUG();
147 MessageParcel data;
148 MessageParcel reply;
149 MessageOption option;
150
151 if (client == nullptr) {
152 HILOG_ERROR("RegisterStateObserver fail, Input client is null");
153 return TRANSACTION_ERR;
154 }
155
156 if (!WriteInterfaceToken(data)) {
157 HILOG_ERROR("RegisterStateObserver fail, connection write Token error");
158 return TRANSACTION_ERR;
159 }
160
161 if (!data.WriteRemoteObject(client->AsObject())) {
162 HILOG_ERROR("RegisterStateObserver fail, connection write client error");
163 return TRANSACTION_ERR;
164 }
165
166 if (!SendTransactCmd(AccessibilityInterfaceCode::REGISTER_STATE_CALLBACK,
167 data, reply, option)) {
168 HILOG_ERROR("RegisterStateCallback fail");
169 return TRANSACTION_ERR;
170 }
171
172 return reply.ReadUint32();
173 }
174
GetAbilityList(const uint32_t abilityTypes,const int32_t stateType,std::vector<AccessibilityAbilityInfo> & infos)175 RetError AccessibleAbilityManagerServiceProxy::GetAbilityList(const uint32_t abilityTypes, const int32_t stateType,
176 std::vector<AccessibilityAbilityInfo> &infos)
177 {
178 HILOG_DEBUG();
179 MessageParcel data;
180 MessageParcel reply;
181 MessageOption option;
182
183 if (!WriteInterfaceToken(data)) {
184 HILOG_ERROR("fail, connection write Token error");
185 return RET_ERR_IPC_FAILED;
186 }
187
188 if (!data.WriteUint32(abilityTypes)) {
189 HILOG_ERROR("fail, connection write abilityTypes error");
190 return RET_ERR_IPC_FAILED;
191 }
192
193 if (!data.WriteInt32(stateType)) {
194 HILOG_ERROR("fail, connection write stateType error");
195 return RET_ERR_IPC_FAILED;
196 }
197
198 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_ABILITYLIST,
199 data, reply, option)) {
200 HILOG_ERROR("GetAbilityList fail");
201 return RET_ERR_IPC_FAILED;
202 }
203 // read result
204 int32_t abilityInfoSize = reply.ReadInt32();
205 if (abilityInfoSize < 0 || abilityInfoSize > ABILITY_SIZE_MAX) {
206 HILOG_ERROR("abilityInfoSize is invalid");
207 return RET_ERR_INVALID_PARAM;
208 }
209
210 for (int32_t i = 0; i < abilityInfoSize; i++) {
211 sptr<AccessibilityAbilityInfoParcel> info = reply.ReadStrongParcelable<AccessibilityAbilityInfoParcel>();
212 if (info == nullptr) {
213 HILOG_ERROR("ReadStrongParcelable<AccessibilityAbilityInfoParcel> failed");
214 return RET_ERR_IPC_FAILED;
215 }
216 infos.emplace_back(*info);
217 }
218 return static_cast<RetError>(reply.ReadInt32());
219 }
220
RegisterElementOperator(int32_t windowId,const sptr<IAccessibilityElementOperator> & operation,bool isApp)221 RetError AccessibleAbilityManagerServiceProxy::RegisterElementOperator(
222 int32_t windowId, const sptr<IAccessibilityElementOperator> &operation, bool isApp)
223 {
224 HILOG_DEBUG();
225 MessageParcel data;
226 MessageParcel reply;
227 MessageOption option(MessageOption::TF_ASYNC);
228
229 if (operation == nullptr) {
230 HILOG_ERROR("fail, Input operation is null");
231 return RET_ERR_INVALID_PARAM;
232 }
233
234 if (!WriteInterfaceToken(data)) {
235 HILOG_ERROR("fail, connection write Token");
236 return RET_ERR_IPC_FAILED;
237 }
238
239 if (!data.WriteInt32(windowId)) {
240 HILOG_ERROR("fail, connection write windowId error");
241 return RET_ERR_IPC_FAILED;
242 }
243
244 if (!data.WriteRemoteObject(operation->AsObject())) {
245 HILOG_ERROR("fail, connection write parcelable operation error");
246 return RET_ERR_IPC_FAILED;
247 }
248
249 if (!SendTransactCmd(AccessibilityInterfaceCode::REGISTER_INTERACTION_CONNECTION,
250 data, reply, option)) {
251 HILOG_ERROR("RegisterElementOperator fail");
252 return RET_ERR_IPC_FAILED;
253 }
254 return RET_OK;
255 }
256
RegisterElementOperator(Registration parameter,const sptr<IAccessibilityElementOperator> & operation,bool isApp)257 RetError AccessibleAbilityManagerServiceProxy::RegisterElementOperator(Registration parameter,
258 const sptr<IAccessibilityElementOperator> &operation, bool isApp)
259 {
260 HILOG_DEBUG();
261 MessageParcel data;
262 MessageParcel reply;
263 MessageOption option(MessageOption::TF_ASYNC);
264
265 if (operation == nullptr) {
266 HILOG_ERROR("fail, Input operation is null");
267 return RET_ERR_INVALID_PARAM;
268 }
269
270 if (!WriteInterfaceToken(data)) {
271 HILOG_ERROR("fail, connection write Token");
272 return RET_ERR_IPC_FAILED;
273 }
274
275 if (!data.WriteInt32(parameter.windowId)) {
276 HILOG_ERROR("fail, connection write windowId error");
277 return RET_ERR_IPC_FAILED;
278 }
279
280 if (!data.WriteInt32(parameter.parentWindowId)) {
281 HILOG_ERROR("fail, connection write parentWindowId error");
282 return RET_ERR_IPC_FAILED;
283 }
284
285 if (!data.WriteInt32(parameter.parentTreeId)) {
286 HILOG_ERROR("fail, connection write parentTreeId error");
287 return RET_ERR_IPC_FAILED;
288 }
289
290 if (!data.WriteInt64(parameter.elementId)) {
291 HILOG_ERROR("fail, connection write elementId error");
292 return RET_ERR_IPC_FAILED;
293 }
294
295 if (!data.WriteRemoteObject(operation->AsObject())) {
296 HILOG_ERROR("fail, connection write parcelable operation error");
297 return RET_ERR_IPC_FAILED;
298 }
299
300 if (!SendTransactCmd(AccessibilityInterfaceCode::CARDREGISTER_INTERACTION_CONNECTION,
301 data, reply, option)) {
302 HILOG_ERROR("RegisterElementOperator fail");
303 return RET_ERR_IPC_FAILED;
304 }
305 return RET_OK;
306 }
307
DeregisterElementOperator(const int32_t windowId)308 RetError AccessibleAbilityManagerServiceProxy::DeregisterElementOperator(const int32_t windowId)
309 {
310 HILOG_DEBUG("windowId(%{public}d)", windowId);
311 MessageParcel data;
312 MessageParcel reply;
313 MessageOption option(MessageOption::TF_ASYNC);
314
315 if (!WriteInterfaceToken(data)) {
316 HILOG_ERROR("fail, connection write Token");
317 return RET_ERR_IPC_FAILED;
318 }
319
320 if (!data.WriteInt32(windowId)) {
321 HILOG_ERROR("fail, connection write userId error");
322 return RET_ERR_IPC_FAILED;
323 }
324
325 if (!SendTransactCmd(AccessibilityInterfaceCode::DEREGISTER_INTERACTION_CONNECTION,
326 data, reply, option)) {
327 HILOG_ERROR("DeregisterElementOperator fail");
328 return RET_ERR_IPC_FAILED;
329 }
330 return RET_OK;
331 }
332
DeregisterElementOperator(const int32_t windowId,const int32_t treeId)333 RetError AccessibleAbilityManagerServiceProxy::DeregisterElementOperator(const int32_t windowId, const int32_t treeId)
334 {
335 HILOG_DEBUG("windowId(%{public}d)", windowId);
336 MessageParcel data;
337 MessageParcel reply;
338 MessageOption option(MessageOption::TF_ASYNC);
339
340 if (!WriteInterfaceToken(data)) {
341 HILOG_ERROR("fail, connection write Token");
342 return RET_ERR_IPC_FAILED;
343 }
344
345 if (!data.WriteInt32(windowId)) {
346 HILOG_ERROR("fail, connection write windowId error");
347 return RET_ERR_IPC_FAILED;
348 }
349
350 if (!data.WriteInt32(treeId)) {
351 HILOG_ERROR("fail, connection write treeId error");
352 return RET_ERR_IPC_FAILED;
353 }
354 if (!SendTransactCmd(AccessibilityInterfaceCode::CARDDEREGISTER_INTERACTION_CONNECTION,
355 data, reply, option)) {
356 HILOG_ERROR("DeregisterElementOperator fail");
357 return RET_ERR_IPC_FAILED;
358 }
359 return RET_OK;
360 }
361
GetCaptionProperty(AccessibilityConfig::CaptionProperty & caption)362 RetError AccessibleAbilityManagerServiceProxy::GetCaptionProperty(AccessibilityConfig::CaptionProperty &caption)
363 {
364 HILOG_DEBUG();
365 MessageParcel data;
366 MessageParcel reply;
367 MessageOption option;
368 AccessibilityConfig::CaptionProperty property = {};
369 if (!WriteInterfaceToken(data)) {
370 HILOG_ERROR("fail, connection write Token error");
371 return RET_ERR_IPC_FAILED;
372 }
373
374 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_CAPTION_PROPERTY,
375 data, reply, option)) {
376 HILOG_ERROR("GetCaptionProperty fail");
377 return RET_ERR_IPC_FAILED;
378 }
379 RetError ret = static_cast<RetError>(reply.ReadInt32());
380 if (ret == RET_OK) {
381 caption = *reply.ReadStrongParcelable<CaptionPropertyParcel>();
382 }
383 return ret;
384 }
385
RegisterCaptionObserver(const sptr<IAccessibleAbilityManagerCaptionObserver> & client)386 uint32_t AccessibleAbilityManagerServiceProxy::RegisterCaptionObserver(
387 const sptr<IAccessibleAbilityManagerCaptionObserver> &client)
388 {
389 HILOG_DEBUG();
390 MessageParcel data;
391 MessageParcel reply;
392 MessageOption option;
393
394 if (client == nullptr) {
395 HILOG_ERROR("RegisterCaptionObserver fail, Input client is null");
396 return TRANSACTION_ERR;
397 }
398
399 if (!WriteInterfaceToken(data)) {
400 HILOG_ERROR("RegisterCaptionObserver fail, connection write Token error");
401 return TRANSACTION_ERR;
402 }
403
404 if (!data.WriteRemoteObject(client->AsObject())) {
405 HILOG_ERROR("RegisterCaptionObserver fail, connection write client error");
406 return TRANSACTION_ERR;
407 }
408
409 if (!SendTransactCmd(AccessibilityInterfaceCode::REGISTER_CAPTION_PROPERTY_CALLBACK,
410 data, reply, option)) {
411 HILOG_ERROR("RegisterCaptionPropertyCallback fail");
412 return TRANSACTION_ERR;
413 }
414
415 return reply.ReadUint32();
416 }
417
GetEnabledState()418 bool AccessibleAbilityManagerServiceProxy::GetEnabledState()
419 {
420 HILOG_DEBUG();
421 MessageParcel data;
422 MessageParcel reply;
423 MessageOption option;
424
425 if (!WriteInterfaceToken(data)) {
426 HILOG_ERROR("fail, connection write Token");
427 return false;
428 }
429 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_ENABLED,
430 data, reply, option)) {
431 HILOG_ERROR("GetEnabledState fail");
432 return false;
433 }
434 return reply.ReadBool();
435 }
436
GetCaptionState(bool & state)437 RetError AccessibleAbilityManagerServiceProxy::GetCaptionState(bool &state)
438 {
439 HILOG_DEBUG();
440 MessageParcel data;
441 MessageParcel reply;
442 MessageOption option;
443
444 if (!WriteInterfaceToken(data)) {
445 HILOG_ERROR("fail, connection write Token");
446 return RET_ERR_IPC_FAILED;
447 }
448 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_CAPTION_STATE,
449 data, reply, option)) {
450 HILOG_ERROR("GetCaptionState fail");
451 return RET_ERR_IPC_FAILED;
452 }
453 RetError ret = static_cast<RetError>(reply.ReadInt32());
454 if (ret == RET_OK) {
455 state = reply.ReadBool();
456 }
457 return ret;
458 }
459
GetTouchGuideState()460 bool AccessibleAbilityManagerServiceProxy::GetTouchGuideState()
461 {
462 HILOG_DEBUG();
463 MessageParcel data;
464 MessageParcel reply;
465 MessageOption option;
466
467 if (!WriteInterfaceToken(data)) {
468 HILOG_ERROR("fail, connection write Token");
469 return false;
470 }
471 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_TOUCH_GUIDE_STATE,
472 data, reply, option)) {
473 HILOG_ERROR("GetTouchGuideState fail");
474 return false;
475 }
476 return reply.ReadBool();
477 }
478
GetGestureState()479 bool AccessibleAbilityManagerServiceProxy::GetGestureState()
480 {
481 HILOG_DEBUG();
482 MessageParcel data;
483 MessageParcel reply;
484 MessageOption option;
485
486 if (!WriteInterfaceToken(data)) {
487 HILOG_ERROR("fail, connection write Token");
488 return false;
489 }
490 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_GESTURE_STATE,
491 data, reply, option)) {
492 HILOG_ERROR("GetGestureState fail");
493 return false;
494 }
495 return reply.ReadBool();
496 }
497
GetKeyEventObserverState()498 bool AccessibleAbilityManagerServiceProxy::GetKeyEventObserverState()
499 {
500 HILOG_DEBUG();
501 MessageParcel data;
502 MessageParcel reply;
503 MessageOption option;
504
505 if (!WriteInterfaceToken(data)) {
506 HILOG_ERROR("fail, connection write Token");
507 return false;
508 }
509 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_KEY_EVENT_OBSERVE_STATE,
510 data, reply, option)) {
511 HILOG_ERROR("GetKeyEventObserverState fail");
512 return false;
513 }
514 return reply.ReadBool();
515 }
516
EnableAbility(const std::string & name,const uint32_t capabilities)517 RetError AccessibleAbilityManagerServiceProxy::EnableAbility(const std::string &name, const uint32_t capabilities)
518 {
519 HILOG_DEBUG();
520 MessageParcel data;
521 MessageParcel reply;
522 MessageOption option;
523
524 if (!WriteInterfaceToken(data)) {
525 HILOG_ERROR("EnableAbility fail, connection write Token");
526 return RET_ERR_IPC_FAILED;
527 }
528
529 if (!data.WriteString(name)) {
530 HILOG_ERROR("name write error: %{public}s, ", name.c_str());
531 return RET_ERR_IPC_FAILED;
532 }
533
534 if (!data.WriteUint32(capabilities)) {
535 HILOG_ERROR("capabilities write error: %{public}d, ", capabilities);
536 return RET_ERR_IPC_FAILED;
537 }
538
539 if (!SendTransactCmd(AccessibilityInterfaceCode::ENABLE_ABILITIES,
540 data, reply, option)) {
541 HILOG_ERROR("EnableAbility fail");
542 return RET_ERR_IPC_FAILED;
543 }
544 return static_cast<RetError>(reply.ReadInt32());
545 }
546
GetEnabledAbilities(std::vector<std::string> & enabledAbilities)547 RetError AccessibleAbilityManagerServiceProxy::GetEnabledAbilities(std::vector<std::string> &enabledAbilities)
548 {
549 HILOG_DEBUG();
550 MessageParcel data;
551 MessageParcel reply;
552 MessageOption option;
553
554 if (!WriteInterfaceToken(data)) {
555 HILOG_ERROR("fail, connection write Token error");
556 return RET_ERR_IPC_FAILED;
557 }
558 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_ENABLED_OBJECT,
559 data, reply, option)) {
560 HILOG_ERROR("GetEnabledAbilities fail");
561 return RET_ERR_IPC_FAILED;
562 }
563
564 int32_t dev_num = reply.ReadInt32();
565 if (dev_num < 0 || dev_num > ABILITY_SIZE_MAX) {
566 HILOG_ERROR("dev_num is invalid");
567 return RET_ERR_INVALID_PARAM;
568 }
569
570 for (int32_t i = 0; i < dev_num; i++) {
571 enabledAbilities.push_back(reply.ReadString());
572 }
573 return static_cast<RetError>(reply.ReadInt32());
574 }
575
DisableAbility(const std::string & name)576 RetError AccessibleAbilityManagerServiceProxy::DisableAbility(const std::string &name)
577 {
578 HILOG_DEBUG();
579 MessageParcel data;
580 MessageParcel reply;
581 MessageOption option;
582
583 if (!WriteInterfaceToken(data)) {
584 HILOG_ERROR("DisableAbility fail, connection write Token");
585 return RET_ERR_IPC_FAILED;
586 }
587
588 if (!data.WriteString(name)) {
589 HILOG_ERROR("name write error: %{public}s, ", name.c_str());
590 return RET_ERR_IPC_FAILED;
591 }
592 if (!SendTransactCmd(AccessibilityInterfaceCode::DISABLE_ABILITIES,
593 data, reply, option)) {
594 HILOG_ERROR("DisableAbility fail");
595 return RET_ERR_IPC_FAILED;
596 }
597 return static_cast<RetError>(reply.ReadInt32());
598 }
599
GetActiveWindow()600 int32_t AccessibleAbilityManagerServiceProxy::GetActiveWindow()
601 {
602 HILOG_DEBUG();
603 MessageParcel data;
604 MessageParcel reply;
605 MessageOption option;
606
607 if (!WriteInterfaceToken(data)) {
608 HILOG_ERROR("fail, connection write Token");
609 return false;
610 }
611
612 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_ACTIVE_WINDOW,
613 data, reply, option)) {
614 HILOG_ERROR("GetActiveWindow fail");
615 return false;
616 }
617 return reply.ReadInt32();
618 }
619
EnableUITestAbility(const sptr<IRemoteObject> & obj)620 RetError AccessibleAbilityManagerServiceProxy::EnableUITestAbility(const sptr<IRemoteObject> &obj)
621 {
622 HILOG_DEBUG();
623 MessageParcel data;
624 MessageParcel reply;
625 MessageOption option;
626
627 if (!WriteInterfaceToken(data)) {
628 HILOG_ERROR("fail, connection write Token");
629 return RET_ERR_IPC_FAILED;
630 }
631
632 if (!data.WriteRemoteObject(obj)) {
633 HILOG_ERROR("fail, connection write obj");
634 return RET_ERR_IPC_FAILED;
635 }
636
637 if (!SendTransactCmd(AccessibilityInterfaceCode::ENABLE_UI_TEST_ABILITY,
638 data, reply, option)) {
639 HILOG_ERROR("EnableUITestAbility fail");
640 return RET_ERR_IPC_FAILED;
641 }
642 RetError result = static_cast<RetError>(reply.ReadInt32());
643 HILOG_DEBUG("enable result is %{public}d", result);
644 return result;
645 }
646
DisableUITestAbility()647 RetError AccessibleAbilityManagerServiceProxy::DisableUITestAbility()
648 {
649 HILOG_DEBUG();
650 MessageParcel data;
651 MessageParcel reply;
652 MessageOption option;
653
654 if (!WriteInterfaceToken(data)) {
655 HILOG_ERROR("fail, connection write Token");
656 return RET_ERR_IPC_FAILED;
657 }
658
659 if (!SendTransactCmd(AccessibilityInterfaceCode::DISABLE_UI_TEST_ABILITY,
660 data, reply, option)) {
661 HILOG_ERROR("DisableUITestAbility fail");
662 return RET_ERR_IPC_FAILED;
663 }
664 return static_cast<RetError>(reply.ReadInt32());
665 }
666
SetScreenMagnificationState(const bool state)667 RetError AccessibleAbilityManagerServiceProxy::SetScreenMagnificationState(const bool state)
668 {
669 HILOG_DEBUG();
670 MessageParcel data;
671 MessageParcel reply;
672 MessageOption option;
673
674 if (!WriteInterfaceToken(data)) {
675 HILOG_ERROR("SetScreenMagnificationState fail, connection write Token");
676 return RET_ERR_IPC_FAILED;
677 }
678
679 if (!data.WriteBool(state)) {
680 HILOG_ERROR("SetScreenMagnificationState fail, connection write parcelable Caption State ");
681 return RET_ERR_IPC_FAILED;
682 }
683
684 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_SCREENMAGNIFIER_STATE, data, reply, option)) {
685 HILOG_ERROR("SetScreenMagnificationState fail");
686 return RET_ERR_IPC_FAILED;
687 }
688
689 return static_cast<RetError>(reply.ReadInt32());
690 }
691
SetShortKeyState(const bool state)692 RetError AccessibleAbilityManagerServiceProxy::SetShortKeyState(const bool state)
693 {
694 HILOG_DEBUG();
695 MessageParcel data;
696 MessageParcel reply;
697 MessageOption option;
698
699 if (!WriteInterfaceToken(data)) {
700 HILOG_ERROR("SetShortKeyState fail, connection write Token");
701 return RET_ERR_IPC_FAILED;
702 }
703
704 if (!data.WriteBool(state)) {
705 HILOG_ERROR("SetShortKeyState fail, connection write parcelable Caption State ");
706 return RET_ERR_IPC_FAILED;
707 }
708
709 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_SHORTKEY_STATE, data, reply, option)) {
710 HILOG_ERROR("SetShortKeyState fail");
711 return RET_ERR_IPC_FAILED;
712 }
713
714 return static_cast<RetError>(reply.ReadInt32());
715 }
716
SetMouseKeyState(const bool state)717 RetError AccessibleAbilityManagerServiceProxy::SetMouseKeyState(const bool state)
718 {
719 HILOG_DEBUG();
720 MessageParcel data;
721 MessageParcel reply;
722 MessageOption option;
723
724 if (!WriteInterfaceToken(data)) {
725 HILOG_ERROR("SetMouseKeyState fail, connection write Token");
726 return RET_ERR_IPC_FAILED;
727 }
728
729 if (!data.WriteBool(state)) {
730 HILOG_ERROR("SetMouseKeyState fail, connection write parcelable Caption State");
731 return RET_ERR_IPC_FAILED;
732 }
733
734 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_MOUSEKEY_STATE, data, reply, option)) {
735 HILOG_ERROR("SetMouseKeyState fail");
736 return RET_ERR_IPC_FAILED;
737 }
738
739 return static_cast<RetError>(reply.ReadInt32());
740 }
741
SetMouseAutoClick(const int32_t time)742 RetError AccessibleAbilityManagerServiceProxy::SetMouseAutoClick(const int32_t time)
743 {
744 HILOG_DEBUG();
745 MessageParcel data;
746 MessageParcel reply;
747 MessageOption option;
748
749 if (!WriteInterfaceToken(data)) {
750 HILOG_ERROR("fail, connection write Token");
751 return RET_ERR_IPC_FAILED;
752 }
753
754 if (!data.WriteInt32(time)) {
755 HILOG_ERROR("fail, connection write SetMouseAutoClick time");
756 return RET_ERR_IPC_FAILED;
757 }
758
759 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_MOUSEKEY_AUTOCLICK, data, reply, option)) {
760 HILOG_ERROR("SetMouseAutoClick fail");
761 return RET_ERR_IPC_FAILED;
762 }
763
764 return static_cast<RetError>(reply.ReadInt32());
765 }
766
SetShortkeyTarget(const std::string & name)767 RetError AccessibleAbilityManagerServiceProxy::SetShortkeyTarget(const std::string &name)
768 {
769 HILOG_DEBUG();
770 MessageParcel data;
771 MessageParcel reply;
772 MessageOption option;
773
774 if (!WriteInterfaceToken(data)) {
775 HILOG_ERROR("DisableAbility fail, connection write Token");
776 return RET_ERR_IPC_FAILED;
777 }
778
779 if (!data.WriteString(name)) {
780 HILOG_ERROR("fail, connection write SetShortkeyTarget name");
781 return RET_ERR_IPC_FAILED;
782 }
783
784 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_SHORTKEY_TARGET, data, reply, option)) {
785 HILOG_ERROR("SetShortkeyTarget fail");
786 return RET_ERR_IPC_FAILED;
787 }
788
789 return static_cast<RetError>(reply.ReadInt32());
790 }
791
SetShortkeyMultiTarget(const std::vector<std::string> & name)792 RetError AccessibleAbilityManagerServiceProxy::SetShortkeyMultiTarget(const std::vector<std::string> &name)
793 {
794 HILOG_DEBUG();
795 MessageParcel data;
796 MessageParcel reply;
797 MessageOption option;
798
799 if (!WriteInterfaceToken(data)) {
800 HILOG_ERROR("DisableAbility fail, connection write Token");
801 return RET_ERR_IPC_FAILED;
802 }
803
804 if (!data.WriteStringVector(name)) {
805 HILOG_ERROR("fail, connection write SetShortkeyMultiTarget name");
806 return RET_ERR_IPC_FAILED;
807 }
808
809 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_SHORTKEY_MULTI_TARGET, data, reply, option)) {
810 HILOG_ERROR("send SetShortkeyMultiTarget fail");
811 return RET_ERR_IPC_FAILED;
812 }
813
814 return static_cast<RetError>(reply.ReadInt32());
815 }
816
SetHighContrastTextState(const bool state)817 RetError AccessibleAbilityManagerServiceProxy::SetHighContrastTextState(const bool state)
818 {
819 HILOG_DEBUG();
820 MessageParcel data;
821 MessageParcel reply;
822 MessageOption option;
823
824 if (!WriteInterfaceToken(data)) {
825 HILOG_ERROR("SetHighContrastTextState fail, connection write Token");
826 return RET_ERR_IPC_FAILED;
827 }
828
829 if (!data.WriteBool(state)) {
830 HILOG_ERROR("SetHighContrastTextState fail, connection write parcelable Caption State");
831 return RET_ERR_IPC_FAILED;
832 }
833
834 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_HIGHCONTRASTTEXT_STATE, data, reply, option)) {
835 HILOG_ERROR("SetHighContrastTextState fail");
836 return RET_ERR_IPC_FAILED;
837 }
838
839 return static_cast<RetError>(reply.ReadInt32());
840 }
841
SetInvertColorState(const bool state)842 RetError AccessibleAbilityManagerServiceProxy::SetInvertColorState(const bool state)
843 {
844 HILOG_DEBUG();
845 MessageParcel data;
846 MessageParcel reply;
847 MessageOption option;
848
849 if (!WriteInterfaceToken(data)) {
850 HILOG_ERROR("SetInvertColorState fail, connection write Token");
851 return RET_ERR_IPC_FAILED;
852 }
853
854 if (!data.WriteBool(state)) {
855 HILOG_ERROR("SetInvertColorState fail, connection write parcelable Caption State ");
856 return RET_ERR_IPC_FAILED;
857 }
858
859 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_INVERTCOLOR_STATE, data, reply, option)) {
860 HILOG_ERROR("SetInvertColorState fail");
861 return RET_ERR_IPC_FAILED;
862 }
863
864 return static_cast<RetError>(reply.ReadInt32());
865 }
866
SetAnimationOffState(const bool state)867 RetError AccessibleAbilityManagerServiceProxy::SetAnimationOffState(const bool state)
868 {
869 HILOG_DEBUG();
870 MessageParcel data;
871 MessageParcel reply;
872 MessageOption option;
873
874 if (!WriteInterfaceToken(data)) {
875 HILOG_ERROR("SetAnimationOffState fail, connection write Token");
876 return RET_ERR_IPC_FAILED;
877 }
878
879 if (!data.WriteBool(state)) {
880 HILOG_ERROR("SetAnimationOffState fail, connection write parcelable Caption State ");
881 return RET_ERR_IPC_FAILED;
882 }
883
884 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_ANIMATIONOFF_STATE, data, reply, option)) {
885 HILOG_ERROR("SetAnimationOffState fail");
886 return RET_ERR_IPC_FAILED;
887 }
888
889 return static_cast<RetError>(reply.ReadInt32());
890 }
891
SetAudioMonoState(const bool state)892 RetError AccessibleAbilityManagerServiceProxy::SetAudioMonoState(const bool state)
893 {
894 HILOG_DEBUG();
895 MessageParcel data;
896 MessageParcel reply;
897 MessageOption option;
898
899 if (!WriteInterfaceToken(data)) {
900 HILOG_ERROR("SetAudioMonoState fail, connection write Token");
901 return RET_ERR_IPC_FAILED;
902 }
903
904 if (!data.WriteBool(state)) {
905 HILOG_ERROR("SetAudioMonoState fail, connection write parcelable Caption State ");
906 return RET_ERR_IPC_FAILED;
907 }
908
909 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_AUDIOMONO_STATE, data, reply, option)) {
910 HILOG_ERROR("SetAudioMonoState fail");
911 return RET_ERR_IPC_FAILED;
912 }
913
914 return static_cast<RetError>(reply.ReadInt32());
915 }
916
SetDaltonizationState(const bool state)917 RetError AccessibleAbilityManagerServiceProxy::SetDaltonizationState(const bool state)
918 {
919 HILOG_DEBUG();
920 MessageParcel data;
921 MessageParcel reply;
922 MessageOption option;
923
924 if (!WriteInterfaceToken(data)) {
925 HILOG_ERROR("SetDaltonizationState fail, connection write Token");
926 return RET_ERR_IPC_FAILED;
927 }
928
929 if (!data.WriteBool(state)) {
930 HILOG_ERROR("SetDaltonizationState fail, connection write parcelable Caption State");
931 return RET_ERR_IPC_FAILED;
932 }
933
934 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_DALTONIZATION_STATE, data, reply, option)) {
935 HILOG_ERROR("SetDaltonizationState fail");
936 return RET_ERR_IPC_FAILED;
937 }
938
939 return static_cast<RetError>(reply.ReadInt32());
940 }
941
SetDaltonizationColorFilter(const uint32_t filter)942 RetError AccessibleAbilityManagerServiceProxy::SetDaltonizationColorFilter(const uint32_t filter)
943 {
944 HILOG_DEBUG();
945 MessageParcel data;
946 MessageParcel reply;
947 MessageOption option;
948
949 if (!WriteInterfaceToken(data)) {
950 HILOG_ERROR("fail, connection write Token");
951 return RET_ERR_IPC_FAILED;
952 }
953
954 if (!data.WriteUint32(filter)) {
955 HILOG_ERROR("fail, connection write SetDaltonizationColorFilter time");
956 return RET_ERR_IPC_FAILED;
957 }
958
959 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_DALTONIZATION_COLORFILTER,
960 data, reply, option)) {
961 HILOG_ERROR("SetDaltonizationColorFilter fail");
962 return RET_ERR_IPC_FAILED;
963 }
964
965 return static_cast<RetError>(reply.ReadInt32());
966 }
967
SetContentTimeout(const uint32_t time)968 RetError AccessibleAbilityManagerServiceProxy::SetContentTimeout(const uint32_t time)
969 {
970 HILOG_DEBUG();
971 MessageParcel data;
972 MessageParcel reply;
973 MessageOption option;
974
975 if (!WriteInterfaceToken(data)) {
976 HILOG_ERROR("fail, connection write Token");
977 return RET_ERR_IPC_FAILED;
978 }
979
980 if (!data.WriteUint32(time)) {
981 HILOG_ERROR("fail, connection write SetContentTimeout time");
982 return RET_ERR_IPC_FAILED;
983 }
984
985 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_CONTENT_TIMEOUT, data, reply, option)) {
986 HILOG_ERROR("SetContentTimeout fail");
987 return RET_ERR_IPC_FAILED;
988 }
989
990 return static_cast<RetError>(reply.ReadInt32());
991 }
992
SetBrightnessDiscount(const float discount)993 RetError AccessibleAbilityManagerServiceProxy::SetBrightnessDiscount(const float discount)
994 {
995 HILOG_DEBUG();
996 MessageParcel data;
997 MessageParcel reply;
998 MessageOption option;
999
1000 if (!WriteInterfaceToken(data)) {
1001 HILOG_ERROR("fail, connection write Token");
1002 return RET_ERR_IPC_FAILED;
1003 }
1004
1005 if (!data.WriteFloat(discount)) {
1006 HILOG_ERROR("fail, connection write SetBrightnessDiscount time");
1007 return RET_ERR_IPC_FAILED;
1008 }
1009
1010 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_BRIGHTNESS_DISCOUNT, data, reply, option)) {
1011 HILOG_ERROR("SetBrightnessDiscount fail");
1012 return RET_ERR_IPC_FAILED;
1013 }
1014
1015 return static_cast<RetError>(reply.ReadInt32());
1016 }
1017
SetAudioBalance(const float balance)1018 RetError AccessibleAbilityManagerServiceProxy::SetAudioBalance(const float balance)
1019 {
1020 HILOG_DEBUG();
1021 MessageParcel data;
1022 MessageParcel reply;
1023 MessageOption option;
1024
1025 if (!WriteInterfaceToken(data)) {
1026 HILOG_ERROR("fail, connection write Token");
1027 return RET_ERR_IPC_FAILED;
1028 }
1029
1030 if (!data.WriteFloat(balance)) {
1031 HILOG_ERROR("fail, connection write SetAudioBalance time");
1032 return RET_ERR_IPC_FAILED;
1033 }
1034
1035 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_AUDIO_BALANCE, data, reply, option)) {
1036 HILOG_ERROR("SetAudioBalance fail");
1037 return RET_ERR_IPC_FAILED;
1038 }
1039
1040 return static_cast<RetError>(reply.ReadInt32());
1041 }
1042
SetClickResponseTime(const uint32_t time)1043 RetError AccessibleAbilityManagerServiceProxy::SetClickResponseTime(const uint32_t time)
1044 {
1045 HILOG_DEBUG();
1046 MessageParcel data;
1047 MessageParcel reply;
1048 MessageOption option;
1049
1050 if (!WriteInterfaceToken(data)) {
1051 HILOG_ERROR("fail, connection write Token");
1052 return RET_ERR_IPC_FAILED;
1053 }
1054
1055 if (!data.WriteUint32(time)) {
1056 HILOG_ERROR("fail, connection write SetAudioBalance time");
1057 return RET_ERR_IPC_FAILED;
1058 }
1059
1060 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_CLICK_RESPONSE_TIME, data, reply, option)) {
1061 HILOG_ERROR("SetClickResponseTime fail");
1062 return RET_ERR_IPC_FAILED;
1063 }
1064
1065 return static_cast<RetError>(reply.ReadInt32());
1066 }
1067
SetIgnoreRepeatClickState(const bool state)1068 RetError AccessibleAbilityManagerServiceProxy::SetIgnoreRepeatClickState(const bool state)
1069 {
1070 HILOG_DEBUG();
1071 MessageParcel data;
1072 MessageParcel reply;
1073 MessageOption option;
1074
1075 if (!WriteInterfaceToken(data)) {
1076 HILOG_ERROR("fail, connection write Token");
1077 return RET_ERR_IPC_FAILED;
1078 }
1079
1080 if (!data.WriteBool(state)) {
1081 HILOG_ERROR("fail, connection write SetAudioBalance time");
1082 return RET_ERR_IPC_FAILED;
1083 }
1084
1085 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_IGNORE_REPEAT_CLICK_STATE, data, reply, option)) {
1086 HILOG_ERROR("SetIgnoreRepeatClickState fail");
1087 return RET_ERR_IPC_FAILED;
1088 }
1089
1090 return static_cast<RetError>(reply.ReadInt32());
1091 }
1092
SetIgnoreRepeatClickTime(const uint32_t time)1093 RetError AccessibleAbilityManagerServiceProxy::SetIgnoreRepeatClickTime(const uint32_t time)
1094 {
1095 HILOG_DEBUG();
1096 MessageParcel data;
1097 MessageParcel reply;
1098 MessageOption option;
1099
1100 if (!WriteInterfaceToken(data)) {
1101 HILOG_ERROR("fail, connection write Token");
1102 return RET_ERR_IPC_FAILED;
1103 }
1104
1105 if (!data.WriteUint32(time)) {
1106 HILOG_ERROR("fail, connection write SetAudioBalance time");
1107 return RET_ERR_IPC_FAILED;
1108 }
1109
1110 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_IGNORE_REPEAT_CLICK_TIME, data, reply, option)) {
1111 HILOG_ERROR("SetIgnoreRepeatClickTime fail");
1112 return RET_ERR_IPC_FAILED;
1113 }
1114
1115 return static_cast<RetError>(reply.ReadInt32());
1116 }
1117
GetScreenMagnificationState(bool & state)1118 RetError AccessibleAbilityManagerServiceProxy::GetScreenMagnificationState(bool &state)
1119 {
1120 HILOG_DEBUG();
1121 MessageParcel data;
1122 MessageParcel reply;
1123 MessageOption option;
1124
1125 if (!WriteInterfaceToken(data)) {
1126 HILOG_ERROR("fail, connection write Token");
1127 return RET_ERR_IPC_FAILED;
1128 }
1129 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_SCREENMAGNIFIER_STATE,
1130 data, reply, option)) {
1131 HILOG_ERROR("GetScreenMagnificationState fail");
1132 return RET_ERR_IPC_FAILED;
1133 }
1134
1135 RetError ret = static_cast<RetError>(reply.ReadInt32());
1136 if (ret == RET_OK) {
1137 state = reply.ReadBool();
1138 }
1139 return ret;
1140 }
1141
GetShortKeyState(bool & state)1142 RetError AccessibleAbilityManagerServiceProxy::GetShortKeyState(bool &state)
1143 {
1144 HILOG_DEBUG();
1145 MessageParcel data;
1146 MessageParcel reply;
1147 MessageOption option;
1148
1149 if (!WriteInterfaceToken(data)) {
1150 HILOG_ERROR("fail, connection write Token");
1151 return RET_ERR_IPC_FAILED;
1152 }
1153 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_SHORTKEY_STATE,
1154 data, reply, option)) {
1155 HILOG_ERROR("GetShortKeyState fail");
1156 return RET_ERR_IPC_FAILED;
1157 }
1158 RetError ret = static_cast<RetError>(reply.ReadInt32());
1159 if (ret == RET_OK) {
1160 state = reply.ReadBool();
1161 }
1162 return ret;
1163 }
1164
GetMouseKeyState(bool & state)1165 RetError AccessibleAbilityManagerServiceProxy::GetMouseKeyState(bool &state)
1166 {
1167 HILOG_DEBUG();
1168 MessageParcel data;
1169 MessageParcel reply;
1170 MessageOption option;
1171
1172 if (!WriteInterfaceToken(data)) {
1173 HILOG_ERROR("fail, connection write Token");
1174 return RET_ERR_IPC_FAILED;
1175 }
1176 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_MOUSEKEY_STATE,
1177 data, reply, option)) {
1178 HILOG_ERROR("GetMouseKeyState fail");
1179 return RET_ERR_IPC_FAILED;
1180 }
1181 RetError ret = static_cast<RetError>(reply.ReadInt32());
1182 if (ret == RET_OK) {
1183 state = reply.ReadBool();
1184 }
1185 return ret;
1186 }
1187
GetMouseAutoClick(int32_t & time)1188 RetError AccessibleAbilityManagerServiceProxy::GetMouseAutoClick(int32_t &time)
1189 {
1190 HILOG_DEBUG();
1191 MessageParcel data;
1192 MessageParcel reply;
1193 MessageOption option;
1194
1195 if (!WriteInterfaceToken(data)) {
1196 HILOG_ERROR("fail, connection write Token");
1197 return RET_ERR_IPC_FAILED;
1198 }
1199 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_MOUSEKEY_AUTOCLICK,
1200 data, reply, option)) {
1201 HILOG_ERROR("GetMouseAutoClick fail");
1202 return RET_ERR_IPC_FAILED;
1203 }
1204 RetError ret = static_cast<RetError>(reply.ReadInt32());
1205 if (ret == RET_OK) {
1206 time = reply.ReadInt32();
1207 }
1208 return ret;
1209 }
1210
GetShortkeyTarget(std::string & name)1211 RetError AccessibleAbilityManagerServiceProxy::GetShortkeyTarget(std::string &name)
1212 {
1213 HILOG_DEBUG();
1214 MessageParcel data;
1215 MessageParcel reply;
1216 MessageOption option;
1217 if (!WriteInterfaceToken(data)) {
1218 HILOG_ERROR("fail, connection write Token");
1219 return RET_ERR_IPC_FAILED;
1220 }
1221 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_SHORTKEY_TARGET,
1222 data, reply, option)) {
1223 HILOG_ERROR("GetShortkeyTarget fail");
1224 return RET_ERR_IPC_FAILED;
1225 }
1226 RetError ret = static_cast<RetError>(reply.ReadInt32());
1227 if (ret == RET_OK) {
1228 name = reply.ReadString();
1229 }
1230 return ret;
1231 }
1232
GetShortkeyMultiTarget(std::vector<std::string> & name)1233 RetError AccessibleAbilityManagerServiceProxy::GetShortkeyMultiTarget(std::vector<std::string> &name)
1234 {
1235 HILOG_DEBUG();
1236 MessageParcel data;
1237 MessageParcel reply;
1238 MessageOption option;
1239 if (!WriteInterfaceToken(data)) {
1240 HILOG_ERROR("fail, connection write Token");
1241 return RET_ERR_IPC_FAILED;
1242 }
1243 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_SHORTKEY_MULTI_TARGET,
1244 data, reply, option)) {
1245 HILOG_ERROR("GetShortkeyMultiTarget fail");
1246 return RET_ERR_IPC_FAILED;
1247 }
1248 RetError ret = static_cast<RetError>(reply.ReadInt32());
1249 if (ret != RET_OK) {
1250 return ret;
1251 }
1252 if (!reply.ReadStringVector(&name)) {
1253 return RET_ERR_IPC_FAILED;
1254 }
1255 return RET_OK;
1256 }
1257
GetHighContrastTextState(bool & state)1258 RetError AccessibleAbilityManagerServiceProxy::GetHighContrastTextState(bool &state)
1259 {
1260 HILOG_DEBUG();
1261 MessageParcel data;
1262 MessageParcel reply;
1263 MessageOption option;
1264
1265 if (!WriteInterfaceToken(data)) {
1266 HILOG_ERROR("fail, connection write Token");
1267 return RET_ERR_IPC_FAILED;
1268 }
1269 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_HIGHCONTRASTTEXT_STATE,
1270 data, reply, option)) {
1271 HILOG_ERROR("GetHighContrastTextState fail");
1272 return RET_ERR_IPC_FAILED;
1273 }
1274 RetError ret = static_cast<RetError>(reply.ReadInt32());
1275 if (ret == RET_OK) {
1276 state = reply.ReadBool();
1277 }
1278 return ret;
1279 }
1280
GetInvertColorState(bool & state)1281 RetError AccessibleAbilityManagerServiceProxy::GetInvertColorState(bool &state)
1282 {
1283 HILOG_DEBUG();
1284 MessageParcel data;
1285 MessageParcel reply;
1286 MessageOption option;
1287
1288 if (!WriteInterfaceToken(data)) {
1289 HILOG_ERROR("fail, connection write Token");
1290 return RET_ERR_IPC_FAILED;
1291 }
1292 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_INVERTCOLOR_STATE,
1293 data, reply, option)) {
1294 HILOG_ERROR("GetInvertColorState fail");
1295 return RET_ERR_IPC_FAILED;
1296 }
1297 RetError ret = static_cast<RetError>(reply.ReadInt32());
1298 if (ret == RET_OK) {
1299 state = reply.ReadBool();
1300 }
1301 return ret;
1302 }
1303
GetAnimationOffState(bool & state)1304 RetError AccessibleAbilityManagerServiceProxy::GetAnimationOffState(bool &state)
1305 {
1306 HILOG_DEBUG();
1307 MessageParcel data;
1308 MessageParcel reply;
1309 MessageOption option;
1310
1311 if (!WriteInterfaceToken(data)) {
1312 HILOG_ERROR("fail, connection write Token");
1313 return RET_ERR_IPC_FAILED;
1314 }
1315 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_ANIMATIONOFF_STATE,
1316 data, reply, option)) {
1317 HILOG_ERROR("GetAnimationOffState fail");
1318 return RET_ERR_IPC_FAILED;
1319 }
1320 RetError ret = static_cast<RetError>(reply.ReadInt32());
1321 if (ret == RET_OK) {
1322 state = reply.ReadBool();
1323 }
1324 return ret;
1325 }
1326
GetAudioMonoState(bool & state)1327 RetError AccessibleAbilityManagerServiceProxy::GetAudioMonoState(bool &state)
1328 {
1329 HILOG_DEBUG();
1330 MessageParcel data;
1331 MessageParcel reply;
1332 MessageOption option;
1333
1334 if (!WriteInterfaceToken(data)) {
1335 HILOG_ERROR("fail, connection write Token");
1336 return RET_ERR_IPC_FAILED;
1337 }
1338 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_AUDIOMONO_STATE,
1339 data, reply, option)) {
1340 HILOG_ERROR("GetAudioMonoState fail");
1341 return RET_ERR_IPC_FAILED;
1342 }
1343 RetError ret = static_cast<RetError>(reply.ReadInt32());
1344 if (ret == RET_OK) {
1345 state = reply.ReadBool();
1346 }
1347 return ret;
1348 }
1349
GetDaltonizationState(bool & state)1350 RetError AccessibleAbilityManagerServiceProxy::GetDaltonizationState(bool &state)
1351 {
1352 HILOG_DEBUG();
1353 MessageParcel data;
1354 MessageParcel reply;
1355 MessageOption option;
1356
1357 if (!WriteInterfaceToken(data)) {
1358 HILOG_ERROR("fail, connection write Token");
1359 return RET_ERR_IPC_FAILED;
1360 }
1361 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_DALTONIZATION_STATE,
1362 data, reply, option)) {
1363 HILOG_ERROR("GetDaltonizationState fail");
1364 return RET_ERR_IPC_FAILED;
1365 }
1366 RetError ret = static_cast<RetError>(reply.ReadInt32());
1367 if (ret == RET_OK) {
1368 state = reply.ReadBool();
1369 }
1370 return ret;
1371 }
1372
GetDaltonizationColorFilter(uint32_t & type)1373 RetError AccessibleAbilityManagerServiceProxy::GetDaltonizationColorFilter(uint32_t &type)
1374 {
1375 HILOG_DEBUG();
1376 MessageParcel data;
1377 MessageParcel reply;
1378 MessageOption option;
1379
1380 if (!WriteInterfaceToken(data)) {
1381 HILOG_ERROR("fail, connection write Token");
1382 return RET_ERR_IPC_FAILED;
1383 }
1384 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_DALTONIZATION_COLORFILTER,
1385 data, reply, option)) {
1386 HILOG_ERROR("GetDaltonizationColorFilter fail");
1387 return RET_ERR_IPC_FAILED;
1388 }
1389 RetError ret = static_cast<RetError>(reply.ReadInt32());
1390 if (ret == RET_OK) {
1391 type = reply.ReadUint32();
1392 }
1393 return ret;
1394 }
1395
GetContentTimeout(uint32_t & timer)1396 RetError AccessibleAbilityManagerServiceProxy::GetContentTimeout(uint32_t &timer)
1397 {
1398 HILOG_DEBUG();
1399 MessageParcel data;
1400 MessageParcel reply;
1401 MessageOption option;
1402
1403 if (!WriteInterfaceToken(data)) {
1404 HILOG_ERROR("fail, connection write Token");
1405 return RET_ERR_IPC_FAILED;
1406 }
1407 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_CONTENT_TIMEOUT,
1408 data, reply, option)) {
1409 HILOG_ERROR("GetContentTimeout fail");
1410 return RET_ERR_IPC_FAILED;
1411 }
1412 RetError ret = static_cast<RetError>(reply.ReadInt32());
1413 if (ret == RET_OK) {
1414 timer = reply.ReadUint32();
1415 }
1416 return ret;
1417 }
1418
GetBrightnessDiscount(float & brightness)1419 RetError AccessibleAbilityManagerServiceProxy::GetBrightnessDiscount(float &brightness)
1420 {
1421 HILOG_DEBUG();
1422 MessageParcel data;
1423 MessageParcel reply;
1424 MessageOption option;
1425
1426 if (!WriteInterfaceToken(data)) {
1427 HILOG_ERROR("fail, connection write Token");
1428 return RET_ERR_IPC_FAILED;
1429 }
1430 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_BRIGHTNESS_DISCOUNT,
1431 data, reply, option)) {
1432 HILOG_ERROR("GetBrightnessDiscount fail");
1433 return RET_ERR_IPC_FAILED;
1434 }
1435 RetError ret = static_cast<RetError>(reply.ReadInt32());
1436 if (ret == RET_OK) {
1437 brightness = reply.ReadFloat();
1438 }
1439 return ret;
1440 }
1441
GetAudioBalance(float & balance)1442 RetError AccessibleAbilityManagerServiceProxy::GetAudioBalance(float &balance)
1443 {
1444 HILOG_DEBUG();
1445 MessageParcel data;
1446 MessageParcel reply;
1447 MessageOption option;
1448
1449 if (!WriteInterfaceToken(data)) {
1450 HILOG_ERROR("fail, connection write Token");
1451 return RET_ERR_IPC_FAILED;
1452 }
1453 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_AUDIO_BALANCE,
1454 data, reply, option)) {
1455 HILOG_ERROR("GetAudioBalance fail");
1456 return RET_ERR_IPC_FAILED;
1457 }
1458 RetError ret = static_cast<RetError>(reply.ReadInt32());
1459 if (ret == RET_OK) {
1460 balance = reply.ReadFloat();
1461 }
1462 return ret;
1463 }
1464
GetClickResponseTime(uint32_t & time)1465 RetError AccessibleAbilityManagerServiceProxy::GetClickResponseTime(uint32_t& time)
1466 {
1467 HILOG_DEBUG();
1468 MessageParcel data;
1469 MessageParcel reply;
1470 MessageOption option;
1471
1472 if (!WriteInterfaceToken(data)) {
1473 HILOG_ERROR("fail, connection write Token");
1474 return RET_ERR_IPC_FAILED;
1475 }
1476 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_CLICK_RESPONSE_TIME,
1477 data, reply, option)) {
1478 HILOG_ERROR("GetAudioBalance fail");
1479 return RET_ERR_IPC_FAILED;
1480 }
1481 RetError ret = static_cast<RetError>(reply.ReadInt32());
1482 if (ret == RET_OK) {
1483 time = reply.ReadUint32();
1484 }
1485 return ret;
1486 }
1487
GetIgnoreRepeatClickState(bool & state)1488 RetError AccessibleAbilityManagerServiceProxy::GetIgnoreRepeatClickState(bool& state)
1489 {
1490 HILOG_DEBUG();
1491 MessageParcel data;
1492 MessageParcel reply;
1493 MessageOption option;
1494
1495 if (!WriteInterfaceToken(data)) {
1496 HILOG_ERROR("fail, connection write Token");
1497 return RET_ERR_IPC_FAILED;
1498 }
1499 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_IGNORE_REPEAT_CLICK_STATE,
1500 data, reply, option)) {
1501 HILOG_ERROR("GetAudioBalance fail");
1502 return RET_ERR_IPC_FAILED;
1503 }
1504 RetError ret = static_cast<RetError>(reply.ReadInt32());
1505 if (ret == RET_OK) {
1506 state = reply.ReadBool();
1507 }
1508 return ret;
1509 }
1510
GetIgnoreRepeatClickTime(uint32_t & time)1511 RetError AccessibleAbilityManagerServiceProxy::GetIgnoreRepeatClickTime(uint32_t& time)
1512 {
1513 HILOG_DEBUG();
1514 MessageParcel data;
1515 MessageParcel reply;
1516 MessageOption option;
1517
1518 if (!WriteInterfaceToken(data)) {
1519 HILOG_ERROR("fail, connection write Token");
1520 return RET_ERR_IPC_FAILED;
1521 }
1522 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_IGNORE_REPEAT_CLICK_TIME,
1523 data, reply, option)) {
1524 HILOG_ERROR("GetAudioBalance fail");
1525 return RET_ERR_IPC_FAILED;
1526 }
1527 RetError ret = static_cast<RetError>(reply.ReadInt32());
1528 if (ret == RET_OK) {
1529 time = reply.ReadUint32();
1530 }
1531 return ret;
1532 }
1533
GetAllConfigs(AccessibilityConfigData & configData)1534 void AccessibleAbilityManagerServiceProxy::GetAllConfigs(AccessibilityConfigData& configData)
1535 {
1536 HILOG_DEBUG();
1537 MessageParcel data;
1538 MessageParcel reply;
1539 MessageOption option;
1540
1541 if (!WriteInterfaceToken(data)) {
1542 HILOG_ERROR("fail, connection write Token");
1543 return;
1544 }
1545 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_ALL_CONFIGS,
1546 data, reply, option)) {
1547 HILOG_ERROR("GetAllConfigs fail");
1548 return;
1549 }
1550
1551 RetError ret = static_cast<RetError>(reply.ReadInt32());
1552 if (ret != RET_OK) {
1553 HILOG_ERROR("GetAllConfigs failed %{public}d", ret);
1554 return;
1555 }
1556
1557 std::vector<std::string> tmpMultiTarget;
1558 configData.highContrastText_ = reply.ReadBool();
1559 configData.invertColor_ = reply.ReadBool();
1560 configData.animationOff_ = reply.ReadBool();
1561 configData.audioMono_ = reply.ReadBool();
1562 configData.mouseKey_ = reply.ReadBool();
1563 configData.captionState_ = reply.ReadBool();
1564 configData.screenMagnifier_ = reply.ReadBool();
1565 configData.shortkey_ = reply.ReadBool();
1566 configData.mouseAutoClick_ = reply.ReadInt32();
1567 configData.daltonizationState_ = reply.ReadBool();
1568 configData.daltonizationColorFilter_ = reply.ReadUint32();
1569 configData.contentTimeout_ = reply.ReadUint32();
1570 configData.brightnessDiscount_ = reply.ReadFloat();
1571 configData.audioBalance_ = reply.ReadFloat();
1572 configData.shortkeyTarget_ = reply.ReadString();
1573 configData.captionProperty_ = *reply.ReadStrongParcelable<CaptionPropertyParcel>();
1574 reply.ReadStringVector(&tmpMultiTarget);
1575 configData.shortkeyMultiTarget_ = tmpMultiTarget;
1576 }
1577
RegisterEnableAbilityListsObserver(const sptr<IAccessibilityEnableAbilityListsObserver> & observer)1578 void AccessibleAbilityManagerServiceProxy::RegisterEnableAbilityListsObserver(
1579 const sptr<IAccessibilityEnableAbilityListsObserver> &observer)
1580 {
1581 HILOG_DEBUG();
1582 MessageParcel data;
1583 MessageParcel reply;
1584 MessageOption option(MessageOption::TF_ASYNC);
1585
1586 if (observer == nullptr) {
1587 HILOG_ERROR("observer is nullptr");
1588 return;
1589 }
1590
1591 if (!WriteInterfaceToken(data)) {
1592 HILOG_ERROR("write interface token error");
1593 return;
1594 }
1595
1596 if (!data.WriteRemoteObject(observer->AsObject())) {
1597 HILOG_ERROR("observer write remote object error");
1598 return;
1599 }
1600
1601 if (!SendTransactCmd(AccessibilityInterfaceCode::REGISTER_ENABLE_ABILITY_LISTS_OBSERVER,
1602 data, reply, option)) {
1603 HILOG_ERROR("RegisterEnableAbilityListsObserver fail");
1604 return;
1605 }
1606 }
1607
RegisterConfigObserver(const sptr<IAccessibleAbilityManagerConfigObserver> & client)1608 uint32_t AccessibleAbilityManagerServiceProxy::RegisterConfigObserver(
1609 const sptr<IAccessibleAbilityManagerConfigObserver> &client)
1610 {
1611 HILOG_DEBUG();
1612 MessageParcel data;
1613 MessageParcel reply;
1614 MessageOption option(MessageOption::TF_SYNC);
1615
1616 if (client == nullptr) {
1617 HILOG_ERROR("RegisterConfigObserver fail, Input client is null");
1618 return TRANSACTION_ERR;
1619 }
1620
1621 if (!WriteInterfaceToken(data)) {
1622 HILOG_ERROR("RegisterConfigObserver fail, connection write Token error");
1623 return TRANSACTION_ERR;
1624 }
1625
1626 if (!data.WriteRemoteObject(client->AsObject())) {
1627 HILOG_ERROR("RegisterConfigObserver fail, connection write client error");
1628 return TRANSACTION_ERR;
1629 }
1630
1631 if (!SendTransactCmd(AccessibilityInterfaceCode::REGISTER_CONFIG_CALLBACK,
1632 data, reply, option)) {
1633 HILOG_ERROR("RegisterStateCallback fail");
1634 return TRANSACTION_ERR;
1635 }
1636
1637 return reply.ReadUint32();
1638 }
1639
GetRealWindowAndElementId(int32_t & windowId,int64_t & elementId)1640 void AccessibleAbilityManagerServiceProxy::GetRealWindowAndElementId(int32_t& windowId, int64_t& elementId)
1641 {
1642 HILOG_DEBUG();
1643 MessageParcel data;
1644 MessageParcel reply;
1645 MessageOption option(MessageOption::TF_SYNC);
1646
1647 if (!WriteInterfaceToken(data)) {
1648 HILOG_ERROR("write Token fail");
1649 return;
1650 }
1651
1652 if (!data.WriteInt32(windowId)) {
1653 HILOG_ERROR("write windowId fail");
1654 return;
1655 }
1656
1657 if (!data.WriteInt64(elementId)) {
1658 HILOG_ERROR("write elementId fail");
1659 return;
1660 }
1661
1662 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_WINDOW_AND_ELEMENT_ID,
1663 data, reply, option)) {
1664 HILOG_ERROR("GetRealWindowAndElementId fail");
1665 return;
1666 }
1667
1668 windowId = reply.ReadInt32();
1669 elementId = reply.ReadInt64();
1670 }
1671
GetSceneBoardInnerWinId(int32_t windowId,int64_t elementId,int32_t & innerWid)1672 void AccessibleAbilityManagerServiceProxy::GetSceneBoardInnerWinId(int32_t windowId, int64_t elementId,
1673 int32_t& innerWid)
1674 {
1675 HILOG_DEBUG();
1676 MessageParcel data;
1677 MessageParcel reply;
1678 MessageOption option(MessageOption::TF_SYNC);
1679
1680 if (!WriteInterfaceToken(data)) {
1681 HILOG_ERROR("write Token fail");
1682 return;
1683 }
1684
1685 if (!data.WriteInt32(windowId)) {
1686 HILOG_ERROR("write windowId fail");
1687 return;
1688 }
1689
1690 if (!data.WriteInt64(elementId)) {
1691 HILOG_ERROR("write elementId fail");
1692 return;
1693 }
1694
1695 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_SCENE_BOARD_INNER_WINDOW_ID,
1696 data, reply, option)) {
1697 HILOG_ERROR("GetSceneBoardInnerWinId fail");
1698 return;
1699 }
1700
1701 innerWid = reply.ReadInt32();
1702 }
1703
GetFocusedWindowId(int32_t & focusedWindowId)1704 RetError AccessibleAbilityManagerServiceProxy::GetFocusedWindowId(int32_t &focusedWindowId)
1705 {
1706 HILOG_DEBUG();
1707 MessageParcel data;
1708 MessageParcel reply;
1709 MessageOption option;
1710 if (!WriteInterfaceToken(data)) {
1711 HILOG_ERROR("write token fail");
1712 return RET_ERR_IPC_FAILED;
1713 }
1714
1715 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_FOCUSED_WINDOW_ID, data, reply, option)) {
1716 HILOG_ERROR("GetFocusedWindowId fail");
1717 return RET_ERR_IPC_FAILED;
1718 }
1719
1720 focusedWindowId = reply.ReadInt32();
1721 return RET_OK;
1722 }
1723
RemoveRequestId(int32_t requestId)1724 void AccessibleAbilityManagerServiceProxy::RemoveRequestId(int32_t requestId)
1725 {
1726 HILOG_DEBUG();
1727 MessageParcel data;
1728 MessageParcel reply;
1729 MessageOption option;
1730 if (!WriteInterfaceToken(data)) {
1731 HILOG_ERROR("write token fail");
1732 return;
1733 }
1734
1735 if (!data.WriteInt32(requestId)) {
1736 HILOG_ERROR("write requestId fail");
1737 return;
1738 }
1739
1740 if (!SendTransactCmd(AccessibilityInterfaceCode::REMOVE_REQUEST_ID, data, reply, option)) {
1741 HILOG_ERROR("GetFocusedWindowId fail");
1742 return;
1743 }
1744 return;
1745 }
1746
GetRootParentId(int32_t windowsId,int32_t treeId)1747 int64_t AccessibleAbilityManagerServiceProxy::GetRootParentId(int32_t windowsId, int32_t treeId)
1748 {
1749 HILOG_DEBUG();
1750 MessageParcel data;
1751 MessageParcel reply;
1752 MessageOption option;
1753 if (!WriteInterfaceToken(data)) {
1754 HILOG_ERROR("write token fail");
1755 return false;
1756 }
1757
1758 if (!data.WriteInt32(windowsId)) {
1759 HILOG_ERROR("write windowsId fail");
1760 return RET_ERR_IPC_FAILED;
1761 }
1762
1763 if (!data.WriteInt32(treeId)) {
1764 HILOG_ERROR("write treeId fail");
1765 return RET_ERR_IPC_FAILED;
1766 }
1767
1768 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_ROOT_PARENT_ID, data, reply, option)) {
1769 HILOG_ERROR("GetRootParentId fail");
1770 return false;
1771 }
1772 return reply.ReadInt64();
1773 }
1774
GetAllTreeId(int32_t windowId,std::vector<int32_t> & treeIds)1775 RetError AccessibleAbilityManagerServiceProxy::GetAllTreeId(int32_t windowId, std::vector<int32_t> &treeIds)
1776 {
1777 HILOG_DEBUG();
1778 MessageParcel data;
1779 MessageParcel reply;
1780 MessageOption option;
1781
1782 if (!WriteInterfaceToken(data)) {
1783 HILOG_ERROR("fail, connection write Token error");
1784 return RET_ERR_IPC_FAILED;
1785 }
1786
1787 if (!data.WriteInt32(windowId)) {
1788 HILOG_ERROR("write windowId fail");
1789 return RET_ERR_IPC_FAILED;
1790 }
1791
1792 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_ALL_TREE_ID,
1793 data, reply, option)) {
1794 HILOG_ERROR("GetAllTreeId fail");
1795 return RET_ERR_IPC_FAILED;
1796 }
1797 RetError result = static_cast<RetError>(reply.ReadInt32());
1798 if (result == RET_OK) {
1799 int32_t treeIdSize = reply.ReadInt32();
1800 if (treeIdSize < 0 || treeIdSize > TREE_ID_MAX) {
1801 HILOG_ERROR("treeIdSize is invalid, treeIdSize: %{public}d", treeIdSize);
1802 return RET_ERR_INVALID_PARAM;
1803 }
1804 for (int32_t i = 0; i < treeIdSize; i++) {
1805 treeIds.emplace_back(reply.ReadInt32());
1806 }
1807 }
1808 return result;
1809 }
1810 } // namespace Accessibility
1811 } // namespace OHOS
1812