diff --git a/frameworks/proxy/event_handler/include/input_manager_impl.h b/frameworks/proxy/event_handler/include/input_manager_impl.h index b3453e44a29f0d90e682678c61477868f4e3b189..411850a63ea7933fcd22f78acd8be9563d6e12e0 100644 --- a/frameworks/proxy/event_handler/include/input_manager_impl.h +++ b/frameworks/proxy/event_handler/include/input_manager_impl.h @@ -13,308 +13,309 @@ * limitations under the License. */ -#ifndef INPUT_MANAGER_IMPL_H -#define INPUT_MANAGER_IMPL_H - -#include "event_filter_service.h" -#include "extra_data.h" -#include "i_anco_channel.h" -#include "i_anr_observer.h" -#include "i_input_service_watcher.h" -#include "i_window_checker.h" -#include "if_mmi_client.h" -#include "infrared_frequency_info.h" -#include "input_device_impl.h" -#include "input_device_consumer.h" -#ifdef OHOS_BUILD_ENABLE_INTERCEPTOR -#include "input_interceptor_manager.h" -#endif // OHOS_BUILD_ENABLE_INTERCEPTOR -#ifdef OHOS_BUILD_ENABLE_MONITOR -#include "input_monitor_manager.h" -#endif // OHOS_BUILD_ENABLE_MONITOR -#include "key_option.h" -#include "long_press_event.h" -#include "mmi_event_observer.h" -#include "nap_process.h" -#include "pointer_style.h" -#include "touchpad_control_display_gain.h" -#include "shift_info.h" - -namespace OHOS { -namespace MMI { -class InputManagerImpl final { - DECLARE_SINGLETON(InputManagerImpl); - -public: - DISALLOW_MOVE(InputManagerImpl); - - int32_t GetDisplayBindInfo(DisplayBindInfos &infos); - int32_t GetAllMmiSubscribedEvents(std::map, int32_t> &datas); - int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); - int32_t GetWindowPid(int32_t windowId); - int32_t UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo); - int32_t UpdateDisplayInfo(const std::vector &displayGroupInfo); - int32_t UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo); -#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT - void SetEnhanceConfig(uint8_t *cfg, uint32_t cfgLen); -#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT - int32_t SubscribeKeyEvent(std::shared_ptr keyOption, - std::function)> callback); - void UnsubscribeKeyEvent(int32_t subscriberId); - int32_t SubscribeHotkey(std::shared_ptr keyOption, - std::function)> callback); - void UnsubscribeHotkey(int32_t subscriberId); - int32_t SubscribeKeyMonitor(const KeyMonitorOption &keyOption, - std::function)> callback); - int32_t UnsubscribeKeyMonitor(int32_t subscriberId); - int32_t SubscribeSwitchEvent(int32_t switchType, std::function)> callback); - void UnsubscribeSwitchEvent(int32_t subscriberId); - int32_t QuerySwitchStatus(int32_t switchTpe, int32_t& state); - int32_t SubscribeTabletProximity(std::function)> callback); - void UnsubscribetabletProximity(int32_t subscriberId); - int32_t SubscribeLongPressEvent(const LongPressRequest &LongPressRequest, - std::function callback); - void UnsubscribeLongPressEvent(int32_t subscriberId); - int32_t AddInputEventFilter(std::shared_ptr filter, int32_t priority, uint32_t deviceTags); - int32_t RemoveInputEventFilter(int32_t filterId); - int32_t AddInputEventObserver(std::shared_ptr observer); - int32_t RemoveInputEventObserver(std::shared_ptr observer); - int32_t NotifyNapOnline(); - void NotifyBundleName(int32_t pid, int32_t uid, const std::string &bundleName, int32_t syncStatus); - int32_t SetWindowInputEventConsumer(std::shared_ptr inputEventConsumer, - std::shared_ptr eventHandler); - void ClearWindowPointerStyle(int32_t pid, int32_t windowId); - int32_t SetNapStatus(int32_t pid, int32_t uid, const std::string &bundleName, int32_t napStatus); - int32_t SetTouchpadThreeFingersTapSwitch(bool switchFlag); - int32_t GetTouchpadThreeFingersTapSwitch(bool &switchFlag); - void SetMultiWindowScreenId(uint64_t screenId, uint64_t displayNodeScreenId); - int32_t SetKnuckleSwitch(bool knuckleSwitch); - int32_t SetInputDeviceConsumer(const std::vector& deviceName, - std::shared_ptr consumer); - void OnDeviceConsumerEvent(std::shared_ptr pointerEvent); - -#ifdef OHOS_BUILD_ENABLE_KEYBOARD - void OnKeyEvent(std::shared_ptr keyEvent); -#endif // OHOS_BUILD_ENABLE_KEYBOARD -#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) - void OnPointerEvent(std::shared_ptr pointerEvent); -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH - int32_t PackDisplayData(NetPacket &pkt, DisplayGroupInfo &displayGroupInfo); - - int32_t AddMonitor(std::function)> monitor); - int32_t AddMonitor(std::function)> monitor); - int32_t AddMonitor(std::shared_ptr consumer, - HandleEventType eventType = HANDLE_EVENT_TYPE_KP); - int32_t AddGestureMonitor(std::shared_ptr consumer, - TouchGestureType type, int32_t fingers); - int32_t RemoveGestureMonitor(int32_t monitorId); - int32_t AddMonitor(std::shared_ptr monitor, std::vector actionsType); - - int32_t RemoveMonitor(int32_t monitorId); - void MarkConsumed(int32_t monitorId, int32_t eventId); - void MoveMouse(int32_t offsetX, int32_t offsetY); - - int32_t AddInterceptor(std::shared_ptr interceptor, - int32_t priority = DEFUALT_INTERCEPTOR_PRIORITY, - uint32_t deviceTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX)); - int32_t AddInterceptor(std::function)> interceptor, - int32_t priority = DEFUALT_INTERCEPTOR_PRIORITY, - uint32_t deviceTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX)); - int32_t RemoveInterceptor(int32_t interceptorId); - - void SimulateInputEvent(std::shared_ptr keyEvent, bool isNativeInject = false); - int32_t SimulateInputEvent(std::shared_ptr pointerEvent, bool isNativeInject = false); - void HandleSimulateInputEvent(std::shared_ptr pointerEvent); - void SimulateTouchPadEvent(std::shared_ptr pointerEvent, bool isNativeInject = false); - void SimulateTouchPadInputEvent(std::shared_ptr pointerEvent, - const TouchpadCDG &touchpadCDG); - void OnConnected(); -#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) - template - bool RecoverPointerEvent(std::initializer_list pointerActionEvents, T pointerActionEvent); -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH - void OnDisconnected(); - - int32_t RegisterDevListener(std::string type, std::shared_ptr listener); - int32_t UnregisterDevListener(std::string type, std::shared_ptr listener = nullptr); - int32_t GetDeviceIds(std::function&)> callback); - int32_t GetDevice(int32_t deviceId, std::function)> callback); - int32_t SupportKeys(int32_t deviceId, std::vector &keyCodes, - std::function&)> callback); - int32_t GetKeyboardType(int32_t deviceId, std::function callback); - int32_t SetKeyboardRepeatDelay(int32_t delay); - int32_t SetKeyboardRepeatRate(int32_t rate); - int32_t GetKeyboardRepeatDelay(std::function callback); - int32_t GetKeyboardRepeatRate(std::function callback); - - int32_t SetMouseScrollRows(int32_t rows); - int32_t GetMouseScrollRows(int32_t &rows); - int32_t SetPointerSize(int32_t size); - int32_t GetPointerSize(int32_t &size); - int32_t GetCursorSurfaceId(uint64_t &surfaceId); - int32_t SetCustomCursor(int32_t windowId, int32_t focusX, int32_t focusY, void* pixelMap); - int32_t SetCustomCursor(int32_t windowId, CustomCursor cursor, CursorOptions options); - int32_t SetMouseIcon(int32_t windowId, void* pixelMap); - int32_t SetMouseHotSpot(int32_t windowId, int32_t hotSpotX, int32_t hotSpotY); - int32_t SetMousePrimaryButton(int32_t primaryButton); - int32_t GetMousePrimaryButton(int32_t &primaryButton); - int32_t SetHoverScrollState(bool state); - int32_t GetHoverScrollState(bool &state); - - int32_t SetPointerVisible(bool visible, int32_t priority); - bool IsPointerVisible(); - int32_t SetPointerStyle(int32_t windowId, const PointerStyle& pointerStyle, bool isUiExtension = false); - int32_t GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle, bool isUiExtension = false); - - int32_t SetPointerColor(int32_t color); - int32_t GetPointerColor(int32_t &color); - int32_t EnableCombineKey(bool enable); - int32_t SetPointerSpeed(int32_t speed); - int32_t GetPointerSpeed(int32_t &speed); - - int32_t SetTouchpadScrollSwitch(bool switchFlag); - int32_t GetTouchpadScrollSwitch(bool &switchFlag); - int32_t SetTouchpadScrollDirection(bool state); - int32_t GetTouchpadScrollDirection(bool &state); - int32_t SetTouchpadTapSwitch(bool switchFlag); - int32_t GetTouchpadTapSwitch(bool &switchFlag); - int32_t SetTouchpadPointerSpeed(int32_t speed); - int32_t GetTouchpadPointerSpeed(int32_t &speed); - int32_t GetTouchpadCDG(TouchpadCDG &touchpadCDG); - int32_t SetTouchpadPinchSwitch(bool switchFlag); - int32_t GetTouchpadPinchSwitch(bool &switchFlag); - int32_t SetTouchpadSwipeSwitch(bool switchFlag); - int32_t GetTouchpadSwipeSwitch(bool &switchFlag); - int32_t SetTouchpadRightClickType(int32_t type); - int32_t GetTouchpadRightClickType(int32_t &type); - int32_t SetTouchpadRotateSwitch(bool rotateSwitch); - int32_t GetTouchpadRotateSwitch(bool &rotateSwitch); - int32_t SetTouchpadDoubleTapAndDragState(bool switchFlag); - int32_t GetTouchpadDoubleTapAndDragState(bool &switchFlag); - int32_t EnableHardwareCursorStats(bool enable); - int32_t GetHardwareCursorStats(uint32_t &frameCount, uint32_t &vsyncCount); - int32_t GetPointerSnapshot(void *pixelMapPtr); - int32_t SetTouchpadScrollRows(int32_t rows); - int32_t GetTouchpadScrollRows(int32_t &rows); - - void SetAnrObserver(std::shared_ptr observer); - void OnAnr(int32_t pid, int32_t eventId); - - int32_t EnterCaptureMode(int32_t windowId); - int32_t LeaveCaptureMode(int32_t windowId); - int32_t GetFunctionKeyState(int32_t funcKey, bool &resultState); - int32_t SetFunctionKeyState(int32_t funcKey, bool enable); - int32_t SetPointerLocation(int32_t x, int32_t y, int32_t displayId); - int32_t EnableInputDevice(bool enable); - // 快捷键拉起Ability - int32_t SetKeyDownDuration(const std::string &businessId, int32_t delay); - - int32_t AppendExtraData(const ExtraData& extraData); - int32_t SetShieldStatus(int32_t shieldMode, bool isShield); - int32_t GetShieldStatus(int32_t shieldMode, bool &isShield); - - void AddServiceWatcher(std::shared_ptr watcher); - void RemoveServiceWatcher(std::shared_ptr watcher); - - int32_t MarkProcessed(int32_t eventId, int64_t actionTime); - - int32_t GetKeyState(std::vector &pressedKeys, std::map &specialKeysState); - void Authorize(bool isAuthorize); - int32_t CancelInjection(); - - int32_t HasIrEmitter(bool &hasIrEmitter); - int32_t GetInfraredFrequencies(std::vector& requencys); - int32_t TransmitInfrared(int64_t number, std::vector& pattern); -#ifdef OHOS_BUILD_ENABLE_VKEYBOARD - int32_t CreateVKeyboardDevice(sptr &vkeyboardDevice); -#endif // OHOS_BUILD_ENABLE_VKEYBOARD - int32_t SetPixelMapData(int32_t infoId, void* pixelMap); - int32_t SetCurrentUser(int32_t userId); - int32_t SetMoveEventFilters(bool flag); - int32_t GetWinSyncBatchSize(int32_t maxAreasCount, int32_t displayCount); - int32_t AddVirtualInputDevice(std::shared_ptr device, int32_t &deviceId); - int32_t RemoveVirtualInputDevice(int32_t deviceId); - int32_t AncoAddChannel(std::shared_ptr consumer); - int32_t AncoRemoveChannel(std::shared_ptr consumer); - int32_t SkipPointerLayer(bool isSkip); - int32_t RegisterWindowStateErrorCallback(std::function callback); - void OnWindowStateError(int32_t pid, int32_t windowId); - int32_t GetAllSystemHotkeys(std::vector> &keyOptions, int32_t &count); - int32_t GetIntervalSinceLastInput(int64_t &timeInterval); - int32_t ConvertToCapiKeyAction(int32_t keyAction); - int32_t SetInputDeviceEnabled(int32_t deviceId, bool enable, std::function callback); - int32_t ShiftAppPointerEvent(const ShiftWindowParam ¶m, bool autoGenDown); - int32_t CheckKnuckleEvent(float pointX, float pointY, bool &touchType); - int32_t LaunchAiScreenAbility(); - int32_t GetMaxMultiTouchPointNum(int32_t &pointNum); - int32_t SubscribeInputActive(std::shared_ptr inputEventConsumer, int64_t interval); - void UnsubscribeInputActive(int32_t subscribeId); - -private: - int32_t PackWindowInfo(NetPacket &pkt, DisplayGroupInfo &displayGroupInfo); - int32_t PackWindowGroupInfo(NetPacket &pkt); - int32_t PackDisplayInfo(NetPacket &pkt, DisplayGroupInfo &displayGroupInfo); - int32_t PackUiExtentionWindowInfo(const std::vector& windowsInfo, NetPacket &pkt); - void PrintWindowInfo(const std::vector &windowsInfo); - void PrintForemostThreeWindowInfo(const std::vector &windowsInfo); - void PrintDisplayInfo(DisplayGroupInfo &displayGroupInfo); - void PrintWindowGroupInfo(); - int32_t SendDisplayInfo(DisplayGroupInfo &displayGroupInfo); - int32_t SendWindowInfo(); - void SendWindowAreaInfo(WindowArea area, int32_t pid, int32_t windowId); - bool IsValiadWindowAreas(const std::vector &windows); - int32_t GetDisplayMaxSize(); - int32_t GetWindowMaxSize(int32_t maxAreasCount); - std::vector StringSplit(const std::string &str, char delim); - bool IsGRLOrHopper(); -#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT - int32_t PackEnhanceConfig(NetPacket &pkt); - void SendEnhanceConfig(); - void PrintEnhanceConfig(); -#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT - void ReAddInputEventFilter(); - -#ifdef OHOS_BUILD_ENABLE_KEYBOARD - void OnKeyEventTask(std::shared_ptr consumer, - std::shared_ptr keyEvent); -#endif // OHOS_BUILD_ENABLE_KEYBOARD -#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) - void OnPointerEventTask(std::shared_ptr consumer, - std::shared_ptr pointerEvent); -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH -#ifdef OHOS_BUILD_ENABLE_ANCO - bool IsValidAncoWindow(const std::vector &windows); -#endif // OHOS_BUILD_ENABLE_ANCO - -private: - std::map, int32_t, uint32_t>> eventFilterServices_; - std::shared_ptr eventObserver_ { nullptr }; - std::shared_ptr consumer_ { nullptr }; - std::vector> anrObservers_; - std::shared_ptr winChecker_ { nullptr }; - DisplayGroupInfo displayGroupInfo_ {}; - WindowGroupInfo windowGroupInfo_ {}; - std::mutex mtx_; - std::mutex eventObserverMtx_; - std::mutex winStatecallbackMtx_; - mutable std::mutex resourceMtx_; - std::condition_variable cv_; - std::thread ehThread_; - std::shared_ptr eventHandler_ { nullptr }; - std::shared_ptr lastPointerEvent_ { nullptr }; - std::function windowStatecallback_; - bool knuckleSwitch_ { true }; - std::vector displayGroupInfoArray_; -#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT - uint8_t* enhanceCfg_ = nullptr; - uint32_t enhanceCfgLen_ = 0; -#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT -#ifdef OHOS_BUILD_ENABLE_ANCO - std::map, sptr> ancoChannels_; -#endif // OHOS_BUILD_ENABLE_ANCO -}; - -#define InputMgrImpl ::OHOS::Singleton::GetInstance() -} // namespace MMI -} // namespace OHOS -#endif // INPUT_MANAGER_IMPL_H + #ifndef INPUT_MANAGER_IMPL_H + #define INPUT_MANAGER_IMPL_H + + #include "event_filter_service.h" + #include "extra_data.h" + #include "i_anco_channel.h" + #include "i_anr_observer.h" + #include "i_input_service_watcher.h" + #include "i_window_checker.h" + #include "if_mmi_client.h" + #include "infrared_frequency_info.h" + #include "input_device_impl.h" + #include "input_device_consumer.h" + #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR + #include "input_interceptor_manager.h" + #endif // OHOS_BUILD_ENABLE_INTERCEPTOR + #ifdef OHOS_BUILD_ENABLE_MONITOR + #include "input_monitor_manager.h" + #endif // OHOS_BUILD_ENABLE_MONITOR + #include "key_option.h" + #include "long_press_event.h" + #include "mmi_event_observer.h" + #include "nap_process.h" + #include "pointer_style.h" + #include "touchpad_control_display_gain.h" + #include "shift_info.h" + + namespace OHOS { + namespace MMI { + class InputManagerImpl final { + DECLARE_SINGLETON(InputManagerImpl); + + public: + DISALLOW_MOVE(InputManagerImpl); + + int32_t GetDisplayBindInfo(DisplayBindInfos &infos); + int32_t GetAllMmiSubscribedEvents(std::map, int32_t> &datas); + int32_t SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg); + int32_t GetWindowPid(int32_t windowId); + int32_t UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo); + int32_t UpdateDisplayInfo(const std::vector &displayGroupInfo); + int32_t UpdateWindowInfo(const WindowGroupInfo &windowGroupInfo); + #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT + void SetEnhanceConfig(uint8_t *cfg, uint32_t cfgLen); + #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT + int32_t SubscribeKeyEvent(std::shared_ptr keyOption, + std::function)> callback); + void UnsubscribeKeyEvent(int32_t subscriberId); + int32_t SubscribeHotkey(std::shared_ptr keyOption, + std::function)> callback); + void UnsubscribeHotkey(int32_t subscriberId); + int32_t SubscribeKeyMonitor(const KeyMonitorOption &keyOption, + std::function)> callback); + int32_t UnsubscribeKeyMonitor(int32_t subscriberId); + int32_t SubscribeSwitchEvent(int32_t switchType, std::function)> callback); + void UnsubscribeSwitchEvent(int32_t subscriberId); + int32_t QuerySwitchStatus(int32_t switchTpe, int32_t& state); + int32_t SubscribeTabletProximity(std::function)> callback); + void UnsubscribetabletProximity(int32_t subscriberId); + int32_t SubscribeLongPressEvent(const LongPressRequest &LongPressRequest, + std::function callback); + void UnsubscribeLongPressEvent(int32_t subscriberId); + int32_t AddInputEventFilter(std::shared_ptr filter, int32_t priority, uint32_t deviceTags); + int32_t RemoveInputEventFilter(int32_t filterId); + int32_t AddInputEventObserver(std::shared_ptr observer); + int32_t RemoveInputEventObserver(std::shared_ptr observer); + int32_t NotifyNapOnline(); + void NotifyBundleName(int32_t pid, int32_t uid, const std::string &bundleName, int32_t syncStatus); + int32_t SetWindowInputEventConsumer(std::shared_ptr inputEventConsumer, + std::shared_ptr eventHandler); + void ClearWindowPointerStyle(int32_t pid, int32_t windowId); + int32_t SetNapStatus(int32_t pid, int32_t uid, const std::string &bundleName, int32_t napStatus); + int32_t SetTouchpadThreeFingersTapSwitch(bool switchFlag); + int32_t GetTouchpadThreeFingersTapSwitch(bool &switchFlag); + void SetMultiWindowScreenId(uint64_t screenId, uint64_t displayNodeScreenId); + int32_t SetKnuckleSwitch(bool knuckleSwitch); + int32_t SetInputDeviceConsumer(const std::vector& deviceName, + std::shared_ptr consumer); + void OnDeviceConsumerEvent(std::shared_ptr pointerEvent); + + #ifdef OHOS_BUILD_ENABLE_KEYBOARD + void OnKeyEvent(std::shared_ptr keyEvent); + #endif // OHOS_BUILD_ENABLE_KEYBOARD + #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) + void OnPointerEvent(std::shared_ptr pointerEvent); + #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH + int32_t PackDisplayData(NetPacket &pkt, const DisplayGroupInfo &displayGroupInfo); + + int32_t AddMonitor(std::function)> monitor); + int32_t AddMonitor(std::function)> monitor); + int32_t AddMonitor(std::shared_ptr consumer, + HandleEventType eventType = HANDLE_EVENT_TYPE_KP); + int32_t AddGestureMonitor(std::shared_ptr consumer, + TouchGestureType type, int32_t fingers); + int32_t RemoveGestureMonitor(int32_t monitorId); + int32_t AddMonitor(std::shared_ptr monitor, std::vector actionsType); + + int32_t RemoveMonitor(int32_t monitorId); + void MarkConsumed(int32_t monitorId, int32_t eventId); + void MoveMouse(int32_t offsetX, int32_t offsetY); + + int32_t AddInterceptor(std::shared_ptr interceptor, + int32_t priority = DEFUALT_INTERCEPTOR_PRIORITY, + uint32_t deviceTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX)); + int32_t AddInterceptor(std::function)> interceptor, + int32_t priority = DEFUALT_INTERCEPTOR_PRIORITY, + uint32_t deviceTags = CapabilityToTags(InputDeviceCapability::INPUT_DEV_CAP_MAX)); + int32_t RemoveInterceptor(int32_t interceptorId); + + void SimulateInputEvent(std::shared_ptr keyEvent, bool isNativeInject = false); + int32_t SimulateInputEvent(std::shared_ptr pointerEvent, bool isNativeInject = false); + void HandleSimulateInputEvent(std::shared_ptr pointerEvent); + void SimulateTouchPadEvent(std::shared_ptr pointerEvent, bool isNativeInject = false); + void SimulateTouchPadInputEvent(std::shared_ptr pointerEvent, + const TouchpadCDG &touchpadCDG); + void OnConnected(); + #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) + template + bool RecoverPointerEvent(std::initializer_list pointerActionEvents, T pointerActionEvent); + #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH + void OnDisconnected(); + + int32_t RegisterDevListener(std::string type, std::shared_ptr listener); + int32_t UnregisterDevListener(std::string type, std::shared_ptr listener = nullptr); + int32_t GetDeviceIds(std::function&)> callback); + int32_t GetDevice(int32_t deviceId, std::function)> callback); + int32_t SupportKeys(int32_t deviceId, std::vector &keyCodes, + std::function&)> callback); + int32_t GetKeyboardType(int32_t deviceId, std::function callback); + int32_t SetKeyboardRepeatDelay(int32_t delay); + int32_t SetKeyboardRepeatRate(int32_t rate); + int32_t GetKeyboardRepeatDelay(std::function callback); + int32_t GetKeyboardRepeatRate(std::function callback); + + int32_t SetMouseScrollRows(int32_t rows); + int32_t GetMouseScrollRows(int32_t &rows); + int32_t SetPointerSize(int32_t size); + int32_t GetPointerSize(int32_t &size); + int32_t GetCursorSurfaceId(uint64_t &surfaceId); + int32_t SetCustomCursor(int32_t windowId, int32_t focusX, int32_t focusY, void* pixelMap); + int32_t SetCustomCursor(int32_t windowId, CustomCursor cursor, CursorOptions options); + int32_t SetMouseIcon(int32_t windowId, void* pixelMap); + int32_t SetMouseHotSpot(int32_t windowId, int32_t hotSpotX, int32_t hotSpotY); + int32_t SetMousePrimaryButton(int32_t primaryButton); + int32_t GetMousePrimaryButton(int32_t &primaryButton); + int32_t SetHoverScrollState(bool state); + int32_t GetHoverScrollState(bool &state); + + int32_t SetPointerVisible(bool visible, int32_t priority); + bool IsPointerVisible(); + int32_t SetPointerStyle(int32_t windowId, const PointerStyle& pointerStyle, bool isUiExtension = false); + int32_t GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle, bool isUiExtension = false); + + int32_t SetPointerColor(int32_t color); + int32_t GetPointerColor(int32_t &color); + int32_t EnableCombineKey(bool enable); + int32_t SetPointerSpeed(int32_t speed); + int32_t GetPointerSpeed(int32_t &speed); + + int32_t SetTouchpadScrollSwitch(bool switchFlag); + int32_t GetTouchpadScrollSwitch(bool &switchFlag); + int32_t SetTouchpadScrollDirection(bool state); + int32_t GetTouchpadScrollDirection(bool &state); + int32_t SetTouchpadTapSwitch(bool switchFlag); + int32_t GetTouchpadTapSwitch(bool &switchFlag); + int32_t SetTouchpadPointerSpeed(int32_t speed); + int32_t GetTouchpadPointerSpeed(int32_t &speed); + int32_t GetTouchpadCDG(TouchpadCDG &touchpadCDG); + int32_t SetTouchpadPinchSwitch(bool switchFlag); + int32_t GetTouchpadPinchSwitch(bool &switchFlag); + int32_t SetTouchpadSwipeSwitch(bool switchFlag); + int32_t GetTouchpadSwipeSwitch(bool &switchFlag); + int32_t SetTouchpadRightClickType(int32_t type); + int32_t GetTouchpadRightClickType(int32_t &type); + int32_t SetTouchpadRotateSwitch(bool rotateSwitch); + int32_t GetTouchpadRotateSwitch(bool &rotateSwitch); + int32_t SetTouchpadDoubleTapAndDragState(bool switchFlag); + int32_t GetTouchpadDoubleTapAndDragState(bool &switchFlag); + int32_t EnableHardwareCursorStats(bool enable); + int32_t GetHardwareCursorStats(uint32_t &frameCount, uint32_t &vsyncCount); + int32_t GetPointerSnapshot(void *pixelMapPtr); + int32_t SetTouchpadScrollRows(int32_t rows); + int32_t GetTouchpadScrollRows(int32_t &rows); + + void SetAnrObserver(std::shared_ptr observer); + void OnAnr(int32_t pid, int32_t eventId); + + int32_t EnterCaptureMode(int32_t windowId); + int32_t LeaveCaptureMode(int32_t windowId); + int32_t GetFunctionKeyState(int32_t funcKey, bool &resultState); + int32_t SetFunctionKeyState(int32_t funcKey, bool enable); + int32_t SetPointerLocation(int32_t x, int32_t y, int32_t displayId); + int32_t EnableInputDevice(bool enable); + // 快捷键拉起Ability + int32_t SetKeyDownDuration(const std::string &businessId, int32_t delay); + + int32_t AppendExtraData(const ExtraData& extraData); + int32_t SetShieldStatus(int32_t shieldMode, bool isShield); + int32_t GetShieldStatus(int32_t shieldMode, bool &isShield); + + void AddServiceWatcher(std::shared_ptr watcher); + void RemoveServiceWatcher(std::shared_ptr watcher); + + int32_t MarkProcessed(int32_t eventId, int64_t actionTime); + + int32_t GetKeyState(std::vector &pressedKeys, std::map &specialKeysState); + void Authorize(bool isAuthorize); + int32_t CancelInjection(); + + int32_t HasIrEmitter(bool &hasIrEmitter); + int32_t GetInfraredFrequencies(std::vector& requencys); + int32_t TransmitInfrared(int64_t number, std::vector& pattern); + #ifdef OHOS_BUILD_ENABLE_VKEYBOARD + int32_t CreateVKeyboardDevice(sptr &vkeyboardDevice); + #endif // OHOS_BUILD_ENABLE_VKEYBOARD + int32_t SetPixelMapData(int32_t infoId, void* pixelMap); + int32_t SetCurrentUser(int32_t userId); + int32_t SetMoveEventFilters(bool flag); + int32_t GetWinSyncBatchSize(int32_t maxAreasCount, int32_t displayCount); + int32_t AddVirtualInputDevice(std::shared_ptr device, int32_t &deviceId); + int32_t RemoveVirtualInputDevice(int32_t deviceId); + int32_t AncoAddChannel(std::shared_ptr consumer); + int32_t AncoRemoveChannel(std::shared_ptr consumer); + int32_t SkipPointerLayer(bool isSkip); + int32_t RegisterWindowStateErrorCallback(std::function callback); + void OnWindowStateError(int32_t pid, int32_t windowId); + int32_t GetAllSystemHotkeys(std::vector> &keyOptions, int32_t &count); + int32_t GetIntervalSinceLastInput(int64_t &timeInterval); + int32_t ConvertToCapiKeyAction(int32_t keyAction); + int32_t SetInputDeviceEnabled(int32_t deviceId, bool enable, std::function callback); + int32_t ShiftAppPointerEvent(const ShiftWindowParam ¶m, bool autoGenDown); + int32_t CheckKnuckleEvent(float pointX, float pointY, bool &touchType); + int32_t LaunchAiScreenAbility(); + int32_t GetMaxMultiTouchPointNum(int32_t &pointNum); + int32_t SubscribeInputActive(std::shared_ptr inputEventConsumer, int64_t interval); + void UnsubscribeInputActive(int32_t subscribeId); + + private: + int32_t PackWindowInfo(NetPacket &pkt, const DisplayGroupInfo &displayGroupInfo); + int32_t PackWindowGroupInfo(NetPacket &pkt); + int32_t PackDisplayInfo(NetPacket &pkt, DisplayGroupInfo &displayGroupInfo); + int32_t PackUiExtentionWindowInfo(const std::vector& windowsInfo, NetPacket &pkt); + void PrintWindowInfo(const std::vector &windowsInfo); + void PrintForemostThreeWindowInfo(const std::vector &windowsInfo); + void PrintDisplayInfo(const DisplayGroupInfo &displayGroupInfo); + void PrintWindowGroupInfo(); + int32_t SendDisplayInfo(const DisplayGroupInfo &displayGroupInfo); + int32_t SendWindowInfo(); + void SendWindowAreaInfo(WindowArea area, int32_t pid, int32_t windowId); + bool IsValiadWindowAreas(const std::vector &windows); + int32_t GetDisplayMaxSize(); + int32_t GetWindowMaxSize(int32_t maxAreasCount); + std::vector StringSplit(const std::string &str, char delim); + bool IsGRLOrHopper(); + #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT + int32_t PackEnhanceConfig(NetPacket &pkt); + void SendEnhanceConfig(); + void PrintEnhanceConfig(); + #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT + void ReAddInputEventFilter(); + + #ifdef OHOS_BUILD_ENABLE_KEYBOARD + void OnKeyEventTask(std::shared_ptr consumer, + std::shared_ptr keyEvent); + #endif // OHOS_BUILD_ENABLE_KEYBOARD + #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) + void OnPointerEventTask(std::shared_ptr consumer, + std::shared_ptr pointerEvent); + #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH + #ifdef OHOS_BUILD_ENABLE_ANCO + bool IsValidAncoWindow(const std::vector &windows); + #endif // OHOS_BUILD_ENABLE_ANCO + + private: + std::map, int32_t, uint32_t>> eventFilterServices_; + std::shared_ptr eventObserver_ { nullptr }; + std::shared_ptr consumer_ { nullptr }; + std::vector> anrObservers_; + std::shared_ptr winChecker_ { nullptr }; + DisplayGroupInfo displayGroupInfo_ {}; + WindowGroupInfo windowGroupInfo_ {}; + std::mutex mtx_; + std::mutex eventObserverMtx_; + std::mutex winStatecallbackMtx_; + mutable std::mutex resourceMtx_; + std::condition_variable cv_; + std::thread ehThread_; + std::shared_ptr eventHandler_ { nullptr }; + std::shared_ptr lastPointerEvent_ { nullptr }; + std::function windowStatecallback_; + std::vector displayGroupInfoArray_; + bool knuckleSwitch_ { true }; + std::vector displayGroupInfoArray_; + #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT + uint8_t* enhanceCfg_ = nullptr; + uint32_t enhanceCfgLen_ = 0; + #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT + #ifdef OHOS_BUILD_ENABLE_ANCO + std::map, sptr> ancoChannels_; + #endif // OHOS_BUILD_ENABLE_ANCO + }; + #define InputMgrImpl ::OHOS::Singleton::GetInstance() + } // namespace MMI + } // namespace OHOS + #endif // INPUT_MANAGER_IMPL_H + \ No newline at end of file diff --git a/frameworks/proxy/event_handler/src/input_manager_impl.cpp b/frameworks/proxy/event_handler/src/input_manager_impl.cpp index d420f20b78a7e4a02145069b8445894e1f8419d5..aaf8649b9122a719a1242e3af2f60240d27df09f 100644 --- a/frameworks/proxy/event_handler/src/input_manager_impl.cpp +++ b/frameworks/proxy/event_handler/src/input_manager_impl.cpp @@ -141,40 +141,49 @@ int32_t InputManagerImpl::UpdateDisplayInfo(const DisplayGroupInfo &displayGroup MMI_HILOGE("Failed to initialize MMI client"); return RET_ERR; } - std::lock_guard guard(mtx_); - displayGroupInfoArray_.clear(); - if (displayGroupInfo.windowsInfo.size() < MAX_WINDOW_SIZE) { - windowGroupInfo_.windowsInfo.clear(); + { + std::lock_guard guard(mtx_); + if (displayGroupInfo.windowsInfo.size() < MAX_WINDOW_SIZE) { + windowGroupInfo_.windowsInfo.clear(); + } + displayGroupInfoArray_.clear(); + displayGroupInfoArray_.emplace_back(displayGroupInfo); } - displayGroupInfo_ = displayGroupInfo; - int32_t ret = SendDisplayInfo(displayGroupInfo_); - displayGroupInfoArray_.emplace_back(displayGroupInfo_); + int32_t ret = SendDisplayInfo(displayGroupInfo); if (ret != RET_OK) { MMI_HILOGE("Failed to send display information to service"); return ret; } - PrintDisplayInfo(displayGroupInfo_); + PrintDisplayInfo(displayGroupInfo); return RET_OK; } -int32_t InputManagerImpl::UpdateDisplayInfo(const std::vector &displayGroupInfo) +int32_t InputManagerImpl::UpdateDisplayInfo(const std::vector &displayGroupInfos) { CALL_DEBUG_ENTER; if (!MMIEventHdl.InitClient()) { MMI_HILOGE("Failed to initialize MMI client"); return RET_ERR; } - std::lock_guard guard(mtx_); - displayGroupInfoArray_.clear(); - for (auto &item : displayGroupInfo) { - displayGroupInfo_ = item; - int32_t ret = SendDisplayInfo(displayGroupInfo_); - displayGroupInfoArray_.emplace_back(displayGroupInfo_); + { + std::lock_guard guard(mtx_); + displayGroupInfoArray_.clear(); + int32_t cnt = 0; + for (auto &it : displayGroupInfos) { + displayGroupInfoArray_.emplace_back(it); + cnt += it.windowsInfo.size(); + } + if (cnt < MAX_WINDOW_SIZE) { + windowGroupInfo_.windowsInfo.clear(); + } + } + for (const auto &item : displayGroupInfos) { + int32_t ret = SendDisplayInfo(item); if (ret != RET_OK) { MMI_HILOGE("Failed to send display information to service"); return ret; } - PrintDisplayInfo(displayGroupInfo_); + PrintDisplayInfo(item); } return RET_OK; } @@ -658,7 +667,7 @@ void InputManagerImpl::OnPointerEvent(std::shared_ptr pointerEvent } #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH -int32_t InputManagerImpl::PackDisplayData(NetPacket &pkt, DisplayGroupInfo &displayGroupInfo) +int32_t InputManagerImpl::PackDisplayData(NetPacket &pkt, const DisplayGroupInfo &displayGroupInfo) { CALL_DEBUG_ENTER; pkt << displayGroupInfo.groupId << displayGroupInfo.isMainGroup << displayGroupInfo.width << displayGroupInfo.height @@ -671,7 +680,7 @@ int32_t InputManagerImpl::PackDisplayData(NetPacket &pkt, DisplayGroupInfo &disp MMI_HILOGE("Packet write windows info failed"); return RET_ERR; } - return PackDisplayInfo(pkt, displayGroupInfo); + return PackDisplayInfo(pkt, const_cast(displayGroupInfo)); } int32_t InputManagerImpl::PackWindowGroupInfo(NetPacket &pkt) @@ -744,7 +753,7 @@ int32_t InputManagerImpl::PackUiExtentionWindowInfo(const std::vector(displayGroupInfo.windowsInfo.size()); @@ -859,8 +868,10 @@ int32_t InputManagerImpl::PackDisplayInfo(NetPacket &pkt, DisplayGroupInfo &disp << item.offsetY << item.isCurrentOffScreenRendering << item.screenRealWidth << item.screenRealHeight << item.screenRealPPI << item.screenRealDPI << item.screenCombination << item.validWidth << item.validHeight << item.fixedDirection - << item.physicalWidth << item.physicalHeight << item.scalePercent << item.expandHeight - << item.oneHandX << item.oneHandY << item.uniqueId; + << item.physicalWidth << item.physicalHeight << item.scalePercent << item.expandHeight << item.uniqueId; +#ifdef OHOS_BUILD_ENABLE_ONE_HAND_MODE + pkt << item.oneHandX << item.oneHandY; +#endif #ifdef OHOS_BUILD_ENABLE_VKEYBOARD pkt << item.pointerActiveWidth << item.pointerActiveHeight; #endif // OHOS_BUILD_ENABLE_VKEYBOARD @@ -1728,7 +1739,7 @@ void InputManagerImpl::OnDisconnected() #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH } -int32_t InputManagerImpl::SendDisplayInfo(DisplayGroupInfo &displayGroupInfo) +int32_t InputManagerImpl::SendDisplayInfo(const DisplayGroupInfo &displayGroupInfo) { CALL_DEBUG_ENTER; MMIClientPtr client = MMIEventHdl.GetMMIClient(); diff --git a/frameworks/proxy/event_handler/test/input_manager_impl_test.cpp b/frameworks/proxy/event_handler/test/input_manager_impl_test.cpp index 6b1236d99d0585c67ecd019d4e38eff526c8442b..7947c18df0c5c0aba35e23d6acff1cb6cd027515 100644 --- a/frameworks/proxy/event_handler/test/input_manager_impl_test.cpp +++ b/frameworks/proxy/event_handler/test/input_manager_impl_test.cpp @@ -394,8 +394,8 @@ HWTEST_F(InputManagerImplTest, InputManagerImplTest_EnableCombineKey_02, TestSiz HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_01, TestSize.Level3) { CALL_TEST_DEBUG; - EXPECT_TRUE(InputMgrImpl.displayGroupInfo_.windowsInfo.empty()); - EXPECT_TRUE(InputMgrImpl.displayGroupInfo_.displaysInfo.empty()); + EXPECT_TRUE(InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].windowsInfo.empty()); + EXPECT_TRUE(InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].displaysInfo.empty()); ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected()); } @@ -408,19 +408,19 @@ HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_01, TestSize.Lev HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_02, TestSize.Level2) { CALL_TEST_DEBUG; - InputMgrImpl.displayGroupInfo_.width = 50; - InputMgrImpl.displayGroupInfo_.height = 60; + InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].width = 50; + InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].height = 60; WindowInfo windowInfo; windowInfo.id = 1; windowInfo.pid = 2; - InputMgrImpl.displayGroupInfo_.windowsInfo.push_back(windowInfo); - EXPECT_FALSE(InputMgrImpl.displayGroupInfo_.windowsInfo.empty()); + InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].windowsInfo.push_back(windowInfo); + EXPECT_FALSE(InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].windowsInfo.empty()); DisplayInfo displayInfo; displayInfo.width = 10; displayInfo.height = 20; - InputMgrImpl.displayGroupInfo_.displaysInfo.push_back(displayInfo); - EXPECT_FALSE(InputMgrImpl.displayGroupInfo_.displaysInfo.empty()); + InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].displaysInfo.push_back(displayInfo); + EXPECT_FALSE(InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].displaysInfo.empty()); EXPECT_TRUE(InputMgrImpl.anrObservers_.empty()); ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected()); @@ -438,8 +438,8 @@ HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_03, TestSize.Lev DisplayInfo displayInfo; displayInfo.width = 10; displayInfo.height = 20; - InputMgrImpl.displayGroupInfo_.displaysInfo.push_back(displayInfo); - EXPECT_FALSE(InputMgrImpl.displayGroupInfo_.displaysInfo.empty()); + InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].displaysInfo.push_back(displayInfo); + EXPECT_FALSE(InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].displaysInfo.empty()); ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected()); } @@ -452,13 +452,13 @@ HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_03, TestSize.Lev HWTEST_F(InputManagerImplTest, InputManagerImplTest_OnConnected_04, TestSize.Level2) { CALL_TEST_DEBUG; - InputMgrImpl.displayGroupInfo_.width = 50; - InputMgrImpl.displayGroupInfo_.height = 60; + InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].width = 50; + InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].height = 60; WindowInfo windowInfo; windowInfo.id = 1; windowInfo.pid = 2; - InputMgrImpl.displayGroupInfo_.windowsInfo.push_back(windowInfo); - EXPECT_FALSE(InputMgrImpl.displayGroupInfo_.windowsInfo.empty()); + InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].windowsInfo.push_back(windowInfo); + EXPECT_FALSE(InputMgrImpl.displayGroupInfoArray_[DEFAULT_GROUP_ID].windowsInfo.empty()); ASSERT_NO_FATAL_FAILURE(InputMgrImpl.OnConnected()); } diff --git a/interfaces/native/innerkits/proxy/include/window_info.h b/interfaces/native/innerkits/proxy/include/window_info.h index dd4c0089729d01ffadf72a084f6f0afcba048c16..1c56ccd91afd3673ea7fad7465bdd2ce033777d8 100644 --- a/interfaces/native/innerkits/proxy/include/window_info.h +++ b/interfaces/native/innerkits/proxy/include/window_info.h @@ -13,648 +13,649 @@ * limitations under the License. */ -#ifndef DISPLAY_INFO_H -#define DISPLAY_INFO_H - -#include - -namespace OHOS { -namespace MMI { -inline constexpr int32_t GLOBAL_WINDOW_ID = -1; - -inline constexpr int32_t DEFAULT_DISPLAY_ID = -1; -inline constexpr int32_t DEFAULT_GROUP_ID = -1; - -enum SecureFlag { - DEFAULT_MODE = 0, - PRIVACY_MODE = 1, -}; - -/** - * @brief Enumerates the fold display mode. - */ -enum class DisplayMode: uint32_t { - /** - * The default display mode - * - * @since 9 - */ - UNKNOWN = 0, - - /** - * The full display mode - * - * @since 9 - */ - FULL = 1, - - /** - * The main display mode - * - * @since 9 - */ - MAIN = 2, - - /** - * The sub display mode - * - * @since 9 - */ - SUB = 3, - - /** - * The coordination display mode - * - * @since 9 - */ - COORDINATION = 4, -}; - -enum class WINDOW_UPDATE_ACTION: uint32_t { - /** - * The default window update action - * - * @since 9 - */ - UNKNOWN = 0, - - /** - * Add the window action - * - * @since 9 - */ - ADD = 1, - - /** - * Delete the window action - * - * @since 9 - */ - DEL = 2, - + #ifndef DISPLAY_INFO_H + #define DISPLAY_INFO_H + + #include + + namespace OHOS { + namespace MMI { + inline constexpr int32_t GLOBAL_WINDOW_ID = -1; + + inline constexpr int32_t DEFAULT_DISPLAY_ID = -1; + inline constexpr int32_t DEFAULT_GROUP_ID = 0; + + enum SecureFlag { + DEFAULT_MODE = 0, + PRIVACY_MODE = 1, + }; + + /** + * @brief Enumerates the fold display mode. + */ + enum class DisplayMode: uint32_t { /** - * Change the window action - * - * @since 9 - */ - CHANGE = 3, - - /** - * Add the window action end - * - * @since 9 - */ - ADD_END = 4, -}; - -enum Direction { - /** - * Rotating the display clockwise by 0 degree - * - * @since 9 - */ - DIRECTION0, - - /** - * Rotating the display clockwise by 90 degrees - * - * @since 9 - */ - DIRECTION90, - - /** - * Rotating the display clockwise by 180 degrees - * - * @since 9 - */ - DIRECTION180, - - /** - * Rotating the display clockwise by 270 degrees - * - * @since 9 - */ - DIRECTION270 -}; - -struct Rect { - /** - * X coordinate of the upper left corner - * - * @since 9 - */ - int32_t x; - - /** - * Y coordinate of the upper left corner - * - * @since 9 - */ - int32_t y; - - /** - * Width - * - * @since 9 - */ - int32_t width; - - /** - * Height - * - * @since 9 - */ - int32_t height; -}; - -enum class WindowInputType : uint8_t { - NORMAL = 0, - TRANSMIT_ALL = 1, - TRANSMIT_EXCEPT_MOVE = 2, - ANTI_MISTAKE_TOUCH = 3, - TRANSMIT_AXIS_MOVE = 4, - TRANSMIT_MOUSE_MOVE = 5, - TRANSMIT_LEFT_RIGHT = 6, - TRANSMIT_BUTTOM = 7, - MIX_LEFT_RIGHT_ANTI_AXIS_MOVE = 18, - MIX_BUTTOM_ANTI_AXIS_MOVE = 19, - SLID_TOUCH_WINDOW = 40, - TRANSMIT_ANTI_AXIS_MOVE = 50 -}; - -struct WindowInfo { - /** - * Maximum number of hot areas - * - * @since 9 - */ - static constexpr int32_t MAX_HOTAREA_COUNT = 50; - - static constexpr int32_t DEFAULT_HOTAREA_COUNT = 10; - - /** - * The number of pointer change areas - * - * @since 9 - */ - static constexpr int32_t POINTER_CHANGEAREA_COUNT = 8; - - /** - * The size of window transform, which create a 3*3 matrix - * - * @since 9 - */ - static constexpr int32_t WINDOW_TRANSFORM_SIZE = 9; - - /** - * Untouchable window - * - * @since 9 - */ - static constexpr uint32_t FLAG_BIT_UNTOUCHABLE = 1; - - /** - * Only handwriting window - * - * @since 12 - */ - static constexpr uint32_t FLAG_BIT_HANDWRITING = 2; - - /** - * Globally unique identifier of the window - * - * @since 9 - */ - int32_t id; - - /** - * ID of the process where the window is located - * - * @since 9 - */ - int32_t pid; - - /** - * UID of the process where the window is located - * - * @since 9 - */ - int32_t uid; - - /** - * Window display area - * - * @since 9 - */ - Rect area; - - /** - * Number of touch response areas (excluding the mouse response areas) in the window. - * The value cannot exceed the value of MAX_HOTAREA_COUNT. - * - * @since 9 - */ - std::vector defaultHotAreas; - - /** - * Number of mouse response areas in the window. The value cannot exceed the value of MAX_HOTAREA_COUNT. - * - * @since 9 - */ - std::vector pointerHotAreas; - - /** - * Agent window ID - * - * @since 9 - */ - int32_t agentWindowId; - - /** - * A 32-bit flag that represents the window status. If the 0th bit is 1, - * the window is untouchable; if the 0th bit is 0, the window is touchable. - * - * @since 9 - */ - uint32_t flags; - - /** - * Agent window ID - * - * @since 9 - */ - WINDOW_UPDATE_ACTION action { WINDOW_UPDATE_ACTION::UNKNOWN }; - - /** - * Window display ID - * - * @since 9 - */ - int32_t displayId { DEFAULT_DISPLAY_ID }; - - /** - * display group ID - * - * @since 16 - */ - int32_t groupId { DEFAULT_GROUP_ID }; - - /** - * Window order in Z-index - * - * @since 9 - */ - float zOrder { 0.0f }; - - /** - * Number of mouse style change areas in the window. The value must be POINTER_CHANGEAREA_COUNT. - * - * @since 9 - */ - std::vector pointerChangeAreas; - - /** - * Number of transform in the window which is used to calculate the window x and window y by logic x and window y. - * The value must be POINTER_CHANGEAREA_COUNT. - * - * @since 9 - */ - std::vector transform; - - /** - * pixelMap Indicates the special-shaped window. Its actual type must be OHOS::Media::PixelMap*, - * which is used to determine whether an event is dispatched to the current window. - * - * @since 12 - */ - void* pixelMap { nullptr }; - - WindowInputType windowInputType { WindowInputType::NORMAL }; - - SecureFlag privacyMode { SecureFlag::DEFAULT_MODE }; - - int32_t windowType; - - bool privacyUIFlag { false }; - - std::vector uiExtentionWindowInfo; - - bool rectChangeBySystem { false }; - - bool isDisplayCoord { false }; - - bool isSkipSelfWhenShowOnVirtualScreen { false }; - - int32_t windowNameType; -}; - -/** - * Physical screen information - * - * @since 9 - */ -enum class ScreenCombination : uint32_t { - SCREEN_ALONE, - SCREEN_EXPAND, - SCREEN_MIRROR, - SCREEN_UNIQUE, - SCREEN_EXTEND, - SCREEN_MAIN -}; - -struct DisplayInfo { - /** - * Unique ID of the physical display - * - * @since 9 - */ - int32_t id; - - /** - * X coordinate of the upper left corner on the logical screen - * - * @since 9 - */ - int32_t x; - - /** - * Y coordinate of the upper left corner on the logical screen - * - * @since 9 - */ - int32_t y; - - /** - * Display width, which is the logical width of the original screen when the rotation angle is 0. - * The value remains unchanged even if the display screen is rotated. - * - * @since 9 - */ - int32_t width; - - /** - * Display height, which is the logical height of the original screen when the rotation angle is 0. - * The value remains unchanged even if the display screen is rotated. - * - * @since 9 - */ - int32_t height; - - /** - * Pixel density, which indicates the number of pixels in an inch - * - * @since 10 - */ - int32_t dpi; - - /** - * Name of the physical display, which is used for debugging - * - * @since 9 - */ - std::string name; - - /** - * Unique screen ID, which is used to associate the corresponding touchscreen. The default value is default0. - * - * @since 9 - */ - std::string uniq; - - /** - * Orientation of the physical display - * - * @since 9 - */ - Direction direction; - - Direction displayDirection; - - /** - * DisplayMode of the display - * - * @since 9 - */ - DisplayMode displayMode { DisplayMode::UNKNOWN }; - - /** - * Number of transform in the screen which is used to calculate the display x and display y by logic x and logic y. - * The value must be POINTER_CHANGEAREA_COUNT. - * - * @since 12 - */ - std::vector transform; - - /** - * Orientation of the physical display - * - * @since 12 - */ - int32_t offsetX = 0; - int32_t offsetY = 0; - float ppi; - /** - * Coordinate of the upper left corner of the virtual screen in one-hand mode. - * If oneHandX is 0, the virtual screen is in the lower left corner. - * If oneHandX is greater than 0, the virtual screen is in the lower right corner. - */ - int32_t oneHandX = 0; - int32_t oneHandY = 0; - /** - * Scale percent of oneHand rect to display rect. - * If 'scalePercent < 100', it means one hand mode. - * If 'scalePercent == 100', it means not in one hand mode. - */ - int32_t scalePercent = 100; - /** - * Expand height from bottom. - */ - int32_t expandHeight = 0; - /** - * Use for off screen policy - * - * @since 12 - */ - bool isCurrentOffScreenRendering = false; - int32_t screenRealWidth = 0; - int32_t screenRealHeight = 0; - float screenRealPPI = 0.0f; - int32_t screenRealDPI = 0; - ScreenCombination screenCombination = ScreenCombination::SCREEN_MAIN; - - /** - * Width of the effective area of the screen. When the screen is rotated, the value changes accordingly. - * - * @since 12 - */ - int32_t validWidth = 0; - - /** - * Height of the effective area of the screen. When the screen is rotated, the value changes accordingly. - * - * @since 12 - */ - int32_t validHeight = 0; - - /** - * Rotation angle of the TP patch offset correction. - * - * @since 12 - */ - Direction fixedDirection; - - /** - * The physical width of the screen, in millimeters. - * - * @since 12 - */ - int32_t physicalWidth { 0 }; - - /** - * The physical height of the screen, in millimeters. - * - * @since 12 - */ - int32_t physicalHeight { 0 }; - - /** - * The Pointer Active Width - * - * @since 12 - */ - int32_t pointerActiveWidth { 0 }; - - /** - * The Pointer Active Height - * - * @since 12 - */ - int32_t pointerActiveHeight { 0 }; - - /** Unique ID of the physical display - * - * @since 12 - */ - int32_t uniqueId { 0 }; - - /** - * Display group ID - * - * @since 16 - */ - int32_t groupId { DEFAULT_GROUP_ID }; -}; - -/** - * Logical screen information - * - * @since 9 - */ -struct DisplayGroupInfo { - /** - * index of group. default=-1 - * - * @since 16 - */ - int32_t groupId { DEFAULT_GROUP_ID }; - - /** - * main group flag. default=true - * - * @since 16 - */ - bool isMainGroup { true }; - - /** - * Width of the logical display - * - * @since 9 - */ - int32_t width; - - /** - * Height of the logical display - * - * @since 9 - */ - int32_t height; - - /** - * ID of the focus window - * - * @since 9 - */ - int32_t focusWindowId; - - int32_t currentUserId { -1 }; - - /** - * List of window information of the logical display arranged in Z order, with the top window at the top - * - * @since 9 - */ - std::vector windowsInfo; - - /** - * Physical screen information list - * - * @since 9 - */ - std::vector displaysInfo; -}; - -struct WindowGroupInfo { - /** - * ID of the focus window - * - * @since 9 - */ - int32_t focusWindowId { GLOBAL_WINDOW_ID }; - - /** - * Window display ID - * - * @since 9 - */ - int32_t displayId { DEFAULT_DISPLAY_ID }; - - /** - * List of window information of the logical display arranged in Z order, with the top window at the top - * - * @since 9 - */ - std::vector windowsInfo; -}; - -struct DisplayBindInfo { - int32_t inputDeviceId { -1 }; - std::string inputDeviceName; - int32_t displayId { -1 }; - std::string displayName; -}; -enum class WindowArea: int32_t { - ENTER = 0, - EXIT, - FOCUS_ON_INNER, - FOCUS_ON_TOP, - FOCUS_ON_BOTTOM, - FOCUS_ON_LEFT, - FOCUS_ON_RIGHT, - FOCUS_ON_TOP_LEFT, - FOCUS_ON_TOP_RIGHT, - FOCUS_ON_BOTTOM_LEFT, - FOCUS_ON_BOTTOM_RIGHT, - TOP_LEFT_LIMIT, - TOP_RIGHT_LIMIT, - TOP_LIMIT, - LEFT_LIMIT, - RIGHT_LIMIT, - BOTTOM_LEFT_LIMIT, - BOTTOM_LIMIT, - BOTTOM_RIGHT_LIMIT -}; - -using DisplayBindInfos = std::vector; -} // namespace MMI -} // namespace OHOS -#endif // DISPLAY_INFO_H + * The default display mode + * + * @since 9 + */ + UNKNOWN = 0, + + /** + * The full display mode + * + * @since 9 + */ + FULL = 1, + + /** + * The main display mode + * + * @since 9 + */ + MAIN = 2, + + /** + * The sub display mode + * + * @since 9 + */ + SUB = 3, + + /** + * The coordination display mode + * + * @since 9 + */ + COORDINATION = 4, + }; + + enum class WINDOW_UPDATE_ACTION: uint32_t { + /** + * The default window update action + * + * @since 9 + */ + UNKNOWN = 0, + + /** + * Add the window action + * + * @since 9 + */ + ADD = 1, + + /** + * Delete the window action + * + * @since 9 + */ + DEL = 2, + + /** + * Change the window action + * + * @since 9 + */ + CHANGE = 3, + + /** + * Add the window action end + * + * @since 9 + */ + ADD_END = 4, + }; + + enum Direction { + /** + * Rotating the display clockwise by 0 degree + * + * @since 9 + */ + DIRECTION0, + + /** + * Rotating the display clockwise by 90 degrees + * + * @since 9 + */ + DIRECTION90, + + /** + * Rotating the display clockwise by 180 degrees + * + * @since 9 + */ + DIRECTION180, + + /** + * Rotating the display clockwise by 270 degrees + * + * @since 9 + */ + DIRECTION270 + }; + + struct Rect { + /** + * X coordinate of the upper left corner + * + * @since 9 + */ + int32_t x; + + /** + * Y coordinate of the upper left corner + * + * @since 9 + */ + int32_t y; + + /** + * Width + * + * @since 9 + */ + int32_t width; + + /** + * Height + * + * @since 9 + */ + int32_t height; + }; + + enum class WindowInputType : uint8_t { + NORMAL = 0, + TRANSMIT_ALL = 1, + TRANSMIT_EXCEPT_MOVE = 2, + ANTI_MISTAKE_TOUCH = 3, + TRANSMIT_AXIS_MOVE = 4, + TRANSMIT_MOUSE_MOVE = 5, + TRANSMIT_LEFT_RIGHT = 6, + TRANSMIT_BUTTOM = 7, + MIX_LEFT_RIGHT_ANTI_AXIS_MOVE = 18, + MIX_BUTTOM_ANTI_AXIS_MOVE = 19, + SLID_TOUCH_WINDOW = 40, + TRANSMIT_ANTI_AXIS_MOVE = 50 + }; + + struct WindowInfo { + /** + * Maximum number of hot areas + * + * @since 9 + */ + static constexpr int32_t MAX_HOTAREA_COUNT = 50; + + static constexpr int32_t DEFAULT_HOTAREA_COUNT = 10; + + /** + * The number of pointer change areas + * + * @since 9 + */ + static constexpr int32_t POINTER_CHANGEAREA_COUNT = 8; + + /** + * The size of window transform, which create a 3*3 matrix + * + * @since 9 + */ + static constexpr int32_t WINDOW_TRANSFORM_SIZE = 9; + + /** + * Untouchable window + * + * @since 9 + */ + static constexpr uint32_t FLAG_BIT_UNTOUCHABLE = 1; + + /** + * Only handwriting window + * + * @since 12 + */ + static constexpr uint32_t FLAG_BIT_HANDWRITING = 2; + + /** + * Globally unique identifier of the window + * + * @since 9 + */ + int32_t id; + + /** + * ID of the process where the window is located + * + * @since 9 + */ + int32_t pid; + + /** + * UID of the process where the window is located + * + * @since 9 + */ + int32_t uid; + + /** + * Window display area + * + * @since 9 + */ + Rect area; + + /** + * Number of touch response areas (excluding the mouse response areas) in the window. + * The value cannot exceed the value of MAX_HOTAREA_COUNT. + * + * @since 9 + */ + std::vector defaultHotAreas; + + /** + * Number of mouse response areas in the window. The value cannot exceed the value of MAX_HOTAREA_COUNT. + * + * @since 9 + */ + std::vector pointerHotAreas; + + /** + * Agent window ID + * + * @since 9 + */ + int32_t agentWindowId; + + /** + * A 32-bit flag that represents the window status. If the 0th bit is 1, + * the window is untouchable; if the 0th bit is 0, the window is touchable. + * + * @since 9 + */ + uint32_t flags; + + /** + * Agent window ID + * + * @since 9 + */ + WINDOW_UPDATE_ACTION action { WINDOW_UPDATE_ACTION::UNKNOWN }; + + /** + * Window display ID + * + * @since 9 + */ + int32_t displayId { DEFAULT_DISPLAY_ID }; + + /** + * display group ID + * + * @since 19 + */ + int32_t groupId { DEFAULT_GROUP_ID }; + + /** + * Window order in Z-index + * + * @since 9 + */ + float zOrder { 0.0f }; + + /** + * Number of mouse style change areas in the window. The value must be POINTER_CHANGEAREA_COUNT. + * + * @since 9 + */ + std::vector pointerChangeAreas; + + /** + * Number of transform in the window which is used to calculate the window x and window y by logic x and window y. + * The value must be POINTER_CHANGEAREA_COUNT. + * + * @since 9 + */ + std::vector transform; + + /** + * pixelMap Indicates the special-shaped window. Its actual type must be OHOS::Media::PixelMap*, + * which is used to determine whether an event is dispatched to the current window. + * + * @since 12 + */ + void* pixelMap { nullptr }; + + WindowInputType windowInputType { WindowInputType::NORMAL }; + + SecureFlag privacyMode { SecureFlag::DEFAULT_MODE }; + + int32_t windowType; + + bool privacyUIFlag { false }; + + std::vector uiExtentionWindowInfo; + + bool rectChangeBySystem { false }; + + bool isDisplayCoord { false }; + + bool isSkipSelfWhenShowOnVirtualScreen { false }; + + int32_t windowNameType; + }; + + /** + * Physical screen information + * + * @since 9 + */ + enum class ScreenCombination : uint32_t { + SCREEN_ALONE, + SCREEN_EXPAND, + SCREEN_MIRROR, + SCREEN_UNIQUE, + SCREEN_EXTEND, + SCREEN_MAIN + }; + + struct DisplayInfo { + /** + * Unique ID of the physical display + * + * @since 9 + */ + int32_t id; + + /** + * X coordinate of the upper left corner on the logical screen + * + * @since 9 + */ + int32_t x; + + /** + * Y coordinate of the upper left corner on the logical screen + * + * @since 9 + */ + int32_t y; + + /** + * Display width, which is the logical width of the original screen when the rotation angle is 0. + * The value remains unchanged even if the display screen is rotated. + * + * @since 9 + */ + int32_t width; + + /** + * Display height, which is the logical height of the original screen when the rotation angle is 0. + * The value remains unchanged even if the display screen is rotated. + * + * @since 9 + */ + int32_t height; + + /** + * Pixel density, which indicates the number of pixels in an inch + * + * @since 10 + */ + int32_t dpi; + + /** + * Name of the physical display, which is used for debugging + * + * @since 9 + */ + std::string name; + + /** + * Unique screen ID, which is used to associate the corresponding touchscreen. The default value is default0. + * + * @since 9 + */ + std::string uniq; + + /** + * Orientation of the physical display + * + * @since 9 + */ + Direction direction; + + Direction displayDirection; + + /** + * DisplayMode of the display + * + * @since 9 + */ + DisplayMode displayMode { DisplayMode::UNKNOWN }; + + /** + * Number of transform in the screen which is used to calculate the display x and display y by logic x and logic y. + * The value must be POINTER_CHANGEAREA_COUNT. + * + * @since 12 + */ + std::vector transform; + + /** + * Orientation of the physical display + * + * @since 12 + */ + int32_t offsetX = 0; + int32_t offsetY = 0; + float ppi; + /** + * Coordinate of the upper left corner of the virtual screen in one-hand mode. + * If oneHandX is 0, the virtual screen is in the lower left corner. + * If oneHandX is greater than 0, the virtual screen is in the lower right corner. + */ + int32_t oneHandX = 0; + int32_t oneHandY = 0; + /** + * Scale percent of oneHand rect to display rect. + * If 'scalePercent < 100', it means one hand mode. + * If 'scalePercent == 100', it means not in one hand mode. + */ + int32_t scalePercent = 100; + /** + * Expand height from bottom. + */ + int32_t expandHeight = 0; + /** + * Use for off screen policy + * + * @since 12 + */ + bool isCurrentOffScreenRendering = false; + int32_t screenRealWidth = 0; + int32_t screenRealHeight = 0; + float screenRealPPI = 0.0f; + int32_t screenRealDPI = 0; + ScreenCombination screenCombination = ScreenCombination::SCREEN_MAIN; + + /** + * Width of the effective area of the screen. When the screen is rotated, the value changes accordingly. + * + * @since 12 + */ + int32_t validWidth = 0; + + /** + * Height of the effective area of the screen. When the screen is rotated, the value changes accordingly. + * + * @since 12 + */ + int32_t validHeight = 0; + + /** + * Rotation angle of the TP patch offset correction. + * + * @since 12 + */ + Direction fixedDirection; + + /** + * The physical width of the screen, in millimeters. + * + * @since 12 + */ + int32_t physicalWidth { 0 }; + + /** + * The physical height of the screen, in millimeters. + * + * @since 12 + */ + int32_t physicalHeight { 0 }; + + /** + * The Pointer Active Width + * + * @since 18 + */ + int32_t pointerActiveWidth { 0 }; + + /** + * The Pointer Active Height + * + * @since 18 + */ + int32_t pointerActiveHeight { 0 }; + + /** Unique ID of the physical display + * + * @since 18 + */ + int32_t uniqueId { 0 }; + + /** + * Display group ID + * + * @since 19 + */ + int32_t groupId { DEFAULT_GROUP_ID }; + }; + + /** + * Logical screen information + * + * @since 9 + */ + struct DisplayGroupInfo { + /** + * index of group. default=-1 + * + * @since 19 + */ + int32_t groupId { DEFAULT_GROUP_ID }; + + /** + * main group flag. default=true + * + * @since 19 + */ + bool isMainGroup { false }; + + /** + * Width of the logical display + * + * @since 9 + */ + int32_t width; + + /** + * Height of the logical display + * + * @since 9 + */ + int32_t height; + + /** + * ID of the focus window + * + * @since 9 + */ + int32_t focusWindowId; + + int32_t currentUserId { -1 }; + + /** + * List of window information of the logical display arranged in Z order, with the top window at the top + * + * @since 9 + */ + std::vector windowsInfo; + + /** + * Physical screen information list + * + * @since 9 + */ + std::vector displaysInfo; + }; + + struct WindowGroupInfo { + /** + * ID of the focus window + * + * @since 9 + */ + int32_t focusWindowId { GLOBAL_WINDOW_ID }; + + /** + * Window display ID + * + * @since 9 + */ + int32_t displayId { DEFAULT_DISPLAY_ID }; + + /** + * List of window information of the logical display arranged in Z order, with the top window at the top + * + * @since 9 + */ + std::vector windowsInfo; + }; + + struct DisplayBindInfo { + int32_t inputDeviceId { -1 }; + std::string inputDeviceName; + int32_t displayId { -1 }; + std::string displayName; + }; + enum class WindowArea: int32_t { + ENTER = 0, + EXIT, + FOCUS_ON_INNER, + FOCUS_ON_TOP, + FOCUS_ON_BOTTOM, + FOCUS_ON_LEFT, + FOCUS_ON_RIGHT, + FOCUS_ON_TOP_LEFT, + FOCUS_ON_TOP_RIGHT, + FOCUS_ON_BOTTOM_LEFT, + FOCUS_ON_BOTTOM_RIGHT, + TOP_LEFT_LIMIT, + TOP_RIGHT_LIMIT, + TOP_LIMIT, + LEFT_LIMIT, + RIGHT_LIMIT, + BOTTOM_LEFT_LIMIT, + BOTTOM_LIMIT, + BOTTOM_RIGHT_LIMIT + }; + + using DisplayBindInfos = std::vector; + } // namespace MMI + } // namespace OHOS + #endif // DISPLAY_INFO_H + \ No newline at end of file diff --git a/service/key_command/test/key_command_handler_test.cpp b/service/key_command/test/key_command_handler_test.cpp index bdc343b8df89aad1cd1515bf986c25415cf1987a..e4b2fb5b32f8648810c9891421bed6a54cca3193 100644 --- a/service/key_command/test/key_command_handler_test.cpp +++ b/service/key_command/test/key_command_handler_test.cpp @@ -1078,7 +1078,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureActio displayInfo.width = 150; displayInfo.height = 300; displayInfo.uniq = "default0"; - inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); bool ret = handler.CheckTwoFingerGestureAction(); EXPECT_FALSE(ret); handler.twoFingerGesture_.touches[0].x = 30; @@ -1122,7 +1127,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureActio displayInfo.width = 150; displayInfo.height = 300; displayInfo.uniq = "default0"; - inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); handler.twoFingerGesture_.touches[0].y = 200; handler.twoFingerGesture_.touches[1].x = 30; bool ret = handler.CheckTwoFingerGestureAction(); @@ -1291,11 +1301,16 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_004, TestSiz DisplayInfo displayInfo; displayInfo.dpi = -10; displayInfo.uniq = "default0"; - inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); int32_t ret = handler.ConvertVPToPX(vp); ASSERT_EQ(ret, 0); displayInfo.dpi = 160; - inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo); + displayGroupInfoRef.displaysInfo.push_back(displayInfo); ret = handler.ConvertVPToPX(vp); ASSERT_EQ(ret, 0); } @@ -4048,7 +4063,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_002, TestSiz displayInfo.width = 4; displayInfo.height = 5; displayInfo.dpi = -1; - inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); ret = handler.ConvertVPToPX(vp); ASSERT_EQ(ret, 0); } @@ -4072,7 +4092,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_003, TestSiz displayInfo.width = 4; displayInfo.height = 5; displayInfo.dpi = 160; - inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); int32_t ret = handler.ConvertVPToPX(vp); ASSERT_EQ(ret, 0); } @@ -4104,7 +4129,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureActio displayInfo.width = 4; displayInfo.height = 5; displayInfo.dpi = -1; - inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); bool ret = handler.CheckTwoFingerGestureAction(); EXPECT_FALSE(ret); } @@ -4136,7 +4166,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureActio displayInfo.width = 40; displayInfo.height = 50; displayInfo.dpi = -1; - inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); bool ret = handler.CheckTwoFingerGestureAction(); EXPECT_FALSE(ret); } @@ -4168,7 +4203,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureActio displayInfo.width = 40; displayInfo.height = 50; displayInfo.dpi = -1; - inputWindowsManager.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); bool ret = handler.CheckTwoFingerGestureAction(); EXPECT_FALSE(ret); } @@ -5549,7 +5589,13 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_PreHandleEvent_02, TestSiz } /** - * @tc.name: KeyCommandHandlerTest_HandleKnuckleGestureDownEvent_004 + * @tc.name: DisplayGroupInfo displayGroupInfoRef; +auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); +if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; +} +displayGroupInfoRef.windowsInfo.push_back(windowInfo); +displayGroupInfoRef.displaysInfo.push_back(displayInfo); * @tc.desc: Test HandleKnuckleGestureDownEvent * @tc.type: FUNC * @tc.require: @@ -5577,8 +5623,13 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureDownEv windowInfo.id = 0; windowInfo.windowType = WINDOW_INPUT_METHOD_TYPE; auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo); + displayGroupInfoRef.displaysInfo.push_back(displayInfo); IInputWindowsManager::instance_ = inputWindowsManager; ASSERT_NO_FATAL_FAILURE(handler.HandleKnuckleGestureDownEvent(touchEvent)); @@ -5613,7 +5664,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckTwoFingerGestureActio displayInfo.height = 2720; displayInfo.uniq = "default0"; auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); IInputWindowsManager::instance_ = inputWindowsManager; handler.twoFingerGesture_.touches[0].x = 600; handler.twoFingerGesture_.touches[0].y = 600; @@ -5674,7 +5730,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ConvertVPToPX_006, TestSiz displayInfo.dpi = -1; displayInfo.uniq = "default0"; auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); IInputWindowsManager::instance_ = inputWindowsManager; KeyCommandHandler handler; int32_t ret = handler.ConvertVPToPX(vp); @@ -5710,8 +5771,13 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckKnuckleCondition_001, windowInfo.id = 0; windowInfo.windowType = WINDOW_INPUT_METHOD_TYPE; auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo); + displayGroupInfoRef.displaysInfo.push_back(displayInfo); IInputWindowsManager::instance_ = inputWindowsManager; touchEvent->SetTargetDisplayId(1); @@ -5765,8 +5831,13 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckKnuckleCondition_002, windowInfo.id = 0; windowInfo.windowType = WINDOW_INPUT_METHOD_TYPE; auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo); + displayGroupInfoRef.displaysInfo.push_back(displayInfo); IInputWindowsManager::instance_ = inputWindowsManager; touchEvent->SetTargetDisplayId(0); @@ -5807,7 +5878,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchM displayInfo.id = 0; displayInfo.direction = DIRECTION0; auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); IInputWindowsManager::instance_ = inputWindowsManager; KeyCommandHandler handler; @@ -5853,7 +5929,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchM displayInfo.id = 0; displayInfo.direction = DIRECTION0; auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); IInputWindowsManager::instance_ = inputWindowsManager; KeyCommandHandler handler; @@ -5899,7 +5980,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchM displayInfo.id = 0; displayInfo.direction = DIRECTION0; auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); IInputWindowsManager::instance_ = inputWindowsManager; KeyCommandHandler handler; @@ -5942,7 +6028,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchM displayInfo.id = 0; displayInfo.direction = DIRECTION0; auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); IInputWindowsManager::instance_ = inputWindowsManager; KeyCommandHandler handler; @@ -5988,7 +6079,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchM displayInfo.id = 0; displayInfo.direction = DIRECTION0; auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); IInputWindowsManager::instance_ = inputWindowsManager; KeyCommandHandler handler; @@ -6033,7 +6129,12 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_HandleKnuckleGestureTouchM displayInfo.id = 0; displayInfo.direction = DIRECTION0; auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); IInputWindowsManager::instance_ = inputWindowsManager; KeyCommandHandler handler; @@ -6215,8 +6316,13 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey_002, auto inputWindowsManager = std::make_shared(); WindowInfo windowInfo; windowInfo.id = 0; - inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo); - inputWindowsManager->displayGroupInfo_.focusWindowId = 0; + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo); + displayGroupInfoRef.focusWindowId = 0; UDSServer udsServer; udsServer.idxPidMap_.insert(std::make_pair(0, 1)); SessionPtr sessionPtr = std::make_shared(repeatKey.ability.bundleName, 0, 0, 0, 0); @@ -6252,8 +6358,13 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey_003, auto inputWindowsManager = std::make_shared(); WindowInfo windowInfo; windowInfo.id = 0; - inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo); - inputWindowsManager->displayGroupInfo_.focusWindowId = 0; + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo); + displayGroupInfoRef.focusWindowId = 0; UDSServer udsServer; udsServer.idxPidMap_.insert(std::make_pair(0, 1)); SessionPtr sessionPtr = std::make_shared(repeatKey.ability.bundleName, 0, 0, 0, 0); @@ -6289,8 +6400,13 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_CheckSpecialRepeatKey_004, auto inputWindowsManager = std::make_shared(); WindowInfo windowInfo; windowInfo.id = 0; - inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo); - inputWindowsManager->displayGroupInfo_.focusWindowId = 0; + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo); + displayGroupInfoRef.focusWindowId = 0; UDSServer udsServer; udsServer.idxPidMap_.insert(std::make_pair(0, 1)); SessionPtr sessionPtr = std::make_shared(repeatKey.ability.bundleName, 0, 0, 0, 0); @@ -6619,6 +6735,6 @@ HWTEST_F(KeyCommandHandlerTest, KeyCommandHandlerTest_ReportKnuckleScreenCapture ASSERT_NO_FATAL_FAILURE(handler.ReportKnuckleScreenCapture(touchEvent)); } - +///add } // namespace MMI } // namespace OHOS diff --git a/service/key_command/test/long_press_subscriber_handler_test.cpp b/service/key_command/test/long_press_subscriber_handler_test.cpp index 72a71ed456f2d4abaa7395fa8200d5fedd15d4b1..361daa7f5f4c0e89d8175c709281f9c8679a0a52 100644 --- a/service/key_command/test/long_press_subscriber_handler_test.cpp +++ b/service/key_command/test/long_press_subscriber_handler_test.cpp @@ -13,1399 +13,1429 @@ * limitations under the License. */ -#include -#include "ipc_skeleton.h" - -#include "input_event_handler.h" -#include "input_windows_manager.h" -#include "long_press_subscriber_handler.h" -#include "uds_session.h" - -#undef MMI_LOG_TAG -#define MMI_LOG_TAG "LongPressSubscribeHandlerTest" - -namespace OHOS { -namespace MMI { -namespace { -using namespace testing::ext; -const std::string PROGRAM_NAME = "LongPressSubscribeHandlerTest"; -constexpr int32_t MODULE_TYPE = 1; -constexpr int32_t UDS_FD = -1; -constexpr int32_t UDS_UID = 100; -constexpr int32_t UDS_PID = 100; -} // namespace - -class LongPressSubscribeHandlerTest : public testing::Test { -public: - static void SetUpTestCase(void) {} - static void TearDownTestCase(void) {} - std::shared_ptr SetupZeroFingerDownEvent(); - std::shared_ptr SetupSingleFingerDownEvent(); - std::shared_ptr SetupDoubleFingerDownEvent(); - std::shared_ptr SetupThreeFingerDownEvent(); -}; - -std::shared_ptr LongPressSubscribeHandlerTest::SetupZeroFingerDownEvent() -{ - std::shared_ptr pointerEvent = PointerEvent::Create(); - CHKPP(pointerEvent); - pointerEvent->SetPointerId(0); - pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); - pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); - return pointerEvent; -} - -std::shared_ptr LongPressSubscribeHandlerTest::SetupSingleFingerDownEvent() -{ - std::shared_ptr pointerEvent = PointerEvent::Create(); - CHKPP(pointerEvent); - PointerEvent::PointerItem item; - item.SetPointerId(0); - item.SetToolType(PointerEvent::TOOL_TYPE_FINGER); - int32_t downX = 100; - int32_t downY = 200; - item.SetDisplayX(downX); - item.SetDisplayY(downY); - item.SetPressed(true); - pointerEvent->SetPointerId(0); - pointerEvent->AddPointerItem(item); - pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); - pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); - return pointerEvent; -} - -std::shared_ptr LongPressSubscribeHandlerTest::SetupDoubleFingerDownEvent() -{ - std::shared_ptr pointerEvent = PointerEvent::Create(); - CHKPP(pointerEvent); - PointerEvent::PointerItem item; - PointerEvent::PointerItem item2; - item.SetPointerId(0); - item.SetToolType(PointerEvent::TOOL_TYPE_FINGER); - int32_t downX = 100; - int32_t downY = 200; - item.SetDisplayX(downX); - item.SetDisplayY(downY); - item.SetPressed(true); - item.SetDownTime(0); - pointerEvent->SetPointerId(0); - pointerEvent->AddPointerItem(item); - - item2.SetPointerId(1); - item2.SetToolType(PointerEvent::TOOL_TYPE_FINGER); - int32_t secondDownX = 120; - int32_t secondDownY = 220; - item2.SetDisplayX(secondDownX); - item2.SetDisplayY(secondDownY); - item2.SetPressed(true); - int64_t downTime = 100000; - item2.SetDownTime(downTime); - pointerEvent->SetPointerId(1); - pointerEvent->AddPointerItem(item2); - pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); - pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); - return pointerEvent; -} - -std::shared_ptr LongPressSubscribeHandlerTest::SetupThreeFingerDownEvent() -{ - std::shared_ptr pointerEvent = PointerEvent::Create(); - CHKPP(pointerEvent); - PointerEvent::PointerItem item; - PointerEvent::PointerItem item2; - PointerEvent::PointerItem item3; - item.SetPointerId(0); - item.SetToolType(PointerEvent::TOOL_TYPE_FINGER); - int32_t downX = 100; - int32_t downY = 200; - item.SetDisplayX(downX); - item.SetDisplayY(downY); - item.SetPressed(true); - pointerEvent->SetPointerId(0); - pointerEvent->AddPointerItem(item); - - item2.SetPointerId(1); - item2.SetToolType(PointerEvent::TOOL_TYPE_FINGER); - int32_t secondDownX = 120; - int32_t secondDownY = 220; - item2.SetDisplayX(secondDownX); - item2.SetDisplayY(secondDownY); - item2.SetPressed(true); - pointerEvent->SetPointerId(1); - pointerEvent->AddPointerItem(item2); - - int32_t pointerId2 = 2; - item3.SetPointerId(pointerId2); - item3.SetToolType(PointerEvent::TOOL_TYPE_FINGER); - int32_t thirdDownX = 140; - int32_t thirdDownY = 240; - item3.SetDisplayX(thirdDownX); - item3.SetDisplayY(thirdDownY); - item3.SetPressed(true); - pointerEvent->SetPointerId(pointerId2); - pointerEvent->AddPointerItem(item3); - - pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); - pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); - return pointerEvent; -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_SubscribeLongPressEvent_001 - * @tc.desc: Verify invalid subscribeId when subscribe long press event - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_SubscribeLongPressEvent_001, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = -1; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); - EXPECT_TRUE(ret < 0); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_SubscribeLongPressEvent_002 - * @tc.desc: Verify valid subscribeId when subscribe long press event - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_SubscribeLongPressEvent_002, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); - EXPECT_TRUE(ret >= 0); - ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); - EXPECT_TRUE(ret == RET_OK); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_001 - * @tc.desc: Verify invalid subscribeId when unsubscribe long press event - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_001, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = -1; - int32_t ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); - EXPECT_TRUE(ret < 0); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_002 - * @tc.desc: Verify invalid subscribeId when unsubscribe long press event - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_002, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); - EXPECT_TRUE(ret >= 0); - subscribeId = -1; - ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); - EXPECT_TRUE(ret == RET_ERR); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_003 - * @tc.desc: Verify invalid sess when unsubscribe long press event - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_003, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); - EXPECT_TRUE(ret >= 0); - sess = nullptr; - ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); - EXPECT_TRUE(ret == ERROR_NULL_POINTER); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_004 - * @tc.desc: Verify invalid sess and invalid subscribeId when unsubscribe long press event - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_004, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); - EXPECT_TRUE(ret >= 0); - sess = nullptr; - subscribeId = -1; - ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); - EXPECT_TRUE(ret == ERROR_NULL_POINTER); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_005 - * @tc.desc: Verify !subscribers.empty() - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_005, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId1 = 0; - LongPressRequest longPressRequest1 { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); - EXPECT_TRUE(ret >= 0); - - int32_t subscribeId2 = 1; - LongPressRequest longPressRequest2 { - .fingerCount = 1, - .duration = 900, - }; - ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); - EXPECT_TRUE(ret >= 0); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_AddDurationTimer_001 - * @tc.desc: Verify durationTimer.duration == duration - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_AddDurationTimer_001, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId1 = 0; - LongPressRequest longPressRequest1 { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); - EXPECT_TRUE(ret >= 0); - - int32_t subscribeId2 = 1; - LongPressRequest longPressRequest2 { - .fingerCount = 2, - .duration = 300, - }; - ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); - EXPECT_TRUE(ret >= 0); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_RemoveDurationTimer_001 - * @tc.desc: Verify durationTimer.duration == duration - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_RemoveDurationTimer_001, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId1 = 0; - LongPressRequest longPressRequest1 { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); - EXPECT_TRUE(ret >= 0); - - int32_t subscribeId2 = 1; - LongPressRequest longPressRequest2 { - .fingerCount = 2, - .duration = 300, - }; - ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); - EXPECT_TRUE(ret >= 0); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_RemoveDurationTimer_002 - * @tc.desc: Verify it->first.second == duration && !it->second.empty() - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_RemoveDurationTimer_002, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId1 = 0; - LongPressRequest longPressRequest1 { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); - EXPECT_TRUE(ret >= 0); - - int32_t subscribeId2 = 1; - LongPressRequest longPressRequest2 { - .fingerCount = 1, - .duration = 300, - }; - ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); - EXPECT_TRUE(ret >= 0); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_RemoveDurationTimer_003 - * @tc.desc: Verify it->first.second != duration && !it->second.empty() - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_RemoveDurationTimer_003, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId1 = 0; - LongPressRequest longPressRequest1 { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); - EXPECT_TRUE(ret >= 0); - - int32_t subscribeId2 = 1; - LongPressRequest longPressRequest2 { - .fingerCount = 1, - .duration = 900, - }; - ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); - EXPECT_TRUE(ret >= 0); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_OnSubscribeLongPressEvent_001 - * @tc.desc: Verify subscriberInfos_.find(pair) == subscriberInfos_.end() - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSubscribeLongPressEvent_001, TestSize.Level1) -{ - CALL_TEST_DEBUG; - int32_t fingerCount = 1; - int32_t duration = 300; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressEvent(fingerCount, duration)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_OnSubscribeLongPressEvent_002 - * @tc.desc: Verify subscriberInfos_.find(pair) != subscriberInfos_.end() - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSubscribeLongPressEvent_002, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId1 = 0; - LongPressRequest longPressRequest1 { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); - EXPECT_TRUE(ret >= 0); - int32_t fingerCount = 1; - int32_t duration = 300; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressEvent(fingerCount, duration)); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_InsertSubScriber_001 - * @tc.desc: Verify subscriber->sess_ != nullptr && sub->id_ == subscriber->id_ && sub->sess_ == subscriber->sess - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_InsertSubScriber_001, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId1 = 0; - LongPressRequest longPressRequest1 { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); - EXPECT_TRUE(ret >= 0); - - int32_t subscribeId2 = 0; - LongPressRequest longPressRequest2 { - .fingerCount = 1, - .duration = 900, - }; - ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); - EXPECT_TRUE(ret >= 0); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_InsertSubScriber_002 - * @tc.desc: Verify subscriber->sess_ != nullptr && sub->id_ == subscriber->id_ && sub->sess_ != subscriber->sess - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_InsertSubScriber_002, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess1 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId1 = 0; - LongPressRequest longPressRequest1 { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess1, subscribeId1, longPressRequest1); - EXPECT_TRUE(ret >= 0); - - SessionPtr sess2 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId2 = 0; - LongPressRequest longPressRequest2 { - .fingerCount = 1, - .duration = 900, - }; - ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess2, subscribeId2, longPressRequest2); - EXPECT_TRUE(ret >= 0); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess1, subscribeId1)); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess2, subscribeId2)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_InsertSubScriber_003 - * @tc.desc: Verify subscriber->sess_ != nullptr && sub->id_ != subscriber->id_ && sub->sess_ != subscriber->sess - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_InsertSubScriber_003, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess1 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId1 = 0; - LongPressRequest longPressRequest1 { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess1, subscribeId1, longPressRequest1); - EXPECT_TRUE(ret >= 0); - - SessionPtr sess2 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId2 = 1; - LongPressRequest longPressRequest2 { - .fingerCount = 1, - .duration = 900, - }; - ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess2, subscribeId2, longPressRequest2); - EXPECT_TRUE(ret >= 0); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess1, subscribeId1)); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess2, subscribeId2)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_OnSessionDelete_001 - * @tc.desc: Verify (*iter)->sess_ == sess and subscribers.empty() - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSessionDelete_001, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess1 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId1 = 0; - LongPressRequest longPressRequest1 { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess1, subscribeId1, longPressRequest1); - EXPECT_TRUE(ret >= 0); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSessionDelete(sess1)); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess1, subscribeId1)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_OnSessionDelete_002 - * @tc.desc: Verify (*iter)->sess_ != sess and !subscribers.empty() - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSessionDelete_002, TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess1 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId1 = 0; - LongPressRequest longPressRequest1 { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess1, subscribeId1, longPressRequest1); - EXPECT_TRUE(ret >= 0); - - SessionPtr sess2 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId2 = 1; - LongPressRequest longPressRequest2 { - .fingerCount = 1, - .duration = 300, - }; - ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess2, subscribeId2, longPressRequest2); - EXPECT_TRUE(ret >= 0); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSessionDelete(sess2)); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSessionDelete(sess1)); - - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess1, subscribeId1)); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess2, subscribeId2)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureDownEvent_001 - * @tc.desc: Verify if (fingerCount > 0 && fingerCount <= TwoFingerGesture::MAX_TOUCH_NUM) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureDownEvent_001, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupZeroFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); - - pointerEvent = SetupSingleFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); - - pointerEvent = SetupDoubleFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); - - pointerEvent = SetupThreeFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureDownEvent_002 - * @tc.desc: Verify if (pressTimeInterval > TWO_FINGERS_TIME_LIMIT) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureDownEvent_002, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupDoubleFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - auto fingerCount = pointerEvent->GetPointerIds().size(); - ASSERT_TRUE(fingerCount == 2); - PointerEvent::PointerItem item; - int32_t pointerId = 1; - bool result = pointerEvent->GetPointerItem(pointerId, item); - ASSERT_TRUE(result); - item.SetDownTime(item.GetDownTime() + 150000); - pointerEvent->UpdatePointerItem(pointerId, item); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_001 - * @tc.desc: Verify if (isAllTimerClosed) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_001, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupThreeFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = true; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureMoveEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_002 - * @tc.desc: Verify if (fingerCount > static_cast(TWO_FINGER)) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_002, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupThreeFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureMoveEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_003 - * @tc.desc: Verify if (pos == std::end(fingerGesture_.touches)) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_003, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupSingleFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); - - PointerEvent::PointerItem item; - int32_t pointerId = 0; - bool result = pointerEvent->GetPointerItem(pointerId, item); - ASSERT_TRUE(result); - item.SetPointerId(item.GetPointerId() + 1); - pointerEvent->UpdatePointerItem(pointerId, item); - - LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureMoveEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_004 - * @tc.desc: Verify if (pos == std::end(fingerGesture_.touches)) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_004, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupSingleFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); - - LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureMoveEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_005 - * @tc.desc: Verify if (moveDistance > TOUCH_MOVE_THRESHOLD) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_005, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupSingleFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); - - PointerEvent::PointerItem item; - int32_t pointerId = 0; - bool result = pointerEvent->GetPointerItem(pointerId, item); - ASSERT_TRUE(result); - item.SetDisplayX(item.GetDisplayX() + 100); - pointerEvent->UpdatePointerItem(pointerId, item); - - LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureMoveEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_001 - * @tc.desc: Verify if (isAllTimerClosed) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_001, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupSingleFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = true; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureUpEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_002 - * @tc.desc: Verify if (touchEvent->GetPointerIds().size() > static_cast(TWO_FINGER)) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_002, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupThreeFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureUpEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_003 - * @tc.desc: Verify if (touchEvent->GetPointerIds().size() > static_cast(TWO_FINGER)) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_003, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupDoubleFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureUpEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_001 - * @tc.desc: Verify if (index < 0 || index > static_cast(ONE_FINGER)) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_001, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupThreeFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); - - pointerEvent = SetupZeroFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_002 - * @tc.desc: Verify if (!durationTimers_.empty()) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_002, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto pointerEvent = SetupSingleFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_003 - * @tc.desc: Verify if (!durationTimers_.empty()) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_003, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); - EXPECT_TRUE(ret >= 0); - - auto pointerEvent = SetupSingleFingerDownEvent(); - PointerEvent::PointerItem item; - int32_t pointerId = 0; - bool result = pointerEvent->GetPointerItem(pointerId, item); - ASSERT_TRUE(result); - item.SetDownTime(0); - pointerEvent->UpdatePointerItem(pointerId, item); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); - - int64_t downTime = 100000; - item.SetDownTime(downTime); - pointerEvent->UpdatePointerItem(pointerId, item); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); - - downTime = 400000; - item.SetDownTime(downTime); - pointerEvent->UpdatePointerItem(pointerId, item); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); - - ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); - EXPECT_TRUE(ret == RET_OK); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_004 - * @tc.desc: Verify if (tempSubs.size() < static_cast(TWO_FINGER)) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_004, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { .fingerCount = 1, .duration = 300, }; - int32_t subscribeId2 = 0; - LongPressRequest longPressRequest2 { .fingerCount = 1, .duration = 900, }; - int32_t subscribeId3 = 0; - LongPressRequest longPressRequest3 { .fingerCount = 1, .duration = 1500, }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); - EXPECT_TRUE(ret >= 0); - ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); - EXPECT_TRUE(ret >= 0); - ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId3, longPressRequest3); - EXPECT_TRUE(ret >= 0); - auto pointerEvent = SetupSingleFingerDownEvent(); - PointerEvent::PointerItem item; - int32_t pointerId = 0; - bool result = pointerEvent->GetPointerItem(pointerId, item); - ASSERT_TRUE(result); - item.SetDownTime(0); - pointerEvent->UpdatePointerItem(pointerId, item); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); - int64_t downTime = 400000; - item.SetDownTime(downTime); - pointerEvent->UpdatePointerItem(pointerId, item); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); - downTime = 1000000; - item.SetDownTime(downTime); - pointerEvent->UpdatePointerItem(pointerId, item); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); - downTime = 1600000; - item.SetDownTime(downTime); - pointerEvent->UpdatePointerItem(pointerId, item); - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); - ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); - EXPECT_TRUE(ret == RET_OK); - ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2); - EXPECT_TRUE(ret == RET_OK); - ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId3); - EXPECT_TRUE(ret == RET_OK); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_OnSubscribeLongPressCancelEvent_001 - * @tc.desc: Verify if (it == sessManager_.end()) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSubscribeLongPressCancelEvent_001, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - - int32_t fingerCount = 1; - int32_t duration = 300; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressCancelEvent(sess, fingerCount, duration)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_OnSubscribeLongPressCancelEvent_002 - * @tc.desc: Verify if (subscriber->fingerCount_ == fingerCount && subscriber->duration_ == duration) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSubscribeLongPressCancelEvent_002, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); - EXPECT_TRUE(ret >= 0); - - int32_t fingerCount = 1; - int32_t duration = 300; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressCancelEvent(sess, fingerCount, duration)); - - fingerCount = 2; - duration = 300; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressCancelEvent(sess, fingerCount, duration)); - - fingerCount = 1; - duration = 900; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressCancelEvent(sess, fingerCount, duration)); - - fingerCount = 2; - duration = 900; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressCancelEvent(sess, fingerCount, duration)); - - ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); - EXPECT_TRUE(ret == RET_OK); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_StartFingerGesture_001 - * @tc.desc: Verify if (!CheckFingerGestureAction(fingerCount)) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_StartFingerGesture_001, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); - EXPECT_TRUE(ret >= 0); - - int32_t fingerCount = 2; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->StartFingerGesture(fingerCount)); - - ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); - EXPECT_TRUE(ret == RET_OK); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_StartFingerGesture_002 - * @tc.desc: Verify if (!CheckFingerGestureAction(fingerCount)) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_StartFingerGesture_002, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); - EXPECT_TRUE(ret >= 0); - - DisplayInfo displayInfo; - displayInfo.dpi = 320; - displayInfo.width = 1260; - displayInfo.height = 2720; - displayInfo.uniq = "default0"; - auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); - IInputWindowsManager::instance_ = inputWindowsManager; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; - int32_t fingerCount = 1; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->StartFingerGesture(fingerCount)); - - ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); - EXPECT_TRUE(ret == RET_OK); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureAction_001 - * @tc.desc: Verify if (firstFinger.x <= leftLimit || firstFinger.x >= rightLimit || - * firstFinger.y <= topLimit || firstFinger.y >= bottomLimit) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureAction_001, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - DisplayInfo displayInfo; - displayInfo.dpi = 320; - displayInfo.width = 1260; - displayInfo.height = 2720; - displayInfo.uniq = "default0"; - auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); - IInputWindowsManager::instance_ = inputWindowsManager; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; - int32_t fingerCount = 1; - bool ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); - EXPECT_EQ(ret, true); - - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 20; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; - ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); - EXPECT_EQ(ret, false); - - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 1250; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; - ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); - EXPECT_EQ(ret, false); - - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 10; - ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); - EXPECT_EQ(ret, false); - - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 2700; - ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); - EXPECT_EQ(ret, false); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureAction_002 - * @tc.desc: Verify if (secondFinger.x <= leftLimit || secondFinger.x >= rightLimit || - * secondFinger.y <= topLimit || secondFinger.y >= bottomLimit) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureAction_002, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - DisplayInfo displayInfo; - displayInfo.dpi = 320; - displayInfo.width = 1260; - displayInfo.height = 2720; - displayInfo.uniq = "default0"; - auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); - IInputWindowsManager::instance_ = inputWindowsManager; - int32_t fingerCount = 2; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; - - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 800; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 600; - bool ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); - EXPECT_EQ(ret, true); - - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 10; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 600; - ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); - EXPECT_EQ(ret, false); - - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 1250; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 600; - ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); - EXPECT_EQ(ret, false); - - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 600; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 10; - ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); - EXPECT_EQ(ret, false); - - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 600; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 2710; - ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); - EXPECT_EQ(ret, false); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureAction_003 - * @tc.desc: Verify if (distance < ConvertVPToPX(TWO_FINGERS_DISTANCE_LIMIT)) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureAction_003, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - DisplayInfo displayInfo; - displayInfo.dpi = 320; - displayInfo.width = 1260; - displayInfo.height = 2720; - displayInfo.uniq = "default0"; - auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); - IInputWindowsManager::instance_ = inputWindowsManager; - int32_t fingerCount = 2; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; - - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 610; - LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 600; - bool ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); - EXPECT_EQ(ret, false); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_InitSessionDeleteCallback_001 - * @tc.desc: Verify if (callbackInitialized_) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_InitSessionDeleteCallback_001, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - LONG_PRESS_EVENT_HANDLER->callbackInitialized_ = true; - bool ret = LONG_PRESS_EVENT_HANDLER->InitSessionDeleteCallback(); - EXPECT_EQ(ret, true); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_InitSessionDeleteCallback_002 - * @tc.desc: Verify if (callbackInitialized_) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_InitSessionDeleteCallback_002, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - LONG_PRESS_EVENT_HANDLER->callbackInitialized_ = false; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->InitSessionDeleteCallback()); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_ConvertVPToPX_001 - * @tc.desc: Verify if (vp <= 0) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_ConvertVPToPX_001, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - int32_t vp = -1; - int32_t ret = LONG_PRESS_EVENT_HANDLER->ConvertVPToPX(vp); - ASSERT_EQ(ret, 0); - ret = LONG_PRESS_EVENT_HANDLER->ConvertVPToPX(vp); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_ConvertVPToPX_002 - * @tc.desc: Verify if (dpi <= 0) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_ConvertVPToPX_002, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - int32_t vp = 5; - DisplayInfo displayInfo; - displayInfo.id = 1; - displayInfo.x = 2; - displayInfo.y = 3; - displayInfo.width = 4; - displayInfo.height = 5; - displayInfo.dpi = -1; - displayInfo.uniq = "default0"; - auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); - IInputWindowsManager::instance_ = inputWindowsManager; - int32_t ret = LONG_PRESS_EVENT_HANDLER->ConvertVPToPX(vp); - ASSERT_EQ(ret, 0); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_GetBundleName_001 - * @tc.desc: Verify if (userid < 0); - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_GetBundleName_001, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - auto inputWindowsManager = std::make_shared(); - int32_t currentUserId = -1; - inputWindowsManager->SetCurrentUser(currentUserId); - IInputWindowsManager::instance_ = inputWindowsManager; - std::string bundleName = "test"; - int32_t windowPid = 0; - int32_t ret = LONG_PRESS_EVENT_HANDLER->GetBundleName(bundleName, windowPid); - ASSERT_EQ(ret, RET_ERR); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_NotifySubscriber_001 - * @tc.desc: Verify if (subscriber->sess_ == nullptr) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_NotifySubscriber_001, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - std::shared_ptr subscriber { nullptr }; - int32_t result = 0; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->NotifySubscriber(subscriber, result)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_NotifySubscriber_002 - * @tc.desc: Verify if (windowPid == RET_ERR) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_NotifySubscriber_002, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - auto subscriber = std::make_shared(subscribeId, sess, longPressRequest.fingerCount, - longPressRequest.duration); - auto pair = std::make_pair(longPressRequest.fingerCount, longPressRequest.duration); - LONG_PRESS_EVENT_HANDLER->subscriberInfos_[pair].push_back(subscriber); - int32_t result = 0; - UDSServer* udsServer = new UDSServer(); - ASSERT_TRUE(udsServer != nullptr); - InputHandler->udsServer_ = udsServer; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->NotifySubscriber(subscriber, result)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_NotifySubscriber_003 - * @tc.desc: Verify if (GetBundleName(bundleName, windowPid) == RET_ERR) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_NotifySubscriber_003, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - auto subscriber = std::make_shared(subscribeId, sess, longPressRequest.fingerCount, - longPressRequest.duration); - auto pair = std::make_pair(longPressRequest.fingerCount, longPressRequest.duration); - LONG_PRESS_EVENT_HANDLER->subscriberInfos_[pair].push_back(subscriber); - int32_t result = 0; - UDSServer* udsServer = new UDSServer(); - ASSERT_TRUE(udsServer != nullptr); - InputHandler->udsServer_ = udsServer; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->NotifySubscriber(subscriber, result)); -} - -/** - * @tc.name: LongPressSubscribeHandlerTest_NotifySubscriber_004 - * @tc.desc: Verify if (GetBundleName(bundleName, windowPid) == RET_ERR) - * @tc.type: Function - * @tc.require: - */ -HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_NotifySubscriber_004, - TestSize.Level1) -{ - CALL_TEST_DEBUG; - SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, - UDS_PID); - int32_t subscribeId = 0; - LongPressRequest longPressRequest { - .fingerCount = 1, - .duration = 300, - }; - - WindowInfo windowInfo; - windowInfo.id = 10000; - auto inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo); - IInputWindowsManager::instance_ = inputWindowsManager; - - auto pointerEvent = SetupSingleFingerDownEvent(); - ASSERT_TRUE(pointerEvent != nullptr); - PointerEvent::PointerItem item; - int32_t pointerId = 0; - bool ret = pointerEvent->GetPointerItem(pointerId, item); - ASSERT_TRUE(ret); - item.SetTargetWindowId(windowInfo.id); - pointerEvent->UpdatePointerItem(pointerId, item); - LONG_PRESS_EVENT_HANDLER->touchEvent_ = pointerEvent; - - auto subscriber = std::make_shared(subscribeId, sess, longPressRequest.fingerCount, - longPressRequest.duration); - auto pair = std::make_pair(longPressRequest.fingerCount, longPressRequest.duration); - LONG_PRESS_EVENT_HANDLER->subscriberInfos_[pair].push_back(subscriber); - int32_t result = 0; - UDSServer* udsServer = new UDSServer(); - ASSERT_TRUE(udsServer != nullptr); - InputHandler->udsServer_ = udsServer; - ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->NotifySubscriber(subscriber, result)); -} -} // namespace MMI -} // namespace OHOS \ No newline at end of file + #include + #include "ipc_skeleton.h" + + #include "input_event_handler.h" + #include "input_windows_manager.h" + #include "long_press_subscriber_handler.h" + #include "uds_session.h" + + #undef MMI_LOG_TAG + #define MMI_LOG_TAG "LongPressSubscribeHandlerTest" + + namespace OHOS { + namespace MMI { + namespace { + using namespace testing::ext; + const std::string PROGRAM_NAME = "LongPressSubscribeHandlerTest"; + constexpr int32_t MODULE_TYPE = 1; + constexpr int32_t UDS_FD = -1; + constexpr int32_t UDS_UID = 100; + constexpr int32_t UDS_PID = 100; + } // namespace + + class LongPressSubscribeHandlerTest : public testing::Test { + public: + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + std::shared_ptr SetupZeroFingerDownEvent(); + std::shared_ptr SetupSingleFingerDownEvent(); + std::shared_ptr SetupDoubleFingerDownEvent(); + std::shared_ptr SetupThreeFingerDownEvent(); + }; + + std::shared_ptr LongPressSubscribeHandlerTest::SetupZeroFingerDownEvent() + { + std::shared_ptr pointerEvent = PointerEvent::Create(); + CHKPP(pointerEvent); + pointerEvent->SetPointerId(0); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); + return pointerEvent; + } + + std::shared_ptr LongPressSubscribeHandlerTest::SetupSingleFingerDownEvent() + { + std::shared_ptr pointerEvent = PointerEvent::Create(); + CHKPP(pointerEvent); + PointerEvent::PointerItem item; + item.SetPointerId(0); + item.SetToolType(PointerEvent::TOOL_TYPE_FINGER); + int32_t downX = 100; + int32_t downY = 200; + item.SetDisplayX(downX); + item.SetDisplayY(downY); + item.SetPressed(true); + pointerEvent->SetPointerId(0); + pointerEvent->AddPointerItem(item); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); + return pointerEvent; + } + + std::shared_ptr LongPressSubscribeHandlerTest::SetupDoubleFingerDownEvent() + { + std::shared_ptr pointerEvent = PointerEvent::Create(); + CHKPP(pointerEvent); + PointerEvent::PointerItem item; + PointerEvent::PointerItem item2; + item.SetPointerId(0); + item.SetToolType(PointerEvent::TOOL_TYPE_FINGER); + int32_t downX = 100; + int32_t downY = 200; + item.SetDisplayX(downX); + item.SetDisplayY(downY); + item.SetPressed(true); + item.SetDownTime(0); + pointerEvent->SetPointerId(0); + pointerEvent->AddPointerItem(item); + + item2.SetPointerId(1); + item2.SetToolType(PointerEvent::TOOL_TYPE_FINGER); + int32_t secondDownX = 120; + int32_t secondDownY = 220; + item2.SetDisplayX(secondDownX); + item2.SetDisplayY(secondDownY); + item2.SetPressed(true); + int64_t downTime = 100000; + item2.SetDownTime(downTime); + pointerEvent->SetPointerId(1); + pointerEvent->AddPointerItem(item2); + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); + return pointerEvent; + } + + std::shared_ptr LongPressSubscribeHandlerTest::SetupThreeFingerDownEvent() + { + std::shared_ptr pointerEvent = PointerEvent::Create(); + CHKPP(pointerEvent); + PointerEvent::PointerItem item; + PointerEvent::PointerItem item2; + PointerEvent::PointerItem item3; + item.SetPointerId(0); + item.SetToolType(PointerEvent::TOOL_TYPE_FINGER); + int32_t downX = 100; + int32_t downY = 200; + item.SetDisplayX(downX); + item.SetDisplayY(downY); + item.SetPressed(true); + pointerEvent->SetPointerId(0); + pointerEvent->AddPointerItem(item); + + item2.SetPointerId(1); + item2.SetToolType(PointerEvent::TOOL_TYPE_FINGER); + int32_t secondDownX = 120; + int32_t secondDownY = 220; + item2.SetDisplayX(secondDownX); + item2.SetDisplayY(secondDownY); + item2.SetPressed(true); + pointerEvent->SetPointerId(1); + pointerEvent->AddPointerItem(item2); + + int32_t pointerId2 = 2; + item3.SetPointerId(pointerId2); + item3.SetToolType(PointerEvent::TOOL_TYPE_FINGER); + int32_t thirdDownX = 140; + int32_t thirdDownY = 240; + item3.SetDisplayX(thirdDownX); + item3.SetDisplayY(thirdDownY); + item3.SetPressed(true); + pointerEvent->SetPointerId(pointerId2); + pointerEvent->AddPointerItem(item3); + + pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); + pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); + return pointerEvent; + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_SubscribeLongPressEvent_001 + * @tc.desc: Verify invalid subscribeId when subscribe long press event + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_SubscribeLongPressEvent_001, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = -1; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); + EXPECT_TRUE(ret < 0); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_SubscribeLongPressEvent_002 + * @tc.desc: Verify valid subscribeId when subscribe long press event + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_SubscribeLongPressEvent_002, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); + EXPECT_TRUE(ret >= 0); + ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); + EXPECT_TRUE(ret == RET_OK); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_001 + * @tc.desc: Verify invalid subscribeId when unsubscribe long press event + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_001, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = -1; + int32_t ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); + EXPECT_TRUE(ret < 0); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_002 + * @tc.desc: Verify invalid subscribeId when unsubscribe long press event + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_002, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); + EXPECT_TRUE(ret >= 0); + subscribeId = -1; + ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); + EXPECT_TRUE(ret == RET_ERR); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_003 + * @tc.desc: Verify invalid sess when unsubscribe long press event + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_003, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); + EXPECT_TRUE(ret >= 0); + sess = nullptr; + ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); + EXPECT_TRUE(ret == ERROR_NULL_POINTER); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_004 + * @tc.desc: Verify invalid sess and invalid subscribeId when unsubscribe long press event + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_004, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); + EXPECT_TRUE(ret >= 0); + sess = nullptr; + subscribeId = -1; + ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); + EXPECT_TRUE(ret == ERROR_NULL_POINTER); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_005 + * @tc.desc: Verify !subscribers.empty() + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_UnsubscribeLongPressEvent_005, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId1 = 0; + LongPressRequest longPressRequest1 { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); + EXPECT_TRUE(ret >= 0); + + int32_t subscribeId2 = 1; + LongPressRequest longPressRequest2 { + .fingerCount = 1, + .duration = 900, + }; + ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); + EXPECT_TRUE(ret >= 0); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_AddDurationTimer_001 + * @tc.desc: Verify durationTimer.duration == duration + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_AddDurationTimer_001, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId1 = 0; + LongPressRequest longPressRequest1 { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); + EXPECT_TRUE(ret >= 0); + + int32_t subscribeId2 = 1; + LongPressRequest longPressRequest2 { + .fingerCount = 2, + .duration = 300, + }; + ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); + EXPECT_TRUE(ret >= 0); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_RemoveDurationTimer_001 + * @tc.desc: Verify durationTimer.duration == duration + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_RemoveDurationTimer_001, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId1 = 0; + LongPressRequest longPressRequest1 { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); + EXPECT_TRUE(ret >= 0); + + int32_t subscribeId2 = 1; + LongPressRequest longPressRequest2 { + .fingerCount = 2, + .duration = 300, + }; + ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); + EXPECT_TRUE(ret >= 0); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_RemoveDurationTimer_002 + * @tc.desc: Verify it->first.second == duration && !it->second.empty() + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_RemoveDurationTimer_002, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId1 = 0; + LongPressRequest longPressRequest1 { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); + EXPECT_TRUE(ret >= 0); + + int32_t subscribeId2 = 1; + LongPressRequest longPressRequest2 { + .fingerCount = 1, + .duration = 300, + }; + ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); + EXPECT_TRUE(ret >= 0); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_RemoveDurationTimer_003 + * @tc.desc: Verify it->first.second != duration && !it->second.empty() + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_RemoveDurationTimer_003, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId1 = 0; + LongPressRequest longPressRequest1 { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); + EXPECT_TRUE(ret >= 0); + + int32_t subscribeId2 = 1; + LongPressRequest longPressRequest2 { + .fingerCount = 1, + .duration = 900, + }; + ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); + EXPECT_TRUE(ret >= 0); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_OnSubscribeLongPressEvent_001 + * @tc.desc: Verify subscriberInfos_.find(pair) == subscriberInfos_.end() + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSubscribeLongPressEvent_001, TestSize.Level1) + { + CALL_TEST_DEBUG; + int32_t fingerCount = 1; + int32_t duration = 300; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressEvent(fingerCount, duration)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_OnSubscribeLongPressEvent_002 + * @tc.desc: Verify subscriberInfos_.find(pair) != subscriberInfos_.end() + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSubscribeLongPressEvent_002, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId1 = 0; + LongPressRequest longPressRequest1 { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); + EXPECT_TRUE(ret >= 0); + int32_t fingerCount = 1; + int32_t duration = 300; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressEvent(fingerCount, duration)); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_InsertSubScriber_001 + * @tc.desc: Verify subscriber->sess_ != nullptr && sub->id_ == subscriber->id_ && sub->sess_ == subscriber->sess + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_InsertSubScriber_001, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId1 = 0; + LongPressRequest longPressRequest1 { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId1, longPressRequest1); + EXPECT_TRUE(ret >= 0); + + int32_t subscribeId2 = 0; + LongPressRequest longPressRequest2 { + .fingerCount = 1, + .duration = 900, + }; + ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); + EXPECT_TRUE(ret >= 0); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId1)); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_InsertSubScriber_002 + * @tc.desc: Verify subscriber->sess_ != nullptr && sub->id_ == subscriber->id_ && sub->sess_ != subscriber->sess + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_InsertSubScriber_002, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess1 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId1 = 0; + LongPressRequest longPressRequest1 { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess1, subscribeId1, longPressRequest1); + EXPECT_TRUE(ret >= 0); + + SessionPtr sess2 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId2 = 0; + LongPressRequest longPressRequest2 { + .fingerCount = 1, + .duration = 900, + }; + ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess2, subscribeId2, longPressRequest2); + EXPECT_TRUE(ret >= 0); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess1, subscribeId1)); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess2, subscribeId2)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_InsertSubScriber_003 + * @tc.desc: Verify subscriber->sess_ != nullptr && sub->id_ != subscriber->id_ && sub->sess_ != subscriber->sess + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_InsertSubScriber_003, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess1 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId1 = 0; + LongPressRequest longPressRequest1 { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess1, subscribeId1, longPressRequest1); + EXPECT_TRUE(ret >= 0); + + SessionPtr sess2 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId2 = 1; + LongPressRequest longPressRequest2 { + .fingerCount = 1, + .duration = 900, + }; + ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess2, subscribeId2, longPressRequest2); + EXPECT_TRUE(ret >= 0); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess1, subscribeId1)); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess2, subscribeId2)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_OnSessionDelete_001 + * @tc.desc: Verify (*iter)->sess_ == sess and subscribers.empty() + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSessionDelete_001, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess1 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId1 = 0; + LongPressRequest longPressRequest1 { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess1, subscribeId1, longPressRequest1); + EXPECT_TRUE(ret >= 0); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSessionDelete(sess1)); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess1, subscribeId1)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_OnSessionDelete_002 + * @tc.desc: Verify (*iter)->sess_ != sess and !subscribers.empty() + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSessionDelete_002, TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess1 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId1 = 0; + LongPressRequest longPressRequest1 { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess1, subscribeId1, longPressRequest1); + EXPECT_TRUE(ret >= 0); + + SessionPtr sess2 = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId2 = 1; + LongPressRequest longPressRequest2 { + .fingerCount = 1, + .duration = 300, + }; + ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess2, subscribeId2, longPressRequest2); + EXPECT_TRUE(ret >= 0); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSessionDelete(sess2)); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSessionDelete(sess1)); + + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess1, subscribeId1)); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess2, subscribeId2)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureDownEvent_001 + * @tc.desc: Verify if (fingerCount > 0 && fingerCount <= TwoFingerGesture::MAX_TOUCH_NUM) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureDownEvent_001, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupZeroFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); + + pointerEvent = SetupSingleFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); + + pointerEvent = SetupDoubleFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); + + pointerEvent = SetupThreeFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureDownEvent_002 + * @tc.desc: Verify if (pressTimeInterval > TWO_FINGERS_TIME_LIMIT) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureDownEvent_002, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupDoubleFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + auto fingerCount = pointerEvent->GetPointerIds().size(); + ASSERT_TRUE(fingerCount == 2); + PointerEvent::PointerItem item; + int32_t pointerId = 1; + bool result = pointerEvent->GetPointerItem(pointerId, item); + ASSERT_TRUE(result); + item.SetDownTime(item.GetDownTime() + 150000); + pointerEvent->UpdatePointerItem(pointerId, item); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_001 + * @tc.desc: Verify if (isAllTimerClosed) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_001, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupThreeFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = true; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureMoveEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_002 + * @tc.desc: Verify if (fingerCount > static_cast(TWO_FINGER)) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_002, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupThreeFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureMoveEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_003 + * @tc.desc: Verify if (pos == std::end(fingerGesture_.touches)) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_003, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupSingleFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); + + PointerEvent::PointerItem item; + int32_t pointerId = 0; + bool result = pointerEvent->GetPointerItem(pointerId, item); + ASSERT_TRUE(result); + item.SetPointerId(item.GetPointerId() + 1); + pointerEvent->UpdatePointerItem(pointerId, item); + + LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureMoveEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_004 + * @tc.desc: Verify if (pos == std::end(fingerGesture_.touches)) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_004, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupSingleFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); + + LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureMoveEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_005 + * @tc.desc: Verify if (moveDistance > TOUCH_MOVE_THRESHOLD) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureMoveEvent_005, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupSingleFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); + + PointerEvent::PointerItem item; + int32_t pointerId = 0; + bool result = pointerEvent->GetPointerItem(pointerId, item); + ASSERT_TRUE(result); + item.SetDisplayX(item.GetDisplayX() + 100); + pointerEvent->UpdatePointerItem(pointerId, item); + + LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureMoveEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_001 + * @tc.desc: Verify if (isAllTimerClosed) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_001, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupSingleFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = true; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureUpEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_002 + * @tc.desc: Verify if (touchEvent->GetPointerIds().size() > static_cast(TWO_FINGER)) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_002, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupThreeFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureUpEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_003 + * @tc.desc: Verify if (touchEvent->GetPointerIds().size() > static_cast(TWO_FINGER)) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_HandleFingerGestureUpEvent_003, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupDoubleFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + LONG_PRESS_EVENT_HANDLER->isAllTimerClosed = false; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureUpEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_001 + * @tc.desc: Verify if (index < 0 || index > static_cast(ONE_FINGER)) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_001, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupThreeFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); + + pointerEvent = SetupZeroFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_002 + * @tc.desc: Verify if (!durationTimers_.empty()) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_002, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto pointerEvent = SetupSingleFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_003 + * @tc.desc: Verify if (!durationTimers_.empty()) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_003, + TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); + EXPECT_TRUE(ret >= 0); + + auto pointerEvent = SetupSingleFingerDownEvent(); + PointerEvent::PointerItem item; + int32_t pointerId = 0; + bool result = pointerEvent->GetPointerItem(pointerId, item); + ASSERT_TRUE(result); + item.SetDownTime(0); + pointerEvent->UpdatePointerItem(pointerId, item); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); + + int64_t downTime = 100000; + item.SetDownTime(downTime); + pointerEvent->UpdatePointerItem(pointerId, item); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); + + downTime = 400000; + item.SetDownTime(downTime); + pointerEvent->UpdatePointerItem(pointerId, item); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); + + ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); + EXPECT_TRUE(ret == RET_OK); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_004 + * @tc.desc: Verify if (tempSubs.size() < static_cast(TWO_FINGER)) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureCancelEvent_004, + TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { .fingerCount = 1, .duration = 300, }; + int32_t subscribeId2 = 0; + LongPressRequest longPressRequest2 { .fingerCount = 1, .duration = 900, }; + int32_t subscribeId3 = 0; + LongPressRequest longPressRequest3 { .fingerCount = 1, .duration = 1500, }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); + EXPECT_TRUE(ret >= 0); + ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId2, longPressRequest2); + EXPECT_TRUE(ret >= 0); + ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId3, longPressRequest3); + EXPECT_TRUE(ret >= 0); + auto pointerEvent = SetupSingleFingerDownEvent(); + PointerEvent::PointerItem item; + int32_t pointerId = 0; + bool result = pointerEvent->GetPointerItem(pointerId, item); + ASSERT_TRUE(result); + item.SetDownTime(0); + pointerEvent->UpdatePointerItem(pointerId, item); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->HandleFingerGestureDownEvent(pointerEvent)); + int64_t downTime = 400000; + item.SetDownTime(downTime); + pointerEvent->UpdatePointerItem(pointerId, item); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); + downTime = 1000000; + item.SetDownTime(downTime); + pointerEvent->UpdatePointerItem(pointerId, item); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); + downTime = 1600000; + item.SetDownTime(downTime); + pointerEvent->UpdatePointerItem(pointerId, item); + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->CheckFingerGestureCancelEvent(pointerEvent)); + ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); + EXPECT_TRUE(ret == RET_OK); + ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId2); + EXPECT_TRUE(ret == RET_OK); + ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId3); + EXPECT_TRUE(ret == RET_OK); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_OnSubscribeLongPressCancelEvent_001 + * @tc.desc: Verify if (it == sessManager_.end()) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSubscribeLongPressCancelEvent_001, + TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + + int32_t fingerCount = 1; + int32_t duration = 300; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressCancelEvent(sess, fingerCount, duration)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_OnSubscribeLongPressCancelEvent_002 + * @tc.desc: Verify if (subscriber->fingerCount_ == fingerCount && subscriber->duration_ == duration) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_OnSubscribeLongPressCancelEvent_002, + TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); + EXPECT_TRUE(ret >= 0); + + int32_t fingerCount = 1; + int32_t duration = 300; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressCancelEvent(sess, fingerCount, duration)); + + fingerCount = 2; + duration = 300; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressCancelEvent(sess, fingerCount, duration)); + + fingerCount = 1; + duration = 900; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressCancelEvent(sess, fingerCount, duration)); + + fingerCount = 2; + duration = 900; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->OnSubscribeLongPressCancelEvent(sess, fingerCount, duration)); + + ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); + EXPECT_TRUE(ret == RET_OK); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_StartFingerGesture_001 + * @tc.desc: Verify if (!CheckFingerGestureAction(fingerCount)) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_StartFingerGesture_001, + TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); + EXPECT_TRUE(ret >= 0); + + int32_t fingerCount = 2; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->StartFingerGesture(fingerCount)); + + ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); + EXPECT_TRUE(ret == RET_OK); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_StartFingerGesture_002 + * @tc.desc: Verify if (!CheckFingerGestureAction(fingerCount)) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_StartFingerGesture_002, + TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + int32_t ret = LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); + EXPECT_TRUE(ret >= 0); + + DisplayInfo displayInfo; + displayInfo.dpi = 320; + displayInfo.width = 1260; + displayInfo.height = 2720; + displayInfo.uniq = "default0"; + auto inputWindowsManager = std::make_shared(); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); + IInputWindowsManager::instance_ = inputWindowsManager; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; + int32_t fingerCount = 1; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->StartFingerGesture(fingerCount)); + + ret = LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); + EXPECT_TRUE(ret == RET_OK); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureAction_001 + * @tc.desc: Verify if (firstFinger.x <= leftLimit || firstFinger.x >= rightLimit || + * firstFinger.y <= topLimit || firstFinger.y >= bottomLimit) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureAction_001, + TestSize.Level1) + { + CALL_TEST_DEBUG; + DisplayInfo displayInfo; + displayInfo.dpi = 320; + displayInfo.width = 1260; + displayInfo.height = 2720; + displayInfo.uniq = "default0"; + auto inputWindowsManager = std::make_shared(); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); + IInputWindowsManager::instance_ = inputWindowsManager; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; + int32_t fingerCount = 1; + bool ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); + EXPECT_EQ(ret, true); + + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 20; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; + ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); + EXPECT_EQ(ret, false); + + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 1250; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; + ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); + EXPECT_EQ(ret, false); + + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 10; + ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); + EXPECT_EQ(ret, false); + + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 2700; + ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); + EXPECT_EQ(ret, false); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureAction_002 + * @tc.desc: Verify if (secondFinger.x <= leftLimit || secondFinger.x >= rightLimit || + * secondFinger.y <= topLimit || secondFinger.y >= bottomLimit) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureAction_002, + TestSize.Level1) + { + CALL_TEST_DEBUG; + DisplayInfo displayInfo; + displayInfo.dpi = 320; + displayInfo.width = 1260; + displayInfo.height = 2720; + displayInfo.uniq = "default0"; + auto inputWindowsManager = std::make_shared(); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); + IInputWindowsManager::instance_ = inputWindowsManager; + int32_t fingerCount = 2; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; + + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 800; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 600; + bool ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); + EXPECT_EQ(ret, true); + + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 10; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 600; + ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); + EXPECT_EQ(ret, false); + + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 1250; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 600; + ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); + EXPECT_EQ(ret, false); + + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 600; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 10; + ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); + EXPECT_EQ(ret, false); + + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 600; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 2710; + ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); + EXPECT_EQ(ret, false); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_CheckFingerGestureAction_003 + * @tc.desc: Verify if (distance < ConvertVPToPX(TWO_FINGERS_DISTANCE_LIMIT)) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_CheckFingerGestureAction_003, + TestSize.Level1) + { + CALL_TEST_DEBUG; + DisplayInfo displayInfo; + displayInfo.dpi = 320; + displayInfo.width = 1260; + displayInfo.height = 2720; + displayInfo.uniq = "default0"; + auto inputWindowsManager = std::make_shared(); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); + IInputWindowsManager::instance_ = inputWindowsManager; + int32_t fingerCount = 2; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].x = 600; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[0].y = 600; + + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].x = 610; + LONG_PRESS_EVENT_HANDLER->fingerGesture_.touches[1].y = 600; + bool ret = LONG_PRESS_EVENT_HANDLER->CheckFingerGestureAction(fingerCount); + EXPECT_EQ(ret, false); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_InitSessionDeleteCallback_001 + * @tc.desc: Verify if (callbackInitialized_) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_InitSessionDeleteCallback_001, + TestSize.Level1) + { + CALL_TEST_DEBUG; + LONG_PRESS_EVENT_HANDLER->callbackInitialized_ = true; + bool ret = LONG_PRESS_EVENT_HANDLER->InitSessionDeleteCallback(); + EXPECT_EQ(ret, true); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_InitSessionDeleteCallback_002 + * @tc.desc: Verify if (callbackInitialized_) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_InitSessionDeleteCallback_002, + TestSize.Level1) + { + CALL_TEST_DEBUG; + LONG_PRESS_EVENT_HANDLER->callbackInitialized_ = false; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->InitSessionDeleteCallback()); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_ConvertVPToPX_001 + * @tc.desc: Verify if (vp <= 0) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_ConvertVPToPX_001, + TestSize.Level1) + { + CALL_TEST_DEBUG; + int32_t vp = -1; + int32_t ret = LONG_PRESS_EVENT_HANDLER->ConvertVPToPX(vp); + ASSERT_EQ(ret, 0); + ret = LONG_PRESS_EVENT_HANDLER->ConvertVPToPX(vp); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_ConvertVPToPX_002 + * @tc.desc: Verify if (dpi <= 0) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_ConvertVPToPX_002, + TestSize.Level1) + { + CALL_TEST_DEBUG; + int32_t vp = 5; + DisplayInfo displayInfo; + displayInfo.id = 1; + displayInfo.x = 2; + displayInfo.y = 3; + displayInfo.width = 4; + displayInfo.height = 5; + displayInfo.dpi = -1; + displayInfo.uniq = "default0"; + auto inputWindowsManager = std::make_shared(); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); + IInputWindowsManager::instance_ = inputWindowsManager; + int32_t ret = LONG_PRESS_EVENT_HANDLER->ConvertVPToPX(vp); + ASSERT_EQ(ret, 0); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_GetBundleName_001 + * @tc.desc: Verify if (userid < 0); + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_GetBundleName_001, + TestSize.Level1) + { + CALL_TEST_DEBUG; + auto inputWindowsManager = std::make_shared(); + int32_t currentUserId = -1; + inputWindowsManager->SetCurrentUser(currentUserId); + IInputWindowsManager::instance_ = inputWindowsManager; + std::string bundleName = "test"; + int32_t windowPid = 0; + int32_t ret = LONG_PRESS_EVENT_HANDLER->GetBundleName(bundleName, windowPid); + ASSERT_EQ(ret, RET_ERR); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_NotifySubscriber_001 + * @tc.desc: Verify if (subscriber->sess_ == nullptr) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_NotifySubscriber_001, + TestSize.Level1) + { + CALL_TEST_DEBUG; + std::shared_ptr subscriber { nullptr }; + int32_t result = 0; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->NotifySubscriber(subscriber, result)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_NotifySubscriber_002 + * @tc.desc: Verify if (windowPid == RET_ERR) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_NotifySubscriber_002, + TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + auto subscriber = std::make_shared(subscribeId, sess, longPressRequest.fingerCount, + longPressRequest.duration); + auto pair = std::make_pair(longPressRequest.fingerCount, longPressRequest.duration); + LONG_PRESS_EVENT_HANDLER->subscriberInfos_[pair].push_back(subscriber); + int32_t result = 0; + UDSServer* udsServer = new UDSServer(); + ASSERT_TRUE(udsServer != nullptr); + InputHandler->udsServer_ = udsServer; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->NotifySubscriber(subscriber, result)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_NotifySubscriber_003 + * @tc.desc: Verify if (GetBundleName(bundleName, windowPid) == RET_ERR) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_NotifySubscriber_003, + TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + auto subscriber = std::make_shared(subscribeId, sess, longPressRequest.fingerCount, + longPressRequest.duration); + auto pair = std::make_pair(longPressRequest.fingerCount, longPressRequest.duration); + LONG_PRESS_EVENT_HANDLER->subscriberInfos_[pair].push_back(subscriber); + int32_t result = 0; + UDSServer* udsServer = new UDSServer(); + ASSERT_TRUE(udsServer != nullptr); + InputHandler->udsServer_ = udsServer; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->NotifySubscriber(subscriber, result)); + } + + /** + * @tc.name: LongPressSubscribeHandlerTest_NotifySubscriber_004 + * @tc.desc: Verify if (GetBundleName(bundleName, windowPid) == RET_ERR) + * @tc.type: Function + * @tc.require: + */ + HWTEST_F(LongPressSubscribeHandlerTest, LongPressSubscribeHandlerTest_NotifySubscriber_004, + TestSize.Level1) + { + CALL_TEST_DEBUG; + SessionPtr sess = std::make_shared("LongPressSubscribeHandlerTest", MODULE_TYPE, UDS_FD, UDS_UID, + UDS_PID); + int32_t subscribeId = 0; + LongPressRequest longPressRequest { + .fingerCount = 1, + .duration = 300, + }; + + WindowInfo windowInfo; + windowInfo.id = 10000; + auto inputWindowsManager = std::make_shared(); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo); + IInputWindowsManager::instance_ = inputWindowsManager; + + auto pointerEvent = SetupSingleFingerDownEvent(); + ASSERT_TRUE(pointerEvent != nullptr); + PointerEvent::PointerItem item; + int32_t pointerId = 0; + bool ret = pointerEvent->GetPointerItem(pointerId, item); + ASSERT_TRUE(ret); + item.SetTargetWindowId(windowInfo.id); + pointerEvent->UpdatePointerItem(pointerId, item); + LONG_PRESS_EVENT_HANDLER->touchEvent_ = pointerEvent; + + auto subscriber = std::make_shared(subscribeId, sess, longPressRequest.fingerCount, + longPressRequest.duration); + auto pair = std::make_pair(longPressRequest.fingerCount, longPressRequest.duration); + LONG_PRESS_EVENT_HANDLER->subscriberInfos_[pair].push_back(subscriber); + int32_t result = 0; + UDSServer* udsServer = new UDSServer(); + ASSERT_TRUE(udsServer != nullptr); + InputHandler->udsServer_ = udsServer; + ASSERT_NO_FATAL_FAILURE(LONG_PRESS_EVENT_HANDLER->NotifySubscriber(subscriber, result)); + } + } // namespace MMI + } // namespace OHOS \ No newline at end of file diff --git a/service/libinput_adapter/src/libinput_adapter.cpp b/service/libinput_adapter/src/libinput_adapter.cpp index 347893ec57ada98ddcad4a4ddb943c4fdd4a86d2..aafc6568e98ce69cb28ad77a78439a71b89ea2d7 100644 --- a/service/libinput_adapter/src/libinput_adapter.cpp +++ b/service/libinput_adapter/src/libinput_adapter.cpp @@ -361,7 +361,8 @@ bool LibinputAdapter::GetIsCaptureMode() InputWindowsManager* inputWindowsManager = static_cast(WIN_MGR.get()); if (inputWindowsManager != nullptr) { - DisplayGroupInfo displayGroupInfo = inputWindowsManager->GetDisplayGroupInfo(); + DisplayGroupInfo displayGroupInfo; + inputWindowsManager->GetDisplayGroupInfo(displayGroupInfo); bool isFloating = false; for (auto &windowInfo : displayGroupInfo.windowsInfo) { if (windowInfo.windowNameType == WINDOW_NAME_TYPE_SCHREENSHOT) { @@ -1360,7 +1361,8 @@ bool LibinputAdapter::IsCursorInCastWindow() if (inputWindowsManager == nullptr) { return false; } - DisplayGroupInfo displayGroupInfo = inputWindowsManager->GetDisplayGroupInfo(); + DisplayGroupInfo displayGroupInfo; + inputWindowsManager->GetDisplayGroupInfo(displayGroupInfo); for (auto &windowInfo : displayGroupInfo.windowsInfo) { if (windowInfo.windowType == CAST_WINDOW_TYPE) { auto mouseInfo = WIN_MGR->GetMouseInfo(); @@ -1972,5 +1974,6 @@ void LibinputAdapter::OnDeviceRemoved(std::string path) OnEventHandler(); } } +///add } // namespace MMI } // namespace OHOS diff --git a/service/message_handle/src/server_msg_handler.cpp b/service/message_handle/src/server_msg_handler.cpp index 0f092e665b77b767e609c7a43624511a6695e508..5cee85b72feb957346f1c517ceafd83e8e2108ae 100644 --- a/service/message_handle/src/server_msg_handler.cpp +++ b/service/message_handle/src/server_msg_handler.cpp @@ -13,1420 +13,1423 @@ * limitations under the License. */ -#include "server_msg_handler.h" - -#include "anr_manager.h" -#include "app_mgr_client.h" -#include "authorization_dialog.h" -#include "authorize_helper.h" -#include "bytrace_adapter.h" -#ifdef OHOS_BUILD_ENABLE_DFX_RADAR -#include "dfx_hisysevent.h" -#endif // OHOS_BUILD_ENABLE_DFX_RADAR -#include "display_event_monitor.h" -#include "event_log_helper.h" -#include "input_device_manager.h" -#include "input_event_handler.h" -#include "i_pointer_drawing_manager.h" -#ifdef OHOS_BUILD_ENABLE_KEY_PRESSED_HANDLER -#include "key_monitor_manager.h" -#endif // OHOS_BUILD_ENABLE_KEY_PRESSED_HANDLER -#ifdef SHORTCUT_KEY_MANAGER_ENABLED -#include "key_shortcut_manager.h" -#endif // SHORTCUT_KEY_MANAGER_ENABLED -#include "long_press_subscriber_handler.h" -#include "libinput_adapter.h" -#include "time_cost_chk.h" -#ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING -#include "touch_drawing_manager.h" -#endif // #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING - -#undef MMI_LOG_DOMAIN -#define MMI_LOG_DOMAIN MMI_LOG_SERVER -#undef MMI_LOG_TAG -#define MMI_LOG_TAG "ServerMsgHandler" - -namespace OHOS { -namespace MMI { -namespace { -#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT -constexpr int32_t SECURITY_COMPONENT_SERVICE_ID = 3050; -#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT -constexpr int32_t SEND_NOTICE_OVERTIME { 5 }; -[[ maybe_unused ]] constexpr int32_t DEFAULT_POINTER_ID { 10000 }; -[[ maybe_unused ]] constexpr int32_t CAST_POINTER_ID { 5000 }; -const std::string PRODUCT_TYPE = system::GetParameter("const.product.devicetype", "unknown"); -const std::string PRODUCT_TYPE_PC = "2in1"; -[[ maybe_unused ]] constexpr int32_t WINDOW_ROTATE { 0 }; -constexpr int32_t COMMON_PERMISSION_CHECK_ERROR { 201 }; -constexpr int32_t CAST_INPUT_DEVICEID { 0xAAAAAAFF }; -constexpr int32_t CAST_SCREEN_DEVICEID { 0xAAAAAAFE }; -constexpr int32_t ANGLE_90 { 90 }; -constexpr int32_t ANGLE_360 { 360 }; -constexpr int32_t ERR_DEVICE_NOT_EXIST { 3900002 }; -constexpr int32_t ERR_NON_INPUT_APPLICATION { 3900003 }; -constexpr int32_t SIMULATE_EVENT_START_ID { 10000 }; -constexpr float MM_TO_INCH { 25.4f }; -constexpr int32_t SCREEN_DIAGONAL_0 { 0 }; -constexpr int32_t SCREEN_DIAGONAL_8 { 8 }; -constexpr int32_t SCREEN_DIAGONAL_18 { 18 }; -constexpr int32_t SCREEN_DIAGONAL_27 { 27 }; -constexpr int32_t SCREEN_DIAGONAL_55 { 55 }; -constexpr float FACTOR_0 { 1.0f }; -constexpr float FACTOR_8 { 0.7f }; -constexpr float FACTOR_18 { 1.0f }; -constexpr float FACTOR_27 { 1.2f }; -constexpr float FACTOR_55 { 1.6f }; -constexpr float FACTOR_MAX { 2.4f }; -} // namespace - -void ServerMsgHandler::Init(UDSServer &udsServer) -{ - udsServer_ = &udsServer; - MsgCallback funs[] = { - {MmiMessageId::DISPLAY_INFO, [this] (SessionPtr sess, NetPacket &pkt) { - return this->OnDisplayInfo(sess, pkt); }}, - {MmiMessageId::WINDOW_INFO, [this] (SessionPtr sess, NetPacket &pkt) { - return this->OnWindowGroupInfo(sess, pkt); }}, - {MmiMessageId::WINDOW_STATE_ERROR_CALLBACK, [this] (SessionPtr sess, NetPacket &pkt) { - return this->RegisterWindowStateErrorCallback(sess, pkt); }}, -#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT - {MmiMessageId::SCINFO_CONFIG, [this] (SessionPtr sess, NetPacket &pkt) { - return this->OnEnhanceConfig(sess, pkt); }}, -#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT - - }; - for (auto &it : funs) { - if (!RegistrationEvent(it)) { - MMI_HILOGW("Failed to register event errCode:%{public}d", EVENT_REG_FAIL); - continue; - } - } - AUTHORIZE_HELPER->Init(clientDeathHandler_); -} - -void ServerMsgHandler::OnMsgHandler(SessionPtr sess, NetPacket& pkt) -{ - CHKPV(sess); - auto id = pkt.GetMsgId(); - TimeCostChk chk("ServerMsgHandler::OnMsgHandler", "overtime 300(us)", MAX_OVER_TIME, id); - BytraceAdapter::StartSocketHandle(static_cast(id)); - auto callback = GetMsgCallback(id); - if (callback == nullptr) { - MMI_HILOGE("Unknown msg id:%{public}d,errCode:%{public}d", id, UNKNOWN_MSG_ID); - return; - } - auto ret = (*callback)(sess, pkt); - BytraceAdapter::StopSocketHandle(); - if (ret < 0) { - MMI_HILOGE("Msg handling failed. id:%{public}d,errCode:%{public}d", id, ret); - } -} - -#ifdef OHOS_BUILD_ENABLE_KEYBOARD -int32_t ServerMsgHandler::OnInjectKeyEvent(const std::shared_ptr keyEvent, int32_t pid, bool isNativeInject) -{ - CALL_DEBUG_ENTER; - CHKPR(keyEvent, ERROR_NULL_POINTER); - LogTracer lt(keyEvent->GetId(), keyEvent->GetEventType(), keyEvent->GetKeyAction()); - if (isNativeInject) { - int32_t checkReturn = NativeInjectCheck(pid); - if (checkReturn != RET_OK) { - return checkReturn; - } - } - keyEvent->SetKeyIntention(KeyItemsTransKeyIntention(keyEvent->GetKeyItems())); - auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); - CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); - inputEventNormalizeHandler->HandleKeyEvent(keyEvent); -#ifdef SHORTCUT_KEY_RULES_ENABLED - KEY_SHORTCUT_MGR->UpdateShortcutConsumed(keyEvent); -#endif // SHORTCUT_KEY_RULES_ENABLED - if (EventLogHelper::IsBetaVersion() && !keyEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) { - MMI_HILOGD("Inject keyCode:%{private}d, action:%{public}d", keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); - } else { - MMI_HILOGD("Inject keyCode:%{private}d, action:%{public}d", keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); - } - return RET_OK; -} - -int32_t ServerMsgHandler::OnGetFunctionKeyState(int32_t funcKey, bool &state) -{ - CALL_INFO_TRACE; - bool hasVirtualKeyboard = false; -#ifdef OHOS_BUILD_ENABLE_VKEYBOARD - hasVirtualKeyboard = INPUT_DEV_MGR->HasVirtualKeyboardDevice(); -#endif // OHOS_BUILD_ENABLE_VKEYBOARD - std::vector input_device; - INPUT_DEV_MGR->GetMultiKeyboardDevice(input_device); - if (input_device.size() == 0 && !hasVirtualKeyboard) { - MMI_HILOGW("No keyboard device is currently available"); - return ERR_DEVICE_NOT_EXIST; - } - const auto &keyEvent = KeyEventHdr->GetKeyEvent(); - CHKPR(keyEvent, ERROR_NULL_POINTER); - state = keyEvent->GetFunctionKey(funcKey); - MMI_HILOGD("Get the function key:%{public}d status as %{public}s", funcKey, state ? "open" : "close"); - return RET_OK; -} - -int32_t ServerMsgHandler::OnSetFunctionKeyState(int32_t pid, int32_t funcKey, bool enable) -{ - CALL_INFO_TRACE; - AppExecFwk::RunningProcessInfo processInfo; - auto appMgrClient = DelayedSingleton::GetInstance(); - CHKPR(appMgrClient, ERROR_NULL_POINTER); - auto begin = std::chrono::high_resolution_clock::now(); - appMgrClient->GetRunningProcessInfoByPid(pid, processInfo); - auto durationMS = std::chrono::duration_cast( - std::chrono::high_resolution_clock::now() - begin).count(); -#ifdef OHOS_BUILD_ENABLE_DFX_RADAR - DfxHisysevent::ReportApiCallTimes(ApiDurationStatistics::Api::GET_RUNNING_PROCESS_INFO_BY_PID, durationMS); -#endif // OHOS_BUILD_ENABLE_DFX_RADAR - if (processInfo.extensionType_ != AppExecFwk::ExtensionAbilityType::INPUTMETHOD) { - MMI_HILOGW("It is prohibited for non-input applications"); - return ERR_NON_INPUT_APPLICATION; - } - bool hasVirtualKeyboard = false; -#ifdef OHOS_BUILD_ENABLE_VKEYBOARD - hasVirtualKeyboard = INPUT_DEV_MGR->HasVirtualKeyboardDevice(); -#endif // OHOS_BUILD_ENABLE_VKEYBOARD - std::vector input_device; - int32_t DeviceId = -1; - INPUT_DEV_MGR->GetMultiKeyboardDevice(input_device); - if (input_device.size() == 0 && !hasVirtualKeyboard) { - MMI_HILOGW("No keyboard device is currently available"); - return ERR_DEVICE_NOT_EXIST; - } - auto keyEvent = KeyEventHdr->GetKeyEvent(); - CHKPR(keyEvent, ERROR_NULL_POINTER); - bool checkState = keyEvent->GetFunctionKey(funcKey); - if (checkState == enable) { - MMI_HILOGE("Current device no need to set up"); - return RET_OK; - } -#ifdef OHOS_BUILD_ENABLE_VKEYBOARD - if (funcKey == KeyEvent::CAPS_LOCK_FUNCTION_KEY) { - // set vkeyboard caps state with separate API. - MMI_HILOGD("Set vkb func state old=%{private}d, new=%{private}d", checkState, enable); - libinput_toggle_caps_key(); - } -#endif // OHOS_BUILD_ENABLE_VKEYBOARD - for (auto it = input_device.begin(); it != input_device.end(); ++it) { - auto device = (*it); - DeviceId = INPUT_DEV_MGR->FindInputDeviceId(device); - if (LibinputAdapter::DeviceLedUpdate(device, funcKey, enable) != RET_OK) { - MMI_HILOGE("Failed to set the keyboard led, device id %{public}d", DeviceId); - } - int32_t state = libinput_get_funckey_state(device, funcKey); - if (state != enable) { - MMI_HILOGE("Failed to enable the function key, device id %{public}d", DeviceId); - } - } - int32_t ret = keyEvent->SetFunctionKey(funcKey, enable); - if (ret != funcKey) { - MMI_HILOGE("Failed to enable the function key"); - return RET_ERR; - } - MMI_HILOGD("Update function key:%{public}d succeed", funcKey); - return RET_OK; -} -#endif // OHOS_BUILD_ENABLE_KEYBOARD - -#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) -int32_t ServerMsgHandler::OnInjectPointerEvent(const std::shared_ptr pointerEvent, int32_t pid, - bool isNativeInject, bool isShell) -{ - CALL_DEBUG_ENTER; - CHKPR(pointerEvent, ERROR_NULL_POINTER); - LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); - if (isNativeInject) { - int32_t checkReturn = NativeInjectCheck(pid); - if (checkReturn != RET_OK) { - return checkReturn; - } - } - return OnInjectPointerEventExt(pointerEvent, isShell); -} - -int32_t ServerMsgHandler::OnInjectTouchPadEvent(const std::shared_ptr pointerEvent, int32_t pid, - const TouchpadCDG &touchpadCDG, bool isNativeInject, bool isShell) -{ - CALL_DEBUG_ENTER; - CHKPR(pointerEvent, ERROR_NULL_POINTER); - LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); - if (isNativeInject) { - int32_t checkReturn = NativeInjectCheck(pid); - if (checkReturn != RET_OK) { - return checkReturn; - } - } - return OnInjectTouchPadEventExt(pointerEvent, touchpadCDG, isShell); -} - -bool ServerMsgHandler::IsNavigationWindowInjectEvent(std::shared_ptr pointerEvent) -{ - return pointerEvent->GetZOrder() > 0; -} - -int32_t ServerMsgHandler::OnInjectTouchPadEventExt(const std::shared_ptr pointerEvent, - const TouchpadCDG &touchpadCDG, bool isShell) -{ - CALL_DEBUG_ENTER; - CHKPR(pointerEvent, ERROR_NULL_POINTER); - EndLogTraceId(pointerEvent->GetId()); - pointerEvent->UpdateId(); - LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); - auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); - CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); - if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) { -#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) - int32_t ret = AccelerateMotionTouchpad(pointerEvent, touchpadCDG); - if (ret != RET_OK) { - MMI_HILOGE("Failed to accelerate motion, error:%{public}d", ret); - return ret; - } - UpdatePointerEvent(pointerEvent); - inputEventNormalizeHandler->HandlePointerEvent(pointerEvent); - CHKPR(pointerEvent, ERROR_NULL_POINTER); - pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY); - if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_HIDE_POINTER)) { - IPointerDrawingManager::GetInstance()->SetMouseDisplayState(false); - } else if (((pointerEvent->GetPointerAction() < PointerEvent::POINTER_ACTION_PULL_DOWN) || - (pointerEvent->GetPointerAction() > PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW)) && - !IPointerDrawingManager::GetInstance()->IsPointerVisible()) { - IPointerDrawingManager::GetInstance()->SetPointerVisible(getpid(), true, 0, false); - } -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH - } else { - MMI_HILOGW("Source types are not Touchpad, source:%{public}d", pointerEvent->GetSourceType()); - } - return SaveTargetWindowId(pointerEvent, isShell); -} - -void ServerMsgHandler::DealGesturePointers(std::shared_ptr pointerEvent) -{ - if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { - return; - } - MMI_HILOGI("Check : current PointerEvent's info :Id=>%{public}d, pointerId=>%{public}d", - pointerEvent->GetId(), pointerEvent->GetPointerId()); - std::shared_ptr touchEvent = WIN_MGR->GetLastPointerEventForGesture(); - if (touchEvent != nullptr) { - std::list listPtItems = touchEvent->GetAllPointerItems(); - for (auto &item : listPtItems) { - MMI_HILOGI("Check : current Item : pointerId=>%{public}d, OriginPointerId=>%{public}d", - item.GetPointerId(), item.GetOriginPointerId()); - if ((item.GetPointerId() % SIMULATE_EVENT_START_ID) != - (pointerEvent->GetPointerId() % SIMULATE_EVENT_START_ID) && item.IsPressed()) { - pointerEvent->AddPointerItem(item); - MMI_HILOGI("Check : add Item : pointerId=>%{public}d, OriginPointerId=>%{public}d", - item.GetPointerId(), item.GetOriginPointerId()); - } - } - } -} - -int32_t ServerMsgHandler::OnInjectPointerEventExt(const std::shared_ptr pointerEvent, bool isShell) -{ - CALL_DEBUG_ENTER; - CHKPR(pointerEvent, ERROR_NULL_POINTER); - EndLogTraceId(pointerEvent->GetId()); - pointerEvent->UpdateId(); - LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); - auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); - CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); - switch (pointerEvent->GetSourceType()) { - case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: { -#ifdef OHOS_BUILD_ENABLE_TOUCH - if (!FixTargetWindowId(pointerEvent, pointerEvent->GetPointerAction(), isShell)) { - return RET_ERR; - } - DealGesturePointers(pointerEvent); - MMI_HILOGI("Check : prepare to send inject pointer event"); - inputEventNormalizeHandler->HandleTouchEvent(pointerEvent); - if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY) && - !(IsCastInject(pointerEvent->GetDeviceId())) && - !IsNavigationWindowInjectEvent(pointerEvent)) { -#ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING - TOUCH_DRAWING_MGR->TouchDrawHandler(pointerEvent); -#endif // #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING - } -#endif // OHOS_BUILD_ENABLE_TOUCH - break; - } - case PointerEvent::SOURCE_TYPE_MOUSE: -#ifdef OHOS_BUILD_ENABLE_JOYSTICK - case PointerEvent::SOURCE_TYPE_JOYSTICK: -#endif // OHOS_BUILD_ENABLE_JOYSTICK - case PointerEvent::SOURCE_TYPE_TOUCHPAD: { -#ifdef OHOS_BUILD_ENABLE_POINTER - int32_t ret = AccelerateMotion(pointerEvent); - if (ret != RET_OK) { - MMI_HILOGE("Failed to accelerate motion, error:%{public}d", ret); - return ret; - } - UpdatePointerEvent(pointerEvent); - inputEventNormalizeHandler->HandlePointerEvent(pointerEvent); - CHKPR(pointerEvent, ERROR_NULL_POINTER); - if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { - break; - } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_HIDE_POINTER)) { - IPointerDrawingManager::GetInstance()->SetMouseDisplayState(false); - } else if (((pointerEvent->GetPointerAction() < PointerEvent::POINTER_ACTION_PULL_DOWN) || - (pointerEvent->GetPointerAction() > PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW)) && - !IPointerDrawingManager::GetInstance()->IsPointerVisible()) { - IPointerDrawingManager::GetInstance()->SetPointerVisible(getpid(), true, 0, false); - } -#endif // OHOS_BUILD_ENABLE_POINTER - break; - } - default: { - MMI_HILOGW("Source type is unknown, source:%{public}d", pointerEvent->GetSourceType()); - break; - } - } - return SaveTargetWindowId(pointerEvent, isShell); -} -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH - -#ifdef OHOS_BUILD_ENABLE_POINTER -float ServerMsgHandler::ScreenFactor(const int32_t diagonalInch) -{ - if (diagonalInch <= SCREEN_DIAGONAL_0) { - return FACTOR_0; - } else if (diagonalInch < SCREEN_DIAGONAL_8) { - return FACTOR_8; - } else if (diagonalInch < SCREEN_DIAGONAL_18) { - return FACTOR_18; - } else if (diagonalInch < SCREEN_DIAGONAL_27) { - return FACTOR_27; - } else if (diagonalInch < SCREEN_DIAGONAL_55) { - return FACTOR_55; - } else { - return FACTOR_MAX; - } -} - -int32_t ServerMsgHandler::AccelerateMotion(std::shared_ptr pointerEvent) -{ - if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT) || - (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE) || - ((pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_MOVE) && - (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_PULL_MOVE) && - (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_BUTTON_DOWN))) { - return RET_OK; - } - PointerEvent::PointerItem pointerItem {}; - if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) { - MMI_HILOGE("Pointer event is corrupted"); - return RET_ERR; - } - CursorPosition cursorPos = WIN_MGR->GetCursorPos(); - if (cursorPos.displayId < 0) { - MMI_HILOGE("No display"); - return RET_ERR; - } - Offset offset { - .dx = pointerItem.GetRawDx(), - .dy = pointerItem.GetRawDy(), - }; - auto displayInfo = WIN_MGR->GetPhysicalDisplay(cursorPos.displayId); - CHKPR(displayInfo, ERROR_NULL_POINTER); -#ifndef OHOS_BUILD_EMULATOR - Direction displayDirection = static_cast(( - ((displayInfo->direction - displayInfo->displayDirection) * ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90); -#ifdef OHOS_BUILD_ENABLE_HARDWARE_CURSOR - if (WIN_MGR->IsSupported()) { - direction = displayInfo->direction; - } -#endif // OHOS_BUILD_ENABLE_HARDWARE_CURSOR - CalculateOffset(displayDirection, offset); -#endif // OHOS_BUILD_EMULATOR - int32_t ret = RET_OK; - if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_DOWN) { - WIN_MGR->UpdateAndAdjustMouseLocation(cursorPos.displayId, cursorPos.cursorPos.x, cursorPos.cursorPos.y); - return RET_OK; - } - if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_TOUCHPAD_POINTER) && - pointerEvent->HasFlag(InputEvent::EVENT_FLAG_VIRTUAL_TOUCHPAD_POINTER)) { - ret = HandleMotionAccelerateTouchpad(&offset, WIN_MGR->GetMouseIsCaptureMode(), - &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, - MouseTransformProcessor::GetTouchpadSpeed(), static_cast(DeviceType::DEVICE_FOLD_PC_VIRT)); - } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_TOUCHPAD_POINTER)) { - ret = HandleMotionAccelerateTouchpad(&offset, WIN_MGR->GetMouseIsCaptureMode(), - &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, - MouseTransformProcessor::GetTouchpadSpeed(), static_cast(DeviceType::DEVICE_PC)); - } else { - uint64_t deltaTime = 0; -#ifdef OHOS_BUILD_MOUSE_REPORTING_RATE - static uint64_t preTime = -1; - uint64_t currentTime = static_cast(pointerEvent->GetActionTime()); - preTime = fmin(preTime, currentTime); - deltaTime = (currentTime - preTime); - preTime = currentTime; -#endif // OHOS_BUILD_MOUSE_REPORTING_RATE - if (displayInfo->ppi != 0) { - int32_t diagonalMm = static_cast(sqrt((displayInfo->physicalWidth * displayInfo->physicalWidth) + - (displayInfo->physicalHeight * displayInfo->physicalHeight))); - int32_t diagonalInch = static_cast(diagonalMm / MM_TO_INCH); - float factor = ScreenFactor(diagonalInch); - ret = HandleMotionDynamicAccelerateMouse(&offset, WIN_MGR->GetMouseIsCaptureMode(), - &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, MouseTransformProcessor::GetPointerSpeed(), - deltaTime, static_cast(displayInfo->ppi), static_cast(factor)); - } else { - ret = HandleMotionAccelerateMouse(&offset, WIN_MGR->GetMouseIsCaptureMode(), - &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, - MouseTransformProcessor::GetPointerSpeed(), static_cast(DeviceType::DEVICE_PC)); - } - } - if (ret != RET_OK) { - MMI_HILOGE("Failed to accelerate pointer motion, error:%{public}d", ret); - return ret; - } - WIN_MGR->UpdateAndAdjustMouseLocation(cursorPos.displayId, cursorPos.cursorPos.x, cursorPos.cursorPos.y); - if (EventLogHelper::IsBetaVersion() && !pointerEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) { - MMI_HILOGD("Cursor move to (x:%.2f, y:%.2f, DisplayId:%d)", - cursorPos.cursorPos.x, cursorPos.cursorPos.y, cursorPos.displayId); - } else { - MMI_HILOGD("Cursor move to (x:%.2f, y:%.2f, DisplayId:%d)", - cursorPos.cursorPos.x, cursorPos.cursorPos.y, cursorPos.displayId); - } - return RET_OK; -} - -int32_t ServerMsgHandler::AccelerateMotionTouchpad(std::shared_ptr pointerEvent, - const TouchpadCDG &touchpadCDG) -{ - PointerEvent::PointerItem pointerItem {}; - if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) { - MMI_HILOGE("Pointer event is corrupted"); - return RET_ERR; - } - CursorPosition cursorPos = WIN_MGR->GetCursorPos(); - if (cursorPos.displayId < 0) { - MMI_HILOGE("No display"); - return RET_ERR; - } - Offset offset { - .dx = pointerItem.GetRawDx(), - .dy = pointerItem.GetRawDy(), - }; - auto displayInfo = WIN_MGR->GetPhysicalDisplay(cursorPos.displayId); - CHKPR(displayInfo, ERROR_NULL_POINTER); -#ifndef OHOS_BUILD_EMULATOR - Direction displayDirection = static_cast(( - ((displayInfo->direction - displayInfo->displayDirection) * ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90); - CalculateOffset(displayDirection, offset); -#endif // OHOS_BUILD_EMULATOR - int32_t ret = RET_OK; - -#ifdef OHOS_BUILD_MOUSE_REPORTING_RATE - MMI_HILOGE("Hidumper before HandleMotionDynamicAccelerateTouchpad"); - static uint64_t preTime = -1; - uint64_t currentTime = static_cast(pointerEvent->GetActionTime()); - preTime = fmin(preTime, currentTime); - uint64_t deltaTime = (currentTime - preTime); - MMI_HILOGE("DeltaTime before HandleMotionDynamicAccelerateTouchpad: %{public}PRId64 ms", deltaTime); - - double displaySize = sqrt(pow(displayInfo->width, 2) + pow(displayInfo->height, 2)); - double touchpadSize = touchpadCDG.size; - double touchpadPPi = touchpadCDG.ppi; - int32_t touchpadSpeed = touchpadCDG.speed; - int32_t frequency = touchpadCDG.frequency; - if (touchpadSize <= 0 || touchpadPPi <= 0 || touchpadSpeed <= 0 || frequency <= 0) { - MMI_HILOGE("touchpadSize, touchpadPPi or touchpadSpeed are invalid, - touchpadSize:%{public}lf, touchpadPPi:%{public}lf, touchpadSpeed:%{public}d, frequency:%{public}d", - touchpadSize, touchpadPPi, touchpadSpeed, frequency); - return RET_ERR; - } - if (pointerEvent->GetPointerAction() == POINTER_ACTION_MOVE) { - ret = HandleMotionDynamicAccelerateTouchpad(&offset, WIN_MGR->GetMouseIsCaptureMode(), &cursorPos.cursorPos.x, - &cursorPos.cursorPos.y, touchpadSpeed, displaySize, touchpadSize, touchpadPPi, frequency); - } - MMI_HILOGE("DeltaTime after HandleMotionDynamicAccelerateTouchpad: %{public}PRId64 ms", deltaTime); - MMI_HILOGE("Hidumper after HandleMotionDynamicAccelerateTouchpad"); - preTime = currentTime; -#else - ret = HandleMotionAccelerateTouchpad(&offset, WIN_MGR->GetMouseIsCaptureMode(), - &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, - MouseTransformProcessor::GetTouchpadSpeed(), static_cast(DeviceType::DEVICE_PC)); -#endif // OHOS_BUILD_MOUSE_REPORTING_RATE - if (ret != RET_OK) { - MMI_HILOGE("Failed to accelerate pointer motion, error:%{public}d", ret); - return ret; - } - WIN_MGR->UpdateAndAdjustMouseLocation(cursorPos.displayId, cursorPos.cursorPos.x, cursorPos.cursorPos.y); - if (EventLogHelper::IsBetaVersion() && !pointerEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) { - MMI_HILOGD("Cursor move to (x:%.2f, y:%.2f, DisplayId:%d)", - cursorPos.cursorPos.x, cursorPos.cursorPos.y, cursorPos.displayId); - } else { - MMI_HILOGD("Cursor move to (x:%.2f, y:%.2f, DisplayId:%d)", - cursorPos.cursorPos.x, cursorPos.cursorPos.y, cursorPos.displayId); - } - return RET_OK; -} - -void ServerMsgHandler::CalculateOffset(Direction direction, Offset &offset) -{ - std::negate neg; - if (direction == DIRECTION90) { - double tmp = offset.dx; - offset.dx = offset.dy; - offset.dy = neg(tmp); - } else if (direction == DIRECTION180) { - offset.dx = neg(offset.dx); - offset.dy = neg(offset.dy); - } else if (direction == DIRECTION270) { - double tmp = offset.dx; - offset.dx = neg(offset.dy); - offset.dy = tmp; - } -} -#endif // OHOS_BUILD_ENABLE_POINTER - -#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) -void ServerMsgHandler::UpdatePointerEvent(std::shared_ptr pointerEvent) -{ - if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT) || - (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE)) { - return; - } - PointerEvent::PointerItem pointerItem {}; - if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) { - MMI_HILOGE("Pointer event is corrupted"); - return; - } - auto mouseInfo = WIN_MGR->GetMouseInfo(); - pointerItem.SetDisplayX(mouseInfo.physicalX); - pointerItem.SetDisplayY(mouseInfo.physicalY); - pointerEvent->UpdatePointerItem(pointerEvent->GetPointerId(), pointerItem); - pointerEvent->SetTargetDisplayId(mouseInfo.displayId); -} - -int32_t ServerMsgHandler::SaveTargetWindowId(std::shared_ptr pointerEvent, bool isShell) -{ - CHKPR(pointerEvent, ERROR_NULL_POINTER); - if ((pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && - (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN || - pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_HOVER_ENTER)) { - int32_t pointerId = pointerEvent->GetPointerId(); - PointerEvent::PointerItem pointerItem; - if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) { - MMI_HILOGE("Can't find pointer item, pointer:%{public}d", pointerId); - return RET_ERR; - } - int32_t targetWindowId = pointerEvent->GetTargetWindowId(); - if (isShell) { - shellTargetWindowIds_[pointerId] = targetWindowId; - } else if (IsCastInject(pointerEvent->GetDeviceId()) && (pointerEvent->GetZOrder() > 0)) { - castTargetWindowIds_[pointerId] = targetWindowId; - } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { - accessTargetWindowIds_[pointerId] = targetWindowId; - } else { - nativeTargetWindowIds_[pointerId] = targetWindowId; - } - } - if ((pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && - (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_UP || - pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_HOVER_EXIT)) { - int32_t pointerId = pointerEvent->GetPointerId(); - if (isShell) { - shellTargetWindowIds_.erase(pointerId); - } else if (IsCastInject(pointerEvent->GetDeviceId()) && (pointerEvent->GetZOrder() > 0)) { - castTargetWindowIds_.erase(pointerId); - } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { - accessTargetWindowIds_.erase(pointerId); - } else { - nativeTargetWindowIds_.erase(pointerId); - } - } - return RET_OK; -} -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH - -#ifdef OHOS_BUILD_ENABLE_TOUCH -bool ServerMsgHandler::FixTargetWindowId(std::shared_ptr pointerEvent, - int32_t action, bool isShell) -{ - int32_t targetWindowId = -1; - int32_t pointerId = pointerEvent->GetPointerId(); - PointerEvent::PointerItem pointerItem; - if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) { - MMI_HILOGE("Can't find pointer item, pointer:%{public}d", pointerId); - return false; - } - if (isShell) { - auto iter = shellTargetWindowIds_.find(pointerEvent->GetPointerId()); - if (iter != shellTargetWindowIds_.end()) { - targetWindowId = iter->second; - } - } else if ((IsCastInject(pointerEvent->GetDeviceId())) && (pointerEvent->GetZOrder() > 0)) { - pointerEvent->RemovePointerItem(pointerId); - pointerId += CAST_POINTER_ID; - pointerItem.SetPointerId(pointerId); - pointerEvent->UpdatePointerItem(pointerId, pointerItem); - pointerEvent->SetPointerId(pointerId); - auto iter = castTargetWindowIds_.find(pointerEvent->GetPointerId()); - if (iter != castTargetWindowIds_.end()) { - targetWindowId = iter->second; - } - } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { - auto iter = accessTargetWindowIds_.find(pointerEvent->GetPointerId()); - if (iter != accessTargetWindowIds_.end()) { - targetWindowId = iter->second; - } - } else { - pointerEvent->RemovePointerItem(pointerId); - pointerId += DEFAULT_POINTER_ID; - pointerItem.SetPointerId(pointerId); - pointerEvent->UpdatePointerItem(pointerId, pointerItem); - pointerEvent->SetPointerId(pointerId); - auto iter = nativeTargetWindowIds_.find(pointerEvent->GetPointerId()); - if (iter != nativeTargetWindowIds_.end()) { - targetWindowId = iter->second; - } - } - MMI_HILOGD("TargetWindowId:%{public}d %{public}d", pointerEvent->GetTargetWindowId(), targetWindowId); - return UpdateTouchEvent(pointerEvent, action, targetWindowId); -} - -bool ServerMsgHandler::UpdateTouchEvent(std::shared_ptr pointerEvent, - int32_t action, int32_t targetWindowId) -{ - int32_t pointerId = pointerEvent->GetPointerId(); - PointerEvent::PointerItem pointerItem; - if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) { - MMI_HILOGE("Can't find pointer item, pointer:%{public}d", pointerId); - return false; - } - if (action == PointerEvent::POINTER_ACTION_HOVER_ENTER || - action == PointerEvent::POINTER_ACTION_DOWN || targetWindowId < 0) { - MMI_HILOGD("Down event or targetWindowId less 0 is not need fix window id"); - return true; - } - auto pointerIds = pointerEvent->GetPointerIds(); - if (pointerIds.empty()) { - MMI_HILOGE("GetPointerIds is empty"); - return false; - } - - pointerEvent->SetTargetWindowId(targetWindowId); - pointerItem.SetTargetWindowId(targetWindowId); - pointerEvent->UpdatePointerItem(pointerId, pointerItem); - return true; -} -#endif // OHOS_BUILD_ENABLE_TOUCH - -int32_t ServerMsgHandler::OnUiExtentionWindowInfo(NetPacket &pkt, WindowInfo& info) -{ - uint32_t num = 0; - pkt >> num; - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read display info failed"); - return RET_ERR; - } - for (uint32_t i = 0; i < num; i++) { - WindowInfo extensionInfo; - pkt >> extensionInfo.id >> extensionInfo.pid >> extensionInfo.uid >> extensionInfo.area - >> extensionInfo.defaultHotAreas >> extensionInfo.pointerHotAreas >> extensionInfo.agentWindowId - >> extensionInfo.flags >> extensionInfo.action >> extensionInfo.displayId >> extensionInfo.groupId - >> extensionInfo.zOrder >> extensionInfo.pointerChangeAreas >> extensionInfo.transform - >> extensionInfo.windowInputType >> extensionInfo.privacyMode >> extensionInfo.windowType - >> extensionInfo.privacyUIFlag >> extensionInfo.rectChangeBySystem - >> extensionInfo.isSkipSelfWhenShowOnVirtualScreen >> extensionInfo.windowNameType; - info.uiExtentionWindowInfo.push_back(extensionInfo); - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read extention window info failed"); - return RET_ERR; - } - } - return RET_OK; -} - -int32_t ServerMsgHandler::ReadDisplayInfo(NetPacket &pkt, DisplayGroupInfo &displayGroupInfo) -{ - uint32_t num = 0; - pkt >> num; - for (uint32_t i = 0; i < num; i++) { - DisplayInfo info; - pkt >> info.id >> info.x >> info.y >> info.width >> info.height >> info.dpi >> info.name - >> info.uniq >> info.direction >> info.displayDirection >> info.displayMode >> info.transform >> info.ppi - >> info.offsetX >> info.offsetY >> info.isCurrentOffScreenRendering >> info.screenRealWidth - >> info.screenRealHeight >> info.screenRealPPI >> info.screenRealDPI >> info.screenCombination - >> info.validWidth >> info.validHeight >> info.fixedDirection - >> info.physicalWidth >> info.physicalHeight >> info.scalePercent >> info.expandHeight - >> info.oneHandX >> info.oneHandY >> info.uniqueId; -#ifdef OHOS_BUILD_ENABLE_VKEYBOARD - pkt >> info.pointerActiveWidth >> info.pointerActiveHeight; -#endif // OHOS_BUILD_ENABLE_VKEYBOARD - pkt >> info.groupId; - if (PRODUCT_TYPE != PRODUCT_TYPE_PC) { - info.uniq = "default" + std::to_string(info.id); - } - displayGroupInfo.displaysInfo.push_back(info); - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read display info failed"); - return RET_ERR; - } - } - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read display info failed"); - return RET_ERR; - } - return RET_OK; -} - -bool ServerMsgHandler::IsCastInject(int32_t deviceid) -{ - return (deviceid == CAST_INPUT_DEVICEID || deviceid == CAST_SCREEN_DEVICEID); -} - -int32_t ServerMsgHandler::OnDisplayInfo(SessionPtr sess, NetPacket &pkt) -{ - CALL_DEBUG_ENTER; - CHKPR(sess, ERROR_NULL_POINTER); - int32_t tokenType = sess->GetTokenType(); - if (tokenType != TokenType::TOKEN_NATIVE && tokenType != TokenType::TOKEN_SHELL && - tokenType !=TokenType::TOKEN_SYSTEM_HAP) { - MMI_HILOGW("Not native or systemapp skip, pid:%{public}d tokenType:%{public}d", sess->GetPid(), tokenType); - return RET_ERR; - } - DisplayGroupInfo displayGroupInfo; - pkt >> displayGroupInfo.groupId >> displayGroupInfo.isMainGroup >> displayGroupInfo.width >> - displayGroupInfo.height >> displayGroupInfo.focusWindowId >> displayGroupInfo.currentUserId; - uint32_t num = 0; - pkt >> num; - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read display info failed"); - return RET_ERR; - } - for (uint32_t i = 0; i < num; i++) { - WindowInfo info; - int32_t byteCount = 0; - pkt >> info.id >> info.pid >> info.uid >> info.area >> info.defaultHotAreas - >> info.pointerHotAreas >> info.agentWindowId >> info.flags >> info.action - >> info.displayId >> info.groupId >> info.zOrder >> info.pointerChangeAreas >> info.transform - >> info.windowInputType >> info.privacyMode >> info.windowType - >> info.isSkipSelfWhenShowOnVirtualScreen >> info.windowNameType >> byteCount; - - OnUiExtentionWindowInfo(pkt, info); - pkt >> info.rectChangeBySystem; - displayGroupInfo.windowsInfo.push_back(info); - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read display info failed"); - return RET_ERR; - } - } - if (ReadDisplayInfo(pkt, displayGroupInfo) != RET_OK) { - return RET_ERR; - } - WIN_MGR->UpdateDisplayInfoExtIfNeed(displayGroupInfo, true); - return RET_OK; -} - -int32_t ServerMsgHandler::OnWindowGroupInfo(SessionPtr sess, NetPacket &pkt) -{ - CALL_DEBUG_ENTER; - CHKPR(sess, ERROR_NULL_POINTER); - int32_t tokenType = sess->GetTokenType(); - if (tokenType != TokenType::TOKEN_NATIVE && tokenType != TokenType::TOKEN_SHELL && - tokenType !=TokenType::TOKEN_SYSTEM_HAP) { - MMI_HILOGW("Not native or systemapp skip, pid:%{public}d tokenType:%{public}d", sess->GetPid(), tokenType); - return RET_ERR; - } - WindowGroupInfo windowGroupInfo; - pkt >> windowGroupInfo.focusWindowId >> windowGroupInfo.displayId; - uint32_t num = 0; - pkt >> num; - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read window group info failed"); - return RET_ERR; - } - for (uint32_t i = 0; i < num; i++) { - WindowInfo info; - pkt >> info.id >> info.pid >> info.uid >> info.area >> info.defaultHotAreas - >> info.pointerHotAreas >> info.agentWindowId >> info.flags >> info.action - >> info.displayId >> info.groupId >> info.zOrder >> info.pointerChangeAreas >> info.transform - >> info.windowInputType >> info.privacyMode >> info.windowType >> info.isSkipSelfWhenShowOnVirtualScreen - >> info.windowNameType; - OnUiExtentionWindowInfo(pkt, info); - pkt >> info.rectChangeBySystem; - windowGroupInfo.windowsInfo.push_back(info); - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read display info failed"); - return RET_ERR; - } - } - WIN_MGR->UpdateWindowInfo(windowGroupInfo); - return RET_OK; -} - -int32_t ServerMsgHandler::RegisterWindowStateErrorCallback(SessionPtr sess, NetPacket &pkt) -{ - CALL_DEBUG_ENTER; - CHKPR(sess, ERROR_NULL_POINTER); - int32_t tokenType = sess->GetTokenType(); - if (tokenType != TokenType::TOKEN_NATIVE && tokenType != TokenType::TOKEN_SHELL && - tokenType !=TokenType::TOKEN_SYSTEM_HAP) { - MMI_HILOGW("Not native or systemapp skip, pid:%{public}d tokenType:%{public}d", sess->GetPid(), tokenType); - return RET_ERR; - } - int32_t pid = sess->GetPid(); - WIN_MGR->SetWindowStateNotifyPid(pid); - MMI_HILOGI("The pid:%{public}d", pid); - return RET_OK; -} - -#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT -int32_t ServerMsgHandler::OnEnhanceConfig(SessionPtr sess, NetPacket &pkt) -{ - CHKPR(sess, ERROR_NULL_POINTER); - int32_t userId = sess->GetUid(); - if (userId != SECURITY_COMPONENT_SERVICE_ID) { - MMI_HILOGE("Session is not security component service"); - return RET_ERR; - } - uint32_t num = 0; - pkt >> num; - uint8_t cfg[num]; - for (uint32_t i = 0; i < num; i++) { - pkt >> cfg[i]; - } - - if (pkt.ChkRWError()) { - MMI_HILOGE("Packet read scinfo config failed"); - return RET_ERR; - } - int32_t result = Security::SecurityComponent::SecCompEnhanceKit::SetEnhanceCfg(cfg, num); - if (result != 0) { - return RET_ERR; - } - return RET_OK; -} -#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT -#if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) -int32_t ServerMsgHandler::OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, - HandleEventType eventType, int32_t priority, uint32_t deviceTags) -{ - CHKPR(sess, ERROR_NULL_POINTER); - MMI_HILOGD("The handlerType:%{public}d", handlerType); -#ifdef OHOS_BUILD_ENABLE_INTERCEPTOR - if (handlerType == InputHandlerType::INTERCEPTOR) { - auto interceptorHandler = InputHandler->GetInterceptorHandler(); - CHKPR(interceptorHandler, ERROR_NULL_POINTER); - return interceptorHandler->AddInputHandler(handlerType, eventType, priority, deviceTags, sess); - } -#endif // OHOS_BUILD_ENABLE_INTERCEPTOR -#ifdef OHOS_BUILD_ENABLE_MONITOR - if (handlerType == InputHandlerType::MONITOR) { - auto monitorHandler = InputHandler->GetMonitorHandler(); - CHKPR(monitorHandler, ERROR_NULL_POINTER); - return monitorHandler->AddInputHandler(handlerType, eventType, sess); - } -#endif // OHOS_BUILD_ENABLE_MONITOR - return RET_OK; -} - -int32_t ServerMsgHandler::OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, - HandleEventType eventType, int32_t priority, uint32_t deviceTags) -{ - CHKPR(sess, ERROR_NULL_POINTER); - MMI_HILOGD("OnRemoveInputHandler handlerType:%{public}d eventType:%{public}u", handlerType, eventType); -#ifdef OHOS_BUILD_ENABLE_INTERCEPTOR - if (handlerType == InputHandlerType::INTERCEPTOR) { - auto interceptorHandler = InputHandler->GetInterceptorHandler(); - CHKPR(interceptorHandler, ERROR_NULL_POINTER); - interceptorHandler->RemoveInputHandler(handlerType, eventType, priority, deviceTags, sess); - } -#endif // OHOS_BUILD_ENABLE_INTERCEPTOR -#ifdef OHOS_BUILD_ENABLE_MONITOR - if (handlerType == InputHandlerType::MONITOR) { - auto monitorHandler = InputHandler->GetMonitorHandler(); - CHKPR(monitorHandler, ERROR_NULL_POINTER); - monitorHandler->RemoveInputHandler(handlerType, eventType, sess); - ANRMgr->RemoveTimersByType(sess, ANR_MONITOR); - } -#endif // OHOS_BUILD_ENABLE_MONITOR - return RET_OK; -} - -#endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR - -int32_t ServerMsgHandler::OnAddGestureMonitor(SessionPtr sess, InputHandlerType handlerType, - HandleEventType eventType, TouchGestureType gestureType, int32_t fingers) -{ -#ifdef OHOS_BUILD_ENABLE_MONITOR - if (handlerType == InputHandlerType::MONITOR) { - auto monitorHandler = InputHandler->GetMonitorHandler(); - CHKPR(monitorHandler, ERROR_NULL_POINTER); - return monitorHandler->AddInputHandler(handlerType, eventType, sess, gestureType, fingers); - } -#endif // OHOS_BUILD_ENABLE_MONITOR - return RET_OK; -} - -int32_t ServerMsgHandler::OnRemoveGestureMonitor(SessionPtr sess, InputHandlerType handlerType, - HandleEventType eventType, TouchGestureType gestureType, int32_t fingers) -{ -#ifdef OHOS_BUILD_ENABLE_MONITOR - if (handlerType == InputHandlerType::MONITOR) { - CHKPR(sess, ERROR_NULL_POINTER); - auto monitorHandler = InputHandler->GetMonitorHandler(); - CHKPR(monitorHandler, ERROR_NULL_POINTER); - monitorHandler->RemoveInputHandler(handlerType, eventType, sess, gestureType, fingers); - } -#endif // OHOS_BUILD_ENABLE_MONITOR - return RET_OK; -} - -#ifdef OHOS_BUILD_ENABLE_MONITOR -int32_t ServerMsgHandler::OnMarkConsumed(SessionPtr sess, int32_t eventId) -{ - CHKPR(sess, ERROR_NULL_POINTER); - auto monitorHandler = InputHandler->GetMonitorHandler(); - CHKPR(monitorHandler, ERROR_NULL_POINTER); - monitorHandler->MarkConsumed(eventId, sess); - return RET_OK; -} -#endif // OHOS_BUILD_ENABLE_MONITOR - -#if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) -int32_t ServerMsgHandler::OnMoveMouse(int32_t offsetX, int32_t offsetY) -{ - CALL_DEBUG_ENTER; - if (MouseEventHdr->NormalizeMoveMouse(offsetX, offsetY)) { - auto pointerEvent = MouseEventHdr->GetPointerEvent(); - CHKPR(pointerEvent, ERROR_NULL_POINTER); - auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); - CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); - inputEventNormalizeHandler->HandlePointerEvent(pointerEvent); - MMI_HILOGD("Mouse movement message processed successfully"); - } - return RET_OK; -} -#endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING - -#ifdef OHOS_BUILD_ENABLE_KEYBOARD -int32_t ServerMsgHandler::OnSubscribeKeyEvent(IUdsServer *server, int32_t pid, - int32_t subscribeId, const std::shared_ptr option) -{ - CALL_DEBUG_ENTER; - CHKPR(server, ERROR_NULL_POINTER); - auto sess = server->GetSessionByPid(pid); - CHKPR(sess, ERROR_NULL_POINTER); - auto subscriberHandler = InputHandler->GetSubscriberHandler(); - CHKPR(subscriberHandler, ERROR_NULL_POINTER); - return subscriberHandler->SubscribeKeyEvent(sess, subscribeId, option); -} - -int32_t ServerMsgHandler::OnUnsubscribeKeyEvent(IUdsServer *server, int32_t pid, int32_t subscribeId) -{ - CALL_DEBUG_ENTER; - CHKPR(server, ERROR_NULL_POINTER); - auto sess = server->GetSessionByPid(pid); - CHKPR(sess, ERROR_NULL_POINTER); - auto subscriberHandler = InputHandler->GetSubscriberHandler(); - CHKPR(subscriberHandler, ERROR_NULL_POINTER); - return subscriberHandler->UnsubscribeKeyEvent(sess, subscribeId); -} - -int32_t ServerMsgHandler::OnSubscribeHotkey(IUdsServer *server, int32_t pid, - int32_t subscribeId, const std::shared_ptr option) -{ -#ifdef SHORTCUT_KEY_MANAGER_ENABLED - CALL_DEBUG_ENTER; - CHKPR(server, ERROR_NULL_POINTER); - auto sess = server->GetSessionByPid(pid); - CHKPR(sess, ERROR_NULL_POINTER); - auto subscriberHandler = InputHandler->GetSubscriberHandler(); - CHKPR(subscriberHandler, ERROR_NULL_POINTER); - return subscriberHandler->SubscribeHotkey(sess, subscribeId, option); -#else - MMI_HILOGI("OnSubscribeHotkey function does not support"); - return ERROR_UNSUPPORT; -#endif // SHORTCUT_KEY_MANAGER_ENABLED -} - -int32_t ServerMsgHandler::OnUnsubscribeHotkey(IUdsServer *server, int32_t pid, int32_t subscribeId) -{ -#ifdef SHORTCUT_KEY_MANAGER_ENABLED - CALL_DEBUG_ENTER; - CHKPR(server, ERROR_NULL_POINTER); - auto sess = server->GetSessionByPid(pid); - CHKPR(sess, ERROR_NULL_POINTER); - auto subscriberHandler = InputHandler->GetSubscriberHandler(); - CHKPR(subscriberHandler, ERROR_NULL_POINTER); - return subscriberHandler->UnsubscribeHotkey(sess, subscribeId); -#else - MMI_HILOGI("OnUnsubscribeHotkey function does not support"); - return ERROR_UNSUPPORT; -#endif // SHORTCUT_KEY_MANAGER_ENABLED -} -#endif // OHOS_BUILD_ENABLE_KEYBOARD - -#ifdef OHOS_BUILD_ENABLE_KEY_PRESSED_HANDLER -int32_t ServerMsgHandler::SubscribeKeyMonitor(int32_t session, const KeyMonitorOption &keyOption) -{ - if ((PRODUCT_TYPE != "phone") && (PRODUCT_TYPE != "tablet")) { - MMI_HILOGW("Does not support subscription of key monitor on %{public}s", PRODUCT_TYPE.c_str()); - return -CAPABILITY_NOT_SUPPORTED; - } - KeyMonitorManager::Monitor monitor { - .session_ = session, - .key_ = keyOption.GetKey(), - .action_ = keyOption.GetAction(), - .isRepeat_ = keyOption.IsRepeat(), - }; - return KEY_MONITOR_MGR->AddMonitor(monitor); -} - -int32_t ServerMsgHandler::UnsubscribeKeyMonitor(int32_t session, const KeyMonitorOption &keyOption) -{ - if ((PRODUCT_TYPE != "phone") && (PRODUCT_TYPE != "tablet")) { - MMI_HILOGW("Does not support subscription of key monitor on %{public}s", PRODUCT_TYPE.c_str()); - return -CAPABILITY_NOT_SUPPORTED; - } - KeyMonitorManager::Monitor monitor { - .session_ = session, - .key_ = keyOption.GetKey(), - .action_ = keyOption.GetAction(), - .isRepeat_ = keyOption.IsRepeat(), - }; - KEY_MONITOR_MGR->RemoveMonitor(monitor); - return RET_OK; -} -#endif // OHOS_BUILD_ENABLE_KEY_PRESSED_HANDLER - -#ifdef OHOS_BUILD_ENABLE_SWITCH -int32_t ServerMsgHandler::OnSubscribeSwitchEvent( - IUdsServer *server, int32_t pid, int32_t subscribeId, int32_t switchType) -{ - CALL_DEBUG_ENTER; - CHKPR(server, ERROR_NULL_POINTER); - auto sess = server->GetSessionByPid(pid); - CHKPR(sess, ERROR_NULL_POINTER); - auto subscriberHandler = InputHandler->GetSwitchSubscriberHandler(); - CHKPR(subscriberHandler, ERROR_NULL_POINTER); - return subscriberHandler->SubscribeSwitchEvent(sess, subscribeId, switchType); -} - -int32_t ServerMsgHandler::OnUnsubscribeSwitchEvent(IUdsServer *server, int32_t pid, int32_t subscribeId) -{ - CALL_DEBUG_ENTER; - CHKPR(server, ERROR_NULL_POINTER); - auto sess = server->GetSessionByPid(pid); - CHKPR(sess, ERROR_NULL_POINTER); - auto subscriberHandler = InputHandler->GetSwitchSubscriberHandler(); - CHKPR(subscriberHandler, ERROR_NULL_POINTER); - return subscriberHandler->UnsubscribeSwitchEvent(sess, subscribeId); -} - -int32_t ServerMsgHandler::OnQuerySwitchStatus(int32_t switchType, int32_t& state) -{ - CALL_DEBUG_ENTER; - auto subscriberHandler = InputHandler->GetSwitchSubscriberHandler(); - CHKPR(subscriberHandler, ERROR_NULL_POINTER); - return subscriberHandler->QuerySwitchStatus(switchType, state); -} -#endif // OHOS_BUILD_ENABLE_SWITCH - -int32_t ServerMsgHandler::OnSubscribeLongPressEvent(IUdsServer *server, int32_t pid, int32_t subscribeId, - const LongPressRequest &longPressRequest) -{ - CALL_DEBUG_ENTER; - CHKPR(server, ERROR_NULL_POINTER); - auto sess = server->GetSessionByPid(pid); - CHKPR(sess, ERROR_NULL_POINTER); - return LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); -} - -int32_t ServerMsgHandler::OnUnsubscribeLongPressEvent(IUdsServer *server, int32_t pid, int32_t subscribeId) -{ - CALL_DEBUG_ENTER; - CHKPR(server, ERROR_NULL_POINTER); - auto sess = server->GetSessionByPid(pid); - CHKPR(sess, ERROR_NULL_POINTER); - return LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); -} - -#if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD) -int32_t ServerMsgHandler::AddInputEventFilter(sptr filter, - int32_t filterId, int32_t priority, uint32_t deviceTags, int32_t clientPid) -{ - auto filterHandler = InputHandler->GetFilterHandler(); - CHKPR(filterHandler, ERROR_NULL_POINTER); - return filterHandler->AddInputEventFilter(filter, filterId, priority, deviceTags, clientPid); -} - -int32_t ServerMsgHandler::RemoveInputEventFilter(int32_t clientPid, int32_t filterId) -{ - auto filterHandler = InputHandler->GetFilterHandler(); - CHKPR(filterHandler, ERROR_NULL_POINTER); - return filterHandler->RemoveInputEventFilter(clientPid, filterId); -} -#endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH || OHOS_BUILD_ENABLE_KEYBOARD - -#ifdef OHOS_BUILD_ENABLE_KEYBOARD -int32_t ServerMsgHandler::SetShieldStatus(int32_t shieldMode, bool isShield) -{ - return KeyEventHdr->SetShieldStatus(shieldMode, isShield); -} - -int32_t ServerMsgHandler::GetShieldStatus(int32_t shieldMode, bool &isShield) -{ - return KeyEventHdr->GetShieldStatus(shieldMode, isShield); -} -#endif // OHOS_BUILD_ENABLE_KEYBOARD - -void ServerMsgHandler::LaunchAbility() -{ - CALL_DEBUG_ENTER; -#ifndef OHOS_BUILD_ENABLE_WATCH - AUTH_DIALOG.ConnectSystemUi(); -#endif // OHOS_BUILD_ENABLE_WATCH -} - -int32_t ServerMsgHandler::OnAuthorize(bool isAuthorize) -{ - CALL_DEBUG_ENTER; - if (isAuthorize) { - auto state = AUTHORIZE_HELPER->GetAuthorizeState(); - int32_t authorPid = AUTHORIZE_HELPER->GetAuthorizePid(); - MMI_HILOGE("OnAuthorize not has authorizing s:%{public}d, authPid:%{public}d", - state, authorPid); - if (state == AuthorizeState::STATE_UNAUTHORIZE) { - MMI_HILOGE("Current not has authorizing"); - return ERR_OK; - } - if (state == AuthorizeState::STATE_UNAUTHORIZE) { - MMI_HILOGE("The injection permission has been granted. authPid:%{public}d ", authorPid); - return ERR_OK; - } - InjectNoticeInfo noticeInfo; - noticeInfo.pid = authorPid; - AddInjectNotice(noticeInfo); - auto result = AUTHORIZE_HELPER->AddAuthorizeProcess(authorPid, [&] (int32_t pid) { - CloseInjectNotice(pid); - }); - if (result != RET_OK) { - MMI_HILOGI("Authorize process failed, pid:%{public}d", authorPid); - } - MMI_HILOGD("Agree to apply injection,pid:%{public}d", authorPid); - return ERR_OK; - } - - auto state = AUTHORIZE_HELPER->GetAuthorizeState(); - int32_t curAuthPid = AUTHORIZE_HELPER->GetAuthorizePid(); - MMI_HILOGD("Reject application injection,s:%{public}d, authPid:%{public}d", - state, curAuthPid); - if (state != AuthorizeState::STATE_UNAUTHORIZE) { - MMI_HILOGI("Cancel injection right,pid:%{public}d", curAuthPid); - AUTHORIZE_HELPER->CancelAuthorize(curAuthPid); - if (state == AuthorizeState::STATE_SELECTION_AUTHORIZE) { - AUTH_DIALOG.CloseDialog(); - } else { - CloseInjectNotice(AUTHORIZE_HELPER->GetAuthorizePid()); - } - } - return ERR_OK; -} - -int32_t ServerMsgHandler::OnCancelInjection(int32_t callPid) -{ - CALL_DEBUG_ENTER; - auto state = AUTHORIZE_HELPER->GetAuthorizeState(); - int32_t curAuthPid = AUTHORIZE_HELPER->GetAuthorizePid(); - MMI_HILOGD("Cancel application injection,s:%{public}d, authPid:%{public}d", - state, curAuthPid); - if (state != AuthorizeState::STATE_UNAUTHORIZE) { - if (callPid != curAuthPid) { - MMI_HILOGW("Authorized pid not callPid"); - return COMMON_PERMISSION_CHECK_ERROR; - } - AUTHORIZE_HELPER->CancelAuthorize(curAuthPid); - if (state == AuthorizeState::STATE_SELECTION_AUTHORIZE) { - AUTH_DIALOG.CloseDialog(); - } else { - CloseInjectNotice(AUTHORIZE_HELPER->GetAuthorizePid()); - } - } - return ERR_OK; -} - -void ServerMsgHandler::SetWindowInfo(int32_t infoId, WindowInfo &info) -{ - CALL_DEBUG_ENTER; - if (transparentWins_.find(infoId) == transparentWins_.end()) { - MMI_HILOGE("The infoId is Invalid, infoId:%{public}d", infoId); - return; - } - info.pixelMap = transparentWins_[infoId].get(); -} - -int32_t ServerMsgHandler::SetPixelMapData(int32_t infoId, void *pixelMap) __attribute__((no_sanitize("cfi"))) -{ - CALL_DEBUG_ENTER; - if (infoId < 0 || pixelMap == nullptr) { - MMI_HILOGE("The infoId is invalid or pixelMap is nullptr"); - return ERR_INVALID_VALUE; - } - - WIN_MGR->SetPixelMapData(infoId, pixelMap); - return RET_OK; -} - -bool ServerMsgHandler::InitInjectNoticeSource() -{ - CALL_DEBUG_ENTER; - MMI_HILOGD("Init InjectNoticeSource enter"); - if (injectNotice_ == nullptr) { - injectNotice_ = std::make_shared(); - } - MMI_HILOGD("Injectnotice StartNoticeAbility end"); - if (!injectNotice_->IsAbilityStart()) { - MMI_HILOGD("Injectnotice StartNoticeAbility begin"); - bool isStart = injectNotice_->StartNoticeAbility(); - if (!isStart) { - MMI_HILOGE("Injectnotice StartNoticeAbility isStart:%{public}d", isStart); - return false; - } - MMI_HILOGD("Injectnotice StartNoticeAbility end"); - } - auto connection = injectNotice_->GetConnection(); - CHKPF(connection); - if (!connection->IsConnected()) { - MMI_HILOGD("Injectnotice ConnectNoticeSrv begin"); - bool isConnect = injectNotice_->ConnectNoticeSrv(); - if (!isConnect) { - MMI_HILOGD("Injectnotice ConnectNoticeSrv isConnect:%{public}d", isConnect); - return false; - } - MMI_HILOGD("Injectnotice ConnectNoticeSrv end"); - } - MMI_HILOGD("Injectnotice InitInjectNoticeSource end"); - return true; -} - -bool ServerMsgHandler::AddInjectNotice(const InjectNoticeInfo ¬iceInfo) -{ - CALL_DEBUG_ENTER; - bool isInit = InitInjectNoticeSource(); - if (!isInit) { - MMI_HILOGE("InitinjectNotice_ Source error"); - return false; - } - MMI_HILOGD("SendNotice submit begin"); - ffrt::submit([this, noticeInfo] { - MMI_HILOGD("SendNotice submit enter"); - CHKPV(injectNotice_); - auto pConnect = injectNotice_->GetConnection(); - CHKPV(pConnect); - int32_t timeSecond = 0; - while (timeSecond <= SEND_NOTICE_OVERTIME) { - bool isConnect = pConnect->IsConnected(); - MMI_HILOGD("SendNotice %{public}d", isConnect); - if (isConnect) { - MMI_HILOGD("SendNotice begin"); - pConnect->SendNotice(noticeInfo); - break; - } - timeSecond += 1; - sleep(1); - } - MMI_HILOGD("SendNotice submit leave"); - }); - return true; -} - -bool ServerMsgHandler::CloseInjectNotice(int32_t pid) -{ - CALL_DEBUG_ENTER; - bool isInit = InitInjectNoticeSource(); - if (!isInit) { - MMI_HILOGE("InitinjectNotice_ Source error"); - return false; - } - MMI_HILOGD("CloseNotice submit begin"); - InjectNoticeInfo noticeInfo; - noticeInfo.pid = pid; - ffrt::submit([this, noticeInfo] { - MMI_HILOGD("CloseNotice submit enter"); - CHKPV(injectNotice_); - auto pConnect = injectNotice_->GetConnection(); - CHKPV(pConnect); - int32_t timeSecond = 0; - while (timeSecond <= SEND_NOTICE_OVERTIME) { - bool isConnect = pConnect->IsConnected(); - MMI_HILOGD("CloseNotice %{public}d", isConnect); - if (isConnect) { - MMI_HILOGD("CloseNotice begin"); - pConnect->CancelNotice(noticeInfo); - break; - } - timeSecond += 1; - sleep(1); - } - MMI_HILOGD("CloseNotice submit leave"); - }); - return true; -} - -int32_t ServerMsgHandler::OnTransferBinderClientSrv(const sptr &binderClientObject, int32_t pid) -{ - CALL_DEBUG_ENTER; - bool bRet = clientDeathHandler_.RegisterClientDeathRecipient(binderClientObject, pid); - if (!bRet) { - MMI_HILOGE("Failed to registerClientDeathRecipient"); - return RET_ERR; - } - return ERR_OK; -} - -int32_t ServerMsgHandler::NativeInjectCheck(int32_t pid) -{ - CALL_DEBUG_ENTER; - if (PRODUCT_TYPE != PRODUCT_TYPE_PC) { - MMI_HILOGW("Current device has no permission"); - return COMMON_PERMISSION_CHECK_ERROR; - } - bool screenLocked = DISPLAY_MONITOR->GetScreenLocked(); - if (screenLocked) { - MMI_HILOGW("Screen locked, no permission"); - return COMMON_PERMISSION_CHECK_ERROR; - } - if (pid <= 0) { - MMI_HILOGW("Invalid process id pid:%{public}d", pid); - return COMMON_PERMISSION_CHECK_ERROR; - } - auto state = AUTHORIZE_HELPER->GetAuthorizeState(); - MMI_HILOGI("The process is already being processed,s:%{public}d,pid:%{public}d,inputPid:%{public}d", - state, AUTHORIZE_HELPER->GetAuthorizePid(), pid); - if (state == AuthorizeState::STATE_UNAUTHORIZE) { - LaunchAbility(); - AuthorizeExitCallback fnCallback = [&] (int32_t pid) { - MMI_HILOGI("User not authorized to inject pid:%{public}d", pid); - AUTH_DIALOG.CloseDialog(); - }; - AUTHORIZE_HELPER->AddAuthorizeProcess(pid, fnCallback); - return COMMON_PERMISSION_CHECK_ERROR; - } - - if (state == AuthorizeState::STATE_SELECTION_AUTHORIZE) { - if (pid == AUTHORIZE_HELPER->GetAuthorizePid()) { - MMI_HILOGI("The current PID is waiting for user authorization"); - } else { - MMI_HILOGI("Another PID is waiting for user authorization"); - } - return COMMON_PERMISSION_CHECK_ERROR; - } - - // Currently, a process is authorized.state is AuthorizeState::STATE_AUTHORIZE - if (pid != AUTHORIZE_HELPER->GetAuthorizePid()) { - MMI_HILOGI("Other processes have been authorized"); - return COMMON_PERMISSION_CHECK_ERROR; - } - return RET_OK; -} -} // namespace MMI -} // namespace OHOS + #include "server_msg_handler.h" + + #include "anr_manager.h" + #include "app_mgr_client.h" + #include "authorization_dialog.h" + #include "authorize_helper.h" + #include "bytrace_adapter.h" + #ifdef OHOS_BUILD_ENABLE_DFX_RADAR + #include "dfx_hisysevent.h" + #endif // OHOS_BUILD_ENABLE_DFX_RADAR + #include "display_event_monitor.h" + #include "event_log_helper.h" + #include "input_device_manager.h" + #include "input_event_handler.h" + #include "i_pointer_drawing_manager.h" + #ifdef OHOS_BUILD_ENABLE_KEY_PRESSED_HANDLER + #include "key_monitor_manager.h" + #endif // OHOS_BUILD_ENABLE_KEY_PRESSED_HANDLER + #ifdef SHORTCUT_KEY_MANAGER_ENABLED + #include "key_shortcut_manager.h" + #endif // SHORTCUT_KEY_MANAGER_ENABLED + #include "long_press_subscriber_handler.h" + #include "libinput_adapter.h" + #include "time_cost_chk.h" + #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING + #include "touch_drawing_manager.h" + #endif // #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING + + #undef MMI_LOG_DOMAIN + #define MMI_LOG_DOMAIN MMI_LOG_SERVER + #undef MMI_LOG_TAG + #define MMI_LOG_TAG "ServerMsgHandler" + + namespace OHOS { + namespace MMI { + namespace { + #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT + constexpr int32_t SECURITY_COMPONENT_SERVICE_ID = 3050; + #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT + constexpr int32_t SEND_NOTICE_OVERTIME { 5 }; + [[ maybe_unused ]] constexpr int32_t DEFAULT_POINTER_ID { 10000 }; + [[ maybe_unused ]] constexpr int32_t CAST_POINTER_ID { 5000 }; + const std::string PRODUCT_TYPE = system::GetParameter("const.product.devicetype", "unknown"); + const std::string PRODUCT_TYPE_PC = "2in1"; + [[ maybe_unused ]] constexpr int32_t WINDOW_ROTATE { 0 }; + constexpr int32_t COMMON_PERMISSION_CHECK_ERROR { 201 }; + constexpr int32_t CAST_INPUT_DEVICEID { 0xAAAAAAFF }; + constexpr int32_t CAST_SCREEN_DEVICEID { 0xAAAAAAFE }; + constexpr int32_t ANGLE_90 { 90 }; + constexpr int32_t ANGLE_360 { 360 }; + constexpr int32_t ERR_DEVICE_NOT_EXIST { 3900002 }; + constexpr int32_t ERR_NON_INPUT_APPLICATION { 3900003 }; + constexpr int32_t SIMULATE_EVENT_START_ID { 10000 }; + constexpr float MM_TO_INCH { 25.4f }; + constexpr int32_t SCREEN_DIAGONAL_0 { 0 }; + constexpr int32_t SCREEN_DIAGONAL_8 { 8 }; + constexpr int32_t SCREEN_DIAGONAL_18 { 18 }; + constexpr int32_t SCREEN_DIAGONAL_27 { 27 }; + constexpr int32_t SCREEN_DIAGONAL_55 { 55 }; + constexpr float FACTOR_0 { 1.0f }; + constexpr float FACTOR_8 { 0.7f }; + constexpr float FACTOR_18 { 1.0f }; + constexpr float FACTOR_27 { 1.2f }; + constexpr float FACTOR_55 { 1.6f }; + constexpr float FACTOR_MAX { 2.4f }; + } // namespace + + void ServerMsgHandler::Init(UDSServer &udsServer) + { + udsServer_ = &udsServer; + MsgCallback funs[] = { + {MmiMessageId::DISPLAY_INFO, [this] (SessionPtr sess, NetPacket &pkt) { + return this->OnDisplayInfo(sess, pkt); }}, + {MmiMessageId::WINDOW_INFO, [this] (SessionPtr sess, NetPacket &pkt) { + return this->OnWindowGroupInfo(sess, pkt); }}, + {MmiMessageId::WINDOW_STATE_ERROR_CALLBACK, [this] (SessionPtr sess, NetPacket &pkt) { + return this->RegisterWindowStateErrorCallback(sess, pkt); }}, + #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT + {MmiMessageId::SCINFO_CONFIG, [this] (SessionPtr sess, NetPacket &pkt) { + return this->OnEnhanceConfig(sess, pkt); }}, + #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT + + }; + for (auto &it : funs) { + if (!RegistrationEvent(it)) { + MMI_HILOGW("Failed to register event errCode:%{public}d", EVENT_REG_FAIL); + continue; + } + } + AUTHORIZE_HELPER->Init(clientDeathHandler_); + } + + void ServerMsgHandler::OnMsgHandler(SessionPtr sess, NetPacket& pkt) + { + CHKPV(sess); + auto id = pkt.GetMsgId(); + TimeCostChk chk("ServerMsgHandler::OnMsgHandler", "overtime 300(us)", MAX_OVER_TIME, id); + BytraceAdapter::StartSocketHandle(static_cast(id)); + auto callback = GetMsgCallback(id); + if (callback == nullptr) { + MMI_HILOGE("Unknown msg id:%{public}d,errCode:%{public}d", id, UNKNOWN_MSG_ID); + return; + } + auto ret = (*callback)(sess, pkt); + BytraceAdapter::StopSocketHandle(); + if (ret < 0) { + MMI_HILOGE("Msg handling failed. id:%{public}d,errCode:%{public}d", id, ret); + } + } + + #ifdef OHOS_BUILD_ENABLE_KEYBOARD + int32_t ServerMsgHandler::OnInjectKeyEvent(const std::shared_ptr keyEvent, int32_t pid, bool isNativeInject) + { + CALL_DEBUG_ENTER; + CHKPR(keyEvent, ERROR_NULL_POINTER); + LogTracer lt(keyEvent->GetId(), keyEvent->GetEventType(), keyEvent->GetKeyAction()); + if (isNativeInject) { + int32_t checkReturn = NativeInjectCheck(pid); + if (checkReturn != RET_OK) { + return checkReturn; + } + } + keyEvent->SetKeyIntention(KeyItemsTransKeyIntention(keyEvent->GetKeyItems())); + auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); + CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); + inputEventNormalizeHandler->HandleKeyEvent(keyEvent); + #ifdef SHORTCUT_KEY_RULES_ENABLED + KEY_SHORTCUT_MGR->UpdateShortcutConsumed(keyEvent); + #endif // SHORTCUT_KEY_RULES_ENABLED + if (EventLogHelper::IsBetaVersion() && !keyEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) { + MMI_HILOGD("Inject keyCode:%{private}d, action:%{public}d", keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); + } else { + MMI_HILOGD("Inject keyCode:%{private}d, action:%{public}d", keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); + } + return RET_OK; + } + + int32_t ServerMsgHandler::OnGetFunctionKeyState(int32_t funcKey, bool &state) + { + CALL_INFO_TRACE; + bool hasVirtualKeyboard = false; + #ifdef OHOS_BUILD_ENABLE_VKEYBOARD + hasVirtualKeyboard = INPUT_DEV_MGR->HasVirtualKeyboardDevice(); + #endif // OHOS_BUILD_ENABLE_VKEYBOARD + std::vector input_device; + INPUT_DEV_MGR->GetMultiKeyboardDevice(input_device); + if (input_device.size() == 0 && !hasVirtualKeyboard) { + MMI_HILOGW("No keyboard device is currently available"); + return ERR_DEVICE_NOT_EXIST; + } + const auto &keyEvent = KeyEventHdr->GetKeyEvent(); + CHKPR(keyEvent, ERROR_NULL_POINTER); + state = keyEvent->GetFunctionKey(funcKey); + MMI_HILOGD("Get the function key:%{public}d status as %{public}s", funcKey, state ? "open" : "close"); + return RET_OK; + } + + int32_t ServerMsgHandler::OnSetFunctionKeyState(int32_t pid, int32_t funcKey, bool enable) + { + CALL_INFO_TRACE; + AppExecFwk::RunningProcessInfo processInfo; + auto appMgrClient = DelayedSingleton::GetInstance(); + CHKPR(appMgrClient, ERROR_NULL_POINTER); + auto begin = std::chrono::high_resolution_clock::now(); + appMgrClient->GetRunningProcessInfoByPid(pid, processInfo); + auto durationMS = std::chrono::duration_cast( + std::chrono::high_resolution_clock::now() - begin).count(); + #ifdef OHOS_BUILD_ENABLE_DFX_RADAR + DfxHisysevent::ReportApiCallTimes(ApiDurationStatistics::Api::GET_RUNNING_PROCESS_INFO_BY_PID, durationMS); + #endif // OHOS_BUILD_ENABLE_DFX_RADAR + if (processInfo.extensionType_ != AppExecFwk::ExtensionAbilityType::INPUTMETHOD) { + MMI_HILOGW("It is prohibited for non-input applications"); + return ERR_NON_INPUT_APPLICATION; + } + bool hasVirtualKeyboard = false; + #ifdef OHOS_BUILD_ENABLE_VKEYBOARD + hasVirtualKeyboard = INPUT_DEV_MGR->HasVirtualKeyboardDevice(); + #endif // OHOS_BUILD_ENABLE_VKEYBOARD + std::vector input_device; + int32_t DeviceId = -1; + INPUT_DEV_MGR->GetMultiKeyboardDevice(input_device); + if (input_device.size() == 0 && !hasVirtualKeyboard) { + MMI_HILOGW("No keyboard device is currently available"); + return ERR_DEVICE_NOT_EXIST; + } + auto keyEvent = KeyEventHdr->GetKeyEvent(); + CHKPR(keyEvent, ERROR_NULL_POINTER); + bool checkState = keyEvent->GetFunctionKey(funcKey); + if (checkState == enable) { + MMI_HILOGE("Current device no need to set up"); + return RET_OK; + } + #ifdef OHOS_BUILD_ENABLE_VKEYBOARD + if (funcKey == KeyEvent::CAPS_LOCK_FUNCTION_KEY) { + // set vkeyboard caps state with separate API. + MMI_HILOGD("Set vkb func state old=%{private}d, new=%{private}d", checkState, enable); + libinput_toggle_caps_key(); + } + #endif // OHOS_BUILD_ENABLE_VKEYBOARD + for (auto it = input_device.begin(); it != input_device.end(); ++it) { + auto device = (*it); + DeviceId = INPUT_DEV_MGR->FindInputDeviceId(device); + if (LibinputAdapter::DeviceLedUpdate(device, funcKey, enable) != RET_OK) { + MMI_HILOGE("Failed to set the keyboard led, device id %{public}d", DeviceId); + } + int32_t state = libinput_get_funckey_state(device, funcKey); + if (state != enable) { + MMI_HILOGE("Failed to enable the function key, device id %{public}d", DeviceId); + } + } + int32_t ret = keyEvent->SetFunctionKey(funcKey, enable); + if (ret != funcKey) { + MMI_HILOGE("Failed to enable the function key"); + return RET_ERR; + } + MMI_HILOGD("Update function key:%{public}d succeed", funcKey); + return RET_OK; + } + #endif // OHOS_BUILD_ENABLE_KEYBOARD + + #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) + int32_t ServerMsgHandler::OnInjectPointerEvent(const std::shared_ptr pointerEvent, int32_t pid, + bool isNativeInject, bool isShell) + { + CALL_DEBUG_ENTER; + CHKPR(pointerEvent, ERROR_NULL_POINTER); + LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); + if (isNativeInject) { + int32_t checkReturn = NativeInjectCheck(pid); + if (checkReturn != RET_OK) { + return checkReturn; + } + } + return OnInjectPointerEventExt(pointerEvent, isShell); + } + + int32_t ServerMsgHandler::OnInjectTouchPadEvent(const std::shared_ptr pointerEvent, int32_t pid, + const TouchpadCDG &touchpadCDG, bool isNativeInject, bool isShell) + { + CALL_DEBUG_ENTER; + CHKPR(pointerEvent, ERROR_NULL_POINTER); + LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); + if (isNativeInject) { + int32_t checkReturn = NativeInjectCheck(pid); + if (checkReturn != RET_OK) { + return checkReturn; + } + } + return OnInjectTouchPadEventExt(pointerEvent, touchpadCDG, isShell); + } + + bool ServerMsgHandler::IsNavigationWindowInjectEvent(std::shared_ptr pointerEvent) + { + return pointerEvent->GetZOrder() > 0; + } + + int32_t ServerMsgHandler::OnInjectTouchPadEventExt(const std::shared_ptr pointerEvent, + const TouchpadCDG &touchpadCDG, bool isShell) + { + CALL_DEBUG_ENTER; + CHKPR(pointerEvent, ERROR_NULL_POINTER); + EndLogTraceId(pointerEvent->GetId()); + pointerEvent->UpdateId(); + LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); + auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); + CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); + if (pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_MOUSE) { + #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) + int32_t ret = AccelerateMotionTouchpad(pointerEvent, touchpadCDG); + if (ret != RET_OK) { + MMI_HILOGE("Failed to accelerate motion, error:%{public}d", ret); + return ret; + } + UpdatePointerEvent(pointerEvent); + inputEventNormalizeHandler->HandlePointerEvent(pointerEvent); + CHKPR(pointerEvent, ERROR_NULL_POINTER); + pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY); + if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_HIDE_POINTER)) { + IPointerDrawingManager::GetInstance()->SetMouseDisplayState(false); + } else if (((pointerEvent->GetPointerAction() < PointerEvent::POINTER_ACTION_PULL_DOWN) || + (pointerEvent->GetPointerAction() > PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW)) && + !IPointerDrawingManager::GetInstance()->IsPointerVisible()) { + IPointerDrawingManager::GetInstance()->SetPointerVisible(getpid(), true, 0, false); + } + #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH + } else { + MMI_HILOGW("Source types are not Touchpad, source:%{public}d", pointerEvent->GetSourceType()); + } + return SaveTargetWindowId(pointerEvent, isShell); + } + + void ServerMsgHandler::DealGesturePointers(std::shared_ptr pointerEvent) + { + if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { + return; + } + MMI_HILOGI("Check : current PointerEvent's info :Id=>%{public}d, pointerId=>%{public}d", + pointerEvent->GetId(), pointerEvent->GetPointerId()); + std::shared_ptr touchEvent = WIN_MGR->GetLastPointerEventForGesture(); + if (touchEvent != nullptr) { + std::list listPtItems = touchEvent->GetAllPointerItems(); + for (auto &item : listPtItems) { + MMI_HILOGI("Check : current Item : pointerId=>%{public}d, OriginPointerId=>%{public}d", + item.GetPointerId(), item.GetOriginPointerId()); + if ((item.GetPointerId() % SIMULATE_EVENT_START_ID) != + (pointerEvent->GetPointerId() % SIMULATE_EVENT_START_ID) && item.IsPressed()) { + pointerEvent->AddPointerItem(item); + MMI_HILOGI("Check : add Item : pointerId=>%{public}d, OriginPointerId=>%{public}d", + item.GetPointerId(), item.GetOriginPointerId()); + } + } + } + } + + int32_t ServerMsgHandler::OnInjectPointerEventExt(const std::shared_ptr pointerEvent, bool isShell) + { + CALL_DEBUG_ENTER; + CHKPR(pointerEvent, ERROR_NULL_POINTER); + EndLogTraceId(pointerEvent->GetId()); + pointerEvent->UpdateId(); + LogTracer lt(pointerEvent->GetId(), pointerEvent->GetEventType(), pointerEvent->GetPointerAction()); + auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); + CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); + switch (pointerEvent->GetSourceType()) { + case PointerEvent::SOURCE_TYPE_TOUCHSCREEN: { + #ifdef OHOS_BUILD_ENABLE_TOUCH + if (!FixTargetWindowId(pointerEvent, pointerEvent->GetPointerAction(), isShell)) { + return RET_ERR; + } + DealGesturePointers(pointerEvent); + MMI_HILOGI("Check : prepare to send inject pointer event"); + inputEventNormalizeHandler->HandleTouchEvent(pointerEvent); + if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY) && + !(IsCastInject(pointerEvent->GetDeviceId())) && + !IsNavigationWindowInjectEvent(pointerEvent)) { + #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING + TOUCH_DRAWING_MGR->TouchDrawHandler(pointerEvent); + #endif // #ifdef OHOS_BUILD_ENABLE_TOUCH_DRAWING + } + #endif // OHOS_BUILD_ENABLE_TOUCH + break; + } + case PointerEvent::SOURCE_TYPE_MOUSE: + #ifdef OHOS_BUILD_ENABLE_JOYSTICK + case PointerEvent::SOURCE_TYPE_JOYSTICK: + #endif // OHOS_BUILD_ENABLE_JOYSTICK + case PointerEvent::SOURCE_TYPE_TOUCHPAD: { + #ifdef OHOS_BUILD_ENABLE_POINTER + int32_t ret = AccelerateMotion(pointerEvent); + if (ret != RET_OK) { + MMI_HILOGE("Failed to accelerate motion, error:%{public}d", ret); + return ret; + } + UpdatePointerEvent(pointerEvent); + inputEventNormalizeHandler->HandlePointerEvent(pointerEvent); + CHKPR(pointerEvent, ERROR_NULL_POINTER); + if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { + break; + } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_HIDE_POINTER)) { + IPointerDrawingManager::GetInstance()->SetMouseDisplayState(false); + } else if (((pointerEvent->GetPointerAction() < PointerEvent::POINTER_ACTION_PULL_DOWN) || + (pointerEvent->GetPointerAction() > PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW)) && + !IPointerDrawingManager::GetInstance()->IsPointerVisible()) { + IPointerDrawingManager::GetInstance()->SetPointerVisible(getpid(), true, 0, false); + } + #endif // OHOS_BUILD_ENABLE_POINTER + break; + } + default: { + MMI_HILOGW("Source type is unknown, source:%{public}d", pointerEvent->GetSourceType()); + break; + } + } + return SaveTargetWindowId(pointerEvent, isShell); + } + #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH + + #ifdef OHOS_BUILD_ENABLE_POINTER + float ServerMsgHandler::ScreenFactor(const int32_t diagonalInch) + { + if (diagonalInch <= SCREEN_DIAGONAL_0) { + return FACTOR_0; + } else if (diagonalInch < SCREEN_DIAGONAL_8) { + return FACTOR_8; + } else if (diagonalInch < SCREEN_DIAGONAL_18) { + return FACTOR_18; + } else if (diagonalInch < SCREEN_DIAGONAL_27) { + return FACTOR_27; + } else if (diagonalInch < SCREEN_DIAGONAL_55) { + return FACTOR_55; + } else { + return FACTOR_MAX; + } + } + + int32_t ServerMsgHandler::AccelerateMotion(std::shared_ptr pointerEvent) + { + if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT) || + (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE) || + ((pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_MOVE) && + (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_PULL_MOVE) && + (pointerEvent->GetPointerAction() != PointerEvent::POINTER_ACTION_BUTTON_DOWN))) { + return RET_OK; + } + PointerEvent::PointerItem pointerItem {}; + if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) { + MMI_HILOGE("Pointer event is corrupted"); + return RET_ERR; + } + CursorPosition cursorPos = WIN_MGR->GetCursorPos(); + if (cursorPos.displayId < 0) { + MMI_HILOGE("No display"); + return RET_ERR; + } + Offset offset { + .dx = pointerItem.GetRawDx(), + .dy = pointerItem.GetRawDy(), + }; + auto displayInfo = WIN_MGR->GetPhysicalDisplay(cursorPos.displayId); + CHKPR(displayInfo, ERROR_NULL_POINTER); + #ifndef OHOS_BUILD_EMULATOR + Direction displayDirection = static_cast(( + ((displayInfo->direction - displayInfo->displayDirection) * ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90); + #ifdef OHOS_BUILD_ENABLE_HARDWARE_CURSOR + if (WIN_MGR->IsSupported()) { + direction = displayInfo->direction; + } + #endif // OHOS_BUILD_ENABLE_HARDWARE_CURSOR + CalculateOffset(displayDirection, offset); + #endif // OHOS_BUILD_EMULATOR + int32_t ret = RET_OK; + if (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_BUTTON_DOWN) { + WIN_MGR->UpdateAndAdjustMouseLocation(cursorPos.displayId, cursorPos.cursorPos.x, cursorPos.cursorPos.y); + return RET_OK; + } + if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_TOUCHPAD_POINTER) && + pointerEvent->HasFlag(InputEvent::EVENT_FLAG_VIRTUAL_TOUCHPAD_POINTER)) { + ret = HandleMotionAccelerateTouchpad(&offset, WIN_MGR->GetMouseIsCaptureMode(), + &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, + MouseTransformProcessor::GetTouchpadSpeed(), static_cast(DeviceType::DEVICE_FOLD_PC_VIRT)); + } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_TOUCHPAD_POINTER)) { + ret = HandleMotionAccelerateTouchpad(&offset, WIN_MGR->GetMouseIsCaptureMode(), + &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, + MouseTransformProcessor::GetTouchpadSpeed(), static_cast(DeviceType::DEVICE_PC)); + } else { + uint64_t deltaTime = 0; + #ifdef OHOS_BUILD_MOUSE_REPORTING_RATE + static uint64_t preTime = -1; + uint64_t currentTime = static_cast(pointerEvent->GetActionTime()); + preTime = fmin(preTime, currentTime); + deltaTime = (currentTime - preTime); + preTime = currentTime; + #endif // OHOS_BUILD_MOUSE_REPORTING_RATE + if (displayInfo->ppi != 0) { + int32_t diagonalMm = static_cast(sqrt((displayInfo->physicalWidth * displayInfo->physicalWidth) + + (displayInfo->physicalHeight * displayInfo->physicalHeight))); + int32_t diagonalInch = static_cast(diagonalMm / MM_TO_INCH); + float factor = ScreenFactor(diagonalInch); + ret = HandleMotionDynamicAccelerateMouse(&offset, WIN_MGR->GetMouseIsCaptureMode(), + &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, MouseTransformProcessor::GetPointerSpeed(), + deltaTime, static_cast(displayInfo->ppi), static_cast(factor)); + } else { + ret = HandleMotionAccelerateMouse(&offset, WIN_MGR->GetMouseIsCaptureMode(), + &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, + MouseTransformProcessor::GetPointerSpeed(), static_cast(DeviceType::DEVICE_PC)); + } + } + if (ret != RET_OK) { + MMI_HILOGE("Failed to accelerate pointer motion, error:%{public}d", ret); + return ret; + } + WIN_MGR->UpdateAndAdjustMouseLocation(cursorPos.displayId, cursorPos.cursorPos.x, cursorPos.cursorPos.y); + if (EventLogHelper::IsBetaVersion() && !pointerEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) { + MMI_HILOGD("Cursor move to (x:%.2f, y:%.2f, DisplayId:%d)", + cursorPos.cursorPos.x, cursorPos.cursorPos.y, cursorPos.displayId); + } else { + MMI_HILOGD("Cursor move to (x:%.2f, y:%.2f, DisplayId:%d)", + cursorPos.cursorPos.x, cursorPos.cursorPos.y, cursorPos.displayId); + } + return RET_OK; + } + + int32_t ServerMsgHandler::AccelerateMotionTouchpad(std::shared_ptr pointerEvent, + const TouchpadCDG &touchpadCDG) + { + PointerEvent::PointerItem pointerItem {}; + if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) { + MMI_HILOGE("Pointer event is corrupted"); + return RET_ERR; + } + CursorPosition cursorPos = WIN_MGR->GetCursorPos(); + if (cursorPos.displayId < 0) { + MMI_HILOGE("No display"); + return RET_ERR; + } + Offset offset { + .dx = pointerItem.GetRawDx(), + .dy = pointerItem.GetRawDy(), + }; + auto displayInfo = WIN_MGR->GetPhysicalDisplay(cursorPos.displayId); + CHKPR(displayInfo, ERROR_NULL_POINTER); + #ifndef OHOS_BUILD_EMULATOR + Direction displayDirection = static_cast(( + ((displayInfo->direction - displayInfo->displayDirection) * ANGLE_90 + ANGLE_360) % ANGLE_360) / ANGLE_90); + CalculateOffset(displayDirection, offset); + #endif // OHOS_BUILD_EMULATOR + int32_t ret = RET_OK; + + #ifdef OHOS_BUILD_MOUSE_REPORTING_RATE + MMI_HILOGE("Hidumper before HandleMotionDynamicAccelerateTouchpad"); + static uint64_t preTime = -1; + uint64_t currentTime = static_cast(pointerEvent->GetActionTime()); + preTime = fmin(preTime, currentTime); + uint64_t deltaTime = (currentTime - preTime); + MMI_HILOGE("DeltaTime before HandleMotionDynamicAccelerateTouchpad: %{public}PRId64 ms", deltaTime); + + double displaySize = sqrt(pow(displayInfo->width, 2) + pow(displayInfo->height, 2)); + double touchpadSize = touchpadCDG.size; + double touchpadPPi = touchpadCDG.ppi; + int32_t touchpadSpeed = touchpadCDG.speed; + int32_t frequency = touchpadCDG.frequency; + if (touchpadSize <= 0 || touchpadPPi <= 0 || touchpadSpeed <= 0 || frequency <= 0) { + MMI_HILOGE("touchpadSize, touchpadPPi or touchpadSpeed are invalid, + touchpadSize:%{public}lf, touchpadPPi:%{public}lf, touchpadSpeed:%{public}d, frequency:%{public}d", + touchpadSize, touchpadPPi, touchpadSpeed, frequency); + return RET_ERR; + } + if (pointerEvent->GetPointerAction() == POINTER_ACTION_MOVE) { + ret = HandleMotionDynamicAccelerateTouchpad(&offset, WIN_MGR->GetMouseIsCaptureMode(), &cursorPos.cursorPos.x, + &cursorPos.cursorPos.y, touchpadSpeed, displaySize, touchpadSize, touchpadPPi, frequency); + } + MMI_HILOGE("DeltaTime after HandleMotionDynamicAccelerateTouchpad: %{public}PRId64 ms", deltaTime); + MMI_HILOGE("Hidumper after HandleMotionDynamicAccelerateTouchpad"); + preTime = currentTime; + #else + ret = HandleMotionAccelerateTouchpad(&offset, WIN_MGR->GetMouseIsCaptureMode(), + &cursorPos.cursorPos.x, &cursorPos.cursorPos.y, + MouseTransformProcessor::GetTouchpadSpeed(), static_cast(DeviceType::DEVICE_PC)); + #endif // OHOS_BUILD_MOUSE_REPORTING_RATE + if (ret != RET_OK) { + MMI_HILOGE("Failed to accelerate pointer motion, error:%{public}d", ret); + return ret; + } + WIN_MGR->UpdateAndAdjustMouseLocation(cursorPos.displayId, cursorPos.cursorPos.x, cursorPos.cursorPos.y); + if (EventLogHelper::IsBetaVersion() && !pointerEvent->HasFlag(InputEvent::EVENT_FLAG_PRIVACY_MODE)) { + MMI_HILOGD("Cursor move to (x:%.2f, y:%.2f, DisplayId:%d)", + cursorPos.cursorPos.x, cursorPos.cursorPos.y, cursorPos.displayId); + } else { + MMI_HILOGD("Cursor move to (x:%.2f, y:%.2f, DisplayId:%d)", + cursorPos.cursorPos.x, cursorPos.cursorPos.y, cursorPos.displayId); + } + return RET_OK; + } + + void ServerMsgHandler::CalculateOffset(Direction direction, Offset &offset) + { + std::negate neg; + if (direction == DIRECTION90) { + double tmp = offset.dx; + offset.dx = offset.dy; + offset.dy = neg(tmp); + } else if (direction == DIRECTION180) { + offset.dx = neg(offset.dx); + offset.dy = neg(offset.dy); + } else if (direction == DIRECTION270) { + double tmp = offset.dx; + offset.dx = neg(offset.dy); + offset.dy = tmp; + } + } + #endif // OHOS_BUILD_ENABLE_POINTER + + #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) + void ServerMsgHandler::UpdatePointerEvent(std::shared_ptr pointerEvent) + { + if (!pointerEvent->HasFlag(InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT) || + (pointerEvent->GetSourceType() != PointerEvent::SOURCE_TYPE_MOUSE)) { + return; + } + PointerEvent::PointerItem pointerItem {}; + if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) { + MMI_HILOGE("Pointer event is corrupted"); + return; + } + auto mouseInfo = WIN_MGR->GetMouseInfo(); + pointerItem.SetDisplayX(mouseInfo.physicalX); + pointerItem.SetDisplayY(mouseInfo.physicalY); + pointerEvent->UpdatePointerItem(pointerEvent->GetPointerId(), pointerItem); + pointerEvent->SetTargetDisplayId(mouseInfo.displayId); + } + + int32_t ServerMsgHandler::SaveTargetWindowId(std::shared_ptr pointerEvent, bool isShell) + { + CHKPR(pointerEvent, ERROR_NULL_POINTER); + if ((pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && + (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_DOWN || + pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_HOVER_ENTER)) { + int32_t pointerId = pointerEvent->GetPointerId(); + PointerEvent::PointerItem pointerItem; + if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) { + MMI_HILOGE("Can't find pointer item, pointer:%{public}d", pointerId); + return RET_ERR; + } + int32_t targetWindowId = pointerEvent->GetTargetWindowId(); + if (isShell) { + shellTargetWindowIds_[pointerId] = targetWindowId; + } else if (IsCastInject(pointerEvent->GetDeviceId()) && (pointerEvent->GetZOrder() > 0)) { + castTargetWindowIds_[pointerId] = targetWindowId; + } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { + accessTargetWindowIds_[pointerId] = targetWindowId; + } else { + nativeTargetWindowIds_[pointerId] = targetWindowId; + } + } + if ((pointerEvent->GetSourceType() == PointerEvent::SOURCE_TYPE_TOUCHSCREEN) && + (pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_UP || + pointerEvent->GetPointerAction() == PointerEvent::POINTER_ACTION_HOVER_EXIT)) { + int32_t pointerId = pointerEvent->GetPointerId(); + if (isShell) { + shellTargetWindowIds_.erase(pointerId); + } else if (IsCastInject(pointerEvent->GetDeviceId()) && (pointerEvent->GetZOrder() > 0)) { + castTargetWindowIds_.erase(pointerId); + } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { + accessTargetWindowIds_.erase(pointerId); + } else { + nativeTargetWindowIds_.erase(pointerId); + } + } + return RET_OK; + } + #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH + + #ifdef OHOS_BUILD_ENABLE_TOUCH + bool ServerMsgHandler::FixTargetWindowId(std::shared_ptr pointerEvent, + int32_t action, bool isShell) + { + int32_t targetWindowId = -1; + int32_t pointerId = pointerEvent->GetPointerId(); + PointerEvent::PointerItem pointerItem; + if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) { + MMI_HILOGE("Can't find pointer item, pointer:%{public}d", pointerId); + return false; + } + if (isShell) { + auto iter = shellTargetWindowIds_.find(pointerEvent->GetPointerId()); + if (iter != shellTargetWindowIds_.end()) { + targetWindowId = iter->second; + } + } else if ((IsCastInject(pointerEvent->GetDeviceId())) && (pointerEvent->GetZOrder() > 0)) { + pointerEvent->RemovePointerItem(pointerId); + pointerId += CAST_POINTER_ID; + pointerItem.SetPointerId(pointerId); + pointerEvent->UpdatePointerItem(pointerId, pointerItem); + pointerEvent->SetPointerId(pointerId); + auto iter = castTargetWindowIds_.find(pointerEvent->GetPointerId()); + if (iter != castTargetWindowIds_.end()) { + targetWindowId = iter->second; + } + } else if (pointerEvent->HasFlag(InputEvent::EVENT_FLAG_ACCESSIBILITY)) { + auto iter = accessTargetWindowIds_.find(pointerEvent->GetPointerId()); + if (iter != accessTargetWindowIds_.end()) { + targetWindowId = iter->second; + } + } else { + pointerEvent->RemovePointerItem(pointerId); + pointerId += DEFAULT_POINTER_ID; + pointerItem.SetPointerId(pointerId); + pointerEvent->UpdatePointerItem(pointerId, pointerItem); + pointerEvent->SetPointerId(pointerId); + auto iter = nativeTargetWindowIds_.find(pointerEvent->GetPointerId()); + if (iter != nativeTargetWindowIds_.end()) { + targetWindowId = iter->second; + } + } + MMI_HILOGD("TargetWindowId:%{public}d %{public}d", pointerEvent->GetTargetWindowId(), targetWindowId); + return UpdateTouchEvent(pointerEvent, action, targetWindowId); + } + + bool ServerMsgHandler::UpdateTouchEvent(std::shared_ptr pointerEvent, + int32_t action, int32_t targetWindowId) + { + int32_t pointerId = pointerEvent->GetPointerId(); + PointerEvent::PointerItem pointerItem; + if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) { + MMI_HILOGE("Can't find pointer item, pointer:%{public}d", pointerId); + return false; + } + if (action == PointerEvent::POINTER_ACTION_HOVER_ENTER || + action == PointerEvent::POINTER_ACTION_DOWN || targetWindowId < 0) { + MMI_HILOGD("Down event or targetWindowId less 0 is not need fix window id"); + return true; + } + auto pointerIds = pointerEvent->GetPointerIds(); + if (pointerIds.empty()) { + MMI_HILOGE("GetPointerIds is empty"); + return false; + } + + pointerEvent->SetTargetWindowId(targetWindowId); + pointerItem.SetTargetWindowId(targetWindowId); + pointerEvent->UpdatePointerItem(pointerId, pointerItem); + return true; + } + #endif // OHOS_BUILD_ENABLE_TOUCH + + int32_t ServerMsgHandler::OnUiExtentionWindowInfo(NetPacket &pkt, WindowInfo& info) + { + uint32_t num = 0; + pkt >> num; + if (pkt.ChkRWError()) { + MMI_HILOGE("Packet read display info failed"); + return RET_ERR; + } + for (uint32_t i = 0; i < num; i++) { + WindowInfo extensionInfo; + pkt >> extensionInfo.id >> extensionInfo.pid >> extensionInfo.uid >> extensionInfo.area + >> extensionInfo.defaultHotAreas >> extensionInfo.pointerHotAreas >> extensionInfo.agentWindowId + >> extensionInfo.flags >> extensionInfo.action >> extensionInfo.displayId >> extensionInfo.groupId + >> extensionInfo.zOrder >> extensionInfo.pointerChangeAreas >> extensionInfo.transform + >> extensionInfo.windowInputType >> extensionInfo.privacyMode >> extensionInfo.windowType + >> extensionInfo.privacyUIFlag >> extensionInfo.rectChangeBySystem + >> extensionInfo.isSkipSelfWhenShowOnVirtualScreen >> extensionInfo.windowNameType; + info.uiExtentionWindowInfo.push_back(extensionInfo); + if (pkt.ChkRWError()) { + MMI_HILOGE("Packet read extention window info failed"); + return RET_ERR; + } + } + return RET_OK; + } + + int32_t ServerMsgHandler::ReadDisplayInfo(NetPacket &pkt, DisplayGroupInfo &displayGroupInfo) + { + uint32_t num = 0; + pkt >> num; + for (uint32_t i = 0; i < num; i++) { + DisplayInfo info; + pkt >> info.id >> info.x >> info.y >> info.width >> info.height >> info.dpi >> info.name + >> info.uniq >> info.direction >> info.displayDirection >> info.displayMode >> info.transform >> info.ppi + >> info.offsetX >> info.offsetY >> info.isCurrentOffScreenRendering >> info.screenRealWidth + >> info.screenRealHeight >> info.screenRealPPI >> info.screenRealDPI >> info.screenCombination + >> info.validWidth >> info.validHeight >> info.fixedDirection + >> info.physicalWidth >> info.physicalHeight >> info.scalePercent >> info.expandHeight >> info.uniqueId; + #ifdef OHOS_BUILD_ENABLE_ONE_HAND_MODE + pkt >> info.oneHandX >> info.oneHandY; + #endif // OHOS_BUILD_ENABLE_ONE_HAND_MODE + #ifdef OHOS_BUILD_ENABLE_VKEYBOARD + pkt >> info.pointerActiveWidth >> info.pointerActiveHeight; + #endif // OHOS_BUILD_ENABLE_VKEYBOARD + if (PRODUCT_TYPE != PRODUCT_TYPE_PC) { + info.uniq = "default" + std::to_string(info.id); + } + pkt >> info.groupId; + displayGroupInfo.displaysInfo.push_back(info); + if (pkt.ChkRWError()) { + MMI_HILOGE("Packet read display info failed"); + return RET_ERR; + } + } + if (pkt.ChkRWError()) { + MMI_HILOGE("Packet read display info failed"); + return RET_ERR; + } + return RET_OK; + } + + bool ServerMsgHandler::IsCastInject(int32_t deviceid) + { + return (deviceid == CAST_INPUT_DEVICEID || deviceid == CAST_SCREEN_DEVICEID); + } + + int32_t ServerMsgHandler::OnDisplayInfo(SessionPtr sess, NetPacket &pkt) + { + CALL_DEBUG_ENTER; + CHKPR(sess, ERROR_NULL_POINTER); + int32_t tokenType = sess->GetTokenType(); + if (tokenType != TokenType::TOKEN_NATIVE && tokenType != TokenType::TOKEN_SHELL && + tokenType !=TokenType::TOKEN_SYSTEM_HAP) { + MMI_HILOGW("Not native or systemapp skip, pid:%{public}d tokenType:%{public}d", sess->GetPid(), tokenType); + return RET_ERR; + } + DisplayGroupInfo displayGroupInfo; + pkt >> displayGroupInfo.groupId >> displayGroupInfo.isMainGroup >> displayGroupInfo.width >> + displayGroupInfo.height >> displayGroupInfo.focusWindowId >> displayGroupInfo.currentUserId; + uint32_t num = 0; + pkt >> num; + if (pkt.ChkRWError()) { + MMI_HILOGE("Packet read display info failed"); + return RET_ERR; + } + for (uint32_t i = 0; i < num; i++) { + WindowInfo info; + int32_t byteCount = 0; + pkt >> info.id >> info.pid >> info.uid >> info.area >> info.defaultHotAreas + >> info.pointerHotAreas >> info.agentWindowId >> info.flags >> info.action + >> info.displayId >> info.groupId >> info.zOrder >> info.pointerChangeAreas >> info.transform + >> info.windowInputType >> info.privacyMode >> info.windowType + >> info.isSkipSelfWhenShowOnVirtualScreen >> info.windowNameType >> byteCount; + + OnUiExtentionWindowInfo(pkt, info); + pkt >> info.rectChangeBySystem; + displayGroupInfo.windowsInfo.push_back(info); + if (pkt.ChkRWError()) { + MMI_HILOGE("Packet read display info failed"); + return RET_ERR; + } + } + if (ReadDisplayInfo(pkt, displayGroupInfo) != RET_OK) { + return RET_ERR; + } + WIN_MGR->UpdateDisplayInfoExtIfNeed(displayGroupInfo, true); + return RET_OK; + } + + int32_t ServerMsgHandler::OnWindowGroupInfo(SessionPtr sess, NetPacket &pkt) + { + CALL_DEBUG_ENTER; + CHKPR(sess, ERROR_NULL_POINTER); + int32_t tokenType = sess->GetTokenType(); + if (tokenType != TokenType::TOKEN_NATIVE && tokenType != TokenType::TOKEN_SHELL && + tokenType !=TokenType::TOKEN_SYSTEM_HAP) { + MMI_HILOGW("Not native or systemapp skip, pid:%{public}d tokenType:%{public}d", sess->GetPid(), tokenType); + return RET_ERR; + } + WindowGroupInfo windowGroupInfo; + pkt >> windowGroupInfo.focusWindowId >> windowGroupInfo.displayId; + uint32_t num = 0; + pkt >> num; + if (pkt.ChkRWError()) { + MMI_HILOGE("Packet read window group info failed"); + return RET_ERR; + } + for (uint32_t i = 0; i < num; i++) { + WindowInfo info; + pkt >> info.id >> info.pid >> info.uid >> info.area >> info.defaultHotAreas + >> info.pointerHotAreas >> info.agentWindowId >> info.flags >> info.action + >> info.displayId >> info.groupId >> info.zOrder >> info.pointerChangeAreas >> info.transform + >> info.windowInputType >> info.privacyMode >> info.windowType >> info.isSkipSelfWhenShowOnVirtualScreen + >> info.windowNameType; + OnUiExtentionWindowInfo(pkt, info); + pkt >> info.rectChangeBySystem; + windowGroupInfo.windowsInfo.push_back(info); + if (pkt.ChkRWError()) { + MMI_HILOGE("Packet read display info failed"); + return RET_ERR; + } + } + WIN_MGR->UpdateWindowInfo(windowGroupInfo); + return RET_OK; + } + + int32_t ServerMsgHandler::RegisterWindowStateErrorCallback(SessionPtr sess, NetPacket &pkt) + { + CALL_DEBUG_ENTER; + CHKPR(sess, ERROR_NULL_POINTER); + int32_t tokenType = sess->GetTokenType(); + if (tokenType != TokenType::TOKEN_NATIVE && tokenType != TokenType::TOKEN_SHELL && + tokenType !=TokenType::TOKEN_SYSTEM_HAP) { + MMI_HILOGW("Not native or systemapp skip, pid:%{public}d tokenType:%{public}d", sess->GetPid(), tokenType); + return RET_ERR; + } + int32_t pid = sess->GetPid(); + WIN_MGR->SetWindowStateNotifyPid(pid); + MMI_HILOGI("The pid:%{public}d", pid); + return RET_OK; + } + + #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT + int32_t ServerMsgHandler::OnEnhanceConfig(SessionPtr sess, NetPacket &pkt) + { + CHKPR(sess, ERROR_NULL_POINTER); + int32_t userId = sess->GetUid(); + if (userId != SECURITY_COMPONENT_SERVICE_ID) { + MMI_HILOGE("Session is not security component service"); + return RET_ERR; + } + uint32_t num = 0; + pkt >> num; + uint8_t cfg[num]; + for (uint32_t i = 0; i < num; i++) { + pkt >> cfg[i]; + } + + if (pkt.ChkRWError()) { + MMI_HILOGE("Packet read scinfo config failed"); + return RET_ERR; + } + int32_t result = Security::SecurityComponent::SecCompEnhanceKit::SetEnhanceCfg(cfg, num); + if (result != 0) { + return RET_ERR; + } + return RET_OK; + } + #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT + #if defined(OHOS_BUILD_ENABLE_INTERCEPTOR) || defined(OHOS_BUILD_ENABLE_MONITOR) + int32_t ServerMsgHandler::OnAddInputHandler(SessionPtr sess, InputHandlerType handlerType, + HandleEventType eventType, int32_t priority, uint32_t deviceTags) + { + CHKPR(sess, ERROR_NULL_POINTER); + MMI_HILOGD("The handlerType:%{public}d", handlerType); + #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR + if (handlerType == InputHandlerType::INTERCEPTOR) { + auto interceptorHandler = InputHandler->GetInterceptorHandler(); + CHKPR(interceptorHandler, ERROR_NULL_POINTER); + return interceptorHandler->AddInputHandler(handlerType, eventType, priority, deviceTags, sess); + } + #endif // OHOS_BUILD_ENABLE_INTERCEPTOR + #ifdef OHOS_BUILD_ENABLE_MONITOR + if (handlerType == InputHandlerType::MONITOR) { + auto monitorHandler = InputHandler->GetMonitorHandler(); + CHKPR(monitorHandler, ERROR_NULL_POINTER); + return monitorHandler->AddInputHandler(handlerType, eventType, sess); + } + #endif // OHOS_BUILD_ENABLE_MONITOR + return RET_OK; + } + + int32_t ServerMsgHandler::OnRemoveInputHandler(SessionPtr sess, InputHandlerType handlerType, + HandleEventType eventType, int32_t priority, uint32_t deviceTags) + { + CHKPR(sess, ERROR_NULL_POINTER); + MMI_HILOGD("OnRemoveInputHandler handlerType:%{public}d eventType:%{public}u", handlerType, eventType); + #ifdef OHOS_BUILD_ENABLE_INTERCEPTOR + if (handlerType == InputHandlerType::INTERCEPTOR) { + auto interceptorHandler = InputHandler->GetInterceptorHandler(); + CHKPR(interceptorHandler, ERROR_NULL_POINTER); + interceptorHandler->RemoveInputHandler(handlerType, eventType, priority, deviceTags, sess); + } + #endif // OHOS_BUILD_ENABLE_INTERCEPTOR + #ifdef OHOS_BUILD_ENABLE_MONITOR + if (handlerType == InputHandlerType::MONITOR) { + auto monitorHandler = InputHandler->GetMonitorHandler(); + CHKPR(monitorHandler, ERROR_NULL_POINTER); + monitorHandler->RemoveInputHandler(handlerType, eventType, sess); + ANRMgr->RemoveTimersByType(sess, ANR_MONITOR); + } + #endif // OHOS_BUILD_ENABLE_MONITOR + return RET_OK; + } + + #endif // OHOS_BUILD_ENABLE_INTERCEPTOR || OHOS_BUILD_ENABLE_MONITOR + + int32_t ServerMsgHandler::OnAddGestureMonitor(SessionPtr sess, InputHandlerType handlerType, + HandleEventType eventType, TouchGestureType gestureType, int32_t fingers) + { + #ifdef OHOS_BUILD_ENABLE_MONITOR + if (handlerType == InputHandlerType::MONITOR) { + auto monitorHandler = InputHandler->GetMonitorHandler(); + CHKPR(monitorHandler, ERROR_NULL_POINTER); + return monitorHandler->AddInputHandler(handlerType, eventType, sess, gestureType, fingers); + } + #endif // OHOS_BUILD_ENABLE_MONITOR + return RET_OK; + } + + int32_t ServerMsgHandler::OnRemoveGestureMonitor(SessionPtr sess, InputHandlerType handlerType, + HandleEventType eventType, TouchGestureType gestureType, int32_t fingers) + { + #ifdef OHOS_BUILD_ENABLE_MONITOR + if (handlerType == InputHandlerType::MONITOR) { + CHKPR(sess, ERROR_NULL_POINTER); + auto monitorHandler = InputHandler->GetMonitorHandler(); + CHKPR(monitorHandler, ERROR_NULL_POINTER); + monitorHandler->RemoveInputHandler(handlerType, eventType, sess, gestureType, fingers); + } + #endif // OHOS_BUILD_ENABLE_MONITOR + return RET_OK; + } + + #ifdef OHOS_BUILD_ENABLE_MONITOR + int32_t ServerMsgHandler::OnMarkConsumed(SessionPtr sess, int32_t eventId) + { + CHKPR(sess, ERROR_NULL_POINTER); + auto monitorHandler = InputHandler->GetMonitorHandler(); + CHKPR(monitorHandler, ERROR_NULL_POINTER); + monitorHandler->MarkConsumed(eventId, sess); + return RET_OK; + } + #endif // OHOS_BUILD_ENABLE_MONITOR + + #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING) + int32_t ServerMsgHandler::OnMoveMouse(int32_t offsetX, int32_t offsetY) + { + CALL_DEBUG_ENTER; + if (MouseEventHdr->NormalizeMoveMouse(offsetX, offsetY)) { + auto pointerEvent = MouseEventHdr->GetPointerEvent(); + CHKPR(pointerEvent, ERROR_NULL_POINTER); + auto inputEventNormalizeHandler = InputHandler->GetEventNormalizeHandler(); + CHKPR(inputEventNormalizeHandler, ERROR_NULL_POINTER); + inputEventNormalizeHandler->HandlePointerEvent(pointerEvent); + MMI_HILOGD("Mouse movement message processed successfully"); + } + return RET_OK; + } + #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING + + #ifdef OHOS_BUILD_ENABLE_KEYBOARD + int32_t ServerMsgHandler::OnSubscribeKeyEvent(IUdsServer *server, int32_t pid, + int32_t subscribeId, const std::shared_ptr option) + { + CALL_DEBUG_ENTER; + CHKPR(server, ERROR_NULL_POINTER); + auto sess = server->GetSessionByPid(pid); + CHKPR(sess, ERROR_NULL_POINTER); + auto subscriberHandler = InputHandler->GetSubscriberHandler(); + CHKPR(subscriberHandler, ERROR_NULL_POINTER); + return subscriberHandler->SubscribeKeyEvent(sess, subscribeId, option); + } + + int32_t ServerMsgHandler::OnUnsubscribeKeyEvent(IUdsServer *server, int32_t pid, int32_t subscribeId) + { + CALL_DEBUG_ENTER; + CHKPR(server, ERROR_NULL_POINTER); + auto sess = server->GetSessionByPid(pid); + CHKPR(sess, ERROR_NULL_POINTER); + auto subscriberHandler = InputHandler->GetSubscriberHandler(); + CHKPR(subscriberHandler, ERROR_NULL_POINTER); + return subscriberHandler->UnsubscribeKeyEvent(sess, subscribeId); + } + + int32_t ServerMsgHandler::OnSubscribeHotkey(IUdsServer *server, int32_t pid, + int32_t subscribeId, const std::shared_ptr option) + { + #ifdef SHORTCUT_KEY_MANAGER_ENABLED + CALL_DEBUG_ENTER; + CHKPR(server, ERROR_NULL_POINTER); + auto sess = server->GetSessionByPid(pid); + CHKPR(sess, ERROR_NULL_POINTER); + auto subscriberHandler = InputHandler->GetSubscriberHandler(); + CHKPR(subscriberHandler, ERROR_NULL_POINTER); + return subscriberHandler->SubscribeHotkey(sess, subscribeId, option); + #else + MMI_HILOGI("OnSubscribeHotkey function does not support"); + return ERROR_UNSUPPORT; + #endif // SHORTCUT_KEY_MANAGER_ENABLED + } + + int32_t ServerMsgHandler::OnUnsubscribeHotkey(IUdsServer *server, int32_t pid, int32_t subscribeId) + { + #ifdef SHORTCUT_KEY_MANAGER_ENABLED + CALL_DEBUG_ENTER; + CHKPR(server, ERROR_NULL_POINTER); + auto sess = server->GetSessionByPid(pid); + CHKPR(sess, ERROR_NULL_POINTER); + auto subscriberHandler = InputHandler->GetSubscriberHandler(); + CHKPR(subscriberHandler, ERROR_NULL_POINTER); + return subscriberHandler->UnsubscribeHotkey(sess, subscribeId); + #else + MMI_HILOGI("OnUnsubscribeHotkey function does not support"); + return ERROR_UNSUPPORT; + #endif // SHORTCUT_KEY_MANAGER_ENABLED + } + #endif // OHOS_BUILD_ENABLE_KEYBOARD + + #ifdef OHOS_BUILD_ENABLE_KEY_PRESSED_HANDLER + int32_t ServerMsgHandler::SubscribeKeyMonitor(int32_t session, const KeyMonitorOption &keyOption) + { + if ((PRODUCT_TYPE != "phone") && (PRODUCT_TYPE != "tablet")) { + MMI_HILOGW("Does not support subscription of key monitor on %{public}s", PRODUCT_TYPE.c_str()); + return -CAPABILITY_NOT_SUPPORTED; + } + KeyMonitorManager::Monitor monitor { + .session_ = session, + .key_ = keyOption.GetKey(), + .action_ = keyOption.GetAction(), + .isRepeat_ = keyOption.IsRepeat(), + }; + return KEY_MONITOR_MGR->AddMonitor(monitor); + } + + int32_t ServerMsgHandler::UnsubscribeKeyMonitor(int32_t session, const KeyMonitorOption &keyOption) + { + if ((PRODUCT_TYPE != "phone") && (PRODUCT_TYPE != "tablet")) { + MMI_HILOGW("Does not support subscription of key monitor on %{public}s", PRODUCT_TYPE.c_str()); + return -CAPABILITY_NOT_SUPPORTED; + } + KeyMonitorManager::Monitor monitor { + .session_ = session, + .key_ = keyOption.GetKey(), + .action_ = keyOption.GetAction(), + .isRepeat_ = keyOption.IsRepeat(), + }; + KEY_MONITOR_MGR->RemoveMonitor(monitor); + return RET_OK; + } + #endif // OHOS_BUILD_ENABLE_KEY_PRESSED_HANDLER + + #ifdef OHOS_BUILD_ENABLE_SWITCH + int32_t ServerMsgHandler::OnSubscribeSwitchEvent( + IUdsServer *server, int32_t pid, int32_t subscribeId, int32_t switchType) + { + CALL_DEBUG_ENTER; + CHKPR(server, ERROR_NULL_POINTER); + auto sess = server->GetSessionByPid(pid); + CHKPR(sess, ERROR_NULL_POINTER); + auto subscriberHandler = InputHandler->GetSwitchSubscriberHandler(); + CHKPR(subscriberHandler, ERROR_NULL_POINTER); + return subscriberHandler->SubscribeSwitchEvent(sess, subscribeId, switchType); + } + + int32_t ServerMsgHandler::OnUnsubscribeSwitchEvent(IUdsServer *server, int32_t pid, int32_t subscribeId) + { + CALL_DEBUG_ENTER; + CHKPR(server, ERROR_NULL_POINTER); + auto sess = server->GetSessionByPid(pid); + CHKPR(sess, ERROR_NULL_POINTER); + auto subscriberHandler = InputHandler->GetSwitchSubscriberHandler(); + CHKPR(subscriberHandler, ERROR_NULL_POINTER); + return subscriberHandler->UnsubscribeSwitchEvent(sess, subscribeId); + } + + int32_t ServerMsgHandler::OnQuerySwitchStatus(int32_t switchType, int32_t& state) + { + CALL_DEBUG_ENTER; + auto subscriberHandler = InputHandler->GetSwitchSubscriberHandler(); + CHKPR(subscriberHandler, ERROR_NULL_POINTER); + return subscriberHandler->QuerySwitchStatus(switchType, state); + } + #endif // OHOS_BUILD_ENABLE_SWITCH + + int32_t ServerMsgHandler::OnSubscribeLongPressEvent(IUdsServer *server, int32_t pid, int32_t subscribeId, + const LongPressRequest &longPressRequest) + { + CALL_DEBUG_ENTER; + CHKPR(server, ERROR_NULL_POINTER); + auto sess = server->GetSessionByPid(pid); + CHKPR(sess, ERROR_NULL_POINTER); + return LONG_PRESS_EVENT_HANDLER->SubscribeLongPressEvent(sess, subscribeId, longPressRequest); + } + + int32_t ServerMsgHandler::OnUnsubscribeLongPressEvent(IUdsServer *server, int32_t pid, int32_t subscribeId) + { + CALL_DEBUG_ENTER; + CHKPR(server, ERROR_NULL_POINTER); + auto sess = server->GetSessionByPid(pid); + CHKPR(sess, ERROR_NULL_POINTER); + return LONG_PRESS_EVENT_HANDLER->UnsubscribeLongPressEvent(sess, subscribeId); + } + + #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) || defined(OHOS_BUILD_ENABLE_KEYBOARD) + int32_t ServerMsgHandler::AddInputEventFilter(sptr filter, + int32_t filterId, int32_t priority, uint32_t deviceTags, int32_t clientPid) + { + auto filterHandler = InputHandler->GetFilterHandler(); + CHKPR(filterHandler, ERROR_NULL_POINTER); + return filterHandler->AddInputEventFilter(filter, filterId, priority, deviceTags, clientPid); + } + + int32_t ServerMsgHandler::RemoveInputEventFilter(int32_t clientPid, int32_t filterId) + { + auto filterHandler = InputHandler->GetFilterHandler(); + CHKPR(filterHandler, ERROR_NULL_POINTER); + return filterHandler->RemoveInputEventFilter(clientPid, filterId); + } + #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH || OHOS_BUILD_ENABLE_KEYBOARD + + #ifdef OHOS_BUILD_ENABLE_KEYBOARD + int32_t ServerMsgHandler::SetShieldStatus(int32_t shieldMode, bool isShield) + { + return KeyEventHdr->SetShieldStatus(shieldMode, isShield); + } + + int32_t ServerMsgHandler::GetShieldStatus(int32_t shieldMode, bool &isShield) + { + return KeyEventHdr->GetShieldStatus(shieldMode, isShield); + } + #endif // OHOS_BUILD_ENABLE_KEYBOARD + + void ServerMsgHandler::LaunchAbility() + { + CALL_DEBUG_ENTER; + #ifndef OHOS_BUILD_ENABLE_WATCH + AUTH_DIALOG.ConnectSystemUi(); + #endif // OHOS_BUILD_ENABLE_WATCH + } + + int32_t ServerMsgHandler::OnAuthorize(bool isAuthorize) + { + CALL_DEBUG_ENTER; + if (isAuthorize) { + auto state = AUTHORIZE_HELPER->GetAuthorizeState(); + int32_t authorPid = AUTHORIZE_HELPER->GetAuthorizePid(); + MMI_HILOGE("OnAuthorize not has authorizing s:%{public}d, authPid:%{public}d", + state, authorPid); + if (state == AuthorizeState::STATE_UNAUTHORIZE) { + MMI_HILOGE("Current not has authorizing"); + return ERR_OK; + } + if (state == AuthorizeState::STATE_UNAUTHORIZE) { + MMI_HILOGE("The injection permission has been granted. authPid:%{public}d ", authorPid); + return ERR_OK; + } + InjectNoticeInfo noticeInfo; + noticeInfo.pid = authorPid; + AddInjectNotice(noticeInfo); + auto result = AUTHORIZE_HELPER->AddAuthorizeProcess(authorPid, [&] (int32_t pid) { + CloseInjectNotice(pid); + }); + if (result != RET_OK) { + MMI_HILOGI("Authorize process failed, pid:%{public}d", authorPid); + } + MMI_HILOGD("Agree to apply injection,pid:%{public}d", authorPid); + return ERR_OK; + } + + auto state = AUTHORIZE_HELPER->GetAuthorizeState(); + int32_t curAuthPid = AUTHORIZE_HELPER->GetAuthorizePid(); + MMI_HILOGD("Reject application injection,s:%{public}d, authPid:%{public}d", + state, curAuthPid); + if (state != AuthorizeState::STATE_UNAUTHORIZE) { + MMI_HILOGI("Cancel injection right,pid:%{public}d", curAuthPid); + AUTHORIZE_HELPER->CancelAuthorize(curAuthPid); + if (state == AuthorizeState::STATE_SELECTION_AUTHORIZE) { + AUTH_DIALOG.CloseDialog(); + } else { + CloseInjectNotice(AUTHORIZE_HELPER->GetAuthorizePid()); + } + } + return ERR_OK; + } + + int32_t ServerMsgHandler::OnCancelInjection(int32_t callPid) + { + CALL_DEBUG_ENTER; + auto state = AUTHORIZE_HELPER->GetAuthorizeState(); + int32_t curAuthPid = AUTHORIZE_HELPER->GetAuthorizePid(); + MMI_HILOGD("Cancel application injection,s:%{public}d, authPid:%{public}d", + state, curAuthPid); + if (state != AuthorizeState::STATE_UNAUTHORIZE) { + if (callPid != curAuthPid) { + MMI_HILOGW("Authorized pid not callPid"); + return COMMON_PERMISSION_CHECK_ERROR; + } + AUTHORIZE_HELPER->CancelAuthorize(curAuthPid); + if (state == AuthorizeState::STATE_SELECTION_AUTHORIZE) { + AUTH_DIALOG.CloseDialog(); + } else { + CloseInjectNotice(AUTHORIZE_HELPER->GetAuthorizePid()); + } + } + return ERR_OK; + } + + void ServerMsgHandler::SetWindowInfo(int32_t infoId, WindowInfo &info) + { + CALL_DEBUG_ENTER; + if (transparentWins_.find(infoId) == transparentWins_.end()) { + MMI_HILOGE("The infoId is Invalid, infoId:%{public}d", infoId); + return; + } + info.pixelMap = transparentWins_[infoId].get(); + } + + int32_t ServerMsgHandler::SetPixelMapData(int32_t infoId, void *pixelMap) __attribute__((no_sanitize("cfi"))) + { + CALL_DEBUG_ENTER; + if (infoId < 0 || pixelMap == nullptr) { + MMI_HILOGE("The infoId is invalid or pixelMap is nullptr"); + return ERR_INVALID_VALUE; + } + + WIN_MGR->SetPixelMapData(infoId, pixelMap); + return RET_OK; + } + + bool ServerMsgHandler::InitInjectNoticeSource() + { + CALL_DEBUG_ENTER; + MMI_HILOGD("Init InjectNoticeSource enter"); + if (injectNotice_ == nullptr) { + injectNotice_ = std::make_shared(); + } + MMI_HILOGD("Injectnotice StartNoticeAbility end"); + if (!injectNotice_->IsAbilityStart()) { + MMI_HILOGD("Injectnotice StartNoticeAbility begin"); + bool isStart = injectNotice_->StartNoticeAbility(); + if (!isStart) { + MMI_HILOGE("Injectnotice StartNoticeAbility isStart:%{public}d", isStart); + return false; + } + MMI_HILOGD("Injectnotice StartNoticeAbility end"); + } + auto connection = injectNotice_->GetConnection(); + CHKPF(connection); + if (!connection->IsConnected()) { + MMI_HILOGD("Injectnotice ConnectNoticeSrv begin"); + bool isConnect = injectNotice_->ConnectNoticeSrv(); + if (!isConnect) { + MMI_HILOGD("Injectnotice ConnectNoticeSrv isConnect:%{public}d", isConnect); + return false; + } + MMI_HILOGD("Injectnotice ConnectNoticeSrv end"); + } + MMI_HILOGD("Injectnotice InitInjectNoticeSource end"); + return true; + } + + bool ServerMsgHandler::AddInjectNotice(const InjectNoticeInfo ¬iceInfo) + { + CALL_DEBUG_ENTER; + bool isInit = InitInjectNoticeSource(); + if (!isInit) { + MMI_HILOGE("InitinjectNotice_ Source error"); + return false; + } + MMI_HILOGD("SendNotice submit begin"); + ffrt::submit([this, noticeInfo] { + MMI_HILOGD("SendNotice submit enter"); + CHKPV(injectNotice_); + auto pConnect = injectNotice_->GetConnection(); + CHKPV(pConnect); + int32_t timeSecond = 0; + while (timeSecond <= SEND_NOTICE_OVERTIME) { + bool isConnect = pConnect->IsConnected(); + MMI_HILOGD("SendNotice %{public}d", isConnect); + if (isConnect) { + MMI_HILOGD("SendNotice begin"); + pConnect->SendNotice(noticeInfo); + break; + } + timeSecond += 1; + sleep(1); + } + MMI_HILOGD("SendNotice submit leave"); + }); + return true; + } + + bool ServerMsgHandler::CloseInjectNotice(int32_t pid) + { + CALL_DEBUG_ENTER; + bool isInit = InitInjectNoticeSource(); + if (!isInit) { + MMI_HILOGE("InitinjectNotice_ Source error"); + return false; + } + MMI_HILOGD("CloseNotice submit begin"); + InjectNoticeInfo noticeInfo; + noticeInfo.pid = pid; + ffrt::submit([this, noticeInfo] { + MMI_HILOGD("CloseNotice submit enter"); + CHKPV(injectNotice_); + auto pConnect = injectNotice_->GetConnection(); + CHKPV(pConnect); + int32_t timeSecond = 0; + while (timeSecond <= SEND_NOTICE_OVERTIME) { + bool isConnect = pConnect->IsConnected(); + MMI_HILOGD("CloseNotice %{public}d", isConnect); + if (isConnect) { + MMI_HILOGD("CloseNotice begin"); + pConnect->CancelNotice(noticeInfo); + break; + } + timeSecond += 1; + sleep(1); + } + MMI_HILOGD("CloseNotice submit leave"); + }); + return true; + } + + int32_t ServerMsgHandler::OnTransferBinderClientSrv(const sptr &binderClientObject, int32_t pid) + { + CALL_DEBUG_ENTER; + bool bRet = clientDeathHandler_.RegisterClientDeathRecipient(binderClientObject, pid); + if (!bRet) { + MMI_HILOGE("Failed to registerClientDeathRecipient"); + return RET_ERR; + } + return ERR_OK; + } + + int32_t ServerMsgHandler::NativeInjectCheck(int32_t pid) + { + CALL_DEBUG_ENTER; + if (PRODUCT_TYPE != PRODUCT_TYPE_PC) { + MMI_HILOGW("Current device has no permission"); + return COMMON_PERMISSION_CHECK_ERROR; + } + bool screenLocked = DISPLAY_MONITOR->GetScreenLocked(); + if (screenLocked) { + MMI_HILOGW("Screen locked, no permission"); + return COMMON_PERMISSION_CHECK_ERROR; + } + if (pid <= 0) { + MMI_HILOGW("Invalid process id pid:%{public}d", pid); + return COMMON_PERMISSION_CHECK_ERROR; + } + auto state = AUTHORIZE_HELPER->GetAuthorizeState(); + MMI_HILOGI("The process is already being processed,s:%{public}d,pid:%{public}d,inputPid:%{public}d", + state, AUTHORIZE_HELPER->GetAuthorizePid(), pid); + if (state == AuthorizeState::STATE_UNAUTHORIZE) { + LaunchAbility(); + AuthorizeExitCallback fnCallback = [&] (int32_t pid) { + MMI_HILOGI("User not authorized to inject pid:%{public}d", pid); + AUTH_DIALOG.CloseDialog(); + }; + AUTHORIZE_HELPER->AddAuthorizeProcess(pid, fnCallback); + return COMMON_PERMISSION_CHECK_ERROR; + } + + if (state == AuthorizeState::STATE_SELECTION_AUTHORIZE) { + if (pid == AUTHORIZE_HELPER->GetAuthorizePid()) { + MMI_HILOGI("The current PID is waiting for user authorization"); + } else { + MMI_HILOGI("Another PID is waiting for user authorization"); + } + return COMMON_PERMISSION_CHECK_ERROR; + } + + // Currently, a process is authorized.state is AuthorizeState::STATE_AUTHORIZE + if (pid != AUTHORIZE_HELPER->GetAuthorizePid()) { + MMI_HILOGI("Other processes have been authorized"); + return COMMON_PERMISSION_CHECK_ERROR; + } + return RET_OK; + } + } // namespace MMI + } // namespace OHOS + \ No newline at end of file diff --git a/service/window_manager/include/input_windows_manager.h b/service/window_manager/include/input_windows_manager.h index 5cbea4cdf6080b243cb2906815165a6661459852..49fa40fb0314552ad69497169d9e2608ca6a207c 100644 --- a/service/window_manager/include/input_windows_manager.h +++ b/service/window_manager/include/input_windows_manager.h @@ -113,10 +113,10 @@ public: void UpdateAndAdjustMouseLocation(int32_t& displayId, double& x, double& y, bool isRealData = true); #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH #ifdef OHOS_BUILD_ENABLE_POINTER - const DisplayGroupInfo& GetDisplayGroupInfo(int32_t groupId = -1); - std::vector GetDisplayInfoVector(int32_t groupId = -1) const; - const std::vector GetWindowInfoVector(int32_t groupId = -1) const; - int32_t GetFocusWindowId(int32_t groupId = -1) const; + void GetDisplayGroupInfo(DisplayGroupInfo& displayGroupInfoCur, int32_t groupId = DEFAULT_GROUP_ID); + std::vector GetDisplayInfoVector(int32_t groupId = DEFAULT_GROUP_ID) const; + const std::vector GetWindowInfoVector(int32_t groupId = DEFAULT_GROUP_ID) const; + int32_t GetFocusWindowId(int32_t groupId = DEFAULT_GROUP_ID) const; int32_t GetLogicalPositionX(int32_t id); int32_t GetLogicalPositionY(int32_t id); Direction GetLogicalPositionDirection(int32_t id); @@ -213,8 +213,9 @@ public: #endif // OHOS_BUILD_ENABLE_ANCO int32_t SetPixelMapData(int32_t infoId, void *pixelMap); - void CleanInvalidPiexMap(int32_t groupId = -1); + void CleanInvalidPiexMap(int32_t groupId = DEFAULT_GROUP_ID); void HandleWindowPositionChange(const DisplayGroupInfo &displayGroupInfo); + void SendCancelEventWhenWindowChange(int32_t pointerId, int32_t groupId = DEFAULT_GROUP_ID); #ifdef OHOS_BUILD_ENABLE_HARDWARE_CURSOR bool IsSupported(); #endif // OHOS_BUILD_ENABLE_HARDWARE_CURSOR @@ -242,7 +243,7 @@ private: void PrintDisplayGroupInfo(const DisplayGroupInfo displayGroupInfo); void PrintDisplayInfo(const DisplayInfo displayInfo); void PrintWindowGroupInfo(const WindowGroupInfo &windowGroupInfo); - void PrintWindowNavbar(int32_t groupId = -1); + void PrintWindowNavbar(int32_t groupId = DEFAULT_GROUP_ID); void CheckFocusWindowChange(const DisplayGroupInfo &displayGroupInfo); void CheckZorderWindowChange(const std::vector &oldWindowsInfo, const std::vector &newWindowsInfo); @@ -284,9 +285,9 @@ private: int32_t UpdateMouseTarget(std::shared_ptr pointerEvent); void UpdatePointerEvent(int32_t logicalX, int32_t logicalY, const std::shared_ptr& pointerEvent, const WindowInfo& touchWindow); - void NotifyPointerToWindow(int32_t groupId = -1); + void NotifyPointerToWindow(int32_t groupId = DEFAULT_GROUP_ID); void OnSessionLost(SessionPtr session); - void InitPointerStyle(int32_t groupId = -1); + void InitPointerStyle(int32_t groupId = DEFAULT_GROUP_ID); #endif // OHOS_BUILD_ENABLE_POINTER #if defined(OHOS_BUILD_ENABLE_POINTER) || defined(OHOS_BUILD_ENABLE_TOUCH) int32_t UpdatePoinerStyle(int32_t pid, int32_t windowId, PointerStyle pointerStyle); @@ -301,7 +302,7 @@ private: const std::shared_ptr& pointerEvent); void CheckUIExtentionWindowPointerHotArea(int32_t logicalX, int32_t logicalY, const std::vector& windowInfos, int32_t& windowId); - std::optional GetWindowInfo(int32_t logicalX, int32_t logicalY, int32_t groupId = -1); + std::optional GetWindowInfo(int32_t logicalX, int32_t logicalY, int32_t groupId = DEFAULT_GROUP_ID); bool IsInsideDisplay(const DisplayInfo& displayInfo, double physicalX, double physicalY); bool CalculateLayout(const DisplayInfo& displayInfo, const Vector2D &physical, Vector2D& layout); void FindPhysicalDisplay(const DisplayInfo& displayInfo, double& physicalX, @@ -316,10 +317,10 @@ private: int32_t logicalX, int32_t logicalY); void UpdatePointerChangeAreas(const DisplayGroupInfo &displayGroupInfo); #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING - void AdjustDisplayRotation(int32_t groupId = -1); + void AdjustDisplayRotation(int32_t groupId = DEFAULT_GROUP_ID); void SetPointerEvent(int32_t pointerAction, std::shared_ptr pointerEvent); void DispatchPointerCancel(int32_t displayId); - void AdjustDragPosition(int32_t groupId = -1); + void AdjustDragPosition(int32_t groupId = DEFAULT_GROUP_ID); #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH @@ -357,7 +358,7 @@ void HandleOneHandMode(const DisplayInfo &displayInfo, std::shared_ptr pointerEvent, const WindowInfo* touchWindow); - void DispatchTouch(int32_t pointerAction, int32_t groupId = -1); + void DispatchTouch(int32_t pointerAction, int32_t groupId = DEFAULT_GROUP_ID); const std::shared_ptr FindPhysicalDisplayInfo(const std::string& uniq) const; bool GetPhysicalDisplayCoord(struct libinput_event_touch* touch, const DisplayInfo& info, EventTouch& touchInfo, bool isNeedClear = false); @@ -392,7 +393,7 @@ void HandleOneHandMode(const DisplayInfo &displayInfo, std::shared_ptr pointerEvent); #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_CROWN - void UpdateDisplayMode(int32_t groupId = -1); + void UpdateDisplayMode(int32_t groupId = DEFAULT_GROUP_ID); void HandleValidDisplayChange(const DisplayGroupInfo &displayGroupInfo); void ResetPointerPositionIfOutValidDisplay(const DisplayGroupInfo &displayGroupInfo); void CancelMouseEvent(); @@ -401,7 +402,7 @@ void HandleOneHandMode(const DisplayInfo &displayInfo, std::shared_ptr keyEvent, int32_t focusWindowId, int32_t groupId = -1); + void UpdateKeyEventDisplayId(std::shared_ptr keyEvent, int32_t focusWindowId, int32_t groupId = DEFAULT_GROUP_ID); bool OnDisplayRemovedOrCombinationChanged(const DisplayGroupInfo &displayGroupInfo); void ChangeWindowArea(int32_t x, int32_t y, WindowInfo &windowInfo); void ResetPointerPosition(const DisplayGroupInfo &displayGroupInfo); @@ -430,7 +431,9 @@ private: int32_t FindDisplayGroupId(int32_t displayId) const; DisplayGroupInfo& GetMainDisplayGroupInfo(); const DisplayGroupInfo& GetConstMainDisplayGroupInfo() const; - const DisplayGroupInfo& FindDisplayGroupInfo(int32_t displayId) const; + void RotateScreen90(const DisplayInfo& info, PhysicalCoordinate& coord) const; + void InitDisplayGroupInfo(DisplayGroupInfo &displayGroupInfo); + void UpdateGroupInfo(); private: UDSServer* udsServer_ { nullptr }; @@ -460,6 +463,7 @@ private: std::weak_ptr touchGestureMgr_; #endif // defined(OHOS_BUILD_ENABLE_TOUCH) && defined(OHOS_BUILD_ENABLE_MONITOR) std::map displayGroupInfoMap_; + std::map displayGroupInfoMapTmp_; bool mainGroupExisted_; DisplayGroupInfo displayGroupInfoTmp_; std::mutex tmpInfoMutex_; @@ -470,7 +474,7 @@ private: std::map> windowsPerDisplayMap_; PointerStyle lastPointerStyle_ {.id = -1}; PointerStyle dragPointerStyle_ {.id = -1}; - MouseLocation mouseLocation_ = { -1, -1 }; + MouseLocation mouseLocation_ = { -1, 0, 0 }; std::map mouseLocationMap_; CursorPosition cursorPos_ {}; std::map cursorPosMap_; @@ -528,7 +532,10 @@ private: #endif // OHOS_BUILD_ENABLE_TOUCH bool IsFoldable_ { false }; int32_t timerId_ { -1 }; + int32_t lastDpi_ { 0 }; + std::map lastDpiMap_; std::shared_ptr GetlastPointerEvent(); + void SetDragFlagByPointer(std::shared_ptr lastPointerEvent); std::mutex mtx_; std::atomic_bool isHPR_ { false }; std::mutex oneHandMtx_; diff --git a/service/window_manager/src/input_windows_manager.cpp b/service/window_manager/src/input_windows_manager.cpp index f0a025f8a25a1949250dc8fff43bb9791a4744fd..25c4ee02be824fc3c1ae3422f5a66a877b66e705 100644 --- a/service/window_manager/src/input_windows_manager.cpp +++ b/service/window_manager/src/input_windows_manager.cpp @@ -6781,5 +6781,6 @@ bool InputWindowsManager::IsAccessibilityEventWithZorderInjected(std::shared_ptr } return false; } +/////add } // namespace MMI } // namespace OHOS diff --git a/service/window_manager/test/input_windows_manager_ex_test.cpp b/service/window_manager/test/input_windows_manager_ex_test.cpp index 2a43f316a11e10bfbe81d454ef4883bb5df4885c..fb67341d92998a6115ef2240b9c57109c75d7346 100644 --- a/service/window_manager/test/input_windows_manager_ex_test.cpp +++ b/service/window_manager/test/input_windows_manager_ex_test.cpp @@ -4140,5 +4140,6 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_SkipPrivacyProtectionW isSkip = false; EXPECT_FALSE(inputWindowsManager->SkipPrivacyProtectionWindow(pointerEvent, isSkip)); } +///add } // namespace MMI } // namespace OHOS \ No newline at end of file diff --git a/service/window_manager/test/input_windows_manager_one_test.cpp b/service/window_manager/test/input_windows_manager_one_test.cpp index 8aff791778940d81225917691e8895cfed665b23..ff2d33e5c821c35b4252069017ffdf080e3a9097 100644 --- a/service/window_manager/test/input_windows_manager_one_test.cpp +++ b/service/window_manager/test/input_windows_manager_one_test.cpp @@ -1453,6 +1453,7 @@ HWTEST_F(InputWindowsManagerOneTest, InputWindowsManagerOneTest_CalcDrawCoordina EXPECT_EQ(result.first, 0); EXPECT_EQ(result.second, 0); } +///add #endif // OHOS_BUILD_ENABLE_TOUCH } // namespace MMI } // namespace OHOS diff --git a/service/window_manager/test/input_windows_manager_test.cpp b/service/window_manager/test/input_windows_manager_test.cpp index 282378ff26c7a78233867a0b886691273af72bf8..4782da401da5d0830382e8d61c207e68fb61257f 100644 --- a/service/window_manager/test/input_windows_manager_test.cpp +++ b/service/window_manager/test/input_windows_manager_test.cpp @@ -4417,13 +4417,18 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateCrownTarget_001, std::shared_ptr inputEvent = InputEvent::Create(); EXPECT_NE(inputEvent, nullptr); inputEvent->targetDisplayId_ = -1; - inputWindowsManager.displayGroupInfo_.focusWindowId = -1; + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.focusWindowId = -1; int32_t ret = inputWindowsManager.UpdateCrownTarget(pointerEvent); EXPECT_NE(ret, RET_OK); inputEvent->targetDisplayId_ = 5; ret = inputWindowsManager.UpdateCrownTarget(pointerEvent); EXPECT_NE(ret, RET_OK); - inputWindowsManager.displayGroupInfo_.focusWindowId = 5; + displayGroupInfoRef.focusWindowId = 5; ret = inputWindowsManager.UpdateCrownTarget(pointerEvent); EXPECT_NE(ret, RET_OK); } @@ -5106,7 +5111,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTouchScreenTarge inputWindowsMgr.extraData_.pointerId = 150; inputWindowsMgr.extraData_.sourceType = PointerEvent::SOURCE_TYPE_TOUCHSCREEN; pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); inputWindowsMgr.windowsPerDisplay_.insert(std::make_pair(100, winGroupInfo)); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.UpdateTouchScreenTarget(pointerEvent)); } @@ -5160,7 +5170,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTouchScreenTarge inputWindowsMgr.extraData_.appended = false; inputWindowsMgr.extraData_.sourceType = PointerEvent::SOURCE_TYPE_MOUSE; pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN); - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); inputWindowsMgr.windowsPerDisplay_.insert(std::make_pair(100, winGroupInfo)); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.UpdateTouchScreenTarget(pointerEvent)); } @@ -5236,7 +5251,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTouchScreenTarge pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); inputWindowsMgr.isOpenAntiMisTakeObserver_ = false; inputWindowsMgr.antiMistake_.isOpen = true; - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); inputWindowsMgr.windowsPerDisplay_.insert(std::make_pair(100, winGroupInfo)); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.UpdateTouchScreenTarget(pointerEvent)); } @@ -5283,7 +5303,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTouchScreenTarge inputWindowsMgr.extraData_.sourceType = PointerEvent::SOURCE_TYPE_TOUCHSCREEN; inputWindowsMgr.isOpenAntiMisTakeObserver_ = true; inputWindowsMgr.antiMistake_.isOpen = false; - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); inputWindowsMgr.windowsPerDisplay_.insert(std::make_pair(100, winGroupInfo)); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.UpdateTouchScreenTarget(pointerEvent)); } @@ -5326,7 +5351,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTouchScreenTarge winGroupInfo.windowsInfo.push_back(winInfo); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN); inputWindowsMgr.extraData_.appended = false; - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); inputWindowsMgr.windowsPerDisplay_.insert(std::make_pair(100, winGroupInfo)); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.UpdateTouchScreenTarget(pointerEvent)); } @@ -5371,7 +5401,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTouchScreenTarge winGroupInfo.windowsInfo.push_back(winInfo); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN); inputWindowsMgr.extraData_.appended = false; - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); inputWindowsMgr.windowsPerDisplay_.insert(std::make_pair(100, winGroupInfo)); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.UpdateTouchScreenTarget(pointerEvent)); } @@ -5414,7 +5449,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTouchScreenTarge winGroupInfo.windowsInfo.push_back(winInfo); pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN); inputWindowsMgr.extraData_.appended = false; - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); inputWindowsMgr.windowsPerDisplay_.insert(std::make_pair(100, winGroupInfo)); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.UpdateTouchScreenTarget(pointerEvent)); } @@ -5460,7 +5500,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTouchScreenTarge pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); inputWindowsMgr.lastTouchEventOnBackGesture_->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL); inputWindowsMgr.extraData_.appended = false; - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); inputWindowsMgr.windowsPerDisplay_.insert(std::make_pair(100, winGroupInfo)); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.UpdateTouchScreenTarget(pointerEvent)); } @@ -5506,7 +5551,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTouchScreenTarge pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN); inputWindowsMgr.lastTouchEventOnBackGesture_->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); inputWindowsMgr.extraData_.appended = false; - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); inputWindowsMgr.windowsPerDisplay_.insert(std::make_pair(100, winGroupInfo)); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.UpdateTouchScreenTarget(pointerEvent)); } @@ -5552,7 +5602,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTouchScreenTarge pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN); inputWindowsMgr.lastTouchEventOnBackGesture_->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL); inputWindowsMgr.extraData_.appended = false; - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); inputWindowsMgr.windowsPerDisplay_.insert(std::make_pair(100, winGroupInfo)); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.UpdateTouchScreenTarget(pointerEvent)); } @@ -5598,7 +5653,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateTouchScreenTarge pointerEvent->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN); inputWindowsMgr.lastTouchEventOnBackGesture_->SetPointerAction(PointerEvent::POINTER_ACTION_CANCEL); inputWindowsMgr.extraData_.appended = false; - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); inputWindowsMgr.windowsPerDisplay_.insert(std::make_pair(100, winGroupInfo)); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.UpdateTouchScreenTarget(pointerEvent)); } @@ -5737,17 +5797,22 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_HandleKeyEventWindowId ASSERT_NE(keyEvent, nullptr); WindowInfo winInfo; keyEvent->SetTargetDisplayId(-1); - inputWindowsMgr.displayGroupInfo_.focusWindowId = 50; + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.focusWindowId = 50; winInfo.id = 50; winInfo.agentWindowId = 100; winInfo.privacyMode = SecureFlag::PRIVACY_MODE; - inputWindowsMgr.displayGroupInfo_.windowsInfo.push_back(winInfo); + displayGroupInfoRef.windowsInfo.push_back(winInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.HandleKeyEventWindowId(keyEvent)); - inputWindowsMgr.displayGroupInfo_.windowsInfo[0].privacyMode = SecureFlag::DEFAULT_MODE; + displayGroupInfoRef.windowsInfo[0].privacyMode = SecureFlag::DEFAULT_MODE; EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.HandleKeyEventWindowId(keyEvent)); - inputWindowsMgr.displayGroupInfo_.focusWindowId = 80; + displayGroupInfoRef.focusWindowId = 80; EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.HandleKeyEventWindowId(keyEvent)); } @@ -5766,7 +5831,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetDisplayId, TestSize DisplayInfo displayInfo; displayInfo.id = 100; inputEvent->SetTargetDisplayId(-1); - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.GetDisplayId(inputEvent)); } @@ -5793,7 +5863,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetClientFd_004, TestS winInfo.uiExtentionWindowInfo.push_back(winInfo); winInfo.pid = 50; winInfo.flags = 15; - inputWindowsMgr.displayGroupInfo_.windowsInfo.push_back(winInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(winInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.GetClientFd(pointerEvent, windowId)); windowId = 100; EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.GetClientFd(pointerEvent, windowId)); @@ -5819,11 +5894,16 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetPidAndUpdateTarget, winInfo.privacyUIFlag = true; winInfo.uiExtentionWindowInfo.push_back(winInfo); keyEvent->SetTargetDisplayId(-1); - inputWindowsMgr.displayGroupInfo_.focusWindowId = 10; - inputWindowsMgr.displayGroupInfo_.windowsInfo.push_back(winInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.focusWindowId = 10; + displayGroupInfoRef.windowsInfo.push_back(winInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.GetPidAndUpdateTarget(keyEvent)); - inputWindowsMgr.displayGroupInfo_.windowsInfo[0].uiExtentionWindowInfo[0].privacyUIFlag = false; + displayGroupInfoRef.windowsInfo[0].uiExtentionWindowInfo[0].privacyUIFlag = false; EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.GetPidAndUpdateTarget(keyEvent)); } @@ -5912,7 +5992,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_DispatchUIExtentionPoi winInfo.agentWindowId = 200; winInfo.uiExtentionWindowInfo.push_back(winInfo); winInfo.id = 300; - inputWindowsMgr.displayGroupInfo_.windowsInfo.push_back(winInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(winInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.DispatchUIExtentionPointerEvent(logicalX, logicalY, pointerEvent)); } @@ -5959,13 +6044,18 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateCrownTarget, Tes std::shared_ptr pointerEvent = PointerEvent::Create(); ASSERT_NE(pointerEvent, nullptr); pointerEvent->SetTargetDisplayId(-1); - inputWindowsMgr.displayGroupInfo_.focusWindowId = 100; + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.focusWindowId = 100; winInfo.id = 200; - inputWindowsMgr.displayGroupInfo_.windowsInfo.push_back(winInfo); + displayGroupInfoRef.windowsInfo.push_back(winInfo); winInfo.id = 100; winInfo.agentWindowId = 500; winInfo.privacyMode = SecureFlag::DEFAULT_MODE; - inputWindowsMgr.displayGroupInfo_.windowsInfo.push_back(winInfo); + displayGroupInfoRef.windowsInfo.push_back(winInfo); EXPECT_EQ(inputWindowsMgr.UpdateCrownTarget(pointerEvent), RET_OK); } #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_CROWN @@ -6057,9 +6147,14 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_ReverseXY_001, TestSiz int32_t y = 100; DisplayInfo displayInfo; displayInfo.direction = static_cast(-1); - inputWindowsMgr.displayGroupInfo_.displaysInfo.push_back(displayInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.ReverseXY(x, y)); - inputWindowsMgr.displayGroupInfo_.displaysInfo[0].direction = static_cast(10); + displayGroupInfoRef.displaysInfo[0].direction = static_cast(10); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.ReverseXY(x, y)); } @@ -6110,11 +6205,16 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_DispatchPointerCancel, inputWindowsMgr.lastPointerEvent_ = PointerEvent::Create(); ASSERT_NE(inputWindowsMgr.lastPointerEvent_, nullptr); winInfo.id = 10; - inputWindowsMgr.displayGroupInfo_.windowsInfo.push_back(winInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(winInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.DispatchPointerCancel(displayId)); - inputWindowsMgr.displayGroupInfo_.windowsInfo.clear(); + displayGroupInfoRef.windowsInfo.clear(); winInfo.id = 100; - inputWindowsMgr.displayGroupInfo_.windowsInfo.push_back(winInfo); + displayGroupInfoRef.windowsInfo.push_back(winInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsMgr.DispatchPointerCancel(displayId)); } @@ -6132,7 +6232,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetPidByWindowId, Test WindowInfo winInfo; winInfo.id = 100; winInfo.pid = 150; - inputWindowsMgr.displayGroupInfo_.windowsInfo.push_back(winInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsMgr.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsMgr.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(winInfo); EXPECT_EQ(inputWindowsMgr.GetPidByWindowId(id), winInfo.pid); id = 300; EXPECT_EQ(inputWindowsMgr.GetPidByWindowId(id), RET_ERR); @@ -6355,7 +6460,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateKeyEventDisplayI EXPECT_EQ(keyEvent->GetTargetDisplayId(), 1); DisplayInfo info1 = {.id = 0, .x = 0, .y = 0, .width = 100, .height = 200}; - inputWindowsManager.displayGroupInfo_.displaysInfo.emplace_back(info1); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.emplace_back(info1); inputWindowsManager.UpdateKeyEventDisplayId(keyEvent, focusWindowId); EXPECT_EQ(keyEvent->GetTargetDisplayId(), 0); } @@ -6376,7 +6486,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_OnDisplayRemovedOrComb DisplayInfo info1 = {.id = 0, .x = 0, .y = 0, .width = 100, .height = 200}; DisplayInfo info2 = {.id = 1, .x = 100, .y = 0, .width = 100, .height = 200}; - inputWindowsManager.displayGroupInfo_.displaysInfo = {info1, info2}; + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo = {info1, info2}; displayGroupInfo.displaysInfo = {info2}; ret = inputWindowsManager.OnDisplayRemovedOrCombinationChanged(displayGroupInfo); EXPECT_TRUE(ret); @@ -6620,7 +6735,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_CleanInvalidPiexMap, T winInfo.id = 10; std::unique_ptr pixelMap = nullptr; inputWindowsManager.transparentWins_.insert_or_assign(windowId, std::move(pixelMap)); - inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(winInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(winInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsManager.CleanInvalidPiexMap()); } @@ -6639,7 +6759,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_CleanInvalidPiexMap_00 winInfo.id = 10; std::unique_ptr pixelMap = nullptr; inputWindowsManager.transparentWins_.insert_or_assign(windowId, std::move(pixelMap)); - inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(winInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(winInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsManager.CleanInvalidPiexMap()); } @@ -6996,8 +7121,13 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_JudgeCaramaInFore_001, WindowInfo windowInfo; windowInfo.id = 20; - inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(windowInfo); - inputWindowsManager.displayGroupInfo_.focusWindowId = 20; + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo); + displayGroupInfoRef.focusWindowId = 20; EXPECT_EQ(inputWindowsManager.JudgeCaramaInFore(), false); } @@ -7269,7 +7399,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetClientFd_010, TestS WindowInfo windowInfo1; windowInfo1.id = 1; windowInfo1.uiExtentionWindowInfo.push_back(windowInfo1); - inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(windowInfo1); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo1); EXPECT_NO_FATAL_FAILURE(inputWindowsManager.GetClientFd(pointerEvent)); } @@ -7292,7 +7427,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetClientFd_011, TestS WindowInfo windowInfo1; windowInfo1.id = 1; - windowInfo1.uiExtentionWindowInfo.push_back(windowInfo1); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo1); inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(windowInfo1); EXPECT_NO_FATAL_FAILURE(inputWindowsManager.GetClientFd(pointerEvent)); @@ -7354,7 +7494,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetWindowPid_002, Test WindowInfo windowInfo2; windowInfo2.id = 1; windowInfo1.uiExtentionWindowInfo.push_back(windowInfo2); - inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(windowInfo1); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo1); EXPECT_NO_FATAL_FAILURE(inputWindowsManager.GetWindowPid(windowId)); } @@ -7375,7 +7520,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetWindowPid_003, Test WindowInfo windowInfo2; windowInfo2.id = 3; windowInfo1.uiExtentionWindowInfo.push_back(windowInfo2); - inputWindowsManager.displayGroupInfo_.windowsInfo.push_back(windowInfo1); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager.displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager.displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo1); EXPECT_NO_FATAL_FAILURE(inputWindowsManager.GetWindowPid(windowId)); } @@ -8569,10 +8719,15 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateCaptureMode_003, DisplayGroupInfo displayGroupInfo; WindowInfo windowInfo; inputWindowsManager->captureModeInfo_.isCaptureMode = true; - inputWindowsManager->displayGroupInfo_.focusWindowId = 25; + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.focusWindowId = 25; displayGroupInfo.focusWindowId = 26; windowInfo.id = 10; - inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo); + displayGroupInfoRef.windowsInfo.push_back(windowInfo); displayGroupInfo.windowsInfo.push_back(windowInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsManager->UpdateCaptureMode(displayGroupInfo)); @@ -8632,7 +8787,13 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_PointerDrawingManagerO displayInfo.dpi++; displayInfo.x = 300; displayInfo.y = 300; - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displayInfo); + inputWindowsManager->lastDpi_ = displayInfo.dpi + 1; + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displayInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsManager->PointerDrawingManagerOnDisplayInfo(displayGroupInfo)); } @@ -8654,7 +8815,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdatePointerDrawingMa DisplayInfo displaysInfo; inputWindowsManager->lastPointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN); inputWindowsManager->lastPointerEvent_->SetButtonPressed(1); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displaysInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displaysInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsManager->UpdatePointerDrawingManagerWindowInfo()); } @@ -8672,7 +8838,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdatePointerDrawingMa EXPECT_NE(inputWindowsManager->lastPointerEvent_, nullptr); DisplayInfo displaysInfo; inputWindowsManager->lastPointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_UNKNOWN); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displaysInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displaysInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsManager->UpdatePointerDrawingManagerWindowInfo()); } @@ -8690,7 +8861,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdatePointerDrawingMa EXPECT_NE(inputWindowsManager->lastPointerEvent_, nullptr); DisplayInfo displaysInfo; inputWindowsManager->lastPointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_PULL_UP); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displaysInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displaysInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsManager->UpdatePointerDrawingManagerWindowInfo()); } @@ -8708,7 +8884,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdatePointerDrawingMa EXPECT_NE(inputWindowsManager->lastPointerEvent_, nullptr); DisplayInfo displaysInfo; inputWindowsManager->lastPointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_BUTTON_UP); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displaysInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displaysInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsManager->UpdatePointerDrawingManagerWindowInfo()); } @@ -8726,7 +8907,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdatePointerDrawingMa EXPECT_NE(inputWindowsManager->lastPointerEvent_, nullptr); DisplayInfo displaysInfo; inputWindowsManager->lastPointerEvent_->SetPointerAction(PointerEvent::POINTER_ACTION_DOWN); - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displaysInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displaysInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsManager->UpdatePointerDrawingManagerWindowInfo()); } @@ -8744,9 +8930,14 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_UpdateDisplayIdAndName displaysInfo.id = 1; displaysInfo.uniqueId = 1; displaysInfo.uniq = "abc"; - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displaysInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displaysInfo); displaysInfo.uniqueId = 1000; - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displaysInfo); + displayGroupInfoRef.displaysInfo.push_back(displaysInfo); inputWindowsManager->bindInfo_.AddDisplay(1, "abc"); inputWindowsManager->bindInfo_.AddDisplay(1, "abc"); @@ -8765,7 +8956,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetCursorPos_003, Test { CALL_TEST_DEBUG; std::shared_ptr inputWindowsManager = std::make_shared(); - inputWindowsManager->cursorPos_.displayId = -1; + CursorPosition cursorPosRef; + auto it = inputWindowsManager->cursorPosMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->cursorPosMap_.end()) { + cursorPosRef = it->second; + } + cursorPosRef.displayId = -1; DisplayInfo displaysInfo; displaysInfo.id = 2; displaysInfo.width = 30; @@ -8774,9 +8970,14 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetCursorPos_003, Test displaysInfo.validHeight = displaysInfo.height; displaysInfo.name = "name2"; displaysInfo.uniq = "uniq2"; - inputWindowsManager->displayGroupInfo_.displaysInfo.push_back(displaysInfo); + DisplayGroupInfo displayGroupInfoRef; + auto iter = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (iter != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = iter->second; + } + displayGroupInfoRef.displaysInfo.push_back(displaysInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsManager->GetCursorPos()); - EXPECT_EQ(inputWindowsManager->cursorPos_.displayId, displaysInfo.id); + EXPECT_EQ(cursorPosRef.displayId, displaysInfo.id); EXPECT_NO_FATAL_FAILURE(inputWindowsManager->GetCursorPos()); } @@ -8790,7 +8991,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_GetCursorPos_004, Test { CALL_TEST_DEBUG; std::shared_ptr inputWindowsManager = std::make_shared(); - inputWindowsManager->cursorPos_.displayId = -1; + CursorPosition cursorPosRef; + auto it = inputWindowsManager->cursorPosMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->cursorPosMap_.end()) { + cursorPosRef = it->second; + } + cursorPosRef.displayId = -1; EXPECT_NO_FATAL_FAILURE(inputWindowsManager->GetCursorPos()); } @@ -8814,9 +9020,14 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_ResetPointerPositionIf displaysInfo.name = "name2"; displaysInfo.uniq = "uniq2"; displayGroupInfo.displaysInfo.push_back(displaysInfo); - inputWindowsManager->cursorPos_.displayId = displaysInfo.id; - inputWindowsManager->cursorPos_.cursorPos.x = 300; - inputWindowsManager->cursorPos_.cursorPos.y = 300; + CursorPosition cursorPosRef; + auto it = inputWindowsManager->cursorPosMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->cursorPosMap_.end()) { + cursorPosRef = it->second; + } + cursorPosRef.displayId = displaysInfo.id; + cursorPosRef.cursorPos.x = 300; + cursorPosRef.cursorPos.y = 300; EXPECT_NO_FATAL_FAILURE(inputWindowsManager->ResetPointerPositionIfOutValidDisplay(displayGroupInfo)); } @@ -8842,7 +9053,12 @@ HWTEST_F( DisplayInfo displaysInfo; displaysInfo.id = 100; pointerEvent->SetTargetDisplayId(displaysInfo.id); - displayGroupInfo.displaysInfo.push_back(displaysInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.displaysInfo.push_back(displaysInfo); pointerEvent->SetSourceType(PointerEvent::SOURCE_TYPE_TOUCHSCREEN); EXPECT_NO_FATAL_FAILURE(inputWindowsManager->CancelTouchScreenEventIfValidDisplayChange(displayGroupInfo)); } @@ -9002,7 +9218,12 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_PrintWindowNavbar_001, WindowInfo windowInfo; windowInfo.id = 20; windowInfo.windowInputType = WindowInputType::MIX_BUTTOM_ANTI_AXIS_MOVE; - inputWindowsManager->displayGroupInfo_.windowsInfo.push_back(windowInfo); + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.push_back(windowInfo); EXPECT_NO_FATAL_FAILURE(inputWindowsManager->PrintWindowNavbar()); } @@ -9193,15 +9414,20 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_CheckAppFocused_001, T windowInfo.pid = pid; windowInfo.id = pid; std::shared_ptr inputWindowsManager = std::make_shared(); - inputWindowsManager->displayGroupInfo_.windowsInfo.clear(); - inputWindowsManager->displayGroupInfo_.windowsInfo.emplace_back(windowInfo); - inputWindowsManager->displayGroupInfo_.focusWindowId = pid; + DisplayGroupInfo displayGroupInfoRef; + auto it = inputWindowsManager->displayGroupInfoMap_.find(DEFAULT_GROUP_ID); + if (it != inputWindowsManager->displayGroupInfoMap_.end()) { + displayGroupInfoRef = it->second; + } + displayGroupInfoRef.windowsInfo.clear(); + displayGroupInfoRef.windowsInfo.emplace_back(windowInfo); + displayGroupInfoRef.focusWindowId = pid; EXPECT_TRUE(inputWindowsManager->CheckAppFocused(pid)); pid++; EXPECT_FALSE(inputWindowsManager->CheckAppFocused(pid)); - inputWindowsManager->displayGroupInfo_.focusWindowId = pid + 1; + displayGroupInfoRef.focusWindowId = pid + 1; EXPECT_FALSE(inputWindowsManager->CheckAppFocused(pid)); } @@ -9246,6 +9472,7 @@ HWTEST_F(InputWindowsManagerTest, InputWindowsManagerTest_CalculateAcrossDirecti ret = inputWindowsManager.CalculateAcrossDirection(displayInfo, layout); EXPECT_EQ(ret, AcrossDirection::ACROSS_ERROR); } +///add #endif // OHOS_BUILD_ENABLE_POINTER || OHOS_BUILD_ENABLE_TOUCH } // namespace MMI } // namespace OHOS diff --git a/util/common/include/define_multimodal.h b/util/common/include/define_multimodal.h index 56347164b0e17141a52ddd1d9650759ba4c2d799..df1747d8a43072980e79cf974cdd2245d739bc55 100644 --- a/util/common/include/define_multimodal.h +++ b/util/common/include/define_multimodal.h @@ -124,6 +124,13 @@ inline constexpr int32_t INVALID_PID { -1 }; } \ } while (0) +#define CHKCC(cond) \ + { \ + if (!(cond)) { \ + continue; \ + } \ + } + #define CHK_PID_AND_TID() \ do { \ MMI_HILOGD("%{public}s, (%{public}d), pid:%{public}d threadId:%{public}" PRIu64, \ @@ -266,6 +273,13 @@ inline constexpr int32_t INVALID_PID { -1 }; } \ } while (0) +#define CHKCC(cond) \ + { \ + if (!(cond)) { \ + continue; \ + } \ + } + #define CHK_PID_AND_TID() \ do { \ MMI_HILOGD("pid:%{public}d threadId:%{public}" PRIu64, GetPid(), GetThisThreadId()); \