/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "accessibility_element_operator_callback_stub.h" #include "accessibility_element_info_parcel.h" #include "hilog_wrapper.h" namespace OHOS { namespace Accessibility { AccessibilityElementOperatorCallbackStub::AccessibilityElementOperatorCallbackStub() { memberFuncMap_[static_cast( IAccessibilityElementOperatorCallback::Message::SET_RESULT_BY_ACCESSIBILITY_ID)] = &AccessibilityElementOperatorCallbackStub::HandleSetSearchElementInfoByAccessibilityIdResult; memberFuncMap_[static_cast(IAccessibilityElementOperatorCallback::Message::SET_RESULT_BY_TEXT)] = &AccessibilityElementOperatorCallbackStub::HandleSetSearchElementInfoByTextResult; memberFuncMap_[static_cast( IAccessibilityElementOperatorCallback::Message::SET_RESULT_FOCUSED_INFO)] = &AccessibilityElementOperatorCallbackStub::HandleSetFindFocusedElementInfoResult; memberFuncMap_[static_cast(IAccessibilityElementOperatorCallback::Message::SET_RESULT_FOCUS_MOVE)] = &AccessibilityElementOperatorCallbackStub::HandleSetFocusMoveSearchResult; memberFuncMap_[static_cast( IAccessibilityElementOperatorCallback::Message::SET_RESULT_PERFORM_ACTION)] = &AccessibilityElementOperatorCallbackStub::HandleSetExecuteActionResult; } AccessibilityElementOperatorCallbackStub::~AccessibilityElementOperatorCallbackStub() { HILOG_DEBUG(); memberFuncMap_.clear(); } int AccessibilityElementOperatorCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { HILOG_DEBUG("cmd = %{public}u, flags= %{public}d", code, option.GetFlags()); std::u16string descriptor = AccessibilityElementOperatorCallbackStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { HILOG_ERROR("local descriptor is not equal to remote"); return ERR_INVALID_STATE; } auto memFunc = memberFuncMap_.find(code); if (memFunc != memberFuncMap_.end()) { auto func = memFunc->second; if (func != nullptr) { return (this->*func)(data, reply); } } HILOG_WARN("AccessibilityElementOperatorCallbackStub::OnRemoteRequest, default case, need check."); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } ErrCode AccessibilityElementOperatorCallbackStub::HandleSetSearchElementInfoByAccessibilityIdResult( MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); std::vector infos {}; int32_t accessibilityInfosize = data.ReadInt32(); for (int32_t i = 0; i < accessibilityInfosize; i++) { sptr accessibilityInfo = data.ReadStrongParcelable(); if (!accessibilityInfo) { HILOG_ERROR("ReadStrongParcelable failed"); return TRANSACTION_ERR; } infos.emplace_back(*accessibilityInfo); } int32_t requestId = data.ReadInt32(); SetSearchElementInfoByAccessibilityIdResult(infos, requestId); return NO_ERROR; } ErrCode AccessibilityElementOperatorCallbackStub::HandleSetSearchElementInfoByTextResult( MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); std::vector infos {}; int32_t accessibilityInfosize = data.ReadInt32(); for (int32_t i = 0; i < accessibilityInfosize; i++) { sptr accessibilityInfo = data.ReadStrongParcelable(); if (!accessibilityInfo) { HILOG_ERROR("ReadStrongParcelable failed"); return TRANSACTION_ERR; } infos.emplace_back(*accessibilityInfo); } int32_t requestId = data.ReadInt32(); SetSearchElementInfoByTextResult(infos, requestId); return NO_ERROR; } ErrCode AccessibilityElementOperatorCallbackStub::HandleSetFindFocusedElementInfoResult(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); sptr info = data.ReadStrongParcelable(); if (!info) { HILOG_ERROR("ReadStrongParcelable failed"); return TRANSACTION_ERR; } int32_t requestId = data.ReadInt32(); SetFindFocusedElementInfoResult(*info, requestId); return NO_ERROR; } ErrCode AccessibilityElementOperatorCallbackStub::HandleSetFocusMoveSearchResult(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); sptr info = data.ReadStrongParcelable(); if (!info) { HILOG_ERROR("ReadStrongParcelable failed"); return TRANSACTION_ERR; } int32_t requestId = data.ReadInt32(); SetFocusMoveSearchResult(*info, requestId); return NO_ERROR; } ErrCode AccessibilityElementOperatorCallbackStub::HandleSetExecuteActionResult(MessageParcel &data, MessageParcel &reply) { HILOG_DEBUG(); bool succeeded = data.ReadBool(); int32_t requestId = data.ReadInt32(); SetExecuteActionResult(succeeded, requestId); return NO_ERROR; } } // namespace Accessibility } // namespace OHOS