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 ACCESSIBILITY_ELEMENT_OPERATOR_CALLBACK_PROXY_H
17 #define ACCESSIBILITY_ELEMENT_OPERATOR_CALLBACK_PROXY_H
18 
19 #include "accessibility_ipc_interface_code.h"
20 #include "i_accessibility_element_operator_callback.h"
21 #include "iremote_proxy.h"
22 namespace OHOS {
23 namespace Accessibility {
24 /*
25 * The class supply the callback to feedback the result from UI to AA.
26 */
27 class AccessibilityElementOperatorCallbackProxy : public IRemoteProxy<IAccessibilityElementOperatorCallback> {
28 public:
29     /**
30      * @brief construct function
31      * @param object The object of IPC
32      */
33     explicit AccessibilityElementOperatorCallbackProxy(const sptr<IRemoteObject> &object);
34 
35     /**
36      * @brief destruct function
37      */
38     virtual ~AccessibilityElementOperatorCallbackProxy() override;
39 
40     /**
41      * @brief Set the element information by accessibility id to AA.
42      * @param infos The element info searched by accessibility id.
43      * @param requestId The request id from AA, it is used to match with request and response.
44      */
45     void SetSearchElementInfoByAccessibilityIdResult(const std::vector<AccessibilityElementInfo> &infos,
46         const int32_t requestId) override;
47 
48     /**
49      * @brief Set the element information matched with text to AA.
50      * @param infos The element information searched matched with text.
51      * @param requestId The request id from AA, it is used to match with request and response.
52      */
53     void SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> &infos,
54         const int32_t requestId) override;
55 
56     /**
57      * @brief Set the element information matched with focus type to AA.
58      * @param info The element information searched matched with focus type.
59      * @param requestId The request id from AA, it is used to match with request and response.
60      */
61     void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info, const int32_t requestId) override;
62 
63     /**
64      * @brief Set the element information by focus direction to AA.
65      * @param info The element information searched by focus direction.
66      * @param requestId The request id from AA, it is used to match with request and response.
67      */
68     void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int32_t requestId) override;
69 
70     /**
71      * @brief Set the result of action executed to AA.
72      * @param succeeded True: The action is executed successfully; otherwise is false.
73      * @param requestId The request id from AA, it is used to match with request and response.
74      */
75     void SetExecuteActionResult(const bool succeeded, const int32_t requestId) override;
76 
77     /**
78      * @brief Set the result of cursor position to AA.
79      * @param cursorPosition The position of the cursor to return.
80      * @param requestId The request id from AA, it is used to match with request and response.
81      */
82     void SetCursorPositionResult(const int32_t cursorPosition, const int32_t requestId) override;
83 
84 private:
85     /**
86      * @brief Write the descriptor of IPC.
87      * @param data It is include the descriptor of IPC.
88      * @return true: Write the descriptor successfully; otherwise is not.
89      */
90     bool WriteInterfaceToken(MessageParcel &data);
91 
92     /**
93      * @brief Send the command data from proxy to stub in IPC mechanism.
94      * @param code The code matched the function called.
95      * @param data Serializable data
96      * @param reply The response of IPC
97      * @param option The option parameter of IPC,such as: async,sync
98      * @return true: Write the descriptor successfully; otherwise is not.
99      */
100     bool SendTransactCmd(AccessibilityInterfaceCode code, MessageParcel &data,
101         MessageParcel &reply,  MessageOption &option);
102 
103     int32_t GetTransmitFlag(int32_t time, int32_t leftSize);
104 
105     static inline BrokerDelegator<AccessibilityElementOperatorCallbackProxy> delegator;
106 };
107 } // namespace Accessibility
108 } // namespace OHOS
109 #endif // ACCESSIBILITY_ELEMENT_OPERATOR_CALLBACK_PROXY_H