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,bool systemApi)62 RetError AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const ElementBasicInfo elementBasicInfo,
63 const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback,
64 const int32_t mode, bool isFilter, bool systemApi)
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 (!data.WriteBool(systemApi)) {
108 return RET_ERR_IPC_FAILED;
109 }
110 if (!SendTransactCmd(AccessibilityInterfaceCode::SEARCH_ELEMENTINFO_BY_ACCESSIBILITY_ID,
111 data, reply, option)) {
112 HILOG_ERROR("fail to find elementInfo by elementId");
113 return RET_ERR_IPC_FAILED;
114 }
115 return static_cast<RetError>(reply.ReadInt32());
116 }
117
SearchDefaultFocusedByWindowId(const ElementBasicInfo elementBasicInfo,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback,const int32_t mode,bool isFilter)118 RetError AccessibleAbilityChannelProxy::SearchDefaultFocusedByWindowId(const ElementBasicInfo elementBasicInfo,
119 const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback,
120 const int32_t mode, bool isFilter)
121 {
122 HILOG_DEBUG();
123 if (callback == nullptr) {
124 HILOG_ERROR("callback is nullptr.");
125 return RET_ERR_INVALID_PARAM;
126 }
127
128 MessageParcel data;
129 MessageParcel reply;
130 MessageOption option;
131
132 if (!WriteInterfaceToken(data)) {
133 return RET_ERR_IPC_FAILED;
134 }
135 if (!data.WriteInt32(elementBasicInfo.windowId)) {
136 HILOG_ERROR("windowId write error: %{public}d, ", elementBasicInfo.windowId);
137 return RET_ERR_IPC_FAILED;
138 }
139 if (!data.WriteInt64(elementBasicInfo.elementId)) {
140 HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementBasicInfo.elementId);
141 return RET_ERR_IPC_FAILED;
142 }
143 if (!data.WriteInt32(elementBasicInfo.treeId)) {
144 HILOG_ERROR("treeId write error: %{public}d, ", elementBasicInfo.treeId);
145 return RET_ERR_IPC_FAILED;
146 }
147 if (!data.WriteInt32(requestId)) {
148 HILOG_ERROR("requestId write error: %{public}d, ", requestId);
149 return RET_ERR_IPC_FAILED;
150 }
151 if (!data.WriteRemoteObject(callback->AsObject())) {
152 HILOG_ERROR("callback write error");
153 return RET_ERR_IPC_FAILED;
154 }
155 if (!data.WriteInt32(mode)) {
156 HILOG_ERROR("mode write error: %{public}d, ", mode);
157 return RET_ERR_IPC_FAILED;
158 }
159 if (!data.WriteBool(isFilter)) {
160 HILOG_ERROR("isFilter write error: %{public}d, ", isFilter);
161 return RET_ERR_IPC_FAILED;
162 }
163 if (!SendTransactCmd(AccessibilityInterfaceCode::SEARCH_DEFAULTFOCUSED_BY_WINDOW_ID,
164 data, reply, option)) {
165 HILOG_ERROR("fail to find elementInfo by elementId");
166 return RET_ERR_IPC_FAILED;
167 }
168 return static_cast<RetError>(reply.ReadInt32());
169 }
170
SearchElementInfosByText(const int32_t accessibilityWindowId,const int64_t elementId,const std::string & text,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback,bool systemApi)171 RetError AccessibleAbilityChannelProxy::SearchElementInfosByText(const int32_t accessibilityWindowId,
172 const int64_t elementId, const std::string &text, const int32_t requestId,
173 const sptr<IAccessibilityElementOperatorCallback> &callback, bool systemApi)
174 {
175 HILOG_DEBUG();
176
177 if (callback == nullptr) {
178 HILOG_ERROR("callback is nullptr.");
179 return RET_ERR_INVALID_PARAM;
180 }
181
182 MessageParcel data;
183 MessageParcel reply;
184 MessageOption option;
185
186 if (!WriteInterfaceToken(data)) {
187 return RET_ERR_IPC_FAILED;
188 }
189 if (!data.WriteInt32(accessibilityWindowId)) {
190 HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId);
191 return RET_ERR_IPC_FAILED;
192 }
193 if (!data.WriteInt64(elementId)) {
194 HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId);
195 return RET_ERR_IPC_FAILED;
196 }
197 if (!data.WriteString(text)) {
198 HILOG_ERROR("text write error: %{public}s, ", text.c_str());
199 return RET_ERR_IPC_FAILED;
200 }
201 if (!data.WriteInt32(requestId)) {
202 HILOG_ERROR("requestId write error: %{public}d, ", requestId);
203 return RET_ERR_IPC_FAILED;
204 }
205 if (!data.WriteRemoteObject(callback->AsObject())) {
206 HILOG_ERROR("callback write error");
207 return RET_ERR_IPC_FAILED;
208 }
209 if (!data.WriteBool(systemApi)) {
210 HILOG_ERROR("systemApi write error: %{public}d, ", systemApi);
211 return RET_ERR_IPC_FAILED;
212 }
213
214 if (!SendTransactCmd(AccessibilityInterfaceCode::SEARCH_ELEMENTINFOS_BY_TEXT,
215 data, reply, option)) {
216 HILOG_ERROR("fail to find elementInfo by text");
217 return RET_ERR_IPC_FAILED;
218 }
219 return static_cast<RetError>(reply.ReadInt32());
220 }
221
FindFocusedElementInfo(const int32_t accessibilityWindowId,const int64_t elementId,const int32_t focusType,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback,bool systemApi)222 RetError AccessibleAbilityChannelProxy::FindFocusedElementInfo(const int32_t accessibilityWindowId,
223 const int64_t elementId, const int32_t focusType, const int32_t requestId,
224 const sptr<IAccessibilityElementOperatorCallback> &callback, bool systemApi)
225 {
226 HILOG_DEBUG();
227 if (callback == nullptr) {
228 HILOG_ERROR("callback is nullptr.");
229 return RET_ERR_INVALID_PARAM;
230 }
231
232 MessageParcel data;
233 MessageParcel reply;
234 MessageOption option;
235
236 if (!WriteInterfaceToken(data)) {
237 return RET_ERR_IPC_FAILED;
238 }
239 if (!data.WriteInt32(accessibilityWindowId)) {
240 HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId);
241 return RET_ERR_IPC_FAILED;
242 }
243 if (!data.WriteInt64(elementId)) {
244 HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId);
245 return RET_ERR_IPC_FAILED;
246 }
247 if (!data.WriteInt32(focusType)) {
248 HILOG_ERROR("focusType write error: %{public}d, ", focusType);
249 return RET_ERR_IPC_FAILED;
250 }
251 if (!data.WriteInt32(requestId)) {
252 HILOG_ERROR("requestId write error: %{public}d, ", requestId);
253 return RET_ERR_IPC_FAILED;
254 }
255 if (!data.WriteRemoteObject(callback->AsObject())) {
256 HILOG_ERROR("callback write error");
257 return RET_ERR_IPC_FAILED;
258 }
259 if (!data.WriteBool(systemApi)) {
260 HILOG_ERROR("systemApi write error: %{public}d, ", systemApi);
261 return RET_ERR_IPC_FAILED;
262 }
263
264 if (!SendTransactCmd(AccessibilityInterfaceCode::FIND_FOCUSED_ELEMENTINFO, data, reply, option)) {
265 HILOG_ERROR("fail to gain focus");
266 return RET_ERR_IPC_FAILED;
267 }
268 return static_cast<RetError>(reply.ReadInt32());
269 }
270
FocusMoveSearch(const int32_t accessibilityWindowId,const int64_t elementId,const int32_t direction,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback,bool systemApi)271 RetError AccessibleAbilityChannelProxy::FocusMoveSearch(const int32_t accessibilityWindowId, const int64_t elementId,
272 const int32_t direction, const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback,
273 bool systemApi)
274 {
275 HILOG_DEBUG();
276 if (callback == nullptr) {
277 HILOG_ERROR("callback is nullptr.");
278 return RET_ERR_INVALID_PARAM;
279 }
280
281 MessageParcel data;
282 MessageParcel reply;
283 MessageOption option;
284
285 if (!WriteInterfaceToken(data)) {
286 return RET_ERR_IPC_FAILED;
287 }
288 if (!data.WriteInt32(accessibilityWindowId)) {
289 HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId);
290 return RET_ERR_IPC_FAILED;
291 }
292 if (!data.WriteInt64(elementId)) {
293 HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId);
294 return RET_ERR_IPC_FAILED;
295 }
296 if (!data.WriteInt32(direction)) {
297 HILOG_ERROR("direction write error: %{public}d, ", direction);
298 return RET_ERR_IPC_FAILED;
299 }
300 if (!data.WriteInt32(requestId)) {
301 HILOG_ERROR("requestId write error: %{public}d, ", requestId);
302 return RET_ERR_IPC_FAILED;
303 }
304 if (!data.WriteRemoteObject(callback->AsObject())) {
305 HILOG_ERROR("callback write error");
306 return RET_ERR_IPC_FAILED;
307 }
308 if (!data.WriteBool(systemApi)) {
309 HILOG_ERROR("systemApi write error: %{public}d, ", systemApi);
310 return RET_ERR_IPC_FAILED;
311 }
312
313 if (!SendTransactCmd(AccessibilityInterfaceCode::FOCUS_MOVE_SEARCH, data, reply, option)) {
314 HILOG_ERROR("fail to search focus");
315 return RET_ERR_IPC_FAILED;
316 }
317 return static_cast<RetError>(reply.ReadInt32());
318 }
319
EnableScreenCurtain(bool isEnable)320 RetError AccessibleAbilityChannelProxy::EnableScreenCurtain(bool isEnable)
321 {
322 HILOG_DEBUG();
323
324 MessageParcel data;
325 MessageParcel reply;
326 MessageOption option;
327
328 if (!WriteInterfaceToken(data)) {
329 return RET_ERR_IPC_FAILED;
330 }
331 if (!data.WriteBool(isEnable)) {
332 HILOG_ERROR("isEnable write error: %{public}d, ", isEnable);
333 return RET_ERR_IPC_FAILED;
334 }
335 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_CURTAIN_SCREEN,
336 data, reply, option)) {
337 HILOG_ERROR("fail to enable screen curtain");
338 return RET_ERR_IPC_FAILED;
339 }
340
341 return static_cast<RetError>(reply.ReadInt32());
342 }
343
HoldRunningLock()344 RetError AccessibleAbilityChannelProxy::HoldRunningLock()
345 {
346 HILOG_DEBUG();
347
348 MessageParcel data;
349 MessageParcel reply;
350 MessageOption option;
351
352 if (!WriteInterfaceToken(data)) {
353 return RET_ERR_IPC_FAILED;
354 }
355
356 if (!SendTransactCmd(AccessibilityInterfaceCode::HOLD_RUNNING_LOCK,
357 data, reply, option)) {
358 HILOG_ERROR("fail to hold the running lock");
359 return RET_ERR_IPC_FAILED;
360 }
361
362 return static_cast<RetError>(reply.ReadInt32());
363 }
364
UnholdRunningLock()365 RetError AccessibleAbilityChannelProxy::UnholdRunningLock()
366 {
367 HILOG_DEBUG();
368
369 MessageParcel data;
370 MessageParcel reply;
371 MessageOption option;
372
373 if (!WriteInterfaceToken(data)) {
374 return RET_ERR_IPC_FAILED;
375 }
376 if (!SendTransactCmd(AccessibilityInterfaceCode::UNHOLD_RUNNING_LOCK,
377 data, reply, option)) {
378 HILOG_ERROR("fail to unhold the running lock");
379 return RET_ERR_IPC_FAILED;
380 }
381
382 return static_cast<RetError>(reply.ReadInt32());
383 }
384
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)385 RetError AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWindowId, const int64_t elementId,
386 const int32_t action, const std::map<std::string, std::string> &actionArguments, const int32_t requestId,
387 const sptr<IAccessibilityElementOperatorCallback> &callback)
388 {
389 HILOG_DEBUG();
390
391 MessageParcel data;
392 MessageParcel reply;
393 MessageOption option;
394
395 if (!WriteInterfaceToken(data)) {
396 return RET_ERR_IPC_FAILED;
397 }
398 if (!data.WriteInt32(accessibilityWindowId)) {
399 HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId);
400 return RET_ERR_IPC_FAILED;
401 }
402 if (!data.WriteInt64(elementId)) {
403 HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId);
404 return RET_ERR_IPC_FAILED;
405 }
406 if (!data.WriteInt32(action)) {
407 HILOG_ERROR("action write error: %{public}d, ", action);
408 return RET_ERR_IPC_FAILED;
409 }
410
411 std::vector<std::string> actionArgumentsKey {};
412 std::vector<std::string> actionArgumentsValue {};
413 for (auto iter = actionArguments.begin(); iter != actionArguments.end(); iter++) {
414 actionArgumentsKey.push_back(iter->first);
415 actionArgumentsValue.push_back(iter->second);
416 }
417 if (!data.WriteStringVector(actionArgumentsKey)) {
418 HILOG_ERROR("actionArgumentsKey write error");
419 return RET_ERR_IPC_FAILED;
420 }
421 if (!data.WriteStringVector(actionArgumentsValue)) {
422 HILOG_ERROR("actionArgumentsValue write error");
423 return RET_ERR_IPC_FAILED;
424 }
425
426 if (!data.WriteInt32(requestId)) {
427 HILOG_ERROR("requestId write error: %{public}d, ", requestId);
428 return RET_ERR_IPC_FAILED;
429 }
430 if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) {
431 HILOG_ERROR("callback write error");
432 return RET_ERR_IPC_FAILED;
433 }
434
435 if (!SendTransactCmd(AccessibilityInterfaceCode::PERFORM_ACTION,
436 data, reply, option)) {
437 HILOG_ERROR("fail to perform accessibility action");
438 return RET_ERR_IPC_FAILED;
439 }
440 return static_cast<RetError>(reply.ReadInt32());
441 }
442
GetWindow(const int32_t windowId,AccessibilityWindowInfo & windowInfo)443 RetError AccessibleAbilityChannelProxy::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo)
444 {
445 HILOG_DEBUG();
446
447 MessageParcel data;
448 MessageParcel reply;
449 MessageOption option;
450
451 if (!WriteInterfaceToken(data)) {
452 return RET_ERR_IPC_FAILED;
453 }
454
455 if (!data.WriteInt32(windowId)) {
456 HILOG_ERROR("windowId write error: %{public}d, ", windowId);
457 return RET_ERR_IPC_FAILED;
458 }
459
460 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_WINDOW, data, reply, option)) {
461 HILOG_ERROR("fail to get window");
462 return RET_ERR_IPC_FAILED;
463 }
464
465 sptr<AccessibilityWindowInfoParcel> windowInfoParcel = reply.ReadStrongParcelable<AccessibilityWindowInfoParcel>();
466 if (windowInfoParcel == nullptr) {
467 HILOG_ERROR("ReadStrongParcelable<AccessibilityWindowInfoParcel> failed");
468 return RET_ERR_IPC_FAILED;
469 }
470 windowInfo = *windowInfoParcel;
471
472 return static_cast<RetError>(reply.ReadInt32());
473 }
474
GetWindows(std::vector<AccessibilityWindowInfo> & windows,bool systemApi)475 RetError AccessibleAbilityChannelProxy::GetWindows(std::vector<AccessibilityWindowInfo> &windows, bool systemApi)
476 {
477 HILOG_DEBUG();
478 MessageParcel data;
479 MessageParcel reply;
480 MessageOption option;
481
482 if (!WriteInterfaceToken(data)) {
483 return RET_ERR_IPC_FAILED;
484 }
485 if (!data.WriteBool(systemApi)) {
486 HILOG_ERROR("systemApi write error: %{public}d, ", systemApi);
487 return RET_ERR_IPC_FAILED;
488 }
489
490 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_WINDOWS, data, reply, option)) {
491 HILOG_ERROR("fail to get windows");
492 return RET_ERR_IPC_FAILED;
493 }
494
495 int32_t windowsSize = reply.ReadInt32();
496 if (windowsSize < 0 || windowsSize > MAX_ALLOW_SIZE) {
497 HILOG_ERROR("windowsSize is invalid");
498 return RET_ERR_INVALID_PARAM;
499 }
500
501 for (int32_t i = 0; i < windowsSize; i++) {
502 sptr<AccessibilityWindowInfoParcel> window = reply.ReadStrongParcelable<AccessibilityWindowInfoParcel>();
503 if (window == nullptr) {
504 HILOG_ERROR("ReadStrongParcelable<AccessibilityWindowInfoParcel> failed");
505 return RET_ERR_IPC_FAILED;
506 }
507 windows.emplace_back(*window);
508 }
509
510 return static_cast<RetError>(reply.ReadInt32());
511 }
512
GetWindowsByDisplayId(const uint64_t displayId,std::vector<AccessibilityWindowInfo> & windows,bool systemApi)513 RetError AccessibleAbilityChannelProxy::GetWindowsByDisplayId(const uint64_t displayId,
514 std::vector<AccessibilityWindowInfo> &windows, bool systemApi)
515 {
516 HILOG_DEBUG();
517
518 MessageParcel data;
519 MessageParcel reply;
520 MessageOption option;
521
522 if (!WriteInterfaceToken(data)) {
523 return RET_ERR_IPC_FAILED;
524 }
525
526 if (!data.WriteUint64(displayId)) {
527 HILOG_ERROR("displayId write error: %{public}" PRIu64 ", ", displayId);
528 return RET_ERR_IPC_FAILED;
529 }
530
531 if (!data.WriteBool(systemApi)) {
532 HILOG_ERROR("systemApi write error: %{public}d, ", systemApi);
533 return RET_ERR_IPC_FAILED;
534 }
535
536 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_WINDOWS_BY_DISPLAY_ID, data, reply, option)) {
537 HILOG_ERROR("fail to get windows");
538 return RET_ERR_IPC_FAILED;
539 }
540
541 int32_t windowsSize = reply.ReadInt32();
542 if (windowsSize < 0 || windowsSize > MAX_ALLOW_SIZE) {
543 HILOG_ERROR("windowsSize is invalid");
544 return RET_ERR_INVALID_PARAM;
545 }
546
547 for (int32_t i = 0; i < windowsSize; i++) {
548 sptr<AccessibilityWindowInfoParcel> window = reply.ReadStrongParcelable<AccessibilityWindowInfoParcel>();
549 if (window == nullptr) {
550 HILOG_ERROR("ReadStrongParcelable<AccessibilityWindowInfoParcel> failed");
551 return RET_ERR_IPC_FAILED;
552 }
553 windows.emplace_back(*window);
554 }
555
556 return static_cast<RetError>(reply.ReadInt32());
557 }
558
SetOnKeyPressEventResult(const bool handled,const int32_t sequence)559 void AccessibleAbilityChannelProxy::SetOnKeyPressEventResult(const bool handled, const int32_t sequence)
560 {
561 HILOG_DEBUG();
562
563 MessageParcel data;
564 MessageParcel reply;
565 MessageOption option(MessageOption::TF_ASYNC);
566
567 if (!WriteInterfaceToken(data)) {
568 return;
569 }
570 if (!data.WriteBool(handled)) {
571 HILOG_ERROR("handled write error: %{public}d, ", handled);
572 return;
573 }
574 if (!data.WriteInt32(sequence)) {
575 HILOG_ERROR("sequence write error: %{public}d, ", sequence);
576 return;
577 }
578 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_ON_KEY_PRESS_EVENT_RESULT,
579 data, reply, option)) {
580 HILOG_ERROR("fail to set onKeyPressEvent result");
581 }
582 }
583
GetCursorPosition(const int32_t accessibilityWindowId,const int64_t elementId,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)584 RetError AccessibleAbilityChannelProxy::GetCursorPosition(const int32_t accessibilityWindowId, const int64_t elementId,
585 const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback)
586 {
587 HILOG_DEBUG();
588
589 MessageParcel data;
590 MessageParcel reply;
591 MessageOption option(MessageOption::TF_ASYNC);
592 if (!WriteInterfaceToken(data)) {
593 return RET_ERR_FAILED;
594 }
595 if (!data.WriteInt32(accessibilityWindowId)) {
596 HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId);
597 return RET_ERR_FAILED;
598 }
599 if (!data.WriteInt64(elementId)) {
600 HILOG_ERROR("elementId write error");
601 return RET_ERR_FAILED;
602 }
603 if (!data.WriteInt32(requestId)) {
604 HILOG_ERROR("requestId write error: %{public}d, ", requestId);
605 return RET_ERR_IPC_FAILED;
606 }
607 if (callback == nullptr) {
608 HILOG_ERROR("callback is null");
609 return RET_ERR_FAILED;
610 }
611 if (callback->AsObject() == nullptr) {
612 HILOG_ERROR("callback->AsObject() is null");
613 return RET_ERR_FAILED;
614 }
615 if (!data.WriteRemoteObject(callback->AsObject())) {
616 HILOG_ERROR("callback write error");
617 return RET_ERR_IPC_FAILED;
618 }
619 if (!SendTransactCmd(AccessibilityInterfaceCode::GET_CURSOR_POSITION,
620 data, reply, option)) {
621 HILOG_ERROR("fail to set onKeyPressEvent result");
622 return RET_ERR_FAILED;
623 }
624
625 return static_cast<RetError>(reply.ReadInt32());
626 }
627
SendSimulateGesture(const std::shared_ptr<AccessibilityGestureInjectPath> & gesturePath)628 RetError AccessibleAbilityChannelProxy::SendSimulateGesture(
629 const std::shared_ptr<AccessibilityGestureInjectPath>& gesturePath)
630 {
631 HILOG_DEBUG();
632 sptr<AccessibilityGestureInjectPathParcel> path =
633 new(std::nothrow) AccessibilityGestureInjectPathParcel(*gesturePath);
634 if (path == nullptr) {
635 HILOG_ERROR("Failed to create path.");
636 return RET_ERR_NULLPTR;
637 }
638
639 MessageParcel data;
640 MessageParcel reply;
641 MessageOption option(MessageOption::TF_SYNC);
642
643 if (!WriteInterfaceToken(data)) {
644 return RET_ERR_IPC_FAILED;
645 }
646
647 if (!data.WriteStrongParcelable(path)) {
648 HILOG_ERROR("WriteStrongParcelable<AccessibilityGestureInjectPathParcel> failed");
649 return RET_ERR_IPC_FAILED;
650 }
651
652 if (!SendTransactCmd(AccessibilityInterfaceCode::SEND_SIMULATE_GESTURE_PATH, data, reply, option)) {
653 HILOG_ERROR("fail to send simulation gesture path");
654 return RET_ERR_IPC_FAILED;
655 }
656 return static_cast<RetError>(reply.ReadInt32());
657 }
658
SetTargetBundleName(const std::vector<std::string> & targetBundleNames)659 RetError AccessibleAbilityChannelProxy::SetTargetBundleName(const std::vector<std::string> &targetBundleNames)
660 {
661 HILOG_DEBUG();
662
663 MessageParcel data;
664 MessageParcel reply;
665 MessageOption option(MessageOption::TF_SYNC);
666
667 if (!WriteInterfaceToken(data)) {
668 return RET_ERR_IPC_FAILED;
669 }
670 if (!data.WriteInt32(targetBundleNames.size())) {
671 HILOG_ERROR("targetBundleNames.size() write error: %{public}zu, ", targetBundleNames.size());
672 return RET_ERR_IPC_FAILED;
673 }
674 for (auto &targetBundleName : targetBundleNames) {
675 if (!data.WriteString(targetBundleName)) {
676 HILOG_ERROR("targetBundleName write error: %{public}s, ", targetBundleName.c_str());
677 return RET_ERR_IPC_FAILED;
678 }
679 }
680 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_TARGET_BUNDLE_NAME, data, reply, option)) {
681 HILOG_ERROR("fail to set target bundle name filter");
682 return RET_ERR_IPC_FAILED;
683 }
684 return static_cast<RetError>(reply.ReadInt32());
685 }
686
SetIsRegisterDisconnectCallback(bool isRegister)687 RetError AccessibleAbilityChannelProxy::SetIsRegisterDisconnectCallback(bool isRegister)
688 {
689 HILOG_DEBUG();
690
691 MessageParcel data;
692 MessageParcel reply;
693 MessageOption option;
694
695 if (!WriteInterfaceToken(data)) {
696 return RET_ERR_IPC_FAILED;
697 }
698 if (!data.WriteBool(isRegister)) {
699 HILOG_ERROR("isRegister write error: %{public}d, ", isRegister);
700 return RET_ERR_IPC_FAILED;
701 }
702 if (!SendTransactCmd(AccessibilityInterfaceCode::SET_IS_REGISTER_DISCONNECT_CALLBACK,
703 data, reply, option)) {
704 HILOG_ERROR("fail to SetIsRegisterDisconnectCallback");
705 return RET_ERR_IPC_FAILED;
706 }
707
708 return static_cast<RetError>(reply.ReadInt32());
709 }
710
NotifyDisconnect()711 RetError AccessibleAbilityChannelProxy::NotifyDisconnect()
712 {
713 HILOG_DEBUG();
714
715 MessageParcel data;
716 MessageParcel reply;
717 MessageOption option(MessageOption::TF_SYNC);
718
719 if (!WriteInterfaceToken(data)) {
720 return RET_ERR_IPC_FAILED;
721 }
722
723 if (!SendTransactCmd(AccessibilityInterfaceCode::NOTIFY_DISCONNECT,
724 data, reply, option)) {
725 HILOG_ERROR("fail to notify disconnect");
726 return RET_ERR_IPC_FAILED;
727 }
728
729 return static_cast<RetError>(reply.ReadInt32());
730 }
731
ConfigureEvents(const std::vector<uint32_t> needEvents)732 RetError AccessibleAbilityChannelProxy::ConfigureEvents(const std::vector<uint32_t> needEvents)
733 {
734 HILOG_DEBUG();
735
736 MessageParcel data;
737 MessageParcel reply;
738 MessageOption option(MessageOption::TF_SYNC);
739
740 if (!WriteInterfaceToken(data)) {
741 return RET_ERR_IPC_FAILED;
742 }
743 if (!data.WriteUint32(needEvents.size())) {
744 HILOG_ERROR("needEvents size write error: %{public}zu", needEvents.size());
745 return RET_ERR_IPC_FAILED;
746 }
747 for (auto &needEvent : needEvents) {
748 if (!data.WriteUint32(needEvent)) {
749 HILOG_ERROR("needEvent write error: %{public}d", needEvent);
750 return RET_ERR_IPC_FAILED;
751 }
752 }
753
754 if (!SendTransactCmd(AccessibilityInterfaceCode::CONFIGURE_EVENTS,
755 data, reply, option)) {
756 HILOG_ERROR("fail to notify disconnect");
757 return RET_ERR_IPC_FAILED;
758 }
759
760 return static_cast<RetError>(reply.ReadInt32());
761 }
762
SearchElementInfoBySpecificProperty(const ElementBasicInfo elementBasicInfo,const SpecificPropertyParam & param,const int32_t requestId,const sptr<IAccessibilityElementOperatorCallback> & callback)763 void AccessibleAbilityChannelProxy::SearchElementInfoBySpecificProperty(const ElementBasicInfo elementBasicInfo,
764 const SpecificPropertyParam& param, const int32_t requestId,
765 const sptr<IAccessibilityElementOperatorCallback> &callback)
766 {
767 HILOG_DEBUG("windowId:%{public}d, elementId:%{public}" PRId64 ", propertyTarget:%{public}s,"
768 "propertyType:%{public}u, requestId:%{public}d", elementBasicInfo.windowId, elementBasicInfo.elementId,
769 param.propertyTarget.c_str(), static_cast<uint32_t>(param.propertyType), requestId);
770 if (callback == nullptr) {
771 HILOG_ERROR("callback is nullptr.");
772 return;
773 }
774
775 MessageParcel data;
776 MessageParcel reply;
777 MessageOption option;
778
779 if (!WriteInterfaceToken(data)) {
780 return;
781 }
782 if (!data.WriteInt32(elementBasicInfo.windowId)) {
783 HILOG_ERROR("windowId write error: %{public}d, ", elementBasicInfo.windowId);
784 return;
785 }
786 if (!data.WriteInt64(elementBasicInfo.elementId)) {
787 HILOG_ERROR("elementId write error: %{public}" PRId64 ", ", elementBasicInfo.elementId);
788 return;
789 }
790 if (!data.WriteInt32(elementBasicInfo.treeId)) {
791 HILOG_ERROR("treeId write error: %{public}d, ", elementBasicInfo.treeId);
792 return;
793 }
794 if (!data.WriteString(param.propertyTarget)) {
795 HILOG_ERROR("propertyTarget write error");
796 return;
797 }
798 if (!data.WriteUint32(static_cast<uint32_t>(param.propertyType))) {
799 HILOG_ERROR("propertyType write error");
800 return;
801 }
802 if (!data.WriteInt32(requestId)) {
803 HILOG_ERROR("requestId write error: %{public}d, ", requestId);
804 return;
805 }
806 if (!data.WriteRemoteObject(callback->AsObject())) {
807 HILOG_ERROR("callback write error");
808 return;
809 }
810
811 if (!SendTransactCmd(AccessibilityInterfaceCode::SEARCH_ELEMENTINFOS_BY_SPECIFIC_PROPERTY,
812 data, reply, option)) {
813 HILOG_ERROR("fail to find elementInfo by specific property");
814 return;
815 }
816 }
817 } // namespace Accessibility
818 } // namespace OHOS