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 Get the window information related with the event
129      * @param windowId The window id.
130      * @param windowInfo The window information.
131      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
132      */
133     RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo);
134 
135     /**
136      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
137      * @param windows The information of windows.
138      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
139      */
140     RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows);
141 
142     /**
143      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
144      * @param displayId the id of display
145      * @param windows The information of windows.
146      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
147      */
148     RetError GetWindows(const uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) const;
149 
150     /**
151      * @brief Find the node information filtered by text.
152      * @param accessibilityWindowId The window id that the component belongs to.
153      * @param elementId: The unique id of the component ID.
154      * @param text The filter text.
155      * @param elementInfos[out] The components information matched conditions searched.
156      * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure.
157      */
158     RetError SearchElementInfosByText(int32_t accessibilityWindowId, int64_t elementId,
159         const std::string &text, std::vector<AccessibilityElementInfo> &elementInfos);
160 
161     /**
162      * @brief Find the node information by focus move direction.
163      * @param accessibilityWindowId The window id that the component belongs to.
164      * @param elementId: The unique id of the component ID.
165      * @param direction The direction of focus move direction.
166      *                  Refer to FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD).
167      * @param elementInfo[out] The components information matched conditions searched.
168      * @return Return RET_OK if find element info successfully, otherwise refer to the RetError for the failure.
169      */
170     RetError FocusMoveSearch(int32_t accessibilityWindowId,
171         int64_t elementId, int32_t direction, AccessibilityElementInfo &elementInfo);
172 
173     /**
174      * @brief Set target bundle names.
175      * @param targetBundleNames The target bundle name
176      * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure.
177      */
178     RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames);
179 
180 private:
181     int32_t GenerateRequestId();
182 
183     int32_t channelId_ = INVALID_CHANNEL_ID;
184     int32_t accessibilityFocusedWindowId_ = INVALID_WINDOW_ID;
185     int64_t accessibilityFocusedElementId_ = INVALID_WINDOW_ID;
186     sptr<IAccessibleAbilityChannel> proxy_ = nullptr;
187     std::atomic<int> requestId_ = 0;
188 };
189 } // namespace Accessibility
190 } // namespace OHOS
191 #endif // ACCESSIBLE_ABILITY_CHANNEL_CLIENT_H