• 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 #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) = 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 Executes a specified action.
186      * @param elementInfo The source info to execute action.
187      * @param action: the action type
188      * @param actionArguments: The parameter for action type. such as:
189      *      action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM,
190      *                  actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType)
191      *      action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM,
192      *                  actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType)
193      *      action: ACCESSIBILITY_ACTION_NEXT_TEXT,
194      *                  actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX)
195      *      action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT,
196      *                  actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX)
197      *      action: ACCESSIBILITY_ACTION_SET_SELECTION,
198      *                  actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)},
199      *                                  {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)})
200      *      action: ACCESSIBILITY_ACTION_SET_TEXT,
201      *                  actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted")
202      * @return Return RET_OK if performs action succeed, otherwise refer to the RetError for the failure.
203      */
204     virtual RetError ExecuteAction(const AccessibilityElementInfo &elementInfo, const ActionType action,
205         const std::map<std::string, std::string> &actionArguments) = 0;
206 
207     /**
208      * @brief Register ability listener.
209      * @param listener The listener to add.
210      * @return Return RET_OK if registers listener successfully, otherwise refer to the RetError for the failure.
211      */
212     virtual RetError RegisterAbilityListener(const std::shared_ptr<AccessibleAbilityListener> &listener) = 0;
213 
214     /**
215      * @brief Set target bundle names.
216      * @param targetBundleNames The target bundle name
217      * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure.
218      */
219     virtual RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames) = 0;
220 
221     /**
222      * @brief Set cache mode.
223      *        The mode is used for functions: GetRoot, GetRootByWindow, GetChildElementInfo,
224      *        GetChildren, GetSource, GetParentElementInfo.
225      * @param cacheMode The cache mode. It includes:
226      *             PREFETCH_PREDECESSORS: cache the parent node info also.
227      *             PREFETCH_SIBLINGS: cache the sister/brothers node info also.
228      *             PREFETCH_CHILDREN: cache the child node info also.
229      *             otherwise: no cache.
230      * @return Return RET_OK if sets cache mode successfully, otherwise refer to the RetError for the failure.
231      */
232     virtual RetError SetCacheMode(const int32_t cacheMode) = 0;
233 };
234 } // namespace Accessibility
235 } // namespace OHOS
236 #endif // ACCESSIBLE_ABILITY_CLIENT_H