• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 INPUT_EVENT_INTERCEPTOR_H
17 #define INPUT_EVENT_INTERCEPTOR_H
18 
19 #include <atomic>
20 
21 #include "nocopyable.h"
22 
23 #include "channel.h"
24 #include "cooperate_events.h"
25 #include "i_context.h"
26 #include "input_event_transmission/input_event_sampler.h"
27 
28 namespace OHOS {
29 namespace Msdp {
30 namespace DeviceStatus {
31 namespace Cooperate {
32 class Context;
33 
34 class InputEventInterceptor final {
35 public:
InputEventInterceptor(IContext * env)36     InputEventInterceptor(IContext *env) : env_(env) {}
37     ~InputEventInterceptor();
38     DISALLOW_COPY_AND_MOVE(InputEventInterceptor);
39 
40     int32_t Enable(Context &context);
41     void Disable();
42     void Update(Context &context);
43 
44 private:
45     void OnPointerEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent);
46     void OnNotifyCrossDrag(std::shared_ptr<MMI::PointerEvent> pointerEvent);
47     void OnKeyEvent(std::shared_ptr<MMI::KeyEvent> keyEvent);
48     void ReportPointerEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent);
49     void TurnOffChannelScan();
50     void TurnOnChannelScan();
51     void ExecuteInner();
52     void HandleStopTimer();
53     int32_t SetWifiScene(unsigned int scene);
54     void RefreshActivity();
55     void HeartBeatSend();
56 
57     IContext *env_ { nullptr };
58     int32_t interceptorId_ { -1 };
59     bool scanState_ { true };
60     std::atomic<int32_t> heartTimer_ { -1 };
61     int32_t pointerEventTimer_ { -1 };
62     std::string remoteNetworkId_;
63     Channel<CooperateEvent>::Sender sender_;
64     InputEventSampler inputEventSampler_;
65     static std::set<int32_t> filterKeys_;
66     static std::set<int32_t> filterPointers_;
67 };
68 } // namespace Cooperate
69 } // namespace DeviceStatus
70 } // namespace Msdp
71 } // namespace OHOS
72 #endif // INPUT_EVENT_INTERCEPTOR_H
73