• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         HILOG_DEBUG("SetCardProxy : operation is nullptr");
46         return RET_ERR_FAILED;
47     }
48     cardProxy_.EnsureInsert(treeId, operation);
49     return RET_OK;
50 }
51 
GetCardProxy(const int32_t treeId)52 sptr<IAccessibilityElementOperator> AccessibilityWindowConnection::GetCardProxy(const int32_t treeId)
53 {
54     sptr<IAccessibilityElementOperator> connection = nullptr;
55     bool ret = cardProxy_.Find(treeId, connection);
56     HILOG_DEBUG("GetCardProxy : operation is %{public}d", connection != nullptr);
57     return connection;
58 }
59 
SetTokenIdMap(const int32_t treeId,const uint32_t tokenId)60 RetError AccessibilityWindowConnection::SetTokenIdMap(const int32_t treeId,
61     const uint32_t tokenId)
62 {
63     HILOG_DEBUG("treeId : %{public}d", treeId);
64     tokenIdMap_.EnsureInsert(treeId, tokenId);
65     return RET_OK;
66 }
67 
GetTokenIdMap(const int32_t treeId)68 uint32_t AccessibilityWindowConnection::GetTokenIdMap(const int32_t treeId)
69 {
70     HILOG_DEBUG("treeId : %{public}d", treeId);
71     return tokenIdMap_.ReadVal(treeId);
72 }
73 
GetAllTreeId(std::vector<int32_t> & treeIds)74 void AccessibilityWindowConnection::GetAllTreeId(std::vector<int32_t> &treeIds)
75 {
76     auto getAllTreeIdFunc = [&treeIds](const int32_t treeId, sptr<IAccessibilityElementOperator> connection) {
77         treeIds.emplace_back(treeId);
78     };
79     cardProxy_.Iterate(getAllTreeIdFunc);
80 }
81 
GetRootParentId(int32_t treeId,int64_t & elementId)82 RetError AccessibilityWindowConnection::GetRootParentId(int32_t treeId, int64_t &elementId)
83 {
84     bool ret = treeIdParentId_.Find(treeId, elementId);
85     return ret == true ? RET_OK : RET_ERR_FAILED;
86 }
87 
SetRootParentId(const int32_t treeId,const int64_t elementId)88 RetError AccessibilityWindowConnection::SetRootParentId(const int32_t treeId, const int64_t elementId)
89 {
90     treeIdParentId_.EnsureInsert(treeId, elementId);
91     return RET_OK;
92 }
EraseProxy(const int32_t treeId)93 void AccessibilityWindowConnection::EraseProxy(const int32_t treeId)
94 {
95     sptr<IAccessibilityElementOperator> connection = nullptr;
96     bool ret = cardProxy_.Find(treeId, connection);
97     if (ret) {
98         cardProxy_.Erase(treeId);
99     }
100 }
101 } // namespace Accessibility
102 } // namespace OHOS