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_proxy.h" 17885b47fbSopenharmony_ci 18885b47fbSopenharmony_ci#include <cinttypes> 19885b47fbSopenharmony_ci 20885b47fbSopenharmony_ci#include "accessibility_element_info_parcel.h" 21885b47fbSopenharmony_ci#include "accessibility_gesture_inject_path_parcel.h" 22885b47fbSopenharmony_ci#include "accessibility_ipc_interface_code.h" 23885b47fbSopenharmony_ci#include "accessibility_window_info_parcel.h" 24885b47fbSopenharmony_ci#include "hilog_wrapper.h" 25885b47fbSopenharmony_ci 26885b47fbSopenharmony_cinamespace OHOS { 27885b47fbSopenharmony_cinamespace Accessibility { 28885b47fbSopenharmony_ciAccessibleAbilityChannelProxy::AccessibleAbilityChannelProxy( 29885b47fbSopenharmony_ci const sptr<IRemoteObject> &object): IRemoteProxy<IAccessibleAbilityChannel>(object) 30885b47fbSopenharmony_ci{ 31885b47fbSopenharmony_ci} 32885b47fbSopenharmony_ci 33885b47fbSopenharmony_cibool AccessibleAbilityChannelProxy::WriteInterfaceToken(MessageParcel &data) 34885b47fbSopenharmony_ci{ 35885b47fbSopenharmony_ci HILOG_DEBUG(); 36885b47fbSopenharmony_ci 37885b47fbSopenharmony_ci if (!data.WriteInterfaceToken(AccessibleAbilityChannelProxy::GetDescriptor())) { 38885b47fbSopenharmony_ci HILOG_ERROR("write interface token failed"); 39885b47fbSopenharmony_ci return false; 40885b47fbSopenharmony_ci } 41885b47fbSopenharmony_ci return true; 42885b47fbSopenharmony_ci} 43885b47fbSopenharmony_ci 44885b47fbSopenharmony_cibool AccessibleAbilityChannelProxy::SendTransactCmd(AccessibilityInterfaceCode code, 45885b47fbSopenharmony_ci MessageParcel &data, MessageParcel &reply, MessageOption &option) 46885b47fbSopenharmony_ci{ 47885b47fbSopenharmony_ci HILOG_DEBUG(); 48885b47fbSopenharmony_ci 49885b47fbSopenharmony_ci sptr<IRemoteObject> remoteChannelProxy = Remote(); 50885b47fbSopenharmony_ci if (remoteChannelProxy == nullptr) { 51885b47fbSopenharmony_ci HILOG_ERROR("fail to send transact cmd %{public}d due to remote object", code); 52885b47fbSopenharmony_ci return false; 53885b47fbSopenharmony_ci } 54885b47fbSopenharmony_ci int32_t resultChannelProxy = remoteChannelProxy->SendRequest(static_cast<uint32_t>(code), data, reply, option); 55885b47fbSopenharmony_ci if (resultChannelProxy != NO_ERROR) { 56885b47fbSopenharmony_ci HILOG_ERROR("receive error transact code %{public}d in transact cmd %{public}d", resultChannelProxy, code); 57885b47fbSopenharmony_ci return false; 58885b47fbSopenharmony_ci } 59885b47fbSopenharmony_ci return true; 60885b47fbSopenharmony_ci} 61885b47fbSopenharmony_ci 62885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::SearchElementInfoByAccessibilityId(const ElementBasicInfo elementBasicInfo, 63885b47fbSopenharmony_ci const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback, 64885b47fbSopenharmony_ci const int32_t mode, bool isFilter) 65885b47fbSopenharmony_ci{ 66885b47fbSopenharmony_ci HILOG_DEBUG(); 67885b47fbSopenharmony_ci if (callback == nullptr) { 68885b47fbSopenharmony_ci HILOG_ERROR("callback is nullptr."); 69885b47fbSopenharmony_ci return RET_ERR_INVALID_PARAM; 70885b47fbSopenharmony_ci } 71885b47fbSopenharmony_ci 72885b47fbSopenharmony_ci MessageParcel data; 73885b47fbSopenharmony_ci MessageParcel reply; 74885b47fbSopenharmony_ci MessageOption option; 75885b47fbSopenharmony_ci 76885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 77885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 78885b47fbSopenharmony_ci } 79885b47fbSopenharmony_ci if (!data.WriteInt32(elementBasicInfo.windowId)) { 80885b47fbSopenharmony_ci HILOG_ERROR("windowId write error: %{public}d, ", elementBasicInfo.windowId); 81885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 82885b47fbSopenharmony_ci } 83885b47fbSopenharmony_ci if (!data.WriteInt32(elementBasicInfo.treeId)) { 84885b47fbSopenharmony_ci HILOG_ERROR("treeId write error: %{public}d", elementBasicInfo.treeId); 85885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 86885b47fbSopenharmony_ci } 87885b47fbSopenharmony_ci if (!data.WriteInt64(elementBasicInfo.elementId)) { 88885b47fbSopenharmony_ci HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementBasicInfo.elementId); 89885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 90885b47fbSopenharmony_ci } 91885b47fbSopenharmony_ci if (!data.WriteInt32(requestId)) { 92885b47fbSopenharmony_ci HILOG_ERROR("requestId write error: %{public}d, ", requestId); 93885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 94885b47fbSopenharmony_ci } 95885b47fbSopenharmony_ci if (!data.WriteRemoteObject(callback->AsObject())) { 96885b47fbSopenharmony_ci HILOG_ERROR("callback write error"); 97885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 98885b47fbSopenharmony_ci } 99885b47fbSopenharmony_ci if (!data.WriteInt32(mode)) { 100885b47fbSopenharmony_ci HILOG_ERROR("mode write error: %{public}d, ", mode); 101885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 102885b47fbSopenharmony_ci } 103885b47fbSopenharmony_ci if (!data.WriteBool(isFilter)) { 104885b47fbSopenharmony_ci HILOG_ERROR("isFilter write error: %{public}d, ", isFilter); 105885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 106885b47fbSopenharmony_ci } 107885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::SEARCH_ELEMENTINFO_BY_ACCESSIBILITY_ID, 108885b47fbSopenharmony_ci data, reply, option)) { 109885b47fbSopenharmony_ci HILOG_ERROR("fail to find elementInfo by elementId"); 110885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 111885b47fbSopenharmony_ci } 112885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 113885b47fbSopenharmony_ci} 114885b47fbSopenharmony_ci 115885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::SearchElementInfosByText(const int32_t accessibilityWindowId, 116885b47fbSopenharmony_ci const int64_t elementId, const std::string &text, const int32_t requestId, 117885b47fbSopenharmony_ci const sptr<IAccessibilityElementOperatorCallback> &callback) 118885b47fbSopenharmony_ci{ 119885b47fbSopenharmony_ci HILOG_DEBUG(); 120885b47fbSopenharmony_ci 121885b47fbSopenharmony_ci if (callback == nullptr) { 122885b47fbSopenharmony_ci HILOG_ERROR("callback is nullptr."); 123885b47fbSopenharmony_ci return RET_ERR_INVALID_PARAM; 124885b47fbSopenharmony_ci } 125885b47fbSopenharmony_ci 126885b47fbSopenharmony_ci MessageParcel data; 127885b47fbSopenharmony_ci MessageParcel reply; 128885b47fbSopenharmony_ci MessageOption option; 129885b47fbSopenharmony_ci 130885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 131885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 132885b47fbSopenharmony_ci } 133885b47fbSopenharmony_ci if (!data.WriteInt32(accessibilityWindowId)) { 134885b47fbSopenharmony_ci HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); 135885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 136885b47fbSopenharmony_ci } 137885b47fbSopenharmony_ci if (!data.WriteInt64(elementId)) { 138885b47fbSopenharmony_ci HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId); 139885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 140885b47fbSopenharmony_ci } 141885b47fbSopenharmony_ci if (!data.WriteString(text)) { 142885b47fbSopenharmony_ci HILOG_ERROR("text write error: %{public}s, ", text.c_str()); 143885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 144885b47fbSopenharmony_ci } 145885b47fbSopenharmony_ci if (!data.WriteInt32(requestId)) { 146885b47fbSopenharmony_ci HILOG_ERROR("requestId write error: %{public}d, ", requestId); 147885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 148885b47fbSopenharmony_ci } 149885b47fbSopenharmony_ci if (!data.WriteRemoteObject(callback->AsObject())) { 150885b47fbSopenharmony_ci HILOG_ERROR("callback write error"); 151885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 152885b47fbSopenharmony_ci } 153885b47fbSopenharmony_ci 154885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::SEARCH_ELEMENTINFOS_BY_TEXT, 155885b47fbSopenharmony_ci data, reply, option)) { 156885b47fbSopenharmony_ci HILOG_ERROR("fail to find elementInfo by text"); 157885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 158885b47fbSopenharmony_ci } 159885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 160885b47fbSopenharmony_ci} 161885b47fbSopenharmony_ci 162885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::FindFocusedElementInfo(const int32_t accessibilityWindowId, 163885b47fbSopenharmony_ci const int64_t elementId, const int32_t focusType, const int32_t requestId, 164885b47fbSopenharmony_ci const sptr<IAccessibilityElementOperatorCallback> &callback) 165885b47fbSopenharmony_ci{ 166885b47fbSopenharmony_ci HILOG_DEBUG(); 167885b47fbSopenharmony_ci if (callback == nullptr) { 168885b47fbSopenharmony_ci HILOG_ERROR("callback is nullptr."); 169885b47fbSopenharmony_ci return RET_ERR_INVALID_PARAM; 170885b47fbSopenharmony_ci } 171885b47fbSopenharmony_ci 172885b47fbSopenharmony_ci MessageParcel data; 173885b47fbSopenharmony_ci MessageParcel reply; 174885b47fbSopenharmony_ci MessageOption option; 175885b47fbSopenharmony_ci 176885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 177885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 178885b47fbSopenharmony_ci } 179885b47fbSopenharmony_ci if (!data.WriteInt32(accessibilityWindowId)) { 180885b47fbSopenharmony_ci HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); 181885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 182885b47fbSopenharmony_ci } 183885b47fbSopenharmony_ci if (!data.WriteInt64(elementId)) { 184885b47fbSopenharmony_ci HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId); 185885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 186885b47fbSopenharmony_ci } 187885b47fbSopenharmony_ci if (!data.WriteInt32(focusType)) { 188885b47fbSopenharmony_ci HILOG_ERROR("focusType write error: %{public}d, ", focusType); 189885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 190885b47fbSopenharmony_ci } 191885b47fbSopenharmony_ci if (!data.WriteInt32(requestId)) { 192885b47fbSopenharmony_ci HILOG_ERROR("requestId write error: %{public}d, ", requestId); 193885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 194885b47fbSopenharmony_ci } 195885b47fbSopenharmony_ci if (!data.WriteRemoteObject(callback->AsObject())) { 196885b47fbSopenharmony_ci HILOG_ERROR("callback write error"); 197885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 198885b47fbSopenharmony_ci } 199885b47fbSopenharmony_ci 200885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::FIND_FOCUSED_ELEMENTINFO, data, reply, option)) { 201885b47fbSopenharmony_ci HILOG_ERROR("fail to gain focus"); 202885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 203885b47fbSopenharmony_ci } 204885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 205885b47fbSopenharmony_ci} 206885b47fbSopenharmony_ci 207885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::FocusMoveSearch(const int32_t accessibilityWindowId, const int64_t elementId, 208885b47fbSopenharmony_ci const int32_t direction, const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback) 209885b47fbSopenharmony_ci{ 210885b47fbSopenharmony_ci HILOG_DEBUG(); 211885b47fbSopenharmony_ci if (callback == nullptr) { 212885b47fbSopenharmony_ci HILOG_ERROR("callback is nullptr."); 213885b47fbSopenharmony_ci return RET_ERR_INVALID_PARAM; 214885b47fbSopenharmony_ci } 215885b47fbSopenharmony_ci 216885b47fbSopenharmony_ci MessageParcel data; 217885b47fbSopenharmony_ci MessageParcel reply; 218885b47fbSopenharmony_ci MessageOption option; 219885b47fbSopenharmony_ci 220885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 221885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 222885b47fbSopenharmony_ci } 223885b47fbSopenharmony_ci if (!data.WriteInt32(accessibilityWindowId)) { 224885b47fbSopenharmony_ci HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); 225885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 226885b47fbSopenharmony_ci } 227885b47fbSopenharmony_ci if (!data.WriteInt64(elementId)) { 228885b47fbSopenharmony_ci HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId); 229885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 230885b47fbSopenharmony_ci } 231885b47fbSopenharmony_ci if (!data.WriteInt32(direction)) { 232885b47fbSopenharmony_ci HILOG_ERROR("direction write error: %{public}d, ", direction); 233885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 234885b47fbSopenharmony_ci } 235885b47fbSopenharmony_ci if (!data.WriteInt32(requestId)) { 236885b47fbSopenharmony_ci HILOG_ERROR("requestId write error: %{public}d, ", requestId); 237885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 238885b47fbSopenharmony_ci } 239885b47fbSopenharmony_ci if (!data.WriteRemoteObject(callback->AsObject())) { 240885b47fbSopenharmony_ci HILOG_ERROR("callback write error"); 241885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 242885b47fbSopenharmony_ci } 243885b47fbSopenharmony_ci 244885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::FOCUS_MOVE_SEARCH, data, reply, option)) { 245885b47fbSopenharmony_ci HILOG_ERROR("fail to search focus"); 246885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 247885b47fbSopenharmony_ci } 248885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 249885b47fbSopenharmony_ci} 250885b47fbSopenharmony_ci 251885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::EnableScreenCurtain(bool isEnable) 252885b47fbSopenharmony_ci{ 253885b47fbSopenharmony_ci HILOG_DEBUG(); 254885b47fbSopenharmony_ci 255885b47fbSopenharmony_ci MessageParcel data; 256885b47fbSopenharmony_ci MessageParcel reply; 257885b47fbSopenharmony_ci MessageOption option; 258885b47fbSopenharmony_ci 259885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 260885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 261885b47fbSopenharmony_ci } 262885b47fbSopenharmony_ci if (!data.WriteBool(isEnable)) { 263885b47fbSopenharmony_ci HILOG_ERROR("isEnable write error: %{public}d, ", isEnable); 264885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 265885b47fbSopenharmony_ci } 266885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::SET_CURTAIN_SCREEN, 267885b47fbSopenharmony_ci data, reply, option)) { 268885b47fbSopenharmony_ci HILOG_ERROR("fail to enable screen curtain"); 269885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 270885b47fbSopenharmony_ci } 271885b47fbSopenharmony_ci 272885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 273885b47fbSopenharmony_ci} 274885b47fbSopenharmony_ci 275885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::ExecuteAction(const int32_t accessibilityWindowId, const int64_t elementId, 276885b47fbSopenharmony_ci const int32_t action, const std::map<std::string, std::string> &actionArguments, const int32_t requestId, 277885b47fbSopenharmony_ci const sptr<IAccessibilityElementOperatorCallback> &callback) 278885b47fbSopenharmony_ci{ 279885b47fbSopenharmony_ci HILOG_DEBUG(); 280885b47fbSopenharmony_ci 281885b47fbSopenharmony_ci MessageParcel data; 282885b47fbSopenharmony_ci MessageParcel reply; 283885b47fbSopenharmony_ci MessageOption option; 284885b47fbSopenharmony_ci 285885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 286885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 287885b47fbSopenharmony_ci } 288885b47fbSopenharmony_ci if (!data.WriteInt32(accessibilityWindowId)) { 289885b47fbSopenharmony_ci HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); 290885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 291885b47fbSopenharmony_ci } 292885b47fbSopenharmony_ci if (!data.WriteInt64(elementId)) { 293885b47fbSopenharmony_ci HILOG_ERROR("elementId write error: %{public}" PRId64 "", elementId); 294885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 295885b47fbSopenharmony_ci } 296885b47fbSopenharmony_ci if (!data.WriteInt32(action)) { 297885b47fbSopenharmony_ci HILOG_ERROR("action write error: %{public}d, ", action); 298885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 299885b47fbSopenharmony_ci } 300885b47fbSopenharmony_ci 301885b47fbSopenharmony_ci std::vector<std::string> actionArgumentsKey {}; 302885b47fbSopenharmony_ci std::vector<std::string> actionArgumentsValue {}; 303885b47fbSopenharmony_ci for (auto iter = actionArguments.begin(); iter != actionArguments.end(); iter++) { 304885b47fbSopenharmony_ci actionArgumentsKey.push_back(iter->first); 305885b47fbSopenharmony_ci actionArgumentsValue.push_back(iter->second); 306885b47fbSopenharmony_ci } 307885b47fbSopenharmony_ci if (!data.WriteStringVector(actionArgumentsKey)) { 308885b47fbSopenharmony_ci HILOG_ERROR("actionArgumentsKey write error"); 309885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 310885b47fbSopenharmony_ci } 311885b47fbSopenharmony_ci if (!data.WriteStringVector(actionArgumentsValue)) { 312885b47fbSopenharmony_ci HILOG_ERROR("actionArgumentsValue write error"); 313885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 314885b47fbSopenharmony_ci } 315885b47fbSopenharmony_ci 316885b47fbSopenharmony_ci if (!data.WriteInt32(requestId)) { 317885b47fbSopenharmony_ci HILOG_ERROR("requestId write error: %{public}d, ", requestId); 318885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 319885b47fbSopenharmony_ci } 320885b47fbSopenharmony_ci if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) { 321885b47fbSopenharmony_ci HILOG_ERROR("callback write error"); 322885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 323885b47fbSopenharmony_ci } 324885b47fbSopenharmony_ci 325885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::PERFORM_ACTION, 326885b47fbSopenharmony_ci data, reply, option)) { 327885b47fbSopenharmony_ci HILOG_ERROR("fail to perform accessibility action"); 328885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 329885b47fbSopenharmony_ci } 330885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 331885b47fbSopenharmony_ci} 332885b47fbSopenharmony_ci 333885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) 334885b47fbSopenharmony_ci{ 335885b47fbSopenharmony_ci HILOG_DEBUG(); 336885b47fbSopenharmony_ci 337885b47fbSopenharmony_ci MessageParcel data; 338885b47fbSopenharmony_ci MessageParcel reply; 339885b47fbSopenharmony_ci MessageOption option; 340885b47fbSopenharmony_ci 341885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 342885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 343885b47fbSopenharmony_ci } 344885b47fbSopenharmony_ci 345885b47fbSopenharmony_ci if (!data.WriteInt32(windowId)) { 346885b47fbSopenharmony_ci HILOG_ERROR("windowId write error: %{public}d, ", windowId); 347885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 348885b47fbSopenharmony_ci } 349885b47fbSopenharmony_ci 350885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::GET_WINDOW, data, reply, option)) { 351885b47fbSopenharmony_ci HILOG_ERROR("fail to get window"); 352885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 353885b47fbSopenharmony_ci } 354885b47fbSopenharmony_ci 355885b47fbSopenharmony_ci sptr<AccessibilityWindowInfoParcel> windowInfoParcel = reply.ReadStrongParcelable<AccessibilityWindowInfoParcel>(); 356885b47fbSopenharmony_ci if (windowInfoParcel == nullptr) { 357885b47fbSopenharmony_ci HILOG_ERROR("ReadStrongParcelable<AccessibilityWindowInfoParcel> failed"); 358885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 359885b47fbSopenharmony_ci } 360885b47fbSopenharmony_ci windowInfo = *windowInfoParcel; 361885b47fbSopenharmony_ci 362885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 363885b47fbSopenharmony_ci} 364885b47fbSopenharmony_ci 365885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::GetWindows(std::vector<AccessibilityWindowInfo> &windows) 366885b47fbSopenharmony_ci{ 367885b47fbSopenharmony_ci HILOG_DEBUG(); 368885b47fbSopenharmony_ci MessageParcel data; 369885b47fbSopenharmony_ci MessageParcel reply; 370885b47fbSopenharmony_ci MessageOption option; 371885b47fbSopenharmony_ci 372885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 373885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 374885b47fbSopenharmony_ci } 375885b47fbSopenharmony_ci 376885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::GET_WINDOWS, data, reply, option)) { 377885b47fbSopenharmony_ci HILOG_ERROR("fail to get windows"); 378885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 379885b47fbSopenharmony_ci } 380885b47fbSopenharmony_ci 381885b47fbSopenharmony_ci int32_t windowsSize = reply.ReadInt32(); 382885b47fbSopenharmony_ci if (windowsSize < 0 || windowsSize > INT32_MAX) { 383885b47fbSopenharmony_ci HILOG_ERROR("windowsSize is invalid"); 384885b47fbSopenharmony_ci return RET_ERR_INVALID_PARAM; 385885b47fbSopenharmony_ci } 386885b47fbSopenharmony_ci 387885b47fbSopenharmony_ci for (int32_t i = 0; i < windowsSize; i++) { 388885b47fbSopenharmony_ci sptr<AccessibilityWindowInfoParcel> window = reply.ReadStrongParcelable<AccessibilityWindowInfoParcel>(); 389885b47fbSopenharmony_ci if (window == nullptr) { 390885b47fbSopenharmony_ci HILOG_ERROR("ReadStrongParcelable<AccessibilityWindowInfoParcel> failed"); 391885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 392885b47fbSopenharmony_ci } 393885b47fbSopenharmony_ci windows.emplace_back(*window); 394885b47fbSopenharmony_ci } 395885b47fbSopenharmony_ci 396885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 397885b47fbSopenharmony_ci} 398885b47fbSopenharmony_ci 399885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::GetWindowsByDisplayId(const uint64_t displayId, 400885b47fbSopenharmony_ci std::vector<AccessibilityWindowInfo> &windows) 401885b47fbSopenharmony_ci{ 402885b47fbSopenharmony_ci HILOG_DEBUG(); 403885b47fbSopenharmony_ci 404885b47fbSopenharmony_ci MessageParcel data; 405885b47fbSopenharmony_ci MessageParcel reply; 406885b47fbSopenharmony_ci MessageOption option; 407885b47fbSopenharmony_ci 408885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 409885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 410885b47fbSopenharmony_ci } 411885b47fbSopenharmony_ci 412885b47fbSopenharmony_ci if (!data.WriteUint64(displayId)) { 413885b47fbSopenharmony_ci HILOG_ERROR("displayId write error: %{public}" PRIu64 ", ", displayId); 414885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 415885b47fbSopenharmony_ci } 416885b47fbSopenharmony_ci 417885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::GET_WINDOWS_BY_DISPLAY_ID, data, reply, option)) { 418885b47fbSopenharmony_ci HILOG_ERROR("fail to get windows"); 419885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 420885b47fbSopenharmony_ci } 421885b47fbSopenharmony_ci 422885b47fbSopenharmony_ci int32_t windowsSize = reply.ReadInt32(); 423885b47fbSopenharmony_ci if (windowsSize < 0 || windowsSize > INT32_MAX) { 424885b47fbSopenharmony_ci HILOG_ERROR("windowsSize is invalid"); 425885b47fbSopenharmony_ci return RET_ERR_INVALID_PARAM; 426885b47fbSopenharmony_ci } 427885b47fbSopenharmony_ci 428885b47fbSopenharmony_ci for (int32_t i = 0; i < windowsSize; i++) { 429885b47fbSopenharmony_ci sptr<AccessibilityWindowInfoParcel> window = reply.ReadStrongParcelable<AccessibilityWindowInfoParcel>(); 430885b47fbSopenharmony_ci if (window == nullptr) { 431885b47fbSopenharmony_ci HILOG_ERROR("ReadStrongParcelable<AccessibilityWindowInfoParcel> failed"); 432885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 433885b47fbSopenharmony_ci } 434885b47fbSopenharmony_ci windows.emplace_back(*window); 435885b47fbSopenharmony_ci } 436885b47fbSopenharmony_ci 437885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 438885b47fbSopenharmony_ci} 439885b47fbSopenharmony_ci 440885b47fbSopenharmony_civoid AccessibleAbilityChannelProxy::SetOnKeyPressEventResult(const bool handled, const int32_t sequence) 441885b47fbSopenharmony_ci{ 442885b47fbSopenharmony_ci HILOG_DEBUG(); 443885b47fbSopenharmony_ci 444885b47fbSopenharmony_ci MessageParcel data; 445885b47fbSopenharmony_ci MessageParcel reply; 446885b47fbSopenharmony_ci MessageOption option(MessageOption::TF_ASYNC); 447885b47fbSopenharmony_ci 448885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 449885b47fbSopenharmony_ci return; 450885b47fbSopenharmony_ci } 451885b47fbSopenharmony_ci if (!data.WriteBool(handled)) { 452885b47fbSopenharmony_ci HILOG_ERROR("handled write error: %{public}d, ", handled); 453885b47fbSopenharmony_ci return; 454885b47fbSopenharmony_ci } 455885b47fbSopenharmony_ci if (!data.WriteInt32(sequence)) { 456885b47fbSopenharmony_ci HILOG_ERROR("sequence write error: %{public}d, ", sequence); 457885b47fbSopenharmony_ci return; 458885b47fbSopenharmony_ci } 459885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::SET_ON_KEY_PRESS_EVENT_RESULT, 460885b47fbSopenharmony_ci data, reply, option)) { 461885b47fbSopenharmony_ci HILOG_ERROR("fail to set onKeyPressEvent result"); 462885b47fbSopenharmony_ci } 463885b47fbSopenharmony_ci} 464885b47fbSopenharmony_ci 465885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::GetCursorPosition(const int32_t accessibilityWindowId, const int64_t elementId, 466885b47fbSopenharmony_ci const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback) 467885b47fbSopenharmony_ci{ 468885b47fbSopenharmony_ci HILOG_DEBUG(); 469885b47fbSopenharmony_ci 470885b47fbSopenharmony_ci MessageParcel data; 471885b47fbSopenharmony_ci MessageParcel reply; 472885b47fbSopenharmony_ci MessageOption option(MessageOption::TF_ASYNC); 473885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 474885b47fbSopenharmony_ci return RET_ERR_FAILED; 475885b47fbSopenharmony_ci } 476885b47fbSopenharmony_ci if (!data.WriteInt32(accessibilityWindowId)) { 477885b47fbSopenharmony_ci HILOG_ERROR("accessibilityWindowId write error: %{public}d, ", accessibilityWindowId); 478885b47fbSopenharmony_ci return RET_ERR_FAILED; 479885b47fbSopenharmony_ci } 480885b47fbSopenharmony_ci if (!data.WriteInt64(elementId)) { 481885b47fbSopenharmony_ci HILOG_ERROR("elementId write error"); 482885b47fbSopenharmony_ci return RET_ERR_FAILED; 483885b47fbSopenharmony_ci } 484885b47fbSopenharmony_ci if (!data.WriteInt32(requestId)) { 485885b47fbSopenharmony_ci HILOG_ERROR("requestId write error: %{public}d, ", requestId); 486885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 487885b47fbSopenharmony_ci } 488885b47fbSopenharmony_ci if (callback == nullptr) { 489885b47fbSopenharmony_ci HILOG_ERROR("callback is null"); 490885b47fbSopenharmony_ci return RET_ERR_FAILED; 491885b47fbSopenharmony_ci } 492885b47fbSopenharmony_ci if (callback->AsObject() == nullptr) { 493885b47fbSopenharmony_ci HILOG_ERROR("callback->AsObject() is null"); 494885b47fbSopenharmony_ci return RET_ERR_FAILED; 495885b47fbSopenharmony_ci } 496885b47fbSopenharmony_ci if (!data.WriteRemoteObject(callback->AsObject())) { 497885b47fbSopenharmony_ci HILOG_ERROR("callback write error"); 498885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 499885b47fbSopenharmony_ci } 500885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::GET_CURSOR_POSITION, 501885b47fbSopenharmony_ci data, reply, option)) { 502885b47fbSopenharmony_ci HILOG_ERROR("fail to set onKeyPressEvent result"); 503885b47fbSopenharmony_ci return RET_ERR_FAILED; 504885b47fbSopenharmony_ci } 505885b47fbSopenharmony_ci 506885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 507885b47fbSopenharmony_ci} 508885b47fbSopenharmony_ci 509885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::SendSimulateGesture( 510885b47fbSopenharmony_ci const std::shared_ptr<AccessibilityGestureInjectPath>& gesturePath) 511885b47fbSopenharmony_ci{ 512885b47fbSopenharmony_ci HILOG_DEBUG(); 513885b47fbSopenharmony_ci sptr<AccessibilityGestureInjectPathParcel> path = 514885b47fbSopenharmony_ci new(std::nothrow) AccessibilityGestureInjectPathParcel(*gesturePath); 515885b47fbSopenharmony_ci if (path == nullptr) { 516885b47fbSopenharmony_ci HILOG_ERROR("Failed to create path."); 517885b47fbSopenharmony_ci return RET_ERR_NULLPTR; 518885b47fbSopenharmony_ci } 519885b47fbSopenharmony_ci 520885b47fbSopenharmony_ci MessageParcel data; 521885b47fbSopenharmony_ci MessageParcel reply; 522885b47fbSopenharmony_ci MessageOption option(MessageOption::TF_SYNC); 523885b47fbSopenharmony_ci 524885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 525885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 526885b47fbSopenharmony_ci } 527885b47fbSopenharmony_ci 528885b47fbSopenharmony_ci if (!data.WriteStrongParcelable(path)) { 529885b47fbSopenharmony_ci HILOG_ERROR("WriteStrongParcelable<AccessibilityGestureInjectPathParcel> failed"); 530885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 531885b47fbSopenharmony_ci } 532885b47fbSopenharmony_ci 533885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::SEND_SIMULATE_GESTURE_PATH, data, reply, option)) { 534885b47fbSopenharmony_ci HILOG_ERROR("fail to send simulation gesture path"); 535885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 536885b47fbSopenharmony_ci } 537885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 538885b47fbSopenharmony_ci} 539885b47fbSopenharmony_ci 540885b47fbSopenharmony_ciRetError AccessibleAbilityChannelProxy::SetTargetBundleName(const std::vector<std::string> &targetBundleNames) 541885b47fbSopenharmony_ci{ 542885b47fbSopenharmony_ci HILOG_DEBUG(); 543885b47fbSopenharmony_ci 544885b47fbSopenharmony_ci MessageParcel data; 545885b47fbSopenharmony_ci MessageParcel reply; 546885b47fbSopenharmony_ci MessageOption option(MessageOption::TF_SYNC); 547885b47fbSopenharmony_ci 548885b47fbSopenharmony_ci if (!WriteInterfaceToken(data)) { 549885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 550885b47fbSopenharmony_ci } 551885b47fbSopenharmony_ci if (!data.WriteInt32(targetBundleNames.size())) { 552885b47fbSopenharmony_ci HILOG_ERROR("targetBundleNames.size() write error: %{public}zu, ", targetBundleNames.size()); 553885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 554885b47fbSopenharmony_ci } 555885b47fbSopenharmony_ci for (auto &targetBundleName : targetBundleNames) { 556885b47fbSopenharmony_ci if (!data.WriteString(targetBundleName)) { 557885b47fbSopenharmony_ci HILOG_ERROR("targetBundleName write error: %{public}s, ", targetBundleName.c_str()); 558885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 559885b47fbSopenharmony_ci } 560885b47fbSopenharmony_ci } 561885b47fbSopenharmony_ci if (!SendTransactCmd(AccessibilityInterfaceCode::SET_TARGET_BUNDLE_NAME, data, reply, option)) { 562885b47fbSopenharmony_ci HILOG_ERROR("fail to set target bundle name filter"); 563885b47fbSopenharmony_ci return RET_ERR_IPC_FAILED; 564885b47fbSopenharmony_ci } 565885b47fbSopenharmony_ci return static_cast<RetError>(reply.ReadInt32()); 566885b47fbSopenharmony_ci} 567885b47fbSopenharmony_ci} // namespace Accessibility 568885b47fbSopenharmony_ci} // namespace OHOS