• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 SERVER_MSG_HANDLER_H
17 #define SERVER_MSG_HANDLER_H
18 
19 #include "nocopyable.h"
20 
21 #include "event_dispatch_handler.h"
22 #include "i_event_filter.h"
23 #include "input_handler_type.h"
24 #include "key_option.h"
25 #include "msg_handler.h"
26 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
27 #include "sec_comp_enhance_kit.h"
28 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
29 
30 namespace OHOS {
31 namespace MMI {
32 typedef std::function<int32_t(SessionPtr sess, NetPacket& pkt)> ServerMsgFun;
33 class ServerMsgHandler final : public MsgHandler<MmiMessageId, ServerMsgFun> {
34 public:
35     ServerMsgHandler() = default;
36     DISALLOW_COPY_AND_MOVE(ServerMsgHandler);
37     ~ServerMsgHandler() override = default;
38 
39     void Init(UDSServer& udsServer);
40     void OnMsgHandler(SessionPtr sess, NetPacket& pkt);
41 #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR)
42     int32_t OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType,
43         int32_t priority, uint32_t deviceTags);
44     int32_t OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType,
45         int32_t priority, uint32_t deviceTags);
46 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR
47 #ifdef OHOS_BUILD_ENABLE_MONITOR
48     int32_t OnMarkConsumed(SessionPtr sess, int32_t eventId);
49 #endif // OHOS_BUILD_ENABLE_MONITOR
50 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
51     int32_t OnSubscribeKeyEvent(IUdsServer *server, int32_t pid,
52         int32_t subscribeId, const std::shared_ptr<KeyOption> option);
53     int32_t OnUnsubscribeKeyEvent(IUdsServer *server, int32_t pid, int32_t subscribeId);
54 #endif // OHOS_BUILD_ENABLE_KEYBOARD
55 
56 #ifdef OHOS_BUILD_ENABLE_SWITCH
57     int32_t OnSubscribeSwitchEvent(IUdsServer *server, int32_t pid, int32_t subscribeId);
58     int32_t OnUnsubscribeSwitchEvent(IUdsServer *server, int32_t pid, int32_t subscribeId);
59 #endif // OHOS_BUILD_ENABLE_SWITCH
60 
61 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
62     int32_t OnMoveMouse(int32_t offsetX, int32_t offsetY);
63 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
64 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
65     int32_t OnInjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent);
66     int32_t OnGetFunctionKeyState(int32_t funcKey, bool &state);
67     int32_t OnSetFunctionKeyState(int32_t funcKey, bool enable);
68 #endif // OHOS_BUILD_ENABLE_KEYBOARD
69 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
70     int32_t OnInjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent);
71 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
72 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
73     int32_t AddInputEventFilter(sptr<IEventFilter> filter, int32_t filterId, int32_t priority, uint32_t deviceTags,
74         int32_t clientPid);
75     int32_t RemoveInputEventFilter(int32_t clientPid, int32_t filterId);
76 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
77     int32_t SetShieldStatus(int32_t shieldMode, bool isShield);
78     int32_t GetShieldStatus(int32_t shieldMode, bool &isShield);
79 protected:
80     int32_t OnRegisterMsgHandler(SessionPtr sess, NetPacket& pkt);
81     int32_t OnDisplayInfo(SessionPtr sess, NetPacket& pkt);
82     int32_t OnWindowAreaInfo(SessionPtr sess, NetPacket& pkt);
83     int32_t OnWindowGroupInfo(SessionPtr sess, NetPacket &pkt);
84 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
85     int32_t OnEnhanceConfig(SessionPtr sess, NetPacket& pkt);
86 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
87 
88 private:
89 #ifdef OHOS_BUILD_ENABLE_TOUCH
90     bool FixTargetWindowId(std::shared_ptr<PointerEvent> pointerEvent, int32_t action);
91 #endif // OHOS_BUILD_ENABLE_TOUCH
92 
93 private:
94     UDSServer *udsServer_ { nullptr };
95     std::map<int32_t, int32_t> targetWindowIds_;
96 };
97 } // namespace MMI
98 } // namespace OHOS
99 #endif // SERVER_MSG_HANDLER_H
100