From 74124eda64fd84bc8d313d1c5d8bfb5b9919a4f6 Mon Sep 17 00:00:00 2001 From: s30044129 Date: Thu, 11 Sep 2025 14:24:07 +0800 Subject: [PATCH 1/7] =?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 | 65 +++++++++++++---- .../src/device_manager_service_impl_lite.cpp | 4 +- .../service/include/device_manager_service.h | 3 +- .../include/idevice_manager_service_impl.h | 2 +- .../service/src/device_manager_service.cpp | 32 +++++---- .../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 | 9 +-- .../mock/deviceprofile_connector_mock.cpp | 4 +- .../mock/deviceprofile_connector_mock.h | 5 +- 16 files changed, 177 insertions(+), 82 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..3f709698d 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.GetBindType() == 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.GetBindType() == 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(profile, 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(profile, 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).c_str()); 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.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(), @@ -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.GetBindType() == 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.GetBindType() == 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.GetBindType() == 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.GetBindType() == 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..677601dab 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; @@ -2618,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; @@ -2631,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); @@ -2995,14 +3005,7 @@ int32_t DeviceManagerServiceImpl::DeleteAclForProcV2(const std::string &localUdi LOGI("No acl exist, clear lnn acl"); 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 +3214,38 @@ 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(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); + return; + } +} + extern "C" IDeviceManagerServiceImpl *CreateDMServiceObject(void) { return new DeviceManagerServiceImpl; 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; } diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index b285a2d70..a4a52748a 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, @@ -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/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 504ce2663..1511cda47 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2951,7 +2951,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) { @@ -2968,7 +2968,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) { @@ -2981,12 +2981,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); @@ -3140,17 +3142,11 @@ 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) { - 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, @@ -3184,6 +3180,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/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index f917117d4..149a53a5f 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++) { + 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++) { + msg[i] |= (tokenId >> ((i - UNBIND_DEVICE_TOKENID_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_TOKENID_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_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_TOKENID_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..7199b45c0 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -1898,14 +1898,15 @@ 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 91af9d8bd392b0473daefe8488818ed3ff766099 Mon Sep 17 00:00:00 2001 From: s30044129 Date: Thu, 11 Sep 2025 14:30:17 +0800 Subject: [PATCH 2/7] =?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/include/device_manager_service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index a4a52748a..303ada0fd 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -405,6 +405,7 @@ private: void QueryDependsSwitchState(); #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI DM_EXPORT void SubscribeDataShareCommonEvent(); + void ParseAppUnBindRelationShip(const RelationShipChangeMsg &relationShipMsg); #endif void HandleNetworkConnected(int32_t networkStatus); void NotifyRemoteLocalLogout(const std::vector &peerUdids, @@ -418,7 +419,6 @@ 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; -- Gitee From 88c642cafd5a19d00ee0c2218b09e27131394eed Mon Sep 17 00:00:00 2001 From: s30044129 Date: Thu, 11 Sep 2025 23:09:03 +0800 Subject: [PATCH 3/7] =?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 --- common/src/dm_constants.cpp | 3 +- .../include/deviceprofile_connector.h | 2 +- .../src/deviceprofile_connector.cpp | 28 +++++++++---------- .../src/device_manager_service_impl.cpp | 4 +-- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/common/src/dm_constants.cpp b/common/src/dm_constants.cpp index 73ed7a13c..7dfecbce4 100644 --- a/common/src/dm_constants.cpp +++ b/common/src/dm_constants.cpp @@ -189,7 +189,8 @@ const char* DM_VERSION_5_1_1 = "5.1.1"; const char* DM_VERSION_5_1_2 = "5.1.2"; const char* DM_VERSION_5_1_3 = "5.1.3"; const char* DM_VERSION_5_1_4 = "5.1.4"; -const char* DM_CURRENT_VERSION = DM_VERSION_5_1_4; +const char* DM_VERSION_5_1_5 = "5.1.5"; +const char* DM_CURRENT_VERSION = DM_VERSION_5_1_5; const char* DM_ACL_AGING_VERSION = DM_VERSION_5_1_0; const char* DM_VERSION_5_0_OLD_MAX = "5.0.99"; // Estimated highest version number of the old version const int32_t OLD_DM_HO_OSTYPE = -1; diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 3fd900e4f..c80118c1f 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -115,7 +115,7 @@ typedef struct DmOfflineParam { int32_t leftAclNumber; int32_t peerUserId; bool hasLnnAcl = false; - bool targetAclHasUserLevel = false; + std::unordered_set targetAclHasUserLevelSet; int64_t accessControlId; // save the need unbind acl info std::vector needDelAclInfos; diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 3f709698d..4fb72088b 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -443,8 +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.GetBindType() == DM_IDENTICAL_ACCOUNT); + offlineParam.targetAclHasUserLevelSet.insert( + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT)); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName(); processInfo.userId = acl.GetAccesser().GetAccesserUserId(); @@ -460,8 +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.GetBindType() == DM_IDENTICAL_ACCOUNT); + offlineParam.targetAclHasUserLevelSet.insert( + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT)); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccessee().GetAccesseeBundleName(); processInfo.userId = acl.GetAccessee().GetAccesseeUserId(); @@ -2104,7 +2104,7 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUse } if (item.GetAccesser().GetAccesserDeviceId() == localUdid && item.GetAccessee().GetAccesseeDeviceId() == remoteUdid && - item.GetAccessee().GetAccesseeTokenId() == tokenId) { + (item.GetAccessee().GetAccesseeTokenId() == tokenId || tokenId == 0)) { offlineParam.bindType = USER; CacheAcerAclId(item, offlineParam.needDelAclInfos); LOGI("Src delete acl bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s", item.GetBindType(), @@ -2114,7 +2114,7 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUse } if (item.GetAccessee().GetAccesseeDeviceId() == localUdid && item.GetAccesser().GetAccesserDeviceId() == remoteUdid && - item.GetAccesser().GetAccesserTokenId() == tokenId) { + (item.GetAccesser().GetAccesserTokenId() == tokenId || tokenId == 0)) { offlineParam.bindType = USER; CacheAceeAclId(item, offlineParam.needDelAclInfos); LOGI("Sink delete acl bindType %{public}u, localUdid %{public}s, remoteUdid %{public}s", item.GetBindType(), @@ -2177,8 +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.GetBindType() == DM_IDENTICAL_ACCOUNT); + offlineParam.targetAclHasUserLevelSet.insert( + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT)); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccessee().GetAccesseeBundleName(); processInfo.userId = acl.GetAccessee().GetAccesseeUserId(); @@ -2192,8 +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.GetBindType() == DM_IDENTICAL_ACCOUNT); + offlineParam.targetAclHasUserLevelSet.insert( + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT)); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName(); processInfo.userId = acl.GetAccesser().GetAccesserUserId(); @@ -2256,8 +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.GetBindType() == DM_IDENTICAL_ACCOUNT); + offlineParam.targetAclHasUserLevelSet.insert( + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT)); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccessee().GetAccesseeBundleName(); processInfo.userId = acl.GetAccessee().GetAccesseeUserId(); @@ -2274,8 +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.GetBindType() == DM_IDENTICAL_ACCOUNT); + offlineParam.targetAclHasUserLevelSet.insert( + (acl.GetBindLevel() == USER || acl.GetBindType() == DM_IDENTICAL_ACCOUNT)); ProcessInfo processInfo; processInfo.pkgName = acl.GetAccesser().GetAccesserBundleName(); processInfo.userId = acl.GetAccesser().GetAccesserUserId(); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 677601dab..8e310681a 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -3220,7 +3220,7 @@ void DeviceManagerServiceImpl::NotifyDeviceOrAppOffline(DmOfflineParam &offlineP LOGI("left user acl, not notify"); return; } - if (offlineParam.targetAclHasUserLevel && offlineParam.allUserAclInfos.empty() && + if (offlineParam.targetAclHasUserLevelSet.contain(true) && offlineParam.allUserAclInfos.empty() && !offlineParam.allLeftAppOrSvrAclInfos.empty()) { LOGI("left app or service acl."); ProcessInfo processInfo; @@ -3237,7 +3237,7 @@ void DeviceManagerServiceImpl::NotifyDeviceOrAppOffline(DmOfflineParam &offlineP softbusConnector_->HandleDeviceOffline(remoteUdid); return; } - if (!offlineParam.targetAclHasUserLevel && offlineParam.allUserAclInfos.empty() && + if (!offlineParam.targetAclHasUserLevelSet.contain(true) && offlineParam.allUserAclInfos.empty() && !offlineParam.allLeftAppOrSvrAclInfos.empty()) { LOGI("left user acl, not notify."); softbusConnector_->SetProcessInfoVec(offlineParam.processVec); -- Gitee From 9086554763cb72ffc13478baf153d9ad0b4d4789 Mon Sep 17 00:00:00 2001 From: s30044129 Date: Thu, 11 Sep 2025 23:22:47 +0800 Subject: [PATCH 4/7] =?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 --- common/src/dm_constants.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/src/dm_constants.cpp b/common/src/dm_constants.cpp index 7dfecbce4..73ed7a13c 100644 --- a/common/src/dm_constants.cpp +++ b/common/src/dm_constants.cpp @@ -189,8 +189,7 @@ const char* DM_VERSION_5_1_1 = "5.1.1"; const char* DM_VERSION_5_1_2 = "5.1.2"; const char* DM_VERSION_5_1_3 = "5.1.3"; const char* DM_VERSION_5_1_4 = "5.1.4"; -const char* DM_VERSION_5_1_5 = "5.1.5"; -const char* DM_CURRENT_VERSION = DM_VERSION_5_1_5; +const char* DM_CURRENT_VERSION = DM_VERSION_5_1_4; const char* DM_ACL_AGING_VERSION = DM_VERSION_5_1_0; const char* DM_VERSION_5_0_OLD_MAX = "5.0.99"; // Estimated highest version number of the old version const int32_t OLD_DM_HO_OSTYPE = -1; -- Gitee From cb156133da8c27febdcbfd2f17c905fb5c06c7f5 Mon Sep 17 00:00:00 2001 From: s30044129 Date: Thu, 11 Sep 2025 23:58:19 +0800 Subject: [PATCH 5/7] =?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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 8e310681a..8d52608ff 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -3220,7 +3220,8 @@ void DeviceManagerServiceImpl::NotifyDeviceOrAppOffline(DmOfflineParam &offlineP LOGI("left user acl, not notify"); return; } - if (offlineParam.targetAclHasUserLevelSet.contain(true) && offlineParam.allUserAclInfos.empty() && + if (offlineParam.targetAclHasUserLevelSet.find(true) != offlineParam.targetAclHasUserLevelSet.end() && + offlineParam.allUserAclInfos.empty() && !offlineParam.allLeftAppOrSvrAclInfos.empty()) { LOGI("left app or service acl."); ProcessInfo processInfo; @@ -3237,7 +3238,8 @@ void DeviceManagerServiceImpl::NotifyDeviceOrAppOffline(DmOfflineParam &offlineP softbusConnector_->HandleDeviceOffline(remoteUdid); return; } - if (!offlineParam.targetAclHasUserLevelSet.contain(true) && offlineParam.allUserAclInfos.empty() && + if (!offlineParam.targetAclHasUserLevelSet.find(true) != offlineParam.targetAclHasUserLevelSet.end() && + offlineParam.allUserAclInfos.empty() && !offlineParam.allLeftAppOrSvrAclInfos.empty()) { LOGI("left user acl, not notify."); softbusConnector_->SetProcessInfoVec(offlineParam.processVec); -- Gitee From 0c36e7b1ba860790f7370dec527499a4bbf1b018 Mon Sep 17 00:00:00 2001 From: s30044129 Date: Fri, 12 Sep 2025 00:02:57 +0800 Subject: [PATCH 6/7] =?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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 8d52608ff..4ba7eafd8 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -3238,7 +3238,7 @@ void DeviceManagerServiceImpl::NotifyDeviceOrAppOffline(DmOfflineParam &offlineP softbusConnector_->HandleDeviceOffline(remoteUdid); return; } - if (!offlineParam.targetAclHasUserLevelSet.find(true) != offlineParam.targetAclHasUserLevelSet.end() && + if (offlineParam.targetAclHasUserLevelSet.find(true) == offlineParam.targetAclHasUserLevelSet.end() && offlineParam.allUserAclInfos.empty() && !offlineParam.allLeftAppOrSvrAclInfos.empty()) { LOGI("left user acl, not notify."); -- Gitee From 05919988f223e5403f0c79c2b7ef83f8a1cd4ca5 Mon Sep 17 00:00:00 2001 From: s30044129 Date: Fri, 12 Sep 2025 15:10:15 +0800 Subject: [PATCH 7/7] =?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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 4fb72088b..3bb984db1 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -2104,7 +2104,7 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUse } if (item.GetAccesser().GetAccesserDeviceId() == localUdid && item.GetAccessee().GetAccesseeDeviceId() == remoteUdid && - (item.GetAccessee().GetAccesseeTokenId() == tokenId || tokenId == 0)) { + 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(), @@ -2114,7 +2114,7 @@ DM_EXPORT int32_t DeviceProfileConnector::HandleDevUnBindEvent(int32_t remoteUse } if (item.GetAccessee().GetAccesseeDeviceId() == localUdid && item.GetAccesser().GetAccesserDeviceId() == remoteUdid && - (item.GetAccesser().GetAccesserTokenId() == tokenId || tokenId == 0)) { + 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