From 853f91f85e010090d97bf4577d26def8a4f03a78 Mon Sep 17 00:00:00 2001 From: liuzhongming Date: Thu, 19 Dec 2024 19:59:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=A0=E9=99=A4=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=BE=A4=E7=BB=84=20Signed-off-by:=20liuzhongming=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/deviceprofile_connector.h | 1 + .../src/deviceprofile_connector.cpp | 25 +++++++++++++++++ .../dependency/hichain/hichain_connector.h | 2 ++ .../dependency/hichain/hichain_connector.cpp | 28 ++++++++++++++++--- .../src/device_manager_service_impl.cpp | 12 ++++++-- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 7b746adc9..f8bf601d8 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -113,6 +113,7 @@ public: bool DeleteAclForAccountLogOut(const std::string &localUdid, int32_t localUserId, const std::string &peerUdid, int32_t peerUserId); void DeleteAclForUserRemoved(std::string localUdid, int32_t userId); + void DeleteAclForRemoteUserRemoved(std::string peerUdid, int32_t peerUserId, std::vector &userIds); DmOfflineParam DeleteAccessControlList(const std::string &pkgName, const std::string &localDeviceId, const std::string &remoteDeviceId, int32_t bindLevel); std::vector GetProcessInfoFromAclByUserId(const std::string &localDeviceId, diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index e5cb7d3e1..38e4f6f90 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -512,6 +512,31 @@ void DeviceProfileConnector::DeleteAclForUserRemoved(std::string localUdid, int3 } } +void DeviceProfileConnector::DeleteAclForRemoteUserRemoved(std::string peerUdid, int32_t peerUserId, + std::vector &userIds) +{ + LOGI("peerUdid %{public}s, peerUserId %{public}d.", GetAnonyString(peerUdid).c_str(), peerUserId); + std::vector profiles = GetAccessControlProfileByUserId(peerUserId); + for (const auto &item : profiles) { + std::string accesserUdid = item.GetAccesser().GetAccesserDeviceId(); + std::string accesseeUdid = item.GetAccessee().GetAccesseeDeviceId(); + int32_t accesserUserId = item.GetAccesser().GetAccesserUserId(); + int32_t accesseeUserId = item.GetAccessee().GetAccesseeUserId(); + if (accesserUdid == peerUdid && accesserUserId == peerUserId) { + DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + if (item.GetBindLevel() == DEVICE) { + userIds.push_back(accesseeUserId); + } + } + if (accesseeUdid == peerUdid && accesseeUserId == peerUserId) { + DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + if (item.GetBindLevel() == DEVICE) { + userIds.push_back(accesserUserId); + } + } + } +} + void DeviceProfileConnector::DeleteAccessControlList(const std::string &udid) { LOGI("Udid: %{public}s.", GetAnonyString(udid).c_str()); diff --git a/services/implementation/include/dependency/hichain/hichain_connector.h b/services/implementation/include/dependency/hichain/hichain_connector.h index c5b2c45e7..711ac5866 100644 --- a/services/implementation/include/dependency/hichain/hichain_connector.h +++ b/services/implementation/include/dependency/hichain/hichain_connector.h @@ -234,8 +234,10 @@ public: void DeleteAllGroup(int32_t userId); int32_t GetRelatedGroups(int32_t userId, const std::string &deviceId, std::vector &groupList); int32_t GetRelatedGroupsExt(const std::string &deviceId, std::vector &groupList); + int32_t GetRelatedGroupsExt(int32_t userId, const std::string &deviceId, std::vector &groupList); int32_t DeleteGroupExt(std::string &groupId); + int32_t DeleteGroupExt(int32_t userId, std::string &groupId); int32_t GetRelatedGroupsCommon(const std::string &deviceId, const char* pkgName, std::vector &groupList); diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index 2dc7efda6..3d42784f2 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -530,6 +530,12 @@ int32_t HiChainConnector::GetRelatedGroupsExt(const std::string &deviceId, std:: return GetRelatedGroupsCommon(deviceId, DM_PKG_NAME_EXT, groupList); } +int32_t HiChainConnector::GetRelatedGroupsExt(int32_t userId, const std::string &deviceId, + std::vector &groupList) +{ + return GetRelatedGroupsCommon(userId, deviceId, DM_PKG_NAME_EXT, groupList); +} + int32_t HiChainConnector::GetSyncGroupList(std::vector &groupList, std::vector &syncGroupList) { if (groupList.empty()) { @@ -656,6 +662,20 @@ int32_t HiChainConnector::DeleteGroupExt(std::string &groupId) return DM_OK; } +int32_t HiChainConnector::DeleteGroupExt(int32_t userId, std::string &groupId) +{ + int64_t requestId = GenRequestId(); + nlohmann::json jsonObj; + jsonObj[FIELD_GROUP_ID] = groupId; + std::string disbandParams = SafetyDump(jsonObj); + int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME_EXT, disbandParams.c_str()); + if (ret != 0) { + LOGE("[HICHAIN]fail to delete group with ret:%{public}d.", ret); + return ERR_DM_FAILED; + } + return DM_OK; +} + int32_t HiChainConnector::DeleteGroup(int64_t requestId_, const std::string &userId, const int32_t authType) { networkStyle_ = CREDENTIAL_NETWORK; @@ -1090,16 +1110,16 @@ void HiChainConnector::DeleteAllGroup(int32_t userId) GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); std::string localUdid = static_cast(localDeviceId); std::vector groupList; - GetRelatedGroups(localUdid, groupList); + GetRelatedGroups(userId, localUdid, groupList); for (auto &iter : groupList) { - if (DeleteGroup(iter.groupId) != DM_OK) { + if (DeleteGroup(userId, iter.groupId) != DM_OK) { LOGE("Delete groupId %{public}s failed.", GetAnonyString(iter.groupId).c_str()); } } std::vector groupListExt; - GetRelatedGroupsExt(localUdid, groupListExt); + GetRelatedGroupsExt(userId, localUdid, groupListExt); for (auto &iter : groupListExt) { - if (DeleteGroupExt(iter.groupId) != DM_OK) { + if (DeleteGroupExt(userId, iter.groupId) != DM_OK) { LOGE("DeleteGroupExt groupId %{public}s failed.", GetAnonyString(iter.groupId).c_str()); } } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 46fc34742..08629c769 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -672,9 +672,17 @@ void DeviceManagerServiceImpl::HandleUserRemoved(int32_t preUserId) void DeviceManagerServiceImpl::HandleRemoteUserRemoved(int32_t userId, const std::string &remoteUdid) { LOGI("remoteUdid %{public}s, userId %{public}d", GetAnonyString(remoteUdid).c_str(), userId); - DeviceProfileConnector::GetInstance().DeleteAclForUserRemoved(remoteUdid, userId); + std::vector localUserIds; + DeviceProfileConnector::GetInstance().DeleteAclForRemoteUserRemoved(remoteUdid, userId, localUserIds); + if (localUserIds.empty()) { + return; + } CHECK_NULL_VOID(hiChainConnector_); - hiChainConnector_->DeleteAllGroup(userId); + std::vector> delInfoVec; + for (int32_t localUserId : localUserIds) { + delInfoVec.push_back(std::pair(localUserId, remoteUdid)); + } + hiChainConnector_->DeleteGroupByACL(delInfoVec, localUserIds); } void DeviceManagerServiceImpl::HandleUserSwitched(const std::vector &deviceVec, -- Gitee