diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 1cd88b8d18450b361fb14c73bd5aa10d7078d5c5..c80118c1f01d3aebd0a3dbded5e64171a1e3d4ce 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; + std::unordered_set targetAclHasUserLevelSet; 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 49ec04f9f2578136af67d0279e13b68250aadf2e..3bb984db1fc8bd93475b76560f85e3f5f6fffc6a 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.targetAclHasUserLevelSet.insert( + (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.targetAclHasUserLevelSet.insert( + (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.targetAclHasUserLevelSet.insert( + (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.targetAclHasUserLevelSet.insert( + (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.targetAclHasUserLevelSet.insert( + (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.targetAclHasUserLevelSet.insert( + (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 13759a00d3000ce20f2c6c065eac5f6ddbe2e3de..533f2e99e387a001194db69193390a25c7bed37a 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 3fecede6b016de3f21413b8b090c206d0466e9ec..ac49f8de48da7ec154c3c165cb6ad82456db745d 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 54f5608cbaa13a383e71b74747e6f848bb0a7f92..4ba7eafd8d1b4ffcee61b69e06478be46a765475 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,40 @@ 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.targetAclHasUserLevelSet.find(true) != offlineParam.targetAclHasUserLevelSet.end() && + 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.targetAclHasUserLevelSet.find(true) == offlineParam.targetAclHasUserLevelSet.end() && + 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 b59957cc02cb3a3d6707e5a77f79b59a5a7fee8e..3e3c79bda129d6f74a2397dedbf544b4bf1ca946 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 b285a2d706b89b18e52f0504fdd257a9e3c6798c..303ada0fdaf38826083a3f241743f53e7296e00c 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, @@ -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, diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 08830f86f96369739066fecdcbad7e238870ba7f..6a8288af6951340d033689269c828b00fbeb3738 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 504ce2663d6e5b9599e9fecdef586febcfe6b5e3..1511cda47593ed8f2166c243866605dd7c9aec8b 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 f917117d4aa2a5fed7ead810c8b06ea515126196..149a53a5f9fa32eb64de08c896af0b9de920b304 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 450842cfae136eeb2d82b9f363d58699804f4085..ada7df79ae45abcfa06280f817af076147da683d 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 f9d2b234ee4c4e527cf53d16a4a7c6453ce359b1..fe4a018ee0b6ecfbe27fa9c4fec7631e163b9683 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 e44d72c59f8e456e7f64882c022b5c39d81e11b6..7199b45c03c2429daad14243240b7a3a99981924 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 603e20b2a48f7c8b48e37efc5d648bccd748d18c..8450d37b03dfd36c50385e547b33853886072c4c 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 17d9b9333d44c612de92d4b5f2367e9e07a1aff6..81d47bf85a4697743d072285f89fef49e495f54f 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));