• 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_INPUT_INTERCEPTOR_H
17 #define ACCESSIBILITY_INPUT_INTERCEPTOR_H
18 
19 #include <map>
20 #include <memory>
21 #include <vector>
22 
23 #include "accessibility_event_transmission.h"
24 #include "event_handler.h"
25 #include "i_input_event_consumer.h"
26 #include "input_manager.h"
27 #include "key_event.h"
28 #include "pointer_event.h"
29 
30 namespace OHOS {
31 namespace Accessibility {
32 class AccessibleAbilityManagerService;
33 
34 class AccessibilityInputEventConsumer : public MMI::IInputEventConsumer {
35 public:
36     AccessibilityInputEventConsumer();
37     ~AccessibilityInputEventConsumer();
38     void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
39     void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent)40     void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override {};
41 private:
42     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
43 };
44 
45 class AccessibilityInputInterceptor : public EventTransmission {
46 public:
47     // Feature flag for screen magnification.
48     const static uint32_t FEATURE_SCREEN_MAGNIFICATION = 0x00000001;
49 
50     // Feature flag for touch exploration.
51     const static uint32_t FEATURE_TOUCH_EXPLORATION = 0x00000002;
52 
53     // Feature flag for filtering key events.
54     const static uint32_t FEATURE_FILTER_KEY_EVENTS = 0x00000004;
55 
56     // Feature flag for inject touch events.
57     const static uint32_t FEATURE_INJECT_TOUCH_EVENTS = 0x00000008;
58 
59     static sptr<AccessibilityInputInterceptor> GetInstance();
60     ~AccessibilityInputInterceptor();
61     void ProcessKeyEvent(std::shared_ptr<MMI::KeyEvent> event) const;
62     void ProcessPointerEvent(std::shared_ptr<MMI::PointerEvent> event) const;
63     void OnKeyEvent(MMI::KeyEvent &event) override;
64     void OnPointerEvent(MMI::PointerEvent &event) override;
65     void SetAvailableFunctions(uint32_t availableFunctions);
66     void NotifyAccessibilityEvent(AccessibilityEventInfo &event) const;
67     static void InterceptKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent);
68 
69 private:
70     AccessibilityInputInterceptor();
71     static sptr<AccessibilityInputInterceptor> instance_;
72     void CreateTransmitters();
73     void DestroyTransmitters();
74     void SetNextEventTransmitter(sptr<EventTransmission> &header, sptr<EventTransmission> &current,
75         const sptr<EventTransmission> &next);
76     void CreateInterceptor();
77     void DestroyInterceptor();
78 
79     std::shared_ptr<AccessibleAbilityManagerService> aams_ = nullptr;
80     sptr<EventTransmission> pointerEventTransmitters_ = nullptr;
81     sptr<EventTransmission> keyEventTransmitters_ = nullptr;
82     uint32_t availableFunctions_ = 0;
83     int32_t interceptorId_ = -1;
84     int32_t keyEventInterceptorId_ = -1;
85     MMI::InputManager *inputManager_ = nullptr;
86     std::shared_ptr<AccessibilityInputEventConsumer> inputEventConsumer_ = nullptr;
87     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
88 };
89 } // namespace Accessibility
90 } // namespace OHOS
91 #endif  // ACCESSIBILITY_INPUT_INTERCEPTOR_H
92