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