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 "data_ability_observer_stub.h" 32 #include "datashare_helper.h" 33 #include "display_change_event_listener.h" 34 #include "display_manager.h" 35 #include "pull_throw_listener.h" 36 #endif // OHOS_BUILD_ENABLE_ARKUI_X 37 #include "devicestatus_define.h" 38 #include "drag_data.h" 39 #include "drag_drawing.h" 40 #include "id_factory.h" 41 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 42 #include "event_hub.h" 43 #include "i_context.h" 44 #include "state_change_notify.h" 45 #else 46 #include "i_drag_manager.h" 47 #endif // OHOS_BUILD_ENABLE_ARKUI_X 48 #ifdef OHOS_BUILD_INTERNAL_DROP_ANIMATION 49 #include "drag_internal_animation_wrapper.h" 50 #endif // OHOS_BUILD_INTERNAL_DROP_ANIMATION 51 52 namespace OHOS { 53 namespace Msdp { 54 namespace DeviceStatus { 55 #ifdef OHOS_ENABLE_PULLTHROW 56 enum class ThrowDirection : int32_t { 57 UP = 1, 58 DOWN, 59 LEFT, 60 RIGHT 61 }; 62 63 enum class ScreenId : int32_t { 64 UPSCREEN = 1, 65 DOWNSCREEN, 66 INVALID 67 }; 68 69 enum class ThrowState : int32_t { 70 NOT_THROW = 0, 71 IN_DOWNSCREEN = 1, 72 IN_UPSCREEN = 2 73 }; 74 #endif // OHOS_ENABLE_PULLTHROW 75 class DragManager : public IDragManager, 76 public IdFactory<int32_t> { 77 public: 78 #ifdef OHOS_BUILD_ENABLE_ARKUI_X 79 static DragManager &GetInstance(); 80 #endif // OHOS_BUILD_ENABLE_ARKUI_X 81 DragManager(); 82 DISALLOW_COPY_AND_MOVE(DragManager); 83 ~DragManager(); 84 std::shared_ptr<MMI::PointerEvent> currentPointerEvent_ { nullptr }; 85 #ifdef OHOS_ENABLE_PULLTHROW 86 ThrowDirection GetThrowDirection(double angle); 87 ScreenId GetScreenId(int32_t displayY); 88 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 89 bool ValidateThrowDirection(ScreenId currentScreen, ThrowDirection throwDir); ValidateThrowConditions()90 bool ValidateThrowConditions() { return listener_.ValidateThrowConditions(); } RegisterPullThrowListener()91 bool RegisterPullThrowListener() override { return listener_.RegisterPullThrowListener(); } RegisterVKListener()92 bool RegisterVKListener() override { return listener_.RegisterVKListener(); } 93 void RegisterVKeyboard(); 94 MMI::ExtraData CreatePullThrowExtraData(bool appended, bool drawCursor, 95 std::shared_ptr<MMI::PointerEvent> pointerEvent); 96 #endif // OHOS_BUILD_ENABLE_ARKUI_X 97 double NormalizeThrowAngle(double angle); 98 int32_t OnPullThrow(std::shared_ptr<MMI::PointerEvent> pointerEvent); 99 void InPullThrow(std::shared_ptr<MMI::PointerEvent> pointerEvent); 100 #endif // OHOS_ENABLE_PULLTHROW 101 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 102 int32_t Init(IContext* context); 103 void OnSessionLost(SocketSessionPtr session); 104 int32_t AddListener(int32_t pid) override; 105 int32_t RemoveListener(int32_t pid) override; 106 int32_t AddSubscriptListener(int32_t pid) override; 107 int32_t RemoveSubscriptListener(int32_t pid) override; 108 int32_t StartDrag( 109 const DragData &dragData, int32_t pid, const std::string &peerNetId = "", 110 bool isLongPressDrag = false, const std::string &appCaller = "") override; 111 #else 112 int32_t StartDrag(const DragData &dragData) override; 113 int32_t UpdatePointerAction(std::shared_ptr<MMI::PointerEvent> pointerEvent); 114 #endif // OHOS_BUILD_ENABLE_ARKUI_X 115 int32_t StopDrag( 116 const DragDropResult &dropResult, const std::string &packageName = "", 117 int32_t pid = -1, bool isStopCooperate = false, const DragRadarPackageName &inPackageName = {}) override; 118 int32_t GetDragTargetPid() const override; 119 int32_t GetUdKey(std::string &udKey) const override; 120 void SendDragData(int32_t targetTid, const std::string &udKey); 121 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 122 void UpdateDragStylePositon() override; 123 int32_t UpdateDragStyle( 124 DragCursorStyle style, int32_t targetPid, int32_t targetTid, int32_t eventId = -1) override; 125 #else 126 int32_t UpdateDragStyle(DragCursorStyle style) override; 127 #endif // OHOS_BUILD_ENABLE_ARKUI_X 128 int32_t UpdateShadowPic(const ShadowInfo &shadowInfo) override; 129 int32_t GetDragData(DragData &dragData) override; 130 int32_t GetDragState(DragState &dragState) override; 131 DragCursorStyle GetDragStyle() const override; 132 void GetAllowDragState(bool &isAllowDrag) override; 133 void DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent); 134 void DragUpCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent, int32_t pointerAction); 135 int32_t OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent); 136 void OnDragCancel(std::shared_ptr<MMI::PointerEvent> pointerEvent); 137 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 138 void OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent); 139 #else 140 int32_t OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent); 141 #endif // OHOS_BUILD_ENABLE_ARKUI_X 142 int32_t OnSetDragWindowVisible(bool visible, bool isForce = false, bool isZoomInAndAlphaChanged = false, 143 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override; 144 MMI::ExtraData GetExtraData(bool appended) const override; 145 int32_t OnGetShadowOffset(ShadowOffset &shadowOffset) override; 146 bool GetControlCollaborationVisible() const override; 147 void SetControlCollaborationVisible(bool visible) override; 148 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 149 void Dump(int32_t fd) const override; 150 void RegisterStateChange(std::function<void(DragState)> callback) override; 151 void UnregisterStateChange() override; 152 void RegisterNotifyPullUp(std::function<void(bool)> callback) override; 153 void UnregisterNotifyPullUp() override; 154 void RegisterCrossDrag(std::function<void(bool)> callback) override; 155 void UnregisterCrossDrag() override; 156 void NotifyCrossDrag(bool isButtonDown) override; 157 bool IsCrossDragging() override; 158 #endif // OHOS_BUILD_ENABLE_ARKUI_X 159 void SetPointerEventFilterTime(int64_t filterTime) override; 160 void MoveTo(int32_t x, int32_t y, bool isMultiSelectedAnimation = true) override; 161 void SetMultiSelectedAnimationFlag(bool needMultiSelectedAnimation) override; 162 DragResult GetDragResult() const override; 163 std::string GetAppCallee() const override; 164 DragState GetDragState() const override; 165 void SetDragState(DragState state) override; 166 void SetDragOriginDpi(float dragOriginDpi) override; 167 int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle) override; 168 int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, 169 const PreviewAnimation &animation) override; 170 int32_t RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override; 171 int32_t GetDragSummary(std::map<std::string, int64_t> &summarys) override; 172 int32_t GetDragSummaryInfo(DragSummaryInfo &dragSummaryInfo) override; 173 void DragKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent); 174 int32_t EnterTextEditorArea(bool enable) override; 175 int32_t GetDragAction(DragAction &dragAction) const override; 176 int32_t GetExtraInfo(std::string &extraInfo) const override; 177 int32_t AddPrivilege(int32_t tokenId) override; 178 int32_t EraseMouseIcon() override; 179 int32_t GetDragBundleInfo(DragBundleInfo &dragBundleInfo) const override; 180 bool IsDragStart() const override; 181 #ifdef OHOS_BUILD_INTERNAL_DROP_ANIMATION 182 int32_t EnableInternalDropAnimation(const std::string &animationInfo) override; 183 void GetDragDrawingInfo(DragInternalInfo &dragInternalInfo) override; 184 void ResetDragState() override; 185 void ResetAnimationParameter() override; 186 #endif // OHOS_BUILD_INTERNAL_DROP_ANIMATION 187 188 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 189 int32_t AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap) override; 190 void SimulatePullCancelEvent() override; 191 #endif // OHOS_BUILD_ENABLE_ARKUI_X 192 int32_t RotateDragWindow(Rosen::DisplayId displayId, Rosen::Rotation rotation) override; 193 void SetRotation(Rosen::DisplayId displayId, Rosen::Rotation rotation) override; 194 Rosen::Rotation GetRotation(Rosen::DisplayId displayId) override; 195 void RemoveDisplayIdFromMap(Rosen::DisplayId displayId) override; 196 int32_t ScreenRotate(Rosen::Rotation rotation, Rosen::Rotation lastRotation) override; 197 void SetDragWindowScreenId(uint64_t displayId, uint64_t screenId) override; 198 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 199 int32_t SetMouseDragMonitorState(bool state) override; 200 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR 201 class InterceptorConsumer : public MMI::IInputEventConsumer { 202 public: InterceptorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb)203 InterceptorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb) 204 : pointerEventCallback_(cb) {} 205 void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 206 void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 207 void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 208 private: 209 std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerEventCallback_ { nullptr }; 210 }; 211 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR 212 213 #ifdef OHOS_DRAG_ENABLE_MONITOR 214 class MonitorConsumer : public MMI::IInputEventConsumer { 215 public: MonitorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb,IContext * context)216 explicit MonitorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb, IContext* context) 217 : pointerEventCallback_(cb), context_(context) {} 218 void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override; 219 void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override; 220 void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override; 221 private: 222 std::function<void (std::shared_ptr<MMI::PointerEvent>)> pointerEventCallback_; 223 IContext* context_ { nullptr }; 224 }; 225 #endif //OHOS_DRAG_ENABLE_MONITOR 226 #else 227 void SetDragWindow(std::shared_ptr<OHOS::Rosen::Window> window) override; 228 void AddDragDestroy(std::function<void()> cb) override; 229 void SetSVGFilePath(const std::string &filePath) override; 230 #endif // OHOS_BUILD_ENABLE_ARKUI_X 231 #ifdef OHOS_ENABLE_PULLTHROW 232 ThrowState throwState_ { ThrowState::NOT_THROW }; 233 #endif // OHOS_ENABLE_PULLTHROW 234 private: 235 std::string GetSummaryFormatStrings(const std::map<std::string, std::vector<int32_t>> &summaryFormat); 236 void PrintDragData(const DragData &dragData, const std::string &packageName = ""); 237 int32_t HandleDragSuccess(bool hasCustomAnimation); 238 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 239 int32_t AddDragEventHandler(int32_t sourceType); 240 int32_t AddPointerEventHandler(uint32_t deviceTags); 241 int32_t AddKeyEventMonitor(); 242 int32_t RemoveDragEventHandler(); 243 int32_t RemoveKeyEventMonitor(); 244 int32_t RemovePointerEventHandler(); 245 int32_t NotifyDragResult(DragResult result, DragBehavior dragBehavior); 246 int32_t NotifyHideIcon(); 247 #endif // OHOS_BUILD_ENABLE_ARKUI_X 248 int32_t InitDataManager(const DragData &dragData, const std::string &appCaller = ""); 249 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 250 int32_t OnStartDrag(const struct DragRadarPackageName &dragRadarPackageName, int32_t pid = -1); 251 #else 252 int32_t OnStartDrag(); 253 #endif // OHOS_BUILD_ENABLE_ARKUI_X 254 int32_t OnStopDrag(DragResult result, bool hasCustomAnimation, const std::string &packageName = "", 255 int32_t pid = -1, bool isStopCooperate = false); 256 std::string GetDragState(DragState value) const; 257 std::string GetDragResult(DragResult value) const; 258 std::string GetDragCursorStyle(DragCursorStyle value) const; 259 static MMI::ExtraData CreateExtraData(bool appended, bool drawCursor = false); 260 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 261 void StateChangedNotify(DragState state); 262 int32_t AddDragEvent(const DragData &dragData, const struct DragRadarPackageName &dragRadarPackageName); 263 #endif // OHOS_BUILD_ENABLE_ARKUI_X 264 void CtrlKeyStyleChangedNotify(DragCursorStyle style, DragAction action); 265 int32_t HandleDragResult(DragResult result, bool hasCustomAnimation); 266 void HandleCtrlKeyEvent(DragCursorStyle style, DragAction action); 267 int32_t OnUpdateDragStyle(DragCursorStyle style); 268 void UpdateDragStyleCross(); 269 inline std::string GetDragStyleName(DragCursorStyle style); 270 DragCursorStyle GetRealDragStyle(DragCursorStyle style); 271 void GetDragBehavior(const DragDropResult &dropResult, DragBehavior &dragBehavior); 272 void DoLongPressDragZoomOutAnimation(int32_t displayX, int32_t displayY); 273 int32_t DealPullInWindowEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent, int32_t targetDisplayId); 274 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 275 int32_t NotifyAddSelectedPixelMapResult(bool result); 276 void ResetMouseDragMonitorInfo(); 277 void ResetMouseDragMonitorTimerId(const DragData &dragData); 278 std::string GetPackageName(int32_t pid); 279 DragRadarPackageName GetDragRadarPackageName(int32_t pid, const std::string &packageName, 280 const std::string &appCaller); 281 #endif // OHOS_BUILD_ENABLE_ARKUI_X 282 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 283 void ReportDragWindowVisibleRadarInfo(StageRes stageRes, DragRadarErrCode errCode, const std::string &funcName); 284 void ReportDragRadarInfo(struct DragRadarInfo &dragRadarInfo); 285 void ReportStartDragRadarInfo(BizState bizState, StageRes stageRes, DragRadarErrCode errCode, 286 const std::string &peerNetId, struct DragRadarPackageName &dragRadarPackageName); 287 void ReportStopDragRadarInfo(BizState bizState, StageRes stageRes, DragRadarErrCode errCode, int32_t pid, 288 struct DragRadarPackageName &dragRadarPackageName); 289 void ReportStartDragFailedRadarInfo(StageRes stageRes, DragRadarErrCode errCode, const std::string &funcName, 290 const struct DragRadarPackageName &dragRadarPackageName); 291 void ReportDragUEInfo(struct DragRadarInfo &dragRadarInfo, const std::string &eventDescription); 292 void ReportStartDragUEInfo(const std::string &packageName); 293 void ReportStopDragUEInfo(const std::string &packageName); 294 #endif // OHOS_BUILD_ENABLE_ARKUI_X 295 #ifdef OHOS_BUILD_ENABLE_ANCO 296 bool IsAncoDragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent, int32_t pointerAction); 297 #endif // OHOS_BUILD_ENABLE_ANCO 298 #ifdef OHOS_ENABLE_PULLTHROW 299 void PullThrowDragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent); 300 #endif // OHOS_ENABLE_PULLTHROW 301 #ifdef OHOS_BUILD_INTERNAL_DROP_ANIMATION 302 int32_t PerformInternalDropAnimation(); 303 #endif // OHOS_BUILD_INTERNAL_DROP_ANIMATION 304 private: 305 #ifdef OHOS_ENABLE_PULLTHROW 306 bool existVkListener_ { false }; 307 bool inHoveringState_ { false }; 308 int32_t dragTimerId_ { -1 }; 309 #endif // OHOS_ENABLE_PULLTHROW 310 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 311 #ifdef OHOS_ENABLE_PULLTHROW 312 PullThrowListener listener_; 313 #endif // OHOS_ENABLE_PULLTHROW 314 #endif // OHOS_BUILD_ENABLE_ARKUI_X 315 std::atomic_bool isFoldPC_ { false }; 316 int32_t timerId_ { -1 }; 317 int32_t mouseDragMonitorTimerId_ { -1 }; 318 #ifdef OHOS_BUILD_INTERNAL_DROP_ANIMATION 319 int32_t internalDropTimerId_ { -1 }; 320 #endif // OHOS_BUILD_INTERNAL_DROP_ANIMATION 321 DragState dragState_ { DragState::STOP }; 322 DragResult dragResult_ { DragResult::DRAG_FAIL }; 323 std::string appCallee_; 324 std::atomic<DragAction> dragAction_ { DragAction::MOVE }; 325 DragDrawing dragDrawing_; 326 bool isControlCollaborationVisible_ { false }; 327 bool isCrossDragging_ {false}; 328 inline static std::atomic<int32_t> pullId_ { -1 }; 329 #ifndef OHOS_BUILD_ENABLE_ARKUI_X 330 StateChangeNotify stateNotify_; 331 int32_t keyEventMonitorId_ { -1 }; 332 IContext* context_ { nullptr }; 333 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR 334 int32_t pointerEventInterceptorId_ { -1 }; 335 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR 336 #ifdef OHOS_DRAG_ENABLE_MONITOR 337 int32_t pointerEventMonitorId_ { -1 }; 338 #endif //OHOS_DRAG_ENABLE_MONITOR 339 SocketSessionPtr dragOutSession_ { nullptr }; 340 std::function<void(DragState)> stateChangedCallback_ { nullptr }; 341 std::function<void(bool)> notifyPUllUpCallback_ { nullptr }; 342 std::function<void(bool)> crossDragCallback_ { nullptr }; 343 std::shared_ptr<EventHub> eventHub_ { nullptr }; 344 sptr<ISystemAbilityStatusChange> statusListener_ { nullptr }; 345 sptr<ISystemAbilityStatusChange> displayAbilityStatusChange_ { nullptr }; 346 sptr<ISystemAbilityStatusChange> appStateObserverStatusChange_ { nullptr }; 347 sptr<ISystemAbilityStatusChange> CollaborationServiceStatusChange_ { nullptr }; 348 #endif // OHOS_BUILD_ENABLE_ARKUI_X 349 bool isRTL_ { false }; 350 uint64_t displayId_ { 0 }; 351 uint64_t screenId_ { 0 }; 352 int32_t lastEventId_ { -1 }; 353 int64_t mouseDragMonitorDisplayX_ { -1 }; 354 int64_t mouseDragMonitorDisplayY_ { -1 }; 355 bool mouseDragMonitorState_ { false }; 356 bool existMouseMoveDragCallback_ { false }; 357 int32_t lastDisplayId_ { -1 }; 358 std::string peerNetId_; 359 bool isLongPressDrag_ { false }; 360 bool needLongPressDragAnimation_ { true }; 361 DragRadarPackageName dragPackageName_; 362 #ifdef OHOS_BUILD_INTERNAL_DROP_ANIMATION 363 std::atomic_bool enableInternalDropAnimation_ { false }; 364 DragInternalAnimationWrapper internalAnimationWrapper_; 365 #endif // OHOS_BUILD_INTERNAL_DROP_ANIMATION 366 }; 367 } // namespace DeviceStatus 368 } // namespace Msdp 369 } // namespace OHOS 370 371 #ifdef OHOS_BUILD_ENABLE_ARKUI_X 372 #define DRAG_MANAGER OHOS::Msdp::DeviceStatus::DragManager::GetInstance() 373 #endif // OHOS_BUILD_ENABLE_ARKUI_X 374 #endif // DRAG_MANAGER_H 375