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 "i_accessible_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) override;
53 
54     /**
55      * @brief Make the child element information by accessibility ID and filtered by text and
56      *        set the result by callback through the proxy object.
57      * @param accessibilityWindowId The id of accessibility window.
58      * @param elementId: The unique id of the component ID.
59      * @param text  Filter for the child components to matched with the text
60      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
61      * @param callback  To transfer the element info to ASAC and it defined by ASAC.
62      * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure.
63      */
64     virtual RetError SearchElementInfosByText(const int32_t accessibilityWindowId, const int64_t elementId,
65         const std::string &text, const int32_t requestId,
66         const sptr<IAccessibilityElementOperatorCallback> &callback) override;
67 
68     /**
69      * @brief Make the element information of the component focused
70      *        by the focus type specified through the proxy object.
71      * @param accessibilityWindowId The id of accessibility window.
72      * @param elementId: The unique id of the component ID.
73      * @param focusType FOCUS_TYPE_ACCESSIBILITY: accessibility focus
74      *                  FOCUS_TYPE_INPUT: text input focus
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 find elementInfo successfully, otherwise refer to the RetError for the failure.
78      */
79     virtual RetError FindFocusedElementInfo(const int32_t accessibilityWindowId, const int64_t elementId,
80         const int32_t focusType, const int32_t requestId,
81         const sptr<IAccessibilityElementOperatorCallback> &callback) override;
82 
83     /**
84      * @brief Make the element info by current focus move direction through the proxy object.
85      * @param accessibilityWindowId The id of accessibility window.
86      * @param elementId: The unique id of the component ID.
87      * @param direction Refer to AccessibilityElementInfo.FocusMoveDirection(UP/DOWN/LEFT/RIGHT/FORWARD/BACKWARD)
88      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
89      * @param callback  To transfer the element info to ASAC and it defined by ASAC.
90      * @return Return RET_OK if search elementInfo successfully, otherwise refer to the RetError for the failure.
91      */
92     virtual RetError FocusMoveSearch(const int32_t accessibilityWindowId, const int64_t elementId,
93         const int32_t direction, const int32_t requestId,
94         const sptr<IAccessibilityElementOperatorCallback> &callback) override;
95 
96     /**
97      * @brief To perform action through the proxy object.
98      * @param accessibilityWindowId The id of accessibility window.
99      * @param elementId: The unique id of the component ID.
100      * @param action Refer to [AccessibilityElementInfo.ActionType]
101      * @param actionArguments The parameter for action type.
102      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
103      * @param callback  To transfer the node info to ASAC and it defined by ASAC.
104      * @return Return RET_OK if perform action successfully, otherwise refer to the RetError for the failure.
105      */
106     virtual RetError ExecuteAction(const int32_t accessibilityWindowId, const int64_t elementId, const int32_t action,
107         const std::map<std::string, std::string> &actionArguments, const int32_t requestId,
108         const sptr<IAccessibilityElementOperatorCallback> &callback) override;
109 
110     /**
111      * @brief Get the result of Cursor Position through the proxy object.
112      * @param accessibilityWindowId The target winid.
113      * @param elementId The element Id.
114      * @param requestId Matched the request and response. It needn't cared by ACE, transfer it by callback only.
115      * @param callback  To transfer the node info to ASAC and it defined by ASAC.
116      * @return Return RET_OK if Cursor Position successfully, otherwise refer to the RetError for the failure.
117      */
118     virtual RetError GetCursorPosition(const int32_t accessibilityWindowId, const int64_t elementId,
119         const int32_t requestId, const sptr<IAccessibilityElementOperatorCallback> &callback) override;
120 
121     /**
122      * @brief Get the window information related with the event
123      * @param windowId The window id.
124      * @param windowInfo The window information.
125      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
126      */
127     virtual RetError GetWindow(const int32_t windowId, AccessibilityWindowInfo &windowInfo) override;
128 
129     /**
130      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
131      * @param windows The information of windows.
132      * @return Return RET_OK if obtains windowInfo successfully, otherwise refer to the RetError for the failure.
133      */
134     virtual RetError GetWindows(std::vector<AccessibilityWindowInfo> &windows) override;
135 
136     /**
137      * @brief Package and transfer isenable to the data table
138      * @param isEnable The information of status.
139      * @return Return RET_OK if obtains screen curtain status successfully.
140      */
141     virtual RetError EnableScreenCurtain(bool isEnable) override;
142 
143     /**
144      * @brief Obtains the list of interactive windows on the device, in the layers they are visible to users.
145      * @param displayId the id of display
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 GetWindowsByDisplayId(const uint64_t displayId,
150         std::vector<AccessibilityWindowInfo> &windows) override;
151 
152     /**
153      * @brief Set the result of key press event through the proxy object.
154      * @param handled The result of key press event, true if the event has been consumed, otherwise false.
155      * @param sequence The sequence of key press event result.
156      */
157     virtual void SetOnKeyPressEventResult(const bool handled, const int32_t sequence) override;
158 
159     /**
160      * @brief Send simulation gesture through the proxy object.
161      * @param gesturePath The gesture path to send.
162      * @return Return RET_OK if gesture injection is successfully, otherwise refer to the RetError for the failure.
163      */
164     virtual RetError SendSimulateGesture(const std::shared_ptr<AccessibilityGestureInjectPath>& gesturePath) override;
165 
166     /**
167      * @brief Set target bundle names.
168      * @param targetBundleNames The target bundle name
169      * @return Return RET_OK if sets target bundle names successfully, otherwise refer to the RetError for the failure.
170      */
171     virtual RetError SetTargetBundleName(const std::vector<std::string> &targetBundleNames) override;
172 
173 private:
174     /**
175      * @brief Write the descriptor of IPC.
176      * @param data It is include the descriptor of IPC.
177      * @return true: Write the descriptor successfully; otherwise is not.
178      */
179     bool WriteInterfaceToken(MessageParcel &data);
180     /**
181      * @brief Send the command data from proxy to stub in IPC mechanism.
182      * @param code The code matched the function called.
183      * @param data Serializable data
184      * @param reply The response of IPC
185      * @param option The option parameter of IPC,such as: async,sync
186      * @return true: Write the descriptor successfully; otherwise is not.
187      */
188     bool SendTransactCmd(AccessibilityInterfaceCode code, MessageParcel &data,
189         MessageParcel &reply,  MessageOption &option);
190     static inline BrokerDelegator<AccessibleAbilityChannelProxy> delegator;
191 };
192 } // namespace Accessibility
193 } // namespace OHOS
194 #endif // ACCESSIBLE_ABILITY_CHANNEL_PROXY_H