1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci */
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#ifndef SERVER_MSG_HANDLER_H
17c29fa5a6Sopenharmony_ci#define SERVER_MSG_HANDLER_H
18c29fa5a6Sopenharmony_ci
19c29fa5a6Sopenharmony_ci#include "nocopyable.h"
20c29fa5a6Sopenharmony_ci
21c29fa5a6Sopenharmony_ci#include "event_dispatch_handler.h"
22c29fa5a6Sopenharmony_ci#include "i_event_filter.h"
23c29fa5a6Sopenharmony_ci#include "input_handler_type.h"
24c29fa5a6Sopenharmony_ci#include "key_option.h"
25c29fa5a6Sopenharmony_ci#include "mouse_event_normalize.h"
26c29fa5a6Sopenharmony_ci#include "msg_handler.h"
27c29fa5a6Sopenharmony_ci#include "pixel_map.h"
28c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
29c29fa5a6Sopenharmony_ci#include "sec_comp_enhance_kit.h"
30c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
31c29fa5a6Sopenharmony_ci#include "window_info.h"
32c29fa5a6Sopenharmony_ci#include "inject_notice_manager.h"
33c29fa5a6Sopenharmony_ci#include "client_death_handler.h"
34c29fa5a6Sopenharmony_ci
35c29fa5a6Sopenharmony_cinamespace OHOS {
36c29fa5a6Sopenharmony_cinamespace MMI {
37c29fa5a6Sopenharmony_cienum class AuthorizationStatus : int32_t {
38c29fa5a6Sopenharmony_ci    UNKNOWN,
39c29fa5a6Sopenharmony_ci    AUTHORIZED,
40c29fa5a6Sopenharmony_ci    UNAUTHORIZED
41c29fa5a6Sopenharmony_ci};
42c29fa5a6Sopenharmony_ci
43c29fa5a6Sopenharmony_cienum class InjectionType : int32_t {
44c29fa5a6Sopenharmony_ci    UNKNOWN,
45c29fa5a6Sopenharmony_ci    KEYEVENT,
46c29fa5a6Sopenharmony_ci    POINTEREVENT
47c29fa5a6Sopenharmony_ci};
48c29fa5a6Sopenharmony_ci
49c29fa5a6Sopenharmony_citypedef std::function<int32_t(SessionPtr sess, NetPacket& pkt)> ServerMsgFun;
50c29fa5a6Sopenharmony_ciclass ServerMsgHandler final : public MsgHandler<MmiMessageId, ServerMsgFun> {
51c29fa5a6Sopenharmony_cipublic:
52c29fa5a6Sopenharmony_ci    ServerMsgHandler() = default;
53c29fa5a6Sopenharmony_ci    DISALLOW_COPY_AND_MOVE(ServerMsgHandler);
54c29fa5a6Sopenharmony_ci    ~ServerMsgHandler() override = default;
55c29fa5a6Sopenharmony_ci
56c29fa5a6Sopenharmony_ci    void Init(UDSServer& udsServer);
57c29fa5a6Sopenharmony_ci    void OnMsgHandler(SessionPtr sess, NetPacket& pkt);
58c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR)
59c29fa5a6Sopenharmony_ci    int32_t OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType,
60c29fa5a6Sopenharmony_ci        int32_t priority, uint32_t deviceTags);
61c29fa5a6Sopenharmony_ci    int32_t OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType,
62c29fa5a6Sopenharmony_ci        int32_t priority, uint32_t deviceTags);
63c29fa5a6Sopenharmony_ci    int32_t OnAddGestureMonitor(SessionPtr sess, InputHandlerType handlerType,
64c29fa5a6Sopenharmony_ci        HandleEventType eventType, TouchGestureType gestureType, int32_t fingers);
65c29fa5a6Sopenharmony_ci    int32_t OnRemoveGestureMonitor(SessionPtr sess, InputHandlerType handlerType,
66c29fa5a6Sopenharmony_ci        HandleEventType eventType, TouchGestureType gestureType, int32_t fingers);
67c29fa5a6Sopenharmony_ci    int32_t OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, std::vector<int32_t> actionsType);
68c29fa5a6Sopenharmony_ci    int32_t OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, std::vector<int32_t> actionsType);
69c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR
70c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_MONITOR
71c29fa5a6Sopenharmony_ci    int32_t OnMarkConsumed(SessionPtr sess, int32_t eventId);
72c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_MONITOR
73c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_KEYBOARD
74c29fa5a6Sopenharmony_ci    int32_t OnSubscribeKeyEvent(IUdsServer *server, int32_t pid,
75c29fa5a6Sopenharmony_ci        int32_t subscribeId, const std::shared_ptr<KeyOption> option);
76c29fa5a6Sopenharmony_ci    int32_t OnUnsubscribeKeyEvent(IUdsServer *server, int32_t pid, int32_t subscribeId);
77c29fa5a6Sopenharmony_ci    int32_t OnSubscribeHotkey(IUdsServer *server, int32_t pid,
78c29fa5a6Sopenharmony_ci        int32_t subscribeId, const std::shared_ptr<KeyOption> option);
79c29fa5a6Sopenharmony_ci    int32_t OnUnsubscribeHotkey(IUdsServer *server, int32_t pid, int32_t subscribeId);
80c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_KEYBOARD
81c29fa5a6Sopenharmony_ci
82c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_SWITCH
83c29fa5a6Sopenharmony_ci    int32_t OnSubscribeSwitchEvent(IUdsServer *server, int32_t pid, int32_t subscribeId, int32_t switchType);
84c29fa5a6Sopenharmony_ci    int32_t OnUnsubscribeSwitchEvent(IUdsServer *server, int32_t pid, int32_t subscribeId);
85c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_SWITCH
86c29fa5a6Sopenharmony_ci
87c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
88c29fa5a6Sopenharmony_ci    int32_t OnMoveMouse(int32_t offsetX, int32_t offsetY);
89c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
90c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_KEYBOARD
91c29fa5a6Sopenharmony_ci    int32_t OnInjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent, int32_t pid, bool isNativeInject);
92c29fa5a6Sopenharmony_ci    int32_t OnGetFunctionKeyState(int32_t funcKey, bool &state);
93c29fa5a6Sopenharmony_ci    int32_t OnSetFunctionKeyState(int32_t funcKey, bool enable);
94c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_KEYBOARD
95c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
96c29fa5a6Sopenharmony_ci    int32_t OnInjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent, int32_t pid,
97c29fa5a6Sopenharmony_ci        bool isNativeInject, bool isShell);
98c29fa5a6Sopenharmony_ci    int32_t OnInjectPointerEventExt(const std::shared_ptr<PointerEvent> pointerEvent, bool isShell);
99c29fa5a6Sopenharmony_ci    int32_t SaveTargetWindowId(std::shared_ptr<PointerEvent> pointerEvent, bool isShell);
100c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
101c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD)
102c29fa5a6Sopenharmony_ci    int32_t AddInputEventFilter(sptr<IEventFilter> filter, int32_t filterId, int32_t priority, uint32_t deviceTags,
103c29fa5a6Sopenharmony_ci        int32_t clientPid);
104c29fa5a6Sopenharmony_ci    int32_t RemoveInputEventFilter(int32_t clientPid, int32_t filterId);
105c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH || OHOS_BUILD_ENABLE_KEYBOARD
106c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_KEYBOARD
107c29fa5a6Sopenharmony_ci    int32_t SetShieldStatus(int32_t shieldMode, bool isShield);
108c29fa5a6Sopenharmony_ci    int32_t GetShieldStatus(int32_t shieldMode, bool &isShield);
109c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_KEYBOARD
110c29fa5a6Sopenharmony_ci    int32_t OnAuthorize(bool isAuthorize);
111c29fa5a6Sopenharmony_ci    int32_t OnCancelInjection();
112c29fa5a6Sopenharmony_ci    int32_t SetPixelMapData(int32_t infoId, void* pixelMap);
113c29fa5a6Sopenharmony_ci    bool InitInjectNoticeSource();
114c29fa5a6Sopenharmony_ci    bool AddInjectNotice(const InjectNoticeInfo& noticeInfo);
115c29fa5a6Sopenharmony_ci    int32_t OnTransferBinderClientSrv(const sptr<IRemoteObject> &binderClientObject, int32_t pid);
116c29fa5a6Sopenharmony_ci    int32_t RegisterWindowStateErrorCallback(SessionPtr sess, NetPacket &pkt);
117c29fa5a6Sopenharmony_ci
118c29fa5a6Sopenharmony_ciprotected:
119c29fa5a6Sopenharmony_ci    int32_t OnRegisterMsgHandler(SessionPtr sess, NetPacket& pkt);
120c29fa5a6Sopenharmony_ci    int32_t OnDisplayInfo(SessionPtr sess, NetPacket& pkt);
121c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
122c29fa5a6Sopenharmony_ci    int32_t OnWindowAreaInfo(SessionPtr sess, NetPacket& pkt);
123c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
124c29fa5a6Sopenharmony_ci    int32_t OnWindowGroupInfo(SessionPtr sess, NetPacket &pkt);
125c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
126c29fa5a6Sopenharmony_ci    int32_t OnEnhanceConfig(SessionPtr sess, NetPacket& pkt);
127c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
128c29fa5a6Sopenharmony_ci    void SetWindowInfo(int32_t infoId, WindowInfo &info);
129c29fa5a6Sopenharmony_ci
130c29fa5a6Sopenharmony_ciprivate:
131c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_TOUCH
132c29fa5a6Sopenharmony_ci    bool FixTargetWindowId(std::shared_ptr<PointerEvent> pointerEvent, int32_t action, bool isShell);
133c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_TOUCH
134c29fa5a6Sopenharmony_ci    void LaunchAbility();
135c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_POINTER
136c29fa5a6Sopenharmony_ci    int32_t AccelerateMotion(std::shared_ptr<PointerEvent> pointerEvent);
137c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER
138c29fa5a6Sopenharmony_ci#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH)
139c29fa5a6Sopenharmony_ci    void UpdatePointerEvent(std::shared_ptr<PointerEvent> pointerEvent);
140c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH
141c29fa5a6Sopenharmony_ci#ifdef OHOS_BUILD_ENABLE_POINTER
142c29fa5a6Sopenharmony_ci    void CalculateOffset(Direction direction, Offset &offset);
143c29fa5a6Sopenharmony_ci#endif // OHOS_BUILD_ENABLE_POINTER
144c29fa5a6Sopenharmony_ci    bool CloseInjectNotice(int32_t pid);
145c29fa5a6Sopenharmony_ci    int32_t OnUiExtentionWindowInfo(NetPacket &pkt, WindowInfo& info);
146c29fa5a6Sopenharmony_ci    bool IsNavigationWindowInjectEvent(std::shared_ptr<PointerEvent> pointerEvent);
147c29fa5a6Sopenharmony_ciprivate:
148c29fa5a6Sopenharmony_ci    UDSServer *udsServer_ { nullptr };
149c29fa5a6Sopenharmony_ci    std::map<int32_t, int32_t> nativeTargetWindowIds_;
150c29fa5a6Sopenharmony_ci    std::map<int32_t, int32_t> shellTargetWindowIds_;
151c29fa5a6Sopenharmony_ci    std::map<int32_t, int32_t> accessTargetWindowIds_;
152c29fa5a6Sopenharmony_ci    std::map<int32_t, AuthorizationStatus> authorizationCollection_;
153c29fa5a6Sopenharmony_ci    int32_t CurrentPID_ { -1 };
154c29fa5a6Sopenharmony_ci    InjectionType InjectionType_ { InjectionType::UNKNOWN };
155c29fa5a6Sopenharmony_ci    std::shared_ptr<KeyEvent> keyEvent_ { nullptr };
156c29fa5a6Sopenharmony_ci    std::shared_ptr<PointerEvent> pointerEvent_ { nullptr };
157c29fa5a6Sopenharmony_ci    std::map<int32_t, std::unique_ptr<Media::PixelMap>> transparentWins_;
158c29fa5a6Sopenharmony_ci    std::shared_ptr<InjectNoticeManager> injectNotice_ { nullptr };
159c29fa5a6Sopenharmony_ci    ClientDeathHandler clientDeathHandler_;
160c29fa5a6Sopenharmony_ci};
161c29fa5a6Sopenharmony_ci} // namespace MMI
162c29fa5a6Sopenharmony_ci} // namespace OHOS
163c29fa5a6Sopenharmony_ci#endif // SERVER_MSG_HANDLER_H
164