1885b47fbSopenharmony_ci/*
2885b47fbSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3885b47fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4885b47fbSopenharmony_ci * you may not use this file except in compliance with the License.
5885b47fbSopenharmony_ci * You may obtain a copy of the License at
6885b47fbSopenharmony_ci *
7885b47fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8885b47fbSopenharmony_ci *
9885b47fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10885b47fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11885b47fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12885b47fbSopenharmony_ci * See the License for the specific language governing permissions and
13885b47fbSopenharmony_ci * limitations under the License.
14885b47fbSopenharmony_ci */
15885b47fbSopenharmony_ci
16885b47fbSopenharmony_ci#include "accessible_ability_channel_stub.h"
17885b47fbSopenharmony_ci#include "accessibility_element_info_parcel.h"
18885b47fbSopenharmony_ci#include "accessibility_gesture_inject_path_parcel.h"
19885b47fbSopenharmony_ci#include "accessibility_ipc_interface_code.h"
20885b47fbSopenharmony_ci#include "accessibility_permission.h"
21885b47fbSopenharmony_ci#include "accessibility_window_info_parcel.h"
22885b47fbSopenharmony_ci#include "hilog_wrapper.h"
23885b47fbSopenharmony_ci#include "parcel_util.h"
24885b47fbSopenharmony_ci
25885b47fbSopenharmony_ci#define SWITCH_BEGIN(code) switch (code) {
26885b47fbSopenharmony_ci#define SWITCH_CASE(case_code, func)     \
27885b47fbSopenharmony_ci    case case_code: {                    \
28885b47fbSopenharmony_ci        result_code = func(data, reply); \
29885b47fbSopenharmony_ci        break;                           \
30885b47fbSopenharmony_ci    }
31885b47fbSopenharmony_ci
32885b47fbSopenharmony_ci#define SWITCH_END()                                                                            \
33885b47fbSopenharmony_ci    default: {                                                                                  \
34885b47fbSopenharmony_ci        result_code = ERR_CODE_DEFAULT;                                                         \
35885b47fbSopenharmony_ci        HILOG_WARN("AccessibleAbilityChannelStub::OnRemoteRequest, default case, need check."); \
36885b47fbSopenharmony_ci        break;                                                                                  \
37885b47fbSopenharmony_ci    }                                                                                           \
38885b47fbSopenharmony_ci}
39885b47fbSopenharmony_ci
40885b47fbSopenharmony_ci#define ACCESSIBLE_ABILITY_CHANNEL_STUB_CASES()                                                                       \
41885b47fbSopenharmony_ci    SWITCH_CASE(                                                                                                      \
42885b47fbSopenharmony_ci        AccessibilityInterfaceCode::SEARCH_ELEMENTINFO_BY_ACCESSIBILITY_ID, HandleSearchElementInfoByAccessibilityId) \
43885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::SEARCH_ELEMENTINFOS_BY_TEXT, HandleSearchElementInfosByText)              \
44885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::FIND_FOCUSED_ELEMENTINFO, HandleFindFocusedElementInfo)                   \
45885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::FOCUS_MOVE_SEARCH, HandleFocusMoveSearch)                                 \
46885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::PERFORM_ACTION, HandleExecuteAction)                                      \
47885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::SET_CURTAIN_SCREEN, HandleEnableScreenCurtain)                            \
48885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::GET_WINDOW, HandleGetWindow)                                              \
49885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::GET_WINDOWS, HandleGetWindows)                                            \
50885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::GET_WINDOWS_BY_DISPLAY_ID, HandleGetWindowsByDisplayId)                   \
51885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::SET_ON_KEY_PRESS_EVENT_RESULT, HandleSetOnKeyPressEventResult)            \
52885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::SEND_SIMULATE_GESTURE_PATH, HandleSendSimulateGesturePath)                \
53885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::SET_TARGET_BUNDLE_NAME, HandleSetTargetBundleName)                        \
54885b47fbSopenharmony_ci    SWITCH_CASE(AccessibilityInterfaceCode::GET_CURSOR_POSITION, HandleGetCursorPosition)
55885b47fbSopenharmony_ci
56885b47fbSopenharmony_cinamespace OHOS {
57885b47fbSopenharmony_cinamespace Accessibility {
58885b47fbSopenharmony_ciconstexpr int32_t ERR_CODE_DEFAULT = -1000;
59885b47fbSopenharmony_ci
60885b47fbSopenharmony_ciAccessibleAbilityChannelStub::AccessibleAbilityChannelStub()
61885b47fbSopenharmony_ci{
62885b47fbSopenharmony_ci}
63885b47fbSopenharmony_ci
64885b47fbSopenharmony_ciAccessibleAbilityChannelStub::~AccessibleAbilityChannelStub()
65885b47fbSopenharmony_ci{
66885b47fbSopenharmony_ci}
67885b47fbSopenharmony_ci
68885b47fbSopenharmony_ciint AccessibleAbilityChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
69885b47fbSopenharmony_ci    MessageOption &option)
70885b47fbSopenharmony_ci{
71885b47fbSopenharmony_ci    HILOG_DEBUG("cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
72885b47fbSopenharmony_ci    std::u16string descriptor = AccessibleAbilityChannelStub::GetDescriptor();
73885b47fbSopenharmony_ci    std::u16string remoteDescriptor = data.ReadInterfaceToken();
74885b47fbSopenharmony_ci    if (descriptor != remoteDescriptor) {
75885b47fbSopenharmony_ci        HILOG_INFO("local descriptor is not equal to remote");
76885b47fbSopenharmony_ci        return ERR_INVALID_STATE;
77885b47fbSopenharmony_ci    }
78885b47fbSopenharmony_ci
79885b47fbSopenharmony_ci    ErrCode result_code = ERR_NONE;
80885b47fbSopenharmony_ci    SWITCH_BEGIN(code)
81885b47fbSopenharmony_ci    ACCESSIBLE_ABILITY_CHANNEL_STUB_CASES()
82885b47fbSopenharmony_ci    SWITCH_END()
83885b47fbSopenharmony_ci
84885b47fbSopenharmony_ci    if (result_code != ERR_CODE_DEFAULT) {
85885b47fbSopenharmony_ci        return result_code;
86885b47fbSopenharmony_ci    }
87885b47fbSopenharmony_ci
88885b47fbSopenharmony_ci    return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
89885b47fbSopenharmony_ci}
90885b47fbSopenharmony_ci
91885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleSearchElementInfoByAccessibilityId(MessageParcel &data,
92885b47fbSopenharmony_ci    MessageParcel &reply)
93885b47fbSopenharmony_ci{
94885b47fbSopenharmony_ci    HILOG_DEBUG();
95885b47fbSopenharmony_ci
96885b47fbSopenharmony_ci    ElementBasicInfo elementBasicInfo {};
97885b47fbSopenharmony_ci    elementBasicInfo.windowId = data.ReadInt32();
98885b47fbSopenharmony_ci    elementBasicInfo.treeId = data.ReadInt32();
99885b47fbSopenharmony_ci    elementBasicInfo.elementId = data.ReadInt64();
100885b47fbSopenharmony_ci    int32_t requestId = data.ReadInt32();
101885b47fbSopenharmony_ci
102885b47fbSopenharmony_ci    sptr<IRemoteObject> remote = data.ReadRemoteObject();
103885b47fbSopenharmony_ci    if (remote == nullptr) {
104885b47fbSopenharmony_ci        HILOG_ERROR("remote is nullptr.");
105885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
106885b47fbSopenharmony_ci    }
107885b47fbSopenharmony_ci    sptr<IAccessibilityElementOperatorCallback> callback =
108885b47fbSopenharmony_ci        iface_cast<IAccessibilityElementOperatorCallback>(remote);
109885b47fbSopenharmony_ci    if (callback == nullptr) {
110885b47fbSopenharmony_ci        HILOG_ERROR("callback is nullptr.");
111885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
112885b47fbSopenharmony_ci    }
113885b47fbSopenharmony_ci
114885b47fbSopenharmony_ci    int32_t mode = data.ReadInt32();
115885b47fbSopenharmony_ci    if (mode == PREFETCH_RECURSIVE_CHILDREN) {
116885b47fbSopenharmony_ci        if (!Permission::CheckCallingPermission(OHOS_PERMISSION_QUERY_ACCESSIBILITY_ELEMENT) &&
117885b47fbSopenharmony_ci            !Permission::IsStartByHdcd()) {
118885b47fbSopenharmony_ci            HILOG_ERROR("no get element permission");
119885b47fbSopenharmony_ci            reply.WriteInt32(RET_ERR_NO_CONNECTION);
120885b47fbSopenharmony_ci            return NO_ERROR;
121885b47fbSopenharmony_ci        }
122885b47fbSopenharmony_ci    }
123885b47fbSopenharmony_ci
124885b47fbSopenharmony_ci    if (mode == GET_SOURCE_MODE) {
125885b47fbSopenharmony_ci        mode = PREFETCH_RECURSIVE_CHILDREN;
126885b47fbSopenharmony_ci    }
127885b47fbSopenharmony_ci    bool isFilter = data.ReadBool();
128885b47fbSopenharmony_ci    RetError result = SearchElementInfoByAccessibilityId(elementBasicInfo, requestId, callback, mode,
129885b47fbSopenharmony_ci        isFilter);
130885b47fbSopenharmony_ci    HILOG_DEBUG("SearchElementInfoByAccessibilityId ret = %{public}d", result);
131885b47fbSopenharmony_ci    reply.WriteInt32(result);
132885b47fbSopenharmony_ci
133885b47fbSopenharmony_ci    return NO_ERROR;
134885b47fbSopenharmony_ci}
135885b47fbSopenharmony_ci
136885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleSearchElementInfosByText(MessageParcel &data,
137885b47fbSopenharmony_ci    MessageParcel &reply)
138885b47fbSopenharmony_ci{
139885b47fbSopenharmony_ci    HILOG_DEBUG();
140885b47fbSopenharmony_ci
141885b47fbSopenharmony_ci    int32_t accessibilityWindowId = data.ReadInt32();
142885b47fbSopenharmony_ci    int64_t elementId = data.ReadInt64();
143885b47fbSopenharmony_ci    std::string text = data.ReadString();
144885b47fbSopenharmony_ci    int32_t requestId = data.ReadInt32();
145885b47fbSopenharmony_ci
146885b47fbSopenharmony_ci    sptr<IRemoteObject> remote = data.ReadRemoteObject();
147885b47fbSopenharmony_ci    if (remote == nullptr) {
148885b47fbSopenharmony_ci        HILOG_ERROR("remote is nullptr.");
149885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
150885b47fbSopenharmony_ci    }
151885b47fbSopenharmony_ci    sptr<IAccessibilityElementOperatorCallback> callback =
152885b47fbSopenharmony_ci        iface_cast<IAccessibilityElementOperatorCallback>(remote);
153885b47fbSopenharmony_ci    if (callback == nullptr) {
154885b47fbSopenharmony_ci        HILOG_ERROR("callback is nullptr.");
155885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
156885b47fbSopenharmony_ci    }
157885b47fbSopenharmony_ci
158885b47fbSopenharmony_ci    RetError result = SearchElementInfosByText(accessibilityWindowId, elementId, text, requestId, callback);
159885b47fbSopenharmony_ci    HILOG_DEBUG("SearchElementInfosByText ret = %{public}d", result);
160885b47fbSopenharmony_ci    reply.WriteInt32(result);
161885b47fbSopenharmony_ci
162885b47fbSopenharmony_ci    return NO_ERROR;
163885b47fbSopenharmony_ci}
164885b47fbSopenharmony_ci
165885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleFindFocusedElementInfo(MessageParcel &data, MessageParcel &reply)
166885b47fbSopenharmony_ci{
167885b47fbSopenharmony_ci    HILOG_DEBUG();
168885b47fbSopenharmony_ci
169885b47fbSopenharmony_ci    int32_t accessibilityWindowId = data.ReadInt32();
170885b47fbSopenharmony_ci    int64_t elementId = data.ReadInt64();
171885b47fbSopenharmony_ci    int32_t focusType = data.ReadInt32();
172885b47fbSopenharmony_ci    int32_t requestId = data.ReadInt32();
173885b47fbSopenharmony_ci
174885b47fbSopenharmony_ci    sptr<IRemoteObject> remote = data.ReadRemoteObject();
175885b47fbSopenharmony_ci    if (remote == nullptr) {
176885b47fbSopenharmony_ci        HILOG_ERROR("remote is nullptr.");
177885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
178885b47fbSopenharmony_ci    }
179885b47fbSopenharmony_ci    sptr<IAccessibilityElementOperatorCallback> callback =
180885b47fbSopenharmony_ci        iface_cast<IAccessibilityElementOperatorCallback>(remote);
181885b47fbSopenharmony_ci    if (callback == nullptr) {
182885b47fbSopenharmony_ci        HILOG_ERROR("callback is nullptr.");
183885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
184885b47fbSopenharmony_ci    }
185885b47fbSopenharmony_ci
186885b47fbSopenharmony_ci    RetError result = FindFocusedElementInfo(accessibilityWindowId, elementId, focusType, requestId, callback);
187885b47fbSopenharmony_ci    HILOG_DEBUG("FindFocusedElementInfo ret = %{public}d", result);
188885b47fbSopenharmony_ci    reply.WriteInt32(result);
189885b47fbSopenharmony_ci    return NO_ERROR;
190885b47fbSopenharmony_ci}
191885b47fbSopenharmony_ci
192885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleFocusMoveSearch(MessageParcel &data, MessageParcel &reply)
193885b47fbSopenharmony_ci{
194885b47fbSopenharmony_ci    HILOG_DEBUG();
195885b47fbSopenharmony_ci
196885b47fbSopenharmony_ci    int32_t accessibilityWindowId = data.ReadInt32();
197885b47fbSopenharmony_ci    int64_t elementId = data.ReadInt64();
198885b47fbSopenharmony_ci    int32_t direction = data.ReadInt32();
199885b47fbSopenharmony_ci    int32_t requestId = data.ReadInt32();
200885b47fbSopenharmony_ci
201885b47fbSopenharmony_ci    sptr<IRemoteObject> remote = data.ReadRemoteObject();
202885b47fbSopenharmony_ci    if (remote == nullptr) {
203885b47fbSopenharmony_ci        HILOG_ERROR("remote is nullptr.");
204885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
205885b47fbSopenharmony_ci    }
206885b47fbSopenharmony_ci    sptr<IAccessibilityElementOperatorCallback> callback =
207885b47fbSopenharmony_ci        iface_cast<IAccessibilityElementOperatorCallback>(remote);
208885b47fbSopenharmony_ci    if (callback == nullptr) {
209885b47fbSopenharmony_ci        HILOG_ERROR("callback is nullptr.");
210885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
211885b47fbSopenharmony_ci    }
212885b47fbSopenharmony_ci
213885b47fbSopenharmony_ci    RetError result = FocusMoveSearch(accessibilityWindowId, elementId, direction, requestId, callback);
214885b47fbSopenharmony_ci    HILOG_DEBUG("FocusMoveSearch ret = %{public}d", result);
215885b47fbSopenharmony_ci    reply.WriteInt32(result);
216885b47fbSopenharmony_ci
217885b47fbSopenharmony_ci    return NO_ERROR;
218885b47fbSopenharmony_ci}
219885b47fbSopenharmony_ci
220885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleExecuteAction(MessageParcel &data, MessageParcel &reply)
221885b47fbSopenharmony_ci{
222885b47fbSopenharmony_ci    HILOG_DEBUG();
223885b47fbSopenharmony_ci
224885b47fbSopenharmony_ci    int32_t accessibilityWindowId = data.ReadInt32();
225885b47fbSopenharmony_ci    int64_t elementId = data.ReadInt64();
226885b47fbSopenharmony_ci    int32_t action = data.ReadInt32();
227885b47fbSopenharmony_ci
228885b47fbSopenharmony_ci    std::vector<std::string> actionArgumentsKey;
229885b47fbSopenharmony_ci    std::vector<std::string> actionArgumentsValue;
230885b47fbSopenharmony_ci    std::map<std::string, std::string> actionArguments;
231885b47fbSopenharmony_ci
232885b47fbSopenharmony_ci    if (!data.ReadStringVector(&actionArgumentsKey)) {
233885b47fbSopenharmony_ci        HILOG_ERROR("ReadStringVector actionArgumentsKey failed");
234885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
235885b47fbSopenharmony_ci    }
236885b47fbSopenharmony_ci    if (!data.ReadStringVector(&actionArgumentsValue)) {
237885b47fbSopenharmony_ci        HILOG_ERROR("ReadStringVector actionArgumentsValue failed");
238885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
239885b47fbSopenharmony_ci    }
240885b47fbSopenharmony_ci    if (actionArgumentsKey.size() != actionArgumentsValue.size()) {
241885b47fbSopenharmony_ci        HILOG_ERROR("Read actionArguments failed.");
242885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
243885b47fbSopenharmony_ci    }
244885b47fbSopenharmony_ci    for (size_t i = 0; i < actionArgumentsKey.size(); i++) {
245885b47fbSopenharmony_ci        actionArguments.insert(make_pair(actionArgumentsKey[i], actionArgumentsValue[i]));
246885b47fbSopenharmony_ci    }
247885b47fbSopenharmony_ci
248885b47fbSopenharmony_ci    int32_t requestId = data.ReadInt32();
249885b47fbSopenharmony_ci
250885b47fbSopenharmony_ci    sptr<IRemoteObject> remote = data.ReadRemoteObject();
251885b47fbSopenharmony_ci    if (remote == nullptr) {
252885b47fbSopenharmony_ci        HILOG_ERROR("remote is nullptr.");
253885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
254885b47fbSopenharmony_ci    }
255885b47fbSopenharmony_ci
256885b47fbSopenharmony_ci    auto callback = iface_cast<IAccessibilityElementOperatorCallback>(remote);
257885b47fbSopenharmony_ci    if (callback == nullptr) {
258885b47fbSopenharmony_ci        HILOG_ERROR("callback is nullptr");
259885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
260885b47fbSopenharmony_ci    }
261885b47fbSopenharmony_ci
262885b47fbSopenharmony_ci    RetError result = ExecuteAction(accessibilityWindowId, elementId, action, actionArguments, requestId, callback);
263885b47fbSopenharmony_ci    HILOG_DEBUG("ExecuteAction ret = %{public}d", result);
264885b47fbSopenharmony_ci    reply.WriteInt32(result);
265885b47fbSopenharmony_ci    return NO_ERROR;
266885b47fbSopenharmony_ci}
267885b47fbSopenharmony_ci
268885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleEnableScreenCurtain(MessageParcel &data, MessageParcel &reply)
269885b47fbSopenharmony_ci{
270885b47fbSopenharmony_ci    HILOG_DEBUG();
271885b47fbSopenharmony_ci
272885b47fbSopenharmony_ci    if (!Permission::IsSystemApp()) {
273885b47fbSopenharmony_ci        HILOG_WARN("Not system app");
274885b47fbSopenharmony_ci        reply.WriteInt32(RET_ERR_NOT_SYSTEM_APP);
275885b47fbSopenharmony_ci        return NO_ERROR;
276885b47fbSopenharmony_ci    }
277885b47fbSopenharmony_ci
278885b47fbSopenharmony_ci    bool isEnable = data.ReadBool();
279885b47fbSopenharmony_ci    RetError result = EnableScreenCurtain(isEnable);
280885b47fbSopenharmony_ci    reply.WriteInt32(result);
281885b47fbSopenharmony_ci    return NO_ERROR;
282885b47fbSopenharmony_ci}
283885b47fbSopenharmony_ci
284885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleGetCursorPosition(MessageParcel &data, MessageParcel &reply)
285885b47fbSopenharmony_ci{
286885b47fbSopenharmony_ci    HILOG_DEBUG();
287885b47fbSopenharmony_ci
288885b47fbSopenharmony_ci    int32_t accessibilityWindowId = data.ReadInt32();
289885b47fbSopenharmony_ci    int64_t elementId = data.ReadInt64();
290885b47fbSopenharmony_ci    int32_t requestId = data.ReadInt32();
291885b47fbSopenharmony_ci    HILOG_INFO("AccessibleAbilityChannelStub::HandleGetCursorPosition   The execution was successful");
292885b47fbSopenharmony_ci    sptr<IRemoteObject> remote = data.ReadRemoteObject();
293885b47fbSopenharmony_ci    if (remote == nullptr) {
294885b47fbSopenharmony_ci        HILOG_ERROR("remote is nullptr.");
295885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
296885b47fbSopenharmony_ci    }
297885b47fbSopenharmony_ci    auto callback = iface_cast<IAccessibilityElementOperatorCallback>(remote);
298885b47fbSopenharmony_ci    if (callback == nullptr) {
299885b47fbSopenharmony_ci        HILOG_ERROR("callback is nullptr");
300885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
301885b47fbSopenharmony_ci    }
302885b47fbSopenharmony_ci
303885b47fbSopenharmony_ci    RetError result = GetCursorPosition(accessibilityWindowId, elementId, requestId, callback);
304885b47fbSopenharmony_ci    HILOG_DEBUG("GetCursorPosition ret = %{public}d", result);
305885b47fbSopenharmony_ci    reply.WriteInt32(result);
306885b47fbSopenharmony_ci    return NO_ERROR;
307885b47fbSopenharmony_ci}
308885b47fbSopenharmony_ci
309885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleGetWindow(MessageParcel &data, MessageParcel &reply)
310885b47fbSopenharmony_ci{
311885b47fbSopenharmony_ci    HILOG_DEBUG();
312885b47fbSopenharmony_ci
313885b47fbSopenharmony_ci    int32_t windowId = data.ReadInt32();
314885b47fbSopenharmony_ci    sptr<AccessibilityWindowInfoParcel> windowInfoParcel = new(std::nothrow) AccessibilityWindowInfoParcel();
315885b47fbSopenharmony_ci    if (windowInfoParcel == nullptr) {
316885b47fbSopenharmony_ci        HILOG_ERROR("Failed to create windowInfoParcel.");
317885b47fbSopenharmony_ci        return ERR_NULL_OBJECT;
318885b47fbSopenharmony_ci    }
319885b47fbSopenharmony_ci
320885b47fbSopenharmony_ci    RetError result = GetWindow(windowId, *windowInfoParcel);
321885b47fbSopenharmony_ci    if (!reply.WriteStrongParcelable(windowInfoParcel)) {
322885b47fbSopenharmony_ci        HILOG_ERROR("WriteStrongParcelable windows failed");
323885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
324885b47fbSopenharmony_ci    }
325885b47fbSopenharmony_ci
326885b47fbSopenharmony_ci    reply.WriteInt32(result);
327885b47fbSopenharmony_ci    return NO_ERROR;
328885b47fbSopenharmony_ci}
329885b47fbSopenharmony_ci
330885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleGetWindows(MessageParcel &data, MessageParcel &reply)
331885b47fbSopenharmony_ci{
332885b47fbSopenharmony_ci    HILOG_DEBUG();
333885b47fbSopenharmony_ci    std::vector<AccessibilityWindowInfo> windows;
334885b47fbSopenharmony_ci    RetError result = GetWindows(windows);
335885b47fbSopenharmony_ci    if (!reply.WriteInt32(static_cast<int32_t>(windows.size()))) {
336885b47fbSopenharmony_ci        HILOG_ERROR("windows.size() write error: %{public}zu, ", windows.size());
337885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
338885b47fbSopenharmony_ci    }
339885b47fbSopenharmony_ci    for (auto &window : windows) {
340885b47fbSopenharmony_ci        sptr<AccessibilityWindowInfoParcel> windowInfo = new(std::nothrow) AccessibilityWindowInfoParcel(window);
341885b47fbSopenharmony_ci        if (windowInfo == nullptr) {
342885b47fbSopenharmony_ci            HILOG_ERROR("Failed to create windowInfo.");
343885b47fbSopenharmony_ci            return ERR_NULL_OBJECT;
344885b47fbSopenharmony_ci        }
345885b47fbSopenharmony_ci        if (!reply.WriteStrongParcelable(windowInfo)) {
346885b47fbSopenharmony_ci            HILOG_ERROR("WriteStrongParcelable windows failed");
347885b47fbSopenharmony_ci            return ERR_INVALID_VALUE;
348885b47fbSopenharmony_ci        }
349885b47fbSopenharmony_ci    }
350885b47fbSopenharmony_ci    reply.WriteInt32(result);
351885b47fbSopenharmony_ci    return NO_ERROR;
352885b47fbSopenharmony_ci}
353885b47fbSopenharmony_ci
354885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleGetWindowsByDisplayId(MessageParcel &data, MessageParcel &reply)
355885b47fbSopenharmony_ci{
356885b47fbSopenharmony_ci    HILOG_DEBUG();
357885b47fbSopenharmony_ci
358885b47fbSopenharmony_ci    uint64_t displayId = data.ReadUint64();
359885b47fbSopenharmony_ci    std::vector<AccessibilityWindowInfo> windows;
360885b47fbSopenharmony_ci    RetError result = GetWindowsByDisplayId(displayId, windows);
361885b47fbSopenharmony_ci    if (!reply.WriteInt32(static_cast<int32_t>(windows.size()))) {
362885b47fbSopenharmony_ci        HILOG_ERROR("windows.size() write error: %{public}zu, ", windows.size());
363885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
364885b47fbSopenharmony_ci    }
365885b47fbSopenharmony_ci    for (auto &window : windows) {
366885b47fbSopenharmony_ci        sptr<AccessibilityWindowInfoParcel> windowInfo = new(std::nothrow) AccessibilityWindowInfoParcel(window);
367885b47fbSopenharmony_ci        if (windowInfo == nullptr) {
368885b47fbSopenharmony_ci            HILOG_ERROR("Failed to create windowInfo.");
369885b47fbSopenharmony_ci            return ERR_NULL_OBJECT;
370885b47fbSopenharmony_ci        }
371885b47fbSopenharmony_ci        if (!reply.WriteStrongParcelable(windowInfo)) {
372885b47fbSopenharmony_ci            HILOG_ERROR("WriteStrongParcelable windows failed");
373885b47fbSopenharmony_ci            return ERR_INVALID_VALUE;
374885b47fbSopenharmony_ci        }
375885b47fbSopenharmony_ci    }
376885b47fbSopenharmony_ci    reply.WriteInt32(result);
377885b47fbSopenharmony_ci    return NO_ERROR;
378885b47fbSopenharmony_ci}
379885b47fbSopenharmony_ci
380885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleSetOnKeyPressEventResult(MessageParcel &data, MessageParcel &reply)
381885b47fbSopenharmony_ci{
382885b47fbSopenharmony_ci    HILOG_DEBUG();
383885b47fbSopenharmony_ci
384885b47fbSopenharmony_ci    bool handled = data.ReadBool();
385885b47fbSopenharmony_ci    int32_t sequence = data.ReadInt32();
386885b47fbSopenharmony_ci    SetOnKeyPressEventResult(handled, sequence);
387885b47fbSopenharmony_ci
388885b47fbSopenharmony_ci    return NO_ERROR;
389885b47fbSopenharmony_ci}
390885b47fbSopenharmony_ci
391885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleSendSimulateGesturePath(MessageParcel &data, MessageParcel &reply)
392885b47fbSopenharmony_ci{
393885b47fbSopenharmony_ci    HILOG_DEBUG();
394885b47fbSopenharmony_ci
395885b47fbSopenharmony_ci    sptr<AccessibilityGestureInjectPathParcel> positions =
396885b47fbSopenharmony_ci        data.ReadStrongParcelable<AccessibilityGestureInjectPathParcel>();
397885b47fbSopenharmony_ci    if (positions == nullptr) {
398885b47fbSopenharmony_ci        HILOG_ERROR("ReadStrongParcelable<AccessibilityGestureInjectPathParcel> failed");
399885b47fbSopenharmony_ci        return ERR_INVALID_VALUE;
400885b47fbSopenharmony_ci    }
401885b47fbSopenharmony_ci
402885b47fbSopenharmony_ci    std::shared_ptr<AccessibilityGestureInjectPath> gesturePath =
403885b47fbSopenharmony_ci        std::make_shared<AccessibilityGestureInjectPath>(*positions);
404885b47fbSopenharmony_ci    RetError result = SendSimulateGesture(gesturePath);
405885b47fbSopenharmony_ci    reply.WriteInt32(result);
406885b47fbSopenharmony_ci    return NO_ERROR;
407885b47fbSopenharmony_ci}
408885b47fbSopenharmony_ci
409885b47fbSopenharmony_ciErrCode AccessibleAbilityChannelStub::HandleSetTargetBundleName(MessageParcel &data, MessageParcel &reply)
410885b47fbSopenharmony_ci{
411885b47fbSopenharmony_ci    HILOG_DEBUG();
412885b47fbSopenharmony_ci    std::vector<std::string> targetBundleNames;
413885b47fbSopenharmony_ci    int32_t size = data.ReadInt32();
414885b47fbSopenharmony_ci    bool verifyResult = ContainerSecurityVerify(data, size, targetBundleNames.max_size());
415885b47fbSopenharmony_ci    if (!verifyResult || size < 0 || size > INT32_MAX) {
416885b47fbSopenharmony_ci        return TRANSACTION_ERR;
417885b47fbSopenharmony_ci    }
418885b47fbSopenharmony_ci    for (int32_t i = 0; i < size; i++) {
419885b47fbSopenharmony_ci        std::string temp = data.ReadString();
420885b47fbSopenharmony_ci        targetBundleNames.emplace_back(temp);
421885b47fbSopenharmony_ci    }
422885b47fbSopenharmony_ci    RetError result = SetTargetBundleName(targetBundleNames);
423885b47fbSopenharmony_ci    reply.WriteInt32(result);
424885b47fbSopenharmony_ci    return NO_ERROR;
425885b47fbSopenharmony_ci}
426885b47fbSopenharmony_ci} // namespace Accessibility
427885b47fbSopenharmony_ci} // namespace OHOS