From 3232e0407bbf2b735da51c3c23ba52928a3c173a Mon Sep 17 00:00:00 2001 From: q30043944 Date: Sun, 8 Jun 2025 14:12:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=B9=E6=A1=86=E9=94=80?= =?UTF-8?q?=E6=AF=81=E6=85=A2=E5=8F=8A=E5=9B=9E=E8=B0=83=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E4=B8=8D=E5=8F=8A=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: q30043944 --- .../include/device_manager_service_impl.h | 5 +++ .../src/device_manager_service_impl.cpp | 38 +++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index e7adc930d..8849dd626 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -295,6 +295,11 @@ private: int32_t InitNewProtocolAuthMgr(bool isSrcSide, uint64_t tokenId, uint64_t logicalSessionId, const std::string &pkgName); int32_t InitOldProtocolAuthMgr(uint64_t tokenId, const std::string &pkgName); + bool ParseConnectAddrAndSetProcessInfo(const PeerTargetId &targetId, + PeerTargetId &targetIdTmp, const std::map &bindParam, ProcessInfo &processInfo, + const std::string &pkgName); + void OnAuthResultAndOnBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, + const std::string &deviceId, int32_t reason); private: std::shared_ptr authMgr_; // Old protocol only diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 8eb9f4f7a..236880e52 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -65,6 +65,7 @@ constexpr const char* DM_TAG_PEER_DISPLAY_ID = "peerDisplayId"; constexpr const char* DM_TAG_ACCESSEE_USER_ID = "accesseeUserId"; constexpr const char* DM_TAG_EXTRA_INFO = "extraInfo"; constexpr const char* CHANGE_PINTYPE = "1"; +constexpr const char* BIND_CALLER_USERID = "bindCallerUserId"; // currently, we just support one bind session in one device at same time constexpr size_t MAX_NEW_PROC_SESSION_COUNT_TEMP = 1; const int32_t USLEEP_TIME_US_500000 = 500000; // 500ms @@ -1731,23 +1732,48 @@ void DeviceManagerServiceImpl::SaveTokenIdAndSessionId(uint64_t &tokenId, } } -void DeviceManagerServiceImpl::BindTargetImpl(uint64_t tokenId, const std::string &pkgName, - const PeerTargetId &targetId, const std::map &bindParam) +bool DeviceManagerServiceImpl::ParseConnectAddrAndSetProcessInfo(const PeerTargetId &targetId, + PeerTargetId &targetIdTmp, const std::map &bindParam, ProcessInfo &processInfo, + const std::string &pkgName) { + processInfo.pkgName = pkgName; + if (bindParam.count(BIND_CALLER_USERID) != 0) { + processInfo.userId = std::atoi(bindParam.at(BIND_CALLER_USERID).c_str()); + } std::string deviceId = ""; - PeerTargetId targetIdTmp = const_cast(targetId); if (ParseConnectAddr(targetId, deviceId, bindParam) == DM_OK) { targetIdTmp.deviceId = deviceId; } else { if (targetId.deviceId.empty()) { LOGE("DeviceManagerServiceImpl::BindTarget failed, ParseConnectAddr failed."); - return; + OnAuthResultAndOnBindResult(processInfo, targetId, targetId.deviceId, ERR_DM_INPUT_PARA_INVALID); + return false; } } + return true; +} + +void DeviceManagerServiceImpl::OnAuthResultAndOnBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, + const std::string &deviceId, int32_t reason) +{ + CHECK_NULL_VOID(listener_); + listener_->OnAuthResult(processInfo, deviceId, "", DmAuthStatus::STATUS_DM_AUTH_DEFAULT, reason); + listener_->OnBindResult(processInfo, targetId, reason, DmAuthStatus::STATUS_DM_AUTH_DEFAULT, ""); +} + +void DeviceManagerServiceImpl::BindTargetImpl(uint64_t tokenId, const std::string &pkgName, + const PeerTargetId &targetId, const std::map &bindParam) +{ + PeerTargetId targetIdTmp = const_cast(targetId); + ProcessInfo processInfo; + if (!ParseConnectAddrAndSetProcessInfo(targetId, targetIdTmp, bindParam, processInfo, pkgName)) { + return; + } // Created only at the source end. The same target device will not be created repeatedly with the new protocol. std::shared_ptr curSession = GetOrCreateSession(targetIdTmp.deviceId, bindParam); if (curSession == nullptr) { LOGE("Failed to create the session. Target deviceId: %{public}s.", targetIdTmp.deviceId.c_str()); + OnAuthResultAndOnBindResult(processInfo, targetId, targetIdTmp.deviceId, ERR_DM_TIME_OUT); return; } @@ -1759,6 +1785,7 @@ void DeviceManagerServiceImpl::BindTargetImpl(uint64_t tokenId, const std::strin if (curSession->logicalSessionSet_.find(logicalSessionId) != curSession->logicalSessionSet_.end()) { LOGE("Failed to create the logical session."); softbusConnector_->GetSoftbusSession()->CloseAuthSession(sessionId); + OnAuthResultAndOnBindResult(processInfo, targetId, targetIdTmp.deviceId, ERR_DM_INPUT_PARA_INVALID); return; } } @@ -1768,6 +1795,7 @@ void DeviceManagerServiceImpl::BindTargetImpl(uint64_t tokenId, const std::strin if (ret != DM_OK) { LOGE("InitAndRegisterAuthMgr failed, ret %{public}d.", ret); softbusConnector_->GetSoftbusSession()->CloseAuthSession(sessionId); + OnAuthResultAndOnBindResult(processInfo, targetId, targetIdTmp.deviceId, ret); return; } curSession->logicalSessionSet_.insert(logicalSessionId); @@ -1776,12 +1804,14 @@ void DeviceManagerServiceImpl::BindTargetImpl(uint64_t tokenId, const std::strin auto authMgr = GetAuthMgrByTokenId(tokenId); if (authMgr == nullptr) { CleanAuthMgrByLogicalSessionId(logicalSessionId); + OnAuthResultAndOnBindResult(processInfo, targetId, targetIdTmp.deviceId, ERR_DM_POINT_NULL); return; } authMgr->SetBindTargetParams(targetId); if ((ret = authMgr->BindTarget(pkgName, targetIdTmp, bindParam, sessionId, logicalSessionId)) != DM_OK) { LOGE("authMgr BindTarget failed, ret %{public}d.", ret); CleanAuthMgrByLogicalSessionId(logicalSessionId); + OnAuthResultAndOnBindResult(processInfo, targetId, targetIdTmp.deviceId, ret); } LOGI("end, tokenId %{public}" PRId64".", tokenId); return; -- Gitee