• 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_CHANNEL_CLIENT_H
17 #define ACCESSIBLE_ABILITY_CHANNEL_CLIENT_H
18 
19 #include <atomic>
20 #include "iaccessible_ability_channel.h"
21 
22 namespace OHOS {
23 namespace Accessibility {
24 class AccessibleAbilityChannelClient {
25 public:
26     /**
27      * @brief The constructor of AccessibleAbilityChannelClient.
28      * @param channelId The id of channel.
29      * @param channel The client of channel.
30      */
AccessibleAbilityChannelClient(const int32_t channelId,const sptr<IAccessibleAbilityChannel> & channel)31     explicit AccessibleAbilityChannelClient(const int32_t channelId,
32         const sptr<IAccessibleAbilityChannel> &channel) : channelId_(channelId), proxy_(channel) {}
33 
34     /**
35      * @brief The deconstructor of AccessibleAbilityChannelClient.
36      */
37     virtual ~AccessibleAbilityChannelClient() = default;
38 
39     /**
40      * @brief Get remote object of IAccessibleAbilityChannel
41      * @return Return remote object.
42      */
43     sptr<IRemoteObject> GetRemote();
44 
45     /**
46      * @brief Set the result of key press event.
47      * @param handled The result of OnKeyPressEvent.
48      * @param sequence The sequence of key press event.
49      */
50     void SetOnKeyPressEventResult(const bool handled, const int32_t sequence);
51 
52     /**
53      * @brief Find the focus element information.
54      * @param accessibilityWindowId The window id that the component belongs to.
55      * @param elementId: The unique id of the component ID.
56      * @param focusType The type of focus.
57      *                  FOCUS_TYPE_ACCESSIBILITY: accessibility focus
58      *                  FOCUS_TYPE_INPUT: text input focus
59      * @param elementInfo[out] The components information matched conditions searched.
60      * @return Return RET_OK if finds focus element info successfully, otherwise refer to the RetError for the failure.
61      */
62     RetError FindFocusedElementInfo(int32_t accessibilityWindowId, int64_t elementId,
63         int32_t focusType, AccessibilityElementInfo &elementInfo, bool systemApi = false);
64 
65     /**
66      * @brief Send simulate gesture to aams.
67      * @param gesturePath The path of gesture.
68      * @return Return RET_OK if gesture injection is successfully, otherwise refer to the RetError for the failure.
69      */
70     RetError SendSimulateGesture(const std::shared_ptr<AccessibilityGestureInjectPath> &gesturePath);
71 
72     /**
73      * @brief execute the action on the component.
74      * @param accessibilityWindowId The window id that the component belongs to.
75      * @param elementId: The unique id of the component ID.
76      * @param action The action triggered on component.
77      *               Refer to [AccessibilityElementInfo.ActionType]
78      * @param actionArguments The parameter for action type. such as:
79      *      action: ACCESSIBILITY_ACTION_NEXT_HTML_ITEM,
80      *                  actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType)
81      *      action: ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM,
82      *                  actionArguments(ACTION_ARGU_HTML_ELEMENT,HtmlItemType)
83      *      action: ACCESSIBILITY_ACTION_NEXT_TEXT,
84      *                  actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX)
85      *      action: ACCESSIBILITY_ACTION_PREVIOUS_TEXT,
86      *                  actionArguments(ACTION_ARGU_MOVE_UNIT,MOVE_UNIT_XXX)
87      *      action: ACCESSIBILITY_ACTION_SET_SELECTION,
88      *                  actionArguments({ACTION_ARGU_SELECT_TEXT_START,"1"(start location)},
89      *                                  {ACTION_ARGU_SELECT_TEXT_END,"10"(end location)})
90      *      action: ACCESSIBILITY_ACTION_SET_TEXT,
91      *                  actionArguments(ACTION_ARGU_SET_TEXT,"the text of setted")
92      * @return RET_OK: execute action successfully; otherwise refer to the RetError for the failure.
93      */
94     RetError ExecuteAction(int32_t accessibilityWindowId,
95         int64_t elementId, int32_t action, const std::map<std::string, std::string> &actionArguments);
96 
97     /**
98      * @brief Package status to send server data.
99      * @param isEnable status info.
100      * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure.
101      */
102     RetError EnableScreenCurtain(bool isEnable);
103 
104     /**
105      * @brief Hold running lock to prevent screen turning off automatically.
106      * @param null.
107      * @return Return RET_OK if hold running lock successfully, otherwise refer to the RetError for the failure.
108      */
109     RetError HoldRunningLock();
110 
111     /**
112      * @brief Unhold running lock to prevent screen turning off automatically
113      * @param null.
114      * @return Return RET_OK if Unhold running lock successfully, otherwise refer to the RetError for the failure.
115      */
116     RetError UnholdRunningLock();
117 
118     /**
119      * @brief To return the result of cursor position.
120      * @param accessibilityWindowId The window id that the component belongs to.
121      * @param elementId: The unique id of the component ID.
122      * @param position: The position of the cursor to get.
123      * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure.
124      */
125     RetError GetCursorPosition(int32_t accessibilityWindowId, int64_t elementId, int32_t &position);
126 
127     /**
128      * @brief Find the node information by accessibility ID.
129      * @param accessibilityWindowId The window id that the component belongs to.
130      * @param elementId: The unique id of the component ID.
131      * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also.
132      *              PREFETCH_SIBLINGS: Need to make the sister/brothers node info also.
133      *              PREFETCH_CHILDREN: Need to make the child node info also.
134      *              otherwise: Make the node information by elementId only.
135      * @param elementInfos[out] The components information matched conditions searched.
136      * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure.
137      */
138     RetError SearchElementInfosByAccessibilityId(int32_t accessibilityWindowId, int64_t elementId, int32_t mode,
139         std::vector<AccessibilityElementInfo>& elementInfos, int32_t treeId, bool isFilter = false,
140         bool systemApi = false);
141 
142     /**
143      * @brief Find the node information by window ID.
144      * @param windowId: The window id that the component belongs to.
145      * @param elementId: The unique id of the component ID.
146      * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also.
147      *              PREFETCH_SIBLINGS: Need to make the sister/brothers node info also.
148      *              PREFETCH_CHILDREN: Need to make the child node info also.
149      *              otherwise: Make the node information by elementId only.
150      * @param elementInfos[out] The components information matched conditions searched.
151      * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure.
152      */
153     RetError SearchDefaultFocusedByWindowId(const int32_t windowId, int64_t elementId,
154         int32_t mode, std::vector<AccessibilityElementInfo> &elementInfos, int32_t treeId, bool isFilter = false);
155 
156     /**
157      * @brief Get the window information related with the event
158      * @param windowId The window id.
159      * @param windowInfo The window information.
160      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
161      */
162     RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo);
163 
164     /**
165      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
166      * @param windows The information of windows.
167      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
168      */
169     RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows, bool systemApi = false);
170 
171     /**
172      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
173      * @param displayId the id of display
174      * @param windows The information of windows.
175      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
176      */
177     RetError GetWindows(
178         const uint64_t displayId, std::vector<AccessibilityWindowInfo>& windows, bool systemApi = false) const;
179 
180     /**
181      * @brief Find the node information filtered by text.
182      * @param accessibilityWindowId The window id that the component belongs to.
183      * @param elementId: The unique id of the component ID.
184      * @param text The filter text.
185      * @param elementInfos[out] The components information matched conditions searched.
186      * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure.
187      */
188     RetError SearchElementInfosByText(int32_t accessibilityWindowId, int64_t elementId,
189         const std::string &text, std::vector<AccessibilityElementInfo> &elementInfos, bool systemApi = false);
190 
191     /**
192      * @brief Find the node information by focus move direction.
193      * @param accessibilityWindowId The window id that the component belongs to.
194      * @param elementId: The unique id of the component ID.
195      * @param direction The direction of focus move direction.
196      *                  Refer to FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD).
197      * @param elementInfo[out] The components information matched conditions searched.
198      * @return Return RET_OK if find element info successfully, otherwise refer to the RetError for the failure.
199      */
200     RetError FocusMoveSearch(int32_t accessibilityWindowId,
201         int64_t elementId, int32_t direction, AccessibilityElementInfo &elementInfo, bool systemApi = false);
202 
203     /**
204      * @brief Set target bundle names.
205      * @param targetBundleNames The target bundle name
206      * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure.
207      */
208     RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames);
209 
210     /**
211      * @brief Set is register disconnectCallback.
212      * @param isRegister The isRegister state
213      * @return Return RET_OK if sets isRegister callback successfully, otherwise refer to the RetError for the failure.
214      */
215     RetError SetIsRegisterDisconnectCallback(bool isRegister);
216 
217     /**
218      * @brief Notify disconnect.
219      * @return Return RET_OK if notifyDisconnect successfully, otherwise refer to the RetError for the failure.
220      */
221     RetError NotifyDisconnect();
222 
223     /**
224      * @brief Config need events.
225      * @param needEvents The need events.
226      * @return Return RET_OK if config need events successfully, otherwise refer to the RetError for the failure.
227      */
228     virtual RetError ConfigureEvents(const std::vector<uint32_t> needEvents);
229 
230     /*
231      * @brief Search element infos by specific property.
232      * @param accessibilityWindowId The window id that the component belongs to.
233      * @param elementId  The unique id of the component ID.
234      * @param param The specific property parameters.
235      * @param infos The element infos searched by specific property.
236      * @param elementInfos The element infos searched by specific property.
237      * @param treeId The tree id of the component.
238      * @return Returns 0 on success, others on failure.
239      */
240     RetError SearchElementInfosBySpecificProperty(int32_t accessibilityWindowId, int64_t elementId,
241         const SpecificPropertyParam& param, std::vector<AccessibilityElementInfo> &infos,
242         std::vector<AccessibilityElementInfo> &elementInfos,
243         int32_t treeId);
244 
245 private:
246     int32_t GenerateRequestId();
247 
248     /**
249      * @brief Validate and process element infos with main window ID setting
250      * @param sourceInfos The source element infos to validate and process
251      * @param targetInfos The target vector to store processed infos
252      * @param clearInfos The vector to clear
253      * @param accessibilityWindowId The window ID to set for all elements
254      * @param logType The type name for logging
255      * @return Returns RET_OK on success, RET_ERR_INVALID_ELEMENT_INFO_FROM_ACE on validation failure
256      */
257     RetError ValidateAndProcessElementInfos(const std::vector<AccessibilityElementInfo>& sourceInfos,
258         std::vector<AccessibilityElementInfo>& targetInfos,
259         std::vector<AccessibilityElementInfo>& clearInfos,
260         int32_t accessibilityWindowId,
261         const std::string& logType);
262 
263     int32_t channelId_ = INVALID_CHANNEL_ID;
264     int32_t accessibilityFocusedWindowId_ = INVALID_WINDOW_ID;
265     int64_t accessibilityFocusedElementId_ = INVALID_WINDOW_ID;
266     sptr<IAccessibleAbilityChannel> proxy_ = nullptr;
267     std::atomic<int> requestId_ = 0;
268 };
269 } // namespace Accessibility
270 } // namespace OHOS
271 #endif // ACCESSIBLE_ABILITY_CHANNEL_CLIENT_H