diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 7b746adc91fd4672e0d2638e6f373600f62952aa..f8bf601d8b96bcab6de52763c154e1b1f4f05b68 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 e5cb7d3e132d2dc70b563fb2f965d1a3135887ff..38e4f6f908c7b97a67e4d596636d4edb629d62f4 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 c5b2c45e78685a00a9798512b3866fe28e15d1a0..711ac5866fe2f37f0841a5ecde7efc0052ee4ff7 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 2dc7efda681bd5fa30e3b7a912151375f648f910..3d42784f2aa18f074780477a071a85e7027062be 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 46fc347427cce6669bf75b84e4b482382b3d7187..08629c769f683c358ca9078e7d2bb88afb4e4ef1 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,