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