• 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 "i_accessible_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     ~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);
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 To return the result of cursor position.
106      * @param accessibilityWindowId The window id that the component belongs to.
107      * @param elementId: The unique id of the component ID.
108      * @param position: The position of the cursor to get.
109      * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure.
110      */
111     RetError GetCursorPosition(int32_t accessibilityWindowId, int64_t elementId, int32_t &position);
112 
113     /**
114      * @brief Find the node information by accessibility ID.
115      * @param accessibilityWindowId The window id that the component belongs to.
116      * @param elementId: The unique id of the component ID.
117      * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also.
118      *              PREFETCH_SIBLINGS: Need to make the sister/brothers node info also.
119      *              PREFETCH_CHILDREN: Need to make the child node info also.
120      *              otherwise: Make the node information by elementId only.
121      * @param elementInfos[out] The components information matched conditions searched.
122      * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure.
123      */
124     RetError SearchElementInfosByAccessibilityId(int32_t accessibilityWindowId, int64_t elementId,
125         int32_t mode, std::vector<AccessibilityElementInfo> &elementInfos, int32_t treeId, bool isFilter = false);
126 
127     /**
128      * @brief Find the node information by window ID.
129      * @param windowId: 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 SearchDefaultFocusedByWindowId(const int32_t windowId, int64_t elementId,
139         int32_t mode, std::vector<AccessibilityElementInfo> &elementInfos, int32_t treeId, bool isFilter = false);
140 
141     /**
142      * @brief Get the window information related with the event
143      * @param windowId The window id.
144      * @param windowInfo The window information.
145      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
146      */
147     RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo);
148 
149     /**
150      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
151      * @param windows The information of windows.
152      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
153      */
154     RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows);
155 
156     /**
157      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
158      * @param displayId the id of display
159      * @param windows The information of windows.
160      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
161      */
162     RetError GetWindows(const uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) const;
163 
164     /**
165      * @brief Find the node information filtered by text.
166      * @param accessibilityWindowId The window id that the component belongs to.
167      * @param elementId: The unique id of the component ID.
168      * @param text The filter text.
169      * @param elementInfos[out] The components information matched conditions searched.
170      * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure.
171      */
172     RetError SearchElementInfosByText(int32_t accessibilityWindowId, int64_t elementId,
173         const std::string &text, std::vector<AccessibilityElementInfo> &elementInfos);
174 
175     /**
176      * @brief Find the node information by focus move direction.
177      * @param accessibilityWindowId The window id that the component belongs to.
178      * @param elementId: The unique id of the component ID.
179      * @param direction The direction of focus move direction.
180      *                  Refer to FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD).
181      * @param elementInfo[out] The components information matched conditions searched.
182      * @return Return RET_OK if find element info successfully, otherwise refer to the RetError for the failure.
183      */
184     RetError FocusMoveSearch(int32_t accessibilityWindowId,
185         int64_t elementId, int32_t direction, AccessibilityElementInfo &elementInfo);
186 
187     /**
188      * @brief Set target bundle names.
189      * @param targetBundleNames The target bundle name
190      * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure.
191      */
192     RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames);
193 
194 private:
195     int32_t GenerateRequestId();
196 
197     int32_t channelId_ = INVALID_CHANNEL_ID;
198     int32_t accessibilityFocusedWindowId_ = INVALID_WINDOW_ID;
199     int64_t accessibilityFocusedElementId_ = INVALID_WINDOW_ID;
200     sptr<IAccessibleAbilityChannel> proxy_ = nullptr;
201     std::atomic<int> requestId_ = 0;
202 };
203 } // namespace Accessibility
204 } // namespace OHOS
205 #endif // ACCESSIBLE_ABILITY_CHANNEL_CLIENT_H