• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_MANAGER_H
17 #define ACCESSIBILITY_MANAGER_H
18 
19 #include <vector>
20 
21 #include <functional>
22 #include "nocopyable.h"
23 #include "singleton.h"
24 
25 #include "accessibility_system_ability_client.h"
26 #include "accessibility_ui_test_ability.h"
27 #include "accessible_ability_listener.h"
28 
29 namespace OHOS {
30 namespace Msdp {
31 namespace DeviceStatus {
32 enum AccessibilityStatus {
33     ABILITY_INVALID_STATUS,
34     ON_ABILITY_CONNECTED = 1,
35     ON_ABILITY_SCROLLED_EVENT,
36     ON_ABILITY_DISCONNECTED,
37 };
38 
39 using AccessibilityCallback = std::function<void(int32_t)>;
40 
41 struct DragElementInfo {
42     int64_t rsNodeId { -1 };
43     int32_t leftTopX { -1 };
44     int32_t leftTopY { -1 };
45     int32_t targetWindowId { -1 };
46     std::string componentType;
47     std::string content;
48     int64_t accessibilityId { -1};
49     void Dump();
50 };
51 
52 class AccessibilityManager final {
53     DECLARE_SINGLETON(AccessibilityManager);
54 public:
55     DISALLOW_MOVE(AccessibilityManager);
56 
57     class AccessibleAbilityListenerImpl : public Accessibility::AccessibleAbilityListener {
58     public:
AccessibleAbilityListenerImpl(AccessibilityCallback callback)59         AccessibleAbilityListenerImpl(AccessibilityCallback callback) : callback_(callback) {}
60         ~AccessibleAbilityListenerImpl() = default;
61 
62         void OnAbilityConnected() override;
63         void OnAbilityDisconnected() override;
64         void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo &eventInfo) override;
65         bool OnKeyPressEvent(const std::shared_ptr<MMI::KeyEvent> &keyEvent) override;
66     private:
67         AccessibilityCallback callback_ { nullptr };
68         std::mutex mutex_;
69     };
70 
71     void AccessibilityConnect(AccessibilityCallback callback);
72     void AccessibilityDisconnect();
73 private:
74     std::mutex mutex_;
75 };
76 
77 #define ACCESSIBILITY_MANAGER OHOS::Singleton<AccessibilityManager>::GetInstance()
78 } // namespace DeviceStatus
79 } // namespace Msdp
80 } // namespace OHOS
81 #endif // ACCESSIBILITY_MANAGER_H