• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "extra_data.h"
22 #include "hitrace_meter.h"
23 #include "pixel_map.h"
24 #include "udmf_client.h"
25 #include "unified_types.h"
26 #include "window_manager_lite.h"
27 
28 #include "devicestatus_define.h"
29 #include "drag_data.h"
30 #include "drag_data_manager.h"
31 #include "drag_hisysevent.h"
32 #include "fi_log.h"
33 #include "proto.h"
34 
35 #undef LOG_TAG
36 #define LOG_TAG "DragManager"
37 namespace OHOS {
38 namespace Msdp {
39 namespace DeviceStatus {
40 namespace {
41 constexpr int32_t TIMEOUT_MS { 3000 };
42 constexpr int32_t INTERVAL_MS { 500 };
43 std::atomic<int64_t> g_startFilterTime { -1 };
44 const std::string DRAG_STYLE_DEFAULT {"DEFAULT"};
45 const std::string DRAG_STYLE_FORBIDDEN {"FORBIDDEN"};
46 const std::string DRAG_STYLE_COPY {"COPY"};
47 const std::string DRAG_STYLE_MOVE {"MOVE"};
48 const std::string DRAG_STYLE_UNKNOW {"UNKNOW"};
49 const std::string DRAG_BEHAVIOR {"DRAG_BEHAVIOR"};
50 const std::string ORG_PKG_NAME {"device_status"};
51 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
52 constexpr int32_t DRAG_PRIORITY { 500 };
53 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
54 } // namespace
55 
~DragManager()56 DragManager::~DragManager()
57 {
58     EventHub::UnRegisterEvent(eventHub_);
59 }
60 
Init(IContext * context)61 int32_t DragManager::Init(IContext* context)
62 {
63     FI_HILOGI("enter");
64     CHKPR(context, RET_ERR);
65     context_ = context;
66     int32_t repeatCount = 1;
67     context_->GetTimerManager().AddTimer(INTERVAL_MS, repeatCount, [this]() {
68         if (eventHub_ == nullptr) {
69             eventHub_ = EventHub::GetEventHub(context_);
70         }
71         auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
72         if (samgrProxy == nullptr) {
73             FI_HILOGE("samgrProxy is nullptr");
74             return;
75         }
76         statusListener_ = new (std::nothrow) DragAbilityStatusChange(eventHub_);
77         if (statusListener_ == nullptr) {
78             FI_HILOGE("statusListener_ is nullptr");
79             return;
80         }
81         int32_t ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusListener_);
82         FI_HILOGI("SubscribeSystemAbility COMMON_EVENT_SERVICE_ID result:%{public}d", ret);
83         displayAbilityStatusChange_ = new (std::nothrow) DisplayAbilityStatusChange(context_);
84         if (displayAbilityStatusChange_ == nullptr) {
85             FI_HILOGE("displayAbilityStatusChange is nullptr");
86             return;
87         }
88         ret = samgrProxy->SubscribeSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, displayAbilityStatusChange_);
89         FI_HILOGI("SubscribeSystemAbility DISPLAY_MANAGER_SERVICE_SA_ID result:%{public}d", ret);
90         appStateObserverStatusChange_ = new (std::nothrow) AppStateObserverStatusChange(context_);
91         if (appStateObserverStatusChange_ == nullptr) {
92             FI_HILOGE("appStateObserverStatusChange_ is nullptr");
93             return;
94         }
95         ret = samgrProxy->SubscribeSystemAbility(APP_MGR_SERVICE_ID, appStateObserverStatusChange_);
96         FI_HILOGI("SubscribeSystemAbility APP_MGR_SERVICE_ID result:%{public}d", ret);
97         CollaborationServiceStatusChange_ = new (std::nothrow) CollaborationServiceStatusChange(context_);
98         if (CollaborationServiceStatusChange_ == nullptr) {
99             FI_HILOGE("CollaborationServiceStatusChange_ is nullptr");
100             return;
101         }
102         ret = samgrProxy->SubscribeSystemAbility(DEVICE_COLLABORATION_SA_ID, CollaborationServiceStatusChange_);
103         FI_HILOGI("SubscribeSystemAbility DEVICE_COLLABORATION_SA_ID result:%{public}d", ret);
104     });
105     FI_HILOGI("leave");
106     return RET_OK;
107 }
108 
OnSessionLost(SocketSessionPtr session)109 void DragManager::OnSessionLost(SocketSessionPtr session)
110 {
111     CHKPV(session);
112     RemoveListener(session->GetPid());
113 }
114 
AddListener(int32_t pid)115 int32_t DragManager::AddListener(int32_t pid)
116 {
117     FI_HILOGI("enter");
118     CHKPR(context_, RET_ERR);
119     auto session = context_->GetSocketSessionManager().FindSessionByPid(pid);
120     CHKPR(session, RET_ERR);
121     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
122     info->session = session;
123     info->msgId = MessageId::DRAG_STATE_LISTENER;
124     info->msgType = MessageType::NOTIFY_STATE;
125     stateNotify_.AddNotifyMsg(info);
126     context_->GetSocketSessionManager().AddSessionDeletedCallback(pid,
127         [this](SocketSessionPtr session) { this->OnSessionLost(session); });
128     FI_HILOGI("leave");
129     return RET_OK;
130 }
131 
RemoveListener(int32_t pid)132 int32_t DragManager::RemoveListener(int32_t pid)
133 {
134     FI_HILOGI("Remove listener, pid:%{public}d", pid);
135     CHKPR(context_, RET_ERR);
136     auto session = context_->GetSocketSessionManager().FindSessionByPid(pid);
137     CHKPR(session, RET_ERR);
138     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
139     info->session = session;
140     info->msgType = MessageType::NOTIFY_STATE;
141     stateNotify_.RemoveNotifyMsg(info);
142     FI_HILOGI("leave");
143     return RET_OK;
144 }
145 
AddSubscriptListener(int32_t pid)146 int32_t DragManager::AddSubscriptListener(int32_t pid)
147 {
148     FI_HILOGI("enter");
149     CHKPR(context_, RET_ERR);
150     auto session = context_->GetSocketSessionManager().FindSessionByPid(pid);
151     CHKPR(session, RET_ERR);
152     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
153     info->session = session;
154     info->msgId = MessageId::DRAG_STYLE_LISTENER;
155     info->msgType = MessageType::NOTIFY_STYLE;
156     stateNotify_.AddNotifyMsg(info);
157     FI_HILOGI("leave");
158     return RET_OK;
159 }
160 
RemoveSubscriptListener(int32_t pid)161 int32_t DragManager::RemoveSubscriptListener(int32_t pid)
162 {
163     FI_HILOGI("enter");
164     CHKPR(context_, RET_ERR);
165     auto session = context_->GetSocketSessionManager().FindSessionByPid(pid);
166     CHKPR(session, RET_ERR);
167     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
168     info->msgType = MessageType::NOTIFY_STYLE;
169     info->session = session;
170     stateNotify_.RemoveNotifyMsg(info);
171     FI_HILOGI("leave");
172     return RET_OK;
173 }
174 
PrintDragData(const DragData & dragData,const std::string & packageName)175 void DragManager::PrintDragData(const DragData &dragData, const std::string &packageName)
176 {
177     FI_HILOGI("enter");
178     for (const auto& shadowInfo : dragData.shadowInfos) {
179         CHKPV(shadowInfo.pixelMap);
180         FI_HILOGI("PixelFormat:%{public}d, PixelAlphaType:%{public}d, PixelAllocatorType:%{public}d,"
181             " PixelWidth:%{public}d, PixelHeight:%{public}d, shadowX:%{public}d, shadowY:%{public}d",
182             static_cast<int32_t>(shadowInfo.pixelMap->GetPixelFormat()),
183             static_cast<int32_t>(shadowInfo.pixelMap->GetAlphaType()),
184             static_cast<int32_t>(shadowInfo.pixelMap->GetAllocatorType()),
185             shadowInfo.pixelMap->GetWidth(), shadowInfo.pixelMap->GetHeight(), shadowInfo.x, shadowInfo.y);
186     }
187     std::string summarys;
188     for (const auto &[udKey, recordSize] : dragData.summarys) {
189         std::string str = udKey + "-" + std::to_string(recordSize) + ";";
190         summarys += str;
191     }
192     FI_HILOGI("SourceType:%{public}d, pointerId:%{public}d, displayId:%{public}d,"
193         " displayX:%{private}d, displayY:%{private}d, dragNum:%{public}d,"
194         " hasCanceledAnimation:%{public}d, udKey:%{public}s, hasCoordinateCorrected:%{public}d, summarys:%{public}s,"
195         " packageName:%{public}s", dragData.sourceType, dragData.pointerId, dragData.displayId, dragData.displayX,
196         dragData.displayY, dragData.dragNum, dragData.hasCanceledAnimation, GetAnonyString(dragData.udKey).c_str(),
197         dragData.hasCoordinateCorrected, summarys.c_str(), packageName.c_str());
198 }
199 
StartDrag(const DragData & dragData,int32_t pid)200 int32_t DragManager::StartDrag(const DragData &dragData, int32_t pid)
201 {
202     FI_HILOGI("enter");
203     if ((context_ != nullptr) && (mouseDragMonitorTimerId_ >= 0) &&
204         (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE)) {
205         context_->GetTimerManager().RemoveTimer(mouseDragMonitorTimerId_);
206         mouseDragMonitorTimerId_ = -1;
207     }
208     if (!IsAllowStartDrag()) {
209         FI_HILOGE("Dragging is not allowed when there is an up event");
210         SetAllowStartDrag(true);
211         SetCooperatePriv(0);
212         return RET_ERR;
213     }
214     if (dragState_ == DragState::START) {
215         FI_HILOGE("Drag instance already exists, no need to start drag again");
216         return RET_ERR;
217     }
218     std::string packageName = std::string();
219     CHKPR(context_, RET_ERR);
220     if (pid == -1) {
221         packageName = "Cross-device drag";
222     } else {
223         context_->GetSocketSessionManager().AddSessionDeletedCallback(pid,
224             [this](SocketSessionPtr session) { this->OnSessionLost(session); });
225         dragOutSession_ = context_->GetSocketSessionManager().FindSessionByPid(pid);
226         if (dragOutSession_ != nullptr) {
227             packageName = dragOutSession_->GetProgramName();
228         }
229     }
230     ReportStartDragRadarInfo(BizState::STATE_BEGIN, StageRes::RES_IDLE, DragRadarErrCode::DRAG_SUCCESS, packageName);
231     PrintDragData(dragData, packageName);
232     if (InitDataManager(dragData) != RET_OK) {
233         FI_HILOGE("Failed to init data manager");
234         ResetMouseDragMonitorInfo();
235         ReportStartDragFailedRadarInfo(StageRes::RES_FAIL, DragRadarErrCode::INVALID_DRAG_DATA, __func__, packageName);
236         return RET_ERR;
237     }
238     if (OnStartDrag(packageName) != RET_OK) {
239         DragDFX::WriteStartDrag(dragState_, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
240         FI_HILOGE("Failed to execute OnStartDrag");
241         ResetMouseDragMonitorInfo();
242         return RET_ERR;
243     }
244     if (notifyPUllUpCallback_ != nullptr) {
245         notifyPUllUpCallback_(false);
246     }
247     SetDragState(DragState::START);
248     stateNotify_.StateChangedNotify(DragState::START);
249     StateChangedNotify(DragState::START);
250     ReportStartDragRadarInfo(BizState::STATE_IDLE, StageRes::RES_SUCCESS, DragRadarErrCode::DRAG_SUCCESS, packageName);
251     FI_HILOGI("leave");
252     return RET_OK;
253 }
254 
StopDrag(const DragDropResult & dropResult,const std::string & packageName,int32_t pid)255 int32_t DragManager::StopDrag(const DragDropResult &dropResult, const std::string &packageName, int32_t pid)
256 {
257     ReportStopDragRadarInfo(BizState::STATE_IDLE, StageRes::RES_IDLE, DragRadarErrCode::DRAG_SUCCESS, pid, packageName);
258     std::string dragOutPkgName =
259         (dragOutSession_ == nullptr) ? "Cross-device drag" : dragOutSession_->GetProgramName();
260     FI_HILOGI("mainWindow:%{public}d, dragResult:%{public}d, drop packageName:%{public}s,"
261         "drag out packageName:%{public}s", dropResult.mainWindow, dropResult.result, packageName.c_str(),
262         dragOutPkgName.c_str());
263     if (dragState_ == DragState::STOP) {
264         FI_HILOGE("No drag instance running, can not stop drag");
265         ReportStopDragRadarInfo(BizState::STATE_END, StageRes::RES_FAIL, DragRadarErrCode::REPEATE_STOP_DRAG_EXCEPTION,
266             pid, packageName);
267         return RET_ERR;
268     }
269 #ifdef OHOS_DRAG_ENABLE_ANIMATION
270     dragDrawing_.NotifyDragInfo(dragOutPkgName, packageName);
271 #endif // OHOS_DRAG_ENABLE_ANIMATION
272     if ((dropResult.result != DragResult::DRAG_EXCEPTION) && (context_ != nullptr) && (timerId_ >= 0)) {
273         context_->GetTimerManager().RemoveTimer(timerId_);
274         timerId_ = -1;
275     }
276     int32_t ret = RET_OK;
277     if (OnStopDrag(dropResult.result, dropResult.hasCustomAnimation, packageName, pid) != RET_OK) {
278         DragDFX::WriteStopDrag(dragState_, dropResult, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
279         FI_HILOGE("On stop drag failed");
280         ret = RET_ERR;
281     }
282     if (dropResult.result == DragResult::DRAG_SUCCESS && dropResult.mainWindow > 0) {
283         Rosen::WMError result = Rosen::WindowManagerLite::GetInstance().RaiseWindowToTop(dropResult.mainWindow);
284         if (result != Rosen::WMError::WM_OK) {
285             FI_HILOGE("Raise window to top failed, mainWindow:%{public}d", dropResult.mainWindow);
286         }
287     }
288     stateNotify_.StateChangedNotify(DragState::STOP);
289     DragBehavior dragBehavior = dropResult.dragBehavior;
290     GetDragBehavior(dropResult, dragBehavior);
291     if (NotifyDragResult(dropResult.result, dragBehavior) != RET_OK) {
292         FI_HILOGE("Notify drag result failed");
293         ReportStopDragRadarInfo(BizState::STATE_IDLE, StageRes::RES_FAIL, DragRadarErrCode::FAILED_NOTIFY_DRAG_RESULT,
294             pid, packageName);
295     }
296     lastEventId_ = -1;
297     mouseDragMonitorDisplayX_ = -1;
298     mouseDragMonitorDisplayY_ = -1;
299     mouseDragMonitorState_ = false;
300     existMouseMoveDragCallback_ = false;
301     DRAG_DATA_MGR.ResetDragData();
302     SetAllowStartDrag(true);
303     SetCooperatePriv(0);
304     dragResult_ = static_cast<DragResult>(dropResult.result);
305     StateChangedNotify(DragState::STOP);
306     SetDragState(DragState::STOP);
307     if (isControlMultiScreenVisible_) {
308         isControlMultiScreenVisible_ = false;
309     }
310     ReportStopDragRadarInfo(BizState::STATE_END, StageRes::RES_SUCCESS, DragRadarErrCode::DRAG_SUCCESS, pid,
311         packageName);
312     FI_HILOGI("leave");
313     return ret;
314 }
315 
GetDragTargetPid() const316 int32_t DragManager::GetDragTargetPid() const
317 {
318     FI_HILOGI("enter");
319     return DRAG_DATA_MGR.GetTargetPid();
320 }
321 
GetUdKey(std::string & udKey) const322 int32_t DragManager::GetUdKey(std::string &udKey) const
323 {
324     FI_HILOGI("enter");
325     DragData dragData = DRAG_DATA_MGR.GetDragData();
326     if (dragData.udKey.empty()) {
327         FI_HILOGE("Target udKey is empty");
328         return RET_ERR;
329     }
330     udKey = dragData.udKey;
331     FI_HILOGI("leave");
332     return RET_OK;
333 }
334 
UpdateDragStyle(DragCursorStyle style,int32_t targetPid,int32_t targetTid,int32_t eventId)335 int32_t DragManager::UpdateDragStyle(DragCursorStyle style, int32_t targetPid, int32_t targetTid, int32_t eventId)
336 {
337     FI_HILOGD("DragStyle from ark is dragStyle:%{public}s, event:%{public}d",
338         GetDragStyleName(style).c_str(), eventId);
339     if ((eventId != -1) && (eventId < lastEventId_)) {
340         FI_HILOGE("Invalid eventId:%{public}d, lastEvent:%{public}d", eventId, lastEventId_);
341         return RET_ERR;
342     }
343     lastEventId_ = eventId;
344     auto lastTargetPid = DRAG_DATA_MGR.GetTargetPid();
345     DRAG_DATA_MGR.SetTargetPid(targetPid);
346     DRAG_DATA_MGR.SetTargetTid(targetTid);
347     if (style == DRAG_DATA_MGR.GetDragStyle()) {
348         FI_HILOGD("Not need update drag style");
349         if (targetPid != lastTargetPid) {
350             stateNotify_.StyleChangedNotify(GetRealDragStyle(style));
351         }
352         return RET_OK;
353     }
354     DRAG_DATA_MGR.SetDragStyle(style);
355     if (dragState_ != DragState::START) {
356         FI_HILOGE("No drag instance running, can not update drag style");
357         return RET_ERR;
358     }
359     if ((style < DragCursorStyle::DEFAULT) || (style > DragCursorStyle::MOVE)) {
360         DragDFX::WriteUpdateDragStyle(style, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
361         FI_HILOGE("Invalid style:%{public}d", style);
362         return RET_ERR;
363     }
364     if (OnUpdateDragStyle(style) != RET_OK) {
365         FI_HILOGE("OnUpdateDragStyle dragStyle:%{public}s failed", GetDragStyleName(style).c_str());
366         return RET_ERR;
367     }
368     return RET_OK;
369 }
370 
UpdateShadowPic(const ShadowInfo & shadowInfo)371 int32_t DragManager::UpdateShadowPic(const ShadowInfo &shadowInfo)
372 {
373     FI_HILOGI("enter");
374     if (dragState_ != DragState::START) {
375         FI_HILOGE("No drag instance running, can not update shadow picture");
376         return RET_ERR;
377     }
378     DRAG_DATA_MGR.SetShadowInfos({ shadowInfo });
379     FI_HILOGI("leave");
380     return dragDrawing_.UpdateShadowPic(shadowInfo);
381 }
382 
GetDragData(DragData & dragData)383 int32_t DragManager::GetDragData(DragData &dragData)
384 {
385     FI_HILOGI("enter");
386     if (dragState_ != DragState::START) {
387         FI_HILOGE("No drag instance running, can not get dragData");
388         return RET_ERR;
389     }
390     dragData = DRAG_DATA_MGR.GetDragData();
391     FI_HILOGI("leave");
392     return RET_OK;
393 }
394 
GetDragState(DragState & dragState)395 int32_t DragManager::GetDragState(DragState &dragState)
396 {
397     FI_HILOGD("enter");
398     dragState = GetDragState();
399     if (dragState == DragState::ERROR) {
400         FI_HILOGE("dragState_ is error");
401         return RET_ERR;
402     }
403     FI_HILOGD("leave");
404     return RET_OK;
405 }
406 
GetDragStyle() const407 DragCursorStyle DragManager::GetDragStyle() const
408 {
409     return DRAG_DATA_MGR.GetDragStyle();
410 }
411 
NotifyDragResult(DragResult result,DragBehavior dragBehavior)412 int32_t DragManager::NotifyDragResult(DragResult result, DragBehavior dragBehavior)
413 {
414     FI_HILOGI("enter");
415     DragData dragData = DRAG_DATA_MGR.GetDragData();
416     int32_t targetPid = GetDragTargetPid();
417     NetPacket pkt(MessageId::DRAG_NOTIFY_RESULT);
418     if ((result < DragResult::DRAG_SUCCESS) || (result > DragResult::DRAG_EXCEPTION)) {
419         DragDFX::WriteNotifyDragResult(result, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
420         FI_HILOGE("The invalid result:%{public}d", static_cast<int32_t>(result));
421         return RET_ERR;
422     }
423     pkt << dragData.displayX << dragData.displayY << static_cast<int32_t>(result) << targetPid <<
424         static_cast<int32_t>(dragBehavior);
425     if (pkt.ChkRWError()) {
426         FI_HILOGE("Failed to packet write data");
427         return RET_ERR;
428     }
429     CHKPR(dragOutSession_, RET_ERR);
430     if (!dragOutSession_->SendMsg(pkt)) {
431         FI_HILOGE("Failed to send message");
432         return MSG_SEND_FAIL;
433     }
434     DragDFX::WriteNotifyDragResult(result, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
435     FI_HILOGI("leave");
436     return RET_OK;
437 }
438 
NotifyHideIcon()439 int32_t DragManager::NotifyHideIcon()
440 {
441     FI_HILOGD("enter");
442     NetPacket pkt(MessageId::DRAG_NOTIFY_HIDE_ICON);
443     if (pkt.ChkRWError()) {
444         FI_HILOGE("Packet write data failed");
445         return RET_ERR;
446     }
447     CHKPR(dragOutSession_, RET_ERR);
448     if (!dragOutSession_->SendMsg(pkt)) {
449         FI_HILOGE("Send message failed");
450         return MSG_SEND_FAIL;
451     }
452     FI_HILOGD("leave");
453     return RET_OK;
454 }
455 
DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent)456 void DragManager::DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent)
457 {
458     CHKPV(pointerEvent);
459     int32_t pointerAction = pointerEvent->GetPointerAction();
460     if ((pointerEvent->GetSourceType() == MMI::PointerEvent::SOURCE_TYPE_MOUSE) &&
461         (pointerAction == MMI::PointerEvent::POINTER_ACTION_MOVE) && mouseDragMonitorState_) {
462         MMI::PointerEvent::PointerItem pointerItem;
463         pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem);
464         mouseDragMonitorDisplayX_ = pointerItem.GetDisplayX();
465         mouseDragMonitorDisplayY_ = pointerItem.GetDisplayY();
466         existMouseMoveDragCallback_ = true;
467     }
468     if (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_MOVE) {
469         mouseDragMonitorDisplayX_ = -1;
470         mouseDragMonitorDisplayY_ = -1;
471         OnDragMove(pointerEvent);
472         return;
473     }
474     FI_HILOGD("DragCallback, pointerAction:%{public}d", pointerAction);
475     if (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_UP) {
476         mouseDragMonitorDisplayX_ = -1;
477         mouseDragMonitorDisplayY_ = -1;
478         CHKPV(context_);
479         int32_t ret = context_->GetDelegateTasks().PostAsyncTask([this, pointerEvent] {
480             return this->OnDragUp(pointerEvent);
481         });
482         if (ret != RET_OK) {
483             FI_HILOGE("Post async task failed");
484         }
485         return;
486     }
487     FI_HILOGD("Unknown action, sourceType:%{public}d, pointerId:%{public}d, pointerAction:%{public}d",
488         pointerEvent->GetSourceType(), pointerEvent->GetPointerId(), pointerAction);
489 }
490 
OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent)491 void DragManager::OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent)
492 {
493     CHKPV(pointerEvent);
494     MMI::PointerEvent::PointerItem pointerItem;
495     pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem);
496     int32_t pointerId = pointerEvent->GetPointerId();
497     int32_t displayX = pointerItem.GetDisplayX();
498     int32_t displayY = pointerItem.GetDisplayY();
499     FI_HILOGD("SourceType:%{public}d, pointerId:%{public}d, displayX:%{private}d, displayY:%{private}d, "
500         "pullId:%{public}d", pointerEvent->GetSourceType(), pointerId, displayX, displayY, pointerEvent->GetPullId());
501     dragDrawing_.OnDragMove(pointerEvent->GetTargetDisplayId(), displayX,
502         displayY, pointerEvent->GetActionTime());
503 }
504 
SendDragData(int32_t targetTid,const std::string & udKey)505 void DragManager::SendDragData(int32_t targetTid, const std::string &udKey)
506 {
507     FI_HILOGI("enter");
508     UDMF::QueryOption option;
509     option.key = udKey;
510     UDMF::Privilege privilege;
511     privilege.tokenId = static_cast<uint32_t>(targetTid);
512     int32_t ret = UDMF::UdmfClient::GetInstance().AddPrivilege(option, privilege);
513     if (ret != RET_OK) {
514         FI_HILOGE("Failed to send pid to Udmf client");
515     }
516     FI_HILOGI("leave");
517 }
518 
OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent)519 int32_t DragManager::OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent)
520 {
521     FI_HILOGI("enter");
522     CHKPR(pointerEvent, RET_ERR);
523     if (notifyPUllUpCallback_ != nullptr) {
524         notifyPUllUpCallback_(true);
525     }
526     if (dragState_ != DragState::START) {
527         FI_HILOGW("No drag instance running");
528         return RET_ERR;
529     }
530     DragData dragData = DRAG_DATA_MGR.GetDragData();
531     if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
532         dragDrawing_.EraseMouseIcon();
533         FI_HILOGI("Set the pointer cursor visible");
534         MMI::InputManager::GetInstance()->SetPointerVisible(true);
535     }
536     CHKPR(context_, RET_ERR);
537     int32_t repeatCount = 1;
538     timerId_ = context_->GetTimerManager().AddTimer(TIMEOUT_MS, repeatCount, [this, dragData]() {
539         DragDropResult dropResult { DragResult::DRAG_EXCEPTION, false, -1 };
540         FI_HILOGW("Timeout, automatically stop dragging");
541         this->StopDrag(dropResult);
542         DragRadarInfo dragRadarInfo;
543         dragRadarInfo.funcName = __func__;
544         dragRadarInfo.bizState = static_cast<int32_t>(BizState::STATE_END);
545         dragRadarInfo.bizStage = static_cast<int32_t>(BizStage::STAGE_STOP_DRAG);
546         dragRadarInfo.stageRes = static_cast<int32_t>(StageRes::RES_FAIL);
547         dragRadarInfo.errCode = static_cast<int32_t>(DragRadarErrCode::DRAG_STOP_EXCEPTION);
548         dragRadarInfo.hostName = "";
549         dragRadarInfo.callingPid = "";
550         ReportDragRadarInfo(dragRadarInfo);
551     });
552     FI_HILOGI("leave");
553     return RET_OK;
554 }
555 
556 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const557 void DragManager::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
558 {
559 }
560 
OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const561 void DragManager::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
562 {
563     CHKPV(pointerEvent);
564     if (g_startFilterTime > 0) {
565         auto actionTime = pointerEvent->GetActionTime();
566         if (g_startFilterTime >= actionTime
567             && pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_MOVE) {
568             FI_HILOGW("Invalid event");
569             return;
570         }
571         g_startFilterTime = -1;
572     }
573     CHKPV(pointerEventCallback_);
574     pointerEventCallback_(pointerEvent);
575     pointerEvent->AddFlag(MMI::InputEvent::EVENT_FLAG_NO_INTERCEPT);
576     MMI::InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
577     if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_UP) {
578         FI_HILOGI("Pointer button is released, appened extra data");
579         MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false));
580     }
581 }
582 
OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const583 void DragManager::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const
584 {
585 }
586 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
587 
588 #ifdef OHOS_DRAG_ENABLE_MONITOR
OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const589 void DragManager::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
590 {
591     FI_HILOGD("enter");
592 }
593 
OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const594 void DragManager::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
595 {
596     FI_HILOGD("enter");
597     CHKPV(pointerEvent);
598     CHKPV(pointerEventCallback_);
599     pointerEventCallback_(pointerEvent);
600     if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_UP) {
601         FI_HILOGI("Pointer button is released, appened extra data");
602         MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false));
603     }
604     FI_HILOGD("leave");
605 }
606 
OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const607 void DragManager::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const
608 {
609     FI_HILOGD("enter");
610 }
611 #endif // OHOS_DRAG_ENABLE_MONITOR
612 
Dump(int32_t fd) const613 void DragManager::Dump(int32_t fd) const
614 {
615     DragCursorStyle style = DRAG_DATA_MGR.GetDragStyle();
616     int32_t targetTid = DRAG_DATA_MGR.GetTargetTid();
617     dprintf(fd, "Drag information:\n");
618 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
619     dprintf(fd,
620             "dragState:%s | dragResult:%s | interceptorId:%d | dragTargetPid:%d | dragTargetTid:%d | "
621             "cursorStyle:%s | isWindowVisble:%s\n", GetDragState(dragState_).c_str(),
622             GetDragResult(dragResult_).c_str(), pointerEventInterceptorId_, GetDragTargetPid(), targetTid,
623             GetDragCursorStyle(style).c_str(), DRAG_DATA_MGR.GetDragWindowVisible() ? "true" : "false");
624 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
625 #ifdef OHOS_DRAG_ENABLE_MONITOR
626     dprintf(fd,
627             "dragState:%s | dragResult:%s | monitorId:%d | dragTargetPid:%d | dragTargetTid:%d | "
628             "cursorStyle:%s | isWindowVisble:%s\n", GetDragState(dragState_).c_str(),
629             GetDragResult(dragResult_).c_str(), pointerEventMonitorId_, GetDragTargetPid(), targetTid,
630             GetDragCursorStyle(style).c_str(), DRAG_DATA_MGR.GetDragWindowVisible() ? "true" : "false");
631 #endif // OHOS_DRAG_ENABLE_MONITOR
632     DragData dragData = DRAG_DATA_MGR.GetDragData();
633     std::string udKey;
634     if (RET_ERR == GetUdKey(udKey)) {
635         FI_HILOGE("Target udKey is empty");
636         udKey = "";
637     }
638     for (const auto& shadowInfo : dragData.shadowInfos) {
639         dprintf(fd, "dragData = {\n""\tshadowInfoX:%d\n\tshadowInfoY\n", shadowInfo.x, shadowInfo.y);
640     }
641     dprintf(fd, "dragData = {\n"
642             "\tudKey:%s\n\tfilterInfo:%s\n\textraInfo:%s\n\tsourceType:%d"
643             "\tdragNum:%d\n\tpointerId:%d\n\tdisplayX:%d\n\tdisplayY:%d\n""\tdisplayId:%d\n\thasCanceledAnimation:%s\n",
644             GetAnonyString(dragData.udKey).c_str(), dragData.filterInfo.c_str(), dragData.extraInfo.c_str(),
645             dragData.sourceType, dragData.dragNum, dragData.pointerId, dragData.displayX, dragData.displayY,
646             dragData.displayId, dragData.hasCanceledAnimation ? "true" : "false");
647     if (dragState_ != DragState::STOP) {
648         for (const auto& shadowInfo : dragData.shadowInfos) {
649             CHKPV(shadowInfo.pixelMap);
650             dprintf(fd, "\tpixelMapWidth:%d\n\tpixelMapHeight:%d\n", shadowInfo.pixelMap->GetWidth(),
651                 shadowInfo.pixelMap->GetHeight());
652         }
653     }
654     dprintf(fd, "}\n");
655 }
656 
GetDragState(DragState value) const657 std::string DragManager::GetDragState(DragState value) const
658 {
659     std::string state = "unknown";
660     const std::map<DragState, std::string> dragStates = {
661         { DragState::START, "start" },
662         { DragState::STOP, "stop" },
663         { DragState::CANCEL, "cancel" },
664         { DragState::ERROR, "error" }
665     };
666     auto iter = dragStates.find(value);
667     if (iter != dragStates.end()) {
668         state = iter->second;
669     }
670     return state;
671 }
672 
GetDragResult(DragResult value) const673 std::string DragManager::GetDragResult(DragResult value) const
674 {
675     std::string result = "unknown";
676     const std::map<DragResult, std::string> dragResults = {
677         { DragResult::DRAG_SUCCESS, "success" },
678         { DragResult::DRAG_FAIL, "fail" },
679         { DragResult::DRAG_CANCEL, "cancel" },
680         { DragResult::DRAG_EXCEPTION, "abnormal" }
681     };
682     auto iter = dragResults.find(value);
683     if (iter != dragResults.end()) {
684         result = iter->second;
685     }
686     return result;
687 }
688 
GetDragCursorStyle(DragCursorStyle value) const689 std::string DragManager::GetDragCursorStyle(DragCursorStyle value) const
690 {
691     std::string style = "unknown";
692     const std::map<DragCursorStyle, std::string> cursorStyles = {
693         { DragCursorStyle::COPY, "copy" },
694         { DragCursorStyle::DEFAULT, "default" },
695         { DragCursorStyle::FORBIDDEN, "forbidden" },
696         { DragCursorStyle::MOVE, "move" }
697     };
698     auto iter = cursorStyles.find(value);
699     if (iter != cursorStyles.end()) {
700         style = iter->second;
701     }
702     return style;
703 }
704 
CreateExtraData(bool appended)705 MMI::ExtraData DragManager::CreateExtraData(bool appended)
706 {
707     DragData dragData = DRAG_DATA_MGR.GetDragData();
708     MMI::ExtraData extraData;
709     extraData.buffer = dragData.buffer;
710     extraData.sourceType = dragData.sourceType;
711     extraData.pointerId = dragData.pointerId;
712     extraData.appended = appended;
713     extraData.pullId = pullId_;
714     FI_HILOGD("sourceType:%{public}d, pointerId:%{public}d", extraData.sourceType, extraData.pointerId);
715     return extraData;
716 }
717 
InitDataManager(const DragData & dragData) const718 int32_t DragManager::InitDataManager(const DragData &dragData) const
719 {
720     FI_HILOGI("enter");
721     DRAG_DATA_MGR.Init(dragData);
722     FI_HILOGI("leave");
723     return RET_OK;
724 }
725 
AddDragEventHandler(int32_t sourceType)726 int32_t DragManager::AddDragEventHandler(int32_t sourceType)
727 {
728     FI_HILOGI("enter");
729     uint32_t deviceTags = 0;
730 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
731     if (sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
732         deviceTags = MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_POINTER);
733     } else if (sourceType == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
734         deviceTags = MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_TOUCH) |
735             MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_TABLET_TOOL);
736     } else {
737         FI_HILOGW("Drag is not supported for this device type:%{public}d", sourceType);
738         return RET_ERR;
739     }
740 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
741     if (AddKeyEventMonitor() != RET_OK) {
742         FI_HILOGE("Failed to add key event handler");
743         return RET_ERR;
744     }
745     if (AddPointerEventHandler(deviceTags) != RET_OK) {
746         FI_HILOGE("Failed to add pointer event handler");
747         return RET_ERR;
748     }
749     FI_HILOGI("leave");
750     return RET_OK;
751 }
752 
AddPointerEventHandler(uint32_t deviceTags)753 int32_t DragManager::AddPointerEventHandler(uint32_t deviceTags)
754 {
755     FI_HILOGI("enter");
756     if (pointerEventMonitorId_ <= 0) {
757 #ifdef OHOS_DRAG_ENABLE_MONITOR
758         auto monitor = std::make_shared<MonitorConsumer>([this](std::shared_ptr<MMI::PointerEvent> pointerEvent) {
759             return this->DragCallback(pointerEvent);
760         });
761         pointerEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(monitor);
762         if (pointerEventMonitorId_ <= 0) {
763             FI_HILOGE("Failed to add pointer event monitor");
764             return RET_ERR;
765         }
766 #else
767         auto callback = [this](std::shared_ptr<MMI::PointerEvent> pointerEvent) {
768             return this->DragCallback(pointerEvent);
769         };
770         auto interceptor = std::make_shared<InterceptorConsumer>(callback);
771         pointerEventInterceptorId_ = MMI::InputManager::GetInstance()->AddInterceptor(
772             interceptor, DRAG_PRIORITY, deviceTags);
773         if (pointerEventInterceptorId_ <= 0) {
774             FI_HILOGE("Failed to add pointer event interceptor");
775             return RET_ERR;
776         }
777 #endif // OHOS_DRAG_ENABLE_MONITOR
778         FI_HILOGI("Add drag poniter event handle successfully");
779         FI_HILOGI("leave");
780         return RET_OK;
781     } else {
782         FI_HILOGI("leave");
783         return RET_ERR;
784     }
785 }
786 
AddKeyEventMonitor()787 int32_t DragManager::AddKeyEventMonitor()
788 {
789     FI_HILOGI("enter");
790     if (keyEventMonitorId_ <= 0) {
791         keyEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(
792             [this](std::shared_ptr<MMI::KeyEvent> keyEvent) {
793                 return this->DragKeyEventCallback(keyEvent);
794             });
795         if (keyEventMonitorId_ <= 0) {
796             FI_HILOGE("Failed to add key event monitor");
797             return RET_ERR;
798         }
799         FI_HILOGI("Add drag key event monitor successfully");
800         FI_HILOGI("leave");
801         return RET_OK;
802     } else {
803         FI_HILOGI("leave");
804         return RET_ERR;
805     }
806 }
807 
RemovePointerEventHandler()808 int32_t DragManager::RemovePointerEventHandler()
809 {
810     FI_HILOGI("enter");
811 #ifdef OHOS_DRAG_ENABLE_MONITOR
812     if (pointerEventMonitorId_ <= 0) {
813         FI_HILOGE("Invalid pointer event monitor id:%{public}d", pointerEventMonitorId_);
814         return RET_ERR;
815     }
816     MMI::InputManager::GetInstance()->RemoveMonitor(pointerEventMonitorId_);
817     pointerEventMonitorId_ = -1;
818 #else
819     if (pointerEventInterceptorId_ <= 0) {
820         FI_HILOGE("Invalid pointer event interceptor id:%{public}d", pointerEventInterceptorId_);
821     }
822     MMI::InputManager::GetInstance()->RemoveInterceptor(pointerEventInterceptorId_);
823     pointerEventInterceptorId_ = -1;
824 #endif // OHOS_DRAG_ENABLE_MONITOR
825     FI_HILOGI("Remove drag pointer event handler successfully");
826     return RET_OK;
827 }
828 
RemoveDragEventHandler()829 int32_t DragManager::RemoveDragEventHandler()
830 {
831     FI_HILOGI("enter");
832     if (RemoveKeyEventMonitor() != RET_OK) {
833         FI_HILOGE("Failed to remove key event handler");
834         return RET_ERR;
835     }
836     if (RemovePointerEventHandler() != RET_OK) {
837         FI_HILOGE("Failed to remove pointer event handler");
838         return RET_ERR;
839     }
840     FI_HILOGI("leave");
841     return RET_OK;
842 }
843 
RemoveKeyEventMonitor()844 int32_t DragManager::RemoveKeyEventMonitor()
845 {
846     FI_HILOGI("enter");
847     if (keyEventMonitorId_ <= 0) {
848         FI_HILOGE("Invalid key event monitor id:%{public}d", keyEventMonitorId_);
849         return RET_ERR;
850     }
851     MMI::InputManager::GetInstance()->RemoveMonitor(keyEventMonitorId_);
852     keyEventMonitorId_ = -1;
853     FI_HILOGI("Remove drag key event handle successfully");
854     return RET_OK;
855 }
856 
OnStartDrag(const std::string & packageName)857 int32_t DragManager::OnStartDrag(const std::string &packageName)
858 {
859     FI_HILOGI("enter");
860     pullId_ = GenerateId();
861     FI_HILOGI("Current pullId:%{public}d", pullId_.load());
862     if (isControlMultiScreenVisible_) {
863         isControlMultiScreenVisible_ = false;
864     }
865     auto extraData = CreateExtraData(true);
866     DragData dragData = DRAG_DATA_MGR.GetDragData();
867     bool isHicarOrSuperLauncher = false;
868     sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDisplayById(dragData.displayId);
869     if (display != nullptr) {
870         std::string displayName = display->GetName();
871         isHicarOrSuperLauncher = ((displayName == "HiCar") || (displayName == "SuperLauncher"));
872     }
873     if (!isHicarOrSuperLauncher) {
874         auto displayId = Rosen::DisplayManager::GetInstance().GetDefaultDisplayId();
875         dragData.displayId = static_cast<int32_t>(displayId);
876     }
877     dragDrawing_.SetScreenId(dragData.displayId);
878     if (Rosen::DisplayManager::GetInstance().IsFoldable() && !isHicarOrSuperLauncher) {
879         if (static_cast<uint64_t>(dragData.displayId) == displayId_) {
880             dragDrawing_.SetScreenId(screenId_);
881         }
882     }
883     int32_t ret = dragDrawing_.Init(dragData, context_);
884     if (ret == INIT_FAIL) {
885         FI_HILOGE("Init drag drawing failed");
886         dragDrawing_.DestroyDragWindow();
887         dragDrawing_.UpdateDrawingState();
888         ReportStartDragFailedRadarInfo(StageRes::RES_FAIL, DragRadarErrCode::FAILED_INIT_DRAWING, __func__,
889             packageName);
890         return RET_ERR;
891     }
892     if (ret == INIT_CANCEL) {
893         FI_HILOGE("Init drag drawing cancel, drag animation is running");
894         ReportStartDragFailedRadarInfo(StageRes::RES_CANCEL, DragRadarErrCode::REPEATE_START_DRAG_EXCEPTION, __func__,
895             packageName);
896         return RET_ERR;
897     }
898     if (!mouseDragMonitorState_ || !existMouseMoveDragCallback_) {
899         dragDrawing_.Draw(dragData.displayId, dragData.displayX, dragData.displayY);
900     } else if (mouseDragMonitorState_ && existMouseMoveDragCallback_ && (mouseDragMonitorDisplayX_ != -1)
901         && (mouseDragMonitorDisplayY_ != -1)) {
902         dragDrawing_.Draw(dragData.displayId, mouseDragMonitorDisplayX_, mouseDragMonitorDisplayY_);
903     }
904     FI_HILOGI("Start drag, appened extra data");
905     MMI::InputManager::GetInstance()->AppendExtraData(extraData);
906     if (pointerEventMonitorId_ <= 0) {
907         ret = AddDragEventHandler(dragData.sourceType);
908         if (ret != RET_OK) {
909             FI_HILOGE("Failed to add drag event handler");
910             dragDrawing_.DestroyDragWindow();
911             dragDrawing_.UpdateDrawingState();
912             ReportStartDragFailedRadarInfo(StageRes::RES_FAIL, DragRadarErrCode::FAILED_ADD_INPUT_MONITOR, __func__,
913                 packageName);
914             return RET_ERR;
915         }
916     }
917     dragAction_.store(DragAction::MOVE);
918     FI_HILOGI("leave");
919     return RET_OK;
920 }
921 
OnStopDrag(DragResult result,bool hasCustomAnimation,const std::string & packageName,int32_t pid)922 int32_t DragManager::OnStopDrag(DragResult result, bool hasCustomAnimation, const std::string &packageName, int32_t pid)
923 {
924     FI_HILOGI("Add custom animation:%{public}s", hasCustomAnimation ? "true" : "false");
925     DragData dragData = DRAG_DATA_MGR.GetDragData();
926     if ((RemovePointerEventHandler()!= RET_OK) || (RemoveKeyEventMonitor() != RET_OK)) {
927         DragRadarInfo dragRadarInfo;
928         dragRadarInfo.funcName = __func__;
929         dragRadarInfo.bizState = static_cast<int32_t>(BizState::STATE_END);
930         dragRadarInfo.bizStage = static_cast<int32_t>(BizStage::STAGE_STOP_DRAG);
931         dragRadarInfo.stageRes = static_cast<int32_t>(StageRes::RES_FAIL);
932         dragRadarInfo.errCode = static_cast<int32_t>(DragRadarErrCode::FAILED_REMOVE_INPUT_MONITOR);
933         dragRadarInfo.hostName = packageName;
934         dragRadarInfo.callingPid = pid;
935         ReportDragRadarInfo(dragRadarInfo);
936     }
937     dragAction_.store(DragAction::MOVE);
938     FI_HILOGI("Stop drag, appened extra data");
939     MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false));
940     if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
941         dragDrawing_.EraseMouseIcon();
942         if (dragState_ != DragState::MOTION_DRAGGING) {
943             FI_HILOGI("Set the pointer cursor visible");
944             MMI::InputManager::GetInstance()->SetPointerVisible(true);
945         }
946     }
947     pullId_ = -1;
948     return HandleDragResult(result, hasCustomAnimation);
949 }
950 
OnSetDragWindowVisible(bool visible,bool isForce)951 int32_t DragManager::OnSetDragWindowVisible(bool visible, bool isForce)
952 {
953     FI_HILOGI("Set drag window visibleion:%{public}s", visible ? "true" : "false");
954     if (dragState_ == DragState::MOTION_DRAGGING) {
955         FI_HILOGW("Currently in motion dragging");
956         return RET_OK;
957     }
958     if (dragState_ == DragState::STOP) {
959         FI_HILOGW("No drag instance running, can not set drag window visible");
960         ReportDragWindowVisibleRadarInfo(StageRes::RES_FAIL, DragRadarErrCode::FAILED_SET_DRAG_VISIBLE, __func__);
961         return RET_ERR;
962     }
963     if (!isForce && isControlMultiScreenVisible_) {
964         FI_HILOGW("The drag-and-drop window is controlled by multi-screen coordination,"
965             "can not set drag window visible:%{public}d", visible);
966         return RET_OK;
967     }
968     DragDFX::WriteDragWindowVisible(dragState_, visible, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
969     DRAG_DATA_MGR.SetDragWindowVisible(visible);
970     dragDrawing_.UpdateDragWindowState(visible);
971     DragData dragData = DRAG_DATA_MGR.GetDragData();
972     if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE && visible) {
973         FI_HILOGI("Set the pointer cursor invisible");
974         MMI::InputManager::GetInstance()->SetPointerVisible(false);
975     }
976     if (isForce) {
977         isControlMultiScreenVisible_ = isForce;
978         FI_HILOGW("The drag-and-drop window is controlled by multi-screen coordination");
979     }
980     return RET_OK;
981 }
982 
OnGetShadowOffset(ShadowOffset & shadowOffset)983 int32_t DragManager::OnGetShadowOffset(ShadowOffset &shadowOffset)
984 {
985     return DRAG_DATA_MGR.GetShadowOffset(shadowOffset);
986 }
987 
RegisterStateChange(std::function<void (DragState)> callback)988 void DragManager::RegisterStateChange(std::function<void(DragState)> callback)
989 {
990     FI_HILOGI("enter");
991     CHKPV(callback);
992     stateChangedCallback_ = callback;
993     FI_HILOGI("leave");
994 }
995 
UnregisterStateChange()996 void DragManager::UnregisterStateChange()
997 {
998     FI_HILOGI("Unregister state-change callback");
999     stateChangedCallback_ = nullptr;
1000 }
1001 
RegisterNotifyPullUp(std::function<void (bool)> callback)1002 void DragManager::RegisterNotifyPullUp(std::function<void(bool)> callback)
1003 {
1004     FI_HILOGI("enter");
1005     CHKPV(callback);
1006     notifyPUllUpCallback_ = callback;
1007     FI_HILOGI("leave");
1008 }
1009 
UnregisterNotifyPullUp()1010 void DragManager::UnregisterNotifyPullUp()
1011 {
1012     FI_HILOGI("Unregister notify-pullup callback");
1013     notifyPUllUpCallback_ = nullptr;
1014 }
1015 
StateChangedNotify(DragState state)1016 void DragManager::StateChangedNotify(DragState state)
1017 {
1018     FI_HILOGD("enter");
1019     CHKPV(stateChangedCallback_);
1020     if (state == DragState::STOP) {
1021         stateChangedCallback_(state);
1022     } else if (dragState_ != DragState::MOTION_DRAGGING) {
1023         stateChangedCallback_(state);
1024     }
1025     FI_HILOGD("leave");
1026 }
1027 
GetExtraData(bool appended) const1028 MMI::ExtraData DragManager::GetExtraData(bool appended) const
1029 {
1030     return CreateExtraData(appended);
1031 }
1032 
GetDragState() const1033 DragState DragManager::GetDragState() const
1034 {
1035     return dragState_;
1036 }
1037 
GetAllowDragState(bool & isAllowDrag)1038 void DragManager::GetAllowDragState(bool &isAllowDrag)
1039 {
1040     FI_HILOGD("enter");
1041     if (dragState_ != DragState::START) {
1042         FI_HILOGW("Currently state is \'%{public}d\' not in allowed dragState", static_cast<int32_t>(dragState_));
1043         return;
1044     }
1045     isAllowDrag = dragDrawing_.GetAllowDragState();
1046     FI_HILOGD("leave");
1047 }
1048 
SetDragState(DragState state)1049 void DragManager::SetDragState(DragState state)
1050 {
1051     FI_HILOGI("SetDragState:%{public}d to %{public}d", static_cast<int32_t>(dragState_), static_cast<int32_t>(state));
1052     dragState_ = state;
1053     if (state == DragState::START) {
1054         UpdateDragStyleCross();
1055     }
1056 }
1057 
SetDragOriginDpi(float dragOriginDpi)1058 void DragManager::SetDragOriginDpi(float dragOriginDpi)
1059 {
1060     DRAG_DATA_MGR.SetDragOriginDpi(dragOriginDpi);
1061 }
1062 
GetDragResult() const1063 DragResult DragManager::GetDragResult() const
1064 {
1065     return dragResult_;
1066 }
1067 
GetDragSummary(std::map<std::string,int64_t> & summarys)1068 int32_t DragManager::GetDragSummary(std::map<std::string, int64_t> &summarys)
1069 {
1070     DragData dragData = DRAG_DATA_MGR.GetDragData();
1071     summarys = dragData.summarys;
1072     if (summarys.empty()) {
1073         FI_HILOGD("Summarys is empty");
1074     }
1075     return RET_OK;
1076 }
1077 
HandleDragResult(DragResult result,bool hasCustomAnimation)1078 int32_t DragManager::HandleDragResult(DragResult result, bool hasCustomAnimation)
1079 {
1080     FI_HILOGI("enter");
1081     switch (result) {
1082         case DragResult::DRAG_SUCCESS: {
1083             if (!hasCustomAnimation) {
1084                 dragDrawing_.OnDragSuccess(context_);
1085             } else {
1086                 dragDrawing_.DestroyDragWindow();
1087                 dragDrawing_.UpdateDrawingState();
1088             }
1089             break;
1090         }
1091         case DragResult::DRAG_FAIL:
1092         case DragResult::DRAG_CANCEL: {
1093             if (!hasCustomAnimation) {
1094                 dragDrawing_.OnDragFail(context_);
1095             } else {
1096                 dragDrawing_.DestroyDragWindow();
1097                 dragDrawing_.UpdateDrawingState();
1098             }
1099             break;
1100         }
1101         case DragResult::DRAG_EXCEPTION: {
1102             dragDrawing_.DestroyDragWindow();
1103             dragDrawing_.UpdateDrawingState();
1104             break;
1105         }
1106         default: {
1107             FI_HILOGW("Unsupported DragResult type, DragResult:%{public}d", result);
1108             break;
1109         }
1110     }
1111     FI_HILOGI("leave");
1112     return RET_OK;
1113 }
1114 
SetPointerEventFilterTime(int64_t filterTime)1115 void DragManager::SetPointerEventFilterTime(int64_t filterTime)
1116 {
1117     FI_HILOGD("enter");
1118     g_startFilterTime = filterTime;
1119     FI_HILOGD("leave");
1120 }
1121 
MoveTo(int32_t x,int32_t y,bool isMultiSelectedAnimation)1122 void DragManager::MoveTo(int32_t x, int32_t y, bool isMultiSelectedAnimation)
1123 {
1124     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
1125         FI_HILOGE("Drag instance not running");
1126         return;
1127     }
1128     DragData dragData = DRAG_DATA_MGR.GetDragData();
1129     FI_HILOGI("displayId:%{public}d, x:%{private}d, y:%{private}d", dragData.displayId, x, y);
1130     dragDrawing_.Draw(dragData.displayId, x, y, true, isMultiSelectedAnimation);
1131 }
1132 
UpdatePreviewStyle(const PreviewStyle & previewStyle)1133 int32_t DragManager::UpdatePreviewStyle(const PreviewStyle &previewStyle)
1134 {
1135     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
1136         FI_HILOGE("Drag instance not running");
1137         return RET_ERR;
1138     }
1139     if (previewStyle == DRAG_DATA_MGR.GetPreviewStyle()) {
1140         FI_HILOGD("Not need to update previewStyle");
1141         return RET_OK;
1142     }
1143     DRAG_DATA_MGR.SetPreviewStyle(previewStyle);
1144     FI_HILOGI("Update previewStyle successfully");
1145     return dragDrawing_.UpdatePreviewStyle(previewStyle);
1146 }
1147 
UpdatePreviewStyleWithAnimation(const PreviewStyle & previewStyle,const PreviewAnimation & animation)1148 int32_t DragManager::UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle,
1149     const PreviewAnimation &animation)
1150 {
1151     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
1152         FI_HILOGE("Drag instance not running");
1153         return RET_ERR;
1154     }
1155     if (previewStyle == DRAG_DATA_MGR.GetPreviewStyle()) {
1156         FI_HILOGD("Not need to update previewStyle");
1157         return RET_OK;
1158     }
1159     DRAG_DATA_MGR.SetPreviewStyle(previewStyle);
1160     FI_HILOGI("Update previewStyle successfully");
1161     return dragDrawing_.UpdatePreviewStyleWithAnimation(previewStyle, animation);
1162 }
1163 
RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)1164 int32_t DragManager::RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)
1165 {
1166     return dragDrawing_.RotateDragWindowSync(rsTransaction);
1167 }
1168 
SetDragWindowScreenId(uint64_t displayId,uint64_t screenId)1169 void DragManager::SetDragWindowScreenId(uint64_t displayId, uint64_t screenId)
1170 {
1171     FI_HILOGI("displayId:%{public}" PRId64 ", screenId:%{public}" PRId64 "", displayId, screenId);
1172     displayId_ = displayId;
1173     screenId_ = screenId;
1174 }
1175 
DragKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent)1176 void DragManager::DragKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent)
1177 {
1178     CHKPV(keyEvent);
1179     auto keyItems = keyEvent->GetKeyItems();
1180     auto iter = std::find_if(keyItems.begin(), keyItems.end(),
1181         [] (std::optional<MMI::KeyEvent::KeyItem> keyItem) {
1182             return ((keyItem->GetKeyCode() == MMI::KeyEvent::KEYCODE_CTRL_LEFT) ||
1183                     (keyItem->GetKeyCode() == MMI::KeyEvent::KEYCODE_CTRL_RIGHT));
1184         });
1185     if (iter == keyItems.end()) {
1186         dragAction_.store(DragAction::MOVE);
1187         return;
1188     }
1189     if ((DRAG_DATA_MGR.GetDragStyle() == DragCursorStyle::DEFAULT) ||
1190         (DRAG_DATA_MGR.GetDragStyle() == DragCursorStyle::FORBIDDEN)) {
1191         dragAction_.store(DragAction::MOVE);
1192         return;
1193     }
1194     if (!iter->IsPressed()) {
1195         CtrlKeyStyleChangedNotify(DRAG_DATA_MGR.GetDragStyle(), DragAction::MOVE);
1196         HandleCtrlKeyEvent(DRAG_DATA_MGR.GetDragStyle(), DragAction::MOVE);
1197         dragAction_.store(DragAction::MOVE);
1198         return;
1199     }
1200     if (DRAG_DATA_MGR.GetDragStyle() == DragCursorStyle::COPY) {
1201         FI_HILOGD("Not need update drag style");
1202         return;
1203     }
1204     CtrlKeyStyleChangedNotify(DragCursorStyle::COPY, DragAction::COPY);
1205     HandleCtrlKeyEvent(DragCursorStyle::COPY, DragAction::COPY);
1206     dragAction_.store(DragAction::COPY);
1207 }
1208 
HandleCtrlKeyEvent(DragCursorStyle style,DragAction action)1209 void DragManager::HandleCtrlKeyEvent(DragCursorStyle style, DragAction action)
1210 {
1211     FI_HILOGD("enter");
1212     if (action == dragAction_.load()) {
1213         FI_HILOGD("Not need update drag style");
1214         return;
1215     }
1216     CHKPV(context_);
1217     int32_t ret = context_->GetDelegateTasks().PostAsyncTask([this, style] {
1218         return this->dragDrawing_.UpdateDragStyle(style);
1219     });
1220     if (ret != RET_OK) {
1221         FI_HILOGE("Post async task failed");
1222     }
1223     FI_HILOGD("leave");
1224 }
1225 
OnUpdateDragStyle(DragCursorStyle style)1226 int32_t DragManager::OnUpdateDragStyle(DragCursorStyle style)
1227 {
1228     FI_HILOGD("enter");
1229     DragCursorStyle updateStyle = GetRealDragStyle(style);
1230     stateNotify_.StyleChangedNotify(updateStyle);
1231     if (dragDrawing_.UpdateDragStyle(updateStyle) != RET_OK) {
1232         DragDFX::WriteUpdateDragStyle(updateStyle, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
1233         return RET_ERR;
1234     }
1235     FI_HILOGD("Update dragStyle:%{public}s successfully", GetDragStyleName(updateStyle).c_str());
1236     return RET_OK;
1237 }
1238 
UpdateDragStyleCross()1239 void DragManager::UpdateDragStyleCross()
1240 {
1241     FI_HILOGD("enter");
1242     auto dragStyle = DRAG_DATA_MGR.GetDragStyle();
1243     FI_HILOGI("OnUpdateDragStyle dragStyle:%{public}s", GetDragStyleName(dragStyle).c_str());
1244     if (OnUpdateDragStyle(DRAG_DATA_MGR.GetDragStyle()) != RET_OK) {
1245         FI_HILOGE("OnUpdateDragStyle failed");
1246     }
1247     FI_HILOGD("leave");
1248 }
1249 
GetDragStyleName(DragCursorStyle style)1250 std::string DragManager::GetDragStyleName(DragCursorStyle style)
1251 {
1252     switch (style) {
1253         case DragCursorStyle::DEFAULT : {
1254             return DRAG_STYLE_DEFAULT;
1255         }
1256         case DragCursorStyle::FORBIDDEN : {
1257             return DRAG_STYLE_FORBIDDEN;
1258         }
1259         case DragCursorStyle::COPY : {
1260             return DRAG_STYLE_COPY;
1261         }
1262         case DragCursorStyle::MOVE : {
1263             return DRAG_STYLE_MOVE;
1264         }
1265         default:
1266             break;
1267     }
1268     return DRAG_STYLE_UNKNOW;
1269 }
1270 
GetRealDragStyle(DragCursorStyle style)1271 DragCursorStyle DragManager::GetRealDragStyle(DragCursorStyle style)
1272 {
1273     if ((dragAction_ == DragAction::COPY) && (style == DragCursorStyle::MOVE)) {
1274         return DragCursorStyle::COPY;
1275     }
1276     return style;
1277 }
1278 
GetDragBehavior(const DragDropResult & dropResult,DragBehavior & dragBehavior)1279 void DragManager::GetDragBehavior(const DragDropResult &dropResult, DragBehavior &dragBehavior)
1280 {
1281     FI_HILOGD("enter");
1282     if (dropResult.result != DragResult::DRAG_SUCCESS) {
1283         dragBehavior = DragBehavior::UNKNOWN;
1284         return;
1285     }
1286     if (dragBehavior == DragBehavior::UNKNOWN) {
1287         if (DRAG_DATA_MGR.GetDragStyle() == DragCursorStyle::COPY) {
1288             dragBehavior = DragBehavior::COPY;
1289             return;
1290         }
1291         if (dragAction_.load()== DragAction::COPY) {
1292             dragBehavior = DragBehavior::COPY;
1293             return;
1294         }
1295         DragData dragData = DRAG_DATA_MGR.GetDragData();
1296         if (dropResult.mainWindow == dragData.mainWindow) {
1297             dragBehavior = DragBehavior::MOVE;
1298         } else {
1299             dragBehavior = DragBehavior::COPY;
1300         }
1301     }
1302     FI_HILOGD("leave");
1303 }
1304 
CtrlKeyStyleChangedNotify(DragCursorStyle style,DragAction action)1305 void DragManager::CtrlKeyStyleChangedNotify(DragCursorStyle style, DragAction action)
1306 {
1307     FI_HILOGD("enter");
1308     if (action == dragAction_.load()) {
1309         FI_HILOGD("Has notified");
1310         return;
1311     }
1312     CHKPV(context_);
1313     int32_t ret = context_->GetDelegateTasks().PostAsyncTask([this, style] {
1314         return this->stateNotify_.StyleChangedNotify(style);
1315     });
1316     if (ret != RET_OK) {
1317         FI_HILOGE("Post async task failed");
1318     }
1319     FI_HILOGD("leave");
1320 }
1321 
GetDragAction(DragAction & dragAction) const1322 int32_t DragManager::GetDragAction(DragAction &dragAction) const
1323 {
1324     FI_HILOGD("enter");
1325     if (dragState_ != DragState::START) {
1326         FI_HILOGE("No drag instance running, can not get drag action");
1327         return RET_ERR;
1328     }
1329     dragAction = dragAction_.load();
1330     FI_HILOGD("leave");
1331     return RET_OK;
1332 }
1333 
EnterTextEditorArea(bool enable)1334 int32_t DragManager::EnterTextEditorArea(bool enable)
1335 {
1336     FI_HILOGD("enter");
1337     if (dragState_ != DragState::START) {
1338         FI_HILOGE("No drag instance running");
1339         return RET_ERR;
1340     }
1341     if (DRAG_DATA_MGR.GetTextEditorAreaFlag() == enable) {
1342         FI_HILOGE("Set textEditorArea:%{public}s already", (enable ? "true" : "false"));
1343         return RET_ERR;
1344     }
1345     if (DRAG_DATA_MGR.GetCoordinateCorrected()) {
1346         FI_HILOGE("GetCoordinateCorrected failed");
1347         return RET_ERR;
1348     }
1349     FI_HILOGD("leave");
1350     return dragDrawing_.EnterTextEditorArea(enable);
1351 }
1352 
GetExtraInfo(std::string & extraInfo) const1353 int32_t DragManager::GetExtraInfo(std::string &extraInfo) const
1354 {
1355     FI_HILOGD("enter");
1356     DragData dragData = DRAG_DATA_MGR.GetDragData();
1357     if (dragData.extraInfo.empty()) {
1358         FI_HILOGE("The extraInfo is empty");
1359         return RET_ERR;
1360     }
1361     extraInfo = dragData.extraInfo;
1362     FI_HILOGD("leave");
1363     return RET_OK;
1364 }
1365 
AddPrivilege(int32_t tokenId)1366 int32_t DragManager::AddPrivilege(int32_t tokenId)
1367 {
1368     FI_HILOGD("enter");
1369     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
1370         FI_HILOGE("Drag instance not running");
1371         return RET_ERR;
1372     }
1373     DragData dragData = DRAG_DATA_MGR.GetDragData();
1374     FI_HILOGD("Target window drag tid:%{public}d", tokenId);
1375     SendDragData(tokenId, dragData.udKey);
1376     FI_HILOGD("leave");
1377     return RET_OK;
1378 }
1379 
EraseMouseIcon()1380 int32_t DragManager::EraseMouseIcon()
1381 {
1382     FI_HILOGD("enter");
1383     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
1384         FI_HILOGE("Drag instance not running");
1385         return RET_ERR;
1386     }
1387     dragDrawing_.EraseMouseIcon();
1388     FI_HILOGD("leave");
1389     return RET_OK;
1390 }
1391 
RotateDragWindow(Rosen::Rotation rotation)1392 int32_t DragManager::RotateDragWindow(Rosen::Rotation rotation)
1393 {
1394     FI_HILOGD("enter, rotation:%{public}d", static_cast<int32_t>(rotation));
1395     auto SetDragWindowRotate = [rotation, this]() {
1396         dragDrawing_.SetRotation(rotation);
1397         if ((dragState_ == DragState::START) || (dragState_ == DragState::MOTION_DRAGGING)) {
1398             dragDrawing_.RotateDragWindowAsync(rotation);
1399         }
1400         return RET_OK;
1401     };
1402     CHKPR(context_, RET_ERR);
1403     int32_t ret = context_->GetDelegateTasks().PostAsyncTask(SetDragWindowRotate);
1404     if (ret != RET_OK) {
1405         FI_HILOGE("Post async task failed, ret:%{public}d", ret);
1406         return ret;
1407     }
1408     FI_HILOGD("leave");
1409     return RET_OK;
1410 }
1411 
SetAllowStartDrag(bool hasUpEvent)1412 void DragManager::SetAllowStartDrag(bool hasUpEvent)
1413 {
1414     hasUpEvent_ = hasUpEvent;
1415 }
1416 
IsAllowStartDrag() const1417 bool DragManager::IsAllowStartDrag() const
1418 {
1419     return hasUpEvent_;
1420 }
1421 
SetCooperatePriv(uint32_t priv)1422 void DragManager::SetCooperatePriv(uint32_t priv)
1423 {
1424     priv_ = priv;
1425 }
1426 
GetCooperatePriv() const1427 uint32_t DragManager::GetCooperatePriv() const
1428 {
1429     return priv_;
1430 }
1431 
ResetMouseDragMonitorInfo()1432 void DragManager::ResetMouseDragMonitorInfo()
1433 {
1434     FI_HILOGI("enter");
1435     RemoveDragEventHandler();
1436     mouseDragMonitorDisplayX_ = -1;
1437     mouseDragMonitorDisplayY_ = -1;
1438     existMouseMoveDragCallback_ = false;
1439     mouseDragMonitorState_ = false;
1440     FI_HILOGI("leave");
1441 }
1442 
SetMouseDragMonitorState(bool state)1443 int32_t DragManager::SetMouseDragMonitorState(bool state)
1444 {
1445     if (state) {
1446         if (AddDragEventHandler(MMI::PointerEvent::SOURCE_TYPE_MOUSE) != RET_OK) {
1447             FI_HILOGE("Failed to add drag event handler");
1448             return RET_ERR;
1449         }
1450         if (context_ != nullptr) {
1451             int32_t repeatCount = 1;
1452             mouseDragMonitorTimerId_ = context_->GetTimerManager().AddTimer(TIMEOUT_MS,
1453                 repeatCount, [this]() {
1454                 FI_HILOGW("Timeout, automatically remove monitor");
1455                 this->ResetMouseDragMonitorInfo();
1456             });
1457         }
1458     } else {
1459         ResetMouseDragMonitorInfo();
1460     }
1461     mouseDragMonitorState_ = state;
1462     return RET_OK;
1463 }
1464 
ReportDragWindowVisibleRadarInfo(StageRes stageRes,DragRadarErrCode errCode,const std::string & funcName)1465 void DragManager::ReportDragWindowVisibleRadarInfo(StageRes stageRes, DragRadarErrCode errCode,
1466     const std::string &funcName)
1467 {
1468     HiSysEventWrite(
1469         OHOS::HiviewDFX::HiSysEvent::Domain::MSDP,
1470         DRAG_BEHAVIOR,
1471         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
1472         "ORG_PKG", ORG_PKG_NAME,
1473         "FUNC", funcName,
1474         "BIZ_SCENE", 1,
1475         "BIZ_STATE", static_cast<int32_t>(BizState::STATE_IDLE),
1476         "BIZ_STAGE", static_cast<int32_t>(BizStage::STAGE_DRAGGING),
1477         "STAGE_RES", static_cast<int32_t>(stageRes),
1478         "ERROR_CODE", static_cast<int32_t>(errCode),
1479         "HOST_PKG", "",
1480         "LOCAL_NET_ID", "",
1481         "PEER_NET_ID", "",
1482         "DRAG_SUMMARY", "");
1483 }
1484 
ReportStopDragRadarInfo(BizState bizState,StageRes stageRes,DragRadarErrCode errCode,int32_t pid,const std::string & packageName)1485 void DragManager::ReportStopDragRadarInfo(BizState bizState, StageRes stageRes, DragRadarErrCode errCode, int32_t pid,
1486     const std::string &packageName)
1487 {
1488     DragRadarInfo dragRadarInfo;
1489     dragRadarInfo.funcName = "StopDrag";
1490     dragRadarInfo.bizState = static_cast<int32_t>(bizState);
1491     dragRadarInfo.bizStage = static_cast<int32_t>(BizStage::STAGE_STOP_DRAG);
1492     dragRadarInfo.stageRes = static_cast<int32_t>(stageRes);
1493     dragRadarInfo.errCode = static_cast<int32_t>(errCode);
1494     dragRadarInfo.hostName = packageName;
1495     dragRadarInfo.callingPid = std::to_string(pid);
1496     ReportDragRadarInfo(dragRadarInfo);
1497 }
1498 
ReportStartDragRadarInfo(BizState bizState,StageRes stageRes,DragRadarErrCode errCode,const std::string & packageName)1499 void DragManager::ReportStartDragRadarInfo(BizState bizState, StageRes stageRes, DragRadarErrCode errCode,
1500     const std::string &packageName)
1501 {
1502     DragRadarInfo dragRadarInfo;
1503     dragRadarInfo.funcName = "StartDrag";
1504     dragRadarInfo.bizState = static_cast<int32_t>(bizState);
1505     dragRadarInfo.bizStage = static_cast<int32_t>(BizStage::STAGE_START_DRAG);
1506     dragRadarInfo.stageRes = static_cast<int32_t>(stageRes);
1507     dragRadarInfo.errCode = static_cast<int32_t>(errCode);
1508     dragRadarInfo.hostName = packageName;
1509     ReportDragRadarInfo(dragRadarInfo);
1510 }
1511 
ReportStartDragFailedRadarInfo(StageRes stageRes,DragRadarErrCode errCode,const std::string & funcName,const std::string & packageName)1512 void DragManager::ReportStartDragFailedRadarInfo(StageRes stageRes, DragRadarErrCode errCode,
1513     const std::string &funcName, const std::string &packageName)
1514 {
1515     DragRadarInfo dragRadarInfo;
1516     dragRadarInfo.funcName = funcName;
1517     dragRadarInfo.bizState = static_cast<int32_t>(BizState::STATE_END);
1518     dragRadarInfo.bizStage = static_cast<int32_t>(BizStage::STAGE_START_DRAG);
1519     dragRadarInfo.stageRes = static_cast<int32_t>(stageRes);
1520     dragRadarInfo.errCode = static_cast<int32_t>(errCode);
1521     dragRadarInfo.hostName = packageName;
1522     ReportDragRadarInfo(dragRadarInfo);
1523 }
1524 
ReportDragRadarInfo(struct DragRadarInfo & dragRadarInfo)1525 void DragManager::ReportDragRadarInfo(struct DragRadarInfo &dragRadarInfo)
1526 {
1527     DragData dragData = DRAG_DATA_MGR.GetDragData();
1528     std::string summary;
1529     for (const auto &[udKey, recordSize] : dragData.summarys) {
1530         std::string str = udKey + "-" + std::to_string(recordSize) + ";";
1531         summary += str;
1532     }
1533     HiSysEventWrite(
1534         OHOS::HiviewDFX::HiSysEvent::Domain::MSDP,
1535         DRAG_BEHAVIOR,
1536         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
1537         "ORG_PKG", ORG_PKG_NAME,
1538         "FUNC", dragRadarInfo.funcName,
1539         "BIZ_SCENE", 1,
1540         "BIZ_STATE", dragRadarInfo.bizState,
1541         "BIZ_STAGE", dragRadarInfo.bizStage,
1542         "STAGE_RES", dragRadarInfo.stageRes,
1543         "ERROR_CODE", dragRadarInfo.errCode,
1544         "HOST_PKG", dragRadarInfo.hostName,
1545         "LOCAL_NET_ID", dragRadarInfo.localNetId,
1546         "PEER_NET_ID", dragRadarInfo.peerNetId,
1547         "DRAG_SUMMARY", summary,
1548         "APP_CALLER", dragRadarInfo.callingPid);
1549 }
1550 
ScreenRotate(Rosen::Rotation rotation,Rosen::Rotation lastRotation)1551 int32_t DragManager::ScreenRotate(Rosen::Rotation rotation, Rosen::Rotation lastRotation)
1552 {
1553     FI_HILOGD("enter");
1554     DragData dragData = DRAG_DATA_MGR.GetDragData();
1555     if (dragData.sourceType != MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
1556         FI_HILOGD("Not need screen rotate");
1557         return RET_OK;
1558     }
1559     auto SetDragWindowRotate = [rotation, lastRotation, this]() {
1560         if ((dragState_ == DragState::START) || (dragState_ == DragState::MOTION_DRAGGING)) {
1561             dragDrawing_.ScreenRotate(rotation, lastRotation);
1562         }
1563         return RET_OK;
1564     };
1565     CHKPR(context_, RET_ERR);
1566     int32_t ret = context_->GetDelegateTasks().PostAsyncTask(SetDragWindowRotate);
1567     if (ret != RET_OK) {
1568         FI_HILOGE("Post async task failed, ret:%{public}d", ret);
1569         return ret;
1570     }
1571     FI_HILOGD("leave");
1572     return RET_OK;
1573 }
1574 } // namespace DeviceStatus
1575 } // namespace Msdp
1576 } // namespace OHOS
1577