From 4479d70f1f8b508350e5f1b076c4c54c4750cc98 Mon Sep 17 00:00:00 2001 From: Science Date: Thu, 9 Nov 2023 06:16:16 +0000 Subject: [PATCH 1/2] update Signed-off-by: Science Change-Id: I18762c7285100b22197b122c9deabe11094f0d6b --- .../interaction/include/drag_manager_impl.h | 6 +- .../include/interaction_manager_impl.h | 4 + .../interaction/src/drag_manager_impl.cpp | 5 + .../interaction/src/interaction_manager.cpp | 5 + .../src/interaction_manager_impl.cpp | 6 + frameworks/native/src/devicestatus_client.cpp | 7 + .../innerkits/include/devicestatus_client.h | 1 + .../innerkits/interaction/include/drag_data.h | 6 + .../interaction/include/interaction_manager.h | 8 + .../innerkits/libdevicestatus_client_map | 1 + services/communication/base/i_devicestatus.h | 1 + .../base/msdp_ipc_interface_code.h | 1 + .../client/include/devicestatus_srv_proxy.h | 1 + .../client/src/devicestatus_srv_proxy.cpp | 23 +++ .../service/include/devicestatus_srv_stub.h | 1 + .../service/src/devicestatus_srv_stub.cpp | 16 +- .../interaction/drag/include/drag_manager.h | 24 ++- .../interaction/drag/src/drag_manager.cpp | 150 ++++++++++++++---- .../native/include/devicestatus_service.h | 1 + services/native/src/devicestatus_service.cpp | 10 ++ 20 files changed, 237 insertions(+), 40 deletions(-) diff --git a/frameworks/native/interaction/include/drag_manager_impl.h b/frameworks/native/interaction/include/drag_manager_impl.h index f9691d3af..7cc319f1a 100644 --- a/frameworks/native/interaction/include/drag_manager_impl.h +++ b/frameworks/native/interaction/include/drag_manager_impl.h @@ -50,11 +50,15 @@ public: int32_t UpdateDragStyle(DragCursorStyle style); int32_t UpdateShadowPic(const ShadowInfo &shadowInfo); int32_t GetDragTargetPid(); - int32_t GetDragState(DragState &dragState); int32_t GetUdKey(std::string &udKey); int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height); int32_t GetDragData(DragData &dragData); +<<<<<<< Updated upstream int32_t GetDragSummary(std::map &summarys); +======= + int32_t GetDragState(DragState &dragState); + int32_t GetDropType(DropType& dropType); +>>>>>>> Stashed changes private: std::mutex mtx_; diff --git a/frameworks/native/interaction/include/interaction_manager_impl.h b/frameworks/native/interaction/include/interaction_manager_impl.h index 20945df4c..ef262b80e 100644 --- a/frameworks/native/interaction/include/interaction_manager_impl.h +++ b/frameworks/native/interaction/include/interaction_manager_impl.h @@ -57,7 +57,11 @@ public: int32_t GetDragState(DragState &dragState); int32_t AddHotAreaListener(std::shared_ptr listener); int32_t RemoveHotAreaListener(std::shared_ptr listener = nullptr); +<<<<<<< Updated upstream int32_t GetDragSummary(std::map &summarys); +======= + int32_t GetDropType(DropType &dropType); +>>>>>>> Stashed changes private: void InitMsgHandler(); diff --git a/frameworks/native/interaction/src/drag_manager_impl.cpp b/frameworks/native/interaction/src/drag_manager_impl.cpp index bd4512ba5..51fd1a2a7 100644 --- a/frameworks/native/interaction/src/drag_manager_impl.cpp +++ b/frameworks/native/interaction/src/drag_manager_impl.cpp @@ -270,6 +270,11 @@ int32_t DragManagerImpl::GetDragSummary(std::map &summarys CALL_DEBUG_ENTER; return DeviceStatusClient::GetInstance().GetDragSummary(summarys); } + +int32_t DragManagerImpl::GetDropType(DropType& dropType) +{ + return DeviceStatusClient::GetInstance().GetDropType(dropType); +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/interaction/src/interaction_manager.cpp b/frameworks/native/interaction/src/interaction_manager.cpp index 625f1e758..02380b0d0 100644 --- a/frameworks/native/interaction/src/interaction_manager.cpp +++ b/frameworks/native/interaction/src/interaction_manager.cpp @@ -152,6 +152,11 @@ int32_t InteractionManager::GetDragSummary(std::map &summa { return INTER_MGR_IMPL.GetDragSummary(summarys); } + +int32_t InteractionManager::GetDropType(DropType &dropType) +{ + return INTER_MGR_IMPL.GetDropType(dropType); +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/frameworks/native/interaction/src/interaction_manager_impl.cpp b/frameworks/native/interaction/src/interaction_manager_impl.cpp index 3e6bf3307..d60a688ea 100644 --- a/frameworks/native/interaction/src/interaction_manager_impl.cpp +++ b/frameworks/native/interaction/src/interaction_manager_impl.cpp @@ -299,6 +299,12 @@ int32_t InteractionManagerImpl::GetDragState(DragState &dragState) return dragManagerImpl_.GetDragState(dragState); } +int32_t InteractionManagerImpl::GetDropType(DropType &dropType) +{ + CALL_DEBUG_ENTER; + return dragManagerImpl_.GetDropType(dropType); +} + int32_t InteractionManagerImpl::AddHotAreaListener(std::shared_ptr listener) { CALL_DEBUG_ENTER; diff --git a/frameworks/native/src/devicestatus_client.cpp b/frameworks/native/src/devicestatus_client.cpp index 0bc51f214..fb9efdca9 100644 --- a/frameworks/native/src/devicestatus_client.cpp +++ b/frameworks/native/src/devicestatus_client.cpp @@ -437,6 +437,13 @@ int32_t DeviceStatusClient::GetDragState(DragState &dragState) return devicestatusProxy_->GetDragState(dragState); } +int32_t DeviceStatusClient::GetDropType(DropType& dropType) +{ + CALL_DEBUG_ENTER; + DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR); + return devicestatusProxy_->GetDropType(dropType); +} + int32_t DeviceStatusClient::AddHotAreaListener() { CALL_DEBUG_ENTER; diff --git a/interfaces/innerkits/include/devicestatus_client.h b/interfaces/innerkits/include/devicestatus_client.h index 091b9fb5b..eaf90b726 100644 --- a/interfaces/innerkits/include/devicestatus_client.h +++ b/interfaces/innerkits/include/devicestatus_client.h @@ -67,6 +67,7 @@ public: int32_t UpdateShadowPic(const ShadowInfo &shadowInfo); int32_t GetDragData(DragData &dragData); int32_t GetDragState(DragState &dragState); + int32_t GetDropType(DropType& dropType); int32_t AllocSocketPair(int32_t moduleType); int32_t GetClientSocketFdOfAllocedSocketPair() const; int32_t AddHotAreaListener(); diff --git a/interfaces/innerkits/interaction/include/drag_data.h b/interfaces/innerkits/interaction/include/drag_data.h index 0a3ae8773..2fdaf1822 100644 --- a/interfaces/innerkits/interaction/include/drag_data.h +++ b/interfaces/innerkits/interaction/include/drag_data.h @@ -93,6 +93,12 @@ enum class DragCursorStyle { COPY, MOVE }; + +enum class DropType { + INVALID = -1, + MOVE = 0, + COPY = 1 +}; } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/interfaces/innerkits/interaction/include/interaction_manager.h b/interfaces/innerkits/interaction/include/interaction_manager.h index ff55e4e56..71d0b9560 100644 --- a/interfaces/innerkits/interaction/include/interaction_manager.h +++ b/interfaces/innerkits/interaction/include/interaction_manager.h @@ -215,6 +215,14 @@ public: */ int32_t GetDragData(DragData &dragData); + /** + * @brief Obtains the current droping type. + * @param dropType dropping type while user pressed ctrl or not. + * @return Returns 0 if the operation is successful; returns other values if the operation fails. + * @since 10 + */ + int32_t GetDropType(DropType &dropType); + /** * @brief Registers a listener for screen hot area of the mouse pointer. * @param listener Indicates the listener for screen hot area of the mouse pointer. diff --git a/interfaces/innerkits/libdevicestatus_client_map b/interfaces/innerkits/libdevicestatus_client_map index 3d0114296..cf56731f5 100644 --- a/interfaces/innerkits/libdevicestatus_client_map +++ b/interfaces/innerkits/libdevicestatus_client_map @@ -54,6 +54,7 @@ "OHOS::Msdp::DeviceStatus::InteractionManager::RemoveHotAreaListener(std::__h::shared_ptr)"; "OHOS::Msdp::DeviceStatus::InteractionManager::GetDragSummary(std::__h::map, std::__h::allocator>, long long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long long>>>&)"; "OHOS::Msdp::DeviceStatus::InteractionManager::GetDragSummary(std::__h::map, std::__h::allocator>, long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long>>>&)"; + "OHOS::Msdp::DeviceStatus::InteractionManager::GetDropType(OHOS::Msdp::DeviceStatus::DropType&)"; }; local: *; diff --git a/services/communication/base/i_devicestatus.h b/services/communication/base/i_devicestatus.h index 6ec3b0ffb..c51676acc 100644 --- a/services/communication/base/i_devicestatus.h +++ b/services/communication/base/i_devicestatus.h @@ -62,6 +62,7 @@ public: virtual int32_t GetDragData(DragData &dragData) = 0; virtual int32_t GetDragState(DragState &dragState) = 0; virtual int32_t GetDragSummary(std::map &summarys) = 0; + virtual int32_t GetDropType(DropType &dropType) = 0; virtual bool IsRunning() const { return true; diff --git a/services/communication/base/msdp_ipc_interface_code.h b/services/communication/base/msdp_ipc_interface_code.h index 89b85090c..a4939b743 100644 --- a/services/communication/base/msdp_ipc_interface_code.h +++ b/services/communication/base/msdp_ipc_interface_code.h @@ -45,6 +45,7 @@ enum class DeviceInterfaceCode { UNREGISTER_SUBSCRIPT_MONITOR, GET_DRAG_STATE, GET_DRAG_SUMMARY, + GET_DROP_TYPE, ALLOC_SOCKET_FD = 40, ADD_HOT_AREA_MONITOR = 50, REMOVE_HOT_AREA_MONITOR diff --git a/services/communication/client/include/devicestatus_srv_proxy.h b/services/communication/client/include/devicestatus_srv_proxy.h index 224d48122..2b0061ed8 100644 --- a/services/communication/client/include/devicestatus_srv_proxy.h +++ b/services/communication/client/include/devicestatus_srv_proxy.h @@ -64,6 +64,7 @@ public: virtual int32_t AddHotAreaListener() override; virtual int32_t RemoveHotAreaListener() override; virtual int32_t GetDragSummary(std::map &summarys) override; + virtual int32_t GetDropType(DropType& dropType) override; private: static inline BrokerDelegator delegator_; diff --git a/services/communication/client/src/devicestatus_srv_proxy.cpp b/services/communication/client/src/devicestatus_srv_proxy.cpp index 0ae518b4c..e0f0700ee 100644 --- a/services/communication/client/src/devicestatus_srv_proxy.cpp +++ b/services/communication/client/src/devicestatus_srv_proxy.cpp @@ -733,6 +733,29 @@ int32_t DeviceStatusSrvProxy::GetDragSummary(std::map &sum } return ret; } + +int32_t DeviceStatusSrvProxy::GetDropType(DropType& dropType) +{ + CALL_DEBUG_ENTER; + MessageParcel data; + if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) { + FI_HILOGE("Failed to write descriptor"); + return ERR_INVALID_VALUE; + } + MessageParcel reply; + MessageOption option; + sptr remote = Remote(); + CHKPR(remote, RET_ERR); + int32_t ret = remote->SendRequest(static_cast(DeviceInterfaceCode::GET_DROP_TYPE), + data, reply, option); + if (ret != RET_OK) { + FI_HILOGE("Send request failed, ret:%{public}d", ret); + } + int32_t type; + READINT32(reply, type, IPC_PROXY_DEAD_OBJECT_ERR); + dropType = static_cast(type); + return ret; +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/services/communication/service/include/devicestatus_srv_stub.h b/services/communication/service/include/devicestatus_srv_stub.h index 0b9f039dc..df2250f02 100644 --- a/services/communication/service/include/devicestatus_srv_stub.h +++ b/services/communication/service/include/devicestatus_srv_stub.h @@ -64,6 +64,7 @@ private: int32_t UpdateShadowPicStub(MessageParcel& data, MessageParcel& reply); int32_t GetDragDataStub(MessageParcel& data, MessageParcel& reply); int32_t GetDragStateStub(MessageParcel &data, MessageParcel &reply); + int32_t GetDropTypeStub(MessageParcel &data, MessageParcel &reply); int32_t AddHotAreaListenerStub(MessageParcel& data, MessageParcel& reply); int32_t RemoveHotAreaListenerStub(MessageParcel& data, MessageParcel& reply); int32_t GetDragSummaryStub(MessageParcel& data, MessageParcel& reply); diff --git a/services/communication/service/src/devicestatus_srv_stub.cpp b/services/communication/service/src/devicestatus_srv_stub.cpp index c0dd55978..f308aed30 100644 --- a/services/communication/service/src/devicestatus_srv_stub.cpp +++ b/services/communication/service/src/devicestatus_srv_stub.cpp @@ -110,7 +110,9 @@ void DeviceStatusSrvStub::InitDrag() { static_cast(DeviceInterfaceCode::GET_DRAG_STATE), &DeviceStatusSrvStub::GetDragStateStub }, { static_cast(DeviceInterfaceCode::GET_DRAG_SUMMARY), - &DeviceStatusSrvStub::GetDragSummaryStub } + &DeviceStatusSrvStub::GetDragSummaryStub }, + {static_cast(DeviceInterfaceCode::GET_DROP_TYPE), + &DeviceStatusSrvStub::GetDropTypeStub } }; connFuncs_.insert(dragFuncs_.begin(), dragFuncs_.end()); } @@ -613,6 +615,18 @@ int32_t DeviceStatusSrvStub::GetDragSummaryStub(MessageParcel& data, MessageParc } return RET_OK; } + +int32_t DeviceStatusSrvStub::GetDropTypeStub(MessageParcel &data, MessageParcel &reply) +{ + CALL_DEBUG_ENTER; + DropType dropType; + int32_t ret = GetDropType(dropType); + if (ret != RET_OK) { + return RET_ERR; + } + WRITEINT32(reply, static_cast(dropType), IPC_STUB_WRITE_PARCEL_ERR); + return RET_OK; +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS \ No newline at end of file diff --git a/services/interaction/drag/include/drag_manager.h b/services/interaction/drag/include/drag_manager.h index 6f6b670ab..3ead0575f 100644 --- a/services/interaction/drag/include/drag_manager.h +++ b/services/interaction/drag/include/drag_manager.h @@ -16,6 +16,7 @@ #ifndef DRAG_MANAGER_H #define DRAG_MANAGER_H +#include #include #include "extra_data.h" @@ -69,34 +70,43 @@ public: DragState GetDragState() const override; void SetDragState(DragState state) override; int32_t GetDragSummary(std::map &summarys); + void DragKeyEventCallback(std::shared_ptr keyEvent); + int32_t GetDropType(DropType& dropType) const; #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR class InterceptorConsumer : public MMI::IInputEventConsumer { public: InterceptorConsumer(IContext *context, - std::function)> cb) : context_(context), callback_(cb) {} + std::function)> cb) + : context_(context), + pointerEventCallback_(cb) {} void OnInputEvent(std::shared_ptr keyEvent) const override; void OnInputEvent(std::shared_ptr pointerEvent) const override; void OnInputEvent(std::shared_ptr axisEvent) const override; private: IContext* context_ { nullptr }; - std::function)> callback_ { nullptr }; + std::function)> pointerEventCallback_ { nullptr }; }; #endif // OHOS_DRAG_ENABLE_INTERCEPTOR #ifdef OHOS_DRAG_ENABLE_MONITOR class MonitorConsumer : public MMI::IInputEventConsumer { public: - explicit MonitorConsumer(std::function)> cb) : callback_(cb) {} + explicit MonitorConsumer( + std::function)> cb) : pointerEventCallback_(cb) {} void OnInputEvent(std::shared_ptr keyEvent) const override; void OnInputEvent(std::shared_ptr pointerEvent) const override; void OnInputEvent(std::shared_ptr axisEvent) const override; private: - std::function)> callback_; + std::function)> pointerEventCallback_; }; #endif //OHOS_DRAG_ENABLE_MONITOR private: void PrintDragData(const DragData &dragData); int32_t AddDragEventHandler(int32_t sourceType); + int32_t AddPointerEventHandler(uint32_t deviceTags); + int32_t AddKeyEventMointor(); + int32_t RemoveKeyEventMointor(); + int32_t RemovePointerEventHandler(); int32_t NotifyDragResult(DragResult result); int32_t InitDataManager(const DragData &dragData) const; int32_t OnStartDrag(); @@ -112,11 +122,13 @@ private: StateChangeNotify stateNotify_; DragState dragState_ { DragState::STOP }; DragResult dragResult_ { DragResult::DRAG_FAIL }; + int32_t keyEventMonitorId_ { -1 }; + std::atomic dropType_ { DropType::MOVE }; #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR - int32_t interceptorId_ { -1 }; + int32_t pointerEventInterceptorId_ { -1 }; #endif // OHOS_DRAG_ENABLE_INTERCEPTOR #ifdef OHOS_DRAG_ENABLE_MONITOR - int32_t monitorId_ { -1 }; + int32_t pointerEventMonitorId_ { -1 }; #endif //OHOS_DRAG_ENABLE_MONITOR SessionPtr dragOutSession_ { nullptr }; DragDrawing dragDrawing_; diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index 3a57e26eb..e429fd9ba 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -15,6 +15,8 @@ #include "drag_manager.h" +#include + #include "extra_data.h" #include "hitrace_meter.h" #include "pixel_map.h" @@ -33,6 +35,7 @@ namespace DeviceStatus { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "DragManager" }; constexpr int32_t TIMEOUT_MS { 2000 }; +constexpr size_t SIGNLE_KEY_ITEM { 1 }; #ifdef OHOS_DRAG_ENABLE_INTERCEPTOR constexpr int32_t DRAG_PRIORITY { 500 }; std::atomic g_startFilterTime { -1 }; @@ -360,9 +363,9 @@ void DragManager::InterceptorConsumer::OnInputEvent(std::shared_ptrAddFlag(MMI::InputEvent::EVENT_FLAG_NO_INTERCEPT); auto fun = [] (std::shared_ptr pointerEvent) -> int32_t { MMI::InputManager::GetInstance()->SimulateInputEvent(pointerEvent); @@ -394,8 +397,8 @@ void DragManager::MonitorConsumer::OnInputEvent(std::shared_ptrGetPointerAction() == MMI::PointerEvent::POINTER_ACTION_PULL_UP) { FI_HILOGI("Pointer button is released, appened extra data"); MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false)); @@ -418,14 +421,14 @@ void DragManager::Dump(int32_t fd) const dprintf(fd, "dragState:%s | dragResult:%s | interceptorId:%d | dragTargetPid:%d | dragTargetTid:%d | " "cursorStyle:%s | isWindowVisble:%s\n", GetDragState(dragState_).c_str(), - GetDragResult(dragResult_).c_str(), interceptorId_, GetDragTargetPid(), targetTid, + GetDragResult(dragResult_).c_str(), pointerEventInterceptorId_, GetDragTargetPid(), targetTid, GetDragCursorStyle(style).c_str(), DRAG_DATA_MGR.GetDragWindowVisible() ? "true" : "false"); #endif // OHOS_DRAG_ENABLE_INTERCEPTOR #ifdef OHOS_DRAG_ENABLE_MONITOR dprintf(fd, "dragState:%s | dragResult:%s | monitorId:%d | dragTargetPid:%d | dragTargetTid:%d | " "cursorStyle:%s | isWindowVisble:%s\n", GetDragState(dragState_).c_str(), - GetDragResult(dragResult_).c_str(), monitorId_, GetDragTargetPid(), targetTid, + GetDragResult(dragResult_).c_str(), pointerEventMonitorId_, GetDragTargetPid(), targetTid, GetDragCursorStyle(style).c_str(), DRAG_DATA_MGR.GetDragWindowVisible() ? "true" : "false"); #endif // OHOS_DRAG_ENABLE_MONITOR DragData dragData = DRAG_DATA_MGR.GetDragData(); @@ -531,25 +534,90 @@ int32_t DragManager::AddDragEventHandler(int32_t sourceType) return RET_ERR; } #endif // OHOS_DRAG_ENABLE_INTERCEPTOR + if (AddPointerEventHandler(deviceTags) != RET_OK) { + FI_HILOGE("Failed to add pointer event handler"); + return RET_ERR; + } + if (AddKeyEventMointor() != RET_OK) { + FI_HILOGE("Failed to add key event handler"); + return RET_ERR; + } + return RET_OK; +} + +int32_t DragManager::AddPointerEventHandler(uint32_t deviceTags) +{ + CALL_INFO_TRACE; #ifdef OHOS_DRAG_ENABLE_MONITOR auto monitor = std::make_shared(std::bind(&DragManager::DragCallback, this, std::placeholders::_1)); - FI_HILOGI("Add drag event monitor"); - monitorId_ = MMI::InputManager::GetInstance()->AddMonitor(monitor); - if (monitorId_ <= 0) { - FI_HILOGE("Failed to add monitor, error code:%{public}d", monitorId_); + pointerEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor(monitor); + if (pointerEventMonitorId_ <= 0) { + FI_HILOGE("Failed to add pointer event monitor"); return RET_ERR; } #else auto callback = std::bind(&DragManager::DragCallback, this, std::placeholders::_1); auto interceptor = std::make_shared(context_, callback); - FI_HILOGI("Add drag event interceptor"); - interceptorId_ = MMI::InputManager::GetInstance()->AddInterceptor(interceptor, DRAG_PRIORITY, deviceTags); - if (interceptorId_ <= 0) { - FI_HILOGE("Failed to add interceptor, error code:%{public}d", interceptorId_); + pointerEventInterceptorId_ = MMI::InputManager::GetInstance()->AddInterceptor( + interceptor, DRAG_PRIORITY, deviceTags); + if (pointerEventInterceptorId_ <= 0) { + FI_HILOGE("Failed to add pointer event interceptor"); return RET_ERR; } #endif // OHOS_DRAG_ENABLE_MONITOR + FI_HILOGI("Add drag poniter event handle successfully"); + return RET_OK; +} + +int32_t DragManager::AddKeyEventMointor() +{ + CALL_INFO_TRACE; + keyEventMonitorId_ = MMI::InputManager::GetInstance()->AddMonitor( + std::bind(&DragManager::DragKeyEventCallback, this, std::placeholders::_1)); + if (keyEventMonitorId_ <= 0) { + FI_HILOGE("Failed to add key event monitor"); + return RET_ERR; + } + FI_HILOGI("Add drag key event monitor successfully"); + return RET_OK; +} + +int32_t DragManager::RemovePointerEventHandler() +{ + CALL_INFO_TRACE; +#ifdef OHOS_DRAG_ENABLE_MONITOR + if (pointerEventMonitorId_ <= 0) { + FI_HILOGE("Invalid pointer event monitor id:%{public}d", pointerEventMonitorId_); + return RET_ERR; + } + MMI::InputManager::GetInstance()->RemoveMonitor(pointerEventMonitorId_); + pointerEventMonitorId_ = -1; + if (RemoveKeyEventMointor() != RET_OK) { + FI_HILOGE("Failed to remove key event monitor"); + return RET_ERR; + } +#else + if (pointerEventInterceptorId_ <= 0) { + FI_HILOGE("Invalid pointer event interceptor id:%{public}d", pointerEventInterceptorId_); + } + MMI::InputManager::GetInstance()->RemoveInterceptor(pointerEventInterceptorId_); + pointerEventInterceptorId_ = -1; +#endif // OHOS_DRAG_ENABLE_MONITOR + FI_HILOGI("Remove drag pointer event handler successfully"); + return RET_OK; +} + +int32_t DragManager::RemoveKeyEventMointor() +{ + CALL_INFO_TRACE; + if (keyEventMonitorId_ <= 0) { + FI_HILOGE("Invalid key event monitor id:%{public}d", keyEventMonitorId_); + return RET_ERR; + } + MMI::InputManager::GetInstance()->RemoveMonitor(keyEventMonitorId_); + keyEventMonitorId_ = -1; + FI_HILOGI("Remove drag key event handle successfully"); return RET_OK; } @@ -573,11 +641,7 @@ int32_t DragManager::OnStartDrag() MMI::InputManager::GetInstance()->AppendExtraData(extraData); ret = AddDragEventHandler(dragData.sourceType); if (ret != RET_OK) { -#ifdef OHOS_DRAG_ENABLE_MONITOR - FI_HILOGE("Failed to add drag event monitor"); -#else - FI_HILOGE("Failed to add drag event interceptor"); -#endif // OHOS_DRAG_ENABLE_MONITOR + FI_HILOGE("Failed to add drag event handler"); dragDrawing_.DestroyDragWindow(); return RET_ERR; } @@ -592,23 +656,14 @@ int32_t DragManager::OnStopDrag(DragResult result, bool hasCustomAnimation) { CALL_INFO_TRACE; FI_HILOGI("Add custom animation:%{public}s", hasCustomAnimation ? "true" : "false"); -#ifdef OHOS_DRAG_ENABLE_MONITOR - if (monitorId_ <= 0) { - FI_HILOGE("Invalid monitor to be removed, monitorId_:%{public}d", monitorId_); + if (RemovePointerEventHandler() != RET_OK) { + FI_HILOGE("Failed to remove pointer event handler"); return RET_ERR; } - FI_HILOGI("Remove drag event monitor"); - MMI::InputManager::GetInstance()->RemoveMonitor(monitorId_); - monitorId_ = -1; -#else - if (interceptorId_ <= 0) { - FI_HILOGE("Invalid interceptorId_:%{public}d", interceptorId_); + if (RemoveKeyEventMointor() != RET_OK) { + FI_HILOGE("Failed to remove key event handler"); return RET_ERR; } - FI_HILOGI("Remove drag event interceptor"); - MMI::InputManager::GetInstance()->RemoveInterceptor(interceptorId_); - interceptorId_ = -1; -#endif // OHOS_DRAG_ENABLE_MONITOR DragData dragData = DRAG_DATA_MGR.GetDragData(); if ((dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) && !DRAG_DATA_MGR.IsMotionDrag()) { dragDrawing_.EraseMouseIcon(); @@ -756,6 +811,37 @@ void DragManager::MoveTo(int32_t x, int32_t y) FI_HILOGI("displayId:%{public}d, x:%{public}d, y:%{public}d", dragData.displayId, x, y); dragDrawing_.Draw(dragData.displayId, x, y); } + +void DragManager::DragKeyEventCallback(std::shared_ptr keyEvent) +{ + CHKPV(keyEvent); + auto keys = keyEvent->GetKeyItems(); + int32_t keyCode = keyEvent->GetKeyCode(); + int32_t keyAction = keyEvent->GetKeyAction(); + if (keys.size() != SIGNLE_KEY_ITEM) { + dropType_.store(DropType::MOVE); + return; + } + if (keyAction == MMI::KeyEvent::KEY_ACTION_DOWN && ( + keyCode == MMI::KeyEvent::KEYCODE_CTRL_LEFT || + keyCode == MMI::KeyEvent::KEYCODE_CTRL_RIGHT)) { + dropType_.store(DropType::COPY); + FI_HILOGI("the current drop type is copy"); + } else { + dropType_.store(DropType::MOVE); + } +} + +int32_t DragManager::GetDropType(DropType& dropType) const +{ + CALL_DEBUG_ENTER; + if (dragState_ != DragState::START) { + FI_HILOGE("No drag instance running, can not get drag drop type"); + return RET_ERR; + } + dropType = dropType_.load(); + return RET_OK; +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/services/native/include/devicestatus_service.h b/services/native/include/devicestatus_service.h index 894a8ed9b..2b44c5d74 100644 --- a/services/native/include/devicestatus_service.h +++ b/services/native/include/devicestatus_service.h @@ -85,6 +85,7 @@ public: int32_t UpdateShadowPic(const ShadowInfo &shadowInfo) override; int32_t GetDragData(DragData &dragData) override; int32_t GetDragState(DragState &dragState) override; + int32_t GetDropType(DropType& dropType) override; int32_t AllocSocketFd(const std::string &programName, int32_t moduleType, int32_t &toReturnClientFd, int32_t &tokenType) override; void OnConnected(SessionPtr s) override; diff --git a/services/native/src/devicestatus_service.cpp b/services/native/src/devicestatus_service.cpp index e27333ab3..0f3306619 100644 --- a/services/native/src/devicestatus_service.cpp +++ b/services/native/src/devicestatus_service.cpp @@ -827,6 +827,16 @@ int32_t DeviceStatusService::GetDragTargetPid() return ret; } +int32_t DeviceStatusService::GetDropType(DropType& dropType) +{ + int32_t ret = delegateTasks_.PostSyncTask( + std::bind(&DragManager::GetDropType, &dragMgr_, std::ref(dropType))); + if (ret != RET_OK) { + FI_HILOGE("Get drop type failed, ret:%{public}d", ret); + } + return ret; +} + #ifdef OHOS_BUILD_ENABLE_COORDINATION int32_t DeviceStatusService::OnRegisterCoordinationListener(int32_t pid) { From 309b1e6316ae2eedba5ff4befa29b0667382432a Mon Sep 17 00:00:00 2001 From: Science Date: Thu, 9 Nov 2023 06:22:44 +0000 Subject: [PATCH 2/2] update Signed-off-by: Science Change-Id: I9140a5db7a335f3cc5ed0fcb378ddb8ff80b9992 --- frameworks/native/interaction/include/drag_manager_impl.h | 3 --- .../native/interaction/include/interaction_manager_impl.h | 3 --- 2 files changed, 6 deletions(-) diff --git a/frameworks/native/interaction/include/drag_manager_impl.h b/frameworks/native/interaction/include/drag_manager_impl.h index 7cc319f1a..ba37bd92f 100644 --- a/frameworks/native/interaction/include/drag_manager_impl.h +++ b/frameworks/native/interaction/include/drag_manager_impl.h @@ -53,12 +53,9 @@ public: int32_t GetUdKey(std::string &udKey); int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height); int32_t GetDragData(DragData &dragData); -<<<<<<< Updated upstream int32_t GetDragSummary(std::map &summarys); -======= int32_t GetDragState(DragState &dragState); int32_t GetDropType(DropType& dropType); ->>>>>>> Stashed changes private: std::mutex mtx_; diff --git a/frameworks/native/interaction/include/interaction_manager_impl.h b/frameworks/native/interaction/include/interaction_manager_impl.h index ef262b80e..bef2e3663 100644 --- a/frameworks/native/interaction/include/interaction_manager_impl.h +++ b/frameworks/native/interaction/include/interaction_manager_impl.h @@ -57,11 +57,8 @@ public: int32_t GetDragState(DragState &dragState); int32_t AddHotAreaListener(std::shared_ptr listener); int32_t RemoveHotAreaListener(std::shared_ptr listener = nullptr); -<<<<<<< Updated upstream int32_t GetDragSummary(std::map &summarys); -======= int32_t GetDropType(DropType &dropType); ->>>>>>> Stashed changes private: void InitMsgHandler();