From d3749d7a2fd86a74360aaf1c0c5750f5cfdc85d1 Mon Sep 17 00:00:00 2001 From: s30044129 Date: Wed, 10 Sep 2025 10:52:59 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E8=A7=A3=E7=BB=91=E4=B8=8B=E7=BA=BF?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30044129 --- .../include/deviceprofile_connector.h | 7 +- .../src/deviceprofile_connector.cpp | 72 ++++++++++++------- .../include/device_manager_service_impl.h | 5 +- .../device_manager_service_impl_lite.h | 2 +- .../src/device_manager_service_impl.cpp | 58 +++++++++++---- .../service/include/device_manager_service.h | 2 +- .../include/idevice_manager_service_impl.h | 2 +- .../service/src/device_manager_service.cpp | 11 +-- .../src/device_manager_service_listener.cpp | 10 ++- .../relationship_sync_mgr.cpp | 23 ++++-- .../UTTest_dm_deviceprofile_connector.cpp | 12 ++-- .../UTTest_device_manager_service.cpp | 4 +- .../UTTest_device_manager_service_impl.cpp | 8 +-- .../mock/deviceprofile_connector_mock.cpp | 4 +- .../mock/deviceprofile_connector_mock.h | 5 +- 15 files changed, 155 insertions(+), 70 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 1cd88b8d1..3fd900e4f 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -104,6 +104,7 @@ typedef struct DmAclIdParam { int64_t accessControlId; int32_t skId; std::string credId; + std::string pkgName; } DmAclIdParam; typedef struct DmOfflineParam { @@ -114,6 +115,7 @@ typedef struct DmOfflineParam { int32_t leftAclNumber; int32_t peerUserId; bool hasLnnAcl = false; + bool targetAclHasUserLevel = false; int64_t accessControlId; // save the need unbind acl info std::vector needDelAclInfos; @@ -224,7 +226,7 @@ public: const std::string &remoteUdid, const std::string &localUdid); DM_EXPORT int32_t HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, - const std::string &localUdid, DmOfflineParam &offlineParam); + const std::string &localUdid, DmOfflineParam &offlineParam, int32_t tokenId); DM_EXPORT DmOfflineParam HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid); DM_EXPORT DmOfflineParam HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, @@ -374,7 +376,8 @@ private: void UpdatePeerUserId(DistributedDeviceProfile::AccessControlProfile profile, std::string &localUdid, const std::vector &localUserIds, const std::string &remoteUdid, const std::vector &remoteFrontUserIds); - void SetProcessInfoPkgName(const DistributedDeviceProfile::AccessControlProfile &acl, ProcessInfo &processInfo); + void SetProcessInfoPkgName(const DistributedDeviceProfile::AccessControlProfile &acl, + std::vector &processInfoVec, bool isAccer); bool CheckAclStatusNotMatch(const DistributedDeviceProfile::AccessControlProfile &profile, const std::string &localUdid, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 49ec04f9f..4cc508b59 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -443,6 +443,8 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces if ((acerTokenId == static_cast(localTokenId)) && (acerDeviceId == localUdid) && (aceeDeviceId == remoteUdid) && (peerTokenId == 0 || (peerTokenId != 0 && aceeTokenId == static_cast(peerTokenId)))) { + offlineParam.targetAclHasUserLevel = + (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName(); processInfo.userId = acl.GetAccesser().GetAccesserUserId(); @@ -458,6 +460,8 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces if ((aceeTokenId == static_cast(localTokenId)) && (aceeDeviceId == localUdid) && (acerDeviceId == remoteUdid) && (peerTokenId == 0 || (peerTokenId != 0 && acerTokenId == static_cast(peerTokenId)))) { + offlineParam.targetAclHasUserLevel = + (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccessee().GetAccesseeBundleName(); processInfo.userId = acl.GetAccessee().GetAccesseeUserId(); @@ -1224,10 +1228,7 @@ DM_EXPORT bool DeviceProfileConnector::DeleteAclForAccountLogOut( accesseeUdid == info.peerUdid && accesseeUserId == info.peerUserId && accesserAccountId == accountId) { offlineParam.bindType = item.GetBindType(); - ProcessInfo processInfo; - SetProcessInfoPkgName(item, processInfo); - processInfo.userId = item.GetAccesser().GetAccesserUserId(); - offlineParam.processVec.emplace_back(processInfo); + SetProcessInfoPkgName(item, offlineParam.processVec, true); notifyOffline = (item.GetStatus() == ACTIVE); CacheAcerAclId(item, offlineParam.needDelAclInfos); continue; @@ -1236,10 +1237,7 @@ DM_EXPORT bool DeviceProfileConnector::DeleteAclForAccountLogOut( accesseeUdid == info.localUdid && accesseeUserId == info.localUserId && accesseeAccountId == accountId) { offlineParam.bindType = item.GetBindType(); - ProcessInfo processInfo; - SetProcessInfoPkgName(item, processInfo); - processInfo.userId = item.GetAccessee().GetAccesseeUserId(); - offlineParam.processVec.emplace_back(processInfo); + SetProcessInfoPkgName(item, offlineParam.processVec, false); notifyOffline = (item.GetStatus() == ACTIVE); CacheAceeAclId(item, offlineParam.needDelAclInfos); continue; @@ -1288,10 +1286,7 @@ void DeviceProfileConnector::CacheOfflineParam(const DistributedDeviceProfile::A accesseeUdid == info.peerUdid && accesseeUserId == info.peerUserId && std::string(accesseeAccountIdHash) == accountIdHash) { offlineParam.bindType = profile.GetBindType(); - ProcessInfo processInfo; - SetProcessInfoPkgName(profile, processInfo); - processInfo.userId = profile.GetAccesser().GetAccesserUserId(); - offlineParam.processVec.emplace_back(processInfo); + SetProcessInfoPkgName(item, offlineParam.processVec, true); notifyOffline = (profile.GetStatus() == ACTIVE); CacheAcerAclId(profile, offlineParam.needDelAclInfos); return; @@ -1300,10 +1295,7 @@ void DeviceProfileConnector::CacheOfflineParam(const DistributedDeviceProfile::A accesseeUdid == info.localUdid && accesseeUserId == info.localUserId && std::string(accesserAccountIdHash) == accountIdHash) { offlineParam.bindType = profile.GetBindType(); - ProcessInfo processInfo; - SetProcessInfoPkgName(profile, processInfo); - processInfo.userId = profile.GetAccessee().GetAccesseeUserId(); - offlineParam.processVec.emplace_back(processInfo); + SetProcessInfoPkgName(item, offlineParam.processVec, false); notifyOffline = (profile.GetStatus() == ACTIVE); CacheAceeAclId(profile, offlineParam.needDelAclInfos); return; @@ -2096,10 +2088,10 @@ int32_t DeviceProfileConnector::HandleAccountLogoutEvent(int32_t remoteUserId, DM_EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, - const std::string &localUdid, DmOfflineParam &offlineParam) + const std::string &localUdid, DmOfflineParam &offlineParam, int32_t tokenId) { - LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, localUdid %{public}s.", remoteUserId, - GetAnonyString(remoteUdid).c_str(), GetAnonyString(localUdid).c_str()); + LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, localUdid %{public}s, tokenId %{public}s.", remoteUserId, + GetAnonyString(remoteUdid).c_str(), GetAnonyString(localUdid).c_str(), GetAnonyInt32(tokenId)); std::vector profiles = GetAclProfileByDeviceIdAndUserId(remoteUdid, remoteUserId, localUdid); int32_t bindType = DM_INVALIED_TYPE; for (const auto &item : profiles) { @@ -2111,7 +2103,8 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUse continue; } if (item.GetAccesser().GetAccesserDeviceId() == localUdid && - item.GetAccessee().GetAccesseeDeviceId() == remoteUdid) { + item.GetAccessee().GetAccesseeDeviceId() == remoteUdid && + item.GetAccessee().GetAccesseeTokenId() == tokenId) { offlineParam.bindType = USER; CacheAcerAclId(item, offlineParam.needDelAclInfos); LOGI("Src delete acl bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s", item.GetBindType(), @@ -2120,7 +2113,8 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUse continue; } if (item.GetAccessee().GetAccesseeDeviceId() == localUdid && - item.GetAccesser().GetAccesserDeviceId() == remoteUdid) { + item.GetAccesser().GetAccesserDeviceId() == remoteUdid && + item.GetAccessee().GetAccesseeTokenId() == tokenId) { offlineParam.bindType = USER; CacheAceeAclId(item, offlineParam.needDelAclInfos); LOGI("Sink delete acl bindType %{public}u, localUdid %{public}s, remoteUdid %{public}s", item.GetBindType(), @@ -2183,6 +2177,8 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces int32_t aceeTokenId = static_cast(acl.GetAccessee().GetAccesseeTokenId()); if (acl.GetAccesser().GetAccesserUserId() == remoteUserId && acerDeviceId == remoteUdid && aceeDeviceId == localUdid && (acerTokenId == peerTokenId) && (aceeTokenId == tokenId)) { + offlineParam.targetAclHasUserLevel = + (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccessee().GetAccesseeBundleName(); processInfo.userId = acl.GetAccessee().GetAccesseeUserId(); @@ -2196,6 +2192,8 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces } if (acl.GetAccessee().GetAccesseeUserId() == remoteUserId && aceeDeviceId == remoteUdid && acerDeviceId == localUdid && (aceeTokenId == peerTokenId) && (acerTokenId == tokenId)) { + offlineParam.targetAclHasUserLevel = + (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName(); processInfo.userId = acl.GetAccesser().GetAccesserUserId(); @@ -2258,6 +2256,8 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces acl.GetAccesser().GetAccesserDeviceId() == remoteUdid && (static_cast(acl.GetAccesser().GetAccesserTokenId()) == remoteTokenId) && acl.GetAccessee().GetAccesseeDeviceId() == localUdid) { + offlineParam.targetAclHasUserLevel = + (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccessee().GetAccesseeBundleName(); processInfo.userId = acl.GetAccessee().GetAccesseeUserId(); @@ -2274,6 +2274,8 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces acl.GetAccessee().GetAccesseeDeviceId() == remoteUdid && (static_cast(acl.GetAccessee().GetAccesseeTokenId()) == remoteTokenId) && acl.GetAccesser().GetAccesserDeviceId() == localUdid) { + offlineParam.targetAclHasUserLevel = + (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName(); processInfo.userId = acl.GetAccesser().GetAccesserUserId(); @@ -2601,13 +2603,31 @@ void DeviceProfileConnector::UpdatePeerUserId(AccessControlProfile profile, std: } void DeviceProfileConnector::SetProcessInfoPkgName(const DistributedDeviceProfile::AccessControlProfile &acl, - ProcessInfo &processInfo) + std::vector &processInfoVec, bool isAccer) { - if (acl.GetBindType() == DM_IDENTICAL_ACCOUNT || acl.GetBindLevel() == USER) { - processInfo.pkgName = std::string(DM_PKG_NAME); + OHOS::DistributedHardware::ProcessInfo processInfo; + if (isAccer) { + if (acl.GetBindType() == DM_IDENTICAL_ACCOUNT || acl.GetBindLevel() == USER) { + processInfo.pkgName = std::string(DM_PKG_NAME); + } else { + processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName(); + } + processInfo.userId = acl.GetAccesser().GetAccesserUserId(); } else { - processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName(); + if (acl.GetBindType() == DM_IDENTICAL_ACCOUNT || acl.GetBindLevel() == USER) { + processInfo.pkgName = std::string(DM_PKG_NAME); + } else { + processInfo.pkgName = acl.GetAccessee().GetAccesseeBundleName(); + } + processInfo.userId = acl.GetAccessee().GetAccesseeUserId(); + } + auto check = [&processInfo](const OHOS::DistributedHardware::processInfo &info) { + return info.pkgName = processInfo.pkgName; + }; + if (find_if(processInfoVec.begin(), processInfoVec.end(), check) != processInfoVec.end()) { + return; } + processInfoVec.emplace_back(processInfo); } DM_EXPORT std::multimap DeviceProfileConnector::GetDevIdAndUserIdByActHash( @@ -3058,6 +3078,7 @@ DM_EXPORT void DeviceProfileConnector::CacheAcerAclId(const DistributedDevicePro dmAclIdParam.skId = profile.GetAccesser().GetAccesserSessionKeyId(); dmAclIdParam.credId = profile.GetAccesser().GetAccesserCredentialIdStr(); dmAclIdParam.accessControlId = profile.GetAccessControlId(); + dmAclIdParam.pkgName = profile.GetAccesser().GetAccesserBundleName(); aclInfos.push_back(dmAclIdParam); } @@ -3070,6 +3091,7 @@ DM_EXPORT void DeviceProfileConnector::CacheAceeAclId(const DistributedDevicePro dmAclIdParam.skId = profile.GetAccessee().GetAccesseeSessionKeyId(); dmAclIdParam.credId = profile.GetAccessee().GetAccesseeCredentialIdStr(); dmAclIdParam.accessControlId = profile.GetAccessControlId(); + dmAclIdParam.pkgName = profile.GetAccessee().GetAccesseeBundleName(); aclInfos.push_back(dmAclIdParam); } diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 13759a00d..533f2e99e 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -220,7 +220,7 @@ private: std::multimap GetDeviceIdAndUserId(int32_t userId, const std::string &accountId); void HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, const std::string &remoteUdid); - void HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid); + void HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId); void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId); void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, int32_t peerTokenId); @@ -302,8 +302,9 @@ private: const std::string &pkgName, uint64_t tokenId); void OnAuthResultAndOnBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, const std::string &deviceId, int32_t reason, uint64_t tokenId); - void GetBundleName(const DMAclQuadInfo &info, std::set &pkgNameSet); + void GetBundleName(const DMAclQuadInfo &info, std::set &pkgNameSet, bool ¬ifyOffline); void DeleteSessionKey(int32_t userId, const DistributedDeviceProfile::AccessControlProfile &profile); + void NotifyDeviceOrAppOffline(DmOfflineParam &offlineParam, const std::string &remoteUdid); private: std::mutex authMgrMtx_; std::shared_ptr authMgr_; // Old protocol only diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index 3fecede6b..ac49f8de4 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -134,7 +134,7 @@ public: std::multimap GetDeviceIdAndUserId(int32_t userId, const std::string &accountId); void HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, const std::string &remoteUdid); - void HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid); + void HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId); void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId); void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, int32_t peerTokenId); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 54f5608cb..ab350e719 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -2000,7 +2000,7 @@ void DeviceManagerServiceImpl::HandleIdentAccountLogout(const DMAclQuadInfo &inf } std::set pkgNameSet; - GetBundleName(info, pkgNameSet); + GetBundleName(info, pkgNameSet, notifyOffline); if (notifyOffline) { CHECK_NULL_VOID(softbusConnector_); softbusConnector_->SetProcessInfoVec(offlineParam.processVec); @@ -2011,7 +2011,8 @@ void DeviceManagerServiceImpl::HandleIdentAccountLogout(const DMAclQuadInfo &inf } } -void DeviceManagerServiceImpl::GetBundleName(const DMAclQuadInfo &info, std::set &pkgNameSet) +void DeviceManagerServiceImpl::GetBundleName(const DMAclQuadInfo &info, std::set &pkgNameSet, + bool ¬ifyOffline) { std::vector profiles = DeviceProfileConnector::GetInstance().GetAllAclIncludeLnnAcl(); @@ -2025,12 +2026,20 @@ void DeviceManagerServiceImpl::GetBundleName(const DMAclQuadInfo &info, std::set if (accesserUdid == info.localUdid && accesserUserId == info.localUserId && accesseeUdid == info.peerUdid && accesseeUserId == info.peerUserId && (!accesserPkgName.empty())) { + if (item.GetBindLevel() == USER) { + notifyOffline = false; + return; + } pkgNameSet.insert(accesserPkgName); continue; } if (accesserUdid == info.peerUdid && accesserUserId == info.peerUserId && accesseeUdid == info.localUdid && accesseeUserId == info.localUserId && (!accesseePkgName.empty())) { + if (item.GetBindLevel() == USER) { + notifyOffline = false; + return; + } pkgNameSet.insert(accesseePkgName); continue; } @@ -2203,7 +2212,7 @@ void DeviceManagerServiceImpl::HandleAccountLogoutEvent(int32_t remoteUserId, co } std::set pkgNameSet; - GetBundleName(info, pkgNameSet); + GetBundleName(info, pkgNameSet, notifyOffline); if (notifyOffline) { CHECK_NULL_VOID(softbusConnector_); softbusConnector_->SetProcessInfoVec(offlineParam.processVec); @@ -2248,14 +2257,15 @@ int32_t DeviceManagerServiceImpl::DeleteGroup(const std::string &pkgName, const return DM_OK; } -void DeviceManagerServiceImpl::HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid) +void DeviceManagerServiceImpl::HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId) { char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); std::string localUdid = std::string(localUdidTemp); DmOfflineParam offlineParam; int32_t bindType = DeviceProfileConnector::GetInstance().HandleDevUnBindEvent( - remoteUserId, remoteUdid, localUdid, offlineParam); + remoteUserId, remoteUdid, localUdid, offlineParam, tokenId); if (static_cast(bindType) == DM_INVALIED_TYPE) { LOGE("Invalied bindtype."); return; @@ -2996,13 +3006,7 @@ int32_t DeviceManagerServiceImpl::DeleteAclForProcV2(const std::string &localUdi DeleteSkCredAndAcl(offlineParam.allLnnAclInfos); } - //third, not user/DM_IDENTICAL_ACCOUNT acl exist but app/service acl exist - //determin if need report offline to unbind bundle - if (offlineParam.allUserAclInfos.empty() && !offlineParam.allLeftAppOrSvrAclInfos.empty()) { - LOGI("after clear target acl, No user acl exist, report offline"); - softbusConnector_->SetProcessInfoVec(offlineParam.processVec); - softbusConnector_->HandleDeviceOffline(remoteUdid); - } + NotifyDeviceOrAppOffline(offlineParam, remoteUdid); return DM_OK; } @@ -3211,6 +3215,36 @@ void DeviceManagerServiceImpl::InitTaskOfDelTimeOutAcl(const std::string &device deviceStateMgr_->StartDelTimerByDP(deviceUdid, deviceUdidHash); } +void DeviceManagerServiceImpl::NotifyDeviceOrAppOffline(DmOfflineParam &offlineParam, const std::string &remoteUdid) + if (!offlineParam.allUserAclInfos.empty()) { + LOGI("left user acl, not notify"); + return; + } + if (offlineParam.targetAclHasUserLevel && offlineParam.allUserAclInfos.empty() && + !offlineParam.allLeftAppOrSvrAclInfos.empty()) { + LOGI("left app or service acl."); + ProcessInfo processInfo; + processInfo.pkgName = std::string(DM_PKG_NAME); + processInfo.userId = MultipleUserConnector::GetFirstForegroundUserId(); + offlineParam.processVec.push_back(processInfo); + softbusConnector_->SetProcessInfoVec(offlineParam.processVec); + std::set pkgNameSet; + for (auto &item : offlineParam.allLeftAppOrSvrAclInfos) { + pkgNameSet.insert(item.pkgName); + } + CHECK_NULL_VOID(listener_); + listener_->SetExistPkgName(pkgName); + softbusConnector_->HandleDeviceOffline(remoteUdid); + return; + } + if (!offlineParam.targetAclHasUserLevel && offlineParam.allUserAclInfos.empty() && + !offlineParam.allLeftAppOrSvrAclInfos.empty()) { + LOGI("left user acl, not notify."); + softbusConnector_.SetProcessInfoVec(offlineParam.processVec); + softbusConnector_.HandleDeviceOffline(remoteUdid); + } +} + extern "C" IDeviceManagerServiceImpl *CreateDMServiceObject(void) { return new DeviceManagerServiceImpl; diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index b285a2d70..a1bbdc1e2 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -289,7 +289,7 @@ private: int32_t bindLevel); void SendUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId, int32_t bindLevel, uint64_t peerTokenId); - void SendDeviceUnBindBroadCast(const std::vector &peerUdids, int32_t userId); + void SendDeviceUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId); void SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId); int32_t CalculateBroadCastDelayTime(); void SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 08830f86f..6a8288af6 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -232,7 +232,7 @@ public: const std::string &accountId) = 0; virtual void HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, const std::string &remoteUdid) = 0; - virtual void HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid) = 0; + virtual void HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId) = 0; virtual void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId) = 0; virtual void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, int32_t peerTokenId) = 0; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 7bfe6eae1..72d506750 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2942,7 +2942,7 @@ void DeviceManagerService::SendUnBindBroadCast(const std::vector &p LOGI("TokenId %{public}s, bindLevel %{public}d, userId %{public}d.", GetAnonyInt32(tokenId).c_str(), bindLevel, userId); if (static_cast(bindLevel) == USER) { - SendDeviceUnBindBroadCast(peerUdids, userId); + SendDeviceUnBindBroadCast(peerUdids, userId, tokenId); return; } if (static_cast(bindLevel) == APP) { @@ -2959,7 +2959,7 @@ void DeviceManagerService::SendUnBindBroadCast(const std::vector &p uint64_t tokenId, int32_t bindLevel, uint64_t peerTokenId) { if (static_cast(bindLevel) == USER) { - SendDeviceUnBindBroadCast(peerUdids, userId); + SendDeviceUnBindBroadCast(peerUdids, userId, tokenId); return; } if (static_cast(bindLevel) == APP) { @@ -2972,12 +2972,14 @@ void DeviceManagerService::SendUnBindBroadCast(const std::vector &p } } -void DeviceManagerService::SendDeviceUnBindBroadCast(const std::vector &peerUdids, int32_t userId) +void DeviceManagerService::SendDeviceUnBindBroadCast(const std::vector &peerUdids, int32_t userId, + uint64_t tokenId) { RelationShipChangeMsg msg; msg.type = RelationShipChangeType::DEVICE_UNBIND; msg.userId = static_cast(userId); msg.peerUdids = peerUdids; + msg.tokenId = tokenId; std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); CHECK_NULL_VOID(softbusListener_); softbusListener_->SendAclChangedBroadcast(broadCastMsg); @@ -3131,7 +3133,8 @@ bool DeviceManagerService::ParseRelationShipChangeType(const RelationShipChangeM relationShipMsg.peerUdid); break; case RelationShipChangeType::DEVICE_UNBIND: - dmServiceImpl_->HandleDevUnBindEvent(relationShipMsg.userId, relationShipMsg.peerUdid); + dmServiceImpl_->HandleDevUnBindEvent(relationShipMsg.userId, relationShipMsg.peerUdid, + static_cast(relationShipMsg.tokenId)); break; case RelationShipChangeType::APP_UNBIND: if (relationShipMsg.peerTokenId != 0) { diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index f917117d4..57415e050 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -790,9 +790,14 @@ void DeviceManagerServiceListener::ProcessDeviceOffline(const std::vector(state), GetAnonyString(info.deviceId).c_str()); RemoveNotExistProcess(); + std::vector whiteListVec = GetWhiteListSAProcessInfo(DmCommonNotifyEvent::REG_DEVICE_STATE); std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); + bool isOnline = SoftbusCache::GetInstance().CheckIsOnline(std::string(info.deviceId)); for (const auto &it : procInfoVec) { + if (isOnline && find(whiteListVec.begin(), whiteListVec.end(), it) != whiteListVec.end()) { + continue; + } { std::lock_guard autoLock(alreadyNotifyPkgNameLock_); if (actUnrelatedPkgName_.find(it.pkgName) != actUnrelatedPkgName_.end()) { @@ -880,7 +885,8 @@ void DeviceManagerServiceListener::ProcessAppOffline(const std::vector autoLock(alreadyNotifyPkgNameLock_); @@ -890,7 +896,7 @@ void DeviceManagerServiceListener::ProcessAppOffline(const std::vector> (i * BITS_PER_BYTE)) & 0xFF; } for (int i = USERID_PAYLOAD_LEN; i < DEVICE_UNBIND_PAYLOAD_LEN; i++) { msg[i] |= (broadCastId >> ((i - USERID_PAYLOAD_LEN) * BITS_PER_BYTE)) & 0xFF; } + for (int i = UNBIND_DEVICE_TORENID_LEN; i < DEVICE_UNBIND_PAYLOAD_LEN; i++) { + msg[i] |= (tokenId >> ((i - UNBIND_DEVICE_TORENID_LEN) * BITS_PER_BYTE)) & 0xFF; + } len = DEVICE_UNBIND_PAYLOAD_LEN; } @@ -522,7 +526,7 @@ bool RelationShipChangeMsg::FromDeviceUnbindPayLoad(const cJSON *payloadJson) } } broadCastId = 0; - for (uint32_t j = USERID_PAYLOAD_LEN; j < DEVICE_UNBIND_PAYLOAD_LEN; j++) { + for (uint32_t j = USERID_PAYLOAD_LEN; j < UNBIND_DEVICE_TORENID_LEN; j++) { cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); CHECK_NULL_RETURN(payloadItem, false); if (cJSON_IsNumber(payloadItem)) { @@ -530,6 +534,15 @@ bool RelationShipChangeMsg::FromDeviceUnbindPayLoad(const cJSON *payloadJson) ((j - USERID_PAYLOAD_LEN) * BITS_PER_BYTE); } } + tokenId = 0; + for (uint32_t j = UNBIND_DEVICE_TORENID_LEN; j < DEVICE_UNBIND_PAYLOAD_LEN; J++) { + cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); + CHECK_NULL_RETURN(payloadItem, false); + if (cJSON_IsNumber(payloadItem)) { + tokenId |= (static_cast(payloadItem->valueint)) << + ((j - UNBIND_DEVICE_TORENID_LEN) * BITS_PER_BYTE); + } + } return true; } diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 450842cfa..ada7df79a 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -1193,8 +1193,9 @@ HWTEST_F(DeviceProfileConnectorTest, HandleDevUnBindEvent_001, testing::ext::Tes std::string remoteUdid = "remoteDeviceId"; std::string localUdid = "localDeviceId"; DmOfflineParam offlineParam; + int32_t tokenId = 11; int32_t bindType = DeviceProfileConnector::GetInstance().HandleDevUnBindEvent(remoteUserId, remoteUdid, localUdid, - offlineParam); + offlineParam, tokenId); EXPECT_EQ(bindType, DM_INVALIED_TYPE); } @@ -1420,24 +1421,25 @@ HWTEST_F(DeviceProfileConnectorTest, HandleDevUnBindEvent_002, testing::ext::Tes std::string remoteUdid; std::string localUdid = "localDeviceId"; DmOfflineParam offlineParam; + int32_t tokenId = 11; int32_t bindType = DeviceProfileConnector::GetInstance().HandleDevUnBindEvent(remoteUserId, remoteUdid, localUdid, - offlineParam); + offlineParam, tokenId); EXPECT_EQ(bindType, DM_INVALIED_TYPE); remoteUdid = "123456"; bindType = DeviceProfileConnector::GetInstance().HandleDevUnBindEvent(remoteUserId, remoteUdid, localUdid, - offlineParam); + offlineParam, tokenId); EXPECT_EQ(bindType, DM_INVALIED_TYPE); remoteUdid = "localDeviceId"; remoteUserId = 1234; bindType = DeviceProfileConnector::GetInstance().HandleDevUnBindEvent(remoteUserId, remoteUdid, localUdid, - offlineParam); + offlineParam, tokenId); EXPECT_NE(bindType, DM_IDENTICAL_ACCOUNT); remoteUserId = 456; bindType = DeviceProfileConnector::GetInstance().HandleDevUnBindEvent(remoteUserId, remoteUdid, localUdid, - offlineParam); + offlineParam, tokenId); EXPECT_EQ(bindType, DM_INVALIED_TYPE); } diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index f9d2b234e..fe4a018ee 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -2248,9 +2248,9 @@ HWTEST_F(DeviceManagerServiceTest, SetDnPolicy_003, testing::ext::TestSize.Level DeviceManagerService::GetInstance().SendUnBindBroadCast(peerUdids, userId, tokenId, USER); DeviceManagerService::GetInstance().SendUnBindBroadCast(peerUdids, userId, tokenId, APP); DeviceManagerService::GetInstance().SendUnBindBroadCast(peerUdids, userId, tokenId, 2); - DeviceManagerService::GetInstance().SendDeviceUnBindBroadCast(peerUdids, userId); + DeviceManagerService::GetInstance().SendDeviceUnBindBroadCast(peerUdids, userId, tokenId); DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); - DeviceManagerService::GetInstance().SendDeviceUnBindBroadCast(peerUdids, userId); + DeviceManagerService::GetInstance().SendDeviceUnBindBroadCast(peerUdids, userId, tokenId); DeviceManagerService::GetInstance().softbusListener_ = nullptr; std::string processName = "collaboration_service"; EXPECT_CALL(*permissionManagerMock_, GetCallerProcessName(_)) diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index e44d72c59..9fce72f58 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -1898,14 +1898,14 @@ HWTEST_F(DeviceManagerServiceImplTest, SaveOnlineDeviceInfo_001, testing::ext::T EXPECT_CALL(*deviceProfileConnectorMock_, HandleAppUnBindEvent(_, _, _, _)).WillOnce(Return(dmOfflineParam)); deviceManagerServiceImpl_->HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId); - EXPECT_CALL(*deviceProfileConnectorMock_, HandleDevUnBindEvent(_, _, _, _)).WillOnce(Return(DM_INVALIED_TYPE)); - deviceManagerServiceImpl_->HandleDevUnBindEvent(remoteUserId, remoteUdid); + EXPECT_CALL(*deviceProfileConnectorMock_, HandleDevUnBindEvent(_, _, _, _, _)).WillOnce(Return(DM_INVALIED_TYPE)); + deviceManagerServiceImpl_->HandleDevUnBindEvent(remoteUserId, remoteUdid, tokenId); - EXPECT_CALL(*deviceProfileConnectorMock_, HandleDevUnBindEvent(_, _, _, _)).WillOnce(Return(DM_IDENTICAL_ACCOUNT)); + EXPECT_CALL(*deviceProfileConnectorMock_, HandleDevUnBindEvent(_, _, _, _, _)).WillOnce(Return(DM_IDENTICAL_ACCOUNT)); if (deviceManagerServiceImpl_->authMgr_ == nullptr) { deviceManagerServiceImpl_->Initialize(listener_); } - deviceManagerServiceImpl_->HandleDevUnBindEvent(remoteUserId, remoteUdid); + deviceManagerServiceImpl_->HandleDevUnBindEvent(remoteUserId, remoteUdid, tokenId); int32_t userId = 123456; remoteUdid = "remoteDeviceId"; diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index 603e20b2a..8450d37b0 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -26,10 +26,10 @@ std::vector DeviceProfileConnect } int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, - const std::string &localUdid, DmOfflineParam &offlineParam) + const std::string &localUdid, DmOfflineParam &offlineParam, int32_t tokenId) { return DmDeviceProfileConnector::dmDeviceProfileConnector->HandleDevUnBindEvent(remoteUserId, remoteUdid, - localUdid, offlineParam); + localUdid, offlineParam, tokenId); } int32_t DeviceProfileConnector::HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, diff --git a/test/unittest/mock/deviceprofile_connector_mock.h b/test/unittest/mock/deviceprofile_connector_mock.h index 17d9b9333..81d47bf85 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.h +++ b/test/unittest/mock/deviceprofile_connector_mock.h @@ -29,7 +29,7 @@ public: public: virtual std::vector GetAllAccessControlProfile() = 0; virtual int32_t HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, - const std::string &localUdid, DmOfflineParam &offlineParam) = 0; + const std::string &localUdid, DmOfflineParam &offlineParam, int32_t tokenId) = 0; virtual int32_t HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, const std::string &remoteUdid, const std::string &localUdid) = 0; virtual uint32_t CheckBindType(std::string trustDeviceId, std::string requestDeviceId) = 0; @@ -82,7 +82,8 @@ public: class DeviceProfileConnectorMock : public DmDeviceProfileConnector { public: MOCK_METHOD(std::vector, GetAllAccessControlProfile, ()); - MOCK_METHOD(int32_t, HandleDevUnBindEvent, (int32_t, const std::string &, const std::string &, DmOfflineParam &)); + MOCK_METHOD(int32_t, HandleDevUnBindEvent, (int32_t, const std::string &, const std::string &, DmOfflineParam &, + int32_t)); MOCK_METHOD(int32_t, HandleAccountLogoutEvent, (int32_t, const std::string &, const std::string &, const std::string &)); MOCK_METHOD(uint32_t, CheckBindType, (std::string, std::string)); -- Gitee From b0738c0edaa906c2dc124468ac10932ce54d716f Mon Sep 17 00:00:00 2001 From: s30044129 Date: Wed, 10 Sep 2025 12:08:30 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30044129 --- .../src/deviceprofile_connector.cpp | 22 +++++++++---------- .../src/device_manager_service_impl.cpp | 7 +++--- .../src/device_manager_service_impl_lite.cpp | 4 +++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 4cc508b59..d3a5cd45f 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -444,7 +444,7 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces (acerDeviceId == localUdid) && (aceeDeviceId == remoteUdid) && (peerTokenId == 0 || (peerTokenId != 0 && aceeTokenId == static_cast(peerTokenId)))) { offlineParam.targetAclHasUserLevel = - (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName(); processInfo.userId = acl.GetAccesser().GetAccesserUserId(); @@ -461,7 +461,7 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces (aceeDeviceId == localUdid) && (acerDeviceId == remoteUdid) && (peerTokenId == 0 || (peerTokenId != 0 && acerTokenId == static_cast(peerTokenId)))) { offlineParam.targetAclHasUserLevel = - (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccessee().GetAccesseeBundleName(); processInfo.userId = acl.GetAccessee().GetAccesseeUserId(); @@ -1286,7 +1286,7 @@ void DeviceProfileConnector::CacheOfflineParam(const DistributedDeviceProfile::A accesseeUdid == info.peerUdid && accesseeUserId == info.peerUserId && std::string(accesseeAccountIdHash) == accountIdHash) { offlineParam.bindType = profile.GetBindType(); - SetProcessInfoPkgName(item, offlineParam.processVec, true); + SetProcessInfoPkgName(profile, offlineParam.processVec, true); notifyOffline = (profile.GetStatus() == ACTIVE); CacheAcerAclId(profile, offlineParam.needDelAclInfos); return; @@ -1295,7 +1295,7 @@ void DeviceProfileConnector::CacheOfflineParam(const DistributedDeviceProfile::A accesseeUdid == info.localUdid && accesseeUserId == info.localUserId && std::string(accesserAccountIdHash) == accountIdHash) { offlineParam.bindType = profile.GetBindType(); - SetProcessInfoPkgName(item, offlineParam.processVec, false); + SetProcessInfoPkgName(profile, offlineParam.processVec, false); notifyOffline = (profile.GetStatus() == ACTIVE); CacheAceeAclId(profile, offlineParam.needDelAclInfos); return; @@ -2091,7 +2091,7 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUse const std::string &localUdid, DmOfflineParam &offlineParam, int32_t tokenId) { LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, localUdid %{public}s, tokenId %{public}s.", remoteUserId, - GetAnonyString(remoteUdid).c_str(), GetAnonyString(localUdid).c_str(), GetAnonyInt32(tokenId)); + GetAnonyString(remoteUdid).c_str(), GetAnonyString(localUdid).c_str(), GetAnonyInt32(tokenId).c_str()); std::vector profiles = GetAclProfileByDeviceIdAndUserId(remoteUdid, remoteUserId, localUdid); int32_t bindType = DM_INVALIED_TYPE; for (const auto &item : profiles) { @@ -2178,7 +2178,7 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces if (acl.GetAccesser().GetAccesserUserId() == remoteUserId && acerDeviceId == remoteUdid && aceeDeviceId == localUdid && (acerTokenId == peerTokenId) && (aceeTokenId == tokenId)) { offlineParam.targetAclHasUserLevel = - (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccessee().GetAccesseeBundleName(); processInfo.userId = acl.GetAccessee().GetAccesseeUserId(); @@ -2193,7 +2193,7 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces if (acl.GetAccessee().GetAccesseeUserId() == remoteUserId && aceeDeviceId == remoteUdid && acerDeviceId == localUdid && (aceeTokenId == peerTokenId) && (acerTokenId == tokenId)) { offlineParam.targetAclHasUserLevel = - (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName(); processInfo.userId = acl.GetAccesser().GetAccesserUserId(); @@ -2257,7 +2257,7 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces (static_cast(acl.GetAccesser().GetAccesserTokenId()) == remoteTokenId) && acl.GetAccessee().GetAccesseeDeviceId() == localUdid) { offlineParam.targetAclHasUserLevel = - (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccessee().GetAccesseeBundleName(); processInfo.userId = acl.GetAccessee().GetAccesseeUserId(); @@ -2275,7 +2275,7 @@ bool DeviceProfileConnector::FindTargetAcl(const DistributedDeviceProfile::Acces (static_cast(acl.GetAccessee().GetAccesseeTokenId()) == remoteTokenId) && acl.GetAccesser().GetAccesserDeviceId() == localUdid) { offlineParam.targetAclHasUserLevel = - (acl.GetBindLevel() == USER || acl.GetBindLevel() == DM_IDENTICAL_ACCOUNT); + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName(); processInfo.userId = acl.GetAccesser().GetAccesserUserId(); @@ -2621,8 +2621,8 @@ void DeviceProfileConnector::SetProcessInfoPkgName(const DistributedDeviceProfil } processInfo.userId = acl.GetAccessee().GetAccesseeUserId(); } - auto check = [&processInfo](const OHOS::DistributedHardware::processInfo &info) { - return info.pkgName = processInfo.pkgName; + auto check = [&processInfo](const OHOS::DistributedHardware::ProcessInfo &info) { + return info.pkgName == processInfo.pkgName; }; if (find_if(processInfoVec.begin(), processInfoVec.end(), check) != processInfoVec.end()) { return; diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index ab350e719..8f8ed377b 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -3233,15 +3233,16 @@ void DeviceManagerServiceImpl::NotifyDeviceOrAppOffline(DmOfflineParam &offlineP pkgNameSet.insert(item.pkgName); } CHECK_NULL_VOID(listener_); - listener_->SetExistPkgName(pkgName); + listener_->SetExistPkgName(pkgNameSet); softbusConnector_->HandleDeviceOffline(remoteUdid); return; } if (!offlineParam.targetAclHasUserLevel && offlineParam.allUserAclInfos.empty() && !offlineParam.allLeftAppOrSvrAclInfos.empty()) { LOGI("left user acl, not notify."); - softbusConnector_.SetProcessInfoVec(offlineParam.processVec); - softbusConnector_.HandleDeviceOffline(remoteUdid); + softbusConnector_->SetProcessInfoVec(offlineParam.processVec); + softbusConnector_->HandleDeviceOffline(remoteUdid); + return; } } diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index b59957cc0..3e3c79bda 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -487,10 +487,12 @@ void DeviceManagerServiceImpl::HandleAccountLogoutEvent(int32_t remoteUserId, co return; } -void DeviceManagerServiceImpl::HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid) +void DeviceManagerServiceImpl::HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId) { (void)remoteUserId; (void)remoteUdid; + (void)tokenId; return; } -- Gitee From 1f842635a2852e4f76f0dcafd56d2faa95bc1de7 Mon Sep 17 00:00:00 2001 From: s30044129 Date: Wed, 10 Sep 2025 12:21:05 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30044129 --- services/service/src/device_manager_service_listener.cpp | 2 +- .../src/relationshipsyncmgr/relationship_sync_mgr.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 57415e050..149a53a5f 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -886,7 +886,7 @@ void DeviceManagerServiceListener::ProcessAppOffline(const std::vector autoLock(alreadyNotifyPkgNameLock_); diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 624767c55..9043a1d49 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -58,7 +58,7 @@ namespace { * @brief the userid payload cost 2 bytes. * */ - const int32_t UNBIND_DEVICE_TORENID_LEN = 3; + const int32_t UNBIND_DEVICE_TOKENID_LEN = 3; const int32_t USERID_PAYLOAD_LEN = 2; const int32_t TOKENID_PAYLOAD_LEN = 6; const int32_t ACCOUNTID_PAYLOAD_LEN = 6; @@ -348,14 +348,14 @@ void RelationShipChangeMsg::ToAccountLogoutPayLoad(uint8_t *&msg, uint32_t &len) void RelationShipChangeMsg::ToDeviceUnbindPayLoad(uint8_t *&msg, uint32_t &len) const { msg = new uint8_t[DEVICE_UNBIND_PAYLOAD_LEN](); - for (int i = 0; i < UNBIND_DEVICE_TORENID_LEN; i++) { + for (int i = 0; i < UNBIND_DEVICE_TOKENID_LEN; i++) { msg[i] |= (userId >> (i * BITS_PER_BYTE)) & 0xFF; } for (int i = USERID_PAYLOAD_LEN; i < DEVICE_UNBIND_PAYLOAD_LEN; i++) { msg[i] |= (broadCastId >> ((i - USERID_PAYLOAD_LEN) * BITS_PER_BYTE)) & 0xFF; } - for (int i = UNBIND_DEVICE_TORENID_LEN; i < DEVICE_UNBIND_PAYLOAD_LEN; i++) { - msg[i] |= (tokenId >> ((i - UNBIND_DEVICE_TORENID_LEN) * BITS_PER_BYTE)) & 0xFF; + for (int i = UNBIND_DEVICE_TOKENID_LEN; i < DEVICE_UNBIND_PAYLOAD_LEN; i++) { + msg[i] |= (tokenId >> ((i - UNBIND_DEVICE_TOKENID_LEN) * BITS_PER_BYTE)) & 0xFF; } len = DEVICE_UNBIND_PAYLOAD_LEN; } -- Gitee From f606c58ea562d65d15d0ac4410dc422063b6bb1b Mon Sep 17 00:00:00 2001 From: s30044129 Date: Wed, 10 Sep 2025 12:31:56 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30044129 --- commondependency/src/deviceprofile_connector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index d3a5cd45f..3f709698d 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -2114,7 +2114,7 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUse } if (item.GetAccessee().GetAccesseeDeviceId() == localUdid && item.GetAccesser().GetAccesserDeviceId() == remoteUdid && - item.GetAccessee().GetAccesseeTokenId() == tokenId) { + item.GetAccesser().GetAccesserTokenId() == tokenId) { offlineParam.bindType = USER; CacheAceeAclId(item, offlineParam.needDelAclInfos); LOGI("Sink delete acl bindType %{public}u, localUdid %{public}s, remoteUdid %{public}s", item.GetBindType(), -- Gitee From 448311bcd5ada10c35e36990805465e76ec2c22c Mon Sep 17 00:00:00 2001 From: s30044129 Date: Wed, 10 Sep 2025 14:12:27 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30044129 --- .../src/relationshipsyncmgr/relationship_sync_mgr.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 9043a1d49..00c49ab20 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -348,10 +348,10 @@ void RelationShipChangeMsg::ToAccountLogoutPayLoad(uint8_t *&msg, uint32_t &len) void RelationShipChangeMsg::ToDeviceUnbindPayLoad(uint8_t *&msg, uint32_t &len) const { msg = new uint8_t[DEVICE_UNBIND_PAYLOAD_LEN](); - for (int i = 0; i < UNBIND_DEVICE_TOKENID_LEN; i++) { + for (int i = 0; i < USERID_PAYLOAD_LEN; i++) { msg[i] |= (userId >> (i * BITS_PER_BYTE)) & 0xFF; } - for (int i = USERID_PAYLOAD_LEN; i < DEVICE_UNBIND_PAYLOAD_LEN; i++) { + for (int i = USERID_PAYLOAD_LEN; i < UNBIND_DEVICE_TOKENID_LEN; i++) { msg[i] |= (broadCastId >> ((i - USERID_PAYLOAD_LEN) * BITS_PER_BYTE)) & 0xFF; } for (int i = UNBIND_DEVICE_TOKENID_LEN; i < DEVICE_UNBIND_PAYLOAD_LEN; i++) { @@ -526,7 +526,7 @@ bool RelationShipChangeMsg::FromDeviceUnbindPayLoad(const cJSON *payloadJson) } } broadCastId = 0; - for (uint32_t j = USERID_PAYLOAD_LEN; j < UNBIND_DEVICE_TORENID_LEN; j++) { + for (uint32_t j = USERID_PAYLOAD_LEN; j < UNBIND_DEVICE_TOKENID_LEN; j++) { cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); CHECK_NULL_RETURN(payloadItem, false); if (cJSON_IsNumber(payloadItem)) { @@ -535,12 +535,12 @@ bool RelationShipChangeMsg::FromDeviceUnbindPayLoad(const cJSON *payloadJson) } } tokenId = 0; - for (uint32_t j = UNBIND_DEVICE_TORENID_LEN; j < DEVICE_UNBIND_PAYLOAD_LEN; J++) { + for (uint32_t j = UNBIND_DEVICE_TOKENID_LEN; j < DEVICE_UNBIND_PAYLOAD_LEN; j++) { cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); CHECK_NULL_RETURN(payloadItem, false); if (cJSON_IsNumber(payloadItem)) { tokenId |= (static_cast(payloadItem->valueint)) << - ((j - UNBIND_DEVICE_TORENID_LEN) * BITS_PER_BYTE); + ((j - UNBIND_DEVICE_TOKENID_LEN) * BITS_PER_BYTE); } } return true; -- Gitee From 66069e031205769a0ab47aa3661f97e52958d909 Mon Sep 17 00:00:00 2001 From: s30044129 Date: Wed, 10 Sep 2025 15:44:24 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30044129 --- services/implementation/src/device_manager_service_impl.cpp | 5 +++-- test/unittest/UTTest_device_manager_service_impl.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 8f8ed377b..41998ba84 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -2628,7 +2628,7 @@ void DeviceManagerServiceImpl::GetDelACLInfoVec(const int32_t &accessTokenId, continue; } if (accessTokenId == static_cast(accesssertokenId) && - userId == item.GetAccesser().GetAccesserUserId() && + userId == static_cast(item.GetAccesser().GetAccesserUserId()) && localUdid == item.GetAccessee().GetAccesseeDeviceId()) { DmOfflineParam offlineParam; delProfileMap[item.GetAccessControlId()] = item; @@ -2641,7 +2641,7 @@ void DeviceManagerServiceImpl::GetDelACLInfoVec(const int32_t &accessTokenId, } } if (accessTokenId == static_cast(accessseetokenId) && - userId == item.GetAccessee().GetAccesseeUserId() && + userId == static_cast(item.GetAccessee().GetAccesseeUserId()) && localUdid == item.GetAccesser().GetAccesserDeviceId()) { DmOfflineParam offlineParam; DeviceProfileConnector::GetInstance().CacheAcerAclId(item, offlineParam.needDelAclInfos); @@ -3216,6 +3216,7 @@ void DeviceManagerServiceImpl::InitTaskOfDelTimeOutAcl(const std::string &device } void DeviceManagerServiceImpl::NotifyDeviceOrAppOffline(DmOfflineParam &offlineParam, const std::string &remoteUdid) +{ if (!offlineParam.allUserAclInfos.empty()) { LOGI("left user acl, not notify"); return; diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index 9fce72f58..ddda9024e 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -1898,10 +1898,11 @@ HWTEST_F(DeviceManagerServiceImplTest, SaveOnlineDeviceInfo_001, testing::ext::T EXPECT_CALL(*deviceProfileConnectorMock_, HandleAppUnBindEvent(_, _, _, _)).WillOnce(Return(dmOfflineParam)); deviceManagerServiceImpl_->HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId); - EXPECT_CALL(*deviceProfileConnectorMock_, HandleDevUnBindEvent(_, _, _, _, _)).WillOnce(Return(DM_INVALIED_TYPE)); + EXPECT_CALL(*deviceProfileConnectorMock_,HandleDevUnBindEvent(_, _, _, _, _)).WillOnce(Return(DM_INVALIED_TYPE)); deviceManagerServiceImpl_->HandleDevUnBindEvent(remoteUserId, remoteUdid, tokenId); - EXPECT_CALL(*deviceProfileConnectorMock_, HandleDevUnBindEvent(_, _, _, _, _)).WillOnce(Return(DM_IDENTICAL_ACCOUNT)); + EXPECT_CALL(*deviceProfileConnectorMock_, + HandleDevUnBindEvent(_, _, _, _, _)).WillOnce(Return(DM_IDENTICAL_ACCOUNT)); if (deviceManagerServiceImpl_->authMgr_ == nullptr) { deviceManagerServiceImpl_->Initialize(listener_); } -- Gitee From 617767683aaf799cbd9fab9fd2122b46cc94a269 Mon Sep 17 00:00:00 2001 From: s30044129 Date: Wed, 10 Sep 2025 21:52:48 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30044129 --- .../service/include/device_manager_service.h | 1 + .../service/src/device_manager_service.cpp | 21 ++++++++++++------- .../UTTest_device_manager_service_impl.cpp | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index a1bbdc1e2..a4a52748a 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -418,6 +418,7 @@ private: void GetLocalUserIdFromDataBase(std::vector &foregroundUsers, std::vector &backgroundUsers); void PutLocalUserIdToDataBase(const std::vector &foregroundUsers, const std::vector &backgroundUsers); + void ParseAppUnBindRelationShip(const RelationShipChangeMsg &relationShipMsg); private: bool isImplsoLoaded_ = false; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 72d506750..587a771ab 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -3137,14 +3137,7 @@ bool DeviceManagerService::ParseRelationShipChangeType(const RelationShipChangeM static_cast(relationShipMsg.tokenId)); break; case RelationShipChangeType::APP_UNBIND: - if (relationShipMsg.peerTokenId != 0) { - dmServiceImpl_->HandleAppUnBindEvent(relationShipMsg.userId, relationShipMsg.peerUdid, - static_cast(relationShipMsg.peerTokenId), - static_cast(relationShipMsg.tokenId)); - } else { - dmServiceImpl_->HandleAppUnBindEvent(relationShipMsg.userId, relationShipMsg.peerUdid, - static_cast(relationShipMsg.tokenId)); - } + ParseAppUnBindRelationShip(relationShipMsg); break; case RelationShipChangeType::SERVICE_UNBIND: dmServiceImpl_->HandleServiceUnBindEvent(relationShipMsg.userId, relationShipMsg.peerUdid, @@ -3178,6 +3171,18 @@ bool DeviceManagerService::ParseRelationShipChangeType(const RelationShipChangeM return true; } +void DeviceManagerService::ParseAppUnBindRelationShip(const RelationShipChangeMsg &relationShipMsg) +{ + if (relationShipMsg.peerTokenId != 0) { + dmServiceImpl_->HandleAppUnBindEvent(relationShipMsg.userId, relationShipMsg.peerUdid, + static_cast(relationShipMsg.peerTokenId), + static_cast(relationShipMsg.tokenId)); + } else { + dmServiceImpl_->HandleAppUnBindEvent(relationShipMsg.userId, relationShipMsg.peerUdid, + static_cast(relationShipMsg.tokenId)); + } +} + bool DeviceManagerService::IsMsgEmptyAndDMServiceImplReady(const std::string &msg) { if (msg.empty()) { diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index ddda9024e..7199b45c0 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -1898,7 +1898,7 @@ HWTEST_F(DeviceManagerServiceImplTest, SaveOnlineDeviceInfo_001, testing::ext::T EXPECT_CALL(*deviceProfileConnectorMock_, HandleAppUnBindEvent(_, _, _, _)).WillOnce(Return(dmOfflineParam)); deviceManagerServiceImpl_->HandleAppUnBindEvent(remoteUserId, remoteUdid, tokenId); - EXPECT_CALL(*deviceProfileConnectorMock_,HandleDevUnBindEvent(_, _, _, _, _)).WillOnce(Return(DM_INVALIED_TYPE)); + EXPECT_CALL(*deviceProfileConnectorMock_, HandleDevUnBindEvent(_, _, _, _, _)).WillOnce(Return(DM_INVALIED_TYPE)); deviceManagerServiceImpl_->HandleDevUnBindEvent(remoteUserId, remoteUdid, tokenId); EXPECT_CALL(*deviceProfileConnectorMock_, -- Gitee From 8cfc042c209b2bfffaa177cdbafd06161f78fcb4 Mon Sep 17 00:00:00 2001 From: s30044129 Date: Thu, 11 Sep 2025 09:04:32 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s30044129 --- services/implementation/src/device_manager_service_impl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 41998ba84..677601dab 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -3005,7 +3005,6 @@ int32_t DeviceManagerServiceImpl::DeleteAclForProcV2(const std::string &localUdi LOGI("No acl exist, clear lnn acl"); DeleteSkCredAndAcl(offlineParam.allLnnAclInfos); } - NotifyDeviceOrAppOffline(offlineParam, remoteUdid); return DM_OK; } -- Gitee