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 ACCESSIBLE_ABILITY_MANAGER_SERVICE_H 17 #define ACCESSIBLE_ABILITY_MANAGER_SERVICE_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 24 #include "accessible_ability_manager_service_stub.h" 25 #include "accessible_ability_manager_service_event_handler.h" 26 #include "accessibility_account_data.h" 27 #include "accessibility_common_event_registry.h" 28 #include "accessibility_display_manager.h" 29 #include "accessibility_input_interceptor.h" 30 #include "accessibility_keyevent_filter.h" 31 #include "accessibility_touchEvent_injector.h" 32 #include "accessibility_window_info.h" 33 #include "accessibility_zoom_proxy.h" 34 #include "bundlemgr/bundle_mgr_interface.h" 35 #include "input_manager.h" 36 #include "singleton.h" 37 #include "system_ability.h" 38 #include "window_manager.h" 39 40 namespace OHOS { 41 namespace Accessibility { 42 class AccessibilityAccountData; 43 class TouchEventInjector; 44 45 class AccessibleAbilityManagerService : public SystemAbility, public AccessibleAbilityManagerServiceClientStub { 46 DECLARE_DELAYED_SINGLETON(AccessibleAbilityManagerService) 47 DECLEAR_SYSTEM_ABILITY(AccessibleAbilityManagerService) 48 public: 49 void OnStart() override; 50 void OnStop() override; 51 52 /* For AccessibleAbilityManagerServiceClientStub */ 53 void SendEvent(const AccessibilityEventInfo& uiEvent, const int accountId) override; 54 55 uint32_t RegisterStateCallback( 56 const sptr<IAccessibleAbilityManagerServiceState>& callback, const int accountId) override; 57 58 uint32_t RegisterCaptionPropertyCallback( 59 const sptr<IAccessibleAbilityManagerServiceCaptionProperty>& callback, const int accountId) override; 60 61 std::vector<AccessibilityAbilityInfo> GetAbilityList(const uint32_t abilityTypes, 62 const int32_t stateType) override; 63 64 void RegisterElementOperator( 65 const int windowId, const sptr<IAccessibilityElementOperator>& operation, const int accountId) override; 66 67 void DeregisterElementOperator(const int windowId) override; 68 69 CaptionProperty GetCaptionProperty() override; 70 bool SetCaptionProperty(const CaptionProperty& caption) override; 71 bool SetCaptionState(const bool state) override; 72 bool SetEnabled(const bool state) override; 73 74 /* For InputFilter */ 75 void SetTouchEventInjector(const sptr<TouchEventInjector>& touchEventInjector); 76 GetTouchEventInjector()77 inline sptr<TouchEventInjector> GetTouchEventInjector() 78 { 79 return touchEventInjector_; 80 } 81 82 /* For Key Event Filter */ 83 bool IsWantedKeyEvent(MMI::KeyEvent& event); 84 GetKeyEventFilter()85 inline sptr<KeyEventFilter> GetKeyEventFilter() 86 { 87 return keyEventFilter_; 88 } 89 90 void SetKeyEventFilter(const sptr<KeyEventFilter>& keyEventFilter); 91 92 /* For DisplayResize */ 93 void NotifyDisplayResizeStateChanged(int displayId, Rect& rect, float scale, float centerX, float centerY); 94 GetCurrentAccountId()95 inline int32_t GetCurrentAccountId() 96 { 97 return currentAccountId_; 98 } 99 GetConnectCounter()100 inline uint32_t GetConnectCounter() 101 { 102 return connectCounter_; 103 } 104 GetMainHandler()105 inline std::shared_ptr<AAMSEventHandler>& GetMainHandler() 106 { 107 return handler_; 108 } 109 GetMainRunner()110 inline std::shared_ptr<AppExecFwk::EventRunner>& GetMainRunner() 111 { 112 return runner_; 113 } 114 115 sptr<AccessibilityAccountData> GetCurrentAccountData(); 116 sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy(); 117 118 /* For common event */ 119 void RemovedUser(int32_t accountId); 120 void PresentUser(); 121 void PackageChanged(std::string& bundleName); 122 void PackageRemoved(std::string& bundleName); 123 void PackageAdd(std::string& bundleName); 124 void PackageUpdateFinished(std::string& bundleName); 125 126 void UpdateAccessibilityManagerService(); 127 void UpdateAbilities(); 128 129 bool GetEnabledState() override; 130 bool GetCaptionState() override; 131 bool GetTouchGuideState() override; 132 bool GetGestureState() override; 133 bool GetKeyEventObserverState() override; 134 135 bool SetTouchGuideState(const bool state) override; 136 bool SetGestureState(const bool state) override; 137 bool SetKeyEventObserverState(const bool state) override; 138 139 bool SetEnabledObj(std::map<std::string, AppExecFwk::ElementName> it) override; 140 std::map<std::string, AppExecFwk::ElementName> GetEnabledAbilities() override; 141 std::vector<AccessibilityAbilityInfo> GetInstalledAbilities() override; 142 bool DisableAbilities(std::map<std::string, AppExecFwk::ElementName> it) override; 143 bool RegisterUITestAbilityConnectionClient(const sptr<IRemoteObject>& obj) override; 144 bool DeregisterUITestAbilityConnectionClient() override; 145 int GetActiveWindow() override; 146 protected: 147 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 148 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 149 150 private: 151 void AddUITestClient(const sptr<IRemoteObject>& obj); 152 void RemoveUITestClient(sptr<AccessibleAbilityConnection>& connection); 153 154 class StateCallbackDeathRecipient final : public IRemoteObject::DeathRecipient { 155 public: 156 StateCallbackDeathRecipient() = default; 157 ~StateCallbackDeathRecipient() final = default; 158 DISALLOW_COPY_AND_MOVE(StateCallbackDeathRecipient); 159 160 void OnRemoteDied(const wptr<IRemoteObject>& remote) final; 161 }; 162 163 class InteractionOperationDeathRecipient final : public IRemoteObject::DeathRecipient { 164 public: InteractionOperationDeathRecipient(int windowId)165 InteractionOperationDeathRecipient(int windowId) : windowId_(windowId) {}; 166 ~InteractionOperationDeathRecipient() final = default; 167 DISALLOW_COPY_AND_MOVE(InteractionOperationDeathRecipient); 168 169 void OnRemoteDied(const wptr<IRemoteObject>& remote) final; 170 int windowId_ = INVALID_WINDOW_ID; 171 }; 172 173 class CaptionPropertyCallbackDeathRecipient final : public IRemoteObject::DeathRecipient { 174 public: 175 CaptionPropertyCallbackDeathRecipient() = default; 176 ~CaptionPropertyCallbackDeathRecipient() final = default; 177 DISALLOW_COPY_AND_MOVE(CaptionPropertyCallbackDeathRecipient); 178 179 void OnRemoteDied(const wptr<IRemoteObject>& remote) final; 180 }; 181 182 bool Init(); 183 void SendEventInner(AccessibilityEventInfo& uiEvent); 184 sptr<AccessibilityWindowConnection> GetAccessibilityWindowConnection(int windowId); 185 void ClearFocus(int windowId); 186 void OutsideTouch(int windowId); 187 void OnChanging(bool selfChange, Uri &uri); 188 void UpdateAccessibilityWindowStateByEvent(const AccessibilityEventInfo &event); 189 190 void UpdateAccessibilityState(); 191 void UpdateInputFilter(); 192 void UpdateMagnification(); 193 void UpdateWindowChangeListener(); 194 void UpdateCaptionProperty(); 195 196 bool isRunning_ = false; 197 int32_t currentAccountId_ = 0; 198 uint32_t connectCounter_ = 1; 199 AccessibilityCommonEventRegistry accessibilityCommonEventRegistry_; 200 std::map<int, sptr<AccessibilityAccountData>> a11yAccountsData_; 201 sptr<AppExecFwk::IBundleMgr> bundleManager_; 202 203 sptr<AccessibilityInputInterceptor> inputInterceptor_; 204 sptr<TouchEventInjector> touchEventInjector_; 205 sptr<KeyEventFilter> keyEventFilter_; 206 int32_t interceptorId_ = 0; 207 208 std::shared_ptr<AppExecFwk::EventRunner> runner_; 209 std::shared_ptr<AAMSEventHandler> handler_; 210 211 sptr<IRemoteObject::DeathRecipient> stateCallbackDeathRecipient_ = nullptr; 212 sptr<IRemoteObject::DeathRecipient> interactionOperationDeathRecipient_ = nullptr; 213 sptr<IRemoteObject::DeathRecipient> captionPropertyCallbackDeathRecipient_ = nullptr; 214 static std::mutex mutex_; 215 216 DISALLOW_COPY_AND_MOVE(AccessibleAbilityManagerService); 217 }; 218 } // namespace Accessibility 219 } // namespace OHOS 220 #endif // ACCESSIBLE_ABILITY_MANAGER_SERVICE_H