1885b47fbSopenharmony_ci/*
2885b47fbSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3885b47fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4885b47fbSopenharmony_ci * you may not use this file except in compliance with the License.
5885b47fbSopenharmony_ci * You may obtain a copy of the License at
6885b47fbSopenharmony_ci *
7885b47fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8885b47fbSopenharmony_ci *
9885b47fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10885b47fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11885b47fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12885b47fbSopenharmony_ci * See the License for the specific language governing permissions and
13885b47fbSopenharmony_ci * limitations under the License.
14885b47fbSopenharmony_ci */
15885b47fbSopenharmony_ci
16885b47fbSopenharmony_ci#ifndef ACCESSIBLE_ABILITY_MANAGER_SERVICE_H
17885b47fbSopenharmony_ci#define ACCESSIBLE_ABILITY_MANAGER_SERVICE_H
18885b47fbSopenharmony_ci
19885b47fbSopenharmony_ci#include <map>
20885b47fbSopenharmony_ci#include <memory>
21885b47fbSopenharmony_ci#include <string>
22885b47fbSopenharmony_ci
23885b47fbSopenharmony_ci#include "accessibility_dumper.h"
24885b47fbSopenharmony_ci#include "accessibility_def.h"
25885b47fbSopenharmony_ci#include "accessible_ability_manager_service_stub.h"
26885b47fbSopenharmony_ci#include "accessible_ability_manager_service_event_handler.h"
27885b47fbSopenharmony_ci#include "accessibility_account_data.h"
28885b47fbSopenharmony_ci#include "accessibility_common_event.h"
29885b47fbSopenharmony_ci#ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER
30885b47fbSopenharmony_ci#include "accessibility_display_manager.h"
31885b47fbSopenharmony_ci#endif
32885b47fbSopenharmony_ci#include "accessibility_element_operator_callback_stub.h"
33885b47fbSopenharmony_ci#include "accessibility_input_interceptor.h"
34885b47fbSopenharmony_ci#include "accessibility_keyevent_filter.h"
35885b47fbSopenharmony_ci#include "accessibility_settings.h"
36885b47fbSopenharmony_ci#include "accessibility_touchEvent_injector.h"
37885b47fbSopenharmony_ci#include "accessibility_window_info.h"
38885b47fbSopenharmony_ci#include "bundlemgr/bundle_mgr_interface.h"
39885b47fbSopenharmony_ci#include "input_manager.h"
40885b47fbSopenharmony_ci#include "singleton.h"
41885b47fbSopenharmony_ci#include "system_ability.h"
42885b47fbSopenharmony_ci#include "window_manager.h"
43885b47fbSopenharmony_ci#include "accessibility_short_key.h"
44885b47fbSopenharmony_ci
45885b47fbSopenharmony_cinamespace OHOS {
46885b47fbSopenharmony_cinamespace Accessibility {
47885b47fbSopenharmony_ciclass AccessibilityAccountData;
48885b47fbSopenharmony_ciclass TouchEventInjector;
49885b47fbSopenharmony_ciclass AccessibilitySettings;
50885b47fbSopenharmony_ci
51885b47fbSopenharmony_cienum CallBackID {
52885b47fbSopenharmony_ci    STATE_CALLBACK,
53885b47fbSopenharmony_ci    CAPTION_PROPERTY_CALLBACK,
54885b47fbSopenharmony_ci    ENABLE_ABILITY_LISTS_CALLBACK,
55885b47fbSopenharmony_ci    CONFIG_CALLBACK
56885b47fbSopenharmony_ci};
57885b47fbSopenharmony_ci
58885b47fbSopenharmony_ciconstexpr int REQUEST_ID_INIT = 65535;
59885b47fbSopenharmony_ci
60885b47fbSopenharmony_ciconst std::map<std::string, int32_t> AccessibilityConfigTable = {
61885b47fbSopenharmony_ci    {"HIGH_CONTRAST_TEXT", HIGH_CONTRAST_TEXT},
62885b47fbSopenharmony_ci    {"INVERT_COLOR", INVERT_COLOR},
63885b47fbSopenharmony_ci    {"DALTONIZATION_COLOR_FILTER", DALTONIZATION_COLOR_FILTER},
64885b47fbSopenharmony_ci    {"CONTENT_TIMEOUT", CONTENT_TIMEOUT},
65885b47fbSopenharmony_ci    {"ANIMATION_OFF", ANIMATION_OFF},
66885b47fbSopenharmony_ci    {"BRIGHTNESS_DISCOUNT", BRIGHTNESS_DISCOUNT},
67885b47fbSopenharmony_ci    {"AUDIO_MONO", AUDIO_MONO},
68885b47fbSopenharmony_ci    {"AUDIO_BALANCE", AUDIO_BALANCE},
69885b47fbSopenharmony_ci    {"MOUSE_KEY", MOUSE_KEY},
70885b47fbSopenharmony_ci    {"CAPTION_STATE", CAPTION_STATE},
71885b47fbSopenharmony_ci    {"CAPTION_STYLE", CAPTION_STYLE},
72885b47fbSopenharmony_ci    {"SCREEN_MAGNIFICATION", SCREEN_MAGNIFICATION},
73885b47fbSopenharmony_ci    {"MOUSE_AUTOCLICK", MOUSE_AUTOCLICK}
74885b47fbSopenharmony_ci};
75885b47fbSopenharmony_ci
76885b47fbSopenharmony_ciclass AccessibleAbilityManagerService : public SystemAbility, public AccessibleAbilityManagerServiceStub {
77885b47fbSopenharmony_ci    DECLARE_SINGLETON(AccessibleAbilityManagerService)
78885b47fbSopenharmony_ci    DECLEAR_SYSTEM_ABILITY(AccessibleAbilityManagerService)
79885b47fbSopenharmony_cipublic:
80885b47fbSopenharmony_ci    /* For system ability */
81885b47fbSopenharmony_ci    void OnStart() override;
82885b47fbSopenharmony_ci    void OnStop() override;
83885b47fbSopenharmony_ci    void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
84885b47fbSopenharmony_ci    void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
85885b47fbSopenharmony_ci    int Dump(int fd, const std::vector<std::u16string>& args) override;
86885b47fbSopenharmony_ci    void PostDelayUnloadTask() override;
87885b47fbSopenharmony_ci
88885b47fbSopenharmony_cipublic:
89885b47fbSopenharmony_ci    /* For AccessibleAbilityManagerServiceStub */
90885b47fbSopenharmony_ci    RetError SendEvent(const AccessibilityEventInfo &uiEvent, const int32_t flag = 0) override;
91885b47fbSopenharmony_ci
92885b47fbSopenharmony_ci    RetError VerifyingToKenId(const int32_t windowId, const int64_t elementId);
93885b47fbSopenharmony_ci
94885b47fbSopenharmony_ci    uint32_t RegisterStateObserver(const sptr<IAccessibleAbilityManagerStateObserver> &callback) override;
95885b47fbSopenharmony_ci
96885b47fbSopenharmony_ci    uint32_t RegisterCaptionObserver(const sptr<IAccessibleAbilityManagerCaptionObserver> &callback) override;
97885b47fbSopenharmony_ci
98885b47fbSopenharmony_ci    void RegisterEnableAbilityListsObserver(
99885b47fbSopenharmony_ci        const sptr<IAccessibilityEnableAbilityListsObserver> &observer) override;
100885b47fbSopenharmony_ci
101885b47fbSopenharmony_ci    RetError GetAbilityList(const uint32_t abilityTypes, const int32_t stateType,
102885b47fbSopenharmony_ci        std::vector<AccessibilityAbilityInfo> &infos) override;
103885b47fbSopenharmony_ci
104885b47fbSopenharmony_ci    RetError RegisterElementOperator(const int32_t windowId,
105885b47fbSopenharmony_ci        const sptr<IAccessibilityElementOperator> &operation, bool isApp) override;
106885b47fbSopenharmony_ci
107885b47fbSopenharmony_ci    RetError RegisterElementOperator(Registration parameter,
108885b47fbSopenharmony_ci        const sptr<IAccessibilityElementOperator> &operation, bool isApp) override;
109885b47fbSopenharmony_ci
110885b47fbSopenharmony_ci    RetError DeregisterElementOperator(const int32_t windowId) override;
111885b47fbSopenharmony_ci
112885b47fbSopenharmony_ci    RetError DeregisterElementOperator(const int32_t windowId, const int32_t treeId) override;
113885b47fbSopenharmony_ci
114885b47fbSopenharmony_ci    RetError GetCaptionProperty(AccessibilityConfig::CaptionProperty &caption) override;
115885b47fbSopenharmony_ci    RetError SetCaptionProperty(const AccessibilityConfig::CaptionProperty &caption) override;
116885b47fbSopenharmony_ci    RetError SetCaptionState(const bool state) override;
117885b47fbSopenharmony_ci
118885b47fbSopenharmony_ci    bool GetEnabledState() override;
119885b47fbSopenharmony_ci    RetError GetCaptionState(bool &state) override;
120885b47fbSopenharmony_ci    bool GetTouchGuideState() override;
121885b47fbSopenharmony_ci    bool GetGestureState() override;
122885b47fbSopenharmony_ci    bool GetKeyEventObserverState() override;
123885b47fbSopenharmony_ci
124885b47fbSopenharmony_ci    RetError EnableAbility(const std::string &name, const uint32_t capabilities) override;
125885b47fbSopenharmony_ci    RetError GetEnabledAbilities(std::vector<std::string> &enabledAbilities) override;
126885b47fbSopenharmony_ci    RetError SetCurtainScreenUsingStatus(bool isEnable);
127885b47fbSopenharmony_ci    RetError DisableAbility(const std::string &name) override;
128885b47fbSopenharmony_ci    RetError EnableUITestAbility(const sptr<IRemoteObject>& obj) override;
129885b47fbSopenharmony_ci    RetError DisableUITestAbility() override;
130885b47fbSopenharmony_ci    int32_t GetActiveWindow() override;
131885b47fbSopenharmony_ci    void GetRealWindowAndElementId(int32_t& windowId, int64_t& elementId) override;
132885b47fbSopenharmony_ci    void GetSceneBoardInnerWinId(int32_t windowId, int64_t elementId, int32_t& innerWid) override;
133885b47fbSopenharmony_ci    bool FindFocusedElement(AccessibilityElementInfo &elementInfo);
134885b47fbSopenharmony_ci    bool ExecuteActionOnAccessibilityFocused(const ActionType &action);
135885b47fbSopenharmony_ci    RetError GetFocusedWindowId(int32_t &focusedWindowId) override;
136885b47fbSopenharmony_ci    void SetFocusWindowId(const int32_t focusWindowId);
137885b47fbSopenharmony_ci    void SetFocusElementId(const int64_t focusElementId);
138885b47fbSopenharmony_ci    int32_t GetFocusWindowId();
139885b47fbSopenharmony_ci    int64_t GetFocusElementId();
140885b47fbSopenharmony_ci    static int32_t GetTreeIdBySplitElementId(const int64_t elementId);
141885b47fbSopenharmony_ci    int64_t GetRootParentId(int32_t windowId, int32_t treeId) override;
142885b47fbSopenharmony_ci    RetError GetAllTreeId(int32_t windowId, std::vector<int32_t> &treeIds) override;
143885b47fbSopenharmony_ci    void SetTokenIdMapAndRootParentId(const sptr<AccessibilityWindowConnection> connection,
144885b47fbSopenharmony_ci        const int32_t treeId, const int64_t nodeId, const uint32_t tokenId);
145885b47fbSopenharmony_ci    void RemoveTreeDeathRecipient(const int32_t windowId, const int32_t treeId,
146885b47fbSopenharmony_ci        const sptr<AccessibilityWindowConnection> connection);
147885b47fbSopenharmony_ci    int32_t GenerateRequestId();
148885b47fbSopenharmony_ci    void GetElementOperatorConnection(sptr<AccessibilityWindowConnection> &connection,
149885b47fbSopenharmony_ci        const int64_t elementId, sptr<IAccessibilityElementOperator> &elementOperator);
150885b47fbSopenharmony_ciprivate:
151885b47fbSopenharmony_ci    int32_t focusWindowId_ = -1;
152885b47fbSopenharmony_ci    int64_t focusElementId_ = -1;
153885b47fbSopenharmony_ci    std::atomic<int> requestId_ = REQUEST_ID_INIT;
154885b47fbSopenharmony_cipublic:
155885b47fbSopenharmony_ci    /* For inner modules */
156885b47fbSopenharmony_ci    bool EnableShortKeyTargetAbility(const std::string &name = "");
157885b47fbSopenharmony_ci    bool DisableShortKeyTargetAbility();
158885b47fbSopenharmony_ci    void OnShortKeyProcess();
159885b47fbSopenharmony_ci    void UpdateShortKeyRegister();
160885b47fbSopenharmony_ci
161885b47fbSopenharmony_ci    void SetTouchEventInjector(const sptr<TouchEventInjector> &touchEventInjector);
162885b47fbSopenharmony_ci
163885b47fbSopenharmony_ci    inline sptr<TouchEventInjector> GetTouchEventInjector()
164885b47fbSopenharmony_ci    {
165885b47fbSopenharmony_ci        return touchEventInjector_;
166885b47fbSopenharmony_ci    }
167885b47fbSopenharmony_ci
168885b47fbSopenharmony_ci    inline sptr<KeyEventFilter> GetKeyEventFilter()
169885b47fbSopenharmony_ci    {
170885b47fbSopenharmony_ci        return keyEventFilter_;
171885b47fbSopenharmony_ci    }
172885b47fbSopenharmony_ci
173885b47fbSopenharmony_ci    void SetKeyEventFilter(const sptr<KeyEventFilter> &keyEventFilter);
174885b47fbSopenharmony_ci
175885b47fbSopenharmony_ci    /* For DisplayResize */
176885b47fbSopenharmony_ci    void NotifyDisplayResizeStateChanged(int32_t displayId, Rect& rect, float scale, float centerX, float centerY);
177885b47fbSopenharmony_ci
178885b47fbSopenharmony_ci    inline bool IsServiceReady()
179885b47fbSopenharmony_ci    {
180885b47fbSopenharmony_ci        return isReady_;
181885b47fbSopenharmony_ci    }
182885b47fbSopenharmony_ci
183885b47fbSopenharmony_ci    inline int32_t GetCurrentAccountId()
184885b47fbSopenharmony_ci    {
185885b47fbSopenharmony_ci        return currentAccountId_;
186885b47fbSopenharmony_ci    }
187885b47fbSopenharmony_ci
188885b47fbSopenharmony_ci    inline std::shared_ptr<AAMSEventHandler> &GetMainHandler()
189885b47fbSopenharmony_ci    {
190885b47fbSopenharmony_ci        return handler_;
191885b47fbSopenharmony_ci    }
192885b47fbSopenharmony_ci
193885b47fbSopenharmony_ci    inline std::shared_ptr<AppExecFwk::EventRunner> &GetMainRunner()
194885b47fbSopenharmony_ci    {
195885b47fbSopenharmony_ci        return runner_;
196885b47fbSopenharmony_ci    }
197885b47fbSopenharmony_ci
198885b47fbSopenharmony_ci    sptr<AccessibilityAccountData> GetAccountData(int32_t accountId);
199885b47fbSopenharmony_ci    sptr<AccessibilityAccountData> GetCurrentAccountData();
200885b47fbSopenharmony_ci    std::vector<int32_t> GetAllAccountIds();
201885b47fbSopenharmony_ci    sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy();
202885b47fbSopenharmony_ci
203885b47fbSopenharmony_ci    /* For common event */
204885b47fbSopenharmony_ci    void AddedUser(int32_t accountId);
205885b47fbSopenharmony_ci    void RemovedUser(int32_t accountId);
206885b47fbSopenharmony_ci    void SwitchedUser(int32_t accountId);
207885b47fbSopenharmony_ci    void PackageChanged(const std::string &bundleName);
208885b47fbSopenharmony_ci    void PackageRemoved(const std::string &bundleName);
209885b47fbSopenharmony_ci    void PackageAdd(const std::string &bundleName);
210885b47fbSopenharmony_ci
211885b47fbSopenharmony_ci    void UpdateAccessibilityManagerService();
212885b47fbSopenharmony_ci    void InsertWindowIdEventPair(int32_t windowId, const AccessibilityEventInfo &event);
213885b47fbSopenharmony_ci    bool CheckWindowIdEventExist(int32_t windowId);
214885b47fbSopenharmony_ci    bool CheckWindowRegister(int32_t windowId);
215885b47fbSopenharmony_ci
216885b47fbSopenharmony_ci    // used for arkui windowId 1 map to WMS windowId
217885b47fbSopenharmony_ci    void FindInnerWindowId(const AccessibilityEventInfo &event, int32_t& windowId);
218885b47fbSopenharmony_ci    bool GetParentElementRecursively(int32_t windowId, int64_t elementId,
219885b47fbSopenharmony_ci        std::vector<AccessibilityElementInfo>& infos);
220885b47fbSopenharmony_ci
221885b47fbSopenharmony_ci    // used for arkui windowId 1 map to WMS windowId
222885b47fbSopenharmony_ci    class ElementOperatorCallbackImpl : public AccessibilityElementOperatorCallbackStub {
223885b47fbSopenharmony_ci    public:
224885b47fbSopenharmony_ci        ElementOperatorCallbackImpl() = default;
225885b47fbSopenharmony_ci        ~ElementOperatorCallbackImpl() = default;
226885b47fbSopenharmony_ci
227885b47fbSopenharmony_ci        virtual void SetSearchElementInfoByAccessibilityIdResult(const std::vector<AccessibilityElementInfo> &infos,
228885b47fbSopenharmony_ci            const int32_t requestId) override;
229885b47fbSopenharmony_ci        virtual void SetSearchElementInfoByTextResult(const std::vector<AccessibilityElementInfo> &infos,
230885b47fbSopenharmony_ci            const int32_t requestId) override;
231885b47fbSopenharmony_ci        virtual void SetFindFocusedElementInfoResult(const AccessibilityElementInfo &info,
232885b47fbSopenharmony_ci            const int32_t requestId) override;
233885b47fbSopenharmony_ci        virtual void SetFocusMoveSearchResult(const AccessibilityElementInfo &info, const int32_t requestId) override;
234885b47fbSopenharmony_ci        virtual void SetExecuteActionResult(const bool succeeded, const int32_t requestId) override;
235885b47fbSopenharmony_ci        virtual void SetCursorPositionResult(const int32_t cursorPosition, const int32_t requestId) override;
236885b47fbSopenharmony_ci
237885b47fbSopenharmony_ci    private:
238885b47fbSopenharmony_ci        ffrt::promise<void> promise_;
239885b47fbSopenharmony_ci        bool executeActionResult_ = false;
240885b47fbSopenharmony_ci        AccessibilityElementInfo accessibilityInfoResult_ = {};
241885b47fbSopenharmony_ci        std::vector<AccessibilityElementInfo> elementInfosResult_;
242885b47fbSopenharmony_ci        int32_t callCursorPosition_ = 0;
243885b47fbSopenharmony_ci
244885b47fbSopenharmony_ci        friend class AccessibleAbilityManagerService;
245885b47fbSopenharmony_ci    };
246885b47fbSopenharmony_ci
247885b47fbSopenharmony_ci    RetError SetScreenMagnificationState(const bool state) override;
248885b47fbSopenharmony_ci    RetError SetShortKeyState(const bool state) override;
249885b47fbSopenharmony_ci    RetError SetMouseKeyState(const bool state) override;
250885b47fbSopenharmony_ci    RetError SetMouseAutoClick(const int32_t time) override;
251885b47fbSopenharmony_ci    RetError SetShortkeyTarget(const std::string &name) override;
252885b47fbSopenharmony_ci    RetError SetShortkeyMultiTarget(const std::vector<std::string> &name) override;
253885b47fbSopenharmony_ci    RetError SetHighContrastTextState(const bool state) override;
254885b47fbSopenharmony_ci    RetError SetInvertColorState(const bool state) override;
255885b47fbSopenharmony_ci    RetError SetAnimationOffState(const bool state) override;
256885b47fbSopenharmony_ci    RetError SetAudioMonoState(const bool state) override;
257885b47fbSopenharmony_ci    RetError SetDaltonizationState(const bool state) override;
258885b47fbSopenharmony_ci    RetError SetDaltonizationColorFilter(const uint32_t filter) override;
259885b47fbSopenharmony_ci    RetError SetContentTimeout(const uint32_t time) override;
260885b47fbSopenharmony_ci    RetError SetBrightnessDiscount(const float discount) override;
261885b47fbSopenharmony_ci    RetError SetAudioBalance(const float balance) override;
262885b47fbSopenharmony_ci    RetError SetClickResponseTime(const uint32_t time) override;
263885b47fbSopenharmony_ci    RetError SetIgnoreRepeatClickState(const bool state) override;
264885b47fbSopenharmony_ci    RetError SetIgnoreRepeatClickTime(const uint32_t time) override;
265885b47fbSopenharmony_ci
266885b47fbSopenharmony_ci    RetError GetScreenMagnificationState(bool &state) override;
267885b47fbSopenharmony_ci    RetError GetShortKeyState(bool &state) override;
268885b47fbSopenharmony_ci    RetError GetMouseKeyState(bool &state) override;
269885b47fbSopenharmony_ci    RetError GetMouseAutoClick(int32_t &time) override;
270885b47fbSopenharmony_ci    RetError GetShortkeyTarget(std::string &name) override;
271885b47fbSopenharmony_ci    RetError GetShortkeyMultiTarget(std::vector<std::string> &name) override;
272885b47fbSopenharmony_ci    RetError GetHighContrastTextState(bool &state) override;
273885b47fbSopenharmony_ci    RetError GetInvertColorState(bool &state) override;
274885b47fbSopenharmony_ci    RetError GetAnimationOffState(bool &state) override;
275885b47fbSopenharmony_ci    RetError GetAudioMonoState(bool &state) override;
276885b47fbSopenharmony_ci    RetError GetDaltonizationState(bool &state) override;
277885b47fbSopenharmony_ci    RetError GetDaltonizationColorFilter(uint32_t &type) override;
278885b47fbSopenharmony_ci    RetError GetContentTimeout(uint32_t &timer) override;
279885b47fbSopenharmony_ci    RetError GetBrightnessDiscount(float &brightness) override;
280885b47fbSopenharmony_ci    RetError GetAudioBalance(float &balance) override;
281885b47fbSopenharmony_ci    RetError GetClickResponseTime(uint32_t &time) override;
282885b47fbSopenharmony_ci    RetError GetIgnoreRepeatClickState(bool &state) override;
283885b47fbSopenharmony_ci    RetError GetIgnoreRepeatClickTime(uint32_t &time) override;
284885b47fbSopenharmony_ci    void GetAllConfigs(AccessibilityConfigData &configData) override;
285885b47fbSopenharmony_ci
286885b47fbSopenharmony_ci    uint32_t RegisterConfigObserver(const sptr<IAccessibleAbilityManagerConfigObserver> &callback) override;
287885b47fbSopenharmony_ci    void UpdateConfigState();
288885b47fbSopenharmony_ci    void UpdateAudioBalance();
289885b47fbSopenharmony_ci    void UpdateBrightnessDiscount();
290885b47fbSopenharmony_ci    void UpdateContentTimeout();
291885b47fbSopenharmony_ci    void UpdateDaltonizationColorFilter();
292885b47fbSopenharmony_ci    void UpdateMouseAutoClick();
293885b47fbSopenharmony_ci    void UpdateShortkeyTarget();
294885b47fbSopenharmony_ci    void UpdateShortkeyMultiTarget();
295885b47fbSopenharmony_ci    void UpdateClickResponseTime();
296885b47fbSopenharmony_ci    void UpdateIgnoreRepeatClickTime();
297885b47fbSopenharmony_ci
298885b47fbSopenharmony_ci    void UpdateInputFilter();
299885b47fbSopenharmony_ci    void AddRequestId(int32_t windowId, int32_t treeId, int32_t requestId,
300885b47fbSopenharmony_ci        sptr<IAccessibilityElementOperatorCallback> callback);
301885b47fbSopenharmony_ci    void RemoveRequestId(int32_t requestId) override;
302885b47fbSopenharmony_ci    void OnDataClone();
303885b47fbSopenharmony_ci
304885b47fbSopenharmony_ciprivate:
305885b47fbSopenharmony_ci    void StopCallbackWait(int32_t windowId);
306885b47fbSopenharmony_ci    void StopCallbackWait(int32_t windowId, int32_t treeId);
307885b47fbSopenharmony_ci    RetError CheckCallingUid();
308885b47fbSopenharmony_ci    sptr<AccessibilityWindowConnection> GetRealIdConnection();
309885b47fbSopenharmony_ci    bool FindFocusedElementByConnection(sptr<AccessibilityWindowConnection> connection,
310885b47fbSopenharmony_ci        AccessibilityElementInfo &elementInfo);
311885b47fbSopenharmony_ci    bool SetTargetAbility(const int32_t targetAbilityValue);
312885b47fbSopenharmony_ci    RetError RegisterElementOperatorChildWork(const Registration &parameter, const int32_t treeId,
313885b47fbSopenharmony_ci        const int64_t nodeId, const sptr<IAccessibilityElementOperator> &operation,
314885b47fbSopenharmony_ci        const uint32_t tokenId, bool isApp);
315885b47fbSopenharmony_ci    void IsCheckWindowIdEventExist(const int32_t windowId);
316885b47fbSopenharmony_ci    class StateCallbackDeathRecipient final : public IRemoteObject::DeathRecipient {
317885b47fbSopenharmony_ci    public:
318885b47fbSopenharmony_ci        StateCallbackDeathRecipient() = default;
319885b47fbSopenharmony_ci        ~StateCallbackDeathRecipient() final = default;
320885b47fbSopenharmony_ci        DISALLOW_COPY_AND_MOVE(StateCallbackDeathRecipient);
321885b47fbSopenharmony_ci
322885b47fbSopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject> &remote) final;
323885b47fbSopenharmony_ci    };
324885b47fbSopenharmony_ci
325885b47fbSopenharmony_ci    class InteractionOperationDeathRecipient final : public IRemoteObject::DeathRecipient {
326885b47fbSopenharmony_ci    public:
327885b47fbSopenharmony_ci        InteractionOperationDeathRecipient(int32_t windowId, int32_t accountId) : windowId_(windowId),
328885b47fbSopenharmony_ci            accountId_(accountId) {};
329885b47fbSopenharmony_ci        InteractionOperationDeathRecipient(int32_t windowId, int32_t treeId, int32_t accountId) : windowId_(windowId),
330885b47fbSopenharmony_ci            treeId_(treeId), accountId_(accountId) {};
331885b47fbSopenharmony_ci        ~InteractionOperationDeathRecipient() final = default;
332885b47fbSopenharmony_ci        DISALLOW_COPY_AND_MOVE(InteractionOperationDeathRecipient);
333885b47fbSopenharmony_ci
334885b47fbSopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject> &remote) final;
335885b47fbSopenharmony_ci        int32_t windowId_ = INVALID_WINDOW_ID;
336885b47fbSopenharmony_ci        int32_t treeId_ = INVALID_TREE_ID;
337885b47fbSopenharmony_ci        int32_t accountId_ = 0;
338885b47fbSopenharmony_ci    };
339885b47fbSopenharmony_ci
340885b47fbSopenharmony_ci    class CaptionPropertyCallbackDeathRecipient final : public IRemoteObject::DeathRecipient {
341885b47fbSopenharmony_ci    public:
342885b47fbSopenharmony_ci        CaptionPropertyCallbackDeathRecipient() = default;
343885b47fbSopenharmony_ci        ~CaptionPropertyCallbackDeathRecipient() final = default;
344885b47fbSopenharmony_ci        DISALLOW_COPY_AND_MOVE(CaptionPropertyCallbackDeathRecipient);
345885b47fbSopenharmony_ci
346885b47fbSopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject> &remote) final;
347885b47fbSopenharmony_ci    };
348885b47fbSopenharmony_ci
349885b47fbSopenharmony_ci    class EnableAbilityListsObserverDeathRecipient final : public IRemoteObject::DeathRecipient {
350885b47fbSopenharmony_ci    public:
351885b47fbSopenharmony_ci        EnableAbilityListsObserverDeathRecipient() = default;
352885b47fbSopenharmony_ci        ~EnableAbilityListsObserverDeathRecipient() final = default;
353885b47fbSopenharmony_ci        DISALLOW_COPY_AND_MOVE(EnableAbilityListsObserverDeathRecipient);
354885b47fbSopenharmony_ci
355885b47fbSopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject> &remote) final;
356885b47fbSopenharmony_ci    };
357885b47fbSopenharmony_ci
358885b47fbSopenharmony_ci    bool Init();
359885b47fbSopenharmony_ci    void InitInnerResource();
360885b47fbSopenharmony_ci
361885b47fbSopenharmony_ci    class ConfigCallbackDeathRecipient final : public IRemoteObject::DeathRecipient {
362885b47fbSopenharmony_ci    public:
363885b47fbSopenharmony_ci        ConfigCallbackDeathRecipient() = default;
364885b47fbSopenharmony_ci        ~ConfigCallbackDeathRecipient() final = default;
365885b47fbSopenharmony_ci        DISALLOW_COPY_AND_MOVE(ConfigCallbackDeathRecipient);
366885b47fbSopenharmony_ci
367885b47fbSopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject> &remote) final;
368885b47fbSopenharmony_ci    };
369885b47fbSopenharmony_ci
370885b47fbSopenharmony_ci    class BundleManagerDeathRecipient final : public IRemoteObject::DeathRecipient {
371885b47fbSopenharmony_ci    public:
372885b47fbSopenharmony_ci        BundleManagerDeathRecipient() = default;
373885b47fbSopenharmony_ci        ~BundleManagerDeathRecipient() final = default;
374885b47fbSopenharmony_ci        DISALLOW_COPY_AND_MOVE(BundleManagerDeathRecipient);
375885b47fbSopenharmony_ci
376885b47fbSopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject> &remote) final;
377885b47fbSopenharmony_ci    };
378885b47fbSopenharmony_ci
379885b47fbSopenharmony_ci    class StateObservers {
380885b47fbSopenharmony_ci    public:
381885b47fbSopenharmony_ci        StateObservers() = default;
382885b47fbSopenharmony_ci        ~StateObservers() = default;
383885b47fbSopenharmony_ci        void AddStateObserver(const sptr<IAccessibleAbilityManagerStateObserver>& stateObserver);
384885b47fbSopenharmony_ci        void OnStateObservers(uint32_t state);
385885b47fbSopenharmony_ci        void RemoveStateObserver(const wptr<IRemoteObject>& remote);
386885b47fbSopenharmony_ci        void Clear();
387885b47fbSopenharmony_ci    private:
388885b47fbSopenharmony_ci        std::vector<sptr<IAccessibleAbilityManagerStateObserver>> observersList_;
389885b47fbSopenharmony_ci        ffrt::mutex stateObserversMutex_;
390885b47fbSopenharmony_ci    };
391885b47fbSopenharmony_ci
392885b47fbSopenharmony_ci    RetError InnerEnableAbility(const std::string &name, const uint32_t capabilities);
393885b47fbSopenharmony_ci    RetError InnerDisableAbility(const std::string &name);
394885b47fbSopenharmony_ci
395885b47fbSopenharmony_ci    sptr<AccessibilityWindowConnection> GetAccessibilityWindowConnection(int32_t windowId);
396885b47fbSopenharmony_ci    void ClearFocus(int32_t windowId);
397885b47fbSopenharmony_ci    void OutsideTouch(int32_t windowId);
398885b47fbSopenharmony_ci    void UpdateAccessibilityWindowStateByEvent(const AccessibilityEventInfo &event);
399885b47fbSopenharmony_ci
400885b47fbSopenharmony_ci    void UpdateAccessibilityState();
401885b47fbSopenharmony_ci    void UpdateCaptionProperty();
402885b47fbSopenharmony_ci    void UpdateSettingsInAtoHosTask();
403885b47fbSopenharmony_ci    void UpdateSettingsInAtoHos();
404885b47fbSopenharmony_ci    void UpdateAutoStartAbilities();
405885b47fbSopenharmony_ci    void UpdateAllSetting();
406885b47fbSopenharmony_ci
407885b47fbSopenharmony_ci    void RemoveCallback(CallBackID callback, const sptr<DeathRecipient> &recipient, const wptr<IRemoteObject> &remote);
408885b47fbSopenharmony_ci    void RemoveSavedConfigCallback(const wptr<IRemoteObject>& callback);
409885b47fbSopenharmony_ci    void OnBundleManagerDied(const wptr<IRemoteObject> &remote);
410885b47fbSopenharmony_ci    void DeleteConnectionAndDeathRecipient(
411885b47fbSopenharmony_ci        const int32_t windowId, const sptr<AccessibilityWindowConnection> &connection);
412885b47fbSopenharmony_ci
413885b47fbSopenharmony_ci    void OnDeviceProvisioned();
414885b47fbSopenharmony_ci    void InitializeShortKeyState();
415885b47fbSopenharmony_ci    void RegisterProvisionCallback();
416885b47fbSopenharmony_ci    void RegisterShortKeyEvent();
417885b47fbSopenharmony_ci    bool IsNeedUnload();
418885b47fbSopenharmony_ci    void OffZoomGesture();
419885b47fbSopenharmony_ci    void OnScreenMagnificationStateChanged();
420885b47fbSopenharmony_ci    void RegisterScreenMagnificationState();
421885b47fbSopenharmony_ci    void OnScreenMagnificationTypeChanged();
422885b47fbSopenharmony_ci    void RegisterScreenMagnificationType();
423885b47fbSopenharmony_ci
424885b47fbSopenharmony_ci    bool isReady_ = false;
425885b47fbSopenharmony_ci    bool isPublished_ = false;
426885b47fbSopenharmony_ci    std::map<int32_t, bool> dependentServicesStatus_;
427885b47fbSopenharmony_ci    int32_t currentAccountId_ = -1;
428885b47fbSopenharmony_ci    AccessibilityAccountDataMap  a11yAccountsData_;
429885b47fbSopenharmony_ci    sptr<AppExecFwk::IBundleMgr> bundleManager_ = nullptr;
430885b47fbSopenharmony_ci
431885b47fbSopenharmony_ci    sptr<AccessibilityInputInterceptor> inputInterceptor_ = nullptr;
432885b47fbSopenharmony_ci    sptr<TouchEventInjector> touchEventInjector_ = nullptr;
433885b47fbSopenharmony_ci    sptr<KeyEventFilter> keyEventFilter_ = nullptr;
434885b47fbSopenharmony_ci    sptr<AccessibilityDumper> accessibilityDumper_ = nullptr;
435885b47fbSopenharmony_ci
436885b47fbSopenharmony_ci    std::shared_ptr<AppExecFwk::EventRunner> runner_;
437885b47fbSopenharmony_ci    std::shared_ptr<AAMSEventHandler> handler_;
438885b47fbSopenharmony_ci
439885b47fbSopenharmony_ci    std::shared_ptr<AppExecFwk::EventRunner> actionRunner_;
440885b47fbSopenharmony_ci    std::shared_ptr<AAMSEventHandler> actionHandler_;
441885b47fbSopenharmony_ci
442885b47fbSopenharmony_ci    int64_t ipcTimeoutNum_ = 0; // count ipc timeout number
443885b47fbSopenharmony_ci
444885b47fbSopenharmony_ci    sptr<IRemoteObject::DeathRecipient> stateObserversDeathRecipient_ = nullptr;
445885b47fbSopenharmony_ci    std::map<int32_t, sptr<IRemoteObject::DeathRecipient>> interactionOperationDeathRecipients_ {};
446885b47fbSopenharmony_ci    std::map<int32_t, std::map<int32_t, sptr<IRemoteObject::DeathRecipient>>> interactionOperationDeathMap_ {};
447885b47fbSopenharmony_ci    sptr<IRemoteObject::DeathRecipient> captionPropertyCallbackDeathRecipient_ = nullptr;
448885b47fbSopenharmony_ci    sptr<IRemoteObject::DeathRecipient> enableAbilityListsObserverDeathRecipient_ = nullptr;
449885b47fbSopenharmony_ci    sptr<IRemoteObject::DeathRecipient> configCallbackDeathRecipient_ = nullptr;
450885b47fbSopenharmony_ci    sptr<IRemoteObject::DeathRecipient> bundleManagerDeathRecipient_ = nullptr;
451885b47fbSopenharmony_ci    StateObservers stateObservers_;
452885b47fbSopenharmony_ci    ffrt::mutex mutex_; // current used for register state observer
453885b47fbSopenharmony_ci    std::vector<sptr<IAccessibleAbilityManagerConfigObserver>> defaultConfigCallbacks_;
454885b47fbSopenharmony_ci    std::shared_ptr<AccessibilitySettings> accessibilitySettings_ = nullptr;
455885b47fbSopenharmony_ci    std::shared_ptr<AccessibilityShortKey> accessibilityShortKey_ = nullptr;
456885b47fbSopenharmony_ci    std::vector<std::string> removedAutoStartAbilities_ {};
457885b47fbSopenharmony_ci    std::map<int32_t, AccessibilityEventInfo> windowFocusEventMap_ {};
458885b47fbSopenharmony_ci
459885b47fbSopenharmony_ci    std::map<int32_t, std::map<int32_t, std::set<int32_t>>> windowRequestIdMap_ {}; // windowId->treeId->requestId
460885b47fbSopenharmony_ci    std::map<int32_t, sptr<IAccessibilityElementOperatorCallback>> requestIdMap_ {}; // requestId->callback
461885b47fbSopenharmony_ci};
462885b47fbSopenharmony_ci} // namespace Accessibility
463885b47fbSopenharmony_ci} // namespace OHOS
464885b47fbSopenharmony_ci#endif // ACCESSIBLE_ABILITY_MANAGER_SERVICE_H