• 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 Get touch exploration mode.
114      * @param touchMode 'singleTouchMode': single click mode; 'doubleTouchMode': double click mode;
115      *                  'none": touch exploration is not enabled.
116      */
117     virtual void GetTouchMode(std::string &touchMode) = 0;
118 
119     /**
120      * @brief Queries the list of accessibility abilities.
121      * @param accessibilityAbilityTypes Indicates the accessibility type specified by AccessibilityAbilityTypes.
122      * @param stateType Indicates the accessibility ability status.
123      *                  1 indicates that the ability is enabled;
124      *                  2 indicates that the ability is disabled;
125      *                  3 indicates that the ability has been installed.
126      * @param infos accessibility ability infos by specified types.
127      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
128      */
129     virtual RetError GetAbilityList(const uint32_t accessibilityAbilityTypes, const AbilityStateType stateType,
130         std::vector<AccessibilityAbilityInfo> &infos) = 0;
131 
132     /**
133      * @brief Sends an accessibility event.
134      * @param eventType  Identifies the accessibility event specified by AccessibilityEventInfo.
135      * @param componentId Indicates the ID of the component to be associated with the event.
136      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
137      */
138     virtual RetError SendEvent(const EventType eventType, const int64_t componentId) = 0;
139 
140     /**
141      * @brief Sends information about an accessibility event.
142      * @param event Indicates the accessibility event information specified by AccessibilityEventInfo.
143      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
144      */
145     virtual RetError SendEvent(const AccessibilityEventInfo &event) = 0;
146 
147     /**
148      * @brief Subscribes to the specified type of accessibility status change events.
149      * @param observer Indicates the observer for listening to status events, which is specified
150      *              by AccessibilityStateObserver.
151      * @param eventType Indicates the status type, which is specified by AccessibilityStateEventType.
152      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
153      */
154     virtual RetError SubscribeStateObserver(const std::shared_ptr<AccessibilityStateObserver> &observer,
155         const uint32_t eventType) = 0;
156 
157     /**
158      * @brief Unsubscribe the specified type of accessibility status change events.
159      * @param observer Indicates the registered accessibility status event observer.
160      * @param eventType Indicates the status type, which is specified by AccessibilityStateEventType.
161      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
162      */
163     virtual RetError UnsubscribeStateObserver(const std::shared_ptr<AccessibilityStateObserver> &observer,
164         const uint32_t eventType) = 0;
165 
166     /**
167      * @brief Get enabled abilities.
168      * @param enabledAbilities The infos of enabled abilities.
169      * @return Returns RET_OK if successful, otherwise refer to the RetError for the failure.
170      */
171     virtual RetError GetEnabledAbilities(std::vector<std::string> &enabledAbilities) = 0;
172 
173     virtual uint32_t GetAccessibilityState() = 0;
174     virtual void SetFindAccessibilityNodeInfoResult(const AccessibilityElementInfo elementInfo,
175         const int32_t requestId, const int32_t requestCode) = 0;
176     virtual void SetFindAccessibilityNodeInfosResult(const std::list<AccessibilityElementInfo> elementInfos,
177         const int32_t requestId, const int32_t requestCode) = 0;
178     virtual void SetPerformActionResult(const bool succeeded, const int32_t requestId) = 0;
179     virtual RetError GetFocusedWindowId(int32_t &focusedWindowId) = 0;
180     virtual RetError SearchNeedEvents(std::vector<uint32_t> &needEvents) = 0;
181 
182     /**
183     * @brief Splic ElementId and TreeId.
184     * @param treeId: The tree Id.
185     * @param elementId: The incoming before splicing elementId,Send out after splicing elementId.
186     */
SetSplicElementIdTreeId(const int32_t treeId,int64_t & elementId)187     static void SetSplicElementIdTreeId(const int32_t treeId, int64_t &elementId)
188     {
189         if (treeId == CONT_SPLIT_ID || elementId == CONT_SPLIT_ID) {
190             elementId = CONT_SPLIT_ID;
191             return;
192         }
193         if ((static_cast<uint64_t>(elementId) & MAX_ELEMENT_ID) != static_cast<uint64_t>(elementId)) {
194             return;
195         }
196         uint64_t itemp = 0;
197         itemp = treeId;
198         itemp = (itemp << ELEMENT_MOVE_BIT);
199         itemp |= static_cast<uint64_t>(elementId);
200         elementId = static_cast<int64_t>(itemp);
201     }
202 
203     /**
204     * @brief Split ElementId.
205     * @param elementId:Splic ElementId
206     * @param splitElementId: The split ElementId.
207     * @param splitTreeId: The split TreeId.
208     */
GetTreeIdAndElementIdBySplitElementId(const int64_t elementId,int64_t & splitElementId,int32_t & splitTreeId)209     static void GetTreeIdAndElementIdBySplitElementId(const int64_t elementId, int64_t &splitElementId,
210         int32_t &splitTreeId)
211     {
212         if (elementId <= CONT_SPLIT_ID) {
213             splitTreeId = CONT_SPLIT_ID;
214             splitElementId = CONT_SPLIT_ID;
215             return;
216         }
217         splitTreeId = (static_cast<uint64_t>(elementId) >> ELEMENT_MOVE_BIT);
218         splitElementId = (static_cast<uint64_t>(elementId) & MAX_ELEMENT_ID);
219     }
220 };
221 } // namespace Accessibility
222 } // namespace OHOS
223 #endif // ACCESSIBILITY_SYSTEM_ABILITY_CLIENT_H