1 /* 2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DRAG_MANAGER_H 17 #define DRAG_MANAGER_H 18 19 #include <atomic> 20 #include <string> 21 22 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 23 #include "extra_data.h" 24 #include "i_input_event_consumer.h" 25 #include "input_manager.h" 26 #endif // OHOS_BUILD_ENABLE_ARKUI_X 27 #include "pixel_map.h" 28 29 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 30 #include "collaboration_service_status_change.h" 31 #include "display_change_event_listener.h" 32 #endif // OHOS_BUILD_ENABLE_ARKUI_X 33 #include "devicestatus_define.h" 34 #include "drag_data.h" 35 #include "drag_drawing.h" 36 #include "id_factory.h" 37 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 38 #include "event_hub.h" 39 #include "i_context.h" 40 #include "state_change_notify.h" 41 #else 42 #include "i_drag_manager.h" 43 #endif // OHOS_BUILD_ENABLE_ARKUI_X 44 45 namespace OHOS { 46 namespace Msdp { 47 namespace DeviceStatus { 48 class DragManager : public IDragManager, 49 public IdFactory<int32_t> { 50 public: 51 #ifdef OHOS_BUILD_ENABLE_ARKUI_X 52 static DragManager &GetInstance(); 53 #endif // OHOS_BUILD_ENABLE_ARKUI_X 54 DragManager() = default; 55 DISALLOW_COPY_AND_MOVE(DragManager); 56 ~DragManager(); 57 58 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 59 int32_t Init(IContext* context); 60 void OnSessionLost(SocketSessionPtr session); 61 int32_t AddListener(int32_t pid) override; 62 int32_t RemoveListener(int32_t pid) override; 63 int32_t AddSubscriptListener(int32_t pid) override; 64 int32_t RemoveSubscriptListener(int32_t pid) override; 65 int32_t StartDrag( 66 const DragData &dragData, int32_t pid, const std::string &peerNetId = "", 67 bool isLongPressDrag = false, const std::string &appCaller = "") override; 68 #else 69 int32_t StartDrag(const DragData &dragData) override; 70 int32_t UpdatePointerAction(std::shared_ptr<MMI::PointerEvent> pointerEvent); 71 #endif // OHOS_BUILD_ENABLE_ARKUI_X 72 int32_t StopDrag( 73 const DragDropResult &dropResult, const std::string &packageName = "", 74 int32_t pid = -1, bool isStopCooperate = false, const std::string &appCallee = "") override; 75 int32_t GetDragTargetPid() const override; 76 int32_t GetUdKey(std::string &udKey) const override; 77 void SendDragData(int32_t targetTid, const std::string &udKey); 78 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 79 int32_t UpdateDragStyle( 80 DragCursorStyle style, int32_t targetPid, int32_t targetTid, int32_t eventId = -1) override; 81 #else 82 int32_t UpdateDragStyle(DragCursorStyle style) override; 83 #endif // OHOS_BUILD_ENABLE_ARKUI_X 84 int32_t UpdateShadowPic(const ShadowInfo &shadowInfo) override; 85 int32_t GetDragData(DragData &dragData) override; 86 int32_t GetDragState(DragState &dragState) override; 87 DragCursorStyle GetDragStyle() const override; 88 void GetAllowDragState(bool &isAllowDrag) override; 89 void DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent); 90 int32_t OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent); 91 void OnDragCancel(std::shared_ptr<MMI::PointerEvent> pointerEvent); 92 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 93 void OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent); 94 #else 95 int32_t OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent); 96 #endif // OHOS_BUILD_ENABLE_ARKUI_X 97 int32_t OnSetDragWindowVisible(bool visible, bool isForce = false, bool isZoomInAndAlphaChanged = false) override; 98 MMI::ExtraData GetExtraData(bool appended) const override; 99 int32_t OnGetShadowOffset(ShadowOffset &shadowOffset) override; 100 bool GetControlCollaborationVisible() const override; 101 void SetControlCollaborationVisible(bool visible) override; 102 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 103 void Dump(int32_t fd) const override; 104 void RegisterStateChange(std::function<void(DragState)> callback) override; 105 void UnregisterStateChange() override; 106 void RegisterNotifyPullUp(std::function<void(bool)> callback) override; 107 void UnregisterNotifyPullUp() override; 108 void RegisterCrossDrag(std::function<void(bool)> callback) override; 109 void UnregisterCrossDrag() override; 110 void NotifyCrossDrag(bool isButtonDown) override; 111 bool IsCrossDragging() override; 112 #endif // OHOS_BUILD_ENABLE_ARKUI_X 113 void SetPointerEventFilterTime(int64_t filterTime) override; 114 void MoveTo(int32_t x, int32_t y, bool isMultiSelectedAnimation = true) override; 115 void SetMultiSelectedAnimationFlag(bool needMultiSelectedAnimation) override; 116 DragResult GetDragResult() const override; 117 std::string GetAppCallee() const override; 118 DragState GetDragState() const override; 119 void SetDragState(DragState state) override; 120 void SetDragOriginDpi(float dragOriginDpi) override; 121 int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle) override; 122 int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, 123 const PreviewAnimation &animation) override; 124 int32_t RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override; 125 int32_t GetDragSummary(std::map<std::string, int64_t> &summarys) override; 126 void DragKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent); 127 int32_t EnterTextEditorArea(bool enable) override; 128 int32_t GetDragAction(DragAction &dragAction) const override; 129 int32_t GetExtraInfo(std::string &extraInfo) const override; 130 int32_t AddPrivilege(int32_t tokenId) override; 131 int32_t EraseMouseIcon() override; 132 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 133 int32_t AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap) override; 134 #endif // OHOS_BUILD_ENABLE_ARKUI_X 135 int32_t RotateDragWindow(Rosen::Rotation rotation) override; 136 int32_t ScreenRotate(Rosen::Rotation rotation, Rosen::Rotation lastRotation) override; 137 void SetDragWindowScreenId(uint64_t displayId, uint64_t screenId) override; 138 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 139 int32_t SetMouseDragMonitorState(bool state) override; 140 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR 141 class InterceptorConsumer : public MMI::IInputEventConsumer { 142 public: InterceptorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb)143 InterceptorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb) 144 : pointerEventCallback_(cb) {} 145 void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 146 void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 147 void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 148 private: 149 std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerEventCallback_ { nullptr }; 150 }; 151 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR 152 153 #ifdef OHOS_DRAG_ENABLE_MONITOR 154 class MonitorConsumer : public MMI::IInputEventConsumer { 155 public: MonitorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb,IContext * context)156 explicit MonitorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb, IContext* context) 157 : pointerEventCallback_(cb), context_(context) {} 158 void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 159 void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 160 void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 161 private: 162 std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerEventCallback_; 163 IContext* context_ { nullptr }; 164 }; 165 #endif //OHOS_DRAG_ENABLE_MONITOR 166 #else 167 void SetDragWindow(std::shared_ptr<OHOS::Rosen::Window> window) override; 168 void AddDragDestroy(std::function<void()> cb) override; 169 void SetSVGFilePath(const std::string &filePath) override; 170 #endif // OHOS_BUILD_ENABLE_ARKUI_X 171 private: 172 void PrintDragData(const DragData &dragData, const std::string &packageName = ""); 173 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 174 int32_t AddDragEventHandler(int32_t sourceType); 175 int32_t AddPointerEventHandler(uint32_t deviceTags); 176 int32_t AddKeyEventMonitor(); 177 int32_t RemoveDragEventHandler(); 178 int32_t RemoveKeyEventMonitor(); 179 int32_t RemovePointerEventHandler(); 180 int32_t NotifyDragResult(DragResult result, DragBehavior dragBehavior); 181 int32_t NotifyHideIcon(); 182 #endif // OHOS_BUILD_ENABLE_ARKUI_X 183 int32_t InitDataManager(const DragData &dragData, const std::string &appCaller = ""); 184 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 185 int32_t OnStartDrag(const struct DragRadarPackageName &dragRadarPackageName, int32_t pid = -1); 186 #else 187 int32_t OnStartDrag(); 188 #endif // OHOS_BUILD_ENABLE_ARKUI_X 189 int32_t OnStopDrag(DragResult result, bool hasCustomAnimation, const std::string &packageName = "", 190 int32_t pid = -1, bool isStopCooperate = false); 191 std::string GetDragState(DragState value) const; 192 std::string GetDragResult(DragResult value) const; 193 std::string GetDragCursorStyle(DragCursorStyle value) const; 194 static MMI::ExtraData CreateExtraData(bool appended, bool drawCursor = false); 195 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 196 void StateChangedNotify(DragState state); 197 int32_t AddDragEvent(const DragData &dragData, const struct DragRadarPackageName &dragRadarPackageName); 198 #endif // OHOS_BUILD_ENABLE_ARKUI_X 199 void CtrlKeyStyleChangedNotify(DragCursorStyle style, DragAction action); 200 int32_t HandleDragResult(DragResult result, bool hasCustomAnimation); 201 void HandleCtrlKeyEvent(DragCursorStyle style, DragAction action); 202 int32_t OnUpdateDragStyle(DragCursorStyle style); 203 void UpdateDragStyleCross(); 204 inline std::string GetDragStyleName(DragCursorStyle style); 205 DragCursorStyle GetRealDragStyle(DragCursorStyle style); 206 void GetDragBehavior(const DragDropResult &dropResult, DragBehavior &dragBehavior); 207 void DoLongPressDragZoomOutAnimation(int32_t displayX, int32_t displayY); 208 int32_t DealPullInWindowEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent, int32_t targetDisplayId); 209 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 210 int32_t NotifyAddSelectedPixelMapResult(bool result); 211 void ResetMouseDragMonitorInfo(); 212 void ResetMouseDragMonitorTimerId(const DragData &dragData); 213 std::string GetPackageName(int32_t pid); 214 DragRadarPackageName GetDragRadarPackageName(int32_t pid, const std::string &packageName, 215 const std::string &appCaller); 216 #endif // OHOS_BUILD_ENABLE_ARKUI_X 217 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 218 void ReportDragWindowVisibleRadarInfo(StageRes stageRes, DragRadarErrCode errCode, const std::string &funcName); 219 void ReportDragRadarInfo(struct DragRadarInfo &dragRadarInfo); 220 void ReportStartDragRadarInfo(BizState bizState, StageRes stageRes, DragRadarErrCode errCode, 221 const std::string &peerNetId, struct DragRadarPackageName &dragRadarPackageName); 222 void ReportStopDragRadarInfo(BizState bizState, StageRes stageRes, DragRadarErrCode errCode, int32_t pid, 223 struct DragRadarPackageName &dragRadarPackageName); 224 void ReportStartDragFailedRadarInfo(StageRes stageRes, DragRadarErrCode errCode, const std::string &funcName, 225 const struct DragRadarPackageName &dragRadarPackageName); 226 void ReportDragUEInfo(struct DragRadarInfo &dragRadarInfo, const std::string &eventDescription); 227 void ReportStartDragUEInfo(const std::string &packageName); 228 void ReportStopDragUEInfo(const std::string &packageName); 229 #endif // OHOS_BUILD_ENABLE_ARKUI_X 230 private: 231 int32_t timerId_ { -1 }; 232 int32_t mouseDragMonitorTimerId_ { -1 }; 233 DragState dragState_ { DragState::STOP }; 234 DragResult dragResult_ { DragResult::DRAG_FAIL }; 235 std::string appCallee_; 236 std::atomic<DragAction> dragAction_ { DragAction::MOVE }; 237 DragDrawing dragDrawing_; 238 bool isControlCollaborationVisible_ { false }; 239 bool isCrossDragging_ {false}; 240 inline static std::atomic<int32_t> pullId_ { -1 }; 241 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 242 StateChangeNotify stateNotify_; 243 int32_t keyEventMonitorId_ { -1 }; 244 IContext* context_ { nullptr }; 245 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR 246 int32_t pointerEventInterceptorId_ { -1 }; 247 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR 248 #ifdef OHOS_DRAG_ENABLE_MONITOR 249 int32_t pointerEventMonitorId_ { -1 }; 250 #endif //OHOS_DRAG_ENABLE_MONITOR 251 SocketSessionPtr dragOutSession_ { nullptr }; 252 std::function<void(DragState)> stateChangedCallback_ { nullptr }; 253 std::function<void(bool)> notifyPUllUpCallback_ { nullptr }; 254 std::function<void(bool)> crossDragCallback_ { nullptr }; 255 std::shared_ptr<EventHub> eventHub_ { nullptr }; 256 sptr<ISystemAbilityStatusChange> statusListener_ { nullptr }; 257 sptr<ISystemAbilityStatusChange> displayAbilityStatusChange_ { nullptr }; 258 sptr<ISystemAbilityStatusChange> appStateObserverStatusChange_ { nullptr }; 259 sptr<ISystemAbilityStatusChange> CollaborationServiceStatusChange_ { nullptr }; 260 #endif // OHOS_BUILD_ENABLE_ARKUI_X 261 uint64_t displayId_ { 0 }; 262 uint64_t screenId_ { 0 }; 263 int32_t lastEventId_ { -1 }; 264 int64_t mouseDragMonitorDisplayX_ { -1 }; 265 int64_t mouseDragMonitorDisplayY_ { -1 }; 266 bool mouseDragMonitorState_ { false }; 267 bool existMouseMoveDragCallback_ { false }; 268 int32_t lastDisplayId_ { -1 }; 269 std::string peerNetId_; 270 bool isLongPressDrag_ { false }; 271 bool needLongPressDragAnimation_ { true }; 272 std::shared_ptr<MMI::PointerEvent> currentPointerEvent_ { nullptr }; 273 }; 274 } // namespace DeviceStatus 275 } // namespace Msdp 276 } // namespace OHOS 277 278 #ifdef OHOS_BUILD_ENABLE_ARKUI_X 279 #define DRAG_MANAGER OHOS::Msdp::DeviceStatus::DragManager::GetInstance() 280 #endif // OHOS_BUILD_ENABLE_ARKUI_X 281 #endif // DRAG_MANAGER_H 282