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