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_operator.h"
17
18 namespace OHOS {
19 namespace Accessibility {
20 const int LEFT_TOP_Y = 200;
21 const int RIGHT_BOTTOM_X = 600;
22 const int RIGHT_BOTTOM_Y = 800;
23 std::map<int, sptr<IAccessibleAbilityChannel>> AccessibilityOperator::channels_ = {};
24 std::vector<sptr<AccessibilityOperator>> AccessibilityOperator::instances_ = {};
25 std::recursive_mutex AccessibilityOperator::mutex_ = {};
26
AccessibilityOperator()27 AccessibilityOperator::AccessibilityOperator()
28 {
29 executeActionResult_ = false;
30 }
31
~AccessibilityOperator()32 AccessibilityOperator::~AccessibilityOperator()
33 {
34 }
35
GetInstance()36 AccessibilityOperator &AccessibilityOperator::GetInstance()
37 {
38 sptr<AccessibilityOperator> inst = new AccessibilityOperator();
39 return *inst;
40 }
41
GetChannel(int channelId)42 sptr<IAccessibleAbilityChannel> AccessibilityOperator::GetChannel(int channelId)
43 {
44 auto channel = channels_.find(channelId);
45 if (channel != channels_.end()) {
46 HILOG_DEBUG("Find aams [channelId:%{public}d]", channelId);
47 return channel->second;
48 } else {
49 HILOG_ERROR("Failed to find aams [channelId:%{public}d]", channelId);
50 return nullptr;
51 }
52 }
53
AddChannel(const int channelId,const sptr<IAccessibleAbilityChannel> & channel)54 void AccessibilityOperator::AddChannel(const int channelId, const sptr<IAccessibleAbilityChannel> &channel)
55 {
56 HILOG_DEBUG("Add connection to aams [channelId:%{public}d]", channelId);
57 int tempId = *(const_cast<int *>(&channelId));
58 for (auto iter = channels_.begin(); iter != channels_.end(); iter++) {
59 if (iter->first == tempId) {
60 HILOG_ERROR("Connection to aams [channelId:%{public}d] is exited", channelId);
61 return;
62 }
63 }
64 sptr<IAccessibleAbilityChannel> tempChanel = const_cast<sptr<IAccessibleAbilityChannel> &>(channel);
65 channels_.insert(std::pair<int, sptr<IAccessibleAbilityChannel>>(tempId, tempChanel));
66 }
67
RemoveChannel(int channelId)68 void AccessibilityOperator::RemoveChannel(int channelId)
69 {
70 HILOG_DEBUG("Remove connection to aams [channelId:%{public}d]", channelId);
71 auto iter = channels_.find(channelId);
72 if (iter != channels_.end()) {
73 channels_.erase(iter);
74 } else {
75 HILOG_DEBUG("Failed to remove connection with aams [channelId:%{public}d]", channelId);
76 }
77 }
78
GetRoot(int channelId,AccessibilityElementInfo & elementInfo)79 bool AccessibilityOperator::GetRoot(int channelId, AccessibilityElementInfo &elementInfo)
80 {
81 return true;
82 }
83
GetWindows(int channelId)84 std::vector<AccessibilityWindowInfo> AccessibilityOperator::GetWindows(int channelId)
85 {
86 return windows_;
87 }
88
SearchElementInfosByAccessibilityId(int channelId,int accessibilityWindowId,int elementId,int mode,std::vector<AccessibilityElementInfo> & elementInfos)89 bool AccessibilityOperator::SearchElementInfosByAccessibilityId(int channelId,
90 int accessibilityWindowId, int elementId, int mode, std::vector<AccessibilityElementInfo> &elementInfos)
91 {
92 return true;
93 }
94
SearchElementInfosByText(int channelId,int accessibilityWindowId,int elementId,const std::string & text,std::vector<AccessibilityElementInfo> & elementInfos)95 bool AccessibilityOperator::SearchElementInfosByText(int channelId, int accessibilityWindowId,
96 int elementId, const std::string &text, std::vector<AccessibilityElementInfo> &elementInfos)
97 {
98 return true;
99 }
100
FindFocusedElementInfo(int channelId,int accessibilityWindowId,int elementId,int focusType,AccessibilityElementInfo & elementInfo)101 bool AccessibilityOperator::FindFocusedElementInfo(int channelId, int accessibilityWindowId,
102 int elementId, int focusType, AccessibilityElementInfo &elementInfo)
103 {
104 AccessibilityElementInfo focus;
105 Rect rect(0, LEFT_TOP_Y, RIGHT_BOTTOM_X, RIGHT_BOTTOM_Y);
106 focus.SetRectInScreen(rect);
107 elementInfo = focus;
108 return true;
109 }
110
FocusMoveSearch(int channelId,int accessibilityWindowId,int elementId,int direction,AccessibilityElementInfo & elementInfo)111 bool AccessibilityOperator::FocusMoveSearch(int channelId, int accessibilityWindowId,
112 int elementId, int direction, AccessibilityElementInfo &elementInfo)
113 {
114 return true;
115 }
116
ExecuteAction(int channelId,int accessibilityWindowId,int elementId,int action,std::map<std::string,std::string> & actionArguments)117 bool AccessibilityOperator::ExecuteAction(int channelId, int accessibilityWindowId,
118 int elementId, int action, std::map<std::string, std::string> &actionArguments)
119 {
120 return true;
121 }
122
SetSearchElementInfoByAccessibilityIdResult(const std::vector<AccessibilityElementInfo> & infos,const int requestId)123 void AccessibilityOperator::SetSearchElementInfoByAccessibilityIdResult(
124 const std::vector<AccessibilityElementInfo> &infos, const int requestId)
125 {
126 }
127
SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> & infos,const int requestId)128 void AccessibilityOperator::SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> &infos,
129 const int requestId)
130 {
131 }
132
SetFindFocusedElementInfoResult(const AccessibilityElementInfo & info,const int requestId)133 void AccessibilityOperator::SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info, const int requestId)
134 {
135 }
136
SetFocusMoveSearchResult(const AccessibilityElementInfo & info,const int requestId)137 void AccessibilityOperator::SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int requestId)
138 {
139 }
140
SetExecuteActionResult(const bool succeeded,const int requestId)141 void AccessibilityOperator::SetExecuteActionResult(const bool succeeded, const int requestId)
142 {
143 }
144
ExecuteCommonAction(const int channelId,const int action)145 bool AccessibilityOperator::ExecuteCommonAction(const int channelId, const int action)
146 {
147 return true;
148 }
149
SetOnKeyPressEventResult(const int channelId,const bool handled,const int sequence)150 void AccessibilityOperator::SetOnKeyPressEventResult(const int channelId, const bool handled, const int sequence)
151 {
152 }
153
GetDisplayResizeScale(const int channelId,const int displayId)154 float AccessibilityOperator::GetDisplayResizeScale(const int channelId, const int displayId)
155 {
156 return 1;
157 }
158
GetDisplayResizeCenterX(const int channelId,const int displayId)159 float AccessibilityOperator::GetDisplayResizeCenterX(const int channelId, const int displayId)
160 {
161 return 1;
162 }
163
GetDisplayResizeCenterY(const int channelId,const int displayId)164 float AccessibilityOperator::GetDisplayResizeCenterY(const int channelId, const int displayId)
165 {
166 return 1;
167 }
168
GetDisplayResizeRect(const int channelId,const int displayId)169 Rect AccessibilityOperator::GetDisplayResizeRect(const int channelId, const int displayId)
170 {
171 Rect rect {};
172 return rect;
173 }
174
ResetDisplayResize(const int channelId,const int displayId,const bool animate)175 bool AccessibilityOperator::ResetDisplayResize(const int channelId, const int displayId, const bool animate)
176 {
177 return false;
178 }
179
SetDisplayResizeScaleAndCenter(const int channelId,const int displayId,const float scale,const float centerX,const float centerY,const bool animate)180 bool AccessibilityOperator::SetDisplayResizeScaleAndCenter(const int channelId,
181 const int displayId, const float scale, const float centerX, const float centerY, const bool animate)
182 {
183 return false;
184 }
185
SendSimulateGesture(const int channelId,const int requestId,const std::vector<GesturePathDefine> & gestureSteps)186 void AccessibilityOperator::SendSimulateGesture(const int channelId,
187 const int requestId, const std::vector<GesturePathDefine> &gestureSteps)
188 {
189 }
190 } // namespace Accessibility
191 } // namespace OHOS