• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "drag_manager.h"
17 
18 #include <atomic>
19 
20 #include "display_manager.h"
21 #include "product_name_definition_parser.h"
22 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
23 #include "display_info.h"
24 #include "extra_data.h"
25 #ifdef MSDP_HIVIEWDFX_HITRACE_ENABLE
26 #include "hitrace_meter.h"
27 #endif // MSDP_HIVIEWDFX_HITRACE_ENABLE
28 #endif // OHOS_BUILD_ENABLE_ARKUI_X
29 #include "pixel_map.h"
30 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
31 #ifdef MSDP_FRAMEWORK_UDMF_ENABLED
32 #include "device_manager.h"
33 #include "parameters.h"
34 #include "udmf_client.h"
35 #endif // MSDP_FRAMEWORK_UDMF_ENABLED
36 #include "unified_types.h"
37 #include "window_manager_lite.h"
38 #endif // OHOS_BUILD_ENABLE_ARKUI_X
39 
40 #include <dlfcn.h>
41 #include "devicestatus_define.h"
42 #include "drag_data.h"
43 #include "drag_data_manager.h"
44 #include "drag_hisysevent.h"
45 #include "fi_log.h"
46 #include "devicestatus_proto.h"
47 #include "utility.h"
48 
49 #undef LOG_TAG
50 #define LOG_TAG "DragManager"
51 namespace OHOS {
52 namespace Msdp {
53 namespace DeviceStatus {
54 namespace {
55 constexpr int32_t TIMEOUT_MS { 3000 };
56 constexpr int32_t INTERVAL_MS { 500 };
57 constexpr int32_t POWER_SQUARED { 2 };
58 constexpr int32_t TEN_POWER { 10 * 10 };
59 std::atomic<int64_t> g_startFilterTime { -1 };
60 const std::string DRAG_STYLE_DEFAULT {"DEFAULT"};
61 const std::string DRAG_STYLE_FORBIDDEN {"FORBIDDEN"};
62 const std::string DRAG_STYLE_COPY {"COPY"};
63 const std::string DRAG_STYLE_MOVE {"MOVE"};
64 const std::string DRAG_STYLE_UNKNOW {"UNKNOW"};
65 const std::string DRAG_BEHAVIOR {"DRAG_BEHAVIOR"};
66 const std::string ORG_PKG_NAME {"device_status"};
67 const std::string APP_VERSION_ID {"1.0.0"};
68 const std::string DRAG_FRAMEWORK {"DRAG_FRAMEWORK"};
69 const std::string START_CROSSING_DRAG {"START_CROSSING_DRAG"};
70 const std::string END_CROSSING_DRAG {"END_CROSSING_DRAG"};
71 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
72 const std::string LANGUAGE_KEY {"persist.global.language"};
73 const std::string DEFAULT_LANGUAGE_KEY {"const.global.language"};
74 static std::map<std::string, std::string> g_rtlLanguageMap {
75     { "ar", "arabic" },
76     { "fa", "persian" },
77     { "ur", "urdu" },
78     { "he", "hebrew" },
79     { "ug", "uyghur" },
80 };
81 const std::string PRODUCT_TYPE = OHOS::system::GetParameter("const.build.product", "HYM");
82 #endif // OHOS_BUILD_ENABLE_ARKUI_X
83 #ifdef OHOS_ENABLE_PULLTHROW
84 // 屏幕坐标常量
85 constexpr int32_t UP_SCREEN_MAX_Y { 1608 };       // 上屏最大 Y 坐标
86 constexpr int32_t DOWN_SCREEN_MIN_Y { 1690 };     // 下屏最小 Y 坐标
87 constexpr int32_t DOWN_SCREEN_MAX_Y { 3296 };     // 下屏最大 Y 坐标
88 constexpr int32_t TARGET_X { 1236 };              // 目标 X 坐标
89 constexpr int32_t TARGET_Y_DOWN { 1800 };         // 下屏目标 Y 坐标
90 constexpr int32_t TARGET_Y_UP { 1500 };           // 上屏目标 Y 坐标
91 constexpr int32_t TIMER_TIMEOUT_MS { 30000 };     // 定时器超时值,30秒
92 
93 // 角度常量
94 constexpr double ANGLE_DOWN_MIN { 45.0 };         // 下方角度范围最小值
95 constexpr double ANGLE_DOWN_MAX { 135.0 };        // 下方角度范围最大值
96 constexpr double ANGLE_UP_MIN { 225.0 };          // 上方角度范围最小值
97 constexpr double ANGLE_UP_MAX { 315.0 };          // 上方角度范围最大值
98 constexpr double ANGLE_LEFT_MIN { 135.0 };        // 左方角度范围最小值
99 constexpr double ANGLE_LEFT_MAX { 225.0 };        // 左方角度范围最大值
100 constexpr double FULL_CIRCLE_DEGREES = { 360.0 };
101 constexpr double ANGLE_EPSILON {1e-9};
102 #endif // OHOS_ENABLE_PULLTHROW
103 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
104 constexpr int32_t DRAG_PRIORITY { 500 };
105 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
106 } // namespace
107 
108 #ifdef OHOS_BUILD_ENABLE_ARKUI_X
GetInstance()109 DragManager &DragManager::GetInstance()
110 {
111     static DragManager instance;
112     return instance;
113 }
114 #endif // OHOS_BUILD_ENABLE_ARKUI_X
115 #ifdef OHOS_ENABLE_PULLTHROW
DragManager()116 DragManager::DragManager() : listener_(this) {}
117 #else
DragManager()118 DragManager::DragManager() {}
119 #endif // OHOS_ENABLE_PULLTHROW
~DragManager()120 DragManager::~DragManager()
121 {
122 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
123     EventHub::UnRegisterEvent(eventHub_);
124 #endif // OHOS_BUILD_ENABLE_ARKUI_X
125 }
126 
127 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
Init(IContext * context)128 int32_t DragManager::Init(IContext* context)
129 {
130     FI_HILOGI("enter");
131     CHKPR(context, RET_ERR);
132     context_ = context;
133     int32_t repeatCount = 1;
134     context_->GetTimerManager().AddTimer(INTERVAL_MS, repeatCount, [this]() {
135         if (eventHub_ == nullptr) {
136             eventHub_ = EventHub::GetEventHub(context_);
137         }
138         auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
139         if (samgrProxy == nullptr) {
140             FI_HILOGE("samgrProxy is nullptr");
141             return;
142         }
143         statusListener_ = new (std::nothrow) DragAbilityStatusChange(eventHub_);
144         if (statusListener_ == nullptr) {
145             FI_HILOGE("statusListener_ is nullptr");
146             return;
147         }
148         int32_t ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusListener_);
149         FI_HILOGI("SubscribeSystemAbility COMMON_EVENT_SERVICE_ID result:%{public}d", ret);
150         displayAbilityStatusChange_ = new (std::nothrow) DisplayAbilityStatusChange(context_);
151         if (displayAbilityStatusChange_ == nullptr) {
152             FI_HILOGE("displayAbilityStatusChange is nullptr");
153             return;
154         }
155         ret = samgrProxy->SubscribeSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, displayAbilityStatusChange_);
156         FI_HILOGI("SubscribeSystemAbility DISPLAY_MANAGER_SERVICE_SA_ID result:%{public}d", ret);
157         appStateObserverStatusChange_ = new (std::nothrow) AppStateObserverStatusChange(context_);
158         if (appStateObserverStatusChange_ == nullptr) {
159             FI_HILOGE("appStateObserverStatusChange_ is nullptr");
160             return;
161         }
162         ret = samgrProxy->SubscribeSystemAbility(APP_MGR_SERVICE_ID, appStateObserverStatusChange_);
163         FI_HILOGI("SubscribeSystemAbility APP_MGR_SERVICE_ID result:%{public}d", ret);
164         CollaborationServiceStatusChange_ = new (std::nothrow) CollaborationServiceStatusChange(context_);
165         if (CollaborationServiceStatusChange_ == nullptr) {
166             FI_HILOGE("CollaborationServiceStatusChange_ is nullptr");
167             return;
168         }
169         ret = samgrProxy->SubscribeSystemAbility(DEVICE_COLLABORATION_SA_ID, CollaborationServiceStatusChange_);
170         FI_HILOGI("SubscribeSystemAbility DEVICE_COLLABORATION_SA_ID result:%{public}d", ret);
171     });
172     FI_HILOGI("leave");
173     return RET_OK;
174 }
175 
OnSessionLost(SocketSessionPtr session)176 void DragManager::OnSessionLost(SocketSessionPtr session)
177 {
178     CHKPV(session);
179     RemoveListener(session->GetPid());
180 }
181 
AddListener(int32_t pid)182 int32_t DragManager::AddListener(int32_t pid)
183 {
184     FI_HILOGI("enter");
185     CHKPR(context_, RET_ERR);
186     auto session = context_->GetSocketSessionManager().FindSessionByPid(pid);
187     CHKPR(session, RET_ERR);
188     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
189     info->session = session;
190     info->msgId = MessageId::DRAG_STATE_LISTENER;
191     info->msgType = MessageType::NOTIFY_STATE;
192     stateNotify_.AddNotifyMsg(info);
193     context_->GetSocketSessionManager().AddSessionDeletedCallback(pid,
194         [this](SocketSessionPtr session) { this->OnSessionLost(session); });
195     FI_HILOGI("leave");
196     return RET_OK;
197 }
198 
RemoveListener(int32_t pid)199 int32_t DragManager::RemoveListener(int32_t pid)
200 {
201     FI_HILOGI("Remove listener, pid:%{public}d", pid);
202     CHKPR(context_, RET_ERR);
203     auto session = context_->GetSocketSessionManager().FindSessionByPid(pid);
204     CHKPR(session, RET_ERR);
205     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
206     info->session = session;
207     info->msgType = MessageType::NOTIFY_STATE;
208     stateNotify_.RemoveNotifyMsg(info);
209     FI_HILOGI("leave");
210     return RET_OK;
211 }
212 
AddSubscriptListener(int32_t pid)213 int32_t DragManager::AddSubscriptListener(int32_t pid)
214 {
215     FI_HILOGI("enter");
216     CHKPR(context_, RET_ERR);
217     auto session = context_->GetSocketSessionManager().FindSessionByPid(pid);
218     CHKPR(session, RET_ERR);
219     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
220     info->session = session;
221     info->msgId = MessageId::DRAG_STYLE_LISTENER;
222     info->msgType = MessageType::NOTIFY_STYLE;
223     stateNotify_.AddNotifyMsg(info);
224     FI_HILOGI("leave");
225     return RET_OK;
226 }
227 
RemoveSubscriptListener(int32_t pid)228 int32_t DragManager::RemoveSubscriptListener(int32_t pid)
229 {
230     FI_HILOGI("enter");
231     CHKPR(context_, RET_ERR);
232     auto session = context_->GetSocketSessionManager().FindSessionByPid(pid);
233     CHKPR(session, RET_ERR);
234     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
235     info->msgType = MessageType::NOTIFY_STYLE;
236     info->session = session;
237     stateNotify_.RemoveNotifyMsg(info);
238     FI_HILOGI("leave");
239     return RET_OK;
240 }
241 #endif // OHOS_BUILD_ENABLE_ARKUI_X
242 
GetSummaryFormatStrings(const std::map<std::string,std::vector<int32_t>> & summaryFormat)243 std::string DragManager::GetSummaryFormatStrings(const std::map<std::string, std::vector<int32_t>> &summaryFormat)
244 {
245     std::string summaryFormatStrings;
246     for (const auto &[udKey, format] : summaryFormat) {
247         summaryFormatStrings += udKey + ":";
248         if (!format.empty()) {
249             for (auto const &udsType : format) {
250                 summaryFormatStrings += "_" +  std::to_string(static_cast<int32_t>(udsType));
251             }
252             summaryFormatStrings += ",";
253         }
254     }
255     return summaryFormatStrings;
256 }
257 
PrintDragData(const DragData & dragData,const std::string & packageName)258 void DragManager::PrintDragData(const DragData &dragData, const std::string &packageName)
259 {
260     FI_HILOGI("enter");
261     for (const auto& shadowInfo : dragData.shadowInfos) {
262         CHKPV(shadowInfo.pixelMap);
263         FI_HILOGI("PixelFormat:%{public}d, PixelAlphaType:%{public}d, PixelAllocatorType:%{public}d,"
264             " PixelWidth:%{public}d, PixelHeight:%{public}d, shadowX:%{public}d, shadowY:%{public}d",
265             static_cast<int32_t>(shadowInfo.pixelMap->GetPixelFormat()),
266             static_cast<int32_t>(shadowInfo.pixelMap->GetAlphaType()),
267             static_cast<int32_t>(shadowInfo.pixelMap->GetAllocatorType()),
268             shadowInfo.pixelMap->GetWidth(), shadowInfo.pixelMap->GetHeight(), shadowInfo.x, shadowInfo.y);
269     }
270     std::string summarys;
271     for (const auto &[udKey, recordSize] : dragData.summarys) {
272         std::string str = udKey + "-" + std::to_string(recordSize) + ";";
273         summarys += str;
274     }
275 
276     std::string detailedSummarys;
277     for (const auto &[udKey, recordSize] : dragData.detailedSummarys) {
278         std::string str = udKey + "-" + std::to_string(recordSize) + ";";
279         detailedSummarys += str;
280     }
281     std::string summaryFormat = GetSummaryFormatStrings(dragData.summaryFormat);
282     FI_HILOGI("SourceType:%{public}d, pointerId:%{public}d, displayId:%{public}d,"
283         " displayX:%{private}d, displayY:%{private}d, dragNum:%{public}d,"
284         " hasCanceledAnimation:%{public}d, udKey:%{public}s, hasCoordinateCorrected:%{public}d, summarys:%{public}s,"
285         " packageName:%{public}s, isDragDelay:%{public}d, detailedSummarys:%{public}s, summaryFormat:%{public}s,"
286         " summaryVersion:%{public}d, totalSize:%{public} " PRId64 "", dragData.sourceType, dragData.pointerId,
287         dragData.displayId, dragData.displayX, dragData.displayY, dragData.dragNum, dragData.hasCanceledAnimation,
288         GetAnonyString(dragData.udKey).c_str(), dragData.hasCoordinateCorrected, summarys.c_str(),
289         GetAnonyString(packageName).c_str(), dragData.isDragDelay, detailedSummarys.c_str(), summaryFormat.c_str(),
290         dragData.summaryVersion, dragData.summaryTotalSize);
291 }
292 
293 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
ResetMouseDragMonitorTimerId(const DragData & dragData)294 void DragManager::ResetMouseDragMonitorTimerId(const DragData &dragData)
295 {
296     if ((context_ != nullptr) && (mouseDragMonitorTimerId_ >= 0) &&
297         (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE)) {
298         context_->GetTimerManager().RemoveTimer(mouseDragMonitorTimerId_);
299         mouseDragMonitorTimerId_ = -1;
300     }
301 }
302 
GetPackageName(int32_t pid)303 std::string DragManager::GetPackageName(int32_t pid)
304 {
305     CHKPS(context_);
306     std::string packageName = std::string();
307     if (pid == -1) {
308         packageName = "Cross-device drag";
309     } else {
310         context_->GetSocketSessionManager().AddSessionDeletedCallback(pid,
311             [this](SocketSessionPtr session) { this->OnSessionLost(session); });
312         dragOutSession_ = context_->GetSocketSessionManager().FindSessionByPid(pid);
313         if (dragOutSession_ != nullptr) {
314             packageName = dragOutSession_->GetProgramName();
315         }
316     }
317     return packageName;
318 }
319 
IsCrossDragging()320 bool DragManager::IsCrossDragging()
321 {
322     return isCrossDragging_;
323 }
324 
GetDragRadarPackageName(int32_t pid,const std::string & packageName,const std::string & appCaller)325 DragRadarPackageName DragManager::GetDragRadarPackageName(int32_t pid, const std::string &packageName,
326     const std::string &appCaller)
327 {
328     FI_HILOGI("enter");
329     DragRadarPackageName dragRadarPackageName;
330     dragRadarPackageName.packageName = packageName;
331     if (pid == -1) {
332         dragRadarPackageName.appCaller = appCaller;
333     } else {
334         dragRadarPackageName.appCaller = packageName;
335     }
336     FI_HILOGI("leave");
337     return dragRadarPackageName;
338 }
339 
StartDrag(const DragData & dragData,int32_t pid,const std::string & peerNetId,bool isLongPressDrag,const std::string & appCaller)340 int32_t DragManager::StartDrag(
341     const DragData &dragData, int32_t pid, const std::string &peerNetId, bool isLongPressDrag,
342     const std::string &appCaller)
343 {
344     FI_HILOGI("enter");
345     ResetMouseDragMonitorTimerId(dragData);
346     if (pid == -1) {
347         isCrossDragging_ = true;
348     } else {
349         isCrossDragging_ = false;
350     }
351     if (dragState_ == DragState::START || dragState_ == DragState::MOTION_DRAGGING) {
352         FI_HILOGE("Drag instance already exists, no need to start drag again");
353         return RET_ERR;
354     }
355     peerNetId_ = peerNetId;
356     lastDisplayId_ = dragData.displayId;
357     std::string packageName = GetPackageName(pid);
358     DragRadarPackageName dragRadarPackageName = GetDragRadarPackageName(pid, packageName, appCaller);
359     dragRadarPackageName.dragNum = dragData.dragNum;
360     ReportStartDragRadarInfo(BizState::STATE_BEGIN, StageRes::RES_IDLE, DragRadarErrCode::DRAG_SUCCESS, peerNetId,
361         dragRadarPackageName);
362     dragPackageName_ = dragRadarPackageName;
363     PrintDragData(dragData, packageName);
364     if (InitDataManager(dragData, dragRadarPackageName.appCaller) != RET_OK) {
365         FI_HILOGE("Failed to init data manager");
366         ResetMouseDragMonitorInfo();
367         ReportStartDragFailedRadarInfo(StageRes::RES_FAIL, DragRadarErrCode::INVALID_DRAG_DATA, __func__,
368             dragRadarPackageName);
369         return RET_ERR;
370     }
371     isLongPressDrag_ = isLongPressDrag;
372     if (OnStartDrag(dragRadarPackageName, pid) != RET_OK) {
373 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
374         DragDFX::WriteStartDrag(dragState_, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
375 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
376         FI_HILOGE("Failed to execute OnStartDrag");
377         ResetMouseDragMonitorInfo();
378         return RET_ERR;
379     }
380     if (notifyPUllUpCallback_ != nullptr) {
381         notifyPUllUpCallback_(false);
382     }
383     SetDragState(DragState::START);
384     dragDrawing_.OnStartDragExt();
385     stateNotify_.StateChangedNotify(DragState::START);
386     StateChangedNotify(DragState::START);
387     ReportStartDragRadarInfo(BizState::STATE_IDLE, StageRes::RES_SUCCESS, DragRadarErrCode::DRAG_SUCCESS, peerNetId,
388         dragRadarPackageName);
389     if (pid == -1) {
390         ReportStartDragUEInfo(packageName);
391     }
392     FI_HILOGI("leave");
393     return RET_OK;
394 }
395 #else
StartDrag(const DragData & dragData)396 int32_t DragManager::StartDrag(const DragData &dragData)
397 {
398     CALL_INFO_TRACE;
399     if (dragState_ == DragState::START) {
400         FI_HILOGE("Drag instance already exists, no need to start drag again");
401         return RET_ERR;
402     }
403     std::string packageName;
404     PrintDragData(dragData, packageName);
405 
406     if (InitDataManager(dragData) != RET_OK) {
407         FI_HILOGE("Failed to init data manager");
408         return RET_ERR;
409     }
410     if (OnStartDrag() != RET_OK) {
411 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
412 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
413         DragDFX::WriteStartDrag(dragState_, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
414 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
415 #endif // OHOS_BUILD_ENABLE_ARKUI_X
416         FI_HILOGE("Failed to execute OnStartDrag");
417         return RET_ERR;
418     }
419     SetDragState(DragState::START);
420     return RET_OK;
421 }
422 
UpdatePointerAction(std::shared_ptr<MMI::PointerEvent> pointerEvent)423 int32_t DragManager::UpdatePointerAction(std::shared_ptr<MMI::PointerEvent> pointerEvent)
424 {
425     CALL_INFO_TRACE;
426     CHKPR(pointerEvent, RET_ERR);
427     if (dragState_ != DragState::START || dragState_ == DragState::MOTION_DRAGGING) {
428         FI_HILOGE("ARKUI_X DragState not started");
429         return RET_ERR;
430     }
431 
432     int32_t action = pointerEvent->GetPointerAction();
433     switch (action) {
434         case MMI::PointerEvent::POINTER_ACTION_MOVE: {
435             pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_MOVE);
436             FI_HILOGD("ARKUI_X UpdatePointAction to POINTER_ACTION_PULL_MOVE");
437             return OnDragMove(pointerEvent);
438         }
439         case MMI::PointerEvent::POINTER_ACTION_BUTTON_UP:
440         case MMI::PointerEvent::POINTER_ACTION_UP: {
441             pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_UP);
442             FI_HILOGD("ARKUI_X UpdatePointAction to POINTER_ACTION_PULL_UP");
443             return OnDragUp(pointerEvent);
444         }
445         default: {
446             FI_HILOGD("ARKUI_X unknown action:%{public}d", action);
447             return RET_ERR;
448         }
449     }
450     return RET_OK;
451 }
452 
OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent)453 int32_t DragManager::OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent)
454 {
455     CALL_DEBUG_ENTER;
456     CHKPR(pointerEvent, RET_ERR);
457     MMI::PointerEvent::PointerItem pointerItem;
458     int32_t pointerId = pointerEvent->GetPointerId();
459     if (!pointerEvent->GetPointerItem(pointerId, pointerItem)) {
460         FI_HILOGE("ARKUI_X GetPointerItem fail");
461         return RET_ERR;
462     }
463 
464     int32_t displayX = pointerItem.GetDisplayX();
465     int32_t displayY = pointerItem.GetDisplayY();
466     int32_t sourceType = pointerEvent->GetSourceType();
467     dragDrawing_.OnDragMove(pointerEvent->GetTargetDisplayId(), displayX,
468         displayY, pointerEvent->GetActionTime());
469     FI_HILOGD("ARKUI_X SourceType:%{public}d, pointerId:%{public}d, displayX:%{private}d, displayY:%{private}d",
470         sourceType, pointerId, displayX, displayY);
471 
472     return RET_OK;
473 }
474 #endif // OHOS_BUILD_ENABLE_ARKUI_X
475 
StopDrag(const DragDropResult & dropResult,const std::string & packageName,int32_t pid,bool isStopCooperate,const DragRadarPackageName & inPackageName)476 int32_t DragManager::StopDrag(const DragDropResult &dropResult, const std::string &packageName, int32_t pid,
477     bool isStopCooperate, const DragRadarPackageName &inPackageName)
478 {
479     FI_HILOGI("enter");
480 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
481     DragRadarPackageName dragRadarPackageName;
482     dragRadarPackageName.packageName = packageName;
483     if (pid == -1) {
484         dragRadarPackageName.appCallee = inPackageName.appCallee;
485         dragRadarPackageName.peerNetId = inPackageName.peerNetId;
486     } else {
487         dragRadarPackageName.appCallee = packageName;
488     }
489     DragData dragData = DRAG_DATA_MGR.GetDragData();
490     dragRadarPackageName.dragNum = dragData.dragNum;
491     ReportStopDragRadarInfo(BizState::STATE_IDLE, StageRes::RES_IDLE, DragRadarErrCode::DRAG_SUCCESS, pid,
492         dragRadarPackageName);
493     std::string dragOutPkgName =
494         (dragOutSession_ == nullptr) ? "Cross-device drag" : dragOutSession_->GetProgramName();
495     FI_HILOGI("mainWindow:%{public}d, dragResult:%{public}d, drop packageName:%{public}s,"
496         "drag out packageName:%{public}s", dropResult.mainWindow, dropResult.result, packageName.c_str(),
497         dragOutPkgName.c_str());
498     if (dragState_ == DragState::STOP) {
499         FI_HILOGE("No drag instance running, can not stop drag");
500         ReportStopDragRadarInfo(BizState::STATE_END, StageRes::RES_FAIL, DragRadarErrCode::REPEATE_STOP_DRAG_EXCEPTION,
501             pid, dragRadarPackageName);
502         return RET_ERR;
503     }
504 #ifdef OHOS_DRAG_ENABLE_ANIMATION
505     dragDrawing_.NotifyDragInfo(dragOutPkgName, packageName);
506 #endif // OHOS_DRAG_ENABLE_ANIMATION
507     if ((dropResult.result != DragResult::DRAG_EXCEPTION) && (context_ != nullptr) && (timerId_ >= 0)) {
508         context_->GetTimerManager().RemoveTimer(timerId_);
509         timerId_ = -1;
510     }
511 #endif // OHOS_BUILD_ENABLE_ARKUI_X
512     int32_t ret = RET_OK;
513     if (OnStopDrag(dropResult.result, dropResult.hasCustomAnimation, packageName, pid, isStopCooperate) != RET_OK) {
514 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
515 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
516         DragDFX::WriteStopDrag(dragState_, dropResult, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
517 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
518 #endif // OHOS_BUILD_ENABLE_ARKUI_X
519         FI_HILOGE("On stop drag failed");
520         ret = RET_ERR;
521     }
522 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
523     if (dropResult.result == DragResult::DRAG_SUCCESS && dropResult.mainWindow > 0) {
524         Rosen::WMError result = Rosen::WindowManagerLite::GetInstance().RaiseWindowToTop(dropResult.mainWindow);
525         if (result != Rosen::WMError::WM_OK) {
526             FI_HILOGE("Raise window to top failed, mainWindow:%{public}d", dropResult.mainWindow);
527         }
528     }
529     stateNotify_.StateChangedNotify(DragState::STOP);
530     DragBehavior dragBehavior = dropResult.dragBehavior;
531     GetDragBehavior(dropResult, dragBehavior);
532     if (NotifyDragResult(dropResult.result, dragBehavior) != RET_OK) {
533         FI_HILOGE("Notify drag result failed");
534         ReportStopDragRadarInfo(BizState::STATE_IDLE, StageRes::RES_FAIL, DragRadarErrCode::FAILED_NOTIFY_DRAG_RESULT,
535             pid, dragRadarPackageName);
536     }
537     lastDisplayId_ = -1;
538     lastEventId_ = -1;
539     mouseDragMonitorDisplayX_ = -1;
540     mouseDragMonitorDisplayY_ = -1;
541     mouseDragMonitorState_ = false;
542     existMouseMoveDragCallback_ = false;
543     needLongPressDragAnimation_ = true;
544     isLongPressDrag_ = false;
545     currentPointerEvent_ = nullptr;
546     isRTL_ = false;
547 #ifdef OHOS_ENABLE_PULLTHROW
548     inHoveringState_ = false;
549     throwState_ = ThrowState::NOT_THROW;
550 #endif // OHOS_ENABLE_PULLTHROW
551     DRAG_DATA_MGR.ResetDragData();
552     dragResult_ = static_cast<DragResult>(dropResult.result);
553     appCallee_ = dragRadarPackageName.appCallee;
554     StateChangedNotify(DragState::STOP);
555     dragPackageName_ = {};
556 #else
557     DragBehavior dragBehavior = dropResult.dragBehavior;
558     GetDragBehavior(dropResult, dragBehavior);
559     DRAG_DATA_MGR.ResetDragData();
560     dragResult_ = static_cast<DragResult>(dropResult.result);
561 #endif // OHOS_BUILD_ENABLE_ARKUI_X
562     SetDragState(DragState::STOP);
563     if (GetControlCollaborationVisible()) {
564         SetControlCollaborationVisible(false);
565     }
566 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
567     ReportStopDragRadarInfo(BizState::STATE_END, StageRes::RES_SUCCESS, DragRadarErrCode::DRAG_SUCCESS, pid,
568         dragRadarPackageName);
569     if (dragOutSession_ == nullptr) {
570         ReportStopDragUEInfo(packageName);
571     }
572     dragOutSession_ = nullptr;
573 
574 #ifdef OHOS_BUILD_INTERNAL_DROP_ANIMATION
575     enableInternalDropAnimation_ = false;
576 #endif // OHOS_BUILD_INTERNAL_DROP_ANIMATION
577 
578 #endif // OHOS_BUILD_ENABLE_ARKUI_X
579     peerNetId_ = "";
580     FI_HILOGI("leave");
581     return ret;
582 }
583 
GetDragTargetPid() const584 int32_t DragManager::GetDragTargetPid() const
585 {
586     FI_HILOGI("enter");
587     return DRAG_DATA_MGR.GetTargetPid();
588 }
589 
GetUdKey(std::string & udKey) const590 int32_t DragManager::GetUdKey(std::string &udKey) const
591 {
592     FI_HILOGI("enter");
593     DragData dragData = DRAG_DATA_MGR.GetDragData();
594     if (dragData.udKey.empty()) {
595         FI_HILOGE("Target udKey is empty");
596         return RET_ERR;
597     }
598     udKey = dragData.udKey;
599     FI_HILOGI("leave");
600     return RET_OK;
601 }
602 
603 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
UpdateDragStylePositon()604 void DragManager::UpdateDragStylePositon()
605 {
606     FI_HILOGI("enter");
607     std::string systemLanguage = system::GetParameter(LANGUAGE_KEY, "");
608     if (systemLanguage.empty()) {
609         systemLanguage = system::GetParameter(DEFAULT_LANGUAGE_KEY, "");
610         if (systemLanguage.empty()) {
611             FI_HILOGE("Get systemLanguage failed");
612             return;
613         }
614     }
615     std::transform(systemLanguage.begin(), systemLanguage.end(), systemLanguage.begin(), ::tolower);
616     bool isCurrentRTL = false;
617     if (g_rtlLanguageMap.find(systemLanguage) != g_rtlLanguageMap.end()) {
618         isCurrentRTL = true;
619     }
620     if (isRTL_ != isCurrentRTL) {
621         isRTL_ = isCurrentRTL;
622         dragDrawing_.SetDragStyleRTL(isRTL_);
623         DragCursorStyle dragStyle = DRAG_DATA_MGR.GetDragStyle();
624         dragDrawing_.UpdateDragStyle(dragStyle);
625     }
626     FI_HILOGI("leave");
627 }
628 
UpdateDragStyle(DragCursorStyle style,int32_t targetPid,int32_t targetTid,int32_t eventId)629 int32_t DragManager::UpdateDragStyle(DragCursorStyle style, int32_t targetPid, int32_t targetTid, int32_t eventId)
630 #else
631 int32_t DragManager::UpdateDragStyle(DragCursorStyle style)
632 #endif // OHOS_BUILD_ENABLE_ARKUI_X
633 {
634 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
635     FI_HILOGD("DragStyle from ark is dragStyle:%{public}s, event:%{public}d",
636         GetDragStyleName(style).c_str(), eventId);
637     if ((eventId != -1) && (eventId < lastEventId_)) {
638         FI_HILOGE("Invalid eventId:%{public}d, lastEvent:%{public}d", eventId, lastEventId_);
639         return RET_ERR;
640     }
641     lastEventId_ = eventId;
642     auto lastTargetPid = DRAG_DATA_MGR.GetTargetPid();
643     DRAG_DATA_MGR.SetTargetPid(targetPid);
644     DRAG_DATA_MGR.SetTargetTid(targetTid);
645 #endif // OHOS_BUILD_ENABLE_ARKUI_X
646     if (style == DRAG_DATA_MGR.GetDragStyle()) {
647         FI_HILOGD("Not need update drag style");
648 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
649         if (targetPid != lastTargetPid) {
650             stateNotify_.StyleChangedNotify(GetRealDragStyle(style));
651         }
652 #endif // OHOS_BUILD_ENABLE_ARKUI_X
653         return RET_OK;
654     }
655     DRAG_DATA_MGR.SetDragStyle(style);
656     if (dragState_ != DragState::START) {
657         FI_HILOGE("No drag instance running, can not update drag style");
658         return RET_ERR;
659     }
660     if ((style < DragCursorStyle::DEFAULT) || (style > DragCursorStyle::MOVE)) {
661 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
662 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
663         DragDFX::WriteUpdateDragStyle(style, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
664 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
665 #endif // OHOS_BUILD_ENABLE_ARKUI_X
666         FI_HILOGE("Invalid style:%{public}d", style);
667         return RET_ERR;
668     }
669 #ifdef OHOS_ENABLE_PULLTHROW
670     if (isFoldPC_ && inHoveringState_) {
671         FI_HILOGD("isFoldPC and inHoveringState, dragstyle set to default");
672         return RET_OK;
673     }
674 #endif // OHOS_ENABLE_PULLTHROW
675     if (OnUpdateDragStyle(style) != RET_OK) {
676         FI_HILOGE("OnUpdateDragStyle dragStyle:%{public}s failed", GetDragStyleName(style).c_str());
677         return RET_ERR;
678     }
679     return RET_OK;
680 }
681 
UpdateShadowPic(const ShadowInfo & shadowInfo)682 int32_t DragManager::UpdateShadowPic(const ShadowInfo &shadowInfo)
683 {
684     FI_HILOGI("enter");
685     if (dragState_ != DragState::START) {
686         FI_HILOGE("No drag instance running, can not update shadow picture");
687         return RET_ERR;
688     }
689     DRAG_DATA_MGR.SetShadowInfos({ shadowInfo });
690     FI_HILOGI("leave");
691     return dragDrawing_.UpdateShadowPic(shadowInfo);
692 }
693 
GetDragData(DragData & dragData)694 int32_t DragManager::GetDragData(DragData &dragData)
695 {
696     FI_HILOGI("enter");
697     if ((dragState_ != DragState::START) && (dragState_ != DragState::MOTION_DRAGGING)) {
698         FI_HILOGE("No drag instance running, can not get dragData");
699         return RET_ERR;
700     }
701     dragData = DRAG_DATA_MGR.GetDragData();
702     FI_HILOGI("leave");
703     return RET_OK;
704 }
705 
GetDragState(DragState & dragState)706 int32_t DragManager::GetDragState(DragState &dragState)
707 {
708     FI_HILOGD("enter");
709     dragState = GetDragState();
710     if (dragState == DragState::ERROR) {
711         FI_HILOGE("dragState_ is error");
712         return RET_ERR;
713     }
714     FI_HILOGD("leave");
715     return RET_OK;
716 }
717 
GetDragStyle() const718 DragCursorStyle DragManager::GetDragStyle() const
719 {
720     return DRAG_DATA_MGR.GetDragStyle();
721 }
722 
723 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
NotifyDragResult(DragResult result,DragBehavior dragBehavior)724 int32_t DragManager::NotifyDragResult(DragResult result, DragBehavior dragBehavior)
725 {
726     FI_HILOGI("enter");
727     DragData dragData = DRAG_DATA_MGR.GetDragData();
728     int32_t targetPid = GetDragTargetPid();
729     NetPacket pkt(MessageId::DRAG_NOTIFY_RESULT);
730     if ((result < DragResult::DRAG_SUCCESS) || (result > DragResult::DRAG_EXCEPTION)) {
731 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
732         DragDFX::WriteNotifyDragResult(result, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
733 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
734         FI_HILOGE("The invalid result:%{public}d", static_cast<int32_t>(result));
735         return RET_ERR;
736     }
737     pkt << dragData.displayX << dragData.displayY << static_cast<int32_t>(result) << targetPid <<
738         static_cast<int32_t>(dragBehavior);
739     if (pkt.ChkRWError()) {
740         FI_HILOGE("Failed to packet write data");
741         return RET_ERR;
742     }
743     CHKPR(dragOutSession_, RET_ERR);
744     if (!dragOutSession_->SendMsg(pkt)) {
745         FI_HILOGE("Failed to send message");
746         return MSG_SEND_FAIL;
747     }
748 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
749     DragDFX::WriteNotifyDragResult(result, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
750 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
751     FI_HILOGI("leave");
752     return RET_OK;
753 }
754 
NotifyHideIcon()755 int32_t DragManager::NotifyHideIcon()
756 {
757     FI_HILOGD("enter");
758     NetPacket pkt(MessageId::DRAG_NOTIFY_HIDE_ICON);
759     if (pkt.ChkRWError()) {
760         FI_HILOGE("Packet write data failed");
761         return RET_ERR;
762     }
763     CHKPR(dragOutSession_, RET_ERR);
764     if (!dragOutSession_->SendMsg(pkt)) {
765         FI_HILOGE("Send message failed");
766         return MSG_SEND_FAIL;
767     }
768     FI_HILOGD("leave");
769     return RET_OK;
770 }
771 
DealPullInWindowEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent,int32_t targetDisplayId)772 int32_t DragManager::DealPullInWindowEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent, int32_t targetDisplayId)
773 {
774     CHKPR(pointerEvent, RET_ERR);
775     MMI::PointerEvent::PointerItem pointerItem;
776     pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem);
777     int32_t displayX = -1;
778     int32_t displayY = -1;
779     if (MMI::PointerEvent::FixedMode::AUTO == pointerEvent->GetFixedMode()) {
780         displayX = pointerItem.GetFixedDisplayX();
781         displayY = pointerItem.GetFixedDisplayY();
782     } else {
783         displayX = pointerItem.GetDisplayX();
784         displayY = pointerItem.GetDisplayY();
785     }
786     dragDrawing_.DetachToDisplay(targetDisplayId);
787     bool isNeedAdjustDisplayXY = true;
788     bool isMultiSelectedAnimation = false;
789     dragDrawing_.Draw(targetDisplayId, displayX, displayY, isNeedAdjustDisplayXY, isMultiSelectedAnimation);
790     dragDrawing_.UpdateDragWindowDisplay(targetDisplayId);
791     dragDrawing_.OnDragMove(targetDisplayId, displayX, displayY, pointerEvent->GetActionTime());
792     lastDisplayId_ = targetDisplayId;
793     return RET_OK;
794 }
795 
796 #ifdef OHOS_ENABLE_PULLTHROW
NormalizeThrowAngle(double angle)797 double DragManager::NormalizeThrowAngle(double angle)
798 {
799     return (angle < ANGLE_EPSILON) ? angle + FULL_CIRCLE_DEGREES : angle;
800 }
801 
GetThrowDirection(double angle)802 ThrowDirection DragManager::GetThrowDirection(double angle)
803 {
804     if (angle >= ANGLE_DOWN_MIN && angle < ANGLE_DOWN_MAX) {
805         return ThrowDirection::DOWN;
806     }
807     if (angle >= ANGLE_UP_MIN && angle < ANGLE_UP_MAX) {
808         return ThrowDirection::UP;
809     }
810     if (angle >= ANGLE_LEFT_MIN && angle < ANGLE_LEFT_MAX) {
811         return ThrowDirection::LEFT;
812     }
813     return ThrowDirection::RIGHT;
814 }
815 
GetScreenId(int32_t displayY)816 ScreenId DragManager::GetScreenId(int32_t displayY)
817 {
818     if (displayY <= UP_SCREEN_MAX_Y) {
819         return ScreenId::UPSCREEN;
820     }
821     if (displayY >= DOWN_SCREEN_MIN_Y && displayY <= DOWN_SCREEN_MAX_Y) {
822         return ScreenId::DOWNSCREEN;
823     }
824     return ScreenId::INVALID;
825 }
826 
ValidateThrowDirection(ScreenId currentScreen,ThrowDirection throwDir)827 bool DragManager::ValidateThrowDirection(ScreenId currentScreen, ThrowDirection throwDir)
828 {
829     bool isDownThrow = (throwDir == ThrowDirection::DOWN &&
830                         currentScreen == ScreenId::UPSCREEN &&
831                         throwState_ == ThrowState::NOT_THROW);
832 
833     bool isUpThrow = (throwDir == ThrowDirection::UP &&
834                       currentScreen == ScreenId::DOWNSCREEN &&
835                       throwState_ == ThrowState::NOT_THROW);
836 
837     return isDownThrow || isUpThrow;
838 }
839 
RegisterVKeyboard()840 void DragManager::RegisterVKeyboard()
841 {
842     if (!existVkListener_) {
843         FI_HILOGI("VkListener_ not exist, try register");
844         if (!RegisterVKListener()) {
845             FI_HILOGE("RegisterVKListener fail");
846             return;
847         }
848         existVkListener_ = true;
849     }
850     return;
851 }
852 
OnPullThrow(std::shared_ptr<MMI::PointerEvent> pointerEvent)853 int32_t DragManager::OnPullThrow(std::shared_ptr<MMI::PointerEvent> pointerEvent)
854 {
855     CHKPR(pointerEvent, RET_ERR);
856     dragDrawing_.StopVSyncStation();
857     isFoldPC_.store(PRODUCT_TYPE == PRODUCT_NAME_DEFINITION_PARSER.GetProductName("DEVICE_TYPE_FOLD_PC"));
858     if (!isFoldPC_) {
859         FI_HILOGW("Fail to pull throw, feature not support");
860         return RET_ERR;
861     }
862 
863     RegisterVKeyboard();
864     if (!ValidateThrowConditions()) {
865         FI_HILOGI("ThrowConditions Not satisfied");
866         pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_CANCEL);
867         MMI::InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
868         return RET_ERR;
869     }
870 
871     MMI::PointerEvent::PointerItem pointerItem;
872     pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem);
873     ScreenId currentScreen = GetScreenId(pointerItem.GetDisplayY());
874 
875     double throwAngle = pointerEvent->GetThrowAngle();
876     double throwSpeed = pointerEvent->GetThrowSpeed();
877     throwAngle = NormalizeThrowAngle(throwAngle);
878 
879     ThrowDirection throwDir = GetThrowDirection(throwAngle);
880     float vx = std::abs(throwSpeed * std::cos(throwAngle * M_PI / 180.0));
881     float vy = std::abs(throwSpeed * std::sin(throwAngle * M_PI / 180.0));
882 
883     FI_HILOGI("angle=%{public}f, direction=%{public}d, state=%{public}d, speeds=(%{public}f,%{public}f)",
884               throwAngle, throwDir, throwState_, vx, vy);
885 
886     if (ValidateThrowDirection(currentScreen, throwDir)) {
887         throwState_ = (throwDir == ThrowDirection::DOWN) ? ThrowState::IN_DOWNSCREEN : ThrowState::IN_UPSCREEN;
888         int targetY = (throwDir == ThrowDirection::DOWN) ? TARGET_Y_DOWN : TARGET_Y_UP;
889         FI_HILOGI("SUCCESS: Screen=%{public}d, Direction=%{public}d, Angle=%{public}f, ThrowState=%{public}d",
890                   currentScreen, throwDir, throwAngle, throwState_);
891         dragDrawing_.PullThrowAnimation(TARGET_X, targetY, vx, vy, pointerEvent);
892         inHoveringState_ = true;
893         if (OnUpdateDragStyle(DragCursorStyle::DEFAULT) != RET_OK) {
894             FI_HILOGE("pullthrow OnUpdateDragStyle failed");
895             return RET_ERR;
896         }
897         int32_t repeatCount = 1;
898         CHKPR(context_, RET_ERR);
899         dragTimerId_ = context_->GetTimerManager().AddTimer(TIMER_TIMEOUT_MS, repeatCount, [this]() {
900             FI_HILOGI("Timeout 30s, automatically stop dragging");
901             CHKPV(currentPointerEvent_);
902             currentPointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_CANCEL);
903             MMI::InputManager::GetInstance()->SimulateInputEvent(currentPointerEvent_);
904         });
905     } else {
906         FI_HILOGD("Fail: Screen=%{public}d, Direction=%{public}d, Angle=%{public}f, ThrowState=%{public}d",
907                   currentScreen, throwDir, throwAngle, throwState_);
908         pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_CANCEL);
909         MMI::InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
910     }
911     return RET_OK;
912 }
913 
InPullThrow(std::shared_ptr<MMI::PointerEvent> pointerEvent)914 void DragManager::InPullThrow(std::shared_ptr<MMI::PointerEvent> pointerEvent)
915 {
916     CHKPV(pointerEvent);
917     MMI::PointerEvent::PointerItem pointerItem;
918     pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem);
919     DragData dragData = DRAG_DATA_MGR.GetDragData();
920     CHKPV(context_);
921     if (dragTimerId_ >= 0) {
922         context_->GetTimerManager().RemoveTimer(dragTimerId_);
923         dragTimerId_ = -1;
924         FI_HILOGD("Remove timer");
925     }
926 
927     if (dragData.shadowInfos.size() <= 0) {
928         FI_HILOGE("shadow info size is 0");
929         return;
930     }
931     const ShadowInfo &shadowInfo = dragData.shadowInfos[0];
932     CHKPV(shadowInfo.pixelMap);
933     double hotZoneX = TARGET_X + shadowInfo.x;
934     double baseY = (throwState_ == ThrowState::IN_DOWNSCREEN) ? TARGET_Y_DOWN : TARGET_Y_UP;
935     double hotZoneY = baseY + shadowInfo.y;
936 
937     FI_HILOGI("DRAGDOWN throw state: %{public}d", throwState_);
938     FI_HILOGD("Pointer X: %{private}d, Y: %{private}d",
939               pointerItem.GetDisplayX(), pointerItem.GetDisplayY());
940     FI_HILOGD("Hotzone X: %{public}f, Y: %{public}f, Width: %{public}d, Height: %{public}d",
941               hotZoneX, hotZoneY, shadowInfo.pixelMap->GetWidth(), shadowInfo.pixelMap->GetHeight());
942 
943     bool isPointerOutsideHotZone =
944         (hotZoneY + shadowInfo.pixelMap->GetHeight() <= pointerItem.GetDisplayY()) ||
945         (pointerItem.GetDisplayY() <= hotZoneY) ||
946         (hotZoneX + shadowInfo.pixelMap->GetWidth() <= pointerItem.GetDisplayX()) ||
947         (pointerItem.GetDisplayX() <= hotZoneX);
948     if (isPointerOutsideHotZone) {
949         FI_HILOGI("In POINTER_ACTION_DOWN, Cancel, not in hotzone");
950         dragDrawing_.StopVSyncStation();
951         mouseDragMonitorDisplayX_ = -1;
952         mouseDragMonitorDisplayY_ = -1;
953         OnDragCancel(pointerEvent);
954         throwState_ = ThrowState::NOT_THROW;
955     } else {
956         inHoveringState_ = false;
957         dragDrawing_.PullThrowZoomOutAnimation();
958         FI_HILOGD("inHoveringState_: %{public}d", inHoveringState_);
959         if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN) {
960             bool drawCursor = true;
961             auto extraData = CreatePullThrowExtraData(true, drawCursor, pointerEvent);
962             if (MMI::InputManager::GetInstance()->AppendExtraData(extraData) != RET_OK) {
963                 FI_HILOGE("Failed to append extra data to MMI");
964             }
965         }
966     }
967 }
968 #endif // OHOS_ENABLE_PULLTHROW
969 
970 #ifdef OHOS_BUILD_ENABLE_ANCO
IsAncoDragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent,int32_t pointerAction)971 bool DragManager::IsAncoDragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent, int32_t pointerAction)
972 {
973     CHKPF(pointerEvent);
974     DragData dragData = DRAG_DATA_MGR.GetDragData();
975     if ((pointerAction == MMI::PointerEvent::POINTER_ACTION_MOVE) &&
976         (dragData.pointerId == pointerEvent->GetPointerId()) &&
977         (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN)) {
978         OnDragMove(pointerEvent);
979         return true;
980     } else if (((pointerAction == MMI::PointerEvent::POINTER_ACTION_UP) &&
981         (dragData.pointerId == pointerEvent->GetPointerId()) &&
982         (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN)) ||
983         ((pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_UP) &&
984         (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE)) ||
985         (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_CANCEL)) {
986         CHKPF(context_);
987         int32_t ret = context_->GetDelegateTasks().PostAsyncTask([this, pointerEvent] {
988             this->OnDragCancel(pointerEvent);
989             return RET_OK;
990         });
991         if (ret != RET_OK) {
992             FI_HILOGE("Post async task failed");
993         }
994         return true;
995     }
996     return false;
997 }
998 #endif // OHOS_BUILD_ENABLE_ANCO
999 
1000 #ifdef OHOS_ENABLE_PULLTHROW
PullThrowDragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent)1001 void DragManager::PullThrowDragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent)
1002 {
1003     CHKPV(pointerEvent);
1004     CHKPV(context_);
1005     int32_t ret = context_->GetDelegateTasks().PostAsyncTask([this, pointerEvent] {
1006         return this->OnPullThrow(pointerEvent);
1007     });
1008     if (ret != RET_OK) {
1009         FI_HILOGE("Post async task failed");
1010     }
1011 }
1012 #endif // OHOS_ENABLE_PULLTHROW
1013 
DragUpCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent,int32_t pointerAction)1014 void DragManager::DragUpCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent, int32_t pointerAction)
1015 {
1016     CHKPV(pointerEvent);
1017 #ifdef OHOS_ENABLE_PULLTHROW
1018     throwState_ = ThrowState::NOT_THROW;
1019 #endif // OHOS_ENABLE_PULLTHROW
1020     dragDrawing_.StopVSyncStation();
1021     mouseDragMonitorDisplayX_ = -1;
1022     mouseDragMonitorDisplayY_ = -1;
1023     CHKPV(context_);
1024     int32_t ret = context_->GetDelegateTasks().PostAsyncTask([this, pointerEvent] {
1025         return this->OnDragUp(pointerEvent);
1026     });
1027     if (ret != RET_OK) {
1028         FI_HILOGE("Post async task failed");
1029     }
1030 #ifdef OHOS_ENABLE_PULLTHROW
1031     if (dragTimerId_ >= 0 && pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_CANCEL) {
1032         CHKPV(context_);
1033         context_->GetTimerManager().RemoveTimer(dragTimerId_);
1034         dragTimerId_ = -1;
1035         FI_HILOGD("Remove timer");
1036     }
1037 #endif // OHOS_ENABLE_PULLTHROW
1038 }
1039 
DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent)1040 void DragManager::DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent)
1041 {
1042     CHKPV(pointerEvent);
1043     int32_t pointerAction = pointerEvent->GetPointerAction();
1044 #ifdef OHOS_ENABLE_PULLTHROW
1045     currentPointerEvent_ = pointerEvent;
1046 #endif // OHOS_ENABLE_PULLTHROW
1047     if ((pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) &&
1048         (pointerAction == MMI::PointerEvent::POINTER_ACTION_MOVE) && mouseDragMonitorState_) {
1049         MMI::PointerEvent::PointerItem pointerItem;
1050         pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem);
1051         mouseDragMonitorDisplayX_ = pointerItem.GetDisplayX();
1052         mouseDragMonitorDisplayY_ = pointerItem.GetDisplayY();
1053         existMouseMoveDragCallback_ = true;
1054     }
1055     if (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_MOVE) {
1056         mouseDragMonitorDisplayX_ = -1;
1057         mouseDragMonitorDisplayY_ = -1;
1058         OnDragMove(pointerEvent);
1059         return;
1060     }
1061 #ifdef OHOS_ENABLE_PULLTHROW
1062     if (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_THROW) {
1063         PullThrowDragCallback(pointerEvent);
1064         return;
1065     }
1066 #endif // OHOS_ENABLE_PULLTHROW
1067     FI_HILOGD("DragCallback, pointerAction:%{public}d", pointerAction);
1068 #ifdef OHOS_BUILD_ENABLE_ANCO
1069     bool isAncoDrag = pointerEvent->GetAncoDeal();
1070     FI_HILOGD("DragCallback, pointerAction:%{public}d, isAncoDrag:%{public}d", pointerAction, isAncoDrag);
1071     if (isAncoDrag && IsAncoDragCallback(pointerEvent, pointerAction)) {
1072         FI_HILOGD("DragCallback, anco drag call back");
1073         return;
1074     }
1075 #endif // OHOS_BUILD_ENABLE_ANCO
1076     if ((pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_UP) ||
1077         (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_CANCEL)) {
1078         DragUpCallback(pointerEvent, pointerAction);
1079         return;
1080     }
1081 #ifdef OHOS_ENABLE_PULLTHROW
1082     if ((pointerAction == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN ||
1083         pointerAction == MMI::PointerEvent::POINTER_ACTION_DOWN) &&
1084         throwState_ != ThrowState::NOT_THROW &&
1085         inHoveringState_) {
1086         InPullThrow(pointerEvent);
1087         return;
1088     }
1089 #endif // OHOS_ENABLE_PULLTHROW
1090     int32_t targetDisplayId = pointerEvent->GetTargetDisplayId();
1091     if ((pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) &&
1092         (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW)) {
1093         if (lastDisplayId_ == -1) {
1094             lastDisplayId_ = targetDisplayId;
1095         } else if (lastDisplayId_ != targetDisplayId) {
1096             FI_HILOGI("Interface for processing extended screen access");
1097             CHKPV(context_);
1098             int32_t ret = context_->GetDelegateTasks().PostAsyncTask([this, pointerEvent, targetDisplayId] {
1099                 return this->DealPullInWindowEvent(pointerEvent, targetDisplayId);
1100             });
1101             if (ret != RET_OK) {
1102                 FI_HILOGE("Post async task failed");
1103             }
1104         }
1105     }
1106     FI_HILOGD("Unknown action, sourceType:%{public}d, pointerId:%{public}d, pointerAction:%{public}d",
1107         pointerEvent->GetSourceType(), pointerEvent->GetPointerId(), pointerAction);
1108 }
1109 
DoLongPressDragZoomOutAnimation(int32_t displayX,int32_t displayY)1110 void DragManager::DoLongPressDragZoomOutAnimation(int32_t displayX, int32_t displayY)
1111 {
1112     auto LongPressDragZoomOutAnimation = [displayX, displayY, this]() {
1113         if (needLongPressDragAnimation_) {
1114             DragData dragData = DRAG_DATA_MGR.GetDragData();
1115             int32_t deltaX = abs(displayX - dragData.displayX);
1116             int32_t deltaY = abs(displayY - dragData.displayY);
1117             if ((pow(deltaX, POWER_SQUARED) + pow(deltaY, POWER_SQUARED)) > TEN_POWER) {
1118                 dragDrawing_.LongPressDragZoomOutAnimation();
1119                 needLongPressDragAnimation_ = false;
1120             }
1121         }
1122         return RET_OK;
1123     };
1124     if (isLongPressDrag_) {
1125         CHKPV(context_);
1126         int32_t ret = context_->GetDelegateTasks().PostAsyncTask(LongPressDragZoomOutAnimation);
1127         if (ret != RET_OK) {
1128             FI_HILOGE("Post async task failed, ret:%{public}d", ret);
1129         }
1130     }
1131 }
1132 
OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent)1133 void DragManager::OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent)
1134 {
1135     CHKPV(pointerEvent);
1136     DragData dragData = DRAG_DATA_MGR.GetDragData();
1137     if (pointerEvent->GetSourceType() != dragData.sourceType) {
1138         FI_HILOGW("The pointer source type invaild, the event should be ignored,"
1139             "pointer sourceType:%{public}d, drag sourceType:%{public}d",
1140             pointerEvent->GetSourceType(), dragData.sourceType);
1141         return;
1142     }
1143     MMI::PointerEvent::PointerItem pointerItem;
1144     pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem);
1145     int32_t pointerId = pointerEvent->GetPointerId();
1146     int32_t displayX = -1;
1147     int32_t displayY = -1;
1148     if (MMI::PointerEvent::FixedMode::AUTO == pointerEvent->GetFixedMode()) {
1149         displayX = pointerItem.GetFixedDisplayX();
1150         displayY = pointerItem.GetFixedDisplayY();
1151     } else {
1152         displayX = pointerItem.GetDisplayX();
1153         displayY = pointerItem.GetDisplayY();
1154     }
1155     DoLongPressDragZoomOutAnimation(displayX, displayY);
1156     int32_t targetDisplayId = pointerEvent->GetTargetDisplayId();
1157     FI_HILOGD("SourceType:%{public}d, pointerId:%{public}d, displayX:%{private}d, displayY:%{private}d, "
1158         "targetDisplayId:%{public}d, pullId:%{public}d", pointerEvent->GetSourceType(), pointerId, displayX, displayY,
1159         targetDisplayId, pointerEvent->GetPullId());
1160     if (lastDisplayId_ == -1) {
1161         lastDisplayId_ = targetDisplayId;
1162         dragDrawing_.OnDragMove(targetDisplayId, displayX, displayY, pointerEvent->GetActionTime());
1163     } else if (lastDisplayId_ != targetDisplayId) {
1164         dragDrawing_.DetachToDisplay(targetDisplayId);
1165         bool isNeedAdjustDisplayXY = true;
1166         bool isMultiSelectedAnimation = false;
1167         dragDrawing_.Draw(targetDisplayId, displayX, displayY, isNeedAdjustDisplayXY, isMultiSelectedAnimation);
1168         dragDrawing_.UpdateDragWindowDisplay(targetDisplayId);
1169         dragDrawing_.OnDragMove(targetDisplayId, displayX, displayY, pointerEvent->GetActionTime());
1170         lastDisplayId_ = targetDisplayId;
1171     } else {
1172         dragDrawing_.OnDragMove(targetDisplayId, displayX, displayY, pointerEvent->GetActionTime());
1173     }
1174 }
1175 
OnDragCancel(std::shared_ptr<MMI::PointerEvent> pointerEvent)1176 void DragManager::OnDragCancel(std::shared_ptr<MMI::PointerEvent> pointerEvent)
1177 {
1178     FI_HILOGI("enter");
1179     CHKPV(pointerEvent);
1180     if (dragState_ != DragState::START) {
1181         FI_HILOGW("No drag instance running");
1182         return;
1183     }
1184     DragData dragData = DRAG_DATA_MGR.GetDragData();
1185     if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
1186         dragDrawing_.EraseMouseIcon();
1187         FI_HILOGI("Set the pointer cursor visible");
1188         MMI::InputManager::GetInstance()->SetPointerVisible(true);
1189     }
1190     DragDropResult dropResult { DragResult::DRAG_CANCEL, false, -1 };
1191     StopDrag(dropResult);
1192     DragRadarInfo dragRadarInfo;
1193     dragRadarInfo.funcName = __func__;
1194     dragRadarInfo.bizState = static_cast<int32_t>(BizState::STATE_END);
1195     dragRadarInfo.bizStage = static_cast<int32_t>(BizStage::STAGE_STOP_DRAG);
1196     dragRadarInfo.stageRes = static_cast<int32_t>(StageRes::RES_FAIL);
1197     dragRadarInfo.errCode = static_cast<int32_t>(DragRadarErrCode::DRAG_STOP_CANCEL);
1198     dragRadarInfo.hostName = "";
1199     dragRadarInfo.callingPid = "";
1200     ReportDragRadarInfo(dragRadarInfo);
1201 }
1202 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1203 
SendDragData(int32_t targetTid,const std::string & udKey)1204 void DragManager::SendDragData(int32_t targetTid, const std::string &udKey)
1205 {
1206     FI_HILOGI("enter");
1207 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1208 #ifdef MSDP_FRAMEWORK_UDMF_ENABLED
1209     UDMF::QueryOption option;
1210     option.key = udKey;
1211     UDMF::Privilege privilege;
1212     privilege.tokenId = static_cast<uint32_t>(targetTid);
1213     int32_t ret = UDMF::UdmfClient::GetInstance().AddPrivilege(option, privilege);
1214     if (ret != RET_OK) {
1215         FI_HILOGE("Failed to send pid to Udmf client");
1216     }
1217 #endif // MSDP_FRAMEWORK_UDMF_ENABLED
1218 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1219     FI_HILOGI("leave");
1220 }
1221 
OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent)1222 int32_t DragManager::OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent)
1223 {
1224     FI_HILOGI("enter");
1225     CHKPR(pointerEvent, RET_ERR);
1226 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1227     if (notifyPUllUpCallback_ != nullptr) {
1228         notifyPUllUpCallback_(true);
1229     }
1230 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1231     if (dragState_ != DragState::START) {
1232         FI_HILOGW("No drag instance running");
1233         return RET_ERR;
1234     }
1235     DragData dragData = DRAG_DATA_MGR.GetDragData();
1236 #ifndef OHOS_BUILD_PC_PRODUCT
1237     if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
1238         dragDrawing_.EraseMouseIcon();
1239         FI_HILOGI("Set the pointer cursor visible");
1240 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1241         MMI::InputManager::GetInstance()->SetPointerVisible(true);
1242 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1243     }
1244 #endif // OHOS_BUILD_PC_PRODUCT
1245 
1246 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1247     CHKPR(context_, RET_ERR);
1248     int32_t repeatCount = 1;
1249     timerId_ = context_->GetTimerManager().AddTimer(TIMEOUT_MS, repeatCount, [this, dragData]() {
1250         DragDropResult dropResult { DragResult::DRAG_EXCEPTION, false, -1 };
1251         FI_HILOGW("Timeout, automatically stop dragging");
1252         this->StopDrag(dropResult);
1253         DragRadarInfo dragRadarInfo;
1254         dragRadarInfo.funcName = __func__;
1255         dragRadarInfo.bizState = static_cast<int32_t>(BizState::STATE_END);
1256         dragRadarInfo.bizStage = static_cast<int32_t>(BizStage::STAGE_STOP_DRAG);
1257         dragRadarInfo.stageRes = static_cast<int32_t>(StageRes::RES_FAIL);
1258         dragRadarInfo.errCode = static_cast<int32_t>(DragRadarErrCode::DRAG_STOP_EXCEPTION);
1259         dragRadarInfo.hostName = "";
1260         dragRadarInfo.callingPid = "";
1261         ReportDragRadarInfo(dragRadarInfo);
1262     });
1263 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1264     FI_HILOGI("leave");
1265     return RET_OK;
1266 }
1267 
1268 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1269 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const1270 void DragManager::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
1271 {
1272 }
1273 
OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const1274 void DragManager::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
1275 {
1276     CHKPV(pointerEvent);
1277     if (g_startFilterTime > 0) {
1278         auto actionTime = pointerEvent->GetActionTime();
1279         if (g_startFilterTime >= actionTime
1280             && pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_MOVE) {
1281             FI_HILOGW("Invalid event");
1282             return;
1283         }
1284         g_startFilterTime = -1;
1285     }
1286     CHKPV(pointerEventCallback_);
1287     pointerEventCallback_(pointerEvent);
1288     pointerEvent->AddFlag(MMI::InputEvent::EVENT_FLAG_NO_INTERCEPT);
1289     MMI::InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
1290     if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_UP) {
1291         FI_HILOGI("Pointer button is released, appened extra data");
1292         MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false));
1293     }
1294 }
1295 
OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const1296 void DragManager::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const
1297 {
1298 }
1299 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
1300 
1301 #ifdef OHOS_DRAG_ENABLE_MONITOR
OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const1302 void DragManager::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
1303 {
1304     FI_HILOGD("enter");
1305 }
1306 
OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const1307 void DragManager::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
1308 {
1309     FI_HILOGD("enter");
1310     CHKPV(pointerEvent);
1311     CHKPV(pointerEventCallback_);
1312     pointerEventCallback_(pointerEvent);
1313     if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_UP) {
1314         FI_HILOGI("Pointer button is released, appened extra data");
1315         int32_t ret = context_->GetDelegateTasks().PostAsyncTask([] {
1316             return MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false));
1317         });
1318         if (ret != RET_OK) {
1319             FI_HILOGE("Post async task failed");
1320         }
1321     }
1322     FI_HILOGD("leave");
1323 }
1324 
OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const1325 void DragManager::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const
1326 {
1327     FI_HILOGD("enter");
1328 }
1329 #endif // OHOS_DRAG_ENABLE_MONITOR
1330 
Dump(int32_t fd) const1331 void DragManager::Dump(int32_t fd) const
1332 {
1333     DragCursorStyle style = DRAG_DATA_MGR.GetDragStyle();
1334     int32_t targetTid = DRAG_DATA_MGR.GetTargetTid();
1335     dprintf(fd, "Drag information:\n");
1336 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
1337     dprintf(fd,
1338             "dragState:%s | dragResult:%s | interceptorId:%d | dragTargetPid:%d | dragTargetTid:%d | "
1339             "cursorStyle:%s | isWindowVisble:%s\n", GetDragState(dragState_).c_str(),
1340             GetDragResult(dragResult_).c_str(), pointerEventInterceptorId_, GetDragTargetPid(), targetTid,
1341             GetDragCursorStyle(style).c_str(), DRAG_DATA_MGR.GetDragWindowVisible() ? "true" : "false");
1342 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
1343 #ifdef OHOS_DRAG_ENABLE_MONITOR
1344     dprintf(fd,
1345             "dragState:%s | dragResult:%s | monitorId:%d | dragTargetPid:%d | dragTargetTid:%d | "
1346             "cursorStyle:%s | isWindowVisble:%s\n", GetDragState(dragState_).c_str(),
1347             GetDragResult(dragResult_).c_str(), pointerEventMonitorId_, GetDragTargetPid(), targetTid,
1348             GetDragCursorStyle(style).c_str(), DRAG_DATA_MGR.GetDragWindowVisible() ? "true" : "false");
1349 #endif // OHOS_DRAG_ENABLE_MONITOR
1350     DragData dragData = DRAG_DATA_MGR.GetDragData();
1351     std::string udKey;
1352     if (RET_ERR == GetUdKey(udKey)) {
1353         FI_HILOGE("Target udKey is empty");
1354         udKey = "";
1355     }
1356     for (const auto& shadowInfo : dragData.shadowInfos) {
1357         dprintf(fd, "dragData = {\n""\tshadowInfoX:%d\n\tshadowInfoY:%d\n", shadowInfo.x, shadowInfo.y);
1358     }
1359     dprintf(fd, "dragData = {\n"
1360             "\tudKey:%s\n\tfilterInfo:%s\n\textraInfo:%s\n\tsourceType:%d"
1361             "\tdragNum:%d\n\tpointerId:%d\n\tdisplayX:%d\n\tdisplayY:%d\n""\tdisplayId:%d\n\thasCanceledAnimation:%s\n",
1362             GetAnonyString(dragData.udKey).c_str(), dragData.filterInfo.c_str(), dragData.extraInfo.c_str(),
1363             dragData.sourceType, dragData.dragNum, dragData.pointerId, dragData.displayX, dragData.displayY,
1364             dragData.displayId, dragData.hasCanceledAnimation ? "true" : "false");
1365     if (dragState_ != DragState::STOP) {
1366         for (const auto& shadowInfo : dragData.shadowInfos) {
1367             CHKPV(shadowInfo.pixelMap);
1368             dprintf(fd, "\tpixelMapWidth:%d\n\tpixelMapHeight:%d\n", shadowInfo.pixelMap->GetWidth(),
1369                 shadowInfo.pixelMap->GetHeight());
1370         }
1371     }
1372     dprintf(fd, "}\n");
1373 }
1374 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1375 
GetDragState(DragState value) const1376 std::string DragManager::GetDragState(DragState value) const
1377 {
1378     std::string state = "unknown";
1379     const std::map<DragState, std::string> dragStates = {
1380         { DragState::START, "start" },
1381         { DragState::STOP, "stop" },
1382         { DragState::CANCEL, "cancel" },
1383         { DragState::ERROR, "error" }
1384     };
1385     auto iter = dragStates.find(value);
1386     if (iter != dragStates.end()) {
1387         state = iter->second;
1388     }
1389     return state;
1390 }
1391 
GetDragResult(DragResult value) const1392 std::string DragManager::GetDragResult(DragResult value) const
1393 {
1394     std::string result = "unknown";
1395     const std::map<DragResult, std::string> dragResults = {
1396         { DragResult::DRAG_SUCCESS, "success" },
1397         { DragResult::DRAG_FAIL, "fail" },
1398         { DragResult::DRAG_CANCEL, "cancel" },
1399         { DragResult::DRAG_EXCEPTION, "abnormal" }
1400     };
1401     auto iter = dragResults.find(value);
1402     if (iter != dragResults.end()) {
1403         result = iter->second;
1404     }
1405     return result;
1406 }
1407 
GetDragCursorStyle(DragCursorStyle value) const1408 std::string DragManager::GetDragCursorStyle(DragCursorStyle value) const
1409 {
1410     std::string style = "unknown";
1411     const std::map<DragCursorStyle, std::string> cursorStyles = {
1412         { DragCursorStyle::COPY, "copy" },
1413         { DragCursorStyle::DEFAULT, "default" },
1414         { DragCursorStyle::FORBIDDEN, "forbidden" },
1415         { DragCursorStyle::MOVE, "move" }
1416     };
1417     auto iter = cursorStyles.find(value);
1418     if (iter != cursorStyles.end()) {
1419         style = iter->second;
1420     }
1421     return style;
1422 }
1423 
CreateExtraData(bool appended,bool drawCursor)1424 MMI::ExtraData DragManager::CreateExtraData(bool appended, bool drawCursor)
1425 {
1426     DragData dragData = DRAG_DATA_MGR.GetDragData();
1427     MMI::ExtraData extraData;
1428     extraData.buffer = dragData.buffer;
1429     extraData.sourceType = dragData.sourceType;
1430     extraData.pointerId = dragData.pointerId;
1431     extraData.appended = appended;
1432     extraData.pullId = pullId_;
1433     extraData.drawCursor = drawCursor;
1434     extraData.eventId = DRAG_DATA_MGR.GetEventId();
1435     FI_HILOGD("sourceType:%{public}d, pointerId:%{public}d, eventId:%{public}d",
1436         extraData.sourceType, extraData.pointerId, extraData.eventId);
1437     return extraData;
1438 }
1439 
1440 #ifdef OHOS_ENABLE_PULLTHROW
1441 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
CreatePullThrowExtraData(bool appended,bool drawCursor,std::shared_ptr<MMI::PointerEvent> pointerEvent)1442 MMI::ExtraData DragManager::CreatePullThrowExtraData(bool appended, bool drawCursor,
1443     std::shared_ptr<MMI::PointerEvent> pointerEvent)
1444 {
1445     FI_HILOGI("enter");
1446     DragData dragData = DRAG_DATA_MGR.GetDragData();
1447     DragData mouseDragData = dragData;
1448     mouseDragData.sourceType = MMI::PointerEvent::SOURCE_TYPE_MOUSE;
1449     mouseDragData.pointerId = pointerEvent->GetPointerId();
1450     DRAG_DATA_MGR.Init(mouseDragData, mouseDragData.appCaller);
1451 
1452     MMI::ExtraData extraData;
1453     extraData.buffer = mouseDragData.buffer;
1454     extraData.sourceType = mouseDragData.sourceType;
1455     extraData.pointerId = mouseDragData.pointerId;
1456     extraData.appended = appended;
1457     extraData.pullId = pullId_;
1458     extraData.drawCursor = drawCursor;
1459     extraData.eventId = pointerEvent->GetId();
1460     FI_HILOGD("pullthrow sourceType:%{public}d, pointerId:%{public}d, eventId:%{public}d",
1461         extraData.sourceType, extraData.pointerId, extraData.eventId);
1462     return extraData;
1463 }
1464 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1465 #endif // OHOS_ENABLE_PULLTHROW
1466 
InitDataManager(const DragData & dragData,const std::string & appCaller)1467 int32_t DragManager::InitDataManager(const DragData &dragData, const std::string &appCaller)
1468 {
1469     FI_HILOGI("enter");
1470     DRAG_DATA_MGR.Init(dragData, appCaller);
1471     FI_HILOGI("leave");
1472     return RET_OK;
1473 }
1474 
1475 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
AddDragEventHandler(int32_t sourceType)1476 int32_t DragManager::AddDragEventHandler(int32_t sourceType)
1477 {
1478     FI_HILOGI("enter");
1479     uint32_t deviceTags = 0;
1480 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
1481     if (sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
1482         deviceTags = MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_POINTER);
1483     } else if (sourceType == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
1484         deviceTags = MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_TOUCH) |
1485             MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_TABLET_TOOL);
1486     } else {
1487         FI_HILOGW("Drag is not supported for this device type:%{public}d", sourceType);
1488         return RET_ERR;
1489     }
1490 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
1491     if (AddKeyEventMonitor() != RET_OK) {
1492         FI_HILOGE("Failed to add key event handler");
1493         return RET_ERR;
1494     }
1495     if (AddPointerEventHandler(deviceTags) != RET_OK) {
1496         FI_HILOGE("Failed to add pointer event handler");
1497         return RET_ERR;
1498     }
1499     FI_HILOGI("leave");
1500     return RET_OK;
1501 }
1502 
AddPointerEventHandler(uint32_t deviceTags)1503 int32_t DragManager::AddPointerEventHandler(uint32_t deviceTags)
1504 {
1505     FI_HILOGI("enter");
1506     if (pointerEventMonitorId_ <= 0) {
1507 #ifdef OHOS_DRAG_ENABLE_MONITOR
1508         auto monitor = std::make_shared<MonitorConsumer>([this](std::shared_ptr<MMI::PointerEvent> pointerEvent) {
1509             return this->DragCallback(pointerEvent);
1510         }, context_);
1511         pointerEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(monitor);
1512         if (pointerEventMonitorId_ <= 0) {
1513             FI_HILOGE("Failed to add pointer event monitor");
1514             return RET_ERR;
1515         }
1516 #else
1517         auto callback = [this](std::shared_ptr<MMI::PointerEvent> pointerEvent) {
1518             return this->DragCallback(pointerEvent);
1519         };
1520         auto interceptor = std::make_shared<InterceptorConsumer>(callback);
1521         pointerEventInterceptorId_ = MMI::InputManager::GetInstance()->AddInterceptor(
1522             interceptor, DRAG_PRIORITY, deviceTags);
1523         if (pointerEventInterceptorId_ <= 0) {
1524             FI_HILOGE("Failed to add pointer event interceptor");
1525             return RET_ERR;
1526         }
1527 #endif // OHOS_DRAG_ENABLE_MONITOR
1528         FI_HILOGI("Add drag poniter event handle successfully");
1529         FI_HILOGI("leave");
1530         return RET_OK;
1531     } else {
1532         FI_HILOGI("leave");
1533         return RET_ERR;
1534     }
1535 }
1536 
AddKeyEventMonitor()1537 int32_t DragManager::AddKeyEventMonitor()
1538 {
1539     FI_HILOGI("enter");
1540     if (keyEventMonitorId_ <= 0) {
1541         keyEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(
1542             [this](std::shared_ptr<MMI::KeyEvent> keyEvent) {
1543                 return this->DragKeyEventCallback(keyEvent);
1544             });
1545         if (keyEventMonitorId_ <= 0) {
1546             FI_HILOGE("Failed to add key event monitor");
1547             return RET_ERR;
1548         }
1549         FI_HILOGI("Add drag key event monitor successfully");
1550         FI_HILOGI("leave");
1551         return RET_OK;
1552     } else {
1553         FI_HILOGI("leave");
1554         return RET_ERR;
1555     }
1556 }
1557 
RemovePointerEventHandler()1558 int32_t DragManager::RemovePointerEventHandler()
1559 {
1560     FI_HILOGI("enter");
1561 #ifdef OHOS_DRAG_ENABLE_MONITOR
1562     if (pointerEventMonitorId_ <= 0) {
1563         FI_HILOGE("Invalid pointer event monitor id:%{public}d", pointerEventMonitorId_);
1564         return RET_ERR;
1565     }
1566     MMI::InputManager::GetInstance()->RemoveMonitor(pointerEventMonitorId_);
1567     pointerEventMonitorId_ = -1;
1568 #else
1569     if (pointerEventInterceptorId_ <= 0) {
1570         FI_HILOGE("Invalid pointer event interceptor id:%{public}d", pointerEventInterceptorId_);
1571     }
1572     MMI::InputManager::GetInstance()->RemoveInterceptor(pointerEventInterceptorId_);
1573     pointerEventInterceptorId_ = -1;
1574 #endif // OHOS_DRAG_ENABLE_MONITOR
1575     FI_HILOGI("Remove drag pointer event handler successfully");
1576     return RET_OK;
1577 }
1578 
RemoveDragEventHandler()1579 int32_t DragManager::RemoveDragEventHandler()
1580 {
1581     FI_HILOGI("enter");
1582     if (RemoveKeyEventMonitor() != RET_OK) {
1583         FI_HILOGE("Failed to remove key event handler");
1584         return RET_ERR;
1585     }
1586     if (RemovePointerEventHandler() != RET_OK) {
1587         FI_HILOGE("Failed to remove pointer event handler");
1588         return RET_ERR;
1589     }
1590     FI_HILOGI("leave");
1591     return RET_OK;
1592 }
1593 
RemoveKeyEventMonitor()1594 int32_t DragManager::RemoveKeyEventMonitor()
1595 {
1596     FI_HILOGI("enter");
1597     if (keyEventMonitorId_ <= 0) {
1598         FI_HILOGE("Invalid key event monitor id:%{public}d", keyEventMonitorId_);
1599         return RET_ERR;
1600     }
1601     MMI::InputManager::GetInstance()->RemoveMonitor(keyEventMonitorId_);
1602     keyEventMonitorId_ = -1;
1603     FI_HILOGI("Remove drag key event handle successfully");
1604     return RET_OK;
1605 }
1606 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1607 
1608 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
OnStartDrag(const struct DragRadarPackageName & dragRadarPackageName,int32_t pid)1609 int32_t DragManager::OnStartDrag(const struct DragRadarPackageName &dragRadarPackageName, int32_t pid)
1610 #else
1611 int32_t DragManager::OnStartDrag()
1612 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1613 {
1614     FI_HILOGI("enter");
1615     pullId_ = GenerateId();
1616     FI_HILOGI("Current pullId:%{public}d", pullId_.load());
1617     if (GetControlCollaborationVisible()) {
1618         SetControlCollaborationVisible(false);
1619     }
1620     DragData dragData = DRAG_DATA_MGR.GetDragData();
1621     bool drawCursor = false;
1622 #ifdef OHOS_BUILD_PC_PRODUCT
1623     if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
1624         drawCursor = true;
1625     }
1626 #endif // OHOS_BUILD_PC_PRODUCT
1627     auto extraData = CreateExtraData(true, drawCursor);
1628     bool isHicarOrSuperLauncher = false;
1629 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1630     sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(dragData.displayId);
1631     uint64_t screenId = 0;
1632     if (display != nullptr) {
1633         std::string displayName = display->GetName();
1634         isHicarOrSuperLauncher = ((displayName == "HiCar") || (displayName == "SuperLauncher"));
1635         screenId = display->GetScreenId();
1636     }
1637     FI_HILOGI("Get screen id:%{public}llu", static_cast<unsigned long long>(screenId));
1638     dragDrawing_.SetScreenId(screenId);
1639     if (Rosen::DisplayManager::GetInstance().IsFoldable() && !isHicarOrSuperLauncher) {
1640         if (static_cast<uint64_t>(dragData.displayId) == displayId_) {
1641             dragDrawing_.SetScreenId(screenId_);
1642         }
1643     }
1644     UpdateDragStylePositon();
1645     int32_t ret = dragDrawing_.Init(dragData, context_, isLongPressDrag_);
1646 #else
1647     int32_t ret = dragDrawing_.Init(dragData);
1648 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1649     if (ret == INIT_FAIL) {
1650         FI_HILOGE("Init drag drawing failed");
1651         dragDrawing_.DestroyDragWindow();
1652         dragDrawing_.UpdateDrawingState();
1653 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1654         ReportStartDragFailedRadarInfo(StageRes::RES_FAIL, DragRadarErrCode::FAILED_INIT_DRAWING, __func__,
1655             dragRadarPackageName);
1656 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1657         return RET_ERR;
1658     }
1659     if (ret == INIT_CANCEL) {
1660         FI_HILOGE("Init drag drawing cancel, drag animation is running");
1661 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1662         ReportStartDragFailedRadarInfo(StageRes::RES_CANCEL, DragRadarErrCode::REPEATE_START_DRAG_EXCEPTION, __func__,
1663             dragRadarPackageName);
1664 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1665         return RET_ERR;
1666     }
1667     bool isNeedAdjustDisplayXY = true;
1668     bool isMultiSelectedAnimation = false;
1669     if (!mouseDragMonitorState_ || !existMouseMoveDragCallback_) {
1670         dragDrawing_.Draw(dragData.displayId, dragData.displayX, dragData.displayY, isNeedAdjustDisplayXY,
1671             isMultiSelectedAnimation);
1672     } else if (mouseDragMonitorState_ && existMouseMoveDragCallback_ && (mouseDragMonitorDisplayX_ != -1)
1673         && (mouseDragMonitorDisplayY_ != -1)) {
1674         dragDrawing_.Draw(dragData.displayId, mouseDragMonitorDisplayX_, mouseDragMonitorDisplayY_,
1675             isNeedAdjustDisplayXY, isMultiSelectedAnimation);
1676     }
1677     FI_HILOGI("Start drag, appened extra data");
1678 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1679     ret = AddDragEvent(dragData, dragRadarPackageName);
1680     if (ret != RET_OK) {
1681         FI_HILOGE("Failed to add drag event handler");
1682         return RET_ERR;
1683     }
1684 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1685     dragAction_.store(DragAction::MOVE);
1686     FI_HILOGI("leave");
1687     return RET_OK;
1688 }
1689 
OnStopDrag(DragResult result,bool hasCustomAnimation,const std::string & packageName,int32_t pid,bool isStopCooperate)1690 int32_t DragManager::OnStopDrag(DragResult result, bool hasCustomAnimation, const std::string &packageName, int32_t pid,
1691     bool isStopCooperate)
1692 {
1693     FI_HILOGI("Add custom animation:%{public}s", hasCustomAnimation ? "true" : "false");
1694     DragData dragData = DRAG_DATA_MGR.GetDragData();
1695 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1696     if ((RemovePointerEventHandler()!= RET_OK) || (RemoveKeyEventMonitor() != RET_OK)) {
1697         DragRadarInfo dragRadarInfo;
1698         dragRadarInfo.funcName = __func__;
1699         dragRadarInfo.bizState = static_cast<int32_t>(BizState::STATE_END);
1700         dragRadarInfo.bizStage = static_cast<int32_t>(BizStage::STAGE_STOP_DRAG);
1701         dragRadarInfo.stageRes = static_cast<int32_t>(StageRes::RES_FAIL);
1702         dragRadarInfo.errCode = static_cast<int32_t>(DragRadarErrCode::FAILED_REMOVE_INPUT_MONITOR);
1703         dragRadarInfo.hostName = packageName;
1704         dragRadarInfo.callingPid = pid;
1705         ReportDragRadarInfo(dragRadarInfo);
1706     }
1707 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1708     dragAction_.store(DragAction::MOVE);
1709     FI_HILOGI("Stop drag, appened extra data");
1710 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1711     MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false));
1712 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1713 
1714 #ifndef OHOS_BUILD_PC_PRODUCT
1715     if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
1716         dragDrawing_.EraseMouseIcon();
1717         if (dragState_ != DragState::MOTION_DRAGGING) {
1718             FI_HILOGI("Set the pointer cursor visible");
1719 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1720             if (isStopCooperate) {
1721                 CHKPR(context_, RET_ERR);
1722                 bool hasLocalPointerDevice = context_->GetDeviceManager().HasLocalPointerDevice() ||
1723                     context_->GetInput().HasLocalPointerDevice();
1724                 MMI::InputManager::GetInstance()->SetPointerVisible(hasLocalPointerDevice);
1725             } else {
1726                 MMI::InputManager::GetInstance()->SetPointerVisible(true);
1727             }
1728 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1729         }
1730     }
1731 #endif // OHOS_BUILD_PC_PRODUCT
1732 
1733     pullId_ = -1;
1734     return HandleDragResult(result, hasCustomAnimation);
1735 }
1736 
OnSetDragWindowVisible(bool visible,bool isForce,bool isZoomInAndAlphaChanged,const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)1737 int32_t DragManager::OnSetDragWindowVisible(bool visible, bool isForce, bool isZoomInAndAlphaChanged,
1738     const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)
1739 {
1740     FI_HILOGI("Set drag window visibleion:%{public}s", visible ? "true" : "false");
1741     if (dragState_ == DragState::MOTION_DRAGGING) {
1742         FI_HILOGW("Currently in motion dragging");
1743         return RET_OK;
1744     }
1745     if (dragState_ == DragState::STOP) {
1746         FI_HILOGW("No drag instance running, can not set drag window visible");
1747 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1748         ReportDragWindowVisibleRadarInfo(StageRes::RES_FAIL, DragRadarErrCode::FAILED_SET_DRAG_VISIBLE, __func__);
1749 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1750         return RET_ERR;
1751     }
1752     if (!isForce && GetControlCollaborationVisible() && rsTransaction == nullptr) {
1753         FI_HILOGW("The drag-and-drop window is controlled by multi-screen coordination,"
1754             "can not set drag window visible:%{public}d", visible);
1755         return RET_OK;
1756     }
1757 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1758 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
1759     DragDFX::WriteDragWindowVisible(dragState_, visible, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
1760 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
1761 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1762     DRAG_DATA_MGR.SetDragWindowVisible(visible);
1763     dragDrawing_.UpdateDragWindowState(visible, isZoomInAndAlphaChanged, rsTransaction);
1764     DragData dragData = DRAG_DATA_MGR.GetDragData();
1765 #ifndef OHOS_BUILD_PC_PRODUCT
1766     if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE && visible) {
1767         FI_HILOGI("Set the pointer cursor invisible");
1768 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1769         MMI::InputManager::GetInstance()->SetPointerVisible(false);
1770 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1771     }
1772 #endif // OHOS_BUILD_PC_PRODUCT
1773 
1774     if (isForce) {
1775         SetControlCollaborationVisible(isForce);
1776         FI_HILOGW("The drag-and-drop window is controlled by multi-screen coordination");
1777     }
1778     return RET_OK;
1779 }
1780 
OnGetShadowOffset(ShadowOffset & shadowOffset)1781 int32_t DragManager::OnGetShadowOffset(ShadowOffset &shadowOffset)
1782 {
1783     FI_HILOGI("enter");
1784     return DRAG_DATA_MGR.GetShadowOffset(shadowOffset);
1785 }
1786 
1787 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
RegisterStateChange(std::function<void (DragState)> callback)1788 void DragManager::RegisterStateChange(std::function<void(DragState)> callback)
1789 {
1790     FI_HILOGI("enter");
1791     CHKPV(callback);
1792     stateChangedCallback_ = callback;
1793     FI_HILOGI("leave");
1794 }
1795 
UnregisterStateChange()1796 void DragManager::UnregisterStateChange()
1797 {
1798     FI_HILOGI("Unregister state-change callback");
1799     stateChangedCallback_ = nullptr;
1800 }
1801 
RegisterNotifyPullUp(std::function<void (bool)> callback)1802 void DragManager::RegisterNotifyPullUp(std::function<void(bool)> callback)
1803 {
1804     FI_HILOGI("enter");
1805     CHKPV(callback);
1806     notifyPUllUpCallback_ = callback;
1807     FI_HILOGI("leave");
1808 }
1809 
UnregisterNotifyPullUp()1810 void DragManager::UnregisterNotifyPullUp()
1811 {
1812     FI_HILOGI("Unregister notify-pullup callback");
1813     notifyPUllUpCallback_ = nullptr;
1814 }
1815 
RegisterCrossDrag(std::function<void (bool)> callback)1816 void DragManager::RegisterCrossDrag(std::function<void(bool)> callback)
1817 {
1818     FI_HILOGD("Register cross_drag callback");
1819     crossDragCallback_ = callback;
1820 }
1821 
UnregisterCrossDrag()1822 void DragManager::UnregisterCrossDrag()
1823 {
1824     FI_HILOGD("Unregister cross_drag callback");
1825     crossDragCallback_ = nullptr;
1826 }
1827 
NotifyCrossDrag(bool isButtonDown)1828 void DragManager::NotifyCrossDrag(bool isButtonDown)
1829 {
1830     CHKPV(crossDragCallback_);
1831     crossDragCallback_(isButtonDown);
1832 }
1833 
StateChangedNotify(DragState state)1834 void DragManager::StateChangedNotify(DragState state)
1835 {
1836     FI_HILOGD("enter");
1837     CHKPV(stateChangedCallback_);
1838     if (state == DragState::STOP) {
1839         stateChangedCallback_(state);
1840     } else if (dragState_ != DragState::MOTION_DRAGGING) {
1841         stateChangedCallback_(state);
1842     }
1843     FI_HILOGD("leave");
1844 }
1845 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1846 
GetExtraData(bool appended) const1847 MMI::ExtraData DragManager::GetExtraData(bool appended) const
1848 {
1849     return CreateExtraData(appended);
1850 }
1851 
GetDragState() const1852 DragState DragManager::GetDragState() const
1853 {
1854     return dragState_;
1855 }
1856 
GetAllowDragState(bool & isAllowDrag)1857 void DragManager::GetAllowDragState(bool &isAllowDrag)
1858 {
1859     FI_HILOGD("enter");
1860     if (dragState_ != DragState::START) {
1861         FI_HILOGW("Currently state is \'%{public}d\', allow cooperate", static_cast<int32_t>(dragState_));
1862         return;
1863     }
1864     isAllowDrag = dragDrawing_.GetAllowDragState();
1865     FI_HILOGD("leave");
1866 }
1867 
SetDragState(DragState state)1868 void DragManager::SetDragState(DragState state)
1869 {
1870     FI_HILOGI("SetDragState:%{public}d to %{public}d", static_cast<int32_t>(dragState_), static_cast<int32_t>(state));
1871     if ((dragState_ == DragState::STOP) && (state == DragState::MOTION_DRAGGING)) {
1872         FI_HILOGW("Unreasonable drag state switching");
1873         return;
1874     }
1875     dragState_ = state;
1876     dragDrawing_.UpdateDragState(state);
1877     if (state == DragState::START) {
1878         UpdateDragStyleCross();
1879     }
1880 }
1881 
SetDragOriginDpi(float dragOriginDpi)1882 void DragManager::SetDragOriginDpi(float dragOriginDpi)
1883 {
1884     DRAG_DATA_MGR.SetDragOriginDpi(dragOriginDpi);
1885 }
1886 
GetDragResult() const1887 DragResult DragManager::GetDragResult() const
1888 {
1889     return dragResult_;
1890 }
1891 
GetAppCallee() const1892 std::string DragManager::GetAppCallee() const
1893 {
1894     return appCallee_;
1895 }
1896 
SetControlCollaborationVisible(bool visible)1897 void DragManager::SetControlCollaborationVisible(bool visible)
1898 {
1899     isControlCollaborationVisible_ = visible;
1900 }
GetControlCollaborationVisible() const1901 bool DragManager::GetControlCollaborationVisible() const
1902 {
1903     return isControlCollaborationVisible_;
1904 }
1905 
GetDragSummary(std::map<std::string,int64_t> & summarys)1906 int32_t DragManager::GetDragSummary(std::map<std::string, int64_t> &summarys)
1907 {
1908     FI_HILOGI("enter");
1909     DragData dragData = DRAG_DATA_MGR.GetDragData();
1910     summarys = dragData.detailedSummarys.empty() ? dragData.summarys : dragData.detailedSummarys;
1911     if (summarys.empty()) {
1912         FI_HILOGD("Summarys is empty");
1913     }
1914     FI_HILOGI("leave");
1915     return RET_OK;
1916 }
1917 
GetDragSummaryInfo(DragSummaryInfo & dragSummaryInfo)1918 int32_t DragManager::GetDragSummaryInfo(DragSummaryInfo &dragSummaryInfo)
1919 {
1920     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
1921         FI_HILOGE("Drag instance not running");
1922         return RET_ERR;
1923     }
1924     DRAG_DATA_MGR.GetSummaryInfo(dragSummaryInfo);
1925     std::string summaryFormat = GetSummaryFormatStrings(dragSummaryInfo.summaryFormat);
1926     FI_HILOGI("summaryFormat:%{public}s", summaryFormat.c_str());
1927     return RET_OK;
1928 }
1929 
HandleDragSuccess(bool hasCustomAnimation)1930 int32_t DragManager::HandleDragSuccess(bool hasCustomAnimation)
1931 {
1932     FI_HILOGI("enter");
1933     if (!hasCustomAnimation) {
1934 #ifdef OHOS_BUILD_INTERNAL_DROP_ANIMATION
1935         DragData dragData = DRAG_DATA_MGR.GetDragData();
1936         if (enableInternalDropAnimation_) {
1937             FI_HILOGI("Run internal drp animation");
1938             int32_t ret = PerformInternalDropAnimation();
1939             if (ret != RET_OK) {
1940                 FI_HILOGE("PerformInternalDropAnimation failed");
1941                 dragDrawing_.DestroyDragWindow();
1942                 dragDrawing_.UpdateDrawingState();
1943                 return RET_ERR;
1944             }
1945             return RET_OK;
1946         }
1947 #endif // OHOS_BUILD_INTERNAL_DROP_ANIMATION
1948 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1949         dragDrawing_.OnDragSuccess(context_);
1950 #else
1951         dragDrawing_.OnDragSuccess();
1952 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1953     } else {
1954         dragDrawing_.DestroyDragWindow();
1955         dragDrawing_.UpdateDrawingState();
1956     }
1957     FI_HILOGI("leave");
1958     return RET_OK;
1959 }
1960 
HandleDragResult(DragResult result,bool hasCustomAnimation)1961 int32_t DragManager::HandleDragResult(DragResult result, bool hasCustomAnimation)
1962 {
1963     FI_HILOGI("enter");
1964     switch (result) {
1965         case DragResult::DRAG_SUCCESS: {
1966             int32_t ret = HandleDragSuccess(hasCustomAnimation);
1967             if (ret != RET_OK) {
1968                 FI_HILOGE("HandleDragSuccess failed");
1969                 return ret;
1970             }
1971             break;
1972         }
1973         case DragResult::DRAG_FAIL:
1974         case DragResult::DRAG_CANCEL: {
1975             if (!hasCustomAnimation) {
1976 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
1977                 dragDrawing_.OnDragFail(context_, isLongPressDrag_);
1978 #else
1979                 dragDrawing_.OnDragFail();
1980 #endif // OHOS_BUILD_ENABLE_ARKUI_X
1981             } else {
1982                 dragDrawing_.DestroyDragWindow();
1983                 dragDrawing_.UpdateDrawingState();
1984             }
1985             break;
1986         }
1987         case DragResult::DRAG_EXCEPTION: {
1988             dragDrawing_.DestroyDragWindow();
1989             dragDrawing_.UpdateDrawingState();
1990             break;
1991         }
1992         default: {
1993             FI_HILOGW("Unsupported DragResult type, DragResult:%{public}d", result);
1994             break;
1995         }
1996     }
1997     FI_HILOGI("leave");
1998     return RET_OK;
1999 }
2000 
SetPointerEventFilterTime(int64_t filterTime)2001 void DragManager::SetPointerEventFilterTime(int64_t filterTime)
2002 {
2003     FI_HILOGD("enter");
2004     g_startFilterTime = filterTime;
2005     FI_HILOGD("leave");
2006 }
2007 
MoveTo(int32_t x,int32_t y,bool isMultiSelectedAnimation)2008 void DragManager::MoveTo(int32_t x, int32_t y, bool isMultiSelectedAnimation)
2009 {
2010     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
2011         FI_HILOGE("Drag instance not running");
2012         return;
2013     }
2014     DragData dragData = DRAG_DATA_MGR.GetDragData();
2015     FI_HILOGI("displayId:%{public}d, x:%{private}d, y:%{private}d", dragData.displayId, x, y);
2016     dragDrawing_.Draw(dragData.displayId, x, y, true, isMultiSelectedAnimation);
2017 }
2018 
SetMultiSelectedAnimationFlag(bool needMultiSelectedAnimation)2019 void DragManager::SetMultiSelectedAnimationFlag(bool needMultiSelectedAnimation)
2020 {
2021     FI_HILOGI("needMultiSelectedAnimation:%{public}d", needMultiSelectedAnimation);
2022 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
2023     CHKPV(context_);
2024     int32_t ret = context_->GetDelegateTasks().PostAsyncTask([this, needMultiSelectedAnimation] {
2025         this->dragDrawing_.SetMultiSelectedAnimationFlag(needMultiSelectedAnimation);
2026         return RET_OK;
2027     });
2028     if (ret != RET_OK) {
2029         FI_HILOGE("Post async task failed, ret:%{public}d", ret);
2030     }
2031 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2032 }
2033 
UpdatePreviewStyle(const PreviewStyle & previewStyle)2034 int32_t DragManager::UpdatePreviewStyle(const PreviewStyle &previewStyle)
2035 {
2036     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
2037         FI_HILOGE("Drag instance not running");
2038         return RET_ERR;
2039     }
2040     if (previewStyle == DRAG_DATA_MGR.GetPreviewStyle()) {
2041         FI_HILOGD("Not need to update previewStyle");
2042         return RET_OK;
2043     }
2044     DRAG_DATA_MGR.SetPreviewStyle(previewStyle);
2045     FI_HILOGI("Update previewStyle successfully");
2046     return dragDrawing_.UpdatePreviewStyle(previewStyle);
2047 }
2048 
UpdatePreviewStyleWithAnimation(const PreviewStyle & previewStyle,const PreviewAnimation & animation)2049 int32_t DragManager::UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle,
2050     const PreviewAnimation &animation)
2051 {
2052     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
2053         FI_HILOGE("Drag instance not running");
2054         return RET_ERR;
2055     }
2056     if (previewStyle == DRAG_DATA_MGR.GetPreviewStyle()) {
2057         FI_HILOGD("Not need to update previewStyle");
2058         return RET_OK;
2059     }
2060     DRAG_DATA_MGR.SetPreviewStyle(previewStyle);
2061     FI_HILOGI("Update previewStyle successfully");
2062     return dragDrawing_.UpdatePreviewStyleWithAnimation(previewStyle, animation);
2063 }
2064 
RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)2065 int32_t DragManager::RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)
2066 {
2067 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
2068     auto SetDragWindowRotateAnimation = [rsTransaction, this]() {
2069         return dragDrawing_.RotateDragWindowSync(rsTransaction);
2070     };
2071     CHKPR(context_, RET_ERR);
2072     int32_t ret = context_->GetDelegateTasks().PostAsyncTask(SetDragWindowRotateAnimation);
2073     if (ret != RET_OK) {
2074         FI_HILOGE("Post async task failed, ret:%{public}d", ret);
2075         return ret;
2076     }
2077     return RET_OK;
2078 #else
2079     return dragDrawing_.RotateDragWindowSync(rsTransaction);
2080 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2081 }
2082 
SetDragWindowScreenId(uint64_t displayId,uint64_t screenId)2083 void DragManager::SetDragWindowScreenId(uint64_t displayId, uint64_t screenId)
2084 {
2085     FI_HILOGI("displayId:%{public}" PRId64 ", screenId:%{public}" PRId64 "", displayId, screenId);
2086     displayId_ = displayId;
2087     screenId_ = screenId;
2088 }
2089 
2090 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
SimulatePullCancelEvent()2091 void DragManager::SimulatePullCancelEvent()
2092 {
2093     CHKPV(currentPointerEvent_);
2094     currentPointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_CANCEL);
2095     MMI::InputManager::GetInstance()->SimulateInputEvent(currentPointerEvent_);
2096 }
2097 
DragKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent)2098 void DragManager::DragKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent)
2099 {
2100     CHKPV(keyEvent);
2101     if (keyEvent->GetKeyCode() == MMI::KeyEvent::KEYCODE_ESCAPE) {
2102         SimulatePullCancelEvent();
2103         return;
2104     }
2105     auto keyItems = keyEvent->GetKeyItems();
2106     auto iter = std::find_if(keyItems.begin(), keyItems.end(),
2107         [] (std::optional<MMI::KeyEvent::KeyItem> keyItem) {
2108             return ((keyItem->GetKeyCode() == MMI::KeyEvent::KEYCODE_CTRL_LEFT) ||
2109                     (keyItem->GetKeyCode() == MMI::KeyEvent::KEYCODE_CTRL_RIGHT));
2110         });
2111     if (iter == keyItems.end()) {
2112         dragAction_.store(DragAction::MOVE);
2113         return;
2114     }
2115     if ((DRAG_DATA_MGR.GetDragStyle() == DragCursorStyle::DEFAULT) ||
2116         (DRAG_DATA_MGR.GetDragStyle() == DragCursorStyle::FORBIDDEN)) {
2117         dragAction_.store(DragAction::MOVE);
2118         return;
2119     }
2120     if (!iter->IsPressed()) {
2121         CtrlKeyStyleChangedNotify(DRAG_DATA_MGR.GetDragStyle(), DragAction::MOVE);
2122         HandleCtrlKeyEvent(DRAG_DATA_MGR.GetDragStyle(), DragAction::MOVE);
2123         dragAction_.store(DragAction::MOVE);
2124         return;
2125     }
2126     if (DRAG_DATA_MGR.GetDragStyle() == DragCursorStyle::COPY) {
2127         FI_HILOGD("Not need update drag style");
2128         return;
2129     }
2130     CtrlKeyStyleChangedNotify(DragCursorStyle::COPY, DragAction::COPY);
2131     HandleCtrlKeyEvent(DragCursorStyle::COPY, DragAction::COPY);
2132     dragAction_.store(DragAction::COPY);
2133 }
2134 
HandleCtrlKeyEvent(DragCursorStyle style,DragAction action)2135 void DragManager::HandleCtrlKeyEvent(DragCursorStyle style, DragAction action)
2136 {
2137     FI_HILOGD("enter");
2138     if (action == dragAction_.load()) {
2139         FI_HILOGD("Not need update drag style");
2140         return;
2141     }
2142     CHKPV(context_);
2143     int32_t ret = context_->GetDelegateTasks().PostAsyncTask([this, style] {
2144         return this->dragDrawing_.UpdateDragStyle(style);
2145     });
2146     if (ret != RET_OK) {
2147         FI_HILOGE("Post async task failed");
2148     }
2149     FI_HILOGD("leave");
2150 }
2151 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2152 
OnUpdateDragStyle(DragCursorStyle style)2153 int32_t DragManager::OnUpdateDragStyle(DragCursorStyle style)
2154 {
2155     FI_HILOGD("enter");
2156     DragCursorStyle updateStyle = GetRealDragStyle(style);
2157 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
2158     stateNotify_.StyleChangedNotify(updateStyle);
2159 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2160     if (dragDrawing_.UpdateDragStyle(updateStyle) != RET_OK) {
2161 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
2162 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
2163         DragDFX::WriteUpdateDragStyle(updateStyle, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
2164 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
2165 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2166         return RET_ERR;
2167     }
2168     FI_HILOGD("Update dragStyle:%{public}s successfully", GetDragStyleName(updateStyle).c_str());
2169     return RET_OK;
2170 }
2171 
UpdateDragStyleCross()2172 void DragManager::UpdateDragStyleCross()
2173 {
2174     FI_HILOGD("enter");
2175     auto dragStyle = DRAG_DATA_MGR.GetDragStyle();
2176     FI_HILOGI("OnUpdateDragStyle dragStyle:%{public}s", GetDragStyleName(dragStyle).c_str());
2177 #ifdef OHOS_ENABLE_PULLTHROW
2178     if (isFoldPC_ && inHoveringState_) {
2179         FI_HILOGD("isFoldPC and inHoveringState, dragstyle set to default");
2180         return;
2181     }
2182 #endif // OHOS_ENABLE_PULLTHROW
2183     if (OnUpdateDragStyle(DRAG_DATA_MGR.GetDragStyle()) != RET_OK) {
2184         FI_HILOGE("OnUpdateDragStyle failed");
2185     }
2186     FI_HILOGD("leave");
2187 }
2188 
GetDragStyleName(DragCursorStyle style)2189 std::string DragManager::GetDragStyleName(DragCursorStyle style)
2190 {
2191     switch (style) {
2192         case DragCursorStyle::DEFAULT : {
2193             return DRAG_STYLE_DEFAULT;
2194         }
2195         case DragCursorStyle::FORBIDDEN : {
2196             return DRAG_STYLE_FORBIDDEN;
2197         }
2198         case DragCursorStyle::COPY : {
2199             return DRAG_STYLE_COPY;
2200         }
2201         case DragCursorStyle::MOVE : {
2202             return DRAG_STYLE_MOVE;
2203         }
2204         default:
2205             break;
2206     }
2207     return DRAG_STYLE_UNKNOW;
2208 }
2209 
GetRealDragStyle(DragCursorStyle style)2210 DragCursorStyle DragManager::GetRealDragStyle(DragCursorStyle style)
2211 {
2212     if ((dragAction_ == DragAction::COPY) && (style == DragCursorStyle::MOVE)) {
2213         return DragCursorStyle::COPY;
2214     }
2215     return style;
2216 }
2217 
GetDragBehavior(const DragDropResult & dropResult,DragBehavior & dragBehavior)2218 void DragManager::GetDragBehavior(const DragDropResult &dropResult, DragBehavior &dragBehavior)
2219 {
2220     FI_HILOGD("enter");
2221     if (dropResult.result != DragResult::DRAG_SUCCESS) {
2222         dragBehavior = DragBehavior::UNKNOWN;
2223         return;
2224     }
2225     if (dragBehavior == DragBehavior::UNKNOWN) {
2226         if (DRAG_DATA_MGR.GetDragStyle() == DragCursorStyle::COPY) {
2227             dragBehavior = DragBehavior::COPY;
2228             return;
2229         }
2230         if (dragAction_.load()== DragAction::COPY) {
2231             dragBehavior = DragBehavior::COPY;
2232             return;
2233         }
2234         DragData dragData = DRAG_DATA_MGR.GetDragData();
2235         if (dropResult.mainWindow == dragData.mainWindow) {
2236             dragBehavior = DragBehavior::MOVE;
2237         } else {
2238             dragBehavior = DragBehavior::COPY;
2239         }
2240     }
2241     FI_HILOGD("leave");
2242 }
2243 
2244 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
CtrlKeyStyleChangedNotify(DragCursorStyle style,DragAction action)2245 void DragManager::CtrlKeyStyleChangedNotify(DragCursorStyle style, DragAction action)
2246 {
2247     FI_HILOGD("enter");
2248     if (action == dragAction_.load()) {
2249         FI_HILOGD("Has notified");
2250         return;
2251     }
2252     CHKPV(context_);
2253     int32_t ret = context_->GetDelegateTasks().PostAsyncTask([this, style] {
2254         return this->stateNotify_.StyleChangedNotify(style);
2255     });
2256     if (ret != RET_OK) {
2257         FI_HILOGE("Post async task failed");
2258     }
2259     FI_HILOGD("leave");
2260 }
2261 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2262 
GetDragAction(DragAction & dragAction) const2263 int32_t DragManager::GetDragAction(DragAction &dragAction) const
2264 {
2265     FI_HILOGD("enter");
2266     if (dragState_ != DragState::START) {
2267         FI_HILOGE("No drag instance running, can not get drag action");
2268         return RET_ERR;
2269     }
2270     dragAction = dragAction_.load();
2271     FI_HILOGD("leave");
2272     return RET_OK;
2273 }
2274 
EnterTextEditorArea(bool enable)2275 int32_t DragManager::EnterTextEditorArea(bool enable)
2276 {
2277     FI_HILOGD("enter");
2278     if (dragState_ != DragState::START) {
2279         FI_HILOGE("No drag instance running");
2280         return RET_ERR;
2281     }
2282     if (DRAG_DATA_MGR.GetTextEditorAreaFlag() == enable) {
2283         FI_HILOGE("Set textEditorArea:%{public}s already", (enable ? "true" : "false"));
2284         return RET_ERR;
2285     }
2286     if (DRAG_DATA_MGR.GetCoordinateCorrected()) {
2287         FI_HILOGE("GetCoordinateCorrected failed");
2288         return RET_ERR;
2289     }
2290     FI_HILOGD("leave");
2291     return dragDrawing_.EnterTextEditorArea(enable);
2292 }
2293 
GetExtraInfo(std::string & extraInfo) const2294 int32_t DragManager::GetExtraInfo(std::string &extraInfo) const
2295 {
2296     FI_HILOGD("enter");
2297     DragData dragData = DRAG_DATA_MGR.GetDragData();
2298     if (dragData.extraInfo.empty()) {
2299         FI_HILOGE("The extraInfo is empty");
2300         return RET_ERR;
2301     }
2302     extraInfo = dragData.extraInfo;
2303     FI_HILOGD("leave");
2304     return RET_OK;
2305 }
2306 
AddPrivilege(int32_t tokenId)2307 int32_t DragManager::AddPrivilege(int32_t tokenId)
2308 {
2309     FI_HILOGD("enter");
2310     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
2311         FI_HILOGE("Drag instance not running");
2312         return RET_ERR;
2313     }
2314     DragData dragData = DRAG_DATA_MGR.GetDragData();
2315     FI_HILOGD("Target window drag tid:%{public}d", tokenId);
2316     SendDragData(tokenId, dragData.udKey);
2317     FI_HILOGD("leave");
2318     return RET_OK;
2319 }
2320 
EraseMouseIcon()2321 int32_t DragManager::EraseMouseIcon()
2322 {
2323     FI_HILOGD("enter");
2324     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
2325         FI_HILOGE("Drag instance not running");
2326         return RET_ERR;
2327     }
2328     dragDrawing_.EraseMouseIcon();
2329     FI_HILOGD("leave");
2330     return RET_OK;
2331 }
2332 
GetDragBundleInfo(DragBundleInfo & dragBundleInfo) const2333 int32_t DragManager::GetDragBundleInfo(DragBundleInfo &dragBundleInfo) const
2334 {
2335     FI_HILOGD("enter");
2336     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
2337         FI_HILOGE("No drag instance running, can not get drag bundle info");
2338         return RET_ERR;
2339     }
2340 
2341     dragBundleInfo.isCrossDevice = isCrossDragging_;
2342 
2343     dragBundleInfo.bundleName = dragPackageName_.appCaller;
2344     FI_HILOGD("leave, bundleName:%{public}s, isCrossDevice:%{public}d",
2345         dragBundleInfo.bundleName.c_str(), dragBundleInfo.isCrossDevice);
2346     return RET_OK;
2347 }
2348 
IsDragStart() const2349 bool DragManager::IsDragStart() const
2350 {
2351     FI_HILOGD("enter");
2352     if (dragState_ == DragState::START) {
2353         FI_HILOGD("the drag state is DragState::START");
2354         return true;
2355     }
2356 
2357     FI_HILOGD("the drag state is not DragState::START, it is %{public}d", static_cast<int32_t>(dragState_));
2358     return false;
2359 }
2360 
2361 #ifdef OHOS_BUILD_INTERNAL_DROP_ANIMATION
EnableInternalDropAnimation(const std::string & animationInfo)2362 int32_t DragManager::EnableInternalDropAnimation(const std::string &animationInfo)
2363 {
2364     FI_HILOGI("enter");
2365     int32_t ret = internalAnimationWrapper_.EnableInternalDropAnimation(animationInfo);
2366     if (ret != RET_OK) {
2367         FI_HILOGD("EnableInternalDropAnimation failed, ret:%{public}d", ret);
2368         return ret;
2369     }
2370     enableInternalDropAnimation_ = true;
2371     return RET_OK;
2372 }
2373 
PerformInternalDropAnimation()2374 int32_t DragManager::PerformInternalDropAnimation()
2375 {
2376     if (enableInternalDropAnimation_) {
2377         enableInternalDropAnimation_ = false;
2378     }
2379     if (context_ != nullptr) {
2380         int32_t repeatCount = 1;
2381         internalDropTimerId_ = context_->GetTimerManager().AddTimer(TIMEOUT_MS,
2382             repeatCount, [this]() {
2383             FI_HILOGW("Timeout, automatically ResetDragState");
2384             this->ResetDragState();
2385         });
2386     }
2387     int32_t ret = internalAnimationWrapper_.PerformInternalDropAnimation(context_);
2388     if ((ret != RET_OK) && (context_ != nullptr) && (internalDropTimerId_ >= 0)) {
2389         context_->GetTimerManager().RemoveTimer(internalDropTimerId_);
2390         internalDropTimerId_ = -1;
2391     }
2392     return ret;
2393 }
2394 
GetDragDrawingInfo(DragInternalInfo & dragInternalInfo)2395 void DragManager::GetDragDrawingInfo(DragInternalInfo &dragInternalInfo)
2396 {
2397     return dragDrawing_.GetDragDrawingInfo(dragInternalInfo);
2398 }
2399 
ResetDragState()2400 void DragManager::ResetDragState()
2401 {
2402     FI_HILOGI("enter");
2403     if ((context_ != nullptr) && (internalDropTimerId_ >= 0)) {
2404         context_->GetTimerManager().RemoveTimer(internalDropTimerId_);
2405         internalDropTimerId_ = -1;
2406     }
2407     dragDrawing_.DestroyDragWindow();
2408     dragDrawing_.UpdateDrawingState();
2409     FI_HILOGI("leave");
2410 }
2411 
ResetAnimationParameter()2412 void DragManager::ResetAnimationParameter()
2413 {
2414     FI_HILOGI("enter");
2415     dragDrawing_.ResetAnimationParameter();
2416     dragDrawing_.StopVSyncStation();
2417     dragDrawing_.RemoveStyleNodeAnimations();
2418     FI_HILOGI("leave");
2419 }
2420 #endif // OHOS_BUILD_INTERNAL_DROP_ANIMATION
2421 
RotateDragWindow(Rosen::DisplayId displayId,Rosen::Rotation rotation)2422 int32_t DragManager::RotateDragWindow(Rosen::DisplayId displayId, Rosen::Rotation rotation)
2423 {
2424     FI_HILOGI("displayId:%{public}d, rotation:%{public}d",
2425         static_cast<int32_t>(displayId), static_cast<int32_t>(rotation));
2426     auto SetDragWindowRotate = [displayId, rotation, this]() {
2427         SetRotation(displayId, rotation);
2428         if ((dragState_ == DragState::START) || (dragState_ == DragState::MOTION_DRAGGING)) {
2429             if (static_cast<int32_t>(displayId) == lastDisplayId_) {
2430                 return dragDrawing_.RotateDragWindowAsync(rotation);
2431             }
2432         }
2433         return RET_OK;
2434     };
2435 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
2436     CHKPR(context_, RET_ERR);
2437     int32_t ret = context_->GetDelegateTasks().PostAsyncTask(SetDragWindowRotate);
2438     if (ret != RET_OK) {
2439         FI_HILOGE("Post async task failed, ret:%{public}d", ret);
2440         return ret;
2441     }
2442 #else
2443     SetDragWindowRotate();
2444 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2445     FI_HILOGD("leave");
2446     return RET_OK;
2447 }
2448 
SetRotation(Rosen::DisplayId displayId,Rosen::Rotation rotation)2449 void DragManager::SetRotation(Rosen::DisplayId displayId, Rosen::Rotation rotation)
2450 {
2451 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
2452     CHKPV(context_);
2453     context_->GetDelegateTasks().PostSyncTask([this, displayId, rotation] {
2454         this->dragDrawing_.SetRotation(displayId, rotation);
2455         return RET_OK;
2456     });
2457 #else
2458     dragDrawing_.SetRotation(displayId, rotation);
2459 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2460 }
2461 
GetRotation(Rosen::DisplayId displayId)2462 Rosen::Rotation DragManager::GetRotation(Rosen::DisplayId displayId)
2463 {
2464     Rosen::Rotation rotation = Rosen::Rotation::ROTATION_0;
2465 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
2466     if (context_ != nullptr) {
2467         context_->GetDelegateTasks().PostSyncTask([this, displayId, &rotation] {
2468             rotation = this->dragDrawing_.GetRotation(displayId);
2469             return RET_OK;
2470         });
2471     }
2472 #else
2473     rotation = dragDrawing_.GetRotation(displayId);
2474 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2475     return rotation;
2476 }
2477 
RemoveDisplayIdFromMap(Rosen::DisplayId displayId)2478 void DragManager::RemoveDisplayIdFromMap(Rosen::DisplayId displayId)
2479 {
2480 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
2481     CHKPV(context_);
2482     context_->GetDelegateTasks().PostSyncTask([this, displayId] {
2483         this->dragDrawing_.RemoveDisplayIdFromMap(displayId);
2484         return RET_OK;
2485     });
2486 #else
2487     dragDrawing_.RemoveDisplayIdFromMap(displayId);
2488 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2489 }
2490 
ScreenRotate(Rosen::Rotation rotation,Rosen::Rotation lastRotation)2491 int32_t DragManager::ScreenRotate(Rosen::Rotation rotation, Rosen::Rotation lastRotation)
2492 {
2493     FI_HILOGI("Rotation:%{public}d, lastRotation:%{public}d",
2494         static_cast<int32_t>(rotation), static_cast<int32_t>(lastRotation));
2495     DragData dragData = DRAG_DATA_MGR.GetDragData();
2496     if (dragData.sourceType != MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
2497         FI_HILOGD("Not need screen rotate");
2498         return RET_OK;
2499     }
2500     auto SetDragWindowRotate = [rotation, lastRotation, this]() {
2501         if ((dragState_ == DragState::START) || (dragState_ == DragState::MOTION_DRAGGING)) {
2502             dragDrawing_.ScreenRotate(rotation, lastRotation);
2503         }
2504         return RET_OK;
2505     };
2506 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
2507     CHKPR(context_, RET_ERR);
2508     int32_t ret = context_->GetDelegateTasks().PostAsyncTask(SetDragWindowRotate);
2509     if (ret != RET_OK) {
2510         FI_HILOGE("Post async task failed, ret:%{public}d", ret);
2511         return ret;
2512     }
2513 #else
2514     SetDragWindowRotate();
2515 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2516     FI_HILOGD("leave");
2517     return RET_OK;
2518 }
2519 
2520 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
NotifyAddSelectedPixelMapResult(bool result)2521 int32_t DragManager::NotifyAddSelectedPixelMapResult(bool result)
2522 {
2523     FI_HILOGD("enter");
2524     NetPacket pkt(MessageId::ADD_SELECTED_PIXELMAP_RESULT);
2525     pkt << result;
2526     if (pkt.ChkRWError()) {
2527         FI_HILOGE("Failed to packet write data");
2528         return RET_ERR;
2529     }
2530     CHKPR(dragOutSession_, RET_ERR);
2531     if (!dragOutSession_->SendMsg(pkt)) {
2532         FI_HILOGE("Failed to send message");
2533         return MSG_SEND_FAIL;
2534     }
2535     FI_HILOGD("leave");
2536     return RET_OK;
2537 }
2538 
AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap)2539 int32_t DragManager::AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap)
2540 {
2541     FI_HILOGD("enter");
2542     if (dragState_ != DragState::START) {
2543         FI_HILOGE("Drag not running");
2544         if (NotifyAddSelectedPixelMapResult(false) != RET_OK) {
2545             FI_HILOGE("Notify addSelectedPixelMap result failed");
2546         }
2547         return RET_ERR;
2548     }
2549     if (dragDrawing_.AddSelectedPixelMap(pixelMap) != RET_OK) {
2550         FI_HILOGE("Add select pixelmap fail");
2551         if (NotifyAddSelectedPixelMapResult(false) != RET_OK) {
2552             FI_HILOGE("Notify addSelectedPixelMap result failed");
2553         }
2554         return RET_ERR;
2555     }
2556     DRAG_DATA_MGR.UpdateShadowInfos(pixelMap);
2557     if (NotifyAddSelectedPixelMapResult(true) != RET_OK) {
2558         FI_HILOGW("Notify addSelectedPixelMap result failed");
2559     }
2560     FI_HILOGD("leave");
2561     return RET_OK;
2562 }
2563 
2564 #else
SetDragWindow(std::shared_ptr<OHOS::Rosen::Window> window)2565 void DragManager::SetDragWindow(std::shared_ptr<OHOS::Rosen::Window> window)
2566 {
2567     dragDrawing_.SetDragWindow(window);
2568 }
2569 
AddDragDestroy(std::function<void ()> cb)2570 void DragManager::AddDragDestroy(std::function<void()> cb)
2571 {
2572     dragDrawing_.AddDragDestroy(cb);
2573 }
2574 
SetSVGFilePath(const std::string & filePath)2575 void DragManager::SetSVGFilePath(const std::string &filePath)
2576 {
2577     dragDrawing_.SetSVGFilePath(filePath);
2578 }
2579 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2580 
2581 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
AddDragEvent(const DragData & dragData,const struct DragRadarPackageName & dragRadarPackageName)2582 int32_t DragManager::AddDragEvent(const DragData &dragData, const struct DragRadarPackageName &dragRadarPackageName)
2583 {
2584     bool drawCursor = false;
2585 #ifdef OHOS_BUILD_PC_PRODUCT
2586     if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
2587         drawCursor = true;
2588     }
2589 #endif // OHOS_BUILD_PC_PRODUCT
2590     auto extraData = CreateExtraData(true, drawCursor);
2591     if (MMI::InputManager::GetInstance()->AppendExtraData(extraData) != RET_OK) {
2592         FI_HILOGE("Failed to append extra data to MMI");
2593         dragDrawing_.DestroyDragWindow();
2594         dragDrawing_.UpdateDrawingState();
2595         ReportStartDragFailedRadarInfo(StageRes::RES_FAIL, DragRadarErrCode::FAILED_APPEND_EXTRA_DATA, __func__,
2596             dragRadarPackageName);
2597         return RET_ERR;
2598     }
2599     if (pointerEventMonitorId_ <= 0) {
2600         if (AddDragEventHandler(dragData.sourceType) != RET_OK) {
2601             FI_HILOGE("Failed to add drag event handler");
2602             dragDrawing_.DestroyDragWindow();
2603             dragDrawing_.UpdateDrawingState();
2604             ReportStartDragFailedRadarInfo(StageRes::RES_FAIL, DragRadarErrCode::FAILED_ADD_INPUT_MONITOR, __func__,
2605                 dragRadarPackageName);
2606             return RET_ERR;
2607         }
2608     }
2609     return RET_OK;
2610 }
2611 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2612 
2613 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
ResetMouseDragMonitorInfo()2614 void DragManager::ResetMouseDragMonitorInfo()
2615 {
2616     FI_HILOGI("enter");
2617     RemoveDragEventHandler();
2618     mouseDragMonitorDisplayX_ = -1;
2619     mouseDragMonitorDisplayY_ = -1;
2620     existMouseMoveDragCallback_ = false;
2621     mouseDragMonitorState_ = false;
2622     DRAG_DATA_MGR.SetEventId(-1);
2623     if ((context_ != nullptr) && (mouseDragMonitorTimerId_ >= 0)) {
2624         context_->GetTimerManager().RemoveTimer(mouseDragMonitorTimerId_);
2625         mouseDragMonitorTimerId_ = -1;
2626     }
2627     FI_HILOGI("leave");
2628 }
2629 
SetMouseDragMonitorState(bool state)2630 int32_t DragManager::SetMouseDragMonitorState(bool state)
2631 {
2632     if (state) {
2633         if (AddDragEventHandler(MMI::PointerEvent::SOURCE_TYPE_MOUSE) != RET_OK) {
2634             FI_HILOGE("Failed to add drag event handler");
2635             return RET_ERR;
2636         }
2637         if (context_ != nullptr) {
2638             int32_t repeatCount = 1;
2639             mouseDragMonitorTimerId_ = context_->GetTimerManager().AddTimer(TIMEOUT_MS,
2640                 repeatCount, [this]() {
2641                 FI_HILOGW("Timeout, automatically remove monitor");
2642                 this->ResetMouseDragMonitorInfo();
2643             });
2644         }
2645     } else {
2646         ResetMouseDragMonitorInfo();
2647     }
2648     mouseDragMonitorState_ = state;
2649     return RET_OK;
2650 }
2651 
ReportDragWindowVisibleRadarInfo(StageRes stageRes,DragRadarErrCode errCode,const std::string & funcName)2652 void DragManager::ReportDragWindowVisibleRadarInfo(StageRes stageRes, DragRadarErrCode errCode,
2653     const std::string &funcName)
2654 {
2655 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
2656     HiSysEventWrite(
2657         OHOS::HiviewDFX::HiSysEvent::Domain::MSDP,
2658         DRAG_BEHAVIOR,
2659         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
2660         "ORG_PKG", ORG_PKG_NAME,
2661         "FUNC", funcName,
2662         "BIZ_SCENE", 1,
2663         "BIZ_STATE", static_cast<int32_t>(BizState::STATE_IDLE),
2664         "BIZ_STAGE", static_cast<int32_t>(BizStage::STAGE_DRAGGING),
2665         "STAGE_RES", static_cast<int32_t>(stageRes),
2666         "ERROR_CODE", static_cast<int32_t>(errCode),
2667         "HOST_PKG", "",
2668         "LOCAL_NET_ID", "",
2669         "PEER_NET_ID", "",
2670         "DRAG_SUMMARY", "");
2671 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
2672 }
2673 
ReportStopDragRadarInfo(BizState bizState,StageRes stageRes,DragRadarErrCode errCode,int32_t pid,struct DragRadarPackageName & dragRadarPackageName)2674 void DragManager::ReportStopDragRadarInfo(BizState bizState, StageRes stageRes, DragRadarErrCode errCode, int32_t pid,
2675     struct DragRadarPackageName &dragRadarPackageName)
2676 {
2677     DragRadarInfo dragRadarInfo;
2678     dragRadarInfo.funcName = "StopDrag";
2679     dragRadarInfo.bizState = static_cast<int32_t>(bizState);
2680     dragRadarInfo.bizStage = static_cast<int32_t>(BizStage::STAGE_STOP_DRAG);
2681     dragRadarInfo.stageRes = static_cast<int32_t>(stageRes);
2682     dragRadarInfo.errCode = static_cast<int32_t>(errCode);
2683     dragRadarInfo.hostName = dragRadarPackageName.packageName;
2684     dragRadarInfo.callingPid = std::to_string(pid);
2685     dragRadarInfo.appCallee = dragRadarPackageName.appCallee;
2686     dragRadarInfo.peerNetId = dragRadarPackageName.peerNetId;
2687     dragRadarInfo.dragNum = dragRadarPackageName.dragNum;
2688     ReportDragRadarInfo(dragRadarInfo);
2689 }
2690 
ReportStartDragRadarInfo(BizState bizState,StageRes stageRes,DragRadarErrCode errCode,const std::string & peerNetId,struct DragRadarPackageName & dragRadarPackageName)2691 void DragManager::ReportStartDragRadarInfo(BizState bizState, StageRes stageRes, DragRadarErrCode errCode,
2692     const std::string &peerNetId, struct DragRadarPackageName &dragRadarPackageName)
2693 {
2694     DragRadarInfo dragRadarInfo;
2695     dragRadarInfo.funcName = "StartDrag";
2696     dragRadarInfo.bizState = static_cast<int32_t>(bizState);
2697     dragRadarInfo.bizStage = static_cast<int32_t>(BizStage::STAGE_START_DRAG);
2698     dragRadarInfo.stageRes = static_cast<int32_t>(stageRes);
2699     dragRadarInfo.errCode = static_cast<int32_t>(errCode);
2700     dragRadarInfo.hostName = dragRadarPackageName.packageName;
2701     dragRadarInfo.peerNetId = peerNetId;
2702     dragRadarInfo.appCaller = dragRadarPackageName.appCaller;
2703     dragRadarInfo.dragNum = dragRadarPackageName.dragNum;
2704     ReportDragRadarInfo(dragRadarInfo);
2705 }
2706 
ReportStartDragFailedRadarInfo(StageRes stageRes,DragRadarErrCode errCode,const std::string & funcName,const struct DragRadarPackageName & dragRadarPackageName)2707 void DragManager::ReportStartDragFailedRadarInfo(StageRes stageRes, DragRadarErrCode errCode,
2708     const std::string &funcName, const struct DragRadarPackageName &dragRadarPackageName)
2709 {
2710     DragRadarInfo dragRadarInfo;
2711     dragRadarInfo.funcName = funcName;
2712     dragRadarInfo.bizState = static_cast<int32_t>(BizState::STATE_END);
2713     dragRadarInfo.bizStage = static_cast<int32_t>(BizStage::STAGE_START_DRAG);
2714     dragRadarInfo.stageRes = static_cast<int32_t>(stageRes);
2715     dragRadarInfo.errCode = static_cast<int32_t>(errCode);
2716     dragRadarInfo.hostName = dragRadarPackageName.packageName;
2717     dragRadarInfo.appCaller = dragRadarPackageName.appCaller;
2718     dragRadarInfo.dragNum = dragRadarPackageName.dragNum;
2719     ReportDragRadarInfo(dragRadarInfo);
2720 }
2721 
ReportDragRadarInfo(struct DragRadarInfo & dragRadarInfo)2722 void DragManager::ReportDragRadarInfo(struct DragRadarInfo &dragRadarInfo)
2723 {
2724 #ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
2725     DragData dragData = DRAG_DATA_MGR.GetDragData();
2726     std::string summary;
2727     for (const auto &[udKey, recordSize] : dragData.summarys) {
2728         std::string str = udKey + "-" + std::to_string(recordSize) + ";";
2729         summary += str;
2730     }
2731     HiSysEventWrite(
2732         OHOS::HiviewDFX::HiSysEvent::Domain::MSDP,
2733         DRAG_BEHAVIOR,
2734         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
2735         "ORG_PKG", ORG_PKG_NAME,
2736         "FUNC", dragRadarInfo.funcName,
2737         "BIZ_SCENE", 1,
2738         "BIZ_STATE", dragRadarInfo.bizState,
2739         "BIZ_STAGE", dragRadarInfo.bizStage,
2740         "STAGE_RES", dragRadarInfo.stageRes,
2741         "ERROR_CODE", dragRadarInfo.errCode,
2742         "HOST_PKG", dragRadarInfo.hostName,
2743         "LOCAL_NET_ID", dragRadarInfo.localNetId,
2744         "PEER_NET_ID", dragRadarInfo.peerNetId,
2745         "DRAG_SUMMARY", summary,
2746         "PACKAGE_NAME", dragRadarInfo.callingPid,
2747         "APP_CALLEE", dragRadarInfo.appCallee,
2748         "APP_CALLER", dragRadarInfo.appCaller,
2749         "DRAG_NUM", dragRadarInfo.dragNum);
2750 #endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE
2751 }
2752 
ReportStartDragUEInfo(const std::string & packageName)2753 void DragManager::ReportStartDragUEInfo(const std::string &packageName)
2754 {
2755     DragRadarInfo dragRadarInfo;
2756     dragRadarInfo.packageName = DRAG_FRAMEWORK;
2757     dragRadarInfo.appVersionId = APP_VERSION_ID;
2758     dragRadarInfo.hostName = packageName;
2759     dragRadarInfo.localNetId = Utility::DFXRadarAnonymize(IDSoftbusAdapter::GetLocalNetworkId().c_str());
2760     dragRadarInfo.peerNetId = peerNetId_;
2761     ReportDragUEInfo(dragRadarInfo, START_CROSSING_DRAG);
2762 }
2763 
ReportStopDragUEInfo(const std::string & packageName)2764 void DragManager::ReportStopDragUEInfo(const std::string &packageName)
2765 {
2766     DragRadarInfo dragRadarInfo;
2767     dragRadarInfo.packageName = DRAG_FRAMEWORK;
2768     dragRadarInfo.appVersionId = APP_VERSION_ID;
2769     dragRadarInfo.hostName = packageName;
2770     dragRadarInfo.localNetId = Utility::DFXRadarAnonymize(IDSoftbusAdapter::GetLocalNetworkId().c_str());
2771     dragRadarInfo.peerNetId = peerNetId_;
2772     ReportDragUEInfo(dragRadarInfo, END_CROSSING_DRAG);
2773 }
2774 
ReportDragUEInfo(struct DragRadarInfo & dragRadarInfo,const std::string & eventDescription)2775 void DragManager::ReportDragUEInfo(struct DragRadarInfo &dragRadarInfo, const std::string &eventDescription)
2776 {
2777     HiSysEventWrite(
2778         OHOS::HiviewDFX::HiSysEvent::Domain::DRAG_UE,
2779         eventDescription,
2780         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
2781         "PNAMEID", dragRadarInfo.packageName,
2782         "PVERSIONID", dragRadarInfo.appVersionId,
2783         "HOSTNAME", dragRadarInfo.hostName,
2784         "LOCAL_NET_ID", dragRadarInfo.localNetId,
2785         "PEER_NET_ID", dragRadarInfo.peerNetId);
2786 }
2787 #endif // OHOS_BUILD_ENABLE_ARKUI_X
2788 } // namespace DeviceStatus
2789 } // namespace Msdp
2790 } // namespace OHOS
2791