• 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.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 namespace OHOS {
36 namespace Msdp {
37 namespace DeviceStatus {
38 namespace {
39 constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "DragManager" };
40 constexpr int32_t TIMEOUT_MS { 2000 };
41 constexpr int32_t INTERVAL_MS { 500 };
42 constexpr uint64_t FOLD_SCREEN_ID { 5 };
43 std::atomic<int64_t> g_startFilterTime { -1 };
44 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
45 constexpr int32_t DRAG_PRIORITY { 500 };
46 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
47 } // namespace
48 
~DragManager()49 DragManager::~DragManager()
50 {
51     EventHub::UnRegisterEvent(eventHub_);
52 }
53 
Init(IContext * context)54 int32_t DragManager::Init(IContext* context)
55 {
56     CALL_INFO_TRACE;
57     CHKPR(context, RET_ERR);
58     context_ = context;
59     int32_t repeatCount = 1;
60     context_->GetTimerManager().AddTimer(INTERVAL_MS, repeatCount, [this]() {
61         if (eventHub_ == nullptr) {
62             eventHub_ = EventHub::GetEventHub(context_);
63         }
64         auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
65         if (samgrProxy == nullptr) {
66             FI_HILOGE("samgrProxy is nullptr");
67             return;
68         }
69         statusListener_ = new (std::nothrow) DragAbilityStatusChange(eventHub_);
70         if (statusListener_ == nullptr) {
71             FI_HILOGE("statusListener_ is nullptr");
72             return;
73         }
74         int32_t ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusListener_);
75         FI_HILOGI("SubscribeSystemAbility COMMON_EVENT_SERVICE_ID result:%{public}d", ret);
76         displayAbilityStatusChange_ = new (std::nothrow) DisplayAbilityStatusChange(context_);
77         if (displayAbilityStatusChange_ == nullptr) {
78             FI_HILOGE("displayAbilityStatusChange is nullptr");
79             return;
80         }
81         ret = samgrProxy->SubscribeSystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, displayAbilityStatusChange_);
82         FI_HILOGI("SubscribeSystemAbility DISPLAY_MANAGER_SERVICE_SA_ID result:%{public}d", ret);
83     });
84     return RET_OK;
85 }
86 
OnSessionLost(SessionPtr session)87 void DragManager::OnSessionLost(SessionPtr session)
88 {
89     CALL_INFO_TRACE;
90     if (RemoveListener(session) != RET_OK) {
91         FI_HILOGE("Failed to clear client listener");
92     }
93 }
94 
AddListener(SessionPtr session)95 int32_t DragManager::AddListener(SessionPtr session)
96 {
97     CALL_INFO_TRACE;
98     CHKPR(session, RET_ERR);
99     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
100     info->session = session;
101     info->msgId = MessageId::DRAG_STATE_LISTENER;
102     info->msgType = MessageType::NOTIFY_STATE;
103     stateNotify_.AddNotifyMsg(info);
104     return RET_OK;
105 }
106 
RemoveListener(SessionPtr session)107 int32_t DragManager::RemoveListener(SessionPtr session)
108 {
109     CALL_INFO_TRACE;
110     CHKPR(session, RET_ERR);
111     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
112     info->session = session;
113     info->msgType = MessageType::NOTIFY_STATE;
114     stateNotify_.RemoveNotifyMsg(info);
115     return RET_OK;
116 }
117 
AddSubscriptListener(SessionPtr session)118 int32_t DragManager::AddSubscriptListener(SessionPtr session)
119 {
120     CALL_INFO_TRACE;
121     CHKPR(session, RET_ERR);
122     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
123     info->session = session;
124     info->msgId = MessageId::DRAG_STYLE_LISTENER;
125     info->msgType = MessageType::NOTIFY_STYLE;
126     stateNotify_.AddNotifyMsg(info);
127     return RET_OK;
128 }
129 
RemoveSubscriptListener(SessionPtr session)130 int32_t DragManager::RemoveSubscriptListener(SessionPtr session)
131 {
132     CALL_INFO_TRACE;
133     CHKPR(session, RET_ERR);
134     auto info = std::make_shared<StateChangeNotify::MessageInfo>();
135     info->msgType = MessageType::NOTIFY_STYLE;
136     info->session = session;
137     stateNotify_.RemoveNotifyMsg(info);
138 
139     return RET_OK;
140 }
141 
PrintDragData(const DragData & dragData)142 void DragManager::PrintDragData(const DragData &dragData)
143 {
144     CALL_INFO_TRACE;
145     for (const auto& shadowInfo : dragData.shadowInfos) {
146         CHKPV(shadowInfo.pixelMap);
147         FI_HILOGI("PixelFormat:%{public}d, PixelAlphaType:%{public}d, PixelAllocatorType:%{public}d,"
148             " PixelWidth:%{public}d, PixelHeight:%{public}d, shadowX:%{public}d, shadowY:%{public}d",
149             static_cast<int32_t>(shadowInfo.pixelMap->GetPixelFormat()),
150             static_cast<int32_t>(shadowInfo.pixelMap->GetAlphaType()),
151             static_cast<int32_t>(shadowInfo.pixelMap->GetAllocatorType()),
152             shadowInfo.pixelMap->GetWidth(), shadowInfo.pixelMap->GetHeight(), shadowInfo.x, shadowInfo.y);
153     }
154     std::string summarys;
155     for (const auto &[udKey, recordSize] : dragData.summarys) {
156         std::string str = udKey + "-" + std::to_string(recordSize) + ";";
157         summarys += str;
158     }
159     FI_HILOGI("SourceType:%{public}d, pointerId:%{public}d, displayId:%{public}d,"
160         " displayX:%{public}d, displayY:%{public}d, dragNum:%{public}d,"
161         " hasCanceledAnimation:%{public}d, udKey:%{public}s, hasCoordinateCorrected:%{public}d, summarys:%{public}s",
162         dragData.sourceType, dragData.pointerId, dragData.displayId, dragData.displayX,
163         dragData.displayY, dragData.dragNum, dragData.hasCanceledAnimation,
164         GetAnonyString(dragData.udKey).c_str(), dragData.hasCoordinateCorrected, summarys.c_str());
165 }
166 
StartDrag(const DragData & dragData,SessionPtr sess)167 int32_t DragManager::StartDrag(const DragData &dragData, SessionPtr sess)
168 {
169     CALL_INFO_TRACE;
170     PrintDragData(dragData);
171     if (dragState_ == DragState::START) {
172         FI_HILOGE("Drag instance already exists, no need to start drag again");
173         return RET_ERR;
174     }
175     dragOutSession_ = sess;
176     if (InitDataManager(dragData) != RET_OK) {
177         FI_HILOGE("Failed to init data manager");
178         return RET_ERR;
179     }
180     if (OnStartDrag() != RET_OK) {
181         DragDFX::WriteStartDrag(dragState_, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
182         FI_HILOGE("Failed to execute OnStartDrag");
183         return RET_ERR;
184     }
185 #ifdef OHOS_BUILD_ENABLE_MOTION_DRAG
186     CHKPR(notifyPUllUpCallback_, RET_ERR);
187     notifyPUllUpCallback_(false);
188 #endif
189     SetDragState(DragState::START);
190     stateNotify_.StateChangedNotify(DragState::START);
191     StateChangedNotify(DragState::START);
192     return RET_OK;
193 }
194 
StopDrag(const DragDropResult & dropResult)195 int32_t DragManager::StopDrag(const DragDropResult &dropResult)
196 {
197     CALL_INFO_TRACE;
198     FI_HILOGI("windowId:%{public}d", dropResult.windowId);
199     if (dragState_ == DragState::STOP) {
200         FI_HILOGE("No drag instance running, can not stop drag");
201         return RET_ERR;
202     }
203     if ((dropResult.result != DragResult::DRAG_EXCEPTION) && (context_ != nullptr) && (timerId_ >= 0)) {
204         context_->GetTimerManager().RemoveTimer(timerId_);
205         timerId_ = -1;
206     }
207     int32_t ret = RET_OK;
208     if (OnStopDrag(dropResult.result, dropResult.hasCustomAnimation) != RET_OK) {
209         DragDFX::WriteStopDrag(dragState_, dropResult, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
210         FI_HILOGE("On stop drag failed");
211         ret = RET_ERR;
212     }
213     SetDragState(DragState::STOP);
214     if (dropResult.result == DragResult::DRAG_SUCCESS && dropResult.windowId > 0) {
215         Rosen::WMError result = Rosen::WindowManager::GetInstance().RaiseWindowToTop(dropResult.windowId);
216         if (result != Rosen::WMError::WM_OK) {
217             FI_HILOGE("Raise window to top failed, windowId:%{public}d", dropResult.windowId);
218         }
219     }
220     stateNotify_.StateChangedNotify(DragState::STOP);
221     if (NotifyDragResult(dropResult.result) != RET_OK) {
222         FI_HILOGE("Notify drag result failed");
223     }
224     DRAG_DATA_MGR.ResetDragData();
225     dragResult_ = static_cast<DragResult>(dropResult.result);
226     StateChangedNotify(DragState::STOP);
227     if (isControlMultiScreenVisible_) {
228         isControlMultiScreenVisible_ = false;
229     }
230     return ret;
231 }
232 
GetDragTargetPid() const233 int32_t DragManager::GetDragTargetPid() const
234 {
235     CALL_INFO_TRACE;
236     return DRAG_DATA_MGR.GetTargetPid();
237 }
238 
GetUdKey(std::string & udKey) const239 int32_t DragManager::GetUdKey(std::string &udKey) const
240 {
241     CALL_INFO_TRACE;
242     DragData dragData = DRAG_DATA_MGR.GetDragData();
243     if (dragData.udKey.empty()) {
244         FI_HILOGE("Target udKey is empty");
245         return RET_ERR;
246     }
247     udKey = dragData.udKey;
248     return RET_OK;
249 }
250 
UpdateDragStyle(DragCursorStyle style,int32_t targetPid,int32_t targetTid)251 int32_t DragManager::UpdateDragStyle(DragCursorStyle style, int32_t targetPid, int32_t targetTid)
252 {
253     FI_HILOGD("DragStyle from ark is dragStyle%{public}s", GetDragStyleName(style).c_str());
254     auto lastTargetPid = DRAG_DATA_MGR.GetTargetPid();
255     DRAG_DATA_MGR.SetTargetPid(targetPid);
256     DRAG_DATA_MGR.SetTargetTid(targetTid);
257     if (style == DRAG_DATA_MGR.GetDragStyle()) {
258         FI_HILOGD("Not need update drag style");
259         if (targetPid != lastTargetPid) {
260             stateNotify_.StyleChangedNotify(GetRealDragStyle(style));
261         }
262         return RET_OK;
263     }
264     DRAG_DATA_MGR.SetDragStyle(style);
265     if (dragState_ != DragState::START) {
266         FI_HILOGE("No drag instance running, can not update drag style");
267         return RET_ERR;
268     }
269     if ((style < DragCursorStyle::DEFAULT) || (style > DragCursorStyle::MOVE)) {
270         DragDFX::WriteUpdateDragStyle(style, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
271         FI_HILOGE("Invalid style:%{public}d", style);
272         return RET_ERR;
273     }
274     if (OnUpdateDragStyle(style) != RET_OK) {
275         FI_HILOGE("OnUpdateDragStyle dragStyle%{public}s failed", GetDragStyleName(style).c_str());
276         return RET_ERR;
277     }
278     return RET_OK;
279 }
280 
UpdateShadowPic(const ShadowInfo & shadowInfo)281 int32_t DragManager::UpdateShadowPic(const ShadowInfo &shadowInfo)
282 {
283     CALL_INFO_TRACE;
284     if (dragState_ != DragState::START) {
285         FI_HILOGE("No drag instance running, can not update shadow picture");
286         return RET_ERR;
287     }
288     DRAG_DATA_MGR.SetShadowInfos({ shadowInfo });
289     return dragDrawing_.UpdateShadowPic(shadowInfo);
290 }
291 
GetDragData(DragData & dragData)292 int32_t DragManager::GetDragData(DragData &dragData)
293 {
294     CALL_INFO_TRACE;
295     if (dragState_ != DragState::START) {
296         FI_HILOGE("No drag instance running, can not get dragData");
297         return RET_ERR;
298     }
299     dragData = DRAG_DATA_MGR.GetDragData();
300     return RET_OK;
301 }
302 
GetDragState(DragState & dragState)303 int32_t DragManager::GetDragState(DragState &dragState)
304 {
305     CALL_DEBUG_ENTER;
306     dragState = GetDragState();
307     if (dragState == DragState::ERROR) {
308         FI_HILOGE("dragState_ is error");
309         return RET_ERR;
310     }
311     return RET_OK;
312 }
313 
NotifyDragResult(DragResult result)314 int32_t DragManager::NotifyDragResult(DragResult result)
315 {
316     CALL_INFO_TRACE;
317     DragData dragData = DRAG_DATA_MGR.GetDragData();
318     int32_t targetPid = GetDragTargetPid();
319     NetPacket pkt(MessageId::DRAG_NOTIFY_RESULT);
320     if ((result < DragResult::DRAG_SUCCESS) || (result > DragResult::DRAG_EXCEPTION)) {
321         DragDFX::WriteNotifyDragResult(result, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
322         FI_HILOGE("The invalid result:%{public}d", static_cast<int32_t>(result));
323         return RET_ERR;
324     }
325     pkt << dragData.displayX << dragData.displayY << static_cast<int32_t>(result) << targetPid;
326     if (pkt.ChkRWError()) {
327         FI_HILOGE("Failed to packet write data");
328         return RET_ERR;
329     }
330     CHKPR(dragOutSession_, RET_ERR);
331     if (!dragOutSession_->SendMsg(pkt)) {
332         FI_HILOGE("Failed to send message");
333         return MSG_SEND_FAIL;
334     }
335     DragDFX::WriteNotifyDragResult(result, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
336     return RET_OK;
337 }
338 
NotifyHideIcon()339 int32_t DragManager::NotifyHideIcon()
340 {
341     CALL_DEBUG_ENTER;
342     NetPacket pkt(MessageId::DRAG_NOTIFY_HIDE_ICON);
343     if (pkt.ChkRWError()) {
344         FI_HILOGE("Packet write data failed");
345         return RET_ERR;
346     }
347     CHKPR(dragOutSession_, RET_ERR);
348     if (!dragOutSession_->SendMsg(pkt)) {
349         FI_HILOGE("Send message failed");
350         return MSG_SEND_FAIL;
351     }
352     return RET_OK;
353 }
354 
DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent)355 void DragManager::DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent)
356 {
357     CHKPV(pointerEvent);
358     int32_t pointerAction = pointerEvent->GetPointerAction();
359     if (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_MOVE) {
360         OnDragMove(pointerEvent);
361         return;
362     }
363     if (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_UP) {
364         OnDragUp(pointerEvent);
365         return;
366     }
367     FI_HILOGW("Unknow action, sourceType:%{public}d, pointerId:%{public}d, pointerAction:%{public}d",
368         pointerEvent->GetSourceType(), pointerEvent->GetPointerId(), pointerAction);
369 }
370 
OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent)371 void DragManager::OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent)
372 {
373     CHKPV(pointerEvent);
374     MMI::PointerEvent::PointerItem pointerItem;
375     pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem);
376     FI_HILOGD("SourceType:%{public}d, pointerId:%{public}d, displayX:%{public}d, displayY:%{public}d",
377         pointerEvent->GetSourceType(), pointerEvent->GetPointerId(),
378         pointerItem.GetDisplayX(), pointerItem.GetDisplayY());
379     dragDrawing_.Draw(pointerEvent->GetTargetDisplayId(), pointerItem.GetDisplayX(), pointerItem.GetDisplayY());
380 }
381 
SendDragData(int32_t targetTid,const std::string & udKey)382 void DragManager::SendDragData(int32_t targetTid, const std::string &udKey)
383 {
384     CALL_INFO_TRACE;
385     UDMF::QueryOption option;
386     option.key = udKey;
387     UDMF::Privilege privilege;
388     privilege.tokenId = static_cast<uint32_t>(targetTid);
389     int32_t ret = UDMF::UdmfClient::GetInstance().AddPrivilege(option, privilege);
390     if (ret != RET_OK) {
391         FI_HILOGE("Failed to send pid to Udmf client");
392     }
393 }
394 
OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent)395 void DragManager::OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent)
396 {
397     CALL_INFO_TRACE;
398     CHKPV(pointerEvent);
399     DragData dragData = DRAG_DATA_MGR.GetDragData();
400     if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
401         dragDrawing_.EraseMouseIcon();
402         FI_HILOGI("Set the pointer cursor visible");
403         MMI::InputManager::GetInstance()->SetPointerVisible(true);
404     }
405     CHKPV(context_);
406     int32_t repeatCount = 1;
407     timerId_ = context_->GetTimerManager().AddTimer(TIMEOUT_MS, repeatCount, [this]() {
408         DragDropResult dropResult { DragResult::DRAG_EXCEPTION, false, -1 };
409         FI_HILOGW("Timeout, automatically stop dragging");
410         this->StopDrag(dropResult);
411     });
412     CHKPV(notifyPUllUpCallback_);
413     notifyPUllUpCallback_(true);
414 }
415 
416 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const417 void DragManager::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
418 {
419 }
420 
OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const421 void DragManager::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
422 {
423     CHKPV(pointerEvent);
424     if (g_startFilterTime > 0) {
425         auto actionTime = pointerEvent->GetActionTime();
426         if (g_startFilterTime >= actionTime
427             && pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_MOVE) {
428             FI_HILOGW("Invalid event");
429             return;
430         }
431         g_startFilterTime = -1;
432     }
433     CHKPV(pointerEventCallback_);
434     pointerEventCallback_(pointerEvent);
435     pointerEvent->AddFlag(MMI::InputEvent::EVENT_FLAG_NO_INTERCEPT);
436     MMI::InputManager::GetInstance()->SimulateInputEvent(pointerEvent);
437     if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_UP) {
438         FI_HILOGI("Pointer button is released, appened extra data");
439         MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false));
440     }
441 }
442 
OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const443 void DragManager::InterceptorConsumer::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const
444 {
445 }
446 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
447 
448 #ifdef OHOS_DRAG_ENABLE_MONITOR
OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const449 void DragManager::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
450 {
451     CALL_DEBUG_ENTER;
452 }
453 
OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const454 void DragManager::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
455 {
456     CALL_DEBUG_ENTER;
457     CHKPV(pointerEvent);
458     CHKPV(pointerEventCallback_);
459     pointerEventCallback_(pointerEvent);
460     if (pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_UP) {
461         FI_HILOGI("Pointer button is released, appened extra data");
462         MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false));
463     }
464 }
465 
OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const466 void DragManager::MonitorConsumer::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const
467 {
468     CALL_DEBUG_ENTER;
469 }
470 #endif // OHOS_DRAG_ENABLE_MONITOR
471 
Dump(int32_t fd) const472 void DragManager::Dump(int32_t fd) const
473 {
474     DragCursorStyle style = DRAG_DATA_MGR.GetDragStyle();
475     int32_t targetTid = DRAG_DATA_MGR.GetTargetTid();
476     dprintf(fd, "Drag information:\n");
477 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
478     dprintf(fd,
479             "dragState:%s | dragResult:%s | interceptorId:%d | dragTargetPid:%d | dragTargetTid:%d | "
480             "cursorStyle:%s | isWindowVisble:%s\n", GetDragState(dragState_).c_str(),
481             GetDragResult(dragResult_).c_str(), pointerEventInterceptorId_, GetDragTargetPid(), targetTid,
482             GetDragCursorStyle(style).c_str(), DRAG_DATA_MGR.GetDragWindowVisible() ? "true" : "false");
483 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
484 #ifdef OHOS_DRAG_ENABLE_MONITOR
485     dprintf(fd,
486             "dragState:%s | dragResult:%s | monitorId:%d | dragTargetPid:%d | dragTargetTid:%d | "
487             "cursorStyle:%s | isWindowVisble:%s\n", GetDragState(dragState_).c_str(),
488             GetDragResult(dragResult_).c_str(), pointerEventMonitorId_, GetDragTargetPid(), targetTid,
489             GetDragCursorStyle(style).c_str(), DRAG_DATA_MGR.GetDragWindowVisible() ? "true" : "false");
490 #endif // OHOS_DRAG_ENABLE_MONITOR
491     DragData dragData = DRAG_DATA_MGR.GetDragData();
492     std::string udKey;
493     if (RET_ERR == GetUdKey(udKey)) {
494         FI_HILOGE("Target udKey is empty");
495         udKey = "";
496     }
497     for (const auto& shadowInfo : dragData.shadowInfos) {
498         dprintf(fd, "dragData = {\n""\tshadowInfoX:%d\n\tshadowInfoY\n", shadowInfo.x, shadowInfo.y);
499     }
500     dprintf(fd, "dragData = {\n"
501             "\tudKey:%s\n\tfilterInfo:%s\n\textraInfo:%s\n\tsourceType:%d"
502             "\tdragNum:%d\n\tpointerId:%d\n\tdisplayX:%d\n\tdisplayY:%d\n""\tdisplayId:%d\n\thasCanceledAnimation:%s\n",
503             GetAnonyString(dragData.udKey).c_str(), dragData.filterInfo.c_str(), dragData.extraInfo.c_str(),
504             dragData.sourceType, dragData.dragNum, dragData.pointerId, dragData.displayX, dragData.displayY,
505             dragData.displayId, dragData.hasCanceledAnimation ? "true" : "false");
506     if (dragState_ != DragState::STOP) {
507         for (const auto& shadowInfo : dragData.shadowInfos) {
508             CHKPV(shadowInfo.pixelMap);
509             dprintf(fd, "\tpixelMapWidth:%d\n\tpixelMapHeight:%d\n", shadowInfo.pixelMap->GetWidth(),
510                 shadowInfo.pixelMap->GetHeight());
511         }
512     }
513     dprintf(fd, "}\n");
514 }
515 
GetDragState(DragState value) const516 std::string DragManager::GetDragState(DragState value) const
517 {
518     std::string state = "unknown";
519     const std::map<DragState, std::string> dragStates = {
520         { DragState::START, "start" },
521         { DragState::STOP, "stop" },
522         { DragState::CANCEL, "cancel" },
523         { DragState::ERROR, "error" }
524     };
525     auto iter = dragStates.find(value);
526     if (iter != dragStates.end()) {
527         state = iter->second;
528     }
529     return state;
530 }
531 
GetDragResult(DragResult value) const532 std::string DragManager::GetDragResult(DragResult value) const
533 {
534     std::string result = "unknown";
535     const std::map<DragResult, std::string> dragResults = {
536         { DragResult::DRAG_SUCCESS, "success" },
537         { DragResult::DRAG_FAIL, "fail" },
538         { DragResult::DRAG_CANCEL, "cancel" },
539         { DragResult::DRAG_EXCEPTION, "abnormal" }
540     };
541     auto iter = dragResults.find(value);
542     if (iter != dragResults.end()) {
543         result = iter->second;
544     }
545     return result;
546 }
547 
GetDragCursorStyle(DragCursorStyle value) const548 std::string DragManager::GetDragCursorStyle(DragCursorStyle value) const
549 {
550     std::string style = "unknown";
551     const std::map<DragCursorStyle, std::string> cursorStyles = {
552         { DragCursorStyle::COPY, "copy" },
553         { DragCursorStyle::DEFAULT, "default" },
554         { DragCursorStyle::FORBIDDEN, "forbidden" },
555         { DragCursorStyle::MOVE, "move" }
556     };
557     auto iter = cursorStyles.find(value);
558     if (iter != cursorStyles.end()) {
559         style = iter->second;
560     }
561     return style;
562 }
563 
CreateExtraData(bool appended)564 MMI::ExtraData DragManager::CreateExtraData(bool appended)
565 {
566     DragData dragData = DRAG_DATA_MGR.GetDragData();
567     MMI::ExtraData extraData;
568     extraData.buffer = dragData.buffer;
569     extraData.sourceType = dragData.sourceType;
570     extraData.pointerId = dragData.pointerId;
571     extraData.appended = appended;
572     FI_HILOGD("sourceType:%{public}d, pointerId:%{public}d", extraData.sourceType, extraData.pointerId);
573     return extraData;
574 }
575 
InitDataManager(const DragData & dragData) const576 int32_t DragManager::InitDataManager(const DragData &dragData) const
577 {
578     CALL_INFO_TRACE;
579     DRAG_DATA_MGR.Init(dragData);
580     return RET_OK;
581 }
582 
AddDragEventHandler(int32_t sourceType)583 int32_t DragManager::AddDragEventHandler(int32_t sourceType)
584 {
585     CALL_INFO_TRACE;
586     uint32_t deviceTags = 0;
587 #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR
588     if (sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
589         deviceTags = MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_POINTER);
590     } else if (sourceType == MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN) {
591         deviceTags = MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_TOUCH) |
592             MMI::CapabilityToTags(MMI::INPUT_DEV_CAP_TABLET_TOOL);
593     } else {
594         FI_HILOGW("Drag is not supported for this device type:%{public}d", sourceType);
595         return RET_ERR;
596     }
597 #endif // OHOS_DRAG_ENABLE_INTERCEPTOR
598     if (AddPointerEventHandler(deviceTags) != RET_OK) {
599         FI_HILOGE("Failed to add pointer event handler");
600         return RET_ERR;
601     }
602     if (AddKeyEventMointor() != RET_OK) {
603         FI_HILOGE("Failed to add key event handler");
604         return RET_ERR;
605     }
606     return RET_OK;
607 }
608 
AddPointerEventHandler(uint32_t deviceTags)609 int32_t DragManager::AddPointerEventHandler(uint32_t deviceTags)
610 {
611     CALL_INFO_TRACE;
612 #ifdef OHOS_DRAG_ENABLE_MONITOR
613     auto monitor = std::make_shared<MonitorConsumer>(std::bind(&DragManager::DragCallback, this,
614         std::placeholders::_1));
615     pointerEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(monitor);
616     if (pointerEventMonitorId_ <= 0) {
617         FI_HILOGE("Failed to add pointer event monitor");
618         return RET_ERR;
619     }
620 #else
621     auto callback = std::bind(&DragManager::DragCallback, this, std::placeholders::_1);
622     auto interceptor = std::make_shared<InterceptorConsumer>(callback);
623     pointerEventInterceptorId_ = MMI::InputManager::GetInstance()->AddInterceptor(
624         interceptor, DRAG_PRIORITY, deviceTags);
625     if (pointerEventInterceptorId_ <= 0) {
626         FI_HILOGE("Failed to add pointer event interceptor");
627         return RET_ERR;
628     }
629 #endif // OHOS_DRAG_ENABLE_MONITOR
630     FI_HILOGI("Add drag poniter event handle successfully");
631     return RET_OK;
632 }
633 
AddKeyEventMointor()634 int32_t DragManager::AddKeyEventMointor()
635 {
636     CALL_INFO_TRACE;
637     keyEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(
638         std::bind(&DragManager::DragKeyEventCallback, this, std::placeholders::_1));
639     if (keyEventMonitorId_ <= 0) {
640         FI_HILOGE("Failed to add key event monitor");
641         return RET_ERR;
642     }
643     FI_HILOGI("Add drag key event monitor successfully");
644     return RET_OK;
645 }
646 
RemovePointerEventHandler()647 int32_t DragManager::RemovePointerEventHandler()
648 {
649     CALL_INFO_TRACE;
650 #ifdef OHOS_DRAG_ENABLE_MONITOR
651     if (pointerEventMonitorId_ <= 0) {
652         FI_HILOGE("Invalid pointer event monitor id:%{public}d", pointerEventMonitorId_);
653         return RET_ERR;
654     }
655     MMI::InputManager::GetInstance()->RemoveMonitor(pointerEventMonitorId_);
656     pointerEventMonitorId_ = -1;
657 #else
658     if (pointerEventInterceptorId_ <= 0) {
659         FI_HILOGE("Invalid pointer event interceptor id:%{public}d", pointerEventInterceptorId_);
660     }
661     MMI::InputManager::GetInstance()->RemoveInterceptor(pointerEventInterceptorId_);
662     pointerEventInterceptorId_ = -1;
663 #endif // OHOS_DRAG_ENABLE_MONITOR
664     FI_HILOGI("Remove drag pointer event handler successfully");
665     return RET_OK;
666 }
667 
RemoveKeyEventMointor()668 int32_t DragManager::RemoveKeyEventMointor()
669 {
670     CALL_INFO_TRACE;
671     if (keyEventMonitorId_ <= 0) {
672         FI_HILOGE("Invalid key event monitor id:%{public}d", keyEventMonitorId_);
673         return RET_ERR;
674     }
675     MMI::InputManager::GetInstance()->RemoveMonitor(keyEventMonitorId_);
676     keyEventMonitorId_ = -1;
677     FI_HILOGI("Remove drag key event handle successfully");
678     return RET_OK;
679 }
680 
OnStartDrag()681 int32_t DragManager::OnStartDrag()
682 {
683     CALL_INFO_TRACE;
684     if (isControlMultiScreenVisible_) {
685         isControlMultiScreenVisible_ = false;
686     }
687     auto extraData = CreateExtraData(true);
688     DragData dragData = DRAG_DATA_MGR.GetDragData();
689     dragDrawing_.SetScreenId(dragData.displayId);
690     if (Rosen::DisplayManager::GetInstance().IsFoldable()) {
691         Rosen::FoldDisplayMode foldMode = Rosen::DisplayManager::GetInstance().GetFoldDisplayMode();
692         if (foldMode == Rosen::FoldDisplayMode::MAIN) {
693             dragDrawing_.SetScreenId(FOLD_SCREEN_ID);
694         }
695     }
696     int32_t ret = dragDrawing_.Init(dragData);
697     if (ret == INIT_FAIL) {
698         FI_HILOGE("Init drag drawing failed");
699         dragDrawing_.DestroyDragWindow();
700         return RET_ERR;
701     }
702     if (ret == INIT_CANCEL) {
703         FI_HILOGE("Init drag drawing cancel, drag animation is running");
704         return RET_ERR;
705     }
706     dragDrawing_.Draw(dragData.displayId, dragData.displayX, dragData.displayY);
707     FI_HILOGI("Start drag, appened extra data");
708     MMI::InputManager::GetInstance()->AppendExtraData(extraData);
709     ret = AddDragEventHandler(dragData.sourceType);
710     if (ret != RET_OK) {
711         FI_HILOGE("Failed to add drag event handler");
712         dragDrawing_.DestroyDragWindow();
713         return RET_ERR;
714     }
715     dragAction_.store(DragAction::MOVE);
716     return RET_OK;
717 }
718 
OnStopDrag(DragResult result,bool hasCustomAnimation)719 int32_t DragManager::OnStopDrag(DragResult result, bool hasCustomAnimation)
720 {
721     FI_HILOGI("Add custom animation:%{public}s", hasCustomAnimation ? "true" : "false");
722     if (RemovePointerEventHandler() != RET_OK) {
723         FI_HILOGE("Failed to remove pointer event handler");
724         return RET_ERR;
725     }
726     if (RemoveKeyEventMointor() != RET_OK) {
727         FI_HILOGE("Failed to remove key event handler");
728         return RET_ERR;
729     }
730     dragAction_.store(DragAction::MOVE);
731     DragData dragData = DRAG_DATA_MGR.GetDragData();
732     if ((dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) && !DRAG_DATA_MGR.IsMotionDrag()) {
733         dragDrawing_.EraseMouseIcon();
734         FI_HILOGI("Set the pointer cursor visible");
735         MMI::InputManager::GetInstance()->SetPointerVisible(true);
736     }
737     FI_HILOGI("Stop drag, appened extra data");
738     MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false));
739     return HandleDragResult(result, hasCustomAnimation);
740 }
741 
OnSetDragWindowVisible(bool visible,bool isForce)742 int32_t DragManager::OnSetDragWindowVisible(bool visible, bool isForce)
743 {
744     FI_HILOGI("Set drag window visibleion:%{public}s", visible ? "true" : "false");
745     if (dragState_ == DragState::MOTION_DRAGGING) {
746         FI_HILOGW("Currently in motion dragging");
747         return RET_OK;
748     }
749     if (dragState_ == DragState::STOP) {
750         FI_HILOGW("No drag instance running, can not set drag window visible");
751         return RET_ERR;
752     }
753     if (!isForce && isControlMultiScreenVisible_) {
754         FI_HILOGW("The drag-and-drop window is controlled by multi-screen coordination,"
755             "can not set drag window visible:%{public}d", visible);
756         return RET_OK;
757     }
758     DragDFX::WriteDragWindowVisible(dragState_, visible, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR);
759     DRAG_DATA_MGR.SetDragWindowVisible(visible);
760     dragDrawing_.UpdateDragWindowState(visible);
761     DragData dragData = DRAG_DATA_MGR.GetDragData();
762     if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE && visible) {
763         FI_HILOGI("Set the pointer cursor invisible");
764         MMI::InputManager::GetInstance()->SetPointerVisible(false);
765     }
766     if (isForce) {
767         isControlMultiScreenVisible_ = isForce;
768         FI_HILOGW("The drag-and-drop window is controlled by multi-screen coordination");
769     }
770     return RET_OK;
771 }
772 
OnGetShadowOffset(int32_t & offsetX,int32_t & offsetY,int32_t & width,int32_t & height)773 int32_t DragManager::OnGetShadowOffset(int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height)
774 {
775     return DRAG_DATA_MGR.GetShadowOffset(offsetX, offsetY, width, height);
776 }
777 
RegisterStateChange(std::function<void (DragState)> callback)778 void DragManager::RegisterStateChange(std::function<void(DragState)> callback)
779 {
780     CALL_INFO_TRACE;
781     CHKPV(callback);
782     stateChangedCallback_ = callback;
783 }
784 
RegisterNotifyPullUp(std::function<void (bool)> callback)785 void DragManager::RegisterNotifyPullUp(std::function<void(bool)> callback)
786 {
787     CALL_INFO_TRACE;
788     CHKPV(callback);
789     notifyPUllUpCallback_ = callback;
790 }
791 
StateChangedNotify(DragState state)792 void DragManager::StateChangedNotify(DragState state)
793 {
794     CALL_INFO_TRACE;
795     if ((stateChangedCallback_ != nullptr) && (!DRAG_DATA_MGR.IsMotionDrag())) {
796         stateChangedCallback_(state);
797     }
798 }
799 
GetExtraData(bool appended) const800 MMI::ExtraData DragManager::GetExtraData(bool appended) const
801 {
802     return CreateExtraData(appended);
803 }
804 
GetDragState() const805 DragState DragManager::GetDragState() const
806 {
807     return dragState_;
808 }
809 
GetAllowDragState(bool & isAllowDrag)810 void DragManager::GetAllowDragState(bool &isAllowDrag)
811 {
812     CALL_DEBUG_ENTER;
813     if (dragState_ != DragState::START) {
814         FI_HILOGW("Currently state is \'%{public}d\' not in allowed dragState", static_cast<int32_t>(dragState_));
815         return;
816     }
817     isAllowDrag = dragDrawing_.GetAllowDragState();
818 }
819 
SetDragState(DragState state)820 void DragManager::SetDragState(DragState state)
821 {
822     FI_HILOGI("SetDragState:%{public}d to %{public}d", static_cast<int32_t>(dragState_), static_cast<int32_t>(state));
823     dragState_ = state;
824     if (state == DragState::START) {
825         UpdateDragStyleCross();
826     }
827 }
828 
GetDragResult() const829 DragResult DragManager::GetDragResult() const
830 {
831     return dragResult_;
832 }
833 
GetDragSummary(std::map<std::string,int64_t> & summarys)834 int32_t DragManager::GetDragSummary(std::map<std::string, int64_t> &summarys)
835 {
836     DragData dragData = DRAG_DATA_MGR.GetDragData();
837     summarys = dragData.summarys;
838     if (summarys.empty()) {
839         FI_HILOGW("Summarys is empty");
840     }
841     return RET_OK;
842 }
843 
HandleDragResult(DragResult result,bool hasCustomAnimation)844 int32_t DragManager::HandleDragResult(DragResult result, bool hasCustomAnimation)
845 {
846     CALL_INFO_TRACE;
847     switch (result) {
848         case DragResult::DRAG_SUCCESS: {
849             if (!hasCustomAnimation) {
850                 dragDrawing_.OnDragSuccess();
851             } else {
852                 dragDrawing_.DestroyDragWindow();
853                 dragDrawing_.UpdateDrawingState();
854             }
855             break;
856         }
857         case DragResult::DRAG_FAIL:
858         case DragResult::DRAG_CANCEL: {
859             if (!hasCustomAnimation) {
860                 dragDrawing_.OnDragFail();
861             } else {
862                 dragDrawing_.DestroyDragWindow();
863                 dragDrawing_.UpdateDrawingState();
864             }
865             break;
866         }
867         case DragResult::DRAG_EXCEPTION: {
868             dragDrawing_.DestroyDragWindow();
869             dragDrawing_.UpdateDrawingState();
870             break;
871         }
872         default: {
873             FI_HILOGW("Unsupported DragResult type, DragResult:%{public}d", result);
874             break;
875         }
876     }
877     return RET_OK;
878 }
879 
SetPointerEventFilterTime(int64_t filterTime)880 void DragManager::SetPointerEventFilterTime(int64_t filterTime)
881 {
882     CALL_DEBUG_ENTER;
883     g_startFilterTime = filterTime;
884 }
885 
MoveTo(int32_t x,int32_t y)886 void DragManager::MoveTo(int32_t x, int32_t y)
887 {
888     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
889         FI_HILOGE("Drag instance not running");
890         return;
891     }
892     DragData dragData = DRAG_DATA_MGR.GetDragData();
893     FI_HILOGI("displayId:%{public}d, x:%{public}d, y:%{public}d", dragData.displayId, x, y);
894     dragDrawing_.Draw(dragData.displayId, x, y);
895 }
896 
UpdatePreviewStyle(const PreviewStyle & previewStyle)897 int32_t DragManager::UpdatePreviewStyle(const PreviewStyle &previewStyle)
898 {
899     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
900         FI_HILOGE("Drag instance not running");
901         return RET_ERR;
902     }
903     if (previewStyle == DRAG_DATA_MGR.GetPreviewStyle()) {
904         FI_HILOGD("Not need to update previewStyle");
905         return RET_OK;
906     }
907     DRAG_DATA_MGR.SetPreviewStyle(previewStyle);
908     FI_HILOGI("Update previewStyle successfully");
909     return dragDrawing_.UpdatePreviewStyle(previewStyle);
910 }
911 
UpdatePreviewStyleWithAnimation(const PreviewStyle & previewStyle,const PreviewAnimation & animation)912 int32_t DragManager::UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle,
913     const PreviewAnimation &animation)
914 {
915     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
916         FI_HILOGE("Drag instance not running");
917         return RET_ERR;
918     }
919     if (previewStyle == DRAG_DATA_MGR.GetPreviewStyle()) {
920         FI_HILOGD("Not need to update previewStyle");
921         return RET_OK;
922     }
923     DRAG_DATA_MGR.SetPreviewStyle(previewStyle);
924     FI_HILOGI("Update previewStyle successfully");
925     return dragDrawing_.UpdatePreviewStyleWithAnimation(previewStyle, animation);
926 }
927 
DragKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent)928 void DragManager::DragKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent)
929 {
930     CHKPV(keyEvent);
931     auto keyItems = keyEvent->GetKeyItems();
932     auto iter = std::find_if(keyItems.begin(), keyItems.end(),
933         [] (std::optional<MMI::KeyEvent::KeyItem> keyItem) {
934             return ((keyItem->GetKeyCode() == MMI::KeyEvent::KEYCODE_CTRL_LEFT) ||
935                     (keyItem->GetKeyCode() == MMI::KeyEvent::KEYCODE_CTRL_RIGHT));
936         });
937     if (iter == keyItems.end()) {
938         dragAction_.store(DragAction::MOVE);
939         return;
940     }
941     if ((DRAG_DATA_MGR.GetDragStyle() == DragCursorStyle::DEFAULT) ||
942         (DRAG_DATA_MGR.GetDragStyle() == DragCursorStyle::FORBIDDEN)) {
943         dragAction_.store(DragAction::MOVE);
944         return;
945     }
946     if (!iter->IsPressed()) {
947         CtrlKeyStyleChangedNotify(DRAG_DATA_MGR.GetDragStyle(), DragAction::MOVE);
948         HandleCtrlKeyEvent(DRAG_DATA_MGR.GetDragStyle(), DragAction::MOVE);
949         dragAction_.store(DragAction::MOVE);
950         return;
951     }
952     if (DRAG_DATA_MGR.GetDragStyle() == DragCursorStyle::COPY) {
953         FI_HILOGD("Not need update drag style");
954         return;
955     }
956     CtrlKeyStyleChangedNotify(DragCursorStyle::COPY, DragAction::COPY);
957     HandleCtrlKeyEvent(DragCursorStyle::COPY, DragAction::COPY);
958     dragAction_.store(DragAction::COPY);
959 }
960 
HandleCtrlKeyEvent(DragCursorStyle style,DragAction action)961 void DragManager::HandleCtrlKeyEvent(DragCursorStyle style, DragAction action)
962 {
963     CALL_DEBUG_ENTER;
964     if (action == dragAction_.load()) {
965         FI_HILOGD("Not need update drag style");
966         return;
967     }
968     CHKPV(context_);
969     int32_t ret = context_->GetDelegateTasks().PostAsyncTask(
970         std::bind(&DragDrawing::UpdateDragStyle, &dragDrawing_, style));
971     if (ret != RET_OK) {
972         FI_HILOGE("Post async task failed");
973     }
974 }
975 
OnUpdateDragStyle(DragCursorStyle style)976 int32_t DragManager::OnUpdateDragStyle(DragCursorStyle style)
977 {
978     CALL_DEBUG_ENTER;
979     DragCursorStyle updateStyle = GetRealDragStyle(style);
980     stateNotify_.StyleChangedNotify(updateStyle);
981     if (dragDrawing_.UpdateDragStyle(updateStyle) != RET_OK) {
982         DragDFX::WriteUpdateDragStyle(updateStyle, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT);
983         return RET_ERR;
984     }
985     FI_HILOGD("Update dragStyle:%{public}s successfully", GetDragStyleName(updateStyle).c_str());
986     return RET_OK;
987 }
988 
UpdateDragStyleCross()989 void DragManager::UpdateDragStyleCross()
990 {
991     CALL_DEBUG_ENTER;
992     auto dragStyle = DRAG_DATA_MGR.GetDragStyle();
993     FI_HILOGI("OnUpdateDragStyle dragStyle:%{public}s", GetDragStyleName(dragStyle).c_str());
994     if (OnUpdateDragStyle(DRAG_DATA_MGR.GetDragStyle()) != RET_OK) {
995         FI_HILOGE("OnUpdateDragStyle failed");
996     }
997 }
998 
GetDragStyleName(DragCursorStyle style)999 std::string DragManager::GetDragStyleName(DragCursorStyle style)
1000 {
1001     switch (style) {
1002         case DragCursorStyle::DEFAULT : {
1003             return "DEFAULT";
1004         }
1005         case DragCursorStyle::FORBIDDEN : {
1006             return "FORBIDDEN";
1007         }
1008         case DragCursorStyle::COPY : {
1009             return "COPY";
1010         }
1011         case DragCursorStyle::MOVE : {
1012             return "MOVE";
1013         }
1014         default:
1015             break;
1016     }
1017     return "UNKNOW";
1018 }
1019 
GetRealDragStyle(DragCursorStyle style)1020 DragCursorStyle DragManager::GetRealDragStyle(DragCursorStyle style)
1021 {
1022     if ((dragAction_ == DragAction::COPY) && (style == DragCursorStyle::MOVE)) {
1023         return DragCursorStyle::COPY;
1024     }
1025     return style;
1026 }
1027 
CtrlKeyStyleChangedNotify(DragCursorStyle style,DragAction action)1028 void DragManager::CtrlKeyStyleChangedNotify(DragCursorStyle style, DragAction action)
1029 {
1030     CALL_DEBUG_ENTER;
1031     if (action == dragAction_.load()) {
1032         FI_HILOGD("Has notified");
1033         return;
1034     }
1035     CHKPV(context_);
1036     int32_t ret = context_->GetDelegateTasks().PostAsyncTask(
1037         std::bind(&StateChangeNotify::StyleChangedNotify, &stateNotify_, style));
1038     if (ret != RET_OK) {
1039         FI_HILOGE("Post async task failed");
1040     }
1041 }
1042 
GetDragAction(DragAction & dragAction) const1043 int32_t DragManager::GetDragAction(DragAction &dragAction) const
1044 {
1045     CALL_DEBUG_ENTER;
1046     if (dragState_ != DragState::START) {
1047         FI_HILOGE("No drag instance running, can not get drag action");
1048         return RET_ERR;
1049     }
1050     dragAction = dragAction_.load();
1051     return RET_OK;
1052 }
1053 
EnterTextEditorArea(bool enable)1054 int32_t DragManager::EnterTextEditorArea(bool enable)
1055 {
1056     CALL_DEBUG_ENTER;
1057     if (dragState_ != DragState::START) {
1058         FI_HILOGE("No drag instance running");
1059         return RET_ERR;
1060     }
1061     if (DRAG_DATA_MGR.GetTextEditorAreaFlag() == enable) {
1062         FI_HILOGE("Set textEditorArea:%{public}s already", (enable ? "true" : "false"));
1063         return RET_ERR;
1064     }
1065     if (DRAG_DATA_MGR.GetCoordinateCorrected()) {
1066         FI_HILOGE("GetCoordinateCorrected failed");
1067         return RET_ERR;
1068     }
1069     return dragDrawing_.EnterTextEditorArea(enable);
1070 }
1071 
GetExtraInfo(std::string & extraInfo) const1072 int32_t DragManager::GetExtraInfo(std::string &extraInfo) const
1073 {
1074     CALL_DEBUG_ENTER;
1075     DragData dragData = DRAG_DATA_MGR.GetDragData();
1076     if (dragData.extraInfo.empty()) {
1077         FI_HILOGE("The extraInfo is empty");
1078         return RET_ERR;
1079     }
1080     extraInfo = dragData.extraInfo;
1081     return RET_OK;
1082 }
1083 
AddPrivilege(int32_t tokenId)1084 int32_t DragManager::AddPrivilege(int32_t tokenId)
1085 {
1086     CALL_DEBUG_ENTER;
1087     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
1088         FI_HILOGE("Drag instance not running");
1089         return RET_ERR;
1090     }
1091     DragData dragData = DRAG_DATA_MGR.GetDragData();
1092     FI_HILOGD("Target window drag tid:%{public}d", tokenId);
1093     SendDragData(tokenId, dragData.udKey);
1094     return RET_OK;
1095 }
1096 
RotateDragWindow(Rosen::Rotation rotation)1097 int32_t DragManager::RotateDragWindow(Rosen::Rotation rotation)
1098 {
1099     CALL_DEBUG_ENTER;
1100     dragDrawing_.SetRotation(rotation);
1101     if (dragState_ != DragState::START && dragState_ != DragState::MOTION_DRAGGING) {
1102         FI_HILOGD("Drag instance not running");
1103         return RET_OK;
1104     }
1105     return dragDrawing_.RotateDragWindow(rotation);
1106 }
1107 } // namespace DeviceStatus
1108 } // namespace Msdp
1109 } // namespace OHOS
1110