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 "accessibility_window_connection.h"
17
18 namespace OHOS {
19 namespace Accessibility {
AccessibilityWindowConnection(const int32_t windowId,const sptr<IAccessibilityElementOperator> & connection,const int32_t accountId)20 AccessibilityWindowConnection::AccessibilityWindowConnection(
21 const int32_t windowId, const sptr<IAccessibilityElementOperator>& connection, const int32_t accountId)
22 {
23 windowId_ = windowId;
24 proxy_ = connection;
25 accountId_ = accountId;
26 }
27
AccessibilityWindowConnection(const int32_t windowId,const int32_t treeId,const sptr<IAccessibilityElementOperator> & connection,const int32_t accountId)28 AccessibilityWindowConnection::AccessibilityWindowConnection(
29 const int32_t windowId, const int32_t treeId,
30 const sptr<IAccessibilityElementOperator>& connection, const int32_t accountId)
31 {
32 windowId_ = windowId;
33 treeId_ = treeId;
34 proxy_ = connection;
35 accountId_ = accountId;
36 }
37
~AccessibilityWindowConnection()38 AccessibilityWindowConnection::~AccessibilityWindowConnection()
39 {}
40
SetCardProxy(const int32_t treeId,sptr<IAccessibilityElementOperator> operation)41 RetError AccessibilityWindowConnection::SetCardProxy(const int32_t treeId,
42 sptr<IAccessibilityElementOperator> operation)
43 {
44 if (!operation) {
45 return RET_ERR_FAILED;
46 }
47 cardProxy_[treeId] = operation;
48 return RET_OK;
49 }
50
GetCardProxy(const int32_t treeId)51 sptr<IAccessibilityElementOperator> AccessibilityWindowConnection::GetCardProxy(const int32_t treeId)
52 {
53 auto iter = cardProxy_.find(treeId);
54 if (iter != cardProxy_.end()) {
55 HILOG_DEBUG("GetCardProxy : operation is ok");
56 return cardProxy_[treeId];
57 }
58 HILOG_DEBUG("GetCardProxy : operation is no");
59 return proxy_;
60 }
61
SetTokenIdMap(const int32_t treeId,const uint32_t tokenId)62 RetError AccessibilityWindowConnection::SetTokenIdMap(const int32_t treeId,
63 const uint32_t tokenId)
64 {
65 HILOG_DEBUG("treeId : %{public}d", treeId);
66 tokenIdMap_[treeId] = tokenId;
67 return RET_OK;
68 }
69
GetTokenIdMap(const int32_t treeId)70 uint32_t AccessibilityWindowConnection::GetTokenIdMap(const int32_t treeId)
71 {
72 HILOG_DEBUG("treeId : %{public}d", treeId);
73 return tokenIdMap_[treeId];
74 }
75
GetAllTreeId(std::vector<int32_t> & treeIds)76 void AccessibilityWindowConnection::GetAllTreeId(std::vector<int32_t> &treeIds)
77 {
78 for (auto &treeId: cardProxy_) {
79 treeIds.emplace_back(treeId.first);
80 }
81 }
82
GetRootParentId(int32_t treeId,int64_t & elementId)83 RetError AccessibilityWindowConnection::GetRootParentId(int32_t treeId, int64_t &elementId)
84 {
85 auto iter = treeIdParentId_.find(treeId);
86 if (iter != treeIdParentId_.end()) {
87 elementId = iter->second;
88 return RET_OK;
89 }
90 return RET_ERR_FAILED;
91 }
92
SetRootParentId(const int32_t treeId,const int64_t elementId)93 RetError AccessibilityWindowConnection::SetRootParentId(const int32_t treeId, const int64_t elementId)
94 {
95 treeIdParentId_[treeId] = elementId;
96 return RET_OK;
97 }
98
EraseProxy(const int32_t treeId)99 void AccessibilityWindowConnection::EraseProxy(const int32_t treeId)
100 {
101 auto iter = cardProxy_.find(treeId);
102 if (iter != cardProxy_.end()) {
103 cardProxy_.erase(iter);
104 }
105 }
106 } // namespace Accessibility
107 } // namespace OHOS