• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "accessible_ability_manager_service_proxy.h"
17 #include "accessibility_errorcode.h"
18 #include "hilog_wrapper.h"
19 #include "ipc_types.h"
20 #include "iremote_object.h"
21 #include "accessibility_caption.h"
22 
23 namespace OHOS {
24 namespace Accessibility {
AccessibleAbilityManagerServiceClientProxy(const sptr<IRemoteObject> & impl)25 AccessibleAbilityManagerServiceClientProxy::AccessibleAbilityManagerServiceClientProxy(const sptr<IRemoteObject>& impl)
26     : IRemoteProxy<IAccessibleAbilityManagerServiceClient>(impl)
27 {}
28 
~AccessibleAbilityManagerServiceClientProxy()29 AccessibleAbilityManagerServiceClientProxy::~AccessibleAbilityManagerServiceClientProxy()
30 {}
31 
WriteInterfaceToken(MessageParcel & data)32 bool AccessibleAbilityManagerServiceClientProxy::WriteInterfaceToken(MessageParcel& data)
33 {
34     HILOG_DEBUG("start");
35     if (!data.WriteInterfaceToken(IAccessibleAbilityManagerServiceClient::GetDescriptor())) {
36         HILOG_ERROR("write interface token failed");
37         return false;
38     }
39     return true;
40 }
41 
SendEvent(const AccessibilityEventInfo & uiEvent,const int userId)42 void AccessibleAbilityManagerServiceClientProxy::SendEvent(const AccessibilityEventInfo& uiEvent, const int userId)
43 {
44     HILOG_DEBUG("start");
45 
46     int error = NO_ERROR;
47     MessageParcel data;
48     MessageParcel reply;
49     MessageOption option;
50 
51     if (!WriteInterfaceToken(data)) {
52         HILOG_ERROR("fail, connection write Token");
53         return;
54     }
55 
56     if (!data.WriteParcelable(&uiEvent)) {
57         HILOG_ERROR("fail, connection write parcelable AccessibilityEventInfo error");
58         return;
59     }
60 
61     if (!data.WriteInt32(userId)) {
62         HILOG_ERROR("fail, connection write userId error");
63         return;
64     }
65 
66     error = Remote()->SendRequest(
67         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::SEND_EVENT), data, reply, option);
68     if (error != NO_ERROR) {
69         HILOG_ERROR("SendEvent fail, error: %{public}d", error);
70         return;
71     }
72 }
73 
SetCaptionProperty(const CaptionProperty & caption)74 bool AccessibleAbilityManagerServiceClientProxy::SetCaptionProperty(const CaptionProperty& caption)
75 {
76     HILOG_DEBUG("start");
77 
78     int error = NO_ERROR;
79     MessageParcel data;
80     MessageParcel reply;
81     MessageOption option;
82 
83     if (!WriteInterfaceToken(data)) {
84         HILOG_ERROR("fail, connection write Token");
85         return false;
86     }
87 
88     if (!data.WriteParcelable(&caption)) {
89         HILOG_ERROR("fail, connection write parcelable Caption Property ");
90         return false;
91     }
92 
93     error = Remote()->SendRequest(
94         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::SET_CAPTION_PROPERTY),
95         data,
96         reply,
97         option);
98     if (error != NO_ERROR) {
99         HILOG_ERROR("SetCaptionProperty fail, error: %{public}d", error);
100         return false;
101     }
102     return true;
103 }
104 
SetCaptionState(const bool state)105 bool AccessibleAbilityManagerServiceClientProxy::SetCaptionState(const bool state)
106 {
107     HILOG_DEBUG("start");
108 
109     int error = NO_ERROR;
110     MessageParcel data;
111     MessageParcel reply;
112     MessageOption option;
113 
114     if (!WriteInterfaceToken(data)) {
115         HILOG_ERROR("fail, connection write Token");
116         return false;
117     }
118 
119     if (!data.WriteBool(state)) {
120         HILOG_ERROR("fail, connection write parcelable Caption State ");
121         return false;
122     }
123 
124     error = Remote()->SendRequest(
125         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::SET_CAPTION_STATE), data, reply, option);
126     if (error != NO_ERROR) {
127         HILOG_ERROR("SetCaptionState fail, error: %{public}d", error);
128         return false;
129     }
130     return true;
131 }
132 
SetEnabled(const bool state)133 bool AccessibleAbilityManagerServiceClientProxy::SetEnabled(const bool state)
134 {
135     HILOG_DEBUG("start");
136 
137     int error = NO_ERROR;
138     MessageParcel data;
139     MessageParcel reply;
140     MessageOption option;
141 
142     if (!WriteInterfaceToken(data)) {
143         HILOG_ERROR("fail, connection write Token");
144         return false;
145     }
146 
147     if (!data.WriteBool(state)) {
148         HILOG_ERROR("fail, connection write parcelable Enabled ");
149         return false;
150     }
151 
152     error = Remote()->SendRequest(
153         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::SET_ENABLED), data, reply, option);
154     if (error != NO_ERROR) {
155         HILOG_ERROR("SetEnabled fail, error: %{public}d", error);
156         return false;
157     }
158     return true;
159 }
160 
RegisterStateCallback(const sptr<IAccessibleAbilityManagerServiceState> & client,const int userId)161 uint32_t AccessibleAbilityManagerServiceClientProxy::RegisterStateCallback(
162     const sptr<IAccessibleAbilityManagerServiceState>& client, const int userId)
163 {
164     HILOG_DEBUG("start");
165 
166     int error = NO_ERROR;
167     MessageParcel data;
168     MessageParcel reply;
169     MessageOption option(MessageOption::TF_SYNC);
170 
171     if (!client) {
172         HILOG_ERROR("fail, Input client is null");
173         return ErrCode::ERROR;
174     }
175 
176     if (!WriteInterfaceToken(data)) {
177         HILOG_ERROR("fail, connection write Token error");
178         return ErrCode::ERROR;
179     }
180 
181     if (!data.WriteRemoteObject(client->AsObject())) {
182         HILOG_ERROR("fail, connection write client error");
183         return ErrCode::ERROR;
184     }
185 
186     if (!data.WriteInt32(userId)) {
187         HILOG_ERROR("fail, connection write userId error");
188         return ErrCode::ERROR;
189     }
190 
191     error = Remote()->SendRequest(
192         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::REGISTER_STATE_CALLBACK),
193         data,
194         reply,
195         option);
196     if (error != NO_ERROR) {
197         HILOG_ERROR("SendEvent fail, error: %{public}d", error);
198         return ErrCode::ERROR;
199     }
200 
201     return reply.ReadUint32();
202 }
203 
GetAbilityList(const uint32_t abilityTypes,const int32_t stateType)204 std::vector<AccessibilityAbilityInfo> AccessibleAbilityManagerServiceClientProxy::GetAbilityList(
205     const uint32_t abilityTypes, const int32_t stateType)
206 {
207     HILOG_DEBUG("start");
208 
209     int error = NO_ERROR;
210     MessageParcel data;
211     MessageParcel reply;
212     MessageOption option;
213     std::vector<AccessibilityAbilityInfo> errorList {};
214     std::vector<AccessibilityAbilityInfo> abilityInfos {};
215     if (!WriteInterfaceToken(data)) {
216         HILOG_ERROR("fail, connection write Token error");
217         return errorList;
218     }
219 
220     if (!data.WriteUint32(abilityTypes)) {
221         HILOG_ERROR("fail, connection write abilityTypes error");
222         return errorList;
223     }
224 
225     if (!data.WriteInt32(stateType)) {
226         HILOG_ERROR("fail, connection write stateType error");
227         return errorList;
228     }
229 
230     error = Remote()->SendRequest(
231         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::GET_ABILITYLIST), data, reply, option);
232     if (error != NO_ERROR) {
233         HILOG_ERROR("SendEvent fail, error: %d", error);
234         return errorList;
235     }
236     // read result
237     int32_t abilityInfoSize = reply.ReadInt32();
238     for (int i = 0; i < abilityInfoSize; i++) {
239         std::shared_ptr<AccessibilityAbilityInfo> accessibilityAbilityInfo(
240             reply.ReadParcelable<AccessibilityAbilityInfo>());
241         if (!accessibilityAbilityInfo) {
242             HILOG_ERROR("ReadParcelable<accessibilityAbilityInfo> failed");
243             return errorList;
244         }
245         abilityInfos.emplace_back(*accessibilityAbilityInfo);
246     }
247     return abilityInfos;
248 }
249 
RegisterElementOperator(int windowId,const sptr<IAccessibilityElementOperator> & operation,const int userId)250 void AccessibleAbilityManagerServiceClientProxy::RegisterElementOperator(
251     int windowId, const sptr<IAccessibilityElementOperator>& operation, const int userId)
252 {
253     HILOG_DEBUG("start");
254 
255     int error = NO_ERROR;
256     MessageParcel data;
257     MessageParcel reply;
258     MessageOption option;
259 
260     if (!operation) {
261         HILOG_ERROR("fail, Input operation is null");
262         return;
263     }
264 
265     if (!WriteInterfaceToken(data)) {
266         HILOG_ERROR("fail, connection write Token");
267         return;
268     }
269 
270     if (!data.WriteInt32(windowId)) {
271         HILOG_ERROR("fail, connection write windowId error");
272         return;
273     }
274 
275     if (!data.WriteRemoteObject(operation->AsObject())) {
276         HILOG_ERROR("fail, connection write parcelable operation error");
277         return;
278     }
279 
280     if (!data.WriteInt32(userId)) {
281         HILOG_ERROR("fail, connection write userId error");
282         return;
283     }
284 
285     error = Remote()->SendRequest(
286         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::REGISTER_INTERACTION_CONNECTION),
287         data,
288         reply,
289         option);
290     if (error != NO_ERROR) {
291         HILOG_ERROR("Register fail, error: %{public}d", error);
292         return;
293     }
294 }
295 
DeregisterElementOperator(const int windowId)296 void AccessibleAbilityManagerServiceClientProxy::DeregisterElementOperator(const int windowId)
297 {
298     HILOG_DEBUG("windowId(%{public}d)", windowId);
299 
300     int error = NO_ERROR;
301     MessageParcel data;
302     MessageParcel reply;
303     MessageOption option;
304 
305     if (!WriteInterfaceToken(data)) {
306         HILOG_ERROR("fail, connection write Token");
307         return;
308     }
309 
310     if (!data.WriteInt32(windowId)) {
311         HILOG_ERROR("fail, connection write userId error");
312         return;
313     }
314 
315     error = Remote()->SendRequest(
316         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::DEREGISTER_INTERACTION_CONNECTION),
317         data,
318         reply,
319         option);
320     if (error != NO_ERROR) {
321         HILOG_ERROR("Deregister fail, error: %{public}d", error);
322         return;
323     }
324 }
325 
GetCaptionProperty()326 CaptionProperty AccessibleAbilityManagerServiceClientProxy::GetCaptionProperty()
327 {
328     HILOG_DEBUG("start");
329 
330     int error = NO_ERROR;
331     MessageParcel data;
332     MessageParcel reply;
333     MessageOption option;
334     CaptionProperty property = {};
335     if (!WriteInterfaceToken(data)) {
336         HILOG_ERROR("fail, connection write Token error");
337         return property;
338     }
339     error = Remote()->SendRequest(
340         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::GET_CAPTION_PROPERTY),
341         data,
342         reply,
343         option);
344     if (error != NO_ERROR) {
345         HILOG_ERROR("Interrupt fail, error: %{public}d", error);
346         return property;
347     }
348     return *reply.ReadParcelable<CaptionProperty>();
349 }
350 
RegisterCaptionPropertyCallback(const sptr<IAccessibleAbilityManagerServiceCaptionProperty> & client,const int userId)351 uint32_t AccessibleAbilityManagerServiceClientProxy::RegisterCaptionPropertyCallback(
352     const sptr<IAccessibleAbilityManagerServiceCaptionProperty>& client, const int userId)
353 {
354     HILOG_DEBUG("start");
355 
356     int error = NO_ERROR;
357     MessageParcel data;
358     MessageParcel reply;
359     MessageOption option(MessageOption::TF_ASYNC);
360 
361     if (!client) {
362         HILOG_ERROR("fail, Input client is null");
363         return ErrCode::ERROR;
364     }
365 
366     if (!WriteInterfaceToken(data)) {
367         HILOG_ERROR("fail, connection write Token error");
368         return ErrCode::ERROR;
369     }
370 
371     if (!data.WriteRemoteObject(client->AsObject())) {
372         HILOG_ERROR("fail, connection write client error");
373         return ErrCode::ERROR;
374     }
375 
376     if (!data.WriteInt32(userId)) {
377         HILOG_ERROR("fail, connection write userId error");
378         return ErrCode::ERROR;
379     }
380 
381     error = Remote()->SendRequest(
382         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::REGISTER_CAPTION_PROPERTY_CALLBACK),
383         data,
384         reply,
385         option);
386     if (error != NO_ERROR) {
387         HILOG_ERROR("SendEvent fail, error: %{public}d", error);
388         return ErrCode::ERROR;
389     }
390 
391     return reply.ReadUint32();
392 }
393 
GetObject()394 sptr<IRemoteObject> AccessibleAbilityManagerServiceClientProxy::GetObject()
395 {
396     return this->AsObject();
397 }
398 
GetEnabledState()399 bool AccessibleAbilityManagerServiceClientProxy::GetEnabledState()
400 {
401     HILOG_DEBUG("start");
402 
403     int error = NO_ERROR;
404     MessageParcel data;
405     MessageParcel reply;
406     MessageOption option;
407 
408     if (!WriteInterfaceToken(data)) {
409         HILOG_ERROR("fail, connection write Token");
410         return false;
411     }
412     error = Remote()->SendRequest(
413         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::GET_ENABLED), data, reply, option);
414     if (error != NO_ERROR) {
415         HILOG_ERROR("GetEnabled fail, error: %{public}d", error);
416         return false;
417     }
418     return reply.ReadBool();
419 }
420 
GetCaptionState()421 bool AccessibleAbilityManagerServiceClientProxy::GetCaptionState()
422 {
423     HILOG_DEBUG("start");
424 
425     int error = NO_ERROR;
426     MessageParcel data;
427     MessageParcel reply;
428     MessageOption option;
429 
430     if (!WriteInterfaceToken(data)) {
431         HILOG_ERROR("fail, connection write Token");
432         return false;
433     }
434     error = Remote()->SendRequest(
435         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::GET_CAPTION_STATE), data, reply, option);
436     if (error != NO_ERROR) {
437         HILOG_ERROR("GetCaptionState fail, error: %{public}d", error);
438         return false;
439     }
440     return reply.ReadBool();
441 }
442 
GetTouchGuideState()443 bool AccessibleAbilityManagerServiceClientProxy::GetTouchGuideState()
444 {
445     HILOG_DEBUG("start");
446 
447     int error = NO_ERROR;
448     MessageParcel data;
449     MessageParcel reply;
450     MessageOption option;
451 
452     if (!WriteInterfaceToken(data)) {
453         HILOG_ERROR("fail, connection write Token");
454         return false;
455     }
456     error = Remote()->SendRequest(
457         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::GET_TOUCH_GUIDE_STATE),
458         data,
459         reply,
460         option);
461     if (error != NO_ERROR) {
462         HILOG_ERROR("GetTouchGuideState fail, error: %{public}d", error);
463         return false;
464     }
465     return reply.ReadBool();
466 }
467 
GetGestureState()468 bool AccessibleAbilityManagerServiceClientProxy::GetGestureState()
469 {
470     HILOG_DEBUG("start");
471 
472     int error = NO_ERROR;
473     MessageParcel data;
474     MessageParcel reply;
475     MessageOption option;
476 
477     if (!WriteInterfaceToken(data)) {
478         HILOG_ERROR("fail, connection write Token");
479         return false;
480     }
481     error = Remote()->SendRequest(
482         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::GET_GESTURE_STATE), data, reply, option);
483     if (error != NO_ERROR) {
484         HILOG_ERROR("GetGestureState fail, error: %{public}d", error);
485         return false;
486     }
487     return reply.ReadBool();
488 }
489 
GetKeyEventObserverState()490 bool AccessibleAbilityManagerServiceClientProxy::GetKeyEventObserverState()
491 {
492     HILOG_DEBUG("start");
493 
494     int error = NO_ERROR;
495     MessageParcel data;
496     MessageParcel reply;
497     MessageOption option;
498 
499     if (!WriteInterfaceToken(data)) {
500         HILOG_ERROR("fail, connection write Token");
501         return false;
502     }
503     error = Remote()->SendRequest(
504         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::GET_KEY_EVENT_OBSERVE_STATE),
505         data,
506         reply,
507         option);
508     if (error != NO_ERROR) {
509         HILOG_ERROR("GetKeyEventObserverState fail, error: %{public}d", error);
510         return false;
511     }
512     return reply.ReadBool();
513 }
514 
SetTouchGuideState(const bool state)515 bool AccessibleAbilityManagerServiceClientProxy::SetTouchGuideState(const bool state)
516 {
517     HILOG_DEBUG("start");
518 
519     int error = NO_ERROR;
520     MessageParcel data;
521     MessageParcel reply;
522     MessageOption option;
523 
524     if (!WriteInterfaceToken(data)) {
525         HILOG_ERROR("fail, connection write Token");
526         return false;
527     }
528 
529     if (!data.WriteBool(state)) {
530         HILOG_ERROR("fail, connection write parcelable Caption Property ");
531         return false;
532     }
533 
534     error = Remote()->SendRequest(
535         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::SET_TOUCH_GUIDE_STATE),
536         data,
537         reply,
538         option);
539     if (error != NO_ERROR) {
540         HILOG_ERROR("SetTouchGuideState fail, error: %{public}d", error);
541         return false;
542     }
543     return true;
544 }
545 
SetGestureState(const bool state)546 bool AccessibleAbilityManagerServiceClientProxy::SetGestureState(const bool state)
547 {
548     HILOG_DEBUG("start");
549 
550     int error = NO_ERROR;
551     MessageParcel data;
552     MessageParcel reply;
553     MessageOption option;
554 
555     if (!WriteInterfaceToken(data)) {
556         HILOG_ERROR("fail, connection write Token");
557         return false;
558     }
559 
560     if (!data.WriteBool(state)) {
561         HILOG_ERROR("fail, connection write parcelable Caption Property ");
562         return false;
563     }
564 
565     error = Remote()->SendRequest(
566         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::SET_GESTURE_STATE), data, reply, option);
567     if (error != NO_ERROR) {
568         HILOG_ERROR("SetGestureState fail, error: %{public}d", error);
569         return false;
570     }
571     return true;
572 }
573 
SetKeyEventObserverState(const bool state)574 bool AccessibleAbilityManagerServiceClientProxy::SetKeyEventObserverState(const bool state)
575 {
576     HILOG_DEBUG("start");
577 
578     int error = NO_ERROR;
579     MessageParcel data;
580     MessageParcel reply;
581     MessageOption option;
582 
583     if (!WriteInterfaceToken(data)) {
584         HILOG_ERROR("fail, connection write Token");
585         return false;
586     }
587 
588     if (!data.WriteBool(state)) {
589         HILOG_ERROR("fail, connection write parcelable Caption Property ");
590         return false;
591     }
592 
593     error = Remote()->SendRequest(
594         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::SET_KEY_EVENT_OBSERVE_STATE),
595         data,
596         reply,
597         option);
598     if (error != NO_ERROR) {
599         HILOG_ERROR("SetKeyEventObserverState fail, error: %{public}d", error);
600         return false;
601     }
602     return true;
603 }
604 
SetEnabledObj(std::map<std::string,AppExecFwk::ElementName> it)605 bool AccessibleAbilityManagerServiceClientProxy::SetEnabledObj(std::map<std::string, AppExecFwk::ElementName> it)
606 {
607     HILOG_DEBUG("start");
608 
609     int error = NO_ERROR;
610     MessageParcel data;
611     MessageParcel reply;
612     MessageOption option;
613 
614     if (!WriteInterfaceToken(data)) {
615         HILOG_ERROR("fail, connection write Token");
616         return false;
617     }
618 
619     data.WriteInt32(it.size());
620     std::map<std::string, AppExecFwk::ElementName>::iterator iter;
621 
622     for (iter = it.begin(); iter != it.end(); ++iter) {
623         bool ret = data.WriteParcelable(&iter->second);
624         if (!ret) {
625             return false;
626         }
627     }
628 
629     error = Remote()->SendRequest(
630         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::SET_ENABLED_OBJECT),
631         data,
632         reply,
633         option);
634     if (error != NO_ERROR) {
635         HILOG_ERROR("SetEnabledObj fail, error: %{public}d", error);
636         return false;
637     }
638     return true;
639 }
640 
GetEnabledAbilities()641 std::map<std::string, AppExecFwk::ElementName> AccessibleAbilityManagerServiceClientProxy::GetEnabledAbilities()
642 {
643     HILOG_DEBUG("start");
644 
645     int error = NO_ERROR;
646     MessageParcel data;
647     MessageParcel reply;
648     MessageOption option;
649     std::map<std::string, AppExecFwk::ElementName> it {};
650 
651     if (!WriteInterfaceToken(data)) {
652         HILOG_ERROR("fail, connection write Token error");
653         return it;
654     }
655     error = Remote()->SendRequest(
656         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::GET_ENABLED_OBJECT),
657         data,
658         reply,
659         option);
660     if (error != NO_ERROR) {
661         HILOG_ERROR("Interrupt fail, error: %{public}d", error);
662         return it;
663     }
664 
665     int dev_num = reply.ReadInt32();
666     std::vector<AppExecFwk::ElementName> temp {};
667     for (int i = dev_num; i > 0; i--) {
668         std::unique_ptr<AppExecFwk::ElementName> iter(reply.ReadParcelable<AppExecFwk::ElementName>());
669         if (!iter) {
670             HILOG_ERROR("ReadParcelable<AppExecFwk::ElementName> failed");
671             return it;
672         }
673         temp.push_back(*iter);
674     }
675 
676     for (int i = 0; i < dev_num; i++) {
677         it.insert(make_pair(temp[i].GetURI(), temp[i]));
678     }
679     return it;
680 }
681 
GetInstalledAbilities()682 std::vector<AccessibilityAbilityInfo> AccessibleAbilityManagerServiceClientProxy::GetInstalledAbilities()
683 {
684     HILOG_DEBUG("start");
685 
686     int error = NO_ERROR;
687     MessageParcel data;
688     MessageParcel reply;
689     MessageOption option;
690     std::vector<AccessibilityAbilityInfo> it {};
691 
692     if (!WriteInterfaceToken(data)) {
693         HILOG_ERROR("fail, connection write Token error");
694         return it;
695     }
696     error = Remote()->SendRequest(
697         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::GET_INSTALLED), data, reply, option);
698     if (error != NO_ERROR) {
699         HILOG_ERROR("Interrupt fail, error: %{public}d", error);
700         return it;
701     }
702     int dev_num = reply.ReadInt32();
703     for (int i = dev_num; i > 0; i--) {
704         std::unique_ptr<AccessibilityAbilityInfo> dev(reply.ReadParcelable<AccessibilityAbilityInfo>());
705         if (!dev) {
706             HILOG_ERROR("ReadParcelable<accessibilityAbilityInfo> failed");
707             return it;
708         }
709         it.push_back(*dev);
710     }
711     return it;
712 }
713 
DisableAbilities(std::map<std::string,AppExecFwk::ElementName> it)714 bool AccessibleAbilityManagerServiceClientProxy::DisableAbilities(std::map<std::string, AppExecFwk::ElementName> it)
715 {
716     HILOG_DEBUG("start");
717 
718     int error = NO_ERROR;
719     MessageParcel data;
720     MessageParcel reply;
721     MessageOption option;
722 
723     if (!WriteInterfaceToken(data)) {
724         HILOG_ERROR("fail, connection write Token");
725         return false;
726     }
727     data.WriteInt32(it.size());
728     std::map<std::string, AppExecFwk::ElementName>::iterator iter;
729 
730     for (iter = it.begin(); iter != it.end(); ++iter) {
731         bool ret = data.WriteParcelable(&iter->second);
732         if (!ret) {
733             return false;
734         }
735     }
736     error = Remote()->SendRequest(
737         static_cast<uint32_t>(IAccessibleAbilityManagerServiceClient::Message::DISABLE_ABILITIES),
738         data, reply, option);
739     if (error != NO_ERROR) {
740         HILOG_ERROR("SetEnabledObj fail, error: %{public}d", error);
741         return false;
742     }
743     return true;
744 }
745 
GetActiveWindow()746 int AccessibleAbilityManagerServiceClientProxy::GetActiveWindow()
747 {
748     HILOG_DEBUG("start");
749 
750     int error = NO_ERROR;
751     MessageParcel data;
752     MessageParcel reply;
753     MessageOption option;
754 
755     if (!WriteInterfaceToken(data)) {
756         HILOG_ERROR("fail, connection write Token");
757         return false;
758     }
759 
760     error = Remote()->SendRequest(
761         static_cast<uint32_t>(
762             IAccessibleAbilityManagerServiceClient::Message::GET_ACTIVE_WINDOW),
763         data, reply, option);
764     if (error != NO_ERROR) {
765         HILOG_ERROR("GetActiveWindow fail, error: %{public}d", error);
766         return false;
767     }
768     return reply.ReadInt32();
769 }
770 
RegisterUITestAbilityConnectionClient(const sptr<IRemoteObject> & obj)771 bool AccessibleAbilityManagerServiceClientProxy::RegisterUITestAbilityConnectionClient(const sptr<IRemoteObject>& obj)
772 {
773     HILOG_DEBUG("start");
774 
775     int error = NO_ERROR;
776     MessageParcel data;
777     MessageParcel reply;
778     MessageOption option;
779 
780     if (!WriteInterfaceToken(data)) {
781         HILOG_ERROR("fail, connection write Token");
782         return false;
783     }
784 
785     if (!data.WriteRemoteObject(obj)) {
786         HILOG_ERROR("fail, connection write obj");
787         return false;
788     }
789 
790     error = Remote()->SendRequest(static_cast<uint32_t>
791         (IAccessibleAbilityManagerServiceClient::Message::REGISTER_UITEST_ABILITY_CONNECTION_CLIENT),
792         data, reply, option);
793     if (error != NO_ERROR) {
794         HILOG_ERROR("Interrupt fail, error: %{public}d", error);
795         return false;
796     }
797     return reply.ReadBool();
798 }
799 
DeregisterUITestAbilityConnectionClient()800 bool AccessibleAbilityManagerServiceClientProxy::DeregisterUITestAbilityConnectionClient()
801 {
802     HILOG_DEBUG("start");
803 
804     int error = NO_ERROR;
805     MessageParcel data;
806     MessageParcel reply;
807     MessageOption option;
808 
809     if (!WriteInterfaceToken(data)) {
810         HILOG_ERROR("fail, connection write Token");
811         return false;
812     }
813 
814     error = Remote()->SendRequest(static_cast<uint32_t>
815         (IAccessibleAbilityManagerServiceClient::Message::DEREGISTER_UITEST_ABILITY_CONNECTION_CLIENT),
816         data, reply, option);
817     if (error != NO_ERROR) {
818         HILOG_ERROR("Interrupt fail, error: %{public}d", error);
819         return false;
820     }
821     return reply.ReadBool();
822 }
823 } // namespace Accessibility
824 } // namespace OHOS
825