• 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 Find the node information by accessibility ID.
99      * @param accessibilityWindowId The window id that the component belongs to.
100      * @param elementId: The unique id of the component ID.
101      * @param mode PREFETCH_PREDECESSORS: Need to make the parent node info also.
102      *              PREFETCH_SIBLINGS: Need to make the sister/brothers node info also.
103      *              PREFETCH_CHILDREN: Need to make the child node info also.
104      *              otherwise: Make the node information by elementId only.
105      * @param elementInfos[out] The components information matched conditions searched.
106      * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure.
107      */
108     RetError SearchElementInfosByAccessibilityId(int32_t accessibilityWindowId, int64_t elementId,
109         int32_t mode, std::vector<AccessibilityElementInfo> &elementInfos);
110 
111     /**
112      * @brief Get the window information related with the event
113      * @param windowId The window id.
114      * @param windowInfo The window information.
115      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
116      */
117     RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo);
118 
119     /**
120      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
121      * @param windows The information of windows.
122      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
123      */
124     RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows);
125 
126     /**
127      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
128      * @param displayId the id of display
129      * @param windows The information of windows.
130      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
131      */
132     RetError GetWindows(const uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) const;
133 
134     /**
135      * @brief Find the node information filtered by text.
136      * @param accessibilityWindowId The window id that the component belongs to.
137      * @param elementId: The unique id of the component ID.
138      * @param text The filter text.
139      * @param elementInfos[out] The components information matched conditions searched.
140      * @return Return RET_OK if search element info successfully, otherwise refer to the RetError for the failure.
141      */
142     RetError SearchElementInfosByText(int32_t accessibilityWindowId, int64_t elementId,
143         const std::string &text, std::vector<AccessibilityElementInfo> &elementInfos);
144 
145     /**
146      * @brief Find the node information by focus move direction.
147      * @param accessibilityWindowId The window id that the component belongs to.
148      * @param elementId: The unique id of the component ID.
149      * @param direction The direction of focus move direction.
150      *                  Refer to FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD).
151      * @param elementInfo[out] The components information matched conditions searched.
152      * @return Return RET_OK if find element info successfully, otherwise refer to the RetError for the failure.
153      */
154     RetError FocusMoveSearch(int32_t accessibilityWindowId,
155         int64_t elementId, int32_t direction, AccessibilityElementInfo &elementInfo);
156 
157     /**
158      * @brief Set target bundle names.
159      * @param targetBundleNames The target bundle name
160      * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure.
161      */
162     RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames);
163 
164 private:
165     int32_t GenerateRequestId();
166 
167     int32_t channelId_ = INVALID_CHANNEL_ID;
168     int32_t accessibilityFocusedWindowId_ = INVALID_WINDOW_ID;
169     sptr<IAccessibleAbilityChannel> proxy_ = nullptr;
170     std::atomic<int> requestId_ = 0;
171 };
172 } // namespace Accessibility
173 } // namespace OHOS
174 #endif // ACCESSIBLE_ABILITY_CHANNEL_CLIENT_H