• 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 ACCESSIBILITY_SYSTEM_ABILITY_CLIENT_H
17 #define ACCESSIBILITY_SYSTEM_ABILITY_CLIENT_H
18 
19 #include <map>
20 #include <vector>
21 #include "accessibility_ability_info.h"
22 #include "accessibility_element_operator.h"
23 #include "accessibility_event_info.h"
24 #include "accessibility_state_event.h"
25 #include "accessibility_window_info.h"
26 
27 namespace OHOS {
28 namespace Accessibility {
29 enum AccessibilityControlType : int32_t {
30     CONTENT_CONTROLS = 0x00000001,
31     CONTENT_ICONS = 0x00000002,
32     CONTENT_TEXT = 0x00000004,
33 };
34 
35 constexpr int32_t ELEMENT_MOVE_BIT = 40;
36 constexpr int32_t CONT_SPLIT_ID = -1;
37 constexpr uint64_t MAX_ELEMENT_ID = 0xFFFFFFFFFF;
38 
39 /*
40  * The class register the accessibility service observer to AAMS,and
41  * dispatch the accessibility service status changed. such as Service Enable,
42  * Accessibility Enable. It calls AAMS API to send the event to AA.
43  * It supply sington instance for each process.
44  */
45 class AccessibilitySystemAbilityClient {
46 public:
47     /**
48      * @brief Obtains the AccessibilitySystemAbilityClient instance.
49      * @return AccessibilitySystemAbilityClient instance
50      */
51     static std::shared_ptr<AccessibilitySystemAbilityClient> GetInstance();
52 
53     /**
54      * @brief Deconstruct.
55      */
56     virtual ~AccessibilitySystemAbilityClient() = default;
57 
58     /**
59      * @brief Register the element operator, so the AA can get node info from ACE.
60      * @param windowId Window ID
61      * @param operation The callback object.
62      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
63      */
64     virtual RetError RegisterElementOperator(const int32_t windowId,
65         const std::shared_ptr<AccessibilityElementOperator> &operation) = 0;
66 
67     /**
68      * @brief Register the element operator, so the AA can get node info from ACE.
69      * @param parameter The Register parameters.
70      * @param operation The callback object.
71      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
72      */
73     virtual RetError RegisterElementOperator(Registration parameter,
74         const std::shared_ptr<AccessibilityElementOperator> &operation) = 0;
75 
76     /**
77      * @brief Deregister the element operator.
78      * @param windowId Window ID
79      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
80      */
81     virtual RetError DeregisterElementOperator(const int32_t windowId) = 0;
82 
83     /**
84      * @brief Deregister the element operator.
85      * @param windowId Window ID
86      * @param treeId Tree ID
87      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
88      */
89     virtual RetError DeregisterElementOperator(const int32_t windowId, const int32_t treeId) = 0;
90 
91     /**
92      * @brief Checks whether screenreader ability is enabled.
93      * @param isEnabled true: enabled; false: disabled
94      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
95      */
96     virtual RetError IsScreenReaderEnabled(bool &isEnabled)= 0;
97 
98     /**
99      * @brief Checks whether accessibility ability is enabled.
100      * @param isEnabled true: enabled; false: disabled
101      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
102      */
103     virtual RetError IsEnabled(bool &isEnabled)= 0;
104 
105     /**
106      * @brief Checks whether touch exploration ability is enabled.
107      * @param isEnabled true: enabled; false: disabled
108      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
109      */
110     virtual RetError IsTouchExplorationEnabled(bool &isEnabled) = 0;
111 
112     /**
113      * @brief Queries the list of accessibility abilities.
114      * @param accessibilityAbilityTypes Indicates the accessibility type specified by AccessibilityAbilityTypes.
115      * @param stateType Indicates the accessibility ability status.
116      *                  1 indicates that the ability is enabled;
117      *                  2 indicates that the ability is disabled;
118      *                  3 indicates that the ability has been installed.
119      * @param infos accessibility ability infos by specified types.
120      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
121      */
122     virtual RetError GetAbilityList(const uint32_t accessibilityAbilityTypes, const AbilityStateType stateType,
123         std::vector<AccessibilityAbilityInfo> &infos) = 0;
124 
125     /**
126      * @brief Sends an accessibility event.
127      * @param eventType  Identifies the accessibility event specified by AccessibilityEventInfo.
128      * @param componentId Indicates the ID of the component to be associated with the event.
129      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
130      */
131     virtual RetError SendEvent(const EventType eventType, const int64_t componentId) = 0;
132 
133     /**
134      * @brief Sends information about an accessibility event.
135      * @param event Indicates the accessibility event information specified by AccessibilityEventInfo.
136      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
137      */
138     virtual RetError SendEvent(const AccessibilityEventInfo &event) = 0;
139 
140     /**
141      * @brief Subscribes to the specified type of accessibility status change events.
142      * @param observer Indicates the observer for listening to status events, which is specified
143      *              by AccessibilityStateObserver.
144      * @param eventType Indicates the status type, which is specified by AccessibilityStateEventType.
145      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
146      */
147     virtual RetError SubscribeStateObserver(const std::shared_ptr<AccessibilityStateObserver> &observer,
148         const uint32_t eventType) = 0;
149 
150     /**
151      * @brief Unsubscribe the specified type of accessibility status change events.
152      * @param observer Indicates the registered accessibility status event observer.
153      * @param eventType Indicates the status type, which is specified by AccessibilityStateEventType.
154      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
155      */
156     virtual RetError UnsubscribeStateObserver(const std::shared_ptr<AccessibilityStateObserver> &observer,
157         const uint32_t eventType) = 0;
158 
159     /**
160      * @brief Get enabled abilities.
161      * @param enabledAbilities The infos of enabled abilities.
162      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
163      */
164     virtual RetError GetEnabledAbilities(std::vector<std::string> &enabledAbilities) = 0;
165 
166     virtual uint32_t GetAccessibilityState() = 0;
167     virtual void SetFindAccessibilityNodeInfoResult(const AccessibilityElementInfo elementInfo,
168         const int32_t requestId, const int32_t requestCode) = 0;
169     virtual void SetFindAccessibilityNodeInfosResult(const std::list<AccessibilityElementInfo> elementInfos,
170         const int32_t requestId, const int32_t requestCode) = 0;
171     virtual void SetPerformActionResult(const bool succeeded, const int32_t requestId) = 0;
172     virtual RetError GetFocusedWindowId(int32_t &focusedWindowId) = 0;
173 
174     /**
175     * @brief Splic ElementId and TreeId.
176     * @param treeId: The tree Id.
177     * @param elementId: The incoming before splicing elementId,Send out after splicing elementId.
178     */
SetSplicElementIdTreeId(const int32_t treeId,int64_t & elementId)179     static void SetSplicElementIdTreeId(const int32_t treeId, int64_t &elementId)
180     {
181         if (treeId == CONT_SPLIT_ID || elementId == CONT_SPLIT_ID) {
182             elementId = CONT_SPLIT_ID;
183             return;
184         }
185         if ((static_cast<uint64_t>(elementId) & MAX_ELEMENT_ID) != elementId) {
186             return;
187         }
188         uint64_t itemp = 0;
189         itemp = treeId;
190         itemp = (itemp << ELEMENT_MOVE_BIT);
191         itemp |= static_cast<uint64_t>(elementId);
192         elementId = static_cast<int64_t>(itemp);
193     }
194 
195     /**
196     * @brief Split ElementId.
197     * @param elementId:Splic ElementId
198     * @param splitElementId: The split ElementId.
199     * @param splitTreeId: The split TreeId.
200     */
GetTreeIdAndElementIdBySplitElementId(const int64_t elementId,int64_t & splitElementId,int32_t & splitTreeId)201     static void GetTreeIdAndElementIdBySplitElementId(const int64_t elementId, int64_t &splitElementId,
202         int32_t &splitTreeId)
203     {
204         if (elementId <= CONT_SPLIT_ID) {
205             splitTreeId = CONT_SPLIT_ID;
206             splitElementId = CONT_SPLIT_ID;
207             return;
208         }
209         splitTreeId = (static_cast<uint64_t>(elementId) >> ELEMENT_MOVE_BIT);
210         splitElementId = (static_cast<uint64_t>(elementId) & MAX_ELEMENT_ID);
211     }
212 };
213 } // namespace Accessibility
214 } // namespace OHOS
215 #endif // ACCESSIBILITY_SYSTEM_ABILITY_CLIENT_H