• 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_PROXY_H
17 #define ACCESSIBLE_ABILITY_CHANNEL_PROXY_H
18 
19 #include "accessibility_ipc_interface_code.h"
20 #include "iaccessible_ability_channel.h"
21 #include "iremote_proxy.h"
22 
23 namespace OHOS {
24 namespace Accessibility {
25 class AccessibleAbilityChannelProxy : public IRemoteProxy<IAccessibleAbilityChannel> {
26 public:
27     /**
28      * @brief construct function
29      * @param object The object of IPC
30      */
31     explicit AccessibleAbilityChannelProxy(const sptr<IRemoteObject> &object);
32 
33     /**
34      * @brief destruct function
35      */
36     virtual ~AccessibleAbilityChannelProxy() = default;
37 
38     /**
39      * @brief Searches elementInfo by accessibility id and set the result by callback through the proxy object.
40      * @param accessibilityWindowId The id of accessibility window.
41      * @param elementId The unique id of the component ID.
42      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
43      * @param callback To transfer the element info to ASAC.
44      * @param mode PREFETCH_PREDECESSORS: Need to make the parent element info also.
45      *             PREFETCH_SIBLINGS: Need to make the sister/brothers element info also.
46      *             PREFETCH_CHILDREN: Need to make the child element info also.
47      *             otherwise: Make the element information by elementId only.
48      * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure.
49      */
50     virtual RetError SearchElementInfoByAccessibilityId(const ElementBasicInfo elementBasicInfo,
51         const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback,
52         const int32_t mode, bool isFilter, bool systemApi = false) override;
53 
54     /**
55      * @brief Searches elementInfo by window id and set the result by callback through the proxy object.
56      * @param elementBasicInfo
57      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
58      * @param callback To transfer the element info to ASAC.
59      * @param mode PREFETCH_PREDECESSORS: Need to make the parent element info also.
60      *             PREFETCH_SIBLINGS: Need to make the sister/brothers element info also.
61      *             PREFETCH_CHILDREN: Need to make the child element info also.
62      *             otherwise: Make the element information by elementId only.
63      * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure.
64      */
65     virtual RetError SearchDefaultFocusedByWindowId(const ElementBasicInfo elementBasicInfo,
66         const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback,
67         const int32_t mode, bool isFilter) override;
68 
69     /**
70      * @brief Make the child element information by accessibility ID and filtered by text and
71      *        set the result by callback through the proxy object.
72      * @param accessibilityWindowId The id of accessibility window.
73      * @param elementId: The unique id of the component ID.
74      * @param text  Filter for the child components to matched with the text
75      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
76      * @param callback  To transfer the element info to ASAC and it defined by ASAC.
77      * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure.
78      */
79     virtual RetError SearchElementInfosByText(const int32_t accessibilityWindowId, const int64_t elementId,
80         const std::string &text, const int32_t requestId,
81         const sptr<IAccessibilityElementOperatorCallback> &callback, bool systemApi = false) override;
82 
83     /**
84      * @brief Make the element information of the component focused
85      *        by the focus type specified through the proxy object.
86      * @param accessibilityWindowId The id of accessibility window.
87      * @param elementId: The unique id of the component ID.
88      * @param focusType FOCUS_TYPE_ACCESSIBILITY: accessibility focus
89      *                  FOCUS_TYPE_INPUT: text input focus
90      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
91      * @param callback  To transfer the element info to ASAC and it defined by ASAC.
92      * @return Return RET_OK if find elementInfo successfully, otherwise refer to the RetError for the failure.
93      */
94     virtual RetError FindFocusedElementInfo(const int32_t accessibilityWindowId, const int64_t elementId,
95         const int32_t focusType, const int32_t requestId,
96         const sptr<IAccessibilityElementOperatorCallback> &callback, bool systemApi = false) override;
97 
98     /**
99      * @brief Make the element info by current focus move direction through the proxy object.
100      * @param accessibilityWindowId The id of accessibility window.
101      * @param elementId: The unique id of the component ID.
102      * @param direction Refer to AccessibilityElementInfo.FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD)
103      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
104      * @param callback  To transfer the element info to ASAC and it defined by ASAC.
105      * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure.
106      */
107     virtual RetError FocusMoveSearch(const int32_t accessibilityWindowId, const int64_t elementId,
108         const int32_t direction, const int32_t requestId,
109         const sptr<IAccessibilityElementOperatorCallback> &callback, bool systemApi = false) override;
110 
111     /**
112      * @brief To perform action through the proxy object.
113      * @param accessibilityWindowId The id of accessibility window.
114      * @param elementId: The unique id of the component ID.
115      * @param action Refer to [AccessibilityElementInfo.ActionType]
116      * @param actionArguments The parameter for action type.
117      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
118      * @param callback  To transfer the node info to ASAC and it defined by ASAC.
119      * @return Return RET_OK if perform action successfully, otherwise refer to the RetError for the failure.
120      */
121     virtual RetError ExecuteAction(const int32_t accessibilityWindowId, const int64_t elementId, const int32_t action,
122         const std::map<std::string, std::string> &actionArguments, const int32_t requestId,
123         const sptr<IAccessibilityElementOperatorCallback> &callback) override;
124 
125     /**
126      * @brief Get the result of Cursor Position through the proxy object.
127      * @param accessibilityWindowId The target winid.
128      * @param elementId The element Id.
129      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
130      * @param callback  To transfer the node info to ASAC and it defined by ASAC.
131      * @return Return RET_OK if Cursor Position successfully, otherwise refer to the RetError for the failure.
132      */
133     virtual RetError GetCursorPosition(const int32_t accessibilityWindowId, const int64_t elementId,
134         const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback) override;
135 
136     /**
137      * @brief Get the window information related with the event
138      * @param windowId The window id.
139      * @param windowInfo The window information.
140      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
141      */
142     virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override;
143 
144     /**
145      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
146      * @param windows The information of windows.
147      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
148      */
149     virtual RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows, bool systemApi = false) override;
150 
151     /**
152      * @brief Package and transfer isenable to the data table
153      * @param isEnable The information of status.
154      * @return Return RET_OK if obtains screen curtain status successfully.
155      */
156     virtual RetError EnableScreenCurtain(bool isEnable) override;
157 
158     /**
159      * @brief Hold running lock to prevent screen turning off automatically.
160      * @param null.
161      * @return Return RET_OK if hold running lock successfully, otherwise refer to the RetError for the failure.
162      */
163     virtual RetError HoldRunningLock() override;
164 
165     /**
166      * @brief Unhold running lock to prevent screen turning off automatically
167      * @param null.
168      * @return Return RET_OK if Unhold running lock successfully, otherwise refer to the RetError for the failure.
169      */
170     virtual RetError UnholdRunningLock() override;
171 
172     /**
173      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
174      * @param displayId the id of display
175      * @param windows The information of windows.
176      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
177      */
178     virtual RetError GetWindowsByDisplayId(const uint64_t displayId,
179         std::vector<AccessibilityWindowInfo> &windows, bool systemApi = false) override;
180 
181     /**
182      * @brief Set the result of key press event through the proxy object.
183      * @param handled The result of key press event, true if the event has been consumed, otherwise false.
184      * @param sequence The sequence of key press event result.
185      */
186     virtual void SetOnKeyPressEventResult(const bool handled, const int32_t sequence) override;
187 
188     /**
189      * @brief Send simulation gesture through the proxy object.
190      * @param gesturePath The gesture path to send.
191      * @return Return RET_OK if gesture injection is successfully, otherwise refer to the RetError for the failure.
192      */
193     virtual RetError SendSimulateGesture(const std::shared_ptr<AccessibilityGestureInjectPath>& gesturePath) override;
194 
195     /**
196      * @brief Set target bundle names.
197      * @param targetBundleNames The target bundle name
198      * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure.
199      */
200     virtual RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames) override;
201 
202     /**
203      * @brief Set is register disconnectCallback.
204      * @param targetBundleNames The isRegister state
205      * @return Return RET_OK if sets isRegister callback successfully, otherwise refer to the RetError for the failure.
206      */
207     virtual RetError SetIsRegisterDisconnectCallback(bool isRegister) override;
208 
209     /**
210      * @brief Notify disconnect.
211      * @return Return RET_OK if notifyDisconnect successfully, otherwise refer to the RetError for the failure.
212      */
213     virtual RetError NotifyDisconnect() override;
214 
215     /**
216      * @brief Configure events.
217      * @return Return RET_OK if ConfigureEvents successfully, otherwise refer to the RetError for the failure.
218      */
219     virtual RetError ConfigureEvents(const std::vector<uint32_t> needEvents) override;
220 
221     /**
222      * @brief Search element infos by specific property.
223      * @param elementBasicInfo The basic info of the element.
224      * @param param The specific property parameters.
225      * @param requestId The request id from AA, it is used to match with request and response.
226      * @param callback The callback to return the result.
227      * @return Returns 0 on success, others on failure.
228      */
229     virtual void SearchElementInfoBySpecificProperty(const ElementBasicInfo elementBasicInfo,
230         const SpecificPropertyParam& param, const int32_t requestId,
231         const sptr<IAccessibilityElementOperatorCallback> &callback) override;
232 
233 private:
234     /**
235      * @brief Write the descriptor of IPC.
236      * @param data It is include the descriptor of IPC.
237      * @return true: Write the descriptor successfully; otherwise is not.
238      */
239     bool WriteInterfaceToken(MessageParcel &data);
240     /**
241      * @brief Send the command data from proxy to stub in IPC mechanism.
242      * @param code The code matched the function called.
243      * @param data Serializable data
244      * @param reply The response of IPC
245      * @param option The option parameter of IPC,such as: async,sync
246      * @return true: Write the descriptor successfully; otherwise is not.
247      */
248     bool SendTransactCmd(AccessibilityInterfaceCode code, MessageParcel &data,
249         MessageParcel &reply,  MessageOption &option);
250     static inline BrokerDelegator<AccessibleAbilityChannelProxy> delegator;
251 };
252 } // namespace Accessibility
253 } // namespace OHOS
254 #endif // ACCESSIBLE_ABILITY_CHANNEL_PROXY_H