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 ACCESSIBLE_ABILITY_CLIENT_H 17 #define ACCESSIBLE_ABILITY_CLIENT_H 18 19 #include <map> 20 #include <memory> 21 #include "accessibility_element_info.h" 22 #include "accessibility_event_info.h" 23 #include "accessibility_gesture_inject_path.h" 24 #include "accessibility_window_info.h" 25 #include "accessible_ability_listener.h" 26 #include "iremote_object.h" 27 28 namespace OHOS { 29 namespace Accessibility { 30 class AccessibleAbilityClient : public virtual RefBase { 31 public: 32 /** 33 * @brief Destruct 34 */ 35 virtual ~AccessibleAbilityClient() = default; 36 37 /** 38 * @brief Gets an instance of AccessibleAbilityClient. 39 * @return Return an instance of AccessibleAbilityClient. 40 */ 41 static sptr<AccessibleAbilityClient> GetInstance(); 42 43 /** 44 * @brief Gets remote object. 45 * @return Remote object. 46 */ 47 virtual sptr<IRemoteObject> GetRemoteObject() = 0; 48 49 /** 50 * @brief Obtains elementInfo of focus. 51 * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. 52 * @param elementInfo The accessibilityElementInfo of focus. 53 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 54 */ 55 virtual RetError GetFocus(const int32_t focusType, AccessibilityElementInfo &elementInfo) = 0; 56 57 /** 58 * @brief Obtains elementInfo of focus. 59 * @param sourceInfo The source info to get focus. 60 * @param focusType The type of focus. It contains FOCUS_TYPE_INPUT and FOCUS_TYPE_ACCESSIBILITY. 61 * @param elementInfo The accessibilityElementInfo of focus. 62 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 63 */ 64 virtual RetError GetFocusByElementInfo(const AccessibilityElementInfo &sourceInfo, const int32_t focusType, 65 AccessibilityElementInfo &elementInfo) = 0; 66 67 /** 68 * @brief Sends simulate gestures to the screen. 69 * @param gesturePath The gesture which need to send. 70 * @return Return RET_OK if the gesture sends successfully, otherwise refer to the RetError for the failure. 71 */ 72 virtual RetError InjectGesture(const std::shared_ptr<AccessibilityGestureInjectPath> &gesturePath) = 0; 73 74 /** 75 * @brief Obtains elementInfo of the accessible root node. 76 * @param elementInfo The elementInfo of the accessible root node. 77 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 78 */ 79 virtual RetError GetRoot(AccessibilityElementInfo &elementInfo) = 0; 80 81 /** 82 * @brief Obtains elementInfo of the accessible root node. 83 * @param windowInfo The source window info to get root. 84 * @param elementInfo The elementInfo of the accessible root node. 85 * @return Return RET_OK if obtains elementInfo successfully, otherwise refer to the RetError for the failure. 86 */ 87 virtual RetError GetRootByWindow(const AccessibilityWindowInfo &windowInfo, 88 AccessibilityElementInfo &elementInfo) = 0; 89 90 /** 91 * @brief Obtains elementInfos of the accessible root node in batchs. 92 * @param elementInfos ElementInfos of the accessible root node and its recursive subnodes. 93 * @return Return RET_OK if obtains elementInfos successfully, otherwise refer to the RetError for the failure. 94 */ 95 virtual RetError GetRootBatch(std::vector<AccessibilityElementInfo>& elementInfos) = 0; 96 97 /** 98 * @brief Obtains elementInfos of the accessible root node in batchs. 99 * @param windowInfo The source window info to get root. 100 * @param elementInfos ElementInfos of the accessible root node and its recursive subnodes. 101 * @return Return RET_OK if obtains elementInfos successfully, otherwise refer to the RetError for the failure. 102 */ 103 virtual RetError GetRootByWindowBatch(const AccessibilityWindowInfo &windowInfo, 104 std::vector<AccessibilityElementInfo>& elementInfos, bool isFilter = false) = 0; 105 106 /** 107 * @brief Get the window information related with the event 108 * @param windowId The window id. 109 * @param windowInfo The window information. 110 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 111 */ 112 virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) = 0; 113 114 /** 115 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 116 * @param windows The information of windows. 117 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 118 */ 119 virtual RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows) = 0; 120 121 /** 122 * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users. 123 * @param displayId the id of display 124 * @param windows The information of windows. 125 * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure. 126 */ 127 virtual RetError GetWindows(const uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) = 0; 128 129 /** 130 * @brief Gets the next focused node in the specified direction of the currently focused node. 131 * @param elementInfo The source info to get next info. 132 * @param direction Indicates the direction to obtain the next focused node. Refer to FocusMoveDirection 133 * @param nextElementInfo The info of next element. 134 * @return Return RET_OK if gets next elementInfo successfully, otherwise refer to the RetError for the failure. 135 */ 136 virtual RetError GetNext(const AccessibilityElementInfo &elementInfo, const FocusMoveDirection direction, 137 AccessibilityElementInfo &nextElementInfo) = 0; 138 139 /** 140 * @brief Get the child node information by child index. 141 * @param index The index of the child. 142 * @param parent The parent info to get child. 143 * @param child The element info of child. 144 * @return Return RET_OK if gets child elementInfo successfully, otherwise refer to the RetError for the failure. 145 */ 146 virtual RetError GetChildElementInfo(const int32_t index, const AccessibilityElementInfo &parent, 147 AccessibilityElementInfo &child) = 0; 148 149 /** 150 * @brief Get the children node information 151 * @param parent The parent info to get children. 152 * @param children The element info of children. 153 * @return Return RET_OK if gets children elementInfo successfully, otherwise refer to the RetError for the failure. 154 */ 155 virtual RetError GetChildren(const AccessibilityElementInfo &parent, 156 std::vector<AccessibilityElementInfo> &children) = 0; 157 158 /** 159 * @brief Searches for node information based on the specified content. 160 * @param elementInfo The source info. 161 * @param text specified content 162 * @param elementInfos The element infos of specified content. 163 * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. 164 */ 165 virtual RetError GetByContent(const AccessibilityElementInfo &elementInfo, const std::string &text, 166 std::vector<AccessibilityElementInfo> &elementInfos) = 0; 167 168 /** 169 * @brief Get the node information related with the event 170 * @param eventInfo The source info to get source. 171 * @param elementInfo The element info of source. 172 * @return Return RET_OK if gets elementInfos successfully, otherwise refer to the RetError for the failure. 173 */ 174 virtual RetError GetSource(const AccessibilityEventInfo &eventInfo, AccessibilityElementInfo &elementInfo) = 0; 175 176 /** 177 * @brief Get Parent node information 178 * @param child The child element info to get parent. 179 * @param parent The parent element info. 180 * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. 181 */ 182 virtual RetError GetParentElementInfo(const AccessibilityElementInfo &child, AccessibilityElementInfo &parent) = 0; 183 184 /** 185 * @brief Get node information based on element id in active window. 186 * @param elementId The target element id. 187 * @param windowId The target window id. 188 * @param targetElementInfo The element info of specified content. 189 * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. 190 */ 191 virtual RetError GetByElementId(const int64_t elementId, const int32_t windowId, 192 AccessibilityElementInfo &targetElementInfo) = 0; 193 194 /** 195 * @brief Get node information based on inspectorKey in active window. 196 * @param inspectorKey The target inspectorKey. 197 * @param elementInfo The element info of specified content. 198 * @return Return RET_OK if gets info successfully, otherwise refer to the RetError for the failure. 199 */ 200 virtual RetError SearchElementInfoByInspectorKey(const std::string &inspectorKey, 201 AccessibilityElementInfo &elementInfo) = 0; 202 203 /** 204 * @brief Executes a specified action. 205 * @param elementInfo The source info to execute action. 206 * @param action: the action type 207 * @param actionArguments: The parameter for action type. such as: 208 * action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM, 209 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 210 * action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM, 211 * actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType) 212 * action: ACCESSIBILITY_ACTION_NEXT_TEXT, 213 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 214 * action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT, 215 * actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX) 216 * action: ACCESSIBILITY_ACTION_SET_SELECTION, 217 * actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)}, 218 * {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)}) 219 * action: ACCESSIBILITY_ACTION_SET_TEXT, 220 * actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted") 221 * @return Return RET_OK if performs action succeed, otherwise refer to the RetError for the failure. 222 */ 223 virtual RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action, 224 const std::map<std::string, std::string> &actionArguments) = 0; 225 226 /** 227 * @brief Enable status value. 228 * @param isEnable flag Screen Curtain. 229 * @return Return RET_OK if registers listener successfully, otherwise refer to the RetError for the failure. 230 */ 231 virtual RetError EnableScreenCurtain(bool isEnable) = 0; 232 233 /** 234 * @brief To return the result of cursor position. 235 * @param elementInfo The source info to cursor position. 236 * @param position: The position of the cursor to get. 237 */ 238 virtual RetError GetCursorPosition(const AccessibilityElementInfo &elementInfo, int32_t &position) = 0; 239 /** 240 * @brief Register ability listener. 241 * @param listener The listener to add. 242 * @return Return RET_OK if registers listener successfully, otherwise refer to the RetError for the failure. 243 */ 244 virtual RetError RegisterAbilityListener(const std::shared_ptr<AccessibleAbilityListener> &listener) = 0; 245 246 /** 247 * @brief Set target bundle names. 248 * @param targetBundleNames The target bundle name 249 * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure. 250 */ 251 virtual RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames) = 0; 252 253 /** 254 * @brief Set cache mode. 255 * The mode is used for functions: GetRoot, GetRootByWindow, GetChildElementInfo, 256 * GetChildren, GetSource, GetParentElementInfo. 257 * @param cacheMode The cache mode. It includes: 258 * PREFETCH_PREDECESSORS: cache the parent node info also. 259 * PREFETCH_SIBLINGS: cache the sister/brothers node info also. 260 * PREFETCH_CHILDREN: cache the child node info also. 261 * otherwise: no cache. 262 * @return Return RET_OK if sets cache mode successfully, otherwise refer to the RetError for the failure. 263 */ 264 virtual RetError SetCacheMode(const int32_t cacheMode) = 0; 265 266 /** 267 * @brief Find the node information by accessibility ID. 268 * @param accessibilityWindowId The window id that the component belongs to. 269 * @param elementId: The unique id of the component ID. 270 * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also. 271 * PREFETCH_SIBLINGS: Need to make the sister/brothers node info also. 272 * PREFETCH_CHILDREN: Need to make the child node info also. 273 * otherwise: Make the node information by elementId only. 274 * @param info[out] The components information matched conditions searched. 275 * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure. 276 */ 277 virtual RetError SearchElementInfoByAccessibilityId(const int32_t windowId, const int64_t elementId, 278 const uint32_t mode, AccessibilityElementInfo &info, bool isFilter = false) = 0; 279 }; 280 } // namespace Accessibility 281 } // namespace OHOS 282 #endif // ACCESSIBLE_ABILITY_CLIENT_H