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_stub.h"
17 #include "accessibility_element_info_parcel.h"
18 #include "accessibility_gesture_inject_path_parcel.h"
19 #include "accessibility_ipc_interface_code.h"
20 #include "accessibility_permission.h"
21 #include "accessibility_window_info_parcel.h"
22 #include "hilog_wrapper.h"
23 #include "parcel_util.h"
24
25 #define SWITCH_BEGIN(code) switch (code) {
26 #define SWITCH_CASE(case_code, func) \
27 case case_code: { \
28 result_code = func(data, reply); \
29 break; \
30 }
31
32 #define SWITCH_END() \
33 default: { \
34 result_code = ERR_CODE_DEFAULT; \
35 HILOG_WARN("AccessibleAbilityChannelStub::OnRemoteRequest, default case, need check."); \
36 break; \
37 } \
38 }
39
40 #define ACCESSIBLE_ABILITY_CHANNEL_STUB_CASES() \
41 SWITCH_CASE( \
42 AccessibilityInterfaceCode::SEARCH_ELEMENTINFO_BY_ACCESSIBILITY_ID, HandleSearchElementInfoByAccessibilityId) \
43 SWITCH_CASE(AccessibilityInterfaceCode::SEARCH_ELEMENTINFOS_BY_TEXT, HandleSearchElementInfosByText) \
44 SWITCH_CASE(AccessibilityInterfaceCode::FIND_FOCUSED_ELEMENTINFO, HandleFindFocusedElementInfo) \
45 SWITCH_CASE(AccessibilityInterfaceCode::FOCUS_MOVE_SEARCH, HandleFocusMoveSearch) \
46 SWITCH_CASE(AccessibilityInterfaceCode::PERFORM_ACTION, HandleExecuteAction) \
47 SWITCH_CASE(AccessibilityInterfaceCode::SET_CURTAIN_SCREEN, HandleEnableScreenCurtain) \
48 SWITCH_CASE(AccessibilityInterfaceCode::HOLD_RUNNING_LOCK, HandleHoldRunningLock) \
49 SWITCH_CASE(AccessibilityInterfaceCode::UNHOLD_RUNNING_LOCK, HandleUnholdRunningLock) \
50 SWITCH_CASE(AccessibilityInterfaceCode::GET_WINDOW, HandleGetWindow) \
51 SWITCH_CASE(AccessibilityInterfaceCode::GET_WINDOWS, HandleGetWindows) \
52 SWITCH_CASE(AccessibilityInterfaceCode::GET_WINDOWS_BY_DISPLAY_ID, HandleGetWindowsByDisplayId) \
53 SWITCH_CASE(AccessibilityInterfaceCode::SET_ON_KEY_PRESS_EVENT_RESULT, HandleSetOnKeyPressEventResult) \
54 SWITCH_CASE(AccessibilityInterfaceCode::SEND_SIMULATE_GESTURE_PATH, HandleSendSimulateGesturePath) \
55 SWITCH_CASE(AccessibilityInterfaceCode::SET_TARGET_BUNDLE_NAME, HandleSetTargetBundleName) \
56 SWITCH_CASE(AccessibilityInterfaceCode::GET_CURSOR_POSITION, HandleGetCursorPosition) \
57 SWITCH_CASE(AccessibilityInterfaceCode::SEARCH_DEFAULTFOCUSED_BY_WINDOW_ID, HandleSearchDefaultFocusedByWindowId) \
58 SWITCH_CASE( \
59 AccessibilityInterfaceCode::SET_IS_REGISTER_DISCONNECT_CALLBACK, HandleSetIsRegisterDisconnectCallback) \
60 SWITCH_CASE(AccessibilityInterfaceCode::NOTIFY_DISCONNECT, HandleNotifyDisconnect) \
61 SWITCH_CASE(AccessibilityInterfaceCode::CONFIGURE_EVENTS, HandleConfigureEvents) \
62 SWITCH_CASE(AccessibilityInterfaceCode::SEARCH_ELEMENTINFOS_BY_SPECIFIC_PROPERTY, \
63 HandleSearchElementInfoBySpecificProperty) \
64
65 namespace OHOS {
66 namespace Accessibility {
67 constexpr int32_t ERR_CODE_DEFAULT = -1000;
68
AccessibleAbilityChannelStub()69 AccessibleAbilityChannelStub::AccessibleAbilityChannelStub()
70 {
71 }
72
~AccessibleAbilityChannelStub()73 AccessibleAbilityChannelStub::~AccessibleAbilityChannelStub()
74 {
75 }
76
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)77 int AccessibleAbilityChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
78 MessageOption &option)
79 {
80 HILOG_DEBUG("cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
81 std::u16string descriptor = AccessibleAbilityChannelStub::GetDescriptor();
82 std::u16string remoteDescriptor = data.ReadInterfaceToken();
83 if (descriptor != remoteDescriptor) {
84 HILOG_INFO("local descriptor is not equal to remote");
85 return ERR_INVALID_STATE;
86 }
87
88 ErrCode result_code = ERR_NONE;
89 SWITCH_BEGIN(code)
90 ACCESSIBLE_ABILITY_CHANNEL_STUB_CASES()
91 SWITCH_END()
92
93 if (result_code != ERR_CODE_DEFAULT) {
94 return result_code;
95 }
96
97 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
98 }
99
HandleSearchElementInfoByAccessibilityId(MessageParcel & data,MessageParcel & reply)100 ErrCode AccessibleAbilityChannelStub::HandleSearchElementInfoByAccessibilityId(MessageParcel &data,
101 MessageParcel &reply)
102 {
103 HILOG_DEBUG();
104
105 ElementBasicInfo elementBasicInfo {};
106 elementBasicInfo.windowId = data.ReadInt32();
107 elementBasicInfo.treeId = data.ReadInt32();
108 elementBasicInfo.elementId = data.ReadInt64();
109 int32_t requestId = data.ReadInt32();
110
111 sptr<IRemoteObject> remote = data.ReadRemoteObject();
112 if (remote == nullptr) {
113 HILOG_ERROR("remote is nullptr.");
114 return ERR_INVALID_VALUE;
115 }
116 sptr<IAccessibilityElementOperatorCallback> callback =
117 iface_cast<IAccessibilityElementOperatorCallback>(remote);
118 if (callback == nullptr) {
119 HILOG_ERROR("callback is nullptr.");
120 return ERR_INVALID_VALUE;
121 }
122
123 int32_t mode = data.ReadInt32();
124 if (mode == PREFETCH_RECURSIVE_CHILDREN) {
125 if (!Permission::CheckCallingPermission(OHOS_PERMISSION_QUERY_ACCESSIBILITY_ELEMENT) &&
126 !Permission::CheckCallingPermission(OHOS_PERMISSION_ACCESSIBILITY_EXTENSION_ABILITY) &&
127 !Permission::IsStartByHdcd()) {
128 HILOG_ERROR("no get element permission");
129 reply.WriteInt32(RET_ERR_NO_CONNECTION);
130 return NO_ERROR;
131 }
132 }
133
134 if (mode == GET_SOURCE_MODE) {
135 mode = PREFETCH_RECURSIVE_CHILDREN;
136 }
137 bool isFilter = data.ReadBool();
138 bool systemApi = data.ReadBool();
139 RetError result = SearchElementInfoByAccessibilityId(elementBasicInfo, requestId, callback, mode,
140 isFilter, systemApi);
141 HILOG_DEBUG("SearchElementInfoByAccessibilityId ret = %{public}d", result);
142 reply.WriteInt32(result);
143
144 return NO_ERROR;
145 }
146
HandleSearchDefaultFocusedByWindowId(MessageParcel & data,MessageParcel & reply)147 ErrCode AccessibleAbilityChannelStub::HandleSearchDefaultFocusedByWindowId(MessageParcel &data,
148 MessageParcel &reply)
149 {
150 HILOG_DEBUG();
151
152 ElementBasicInfo elementBasicInfo {};
153 elementBasicInfo.windowId = data.ReadInt32();
154 elementBasicInfo.elementId = data.ReadInt64();
155 elementBasicInfo.treeId = data.ReadInt32();
156 int32_t requestId = data.ReadInt32();
157
158 sptr<IRemoteObject> remote = data.ReadRemoteObject();
159 if (remote == nullptr) {
160 HILOG_ERROR("remote is nullptr.");
161 return ERR_INVALID_VALUE;
162 }
163 sptr<IAccessibilityElementOperatorCallback> callback =
164 iface_cast<IAccessibilityElementOperatorCallback>(remote);
165 if (callback == nullptr) {
166 HILOG_ERROR("callback is nullptr.");
167 return ERR_INVALID_VALUE;
168 }
169
170 int32_t mode = data.ReadInt32();
171 if (mode == PREFETCH_RECURSIVE_CHILDREN) {
172 if (!Permission::CheckCallingPermission(OHOS_PERMISSION_QUERY_ACCESSIBILITY_ELEMENT) &&
173 !Permission::CheckCallingPermission(OHOS_PERMISSION_ACCESSIBILITY_EXTENSION_ABILITY) &&
174 !Permission::IsStartByHdcd()) {
175 HILOG_ERROR("no get element permission");
176 reply.WriteInt32(RET_ERR_NO_CONNECTION);
177 return NO_ERROR;
178 }
179 }
180
181 if (mode == GET_SOURCE_MODE) {
182 mode = PREFETCH_RECURSIVE_CHILDREN;
183 }
184 bool isFilter = data.ReadBool();
185 RetError result = SearchDefaultFocusedByWindowId(elementBasicInfo, requestId, callback, mode,
186 isFilter);
187 HILOG_DEBUG("SearchDefaultFocusedByWindowId ret = %{public}d", result);
188 reply.WriteInt32(result);
189
190 return NO_ERROR;
191 }
192
HandleSearchElementInfosByText(MessageParcel & data,MessageParcel & reply)193 ErrCode AccessibleAbilityChannelStub::HandleSearchElementInfosByText(MessageParcel &data,
194 MessageParcel &reply)
195 {
196 HILOG_DEBUG();
197
198 int32_t accessibilityWindowId = data.ReadInt32();
199 int64_t elementId = data.ReadInt64();
200 std::string text = data.ReadString();
201 int32_t requestId = data.ReadInt32();
202
203 sptr<IRemoteObject> remote = data.ReadRemoteObject();
204 if (remote == nullptr) {
205 HILOG_ERROR("remote is nullptr.");
206 return ERR_INVALID_VALUE;
207 }
208 sptr<IAccessibilityElementOperatorCallback> callback =
209 iface_cast<IAccessibilityElementOperatorCallback>(remote);
210 if (callback == nullptr) {
211 HILOG_ERROR("callback is nullptr.");
212 return ERR_INVALID_VALUE;
213 }
214 bool systemApi = data.ReadBool();
215 RetError result = SearchElementInfosByText(accessibilityWindowId, elementId, text, requestId, callback, systemApi);
216 HILOG_DEBUG("SearchElementInfosByText ret = %{public}d", result);
217 reply.WriteInt32(result);
218
219 return NO_ERROR;
220 }
221
HandleFindFocusedElementInfo(MessageParcel & data,MessageParcel & reply)222 ErrCode AccessibleAbilityChannelStub::HandleFindFocusedElementInfo(MessageParcel &data, MessageParcel &reply)
223 {
224 HILOG_DEBUG();
225
226 int32_t accessibilityWindowId = data.ReadInt32();
227 int64_t elementId = data.ReadInt64();
228 int32_t focusType = data.ReadInt32();
229 int32_t requestId = data.ReadInt32();
230
231 sptr<IRemoteObject> remote = data.ReadRemoteObject();
232 if (remote == nullptr) {
233 HILOG_ERROR("remote is nullptr.");
234 return ERR_INVALID_VALUE;
235 }
236 sptr<IAccessibilityElementOperatorCallback> callback =
237 iface_cast<IAccessibilityElementOperatorCallback>(remote);
238 if (callback == nullptr) {
239 HILOG_ERROR("callback is nullptr.");
240 return ERR_INVALID_VALUE;
241 }
242 bool systemApi = data.ReadBool();
243
244 RetError result =
245 FindFocusedElementInfo(accessibilityWindowId, elementId, focusType, requestId, callback, systemApi);
246 HILOG_DEBUG("FindFocusedElementInfo ret = %{public}d", result);
247 reply.WriteInt32(result);
248 return NO_ERROR;
249 }
250
HandleFocusMoveSearch(MessageParcel & data,MessageParcel & reply)251 ErrCode AccessibleAbilityChannelStub::HandleFocusMoveSearch(MessageParcel &data, MessageParcel &reply)
252 {
253 HILOG_DEBUG();
254
255 int32_t accessibilityWindowId = data.ReadInt32();
256 int64_t elementId = data.ReadInt64();
257 int32_t direction = data.ReadInt32();
258 int32_t requestId = data.ReadInt32();
259
260 sptr<IRemoteObject> remote = data.ReadRemoteObject();
261 if (remote == nullptr) {
262 HILOG_ERROR("remote is nullptr.");
263 return ERR_INVALID_VALUE;
264 }
265 sptr<IAccessibilityElementOperatorCallback> callback =
266 iface_cast<IAccessibilityElementOperatorCallback>(remote);
267 if (callback == nullptr) {
268 HILOG_ERROR("callback is nullptr.");
269 return ERR_INVALID_VALUE;
270 }
271 bool systemApi = data.ReadBool();
272
273 RetError result = FocusMoveSearch(accessibilityWindowId, elementId, direction, requestId, callback, systemApi);
274 HILOG_DEBUG("FocusMoveSearch ret = %{public}d", result);
275 reply.WriteInt32(result);
276
277 return NO_ERROR;
278 }
279
HandleExecuteAction(MessageParcel & data,MessageParcel & reply)280 ErrCode AccessibleAbilityChannelStub::HandleExecuteAction(MessageParcel &data, MessageParcel &reply)
281 {
282 HILOG_DEBUG();
283
284 int32_t accessibilityWindowId = data.ReadInt32();
285 int64_t elementId = data.ReadInt64();
286 int32_t action = data.ReadInt32();
287
288 std::vector<std::string> actionArgumentsKey;
289 std::vector<std::string> actionArgumentsValue;
290 std::map<std::string, std::string> actionArguments;
291
292 if (!data.ReadStringVector(&actionArgumentsKey)) {
293 HILOG_ERROR("ReadStringVector actionArgumentsKey failed");
294 return ERR_INVALID_VALUE;
295 }
296 if (!data.ReadStringVector(&actionArgumentsValue)) {
297 HILOG_ERROR("ReadStringVector actionArgumentsValue failed");
298 return ERR_INVALID_VALUE;
299 }
300 if (actionArgumentsKey.size() != actionArgumentsValue.size()) {
301 HILOG_ERROR("Read actionArguments failed.");
302 return ERR_INVALID_VALUE;
303 }
304 for (size_t i = 0; i < actionArgumentsKey.size(); i++) {
305 actionArguments.insert(make_pair(actionArgumentsKey[i], actionArgumentsValue[i]));
306 }
307
308 int32_t requestId = data.ReadInt32();
309
310 sptr<IRemoteObject> remote = data.ReadRemoteObject();
311 if (remote == nullptr) {
312 HILOG_ERROR("remote is nullptr.");
313 return ERR_INVALID_VALUE;
314 }
315
316 auto callback = iface_cast<IAccessibilityElementOperatorCallback>(remote);
317 if (callback == nullptr) {
318 HILOG_ERROR("callback is nullptr");
319 return ERR_INVALID_VALUE;
320 }
321
322 RetError result = ExecuteAction(accessibilityWindowId, elementId, action, actionArguments, requestId, callback);
323 HILOG_DEBUG("ExecuteAction ret = %{public}d", result);
324 reply.WriteInt32(result);
325 return NO_ERROR;
326 }
327
HandleEnableScreenCurtain(MessageParcel & data,MessageParcel & reply)328 ErrCode AccessibleAbilityChannelStub::HandleEnableScreenCurtain(MessageParcel &data, MessageParcel &reply)
329 {
330 HILOG_DEBUG();
331
332 if (!Permission::IsSystemApp()) {
333 HILOG_WARN("Not system app");
334 reply.WriteInt32(RET_ERR_NOT_SYSTEM_APP);
335 return NO_ERROR;
336 }
337
338 bool isEnable = data.ReadBool();
339 RetError result = EnableScreenCurtain(isEnable);
340 reply.WriteInt32(result);
341 return NO_ERROR;
342 }
343
HandleHoldRunningLock(MessageParcel & data,MessageParcel & reply)344 ErrCode AccessibleAbilityChannelStub::HandleHoldRunningLock(MessageParcel &data, MessageParcel &reply)
345 {
346 HILOG_DEBUG();
347
348 if (!Permission::IsSystemApp()) {
349 HILOG_WARN("Not system app");
350 reply.WriteInt32(RET_ERR_NOT_SYSTEM_APP);
351 return RET_ERR_NOT_SYSTEM_APP;
352 }
353
354 RetError result = HoldRunningLock();
355 reply.WriteInt32(result);
356 return NO_ERROR;
357 }
358
HandleUnholdRunningLock(MessageParcel & data,MessageParcel & reply)359 ErrCode AccessibleAbilityChannelStub::HandleUnholdRunningLock(MessageParcel &data, MessageParcel &reply)
360 {
361 HILOG_DEBUG();
362
363 if (!Permission::IsSystemApp()) {
364 HILOG_WARN("Not system app");
365 reply.WriteInt32(RET_ERR_NOT_SYSTEM_APP);
366 return RET_ERR_NOT_SYSTEM_APP;
367 }
368
369 RetError result = UnholdRunningLock();
370 reply.WriteInt32(result);
371 return NO_ERROR;
372 }
373
HandleGetCursorPosition(MessageParcel & data,MessageParcel & reply)374 ErrCode AccessibleAbilityChannelStub::HandleGetCursorPosition(MessageParcel &data, MessageParcel &reply)
375 {
376 HILOG_DEBUG();
377
378 int32_t accessibilityWindowId = data.ReadInt32();
379 int64_t elementId = data.ReadInt64();
380 int32_t requestId = data.ReadInt32();
381 HILOG_INFO("AccessibleAbilityChannelStub::HandleGetCursorPosition The execution was successful");
382 sptr<IRemoteObject> remote = data.ReadRemoteObject();
383 if (remote == nullptr) {
384 HILOG_ERROR("remote is nullptr.");
385 return ERR_INVALID_VALUE;
386 }
387 auto callback = iface_cast<IAccessibilityElementOperatorCallback>(remote);
388 if (callback == nullptr) {
389 HILOG_ERROR("callback is nullptr");
390 return ERR_INVALID_VALUE;
391 }
392
393 RetError result = GetCursorPosition(accessibilityWindowId, elementId, requestId, callback);
394 HILOG_DEBUG("GetCursorPosition ret = %{public}d", result);
395 reply.WriteInt32(result);
396 return NO_ERROR;
397 }
398
HandleGetWindow(MessageParcel & data,MessageParcel & reply)399 ErrCode AccessibleAbilityChannelStub::HandleGetWindow(MessageParcel &data, MessageParcel &reply)
400 {
401 HILOG_DEBUG();
402
403 int32_t windowId = data.ReadInt32();
404 sptr<AccessibilityWindowInfoParcel> windowInfoParcel = new(std::nothrow) AccessibilityWindowInfoParcel();
405 if (windowInfoParcel == nullptr) {
406 HILOG_ERROR("Failed to create windowInfoParcel.");
407 return ERR_NULL_OBJECT;
408 }
409
410 RetError result = GetWindow(windowId, *windowInfoParcel);
411 if (!reply.WriteStrongParcelable(windowInfoParcel)) {
412 HILOG_ERROR("WriteStrongParcelable windows failed");
413 return ERR_INVALID_VALUE;
414 }
415
416 reply.WriteInt32(result);
417 return NO_ERROR;
418 }
419
HandleGetWindows(MessageParcel & data,MessageParcel & reply)420 ErrCode AccessibleAbilityChannelStub::HandleGetWindows(MessageParcel &data, MessageParcel &reply)
421 {
422 HILOG_DEBUG();
423 bool systemApi = data.ReadBool();
424 std::vector<AccessibilityWindowInfo> windows;
425 RetError result = GetWindows(windows, systemApi);
426 if (!reply.WriteInt32(static_cast<int32_t>(windows.size()))) {
427 HILOG_ERROR("windows.size() write error: %{public}zu, ", windows.size());
428 return ERR_INVALID_VALUE;
429 }
430 for (auto &window : windows) {
431 sptr<AccessibilityWindowInfoParcel> windowInfo = new(std::nothrow) AccessibilityWindowInfoParcel(window);
432 if (windowInfo == nullptr) {
433 HILOG_ERROR("Failed to create windowInfo.");
434 return ERR_NULL_OBJECT;
435 }
436 if (!reply.WriteStrongParcelable(windowInfo)) {
437 HILOG_ERROR("WriteStrongParcelable windows failed");
438 return ERR_INVALID_VALUE;
439 }
440 }
441 reply.WriteInt32(result);
442 return NO_ERROR;
443 }
444
HandleGetWindowsByDisplayId(MessageParcel & data,MessageParcel & reply)445 ErrCode AccessibleAbilityChannelStub::HandleGetWindowsByDisplayId(MessageParcel &data, MessageParcel &reply)
446 {
447 HILOG_DEBUG();
448
449 uint64_t displayId = data.ReadUint64();
450 bool systemApi = data.ReadBool();
451 std::vector<AccessibilityWindowInfo> windows;
452 RetError result = GetWindowsByDisplayId(displayId, windows, systemApi);
453 if (!reply.WriteInt32(static_cast<int32_t>(windows.size()))) {
454 HILOG_ERROR("windows.size() write error: %{public}zu, ", windows.size());
455 return ERR_INVALID_VALUE;
456 }
457 for (auto &window : windows) {
458 sptr<AccessibilityWindowInfoParcel> windowInfo = new(std::nothrow) AccessibilityWindowInfoParcel(window);
459 if (windowInfo == nullptr) {
460 HILOG_ERROR("Failed to create windowInfo.");
461 return ERR_NULL_OBJECT;
462 }
463 if (!reply.WriteStrongParcelable(windowInfo)) {
464 HILOG_ERROR("WriteStrongParcelable windows failed");
465 return ERR_INVALID_VALUE;
466 }
467 }
468 reply.WriteInt32(result);
469 return NO_ERROR;
470 }
471
HandleSetOnKeyPressEventResult(MessageParcel & data,MessageParcel & reply)472 ErrCode AccessibleAbilityChannelStub::HandleSetOnKeyPressEventResult(MessageParcel &data, MessageParcel &reply)
473 {
474 HILOG_DEBUG();
475
476 bool handled = data.ReadBool();
477 int32_t sequence = data.ReadInt32();
478 SetOnKeyPressEventResult(handled, sequence);
479
480 return NO_ERROR;
481 }
482
HandleSendSimulateGesturePath(MessageParcel & data,MessageParcel & reply)483 ErrCode AccessibleAbilityChannelStub::HandleSendSimulateGesturePath(MessageParcel &data, MessageParcel &reply)
484 {
485 HILOG_DEBUG();
486
487 sptr<AccessibilityGestureInjectPathParcel> positions =
488 data.ReadStrongParcelable<AccessibilityGestureInjectPathParcel>();
489 if (positions == nullptr) {
490 HILOG_ERROR("ReadStrongParcelable<AccessibilityGestureInjectPathParcel> failed");
491 return ERR_INVALID_VALUE;
492 }
493
494 std::shared_ptr<AccessibilityGestureInjectPath> gesturePath =
495 std::make_shared<AccessibilityGestureInjectPath>(*positions);
496 RetError result = SendSimulateGesture(gesturePath);
497 reply.WriteInt32(result);
498 return NO_ERROR;
499 }
500
HandleSetTargetBundleName(MessageParcel & data,MessageParcel & reply)501 ErrCode AccessibleAbilityChannelStub::HandleSetTargetBundleName(MessageParcel &data, MessageParcel &reply)
502 {
503 HILOG_DEBUG();
504 std::vector<std::string> targetBundleNames;
505 int32_t size = data.ReadInt32();
506 bool verifyResult = ContainerSecurityVerify(data, size, targetBundleNames.max_size());
507 if (!verifyResult) {
508 return TRANSACTION_ERR;
509 }
510 if (size < 0 || size > MAX_ALLOW_SIZE) {
511 return TRANSACTION_ERR;
512 }
513 for (int32_t i = 0; i < size; i++) {
514 std::string temp = data.ReadString();
515 targetBundleNames.emplace_back(temp);
516 }
517 RetError result = SetTargetBundleName(targetBundleNames);
518 reply.WriteInt32(result);
519 return NO_ERROR;
520 }
521
HandleSetIsRegisterDisconnectCallback(MessageParcel & data,MessageParcel & reply)522 ErrCode AccessibleAbilityChannelStub::HandleSetIsRegisterDisconnectCallback(MessageParcel &data, MessageParcel &reply)
523 {
524 HILOG_DEBUG();
525
526 if (!Permission::IsSystemApp()) {
527 HILOG_WARN("Not system app");
528 reply.WriteInt32(RET_ERR_NOT_SYSTEM_APP);
529 return RET_ERR_NOT_SYSTEM_APP;
530 }
531
532 bool isRegister = data.ReadBool();
533 RetError result = SetIsRegisterDisconnectCallback(isRegister);
534 reply.WriteInt32(result);
535 return NO_ERROR;
536 }
537
HandleNotifyDisconnect(MessageParcel & data,MessageParcel & reply)538 ErrCode AccessibleAbilityChannelStub::HandleNotifyDisconnect(MessageParcel &data, MessageParcel &reply)
539 {
540 HILOG_DEBUG();
541
542 if (!Permission::IsSystemApp()) {
543 HILOG_WARN("Not system app");
544 reply.WriteInt32(RET_ERR_NOT_SYSTEM_APP);
545 return RET_ERR_NOT_SYSTEM_APP;
546 }
547
548 RetError result = NotifyDisconnect();
549 reply.WriteInt32(result);
550 return NO_ERROR;
551 }
552
HandleConfigureEvents(MessageParcel & data,MessageParcel & reply)553 ErrCode AccessibleAbilityChannelStub::HandleConfigureEvents(MessageParcel &data, MessageParcel &reply)
554 {
555 HILOG_DEBUG();
556 std::vector<uint32_t> needEvents;
557 uint32_t size = data.ReadUint32();
558 bool verifyResult = ContainerSecurityVerify(data, size, needEvents.max_size());
559 if (!verifyResult) {
560 return TRANSACTION_ERR;
561 }
562
563 if (size < 0 || size > MAX_ALLOW_SIZE) {
564 return TRANSACTION_ERR;
565 }
566
567 for (uint32_t i = 0; i < size; i++) {
568 uint32_t temp = data.ReadUint32();
569 needEvents.emplace_back(temp);
570 }
571 RetError result = ConfigureEvents(needEvents);
572 reply.WriteInt32(result);
573 return NO_ERROR;
574 }
575
HandleSearchElementInfoBySpecificProperty(MessageParcel & data,MessageParcel & reply)576 ErrCode AccessibleAbilityChannelStub::HandleSearchElementInfoBySpecificProperty(MessageParcel &data,
577 MessageParcel &reply)
578 {
579 HILOG_DEBUG();
580
581 ElementBasicInfo elementBasicInfo {};
582 elementBasicInfo.windowId = data.ReadInt32();
583 elementBasicInfo.elementId = data.ReadInt64();
584 elementBasicInfo.treeId = data.ReadInt32();
585
586 SpecificPropertyParam param;
587 param.propertyTarget = data.ReadString();
588 param.propertyType = static_cast<SEARCH_TYPE>(data.ReadUint32());
589
590 int32_t requestId = data.ReadInt32();
591
592 sptr<IRemoteObject> remote = data.ReadRemoteObject();
593 if (remote == nullptr) {
594 HILOG_ERROR("remote is nullptr.");
595 return ERR_INVALID_VALUE;
596 }
597 sptr<IAccessibilityElementOperatorCallback> callback =
598 iface_cast<IAccessibilityElementOperatorCallback>(remote);
599 if (callback == nullptr) {
600 HILOG_ERROR("callback is nullptr.");
601 return ERR_INVALID_VALUE;
602 }
603
604 SearchElementInfoBySpecificProperty(elementBasicInfo, param, requestId, callback);
605 RetError result = RET_OK;
606 HILOG_DEBUG("SearchElementInfosBySpecificProperty ret = %{public}d", result);
607 reply.WriteInt32(result);
608 return NO_ERROR;
609 }
610 } // namespace Accessibility
611 } // namespace OHOS