1 /* 2 * Copyright (c) 2021-2024 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 "client_death_handler.h" 20 #include "event_dispatch_handler.h" 21 #include "i_event_filter.h" 22 #include "inject_notice_manager.h" 23 #include "key_option.h" 24 #include "long_press_event.h" 25 #include "mouse_event_normalize.h" 26 #include "msg_handler.h" 27 #include "pixel_map.h" 28 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT 29 #include "sec_comp_enhance_kit.h" 30 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT 31 32 33 namespace OHOS { 34 namespace MMI { 35 enum class AuthorizationStatus : int32_t { 36 UNKNOWN, 37 AUTHORIZED, 38 UNAUTHORIZED 39 }; 40 41 enum class InjectionType : int32_t { 42 UNKNOWN, 43 KEYEVENT, 44 POINTEREVENT 45 }; 46 47 typedef std::function<int32_t(SessionPtr sess, NetPacket& pkt)> ServerMsgFun; 48 class ServerMsgHandler final : public MsgHandler<MmiMessageId, ServerMsgFun> { 49 public: 50 ServerMsgHandler() = default; 51 DISALLOW_COPY_AND_MOVE(ServerMsgHandler); 52 ~ServerMsgHandler() override = default; 53 54 void Init(UDSServer& udsServer); 55 void OnMsgHandler(SessionPtr sess, NetPacket& pkt); 56 #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) 57 int32_t OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType, 58 int32_t priority, uint32_t deviceTags); 59 int32_t OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, HandleEventType eventType, 60 int32_t priority, uint32_t deviceTags); 61 int32_t OnAddGestureMonitor(SessionPtr sess, InputHandlerType handlerType, 62 HandleEventType eventType, TouchGestureType gestureType, int32_t fingers); 63 int32_t OnRemoveGestureMonitor(SessionPtr sess, InputHandlerType handlerType, 64 HandleEventType eventType, TouchGestureType gestureType, int32_t fingers); 65 #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR 66 #ifdef OHOS_BUILD_ENABLE_MONITOR 67 int32_t OnMarkConsumed(SessionPtr sess, int32_t eventId); 68 #endif // OHOS_BUILD_ENABLE_MONITOR 69 #ifdef OHOS_BUILD_ENABLE_KEYBOARD 70 int32_t OnSubscribeKeyEvent(IUdsServer *server, int32_t pid, 71 int32_t subscribeId, const std::shared_ptr<KeyOption> option); 72 int32_t OnUnsubscribeKeyEvent(IUdsServer *server, int32_t pid, int32_t subscribeId); 73 int32_t OnSubscribeHotkey(IUdsServer *server, int32_t pid, 74 int32_t subscribeId, const std::shared_ptr<KeyOption> option); 75 int32_t OnUnsubscribeHotkey(IUdsServer *server, int32_t pid, int32_t subscribeId); 76 int32_t SubscribeKeyMonitor(int32_t session, const KeyMonitorOption &keyOption); 77 int32_t UnsubscribeKeyMonitor(int32_t session, const KeyMonitorOption &keyOption); 78 #endif // OHOS_BUILD_ENABLE_KEYBOARD 79 80 #ifdef OHOS_BUILD_ENABLE_SWITCH 81 int32_t OnSubscribeSwitchEvent(IUdsServer *server, int32_t pid, int32_t subscribeId, int32_t switchType); 82 int32_t OnUnsubscribeSwitchEvent(IUdsServer *server, int32_t pid, int32_t subscribeId); 83 #endif // OHOS_BUILD_ENABLE_SWITCH 84 int32_t OnSubscribetabletProximity(IUdsServer *server, int32_t pid, int32_t subscribeId); 85 int32_t OnUnsubscribetabletProximity(IUdsServer *server, int32_t pid, int32_t subscribeId); 86 int32_t OnSubscribeLongPressEvent(IUdsServer *server, int32_t pid, int32_t subscribeId, 87 const LongPressRequest &longPressRequest); 88 int32_t OnUnsubscribeLongPressEvent(IUdsServer *server, int32_t pid, int32_t subscribeId); 89 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) 90 int32_t OnMoveMouse(int32_t offsetX, int32_t offsetY); 91 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING 92 #ifdef OHOS_BUILD_ENABLE_KEYBOARD 93 int32_t OnInjectKeyEvent(const std::shared_ptr<KeyEvent> keyEvent, int32_t pid, bool isNativeInject); 94 int32_t OnGetFunctionKeyState(int32_t funcKey, bool &state); 95 int32_t OnSetFunctionKeyState(int32_t pid, int32_t funcKey, bool enable); 96 #endif // OHOS_BUILD_ENABLE_KEYBOARD 97 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 98 void DealGesturePointers(std::shared_ptr<PointerEvent> pointerEvent); 99 int32_t OnInjectPointerEvent(const std::shared_ptr<PointerEvent> pointerEvent, int32_t pid, 100 bool isNativeInject, bool isShell); 101 int32_t OnInjectTouchPadEvent(const std::shared_ptr<PointerEvent> pointerEvent, int32_t pid, 102 const TouchpadCDG &touchpadCDG, bool isNativeInject, bool isShell); 103 int32_t OnInjectPointerEventExt(const std::shared_ptr<PointerEvent> pointerEvent, bool isShell); 104 int32_t OnInjectTouchPadEventExt(const std::shared_ptr<PointerEvent> pointerEvent, 105 const TouchpadCDG &touchpadCDG, bool isShell); 106 int32_t SaveTargetWindowId(std::shared_ptr<PointerEvent> pointerEvent, bool isShell); 107 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 108 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD) 109 int32_t AddInputEventFilter(sptr<IEventFilter> filter, int32_t filterId, int32_t priority, uint32_t deviceTags, 110 int32_t clientPid); 111 int32_t RemoveInputEventFilter(int32_t clientPid, int32_t filterId); 112 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH || OHOS_BUILD_ENABLE_KEYBOARD 113 #ifdef OHOS_BUILD_ENABLE_KEYBOARD 114 int32_t SetShieldStatus(int32_t shieldMode, bool isShield); 115 int32_t GetShieldStatus(int32_t shieldMode, bool &isShield); 116 #endif // OHOS_BUILD_ENABLE_KEYBOARD 117 int32_t OnAuthorize(bool isAuthorize); 118 int32_t OnCancelInjection(int32_t callPidId = 0); 119 int32_t SetPixelMapData(int32_t infoId, void* pixelMap); 120 bool InitInjectNoticeSource(); 121 bool AddInjectNotice(const InjectNoticeInfo& noticeInfo); 122 int32_t OnTransferBinderClientSrv(const sptr<IRemoteObject> &binderClientObject, int32_t pid); 123 int32_t RegisterWindowStateErrorCallback(SessionPtr sess, NetPacket &pkt); 124 125 protected: 126 int32_t OnRegisterMsgHandler(SessionPtr sess, NetPacket& pkt); 127 int32_t OnDisplayInfo(SessionPtr sess, NetPacket& pkt); 128 int32_t OnWindowGroupInfo(SessionPtr sess, NetPacket &pkt); 129 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT 130 int32_t OnEnhanceConfig(SessionPtr sess, NetPacket& pkt); 131 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT 132 void SetWindowInfo(int32_t infoId, WindowInfo &info); 133 134 private: 135 #ifdef OHOS_BUILD_ENABLE_TOUCH 136 bool FixTargetWindowId(std::shared_ptr<PointerEvent> pointerEvent, int32_t action, bool isShell); 137 bool UpdateTouchEvent(std::shared_ptr<PointerEvent> pointerEvent, int32_t action, int32_t targetWindowId); 138 #endif // OHOS_BUILD_ENABLE_TOUCH 139 void LaunchAbility(); 140 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 141 int32_t AccelerateMotion(std::shared_ptr<PointerEvent> pointerEvent); 142 int32_t AccelerateMotionTouchpad(std::shared_ptr<PointerEvent> pointerEvent, const TouchpadCDG &touchpadCDG); 143 float ScreenFactor(const int32_t diagonalInch); 144 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 145 #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) 146 void UpdatePointerEvent(std::shared_ptr<PointerEvent> pointerEvent); 147 #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH 148 #ifdef OHOS_BUILD_ENABLE_POINTER 149 void CalculateOffset(Direction direction, Offset &offset); 150 #endif // OHOS_BUILD_ENABLE_POINTER 151 int32_t OnUiExtentionWindowInfo(NetPacket &pkt, WindowInfo& info); 152 bool CloseInjectNotice(int32_t pid); 153 bool IsNavigationWindowInjectEvent(std::shared_ptr<PointerEvent> pointerEvent); 154 int32_t NativeInjectCheck(int32_t pid); 155 int32_t ReadDisplayInfo(NetPacket &pkt, DisplayGroupInfo &displayGroupInfo); 156 bool IsCastInject(int32_t deviceid); 157 private: 158 UDSServer *udsServer_ { nullptr }; 159 std::map<int32_t, int32_t> nativeTargetWindowIds_; 160 std::map<int32_t, int32_t> shellTargetWindowIds_; 161 std::map<int32_t, int32_t> accessTargetWindowIds_; 162 std::map<int32_t, int32_t> castTargetWindowIds_; 163 std::map<int32_t, AuthorizationStatus> authorizationCollection_; 164 int32_t CurrentPID_ { -1 }; 165 InjectionType InjectionType_ { InjectionType::UNKNOWN }; 166 std::shared_ptr<KeyEvent> keyEvent_ { nullptr }; 167 std::shared_ptr<PointerEvent> pointerEvent_ { nullptr }; 168 std::map<int32_t, std::unique_ptr<Media::PixelMap>> transparentWins_; 169 std::shared_ptr<InjectNoticeManager> injectNotice_ { nullptr }; 170 ClientDeathHandler clientDeathHandler_; 171 }; 172 } // namespace MMI 173 } // namespace OHOS 174 #endif // SERVER_MSG_HANDLER_H 175