diff --git a/frameworks/native/interaction/include/drag_manager_impl.h b/frameworks/native/interaction/include/drag_manager_impl.h index 472e9c047534925f53c63347aeb133086a08e93b..c480647dcb43303f1b50bc8c7f4124f3d18930d5 100644 --- a/frameworks/native/interaction/include/drag_manager_impl.h +++ b/frameworks/native/interaction/include/drag_manager_impl.h @@ -36,6 +36,8 @@ public: ~DragManagerImpl() = default; int32_t UpdateDragStyle(DragCursorStyle style); int32_t GetDragTargetPid(); + int32_t GetUdKey(std::string &udKey); + int32_t StartDrag(const DragData &dragData, std::function callback); int32_t StopDrag(DragResult result, bool hasCustomAnimation); int32_t OnNotifyResult(const StreamClient& client, NetPacket& pkt); diff --git a/frameworks/native/interaction/include/interaction_manager_impl.h b/frameworks/native/interaction/include/interaction_manager_impl.h index 28a17cb67cf6f02a1f28d15c2ebd15df5589e2c1..9cff01bbd78e1dc539cc9d530a7edbb987b35215 100644 --- a/frameworks/native/interaction/include/interaction_manager_impl.h +++ b/frameworks/native/interaction/include/interaction_manager_impl.h @@ -44,6 +44,7 @@ public: int32_t StartDrag(const DragData &dragData, std::function callback); int32_t StopDrag(DragResult result, bool hasCustomAnimation); int32_t GetDragTargetPid(); + int32_t GetUdKey(std::string &udKey); int32_t AddDraglistener(DragListenerPtr listener); int32_t RemoveDraglistener(DragListenerPtr listener); int32_t SetDragWindowVisible(bool visible); diff --git a/frameworks/native/interaction/src/drag_manager_impl.cpp b/frameworks/native/interaction/src/drag_manager_impl.cpp index 997f4a12181ff5de291d96cb054184ed153461a2..9f992aa6df679f87afd6a7e8f6661273ced651c9 100644 --- a/frameworks/native/interaction/src/drag_manager_impl.cpp +++ b/frameworks/native/interaction/src/drag_manager_impl.cpp @@ -74,6 +74,12 @@ int32_t DragManagerImpl::GetDragTargetPid() return DeviceStatusClient::GetInstance().GetDragTargetPid(); } +int32_t DragManagerImpl::GetUdKey(std::string &udKey) +{ + CALL_DEBUG_ENTER; + return DeviceStatusClient::GetInstance().GetUdKey(udKey); +} + int32_t DragManagerImpl::OnNotifyResult(const StreamClient& client, NetPacket& pkt) { CALL_DEBUG_ENTER; diff --git a/frameworks/native/interaction/src/interaction_manager.cpp b/frameworks/native/interaction/src/interaction_manager.cpp index 03fc1fbeb88064bce23a537bbf2912b3b3baf163..90e88658aa582a9cbb1846517443f464fd08978c 100644 --- a/frameworks/native/interaction/src/interaction_manager.cpp +++ b/frameworks/native/interaction/src/interaction_manager.cpp @@ -85,6 +85,11 @@ int32_t InteractionManager::GetDragTargetPid() return InteractionMgrImpl.GetDragTargetPid(); } +int32_t InteractionManager::GetUdKey(std::string &udKey) +{ + return InteractionMgrImpl.GetUdKey(udKey); +} + int32_t InteractionManager::AddDraglistener(DragListenerPtr listener) { return InteractionMgrImpl.AddDraglistener(listener); diff --git a/frameworks/native/interaction/src/interaction_manager_impl.cpp b/frameworks/native/interaction/src/interaction_manager_impl.cpp index 3aa167716fb35ffa9a7d62ec533551074c6c778e..c15ea58d50cff13a81d4b86c083b788111a90e6e 100644 --- a/frameworks/native/interaction/src/interaction_manager_impl.cpp +++ b/frameworks/native/interaction/src/interaction_manager_impl.cpp @@ -209,6 +209,12 @@ int32_t InteractionManagerImpl::GetDragTargetPid() return dragManagerImpl_.GetDragTargetPid(); } +int32_t InteractionManagerImpl::GetUdKey(std::string &udKey) +{ + CALL_DEBUG_ENTER; + return dragManagerImpl_.GetUdKey(udKey); +} + int32_t InteractionManagerImpl::AddDraglistener(DragListenerPtr listener) { CALL_DEBUG_ENTER; diff --git a/frameworks/native/src/devicestatus_client.cpp b/frameworks/native/src/devicestatus_client.cpp index 4d16b62a81d9840b46f4fc1bb9c6b952ef3935f0..10b47ebd88ae0e1c12c88c896736c6bbdd4bff17 100644 --- a/frameworks/native/src/devicestatus_client.cpp +++ b/frameworks/native/src/devicestatus_client.cpp @@ -246,6 +246,16 @@ int32_t DeviceStatusClient::GetDragTargetPid() return devicestatusProxy_->GetDragTargetPid(); } +int32_t DeviceStatusClient::GetUdKey(std::string &udKey) +{ + CALL_DEBUG_ENTER; + if (devicestatusProxy_ == nullptr) { + DEV_HILOGE(SERVICE, "devicestatusProxy_ is nullptr"); + return RET_ERR; + } + return devicestatusProxy_->GetUdKey(udKey); +} + int32_t DeviceStatusClient::AllocSocketPair(const int32_t moduleType) { CALL_DEBUG_ENTER; diff --git a/interfaces/innerkits/include/devicestatus_client.h b/interfaces/innerkits/include/devicestatus_client.h index 57542a662e79f102296617c082f18ae01dbf289e..1dd0d0753ba35b84c9ab35dc3e346d6ec62c1353 100644 --- a/interfaces/innerkits/include/devicestatus_client.h +++ b/interfaces/innerkits/include/devicestatus_client.h @@ -58,6 +58,8 @@ public: int32_t StopDrag(DragResult result, bool hasCustomAnimation); int32_t UpdateDragStyle(DragCursorStyle style); int32_t GetDragTargetPid(); + int32_t GetUdKey(std::string &udKey); + int32_t AddDraglistener(); int32_t RemoveDraglistener(); int32_t SetDragWindowVisible(bool visible); diff --git a/interfaces/innerkits/interaction/include/drag_data.h b/interfaces/innerkits/interaction/include/drag_data.h index 08812b1161529fc5fd612f661aaa36624620f164..51627a664c9f3ff3e6205f48d91db25f311dbe59 100644 --- a/interfaces/innerkits/interaction/include/drag_data.h +++ b/interfaces/innerkits/interaction/include/drag_data.h @@ -37,6 +37,7 @@ struct ShadowInfo { struct DragData { ShadowInfo shadowInfo; std::vector buffer; + std::string udKey; int32_t sourceType { -1 }; int32_t dragNum { -1 }; int32_t pointerId { -1 }; diff --git a/interfaces/innerkits/interaction/include/interaction_manager.h b/interfaces/innerkits/interaction/include/interaction_manager.h index b7daaa7c5ef70b4e17b18b54799bae08c77c930f..ee97804e0d334243a78a67c408fd90ffddc8e8fc 100644 --- a/interfaces/innerkits/interaction/include/interaction_manager.h +++ b/interfaces/innerkits/interaction/include/interaction_manager.h @@ -121,6 +121,14 @@ public: */ int32_t GetDragTargetPid(); + /** + * @brief 获取拖拽目标窗口UdKey + * @param UdKey 拖拽目标窗口统一数据密钥。 + * @return 返回值如果是-1则是无效值,为大于等于0的值为正确值 + * @since 10 + */ + int32_t GetUdKey(std::string &udKey); + /** * @brief 注册拖拽状态监听。。 * @param listener 拖拽状态监听。 diff --git a/services/communication/base/idevicestatus.h b/services/communication/base/idevicestatus.h index 35cf08f6266b28740e218797247ad40261c5ca43..76cc7fdebbf5c951582df99fd16ea0f046b643df 100644 --- a/services/communication/base/idevicestatus.h +++ b/services/communication/base/idevicestatus.h @@ -42,6 +42,7 @@ public: START_DRAG, STOP_DRAG, GET_DRAG_TARGET_PID, + GET_DRAG_TARGET_UDKEY, REGISTER_DRAG_MONITOR, UNREGISTER_DRAG_MONITOR, SET_DRAG_WINDOW_VISIBLE, @@ -69,6 +70,7 @@ public: virtual int32_t StopDrag(DragResult result, bool hasCustomAnimation) = 0; virtual int32_t UpdateDragStyle(DragCursorStyle style) = 0; virtual int32_t GetDragTargetPid() = 0; + virtual int32_t GetUdKey(std::string &udKey) = 0; virtual int32_t AddDraglistener() = 0; virtual int32_t RemoveDraglistener() = 0; virtual int32_t AllocSocketFd(const std::string &programName, const int32_t moduleType, diff --git a/services/communication/client/include/devicestatus_srv_proxy.h b/services/communication/client/include/devicestatus_srv_proxy.h index 7b90e7991b033640c2161b9ee9c3b19ad43e0de9..75995e97df6a661e5b5d8b2205051bbbca14b1f3 100644 --- a/services/communication/client/include/devicestatus_srv_proxy.h +++ b/services/communication/client/include/devicestatus_srv_proxy.h @@ -52,6 +52,7 @@ public: virtual int32_t StopDrag(DragResult result, bool hasCustomAnimation) override; virtual int32_t UpdateDragStyle(DragCursorStyle style) override; virtual int32_t GetDragTargetPid() override; + virtual int32_t GetUdKey(std::string &udKey) override; virtual int32_t AddDraglistener() override; virtual int32_t RemoveDraglistener() override; virtual int32_t SetDragWindowVisible(bool visible) override; diff --git a/services/communication/client/src/devicestatus_srv_proxy.cpp b/services/communication/client/src/devicestatus_srv_proxy.cpp index 8b0f7ddf887cdb93e5d93b276504e2b6e982130d..9150105d07b884c53c5200c52ec6220902c01e07 100644 --- a/services/communication/client/src/devicestatus_srv_proxy.cpp +++ b/services/communication/client/src/devicestatus_srv_proxy.cpp @@ -273,6 +273,27 @@ int32_t DeviceStatusSrvProxy::GetDragTargetPid() return pid; } +int32_t DeviceStatusSrvProxy::GetUdKey(std::string &udKey) +{ + 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(GET_DRAG_TARGET_UDKEY, data, reply, option); + if (ret != RET_OK) { + FI_HILOGE("Send request fail, ret:%{public}d", ret); + return RET_ERR; + } + READSTRING(reply, udKey, IPC_PROXY_DEAD_OBJECT_ERR); + return RET_OK; +} + int32_t DeviceStatusSrvProxy::GetCoordinationState(int32_t userData, const std::string &deviceId) { CALL_DEBUG_ENTER; @@ -310,6 +331,7 @@ int32_t DeviceStatusSrvProxy::StartDrag(const DragData &dragData) WRITEINT32(data, dragData.shadowInfo.x, ERR_INVALID_VALUE); WRITEINT32(data, dragData.shadowInfo.y, ERR_INVALID_VALUE); WRITEUINT8VECTOR(data, dragData.buffer, ERR_INVALID_VALUE); + WRITESTRING(data, dragData.udKey, ERR_INVALID_VALUE); WRITEINT32(data, dragData.sourceType, ERR_INVALID_VALUE); WRITEINT32(data, dragData.dragNum, ERR_INVALID_VALUE); WRITEINT32(data, dragData.pointerId, ERR_INVALID_VALUE); diff --git a/services/communication/service/include/devicestatus_srv_stub.h b/services/communication/service/include/devicestatus_srv_stub.h index 0a82ac1ccbc729c8d6c2d4656b5b8c505f0a7995..4ee68693b04721d7845f83c48d75177b3e22e6ae 100644 --- a/services/communication/service/include/devicestatus_srv_stub.h +++ b/services/communication/service/include/devicestatus_srv_stub.h @@ -50,6 +50,7 @@ private: int32_t StopDragStub(MessageParcel& data, MessageParcel& reply); int32_t UpdateDragStyleStub(MessageParcel& data, MessageParcel& reply); int32_t GetDragTargetPidStub(MessageParcel& data, MessageParcel& reply); + int32_t GetUdKeyStub(MessageParcel& data, MessageParcel& reply); int32_t AddDraglistenerStub(MessageParcel& data, MessageParcel& reply); int32_t RemoveDraglistenerStub(MessageParcel& data, MessageParcel& reply); int32_t SetDragWindowVisibleStub(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 a218283cbf2ed7143dfa89c8523b31eb3e8314bb..bfd66b0ad9044d15eced1e6d448075e3b8199ed9 100644 --- a/services/communication/service/src/devicestatus_srv_stub.cpp +++ b/services/communication/service/src/devicestatus_srv_stub.cpp @@ -61,6 +61,7 @@ int32_t DeviceStatusSrvStub::OnRemoteRequest(uint32_t code, MessageParcel &data, {Idevicestatus::STOP_DRAG, &DeviceStatusSrvStub::StopDragStub}, {Idevicestatus::UPDATED_DRAG_STYLE, &DeviceStatusSrvStub::UpdateDragStyleStub}, {Idevicestatus::GET_DRAG_TARGET_PID, &DeviceStatusSrvStub::GetDragTargetPidStub}, + {Idevicestatus::GET_DRAG_TARGET_UDKEY, &DeviceStatusSrvStub::GetUdKeyStub}, {Idevicestatus::REGISTER_DRAG_MONITOR, &DeviceStatusSrvStub::AddDraglistenerStub}, {Idevicestatus::UNREGISTER_DRAG_MONITOR, &DeviceStatusSrvStub::RemoveDraglistenerStub}, {Idevicestatus::SET_DRAG_WINDOW_VISIBLE, &DeviceStatusSrvStub::SetDragWindowVisibleStub}, @@ -223,6 +224,19 @@ int32_t DeviceStatusSrvStub::GetDragTargetPidStub(MessageParcel& data, MessagePa return RET_OK; } +int32_t DeviceStatusSrvStub::GetUdKeyStub(MessageParcel& data, MessageParcel& reply) +{ + CALL_DEBUG_ENTER; + std::string udKey; + int32_t ret = GetUdKey(udKey); + if (ret != RET_OK) { + FI_HILOGE("Get udKey failed ret:%{public}d", ret); + } + WRITESTRING(reply, udKey, IPC_STUB_WRITE_PARCEL_ERR); + FI_HILOGD("Target udKey:%{public}s", udKey.c_str()); + return RET_OK; +} + int32_t DeviceStatusSrvStub::HandleAllocSocketFdStub(MessageParcel& data, MessageParcel& reply) { int32_t pid = GetCallingPid(); @@ -275,6 +289,7 @@ int32_t DeviceStatusSrvStub::StartDragStub(MessageParcel& data, MessageParcel& r READINT32(data, dragData.shadowInfo.x, E_DEVICESTATUS_READ_PARCEL_ERROR); READINT32(data, dragData.shadowInfo.y, E_DEVICESTATUS_READ_PARCEL_ERROR); READUINT8VECTOR(data, dragData.buffer, E_DEVICESTATUS_READ_PARCEL_ERROR); + READSTRING(data, dragData.udKey, E_DEVICESTATUS_READ_PARCEL_ERROR); READINT32(data, dragData.sourceType, E_DEVICESTATUS_READ_PARCEL_ERROR); READINT32(data, dragData.dragNum, E_DEVICESTATUS_READ_PARCEL_ERROR); READINT32(data, dragData.pointerId, E_DEVICESTATUS_READ_PARCEL_ERROR); diff --git a/services/interaction/drag/BUILD.gn b/services/interaction/drag/BUILD.gn index 747511a7ceee4f62b9cd52bcd725204e4923eefa..8beeb1c036cf9b9d1f9db478f79fa829d61353ab 100644 --- a/services/interaction/drag/BUILD.gn +++ b/services/interaction/drag/BUILD.gn @@ -59,6 +59,10 @@ ohos_shared_library("interaction_drag") { "window_manager:libwm", ] + if (fusion_interaction_coordination) { + external_deps += [ "udmf:udmf_client" ] + } + subsystem_name = "msdp" part_name = "${device_status_part_name}" } diff --git a/services/interaction/drag/include/drag_data_adapter.h b/services/interaction/drag/include/drag_data_adapter.h index 1015f05fe6bb676f089e2cd6ca70998da20302de..44596d0862e540464d42aad10b0b544dbbccdec0 100644 --- a/services/interaction/drag/include/drag_data_adapter.h +++ b/services/interaction/drag/include/drag_data_adapter.h @@ -41,6 +41,7 @@ public: void SetDragWindowVisible(bool visible); bool GetDragWindowVisible() const; int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height) const; + void ResetDragData(); private: DragData dragData_; diff --git a/services/interaction/drag/include/drag_manager.h b/services/interaction/drag/include/drag_manager.h index d6f5189b1d87a3d518c7bc79f2e58c790391a3e2..798d3ae736d34e207c379e5df1a90f79f5027222 100644 --- a/services/interaction/drag/include/drag_manager.h +++ b/services/interaction/drag/include/drag_manager.h @@ -47,7 +47,9 @@ public: int32_t StartDrag(const DragData &dragData, SessionPtr sess); int32_t StopDrag(DragResult result, bool hasCustomAnimation); int32_t GetDragTargetPid() const; + int32_t GetUdKey(std::string &udKey); void SetDragTargetPid(int32_t dragTargetPid); + void SendDragData(int32_t targetPid, const std::string &udKey); int32_t UpdateDragStyle(DragCursorStyle style); void DragCallback(std::shared_ptr pointerEvent); void OnDragUp(std::shared_ptr pointerEvent); diff --git a/services/interaction/drag/src/drag_data_adapter.cpp b/services/interaction/drag/src/drag_data_adapter.cpp index 75ab638b7c657940c4b6f56f671a0ea7a6d9945c..f39ec045fa53777de84402b34c1ed00a696a9458 100644 --- a/services/interaction/drag/src/drag_data_adapter.cpp +++ b/services/interaction/drag/src/drag_data_adapter.cpp @@ -81,6 +81,14 @@ int32_t DragDataAdapter::GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int offsetX, offsetY, width, height); return RET_OK; } + +void DragDataAdapter::ResetDragData() +{ + CALL_DEBUG_ENTER; + ShadowInfo shadowInfo; + std::vector buffer; + dragData_ = { shadowInfo, buffer, "", -1, -1, -1, -1, -1, -1, false }; +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS \ No newline at end of file diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index bfd87f5806e1186e4970a3b7213f6ff68d238250..db76c91856fe353bf18cb11dafd42ae585c57ef9 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -27,12 +27,17 @@ #include "fi_log.h" #include "proto.h" +#ifdef OHOS_BUILD_ENABLE_COORDINATION +#include "udmf_client.h" +#include "unified_types.h" +#endif // OHOS_BUILD_ENABLE_COORDINATION + namespace OHOS { namespace Msdp { namespace DeviceStatus { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DragManager" }; -constexpr int32_t TIMEOUT_MS = 1000; +constexpr int32_t TIMEOUT_MS = 2000; constexpr int32_t DRAG_PRIORITY = 500; } // namespace @@ -113,6 +118,7 @@ int32_t DragManager::StopDrag(DragResult result, bool hasCustomAnimation) } dragState_ = DragMessage::MSG_DRAG_STATE_STOP; stateNotify_.StateChangedNotify(DragMessage::MSG_DRAG_STATE_STOP); + DataAdapter.ResetDragData(); if (NotifyDragResult(result) != RET_OK) { FI_HILOGE("NotifyDragResult failed"); return RET_ERR; @@ -125,6 +131,18 @@ int32_t DragManager::GetDragTargetPid() const return dragTargetPid_; } +int32_t DragManager::GetUdKey(std::string &udKey) +{ + CALL_DEBUG_ENTER; + DragData dragData = DataAdapter.GetDragData(); + if (dragData.udKey.empty()) { + FI_HILOGE("Target udKey is empty"); + return RET_ERR; + } + udKey = dragData.udKey; + return RET_OK; +} + void DragManager::SetDragTargetPid(int32_t dragTargetPid) { CALL_DEBUG_ENTER; @@ -194,6 +212,25 @@ void DragManager::OnDragMove(std::shared_ptr pointerEvent) dragDrawing_.Draw(pointerEvent->GetTargetDisplayId(), pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); } +void DragManager::SendDragData(int32_t targetPid, const std::string &udKey) +{ + CALL_DEBUG_ENTER; +#ifdef OHOS_BUILD_ENABLE_COORDINATION + UDMF::QueryOption option; + option.key = udKey; + UDMF::Privilege privilege; + privilege.pid = targetPid; + FI_HILOGD("AddPrivilege enter"); + int32_t ret = UDMF::UdmfClient::GetInstance().AddPrivilege(option, privilege); + if (ret != RET_OK) { + FI_HILOGE("Failed to send pid to Udmf client"); + } +#else + (void)(targetPid); + (void)(udKey); +#endif // OHOS_BUILD_ENABLE_COORDINATION +} + void DragManager::OnDragUp(std::shared_ptr pointerEvent) { CALL_DEBUG_ENTER; @@ -210,6 +247,8 @@ void DragManager::OnDragUp(std::shared_ptr pointerEvent) dragDrawing_.EraseMouseIcon(); INPUT_MANAGER->SetPointerVisible(true); } + + SendDragData(pid, dragData.udKey); CHKPV(context_); context_->GetTimerManager().AddTimer(TIMEOUT_MS, 1, [this]() { this->StopDrag(DragResult::DRAG_EXCEPTION, false); diff --git a/services/native/include/devicestatus_service.h b/services/native/include/devicestatus_service.h index a13947ab1d76515365c5c3bee484dba28c1d146f..c0b8a414a562dedf111b8a367444b4c7f20b0235 100644 --- a/services/native/include/devicestatus_service.h +++ b/services/native/include/devicestatus_service.h @@ -76,6 +76,7 @@ public: int32_t StopDrag(DragResult result, bool hasCustomAnimation) override; int32_t UpdateDragStyle(DragCursorStyle style) override; int32_t GetDragTargetPid() override; + int32_t GetUdKey(std::string &udKey) override; int32_t AddDraglistener() override; int32_t RemoveDraglistener() override; int32_t SetDragWindowVisible(bool visible) override; diff --git a/services/native/src/devicestatus_service.cpp b/services/native/src/devicestatus_service.cpp index 4975ecf6f745a1b38c261f0e3ab702eb7e3f33a1..9527ad58301ed92d84e6b4b2ba44838ad83c0eea 100644 --- a/services/native/src/devicestatus_service.cpp +++ b/services/native/src/devicestatus_service.cpp @@ -757,10 +757,26 @@ int32_t DeviceStatusService::UpdateDragStyle(DragCursorStyle style) return ret; } +int32_t DeviceStatusService::GetUdKey(std::string &udKey) +{ + CALL_DEBUG_ENTER; + int32_t ret = delegateTasks_.PostSyncTask( + std::bind(&DragManager::GetUdKey, &dragMgr_, std::ref(udKey))); + if (ret != RET_OK) { + FI_HILOGE("GetUdKey failed, ret:%{public}d", ret); + } + return ret; +} + int32_t DeviceStatusService::GetDragTargetPid() { CALL_DEBUG_ENTER; - return dragMgr_.GetDragTargetPid(); + int32_t ret = delegateTasks_.PostSyncTask( + std::bind(&DragManager::GetDragTargetPid, &dragMgr_)); + if (ret == RET_ERR) { + FI_HILOGE("GetDragTargetPid failed, ret:%{public}d", ret); + } + return ret; } #ifdef OHOS_BUILD_ENABLE_COORDINATION