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 "accessibility_window_connection.h" 17885b47fbSopenharmony_ci 18885b47fbSopenharmony_ciusing namespace std; 19885b47fbSopenharmony_ci 20885b47fbSopenharmony_cinamespace OHOS { 21885b47fbSopenharmony_cinamespace Accessibility { 22885b47fbSopenharmony_ciAccessibilityWindowConnection::AccessibilityWindowConnection(const int32_t windowId, 23885b47fbSopenharmony_ci const sptr<IAccessibilityElementOperator> &connection, const int32_t accountId) 24885b47fbSopenharmony_ci{ 25885b47fbSopenharmony_ci windowId_ = windowId; 26885b47fbSopenharmony_ci proxy_ = connection; 27885b47fbSopenharmony_ci accountId_ = accountId; 28885b47fbSopenharmony_ci cardProxy_[0] = connection; 29885b47fbSopenharmony_ci} 30885b47fbSopenharmony_ci 31885b47fbSopenharmony_ciAccessibilityWindowConnection::AccessibilityWindowConnection(const int32_t windowId, const int32_t treeId, 32885b47fbSopenharmony_ci const sptr<IAccessibilityElementOperator> &connection, const int32_t accountId) 33885b47fbSopenharmony_ci{ 34885b47fbSopenharmony_ci windowId_ = windowId; 35885b47fbSopenharmony_ci treeId_ = treeId; 36885b47fbSopenharmony_ci cardProxy_[treeId] = connection; 37885b47fbSopenharmony_ci accountId_ = accountId; 38885b47fbSopenharmony_ci} 39885b47fbSopenharmony_ci 40885b47fbSopenharmony_ciAccessibilityWindowConnection::~AccessibilityWindowConnection() 41885b47fbSopenharmony_ci{ 42885b47fbSopenharmony_ci} 43885b47fbSopenharmony_ci 44885b47fbSopenharmony_ciRetError AccessibilityWindowConnection::SetCardProxy(const int32_t treeId, 45885b47fbSopenharmony_ci sptr<IAccessibilityElementOperator> operation) 46885b47fbSopenharmony_ci{ 47885b47fbSopenharmony_ci if (!operation) { 48885b47fbSopenharmony_ci HILOG_DEBUG("SetCardProxy : operation is nullptr"); 49885b47fbSopenharmony_ci return RET_ERR_FAILED; 50885b47fbSopenharmony_ci } 51885b47fbSopenharmony_ci cardProxy_[treeId] = operation; 52885b47fbSopenharmony_ci return RET_OK; 53885b47fbSopenharmony_ci} 54885b47fbSopenharmony_ci 55885b47fbSopenharmony_cisptr<IAccessibilityElementOperator> AccessibilityWindowConnection::GetCardProxy(const int32_t treeId) 56885b47fbSopenharmony_ci{ 57885b47fbSopenharmony_ci auto iter = cardProxy_.find(treeId); 58885b47fbSopenharmony_ci if (iter != cardProxy_.end()) { 59885b47fbSopenharmony_ci HILOG_DEBUG("GetCardProxy : operation is ok"); 60885b47fbSopenharmony_ci return cardProxy_[treeId]; 61885b47fbSopenharmony_ci } 62885b47fbSopenharmony_ci HILOG_DEBUG("GetCardProxy : operation is no"); 63885b47fbSopenharmony_ci return nullptr; 64885b47fbSopenharmony_ci} 65885b47fbSopenharmony_ci 66885b47fbSopenharmony_ciRetError AccessibilityWindowConnection::SetTokenIdMap(const int32_t treeId, 67885b47fbSopenharmony_ci const uint32_t tokenId) 68885b47fbSopenharmony_ci{ 69885b47fbSopenharmony_ci HILOG_DEBUG("treeId : %{public}d", treeId); 70885b47fbSopenharmony_ci tokenIdMap_[treeId] = tokenId; 71885b47fbSopenharmony_ci return RET_OK; 72885b47fbSopenharmony_ci} 73885b47fbSopenharmony_ci 74885b47fbSopenharmony_ciuint32_t AccessibilityWindowConnection::GetTokenIdMap(const int32_t treeId) 75885b47fbSopenharmony_ci{ 76885b47fbSopenharmony_ci HILOG_DEBUG("treeId : %{public}d", treeId); 77885b47fbSopenharmony_ci return tokenIdMap_[treeId]; 78885b47fbSopenharmony_ci} 79885b47fbSopenharmony_ci 80885b47fbSopenharmony_civoid AccessibilityWindowConnection::GetAllTreeId(std::vector<int32_t> &treeIds) 81885b47fbSopenharmony_ci{ 82885b47fbSopenharmony_ci for (auto &treeId: cardProxy_) { 83885b47fbSopenharmony_ci treeIds.emplace_back(treeId.first); 84885b47fbSopenharmony_ci } 85885b47fbSopenharmony_ci} 86885b47fbSopenharmony_ci 87885b47fbSopenharmony_ciRetError AccessibilityWindowConnection::GetRootParentId(int32_t treeId, int64_t &elementId) 88885b47fbSopenharmony_ci{ 89885b47fbSopenharmony_ci auto iter = treeIdParentId_.find(treeId); 90885b47fbSopenharmony_ci if (iter != treeIdParentId_.end()) { 91885b47fbSopenharmony_ci elementId = iter->second; 92885b47fbSopenharmony_ci return RET_OK; 93885b47fbSopenharmony_ci } 94885b47fbSopenharmony_ci return RET_ERR_FAILED; 95885b47fbSopenharmony_ci} 96885b47fbSopenharmony_ci 97885b47fbSopenharmony_ciRetError AccessibilityWindowConnection::SetRootParentId(const int32_t treeId, const int64_t elementId) 98885b47fbSopenharmony_ci{ 99885b47fbSopenharmony_ci treeIdParentId_[treeId] = elementId; 100885b47fbSopenharmony_ci return RET_OK; 101885b47fbSopenharmony_ci} 102885b47fbSopenharmony_ci 103885b47fbSopenharmony_civoid AccessibilityWindowConnection::EraseProxy(const int32_t treeId) 104885b47fbSopenharmony_ci{ 105885b47fbSopenharmony_ci cardProxy_.erase(treeId); 106885b47fbSopenharmony_ci} 107885b47fbSopenharmony_ci} // namespace Accessibility 108885b47fbSopenharmony_ci} // namespace OHOS 109