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_ABILITY_MANAGER_SERVICE_PROXY_H
17 #define ACCESSIBILITY_ABILITY_MANAGER_SERVICE_PROXY_H
18 
19 #include "accessibility_ipc_interface_code.h"
20 #include "i_accessible_ability_manager_service.h"
21 #include "iremote_proxy.h"
22 
23 namespace OHOS {
24 namespace Accessibility {
25 /*
26  * The class define the interface to call ABMS API.
27  */
28 class AccessibleAbilityManagerServiceProxy : public IRemoteProxy<IAccessibleAbilityManagerService> {
29 public:
30     /**
31      * @brief construct function
32      * @param object The object of IPC
33      */
34     explicit AccessibleAbilityManagerServiceProxy(const sptr<IRemoteObject> &object);
35 
36     /**
37      * @brief destruct function
38      */
39     virtual ~AccessibleAbilityManagerServiceProxy() override;
40 
41     /**
42      * @brief Sends information about an accessibility event.
43      * @param uiEvent Indicates the accessibility event information specified by AccessibilityEventInfo.
44      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
45      */
46     virtual RetError SendEvent(const AccessibilityEventInfo &uiEvent, const int32_t flag) override;
47 
48     /**
49      * @brief Register the state observer of AAMS.
50      * @param callback state observer
51      * @return 0: Register ok; otherwise is refused.
52      */
53     virtual uint32_t RegisterStateObserver(const sptr<IAccessibleAbilityManagerStateObserver> &callback) override;
54 
55     virtual uint32_t RegisterCaptionObserver(const sptr<IAccessibleAbilityManagerCaptionObserver> &callback) override;
56 
57     virtual void RegisterEnableAbilityListsObserver(
58         const sptr<IAccessibilityEnableAbilityListsObserver> &observer) override;
59 
60     /**
61      * @brief Queries the list of accessibility abilities.
62      * @param accessibilityAbilityTypes Indicates the accessibility type specified by AccessibilityAbilityTypes.
63      * @param stateType Indicates the accessibility ability status.
64      *                  1 indicates that the ability is enabled;
65      *                  2 indicates that the ability is disabled;
66      *                  3 indicates that the ability has been installed.
67      * @param infos accessibility ability infos by specified types.
68      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
69      */
70     virtual RetError GetAbilityList(const uint32_t abilityTypes, const int32_t stateType,
71         std::vector<AccessibilityAbilityInfo> &infos) override;
72 
73     /**
74      * @brief Register the element operator, so the AA can get node info from ACE.
75      * @param windowId Window ID
76      * @param operation The callback object.
77      * @param isApp Whether an application.
78      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
79      */
80     virtual RetError RegisterElementOperator(const int32_t windowId,
81         const sptr<IAccessibilityElementOperator> &operation, bool isApp) override;
82 
83     /**
84      * @brief Register the element operator, so the AA can get node info from ACE.
85      * @param parameter The Register parameters.
86      * @param operation The callback object.
87      * @param isApp Whether an application.
88      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
89      */
90     virtual RetError RegisterElementOperator(Registration parameter,
91         const sptr<IAccessibilityElementOperator> &operation, bool isApp) override;
92 
93     /**
94      * @brief Deregister the element operator.
95      * @param windowId Window ID
96      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
97      */
98     virtual RetError DeregisterElementOperator(const int32_t windowId) override;
99 
100     /**
101      * @brief Deregister the element operator.
102      * @param windowId Window ID
103      * @param treeId Tree ID
104      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
105      */
106     virtual RetError DeregisterElementOperator(const int32_t windowId, const int32_t treeId) override;
107 
108     virtual RetError GetCaptionProperty(AccessibilityConfig::CaptionProperty &caption) override;
109     virtual RetError SetCaptionProperty(const AccessibilityConfig::CaptionProperty &caption) override;
110     virtual RetError SetCaptionState(const bool state) override;
111 
112     virtual bool GetEnabledState() override;
113     virtual RetError GetCaptionState(bool &state) override;
114     virtual bool GetTouchGuideState() override;
115     virtual bool GetGestureState() override;
116     virtual bool GetKeyEventObserverState() override;
117 
118     virtual RetError EnableAbility(const std::string &name, const uint32_t capabilities) override;
119     virtual RetError GetEnabledAbilities(std::vector<std::string> &enabledAbilities) override;
120     virtual RetError DisableAbility(const std::string &name) override;
121     virtual int32_t GetActiveWindow() override;
122 
123     virtual RetError EnableUITestAbility(const sptr<IRemoteObject> &obj) override;
124     virtual RetError DisableUITestAbility() override;
125 
126     virtual RetError SetScreenMagnificationState(const bool state) override;
127     virtual RetError SetShortKeyState(const bool state) override;
128     virtual RetError SetMouseKeyState(const bool state) override;
129     virtual RetError SetMouseAutoClick(const int32_t time) override;
130     virtual RetError SetShortkeyTarget(const std::string &name) override;
131     virtual RetError SetShortkeyMultiTarget(const std::vector<std::string> &name) override;
132     virtual RetError SetHighContrastTextState(const bool state) override;
133     virtual RetError SetInvertColorState(const bool state) override;
134     virtual RetError SetAnimationOffState(const bool state) override;
135     virtual RetError SetAudioMonoState(const bool state) override;
136     virtual RetError SetDaltonizationState(const bool state) override;
137     virtual RetError SetDaltonizationColorFilter(const uint32_t filter) override;
138     virtual RetError SetContentTimeout(const uint32_t time) override;
139     virtual RetError SetBrightnessDiscount(const float discount) override;
140     virtual RetError SetAudioBalance(const float balance) override;
141     virtual RetError SetClickResponseTime(const uint32_t time) override;
142     virtual RetError SetIgnoreRepeatClickState(const bool state) override;
143     virtual RetError SetIgnoreRepeatClickTime(const uint32_t time) override;
144 
145     virtual RetError GetScreenMagnificationState(bool &state) override;
146     virtual RetError GetShortKeyState(bool &state) override;
147     virtual RetError GetMouseKeyState(bool &state) override;
148     virtual RetError GetMouseAutoClick(int32_t &time) override;
149     virtual RetError GetShortkeyTarget(std::string &name) override;
150     virtual RetError GetShortkeyMultiTarget(std::vector<std::string> &name) override;
151     virtual RetError GetHighContrastTextState(bool &state) override;
152     virtual RetError GetInvertColorState(bool &state) override;
153     virtual RetError GetAnimationOffState(bool &state) override;
154     virtual RetError GetAudioMonoState(bool &state) override;
155     virtual RetError GetDaltonizationState(bool &state) override;
156     virtual RetError GetDaltonizationColorFilter(uint32_t &type) override;
157     virtual RetError GetContentTimeout(uint32_t &timer) override;
158     virtual RetError GetBrightnessDiscount(float &brightness) override;
159     virtual RetError GetAudioBalance(float &balance) override;
160     virtual RetError GetClickResponseTime(uint32_t& time) override;
161     virtual RetError GetIgnoreRepeatClickState(bool& state) override;
162     virtual RetError GetIgnoreRepeatClickTime(uint32_t& time) override;
163     virtual void GetAllConfigs(AccessibilityConfigData& configData) override;
164     virtual uint32_t RegisterConfigObserver(const sptr<IAccessibleAbilityManagerConfigObserver> &callback) override;
165     virtual void GetRealWindowAndElementId(int32_t& windowId, int64_t& elementId) override;
166     virtual void GetSceneBoardInnerWinId(int32_t windowId, int64_t elementId, int32_t& innerWid) override;
167     virtual RetError GetFocusedWindowId(int32_t &focusedWindowId) override;
168     virtual void RemoveRequestId(int32_t requestId) override;
169     virtual int64_t GetRootParentId(int32_t windowsId, int32_t treeId) override;
170     virtual RetError GetAllTreeId(int32_t windowId, std::vector<int32_t> &treeIds) override;
171 private:
172     /**
173      * @brief Write the descriptor of IPC.
174      * @param data It is include the descriptor of IPC.
175      * @return true: Write the descriptor successfully; otherwise is not.
176      */
177     bool WriteInterfaceToken(MessageParcel& data);
178 
179     /**
180      * @brief Send the command data from proxy to stub in IPC mechanism.
181      * @param code The code matched the function called.
182      * @param data Serializable data
183      * @param reply The response of IPC
184      * @param option The option parameter of IPC,such as: async,sync
185      * @return true: Write the descriptor successfully; otherwise is not.
186      */
187     bool SendTransactCmd(AccessibilityInterfaceCode code, MessageParcel &data,
188         MessageParcel &reply,  MessageOption &option);
189     static inline BrokerDelegator<AccessibleAbilityManagerServiceProxy> delegator;
190 };
191 } // namespace Accessibility
192 } // namespace OHOS
193 #endif // ACCESSIBILITY_ABILITY_MANAGER_SERVICE_PROXY_H