• 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_channel_proxy.h"
17 
18 #include <cinttypes>
19 
20 #include "accessibility_element_info_parcel.h"
21 #include "accessibility_gesture_inject_path_parcel.h"
22 #include "accessibility_ipc_interface_code.h"
23 #include "accessibility_window_info_parcel.h"
24 #include "hilog_wrapper.h"
25 
26 namespace OHOS {
27 namespace Accessibility {
AccessibleAbilityChannelProxy(const sptr<IRemoteObject> & object)28 AccessibleAbilityChannelProxy::AccessibleAbilityChannelProxy(
29     const sptr<IRemoteObject> &object): IRemoteProxy<IAccessibleAbilityChannel>(object)
30 {
31 }
32 
WriteInterfaceToken(MessageParcel & data)33 bool AccessibleAbilityChannelProxy::WriteInterfaceToken(MessageParcel &data)
34 {
35     HILOG_DEBUG();
36 
37     if (!data.WriteInterfaceToken(AccessibleAbilityChannelProxy::GetDescriptor())) {
38         HILOG_ERROR("write interface token failed");
39         return false;
40     }
41     return true;
42 }
43 
SendTransactCmd(AccessibilityInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)44 bool AccessibleAbilityChannelProxy::SendTransactCmd(AccessibilityInterfaceCode code,
45     MessageParcel &data, MessageParcel &reply, MessageOption &option)
46 {
47     HILOG_DEBUG();
48 
49     sptr<IRemoteObject> remoteChannelProxy = Remote();
50     if (remoteChannelProxy == nullptr) {
51         HILOG_ERROR("fail to send transact cmd %{public}d due to remote object", code);
52         return false;
53     }
54     int32_t resultChannelProxy = remoteChannelProxy->SendRequest(static_cast<uint32_t>(code), data, reply, option);
55     if (resultChannelProxy != NO_ERROR) {
56         HILOG_ERROR("receive error transact code %{public}d in transact cmd %{public}d", resultChannelProxy, code);
57         return false;
58     }
59     return true;
60 }
61 
SearchElementInfoByAccessibilityId(const ElementBasicInfo elementBasicInfo,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback,const int32_t mode,bool isFilter)62 RetError AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const ElementBasicInfo elementBasicInfo,
63     const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback,
64     const int32_t mode, bool isFilter)
65 {
66     HILOG_DEBUG();
67     if (callback == nullptr) {
68         HILOG_ERROR("callback is nullptr.");
69         return RET_ERR_INVALID_PARAM;
70     }
71 
72     MessageParcel data;
73     MessageParcel reply;
74     MessageOption option;
75 
76     if (!WriteInterfaceToken(data)) {
77         return RET_ERR_IPC_FAILED;
78     }
79     if (!data.WriteInt32(elementBasicInfo.windowId)) {
80         HILOG_ERROR("windowId write error: %{public}d, ", elementBasicInfo.windowId);
81         return RET_ERR_IPC_FAILED;
82     }
83     if (!data.WriteInt32(elementBasicInfo.treeId)) {
84         HILOG_ERROR("treeId write error: %{public}d", elementBasicInfo.treeId);
85         return RET_ERR_IPC_FAILED;
86     }
87     if (!data.WriteInt64(elementBasicInfo.elementId)) {
88         HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementBasicInfo.elementId);
89         return RET_ERR_IPC_FAILED;
90     }
91     if (!data.WriteInt32(requestId)) {
92         HILOG_ERROR("requestId write error: %{public}d, ", requestId);
93         return RET_ERR_IPC_FAILED;
94     }
95     if (!data.WriteRemoteObject(callback->AsObject())) {
96         HILOG_ERROR("callback write error");
97         return RET_ERR_IPC_FAILED;
98     }
99     if (!data.WriteInt32(mode)) {
100         HILOG_ERROR("mode write error: %{public}d, ", mode);
101         return RET_ERR_IPC_FAILED;
102     }
103     if (!data.WriteBool(isFilter)) {
104         HILOG_ERROR("isFilter write error: %{public}d, ", isFilter);
105         return RET_ERR_IPC_FAILED;
106     }
107     if (!SendTransactCmd(AccessibilityInterfaceCode::SEARCH_ELEMENTINFO_BY_ACCESSIBILITY_ID,
108         data, reply, option)) {
109         HILOG_ERROR("fail to find elementInfo by elementId");
110         return RET_ERR_IPC_FAILED;
111     }
112     return static_cast<RetError>(reply.ReadInt32());
113 }
114 
SearchDefaultFocusedByWindowId(const ElementBasicInfo elementBasicInfo,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback,const int32_t mode,bool isFilter)115 RetError AccessibleAbilityChannelProxy::SearchDefaultFocusedByWindowId(const ElementBasicInfo elementBasicInfo,
116     const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback,
117     const int32_t mode, bool isFilter)
118 {
119     HILOG_DEBUG();
120     if (callback == nullptr) {
121         HILOG_ERROR("callback is nullptr.");
122         return RET_ERR_INVALID_PARAM;
123     }
124 
125     MessageParcel data;
126     MessageParcel reply;
127     MessageOption option;
128 
129     if (!WriteInterfaceToken(data)) {
130         return RET_ERR_IPC_FAILED;
131     }
132     if (!data.WriteInt32(elementBasicInfo.windowId)) {
133         HILOG_ERROR("windowId write error: %{public}d, ", elementBasicInfo.windowId);
134         return RET_ERR_IPC_FAILED;
135     }
136     if (!data.WriteInt64(elementBasicInfo.elementId)) {
137         HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementBasicInfo.elementId);
138         return RET_ERR_IPC_FAILED;
139     }
140     if (!data.WriteInt32(elementBasicInfo.treeId)) {
141         HILOG_ERROR("treeId write error: %{public}d, ", elementBasicInfo.treeId);
142         return RET_ERR_IPC_FAILED;
143     }
144     if (!data.WriteInt32(requestId)) {
145         HILOG_ERROR("requestId write error: %{public}d, ", requestId);
146         return RET_ERR_IPC_FAILED;
147     }
148     if (!data.WriteRemoteObject(callback->AsObject())) {
149         HILOG_ERROR("callback write error");
150         return RET_ERR_IPC_FAILED;
151     }
152     if (!data.WriteInt32(mode)) {
153         HILOG_ERROR("mode write error: %{public}d, ", mode);
154         return RET_ERR_IPC_FAILED;
155     }
156     if (!data.WriteBool(isFilter)) {
157         HILOG_ERROR("isFilter write error: %{public}d, ", isFilter);
158         return RET_ERR_IPC_FAILED;
159     }
160     if (!SendTransactCmd(AccessibilityInterfaceCode::SEARCH_DEFAULTFOCUSED_BY_WINDOW_ID,
161         data, reply, option)) {
162         HILOG_ERROR("fail to find elementInfo by elementId");
163         return RET_ERR_IPC_FAILED;
164     }
165     return static_cast<RetError>(reply.ReadInt32());
166 }
167 
SearchElementInfosByText(const int32_t accessibilityWindowId,const int64_t elementId,const std::string & text,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)168 RetError AccessibleAbilityChannelProxy::SearchElementInfosByText(const int32_t accessibilityWindowId,
169     const int64_t elementId, const std::string &text, const int32_t requestId,
170     const sptr<IAccessibilityElementOperatorCallback> &callback)
171 {
172     HILOG_DEBUG();
173 
174     if (callback == nullptr) {
175         HILOG_ERROR("callback is nullptr.");
176         return RET_ERR_INVALID_PARAM;
177     }
178 
179     MessageParcel data;
180     MessageParcel reply;
181     MessageOption option;
182 
183     if (!WriteInterfaceToken(data)) {
184         return RET_ERR_IPC_FAILED;
185     }
186     if (!data.WriteInt32(accessibilityWindowId)) {
187         HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId);
188         return RET_ERR_IPC_FAILED;
189     }
190     if (!data.WriteInt64(elementId)) {
191         HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId);
192         return RET_ERR_IPC_FAILED;
193     }
194     if (!data.WriteString(text)) {
195         HILOG_ERROR("text write error: %{public}s, ", text.c_str());
196         return RET_ERR_IPC_FAILED;
197     }
198     if (!data.WriteInt32(requestId)) {
199         HILOG_ERROR("requestId write error: %{public}d, ", requestId);
200         return RET_ERR_IPC_FAILED;
201     }
202     if (!data.WriteRemoteObject(callback->AsObject())) {
203         HILOG_ERROR("callback write error");
204         return RET_ERR_IPC_FAILED;
205     }
206 
207     if (!SendTransactCmd(AccessibilityInterfaceCode::SEARCH_ELEMENTINFOS_BY_TEXT,
208         data, reply, option)) {
209         HILOG_ERROR("fail to find elementInfo by text");
210         return RET_ERR_IPC_FAILED;
211     }
212     return static_cast<RetError>(reply.ReadInt32());
213 }
214 
FindFocusedElementInfo(const int32_t accessibilityWindowId,const int64_t elementId,const int32_t focusType,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)215 RetError AccessibleAbilityChannelProxy::FindFocusedElementInfo(const int32_t accessibilityWindowId,
216     const int64_t elementId, const int32_t focusType, const int32_t requestId,
217     const sptr<IAccessibilityElementOperatorCallback> &callback)
218 {
219     HILOG_DEBUG();
220     if (callback == nullptr) {
221         HILOG_ERROR("callback is nullptr.");
222         return RET_ERR_INVALID_PARAM;
223     }
224 
225     MessageParcel data;
226     MessageParcel reply;
227     MessageOption option;
228 
229     if (!WriteInterfaceToken(data)) {
230         return RET_ERR_IPC_FAILED;
231     }
232     if (!data.WriteInt32(accessibilityWindowId)) {
233         HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId);
234         return RET_ERR_IPC_FAILED;
235     }
236     if (!data.WriteInt64(elementId)) {
237         HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId);
238         return RET_ERR_IPC_FAILED;
239     }
240     if (!data.WriteInt32(focusType)) {
241         HILOG_ERROR("focusType write error: %{public}d, ", focusType);
242         return RET_ERR_IPC_FAILED;
243     }
244     if (!data.WriteInt32(requestId)) {
245         HILOG_ERROR("requestId write error: %{public}d, ", requestId);
246         return RET_ERR_IPC_FAILED;
247     }
248     if (!data.WriteRemoteObject(callback->AsObject())) {
249         HILOG_ERROR("callback write error");
250         return RET_ERR_IPC_FAILED;
251     }
252 
253     if (!SendTransactCmd(AccessibilityInterfaceCode::FIND_FOCUSED_ELEMENTINFO, data, reply, option)) {
254         HILOG_ERROR("fail to gain focus");
255         return RET_ERR_IPC_FAILED;
256     }
257     return static_cast<RetError>(reply.ReadInt32());
258 }
259 
FocusMoveSearch(const int32_t accessibilityWindowId,const int64_t elementId,const int32_t direction,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)260 RetError AccessibleAbilityChannelProxy::FocusMoveSearch(const int32_t accessibilityWindowId, const int64_t elementId,
261     const int32_t direction, const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback)
262 {
263     HILOG_DEBUG();
264     if (callback == nullptr) {
265         HILOG_ERROR("callback is nullptr.");
266         return RET_ERR_INVALID_PARAM;
267     }
268 
269     MessageParcel data;
270     MessageParcel reply;
271     MessageOption option;
272 
273     if (!WriteInterfaceToken(data)) {
274         return RET_ERR_IPC_FAILED;
275     }
276     if (!data.WriteInt32(accessibilityWindowId)) {
277         HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId);
278         return RET_ERR_IPC_FAILED;
279     }
280     if (!data.WriteInt64(elementId)) {
281         HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId);
282         return RET_ERR_IPC_FAILED;
283     }
284     if (!data.WriteInt32(direction)) {
285         HILOG_ERROR("direction write error: %{public}d, ", direction);
286         return RET_ERR_IPC_FAILED;
287     }
288     if (!data.WriteInt32(requestId)) {
289         HILOG_ERROR("requestId write error: %{public}d, ", requestId);
290         return RET_ERR_IPC_FAILED;
291     }
292     if (!data.WriteRemoteObject(callback->AsObject())) {
293         HILOG_ERROR("callback write error");
294         return RET_ERR_IPC_FAILED;
295     }
296 
297     if (!SendTransactCmd(AccessibilityInterfaceCode::FOCUS_MOVE_SEARCH, data, reply, option)) {
298         HILOG_ERROR("fail to search focus");
299         return RET_ERR_IPC_FAILED;
300     }
301     return static_cast<RetError>(reply.ReadInt32());
302 }
303 
EnableScreenCurtain(bool isEnable)304 RetError AccessibleAbilityChannelProxy::EnableScreenCurtain(bool isEnable)
305 {
306     HILOG_DEBUG();
307 
308     MessageParcel data;
309     MessageParcel reply;
310     MessageOption option;
311 
312     if (!WriteInterfaceToken(data)) {
313         return RET_ERR_IPC_FAILED;
314     }
315     if (!data.WriteBool(isEnable)) {
316         HILOG_ERROR("isEnable write error: %{public}d, ", isEnable);
317         return RET_ERR_IPC_FAILED;
318     }
319     if (!SendTransactCmd(AccessibilityInterfaceCode::SET_CURTAIN_SCREEN,
320         data, reply, option)) {
321         HILOG_ERROR("fail to enable screen curtain");
322         return RET_ERR_IPC_FAILED;
323     }
324 
325     return static_cast<RetError>(reply.ReadInt32());
326 }
327 
ExecuteAction(const int32_t accessibilityWindowId,const int64_t elementId,const int32_t action,const std::map<std::string,std::string> & actionArguments,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)328 RetError AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWindowId, const int64_t elementId,
329     const int32_t action, const std::map<std::string, std::string> &actionArguments, const int32_t requestId,
330     const sptr<IAccessibilityElementOperatorCallback> &callback)
331 {
332     HILOG_DEBUG();
333 
334     MessageParcel data;
335     MessageParcel reply;
336     MessageOption option;
337 
338     if (!WriteInterfaceToken(data)) {
339         return RET_ERR_IPC_FAILED;
340     }
341     if (!data.WriteInt32(accessibilityWindowId)) {
342         HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId);
343         return RET_ERR_IPC_FAILED;
344     }
345     if (!data.WriteInt64(elementId)) {
346         HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId);
347         return RET_ERR_IPC_FAILED;
348     }
349     if (!data.WriteInt32(action)) {
350         HILOG_ERROR("action write error: %{public}d, ", action);
351         return RET_ERR_IPC_FAILED;
352     }
353 
354     std::vector<std::string> actionArgumentsKey {};
355     std::vector<std::string> actionArgumentsValue {};
356     for (auto iter = actionArguments.begin(); iter != actionArguments.end(); iter++) {
357         actionArgumentsKey.push_back(iter->first);
358         actionArgumentsValue.push_back(iter->second);
359     }
360     if (!data.WriteStringVector(actionArgumentsKey)) {
361         HILOG_ERROR("actionArgumentsKey write error");
362         return RET_ERR_IPC_FAILED;
363     }
364     if (!data.WriteStringVector(actionArgumentsValue)) {
365         HILOG_ERROR("actionArgumentsValue write error");
366         return RET_ERR_IPC_FAILED;
367     }
368 
369     if (!data.WriteInt32(requestId)) {
370         HILOG_ERROR("requestId write error: %{public}d, ", requestId);
371         return RET_ERR_IPC_FAILED;
372     }
373     if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) {
374         HILOG_ERROR("callback write error");
375         return RET_ERR_IPC_FAILED;
376     }
377 
378     if (!SendTransactCmd(AccessibilityInterfaceCode::PERFORM_ACTION,
379         data, reply, option)) {
380         HILOG_ERROR("fail to perform accessibility action");
381         return RET_ERR_IPC_FAILED;
382     }
383     return static_cast<RetError>(reply.ReadInt32());
384 }
385 
GetWindow(const int32_t windowId,AccessibilityWindowInfo & windowInfo)386 RetError AccessibleAbilityChannelProxy::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo)
387 {
388     HILOG_DEBUG();
389 
390     MessageParcel data;
391     MessageParcel reply;
392     MessageOption option;
393 
394     if (!WriteInterfaceToken(data)) {
395         return RET_ERR_IPC_FAILED;
396     }
397 
398     if (!data.WriteInt32(windowId)) {
399         HILOG_ERROR("windowId write error: %{public}d, ", windowId);
400         return RET_ERR_IPC_FAILED;
401     }
402 
403     if (!SendTransactCmd(AccessibilityInterfaceCode::GET_WINDOW, data, reply, option)) {
404         HILOG_ERROR("fail to get window");
405         return RET_ERR_IPC_FAILED;
406     }
407 
408     sptr<AccessibilityWindowInfoParcel> windowInfoParcel = reply.ReadStrongParcelable<AccessibilityWindowInfoParcel>();
409     if (windowInfoParcel == nullptr) {
410         HILOG_ERROR("ReadStrongParcelable<AccessibilityWindowInfoParcel> failed");
411         return RET_ERR_IPC_FAILED;
412     }
413     windowInfo = *windowInfoParcel;
414 
415     return static_cast<RetError>(reply.ReadInt32());
416 }
417 
GetWindows(std::vector<AccessibilityWindowInfo> & windows)418 RetError AccessibleAbilityChannelProxy::GetWindows(std::vector<AccessibilityWindowInfo> &windows)
419 {
420     HILOG_DEBUG();
421     MessageParcel data;
422     MessageParcel reply;
423     MessageOption option;
424 
425     if (!WriteInterfaceToken(data)) {
426         return RET_ERR_IPC_FAILED;
427     }
428 
429     if (!SendTransactCmd(AccessibilityInterfaceCode::GET_WINDOWS, data, reply, option)) {
430         HILOG_ERROR("fail to get windows");
431         return RET_ERR_IPC_FAILED;
432     }
433 
434     int32_t windowsSize = reply.ReadInt32();
435     if (windowsSize < 0 || windowsSize > MAX_ALLOW_SIZE) {
436         HILOG_ERROR("windowsSize is invalid");
437         return RET_ERR_INVALID_PARAM;
438     }
439 
440     for (int32_t i = 0; i < windowsSize; i++) {
441         sptr<AccessibilityWindowInfoParcel> window = reply.ReadStrongParcelable<AccessibilityWindowInfoParcel>();
442         if (window == nullptr) {
443             HILOG_ERROR("ReadStrongParcelable<AccessibilityWindowInfoParcel> failed");
444             return RET_ERR_IPC_FAILED;
445         }
446         windows.emplace_back(*window);
447     }
448 
449     return static_cast<RetError>(reply.ReadInt32());
450 }
451 
GetWindowsByDisplayId(const uint64_t displayId,std::vector<AccessibilityWindowInfo> & windows)452 RetError AccessibleAbilityChannelProxy::GetWindowsByDisplayId(const uint64_t displayId,
453     std::vector<AccessibilityWindowInfo> &windows)
454 {
455     HILOG_DEBUG();
456 
457     MessageParcel data;
458     MessageParcel reply;
459     MessageOption option;
460 
461     if (!WriteInterfaceToken(data)) {
462         return RET_ERR_IPC_FAILED;
463     }
464 
465     if (!data.WriteUint64(displayId)) {
466         HILOG_ERROR("displayId write error: %{public}" PRIu64 ", ", displayId);
467         return RET_ERR_IPC_FAILED;
468     }
469 
470     if (!SendTransactCmd(AccessibilityInterfaceCode::GET_WINDOWS_BY_DISPLAY_ID, data, reply, option)) {
471         HILOG_ERROR("fail to get windows");
472         return RET_ERR_IPC_FAILED;
473     }
474 
475     int32_t windowsSize = reply.ReadInt32();
476     if (windowsSize < 0 || windowsSize > MAX_ALLOW_SIZE) {
477         HILOG_ERROR("windowsSize is invalid");
478         return RET_ERR_INVALID_PARAM;
479     }
480 
481     for (int32_t i = 0; i < windowsSize; i++) {
482         sptr<AccessibilityWindowInfoParcel> window = reply.ReadStrongParcelable<AccessibilityWindowInfoParcel>();
483         if (window == nullptr) {
484             HILOG_ERROR("ReadStrongParcelable<AccessibilityWindowInfoParcel> failed");
485             return RET_ERR_IPC_FAILED;
486         }
487         windows.emplace_back(*window);
488     }
489 
490     return static_cast<RetError>(reply.ReadInt32());
491 }
492 
SetOnKeyPressEventResult(const bool handled,const int32_t sequence)493 void AccessibleAbilityChannelProxy::SetOnKeyPressEventResult(const bool handled, const int32_t sequence)
494 {
495     HILOG_DEBUG();
496 
497     MessageParcel data;
498     MessageParcel reply;
499     MessageOption option(MessageOption::TF_ASYNC);
500 
501     if (!WriteInterfaceToken(data)) {
502         return;
503     }
504     if (!data.WriteBool(handled)) {
505         HILOG_ERROR("handled write error: %{public}d, ", handled);
506         return;
507     }
508     if (!data.WriteInt32(sequence)) {
509         HILOG_ERROR("sequence write error: %{public}d, ", sequence);
510         return;
511     }
512     if (!SendTransactCmd(AccessibilityInterfaceCode::SET_ON_KEY_PRESS_EVENT_RESULT,
513         data, reply, option)) {
514         HILOG_ERROR("fail to set onKeyPressEvent result");
515     }
516 }
517 
GetCursorPosition(const int32_t accessibilityWindowId,const int64_t elementId,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)518 RetError AccessibleAbilityChannelProxy::GetCursorPosition(const int32_t accessibilityWindowId, const int64_t elementId,
519     const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback)
520 {
521     HILOG_DEBUG();
522 
523     MessageParcel data;
524     MessageParcel reply;
525     MessageOption option(MessageOption::TF_ASYNC);
526     if (!WriteInterfaceToken(data)) {
527         return RET_ERR_FAILED;
528     }
529     if (!data.WriteInt32(accessibilityWindowId)) {
530         HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId);
531         return RET_ERR_FAILED;
532     }
533     if (!data.WriteInt64(elementId)) {
534         HILOG_ERROR("elementId write error");
535         return RET_ERR_FAILED;
536     }
537     if (!data.WriteInt32(requestId)) {
538         HILOG_ERROR("requestId write error: %{public}d, ", requestId);
539         return RET_ERR_IPC_FAILED;
540     }
541     if (callback == nullptr) {
542         HILOG_ERROR("callback is null");
543         return RET_ERR_FAILED;
544     }
545     if (callback->AsObject() == nullptr) {
546         HILOG_ERROR("callback->AsObject() is null");
547         return RET_ERR_FAILED;
548     }
549     if (!data.WriteRemoteObject(callback->AsObject())) {
550         HILOG_ERROR("callback write error");
551         return RET_ERR_IPC_FAILED;
552     }
553     if (!SendTransactCmd(AccessibilityInterfaceCode::GET_CURSOR_POSITION,
554         data, reply, option)) {
555         HILOG_ERROR("fail to set onKeyPressEvent result");
556         return RET_ERR_FAILED;
557     }
558 
559     return static_cast<RetError>(reply.ReadInt32());
560 }
561 
SendSimulateGesture(const std::shared_ptr<AccessibilityGestureInjectPath> & gesturePath)562 RetError AccessibleAbilityChannelProxy::SendSimulateGesture(
563     const std::shared_ptr<AccessibilityGestureInjectPath>& gesturePath)
564 {
565     HILOG_DEBUG();
566     sptr<AccessibilityGestureInjectPathParcel> path =
567         new(std::nothrow) AccessibilityGestureInjectPathParcel(*gesturePath);
568     if (path == nullptr) {
569         HILOG_ERROR("Failed to create path.");
570         return RET_ERR_NULLPTR;
571     }
572 
573     MessageParcel data;
574     MessageParcel reply;
575     MessageOption option(MessageOption::TF_SYNC);
576 
577     if (!WriteInterfaceToken(data)) {
578         return RET_ERR_IPC_FAILED;
579     }
580 
581     if (!data.WriteStrongParcelable(path)) {
582         HILOG_ERROR("WriteStrongParcelable<AccessibilityGestureInjectPathParcel> failed");
583         return RET_ERR_IPC_FAILED;
584     }
585 
586     if (!SendTransactCmd(AccessibilityInterfaceCode::SEND_SIMULATE_GESTURE_PATH, data, reply, option)) {
587         HILOG_ERROR("fail to send simulation gesture path");
588         return RET_ERR_IPC_FAILED;
589     }
590     return static_cast<RetError>(reply.ReadInt32());
591 }
592 
SetTargetBundleName(const std::vector<std::string> & targetBundleNames)593 RetError AccessibleAbilityChannelProxy::SetTargetBundleName(const std::vector<std::string> &targetBundleNames)
594 {
595     HILOG_DEBUG();
596 
597     MessageParcel data;
598     MessageParcel reply;
599     MessageOption option(MessageOption::TF_SYNC);
600 
601     if (!WriteInterfaceToken(data)) {
602         return RET_ERR_IPC_FAILED;
603     }
604     if (!data.WriteInt32(targetBundleNames.size())) {
605         HILOG_ERROR("targetBundleNames.size() write error: %{public}zu, ", targetBundleNames.size());
606         return RET_ERR_IPC_FAILED;
607     }
608     for (auto &targetBundleName : targetBundleNames) {
609         if (!data.WriteString(targetBundleName)) {
610             HILOG_ERROR("targetBundleName write error: %{public}s, ", targetBundleName.c_str());
611             return RET_ERR_IPC_FAILED;
612         }
613     }
614     if (!SendTransactCmd(AccessibilityInterfaceCode::SET_TARGET_BUNDLE_NAME, data, reply, option)) {
615         HILOG_ERROR("fail to set target bundle name filter");
616         return RET_ERR_IPC_FAILED;
617     }
618     return static_cast<RetError>(reply.ReadInt32());
619 }
620 } // namespace Accessibility
621 } // namespace OHOS