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 #ifndef ACCESSIBILITY_INTERACTION_CLIENT_H 17 #define ACCESSIBILITY_INTERACTION_CLIENT_H 18 19 #include <cstdint> 20 #include <list> 21 #include <mutex> 22 #include <string> 23 #include <thread> 24 #include <vector> 25 26 #include "accessible_ability_channel_interface.h" 27 #include "accessible_ability_channel_proxy.h" 28 #include "accessibility_element_info.h" 29 #include "accessibility_element_operator_async_mng.h" 30 #include "accessibility_element_operator_callback_interface.h" 31 #include "accessibility_element_operator_callback_stub.h" 32 #include "accessibility_window_info.h" 33 #include "gesture_simulation.h" 34 #include "refbase.h" 35 36 namespace OHOS { 37 namespace Accessibility { 38 /* 39 * The class supply the api called by AA to get the accessibility info of UI. 40 * It call the API of AAMS and the request will be processed by 41 * UI and then set the result by callback(AA-->this class(with Callback)--> AAMS 42 * --> UI process and set Callback). 43 * It supply one instance for each thread to use this class. 44 */ 45 class AccessibilityOperator : public AccessibilityElementOperatorCallbackStub { 46 public: 47 static const int NONE_ID = -1; 48 static const int MAX_INSTANCE = 10; 49 /** 50 * @brief construct function 51 * @param object The object of IPC 52 * @return 53 */ 54 AccessibilityOperator(); 55 56 /** 57 * @brief destruct function 58 * @param object The object of IPC 59 * @return 60 */ 61 virtual ~AccessibilityOperator(); 62 63 /** 64 * @brief Get the instance of AccessibilityOperator 65 * @param 66 * @return The instance of AccessibilityOperator 67 */ 68 static AccessibilityOperator &GetInstance(); 69 70 /** 71 * @brief Inner function: Get the object connected from AA to AAMS by channel id. 72 * @param channelId The id matched the object connected from AA to AAMS 73 * @return The object connected from AA to AAMS. 74 */ 75 static sptr<IAccessibleAbilityChannel> GetChannel(int channelId); 76 77 /** 78 * @brief Set the object connected from AA to AAMS and channel id matched. 79 * @param channelId The id matched the object connected from AA to AAMS 80 * @param channel The object connected from AA to AAMS. 81 * @return 82 */ 83 static void AddChannel(const int channelId, const sptr<IAccessibleAbilityChannel> &channel); 84 85 /** 86 * @brief Remove the object connected from AA to AAMS by channel id. 87 * @param channelId The id matched the object connected from AA to AAMS 88 * @return 89 */ 90 static void RemoveChannel(int channelId); 91 92 /** 93 * @brief Get the root component information 94 * @param channelId The id matched the object connected from AA to AAMS 95 * @param elementInfo[out] The root component information 96 * @return 97 */ 98 bool GetRoot(int channelId, AccessibilityElementInfo &elementInfo); 99 100 /** 101 * @brief Get all windows of accessibility. 102 * @param channelId The id matched the object connected from AA to AAMS 103 * @return All windows information of accessibility. 104 */ 105 std::vector<AccessibilityWindowInfo> GetWindows(int channelId); 106 107 /** 108 * @brief Find the node information by accessibility ID. 109 * @param channelId The id matched the object connected from AA to AAMS. 110 * @param elementId: The unique id of the component ID. 111 * @param accessibilityWindowId The window id that the component belongs to. 112 * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also. 113 * PREFETCH_SIBLINGS: Need to make the sister/brothers node info also. 114 * PREFETCH_CHILDREN: Need to make the child node info also. 115 * otherwise: Make the node information by elementId only. 116 * @param elementInfos[out] The components information matched conditions searched. 117 * @return - 118 */ 119 bool SearchElementInfosByAccessibilityId(int channelId, 120 int accessibilityWindowId, int elementId, 121 int mode, std::vector<AccessibilityElementInfo> &elementInfos); 122 123 /** 124 * @brief Find the node information filtered by text. 125 * @param channelId The id matched the object connected from AA to AAMS. 126 * @param elementId: The unique id of the component ID. 127 * @param accessibilityWindowId The window id that the component belongs to. 128 * @param text The filter text. 129 * @param elementInfos[out] The components information matched conditions searched. 130 * @return - 131 */ 132 bool SearchElementInfosByText(int channelId, int accessibilityWindowId, int elementId, 133 const std::string &text, std::vector<AccessibilityElementInfo>& elementInfos); 134 135 /** 136 * @brief Find the focus node information. 137 * @param channelId The id matched the object connected from AA to AAMS. 138 * @param elementId: The unique id of the component ID. 139 * @param accessibilityWindowId The window id that the component belongs to. 140 * @param focusType The type of focus. 141 * FOCUS_TYPE_ACCESSIBILITY: accessibility focus 142 * FOCUS_TYPE_INPUT: text input focus 143 * @param elementInfos[out] The components information matched conditions searched. 144 * @return - 145 */ 146 bool FindFocusedElementInfo(int channelId, int accessibilityWindowId, 147 int elementId, int focusType, AccessibilityElementInfo &elementInfo); 148 149 /** 150 * @brief Find the node information by focus move direction. 151 * @param channelId The id matched the object connected from AA to AAMS. 152 * @param elementId: The unique id of the component ID. 153 * @param accessibilityWindowId The window id that the component belongs to. 154 * @param direction The direction of focus move direction. 155 * Refer to FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD). 156 * @param elementInfos[out] The components information matched conditions searched. 157 * @return - 158 */ 159 bool FocusMoveSearch(int channelId, int accessibilityWindowId, 160 int elementId, int direction, AccessibilityElementInfo &elementInfo); 161 162 /** 163 * @brief Perform the action on the component. 164 * @param channelId The id matched the object connected from AA to AAMS. 165 * @param elementId: The unique id of the component ID. 166 * @param accessibilityWindowId The window id that the component belongs to. 167 * @param action The action triggered on component. 168 * Refer to [AccessibilityElementInfo.ActionType] 169 * @param actionArguments The parameter for action type. such as: 170 * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, 171 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 172 * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, 173 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 174 * action: ACCESSIBILITY_ACTION_NEXT_TEXT, 175 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 176 * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, 177 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 178 * action: ACCESSIBILITY_ACTION_SET_SELECTION, 179 * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, 180 * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) 181 * action: ACCESSIBILITY_ACTION_SET_TEXT, 182 * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") 183 * @return true: Perform action successfully; otherwise is not. 184 */ 185 bool ExecuteAction(int channelId, int accessibilityWindowId, 186 int elementId, int action, std::map<std::string, std::string> &actionArguments); 187 188 /** 189 * @brief Save the elements information searched in ACE side 190 * @param infos The elements info searched by accessibility id. 191 * @param sequenceNum The request id from AA, it is used to match with request and response. 192 * @return 193 */ 194 void SetSearchElementInfoByAccessibilityIdResult(const std::vector<AccessibilityElementInfo> &infos, 195 const int sequenceNum) override; 196 197 /** 198 * @brief Save the elements information searched in ACE side 199 * @param infos The elements info searched by accessibility id. 200 * @param sequenceNum The request id from AA, it is used to match with request and response. 201 * @return 202 */ 203 void SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> &infos, 204 const int sequenceNum) override; 205 206 /** 207 * @brief Save the element information searched in ACE side 208 * @param infos The element info searched by accessibility id. 209 * @param sequenceNum The request id from AA, it is used to match with request and response. 210 * @return 211 */ 212 void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info, const int sequenceNum) override; 213 214 /** 215 * @brief Save the element information searched in ACE side 216 * @param infos The element info searched by accessibility id. 217 * @param sequenceNum The request id from AA, it is used to match with request and response. 218 * @return 219 */ 220 void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int sequenceNum) override; 221 222 /** 223 * @brief Save the result of action executed in ACE. 224 * @param succeeded True: The action is executed successfully; otherwise is false. 225 * @param sequenceNum The request id from AA, it is used to match with request and response. 226 * @return 227 */ 228 void SetExecuteActionResult(const bool succeeded, const int sequenceNum) override; 229 230 /** 231 * @brief Wrap the function of function expect for ACE related 232 * @param channelId The id matched the object connected from AA to AAMS. 233 * @param action: The common action 234 * @return true: Perform successfully; otherwise is not. 235 */ 236 bool ExecuteCommonAction(const int channelId, const int action); 237 238 /** 239 * @brief Wrap the function of function expect for ACE related 240 * @param channelId The id matched the object connected from AA to AAMS. 241 * @param handled True: That is handled; otherwise is not. 242 * @param sequence The number of sequence. 243 * @return - 244 */ 245 void SetOnKeyPressEventResult(const int channelId, const bool handled, const int sequence); 246 247 /** 248 * @brief Wrap the function of function expect for ACE related 249 * @param channelId The id matched the object connected from AA to AAMS. 250 * @param displayId The display id 251 * @return - 252 */ 253 float GetDisplayResizeScale(const int channelId, const int displayId); 254 255 /** 256 * @brief Wrap the function of function expect for ACE related 257 * @param channelId The id matched the object connected from AA to AAMS. 258 * @param displayId The display id 259 * @return - 260 */ 261 float GetDisplayResizeCenterX(const int channelId, const int displayId); 262 263 /** 264 * @brief Wrap the function of function expect for ACE related 265 * @param channelId The id matched the object connected from AA to AAMS. 266 * @param displayId The display id 267 * @return - 268 */ 269 float GetDisplayResizeCenterY(const int channelId, const int displayId); 270 271 /** 272 * @brief Wrap the function of function expect for ACE related 273 * @param channelId The id matched the object connected from AA to AAMS. 274 * @param displayId The display id 275 * @return The range displayed. 276 */ 277 Rect GetDisplayResizeRect(const int channelId, const int displayId); 278 279 /** 280 * @brief Wrap the function of function expect for ACE related 281 * @param channelId The id matched the object connected from AA to AAMS. 282 * @param displayId The display id 283 * @param animate true: It is animation; otherwise is not. 284 * @return true: Reset successfully; otherwise is not. 285 */ 286 bool ResetDisplayResize(const int channelId, const int displayId, const bool animate); 287 288 /** 289 * @brief Wrap the function of function expect for ACE related 290 * @param channelId The id matched the object connected from AA to AAMS. 291 * @param displayId The display id 292 * @param scale The value of scaled. 293 * @param animate true: It is animation; otherwise is not. 294 * @param centerX coordinate X. 295 * @param centerY coordinate Y. 296 * @return true: Resize successfully; otherwise is not. 297 */ 298 bool SetDisplayResizeScaleAndCenter(const int channelId, const int displayId, const float scale, 299 const float centerX, const float centerY, const bool animate); 300 301 /** 302 * @brief Wrap the function of function expect for ACE related 303 * @param channelId The id matched the object connected from AA to AAMS. 304 * @param sequenceNum The number of sequence. 305 * @param gestureSteps The value of gesture. 306 * @return - 307 */ 308 void SendSimulateGesture(const int channelId, const int sequenceNum, 309 const std::vector<GesturePathDefine> &gestureSteps); 310 private: 311 static const uint32_t MAX_REQUEST = 0x7FFFFFFF; 312 static std::vector<sptr<AccessibilityOperator>> instances_; 313 static std::map<int, sptr<IAccessibleAbilityChannel>> channels_; 314 AccessibilityElementAsyncOperatorMng asyncElementOperatorMng_ = {}; 315 AccessibilityElementInfo accessibilityInfoResult_ = {}; 316 std::vector<AccessibilityElementInfo> elementInfosResult_; 317 std::vector<AccessibilityWindowInfo> windows_; 318 bool executeActionResult_ = false; 319 static std::recursive_mutex mutex_; 320 }; 321 } // namespace Accessibility 322 } // namespace OHOS 323 #endif