diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 664c0ecfee1438783d3b532ccda07d07a1bd9f65..f4b605b81da4537383d85bdec539c986220576ec 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -95,6 +95,12 @@ class IDeviceProfileConnector { public: virtual ~IDeviceProfileConnector() {} virtual int32_t GetDeviceAclParam(DmDiscoveryInfo discoveryInfo, bool &isOnline, int32_t &authForm) = 0; + virtual std::map GetDeviceIdAndBindLevel(std::vector userIds, + const std::string &localUdid) = 0; + virtual int32_t HandleUserSwitched(const std::string &localUdid, const std::vector &deviceVec, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) = 0; + virtual bool CheckAclByUserId(const std::string &localUdid, std::vector foregroundUserIds, + std::vector backgroundUserIds) = 0; }; class DeviceProfileConnector : public IDeviceProfileConnector { @@ -153,6 +159,8 @@ public: void DeleteAccessControlById(int64_t accessControlId); int32_t HandleUserSwitched(const std::string &localUdid, const std::vector &deviceVec, int32_t currentUserId, int32_t beforeUserId); + int32_t HandleUserSwitched(const std::string &localUdid, const std::vector &deviceVec, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); void HandleSyncForegroundUserIdEvent(const std::vector &remoteUserIds, const std::string &remoteUdid, const std::vector &localUserIds, std::string &localUdid); std::vector GetOfflineProcessInfo(std::string &localUdid, const std::vector &localUserIds, @@ -172,6 +180,8 @@ public: int32_t UnSubscribeDeviceProfileInited(); int32_t PutAllTrustedDevices(const std::vector &deviceInfos); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); + bool CheckAclByUserId(const std::string &localUdid, std::vector foregroundUserIds, + std::vector backgroundUserIds); int32_t UpdateAclDeviceName(const std::string &udid, const std::string &newDeviceName); int32_t PutServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile); int32_t DeleteServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoUniqueKey &key); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 1f7b7689e85782fa6baba7037357230321458e6b..13519bd678014b656e0eaaa29c745c91dd2389dd 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -1274,6 +1274,32 @@ OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppUnBindEv return processInfo; } +bool DeviceProfileConnector::CheckAclByUserId(const std::string &localUdid, std::vector foregroundUserIds, + std::vector backgroundUserIds) +{ + std::vector profiles = GetAllAccessControlProfile(); + LOGI("CheckAclByUserId profiles size is %{public}zu", profiles.size()); + for (auto &item : profiles) { + if ((item.GetAccesser().GetAccesserDeviceId() == localUdid && + (find(backgroundUserIds.begin(), backgroundUserIds.end(), + item.GetAccesser().GetAccesserUserId()) != backgroundUserIds.end()) && item.GetStatus() == ACTIVE) || + (item.GetAccessee().GetAccesseeDeviceId() == localUdid && + (find(backgroundUserIds.begin(), backgroundUserIds.end(), + item.GetAccessee().GetAccesseeUserId()) != backgroundUserIds.end()) && item.GetStatus() == ACTIVE)) { + return true; + } + if ((item.GetAccesser().GetAccesserDeviceId() == localUdid && + (find(foregroundUserIds.begin(), foregroundUserIds.end(), + item.GetAccesser().GetAccesserUserId()) != foregroundUserIds.end()) && item.GetStatus() == INACTIVE) || ( + item.GetAccessee().GetAccesseeDeviceId() == localUdid && + (find(foregroundUserIds.begin(), foregroundUserIds.end(), + item.GetAccessee().GetAccesseeUserId()) != foregroundUserIds.end()) && item.GetStatus() == INACTIVE)) { + return true; + } + } + return false; +} + std::vector DeviceProfileConnector::GetAllAccessControlProfile() { std::vector profiles; @@ -1331,6 +1357,55 @@ int32_t DeviceProfileConnector::HandleUserSwitched(const std::string &localUdid, return DM_OK; } +int32_t DeviceProfileConnector::HandleUserSwitched(const std::string &localUdid, + const std::vector &deviceVec, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds) +{ + LOGI("OnStart HandleUserSwitched"); + if (deviceVec.empty()) { + LOGI("no remote device."); + return DM_OK; + } + std::vector profiles = GetAllAccessControlProfile(); + std::vector activeProfiles; + std::vector inActiveProfiles; + for (auto &item : profiles) { + if (std::find(deviceVec.begin(), deviceVec.end(), item.GetTrustDeviceId()) == deviceVec.end()) { + continue; + } + if ((item.GetAccesser().GetAccesserDeviceId() == localUdid && + (find(backgroundUserIds.begin(), backgroundUserIds.end(), + item.GetAccesser().GetAccesserUserId()) != backgroundUserIds.end()) && item.GetStatus() == ACTIVE) || + (item.GetAccessee().GetAccesseeDeviceId() == localUdid && + (find(backgroundUserIds.begin(), backgroundUserIds.end(), + item.GetAccessee().GetAccesseeUserId()) != backgroundUserIds.end()) && item.GetStatus() == ACTIVE)) { + item.SetStatus(INACTIVE); + inActiveProfiles.push_back(item); + continue; + } + if ((item.GetAccesser().GetAccesserDeviceId() == localUdid && + (find(foregroundUserIds.begin(), foregroundUserIds.end(), + item.GetAccesser().GetAccesserUserId()) != foregroundUserIds.end()) && item.GetStatus() == INACTIVE) || ( + item.GetAccessee().GetAccesseeDeviceId() == localUdid && + (find(foregroundUserIds.begin(), foregroundUserIds.end(), + item.GetAccessee().GetAccesseeUserId()) != foregroundUserIds.end()) && item.GetStatus() == INACTIVE)) { + item.SetStatus(ACTIVE); + activeProfiles.push_back(item); + continue; + } + } + for (auto &item : inActiveProfiles) { + DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); + if (item.GetBindType() != DM_IDENTICAL_ACCOUNT) { + DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + } + } + for (auto &item : activeProfiles) { + DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); + } + return DM_OK; +} + std::vector DeviceProfileConnector::GetAclProfileByUserId(const std::string &localUdid, int32_t userId, const std::string &remoteUdid) { diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 3e9718169fd5f8f52e37f84c0f94ee3ac76978d2..60cda6da3b3e5323720e896afab358b6025da206 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -302,6 +302,17 @@ private: int32_t SendUserIdsByWifi(const std::string &networkId, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); void HandleUserSwitchTimeout(int32_t curUserId, int32_t preUserId, const std::string &udid); + + void HandleUserSwitched(); + void NotifyRemoteLocalUserSwitch(const std::string &localUdid, const std::vector &peerUdids, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); + void NotifyRemoteLocalUserSwitchByWifi(const std::string &localUdid, + const std::map &wifiDevices, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds); + void HandleUserSwitchTimeout(const std::string &localUdid, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds, const std::string &udid); + void UpdateAclAndDeleteGroup(const std::string &localUdid, const std::vector &deviceVec, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); bool InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile); void InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo &serviceInfo); diff --git a/services/service/include/hichain/hichain_listener.h b/services/service/include/hichain/hichain_listener.h index 0adb7b0c6cc125d635481a063b548a21e6972f8d..7eab49cd04e44183da9a106e3f828fda2ef0adb0 100644 --- a/services/service/include/hichain/hichain_listener.h +++ b/services/service/include/hichain/hichain_listener.h @@ -38,15 +38,36 @@ struct GroupInformation { } }; -void from_json(const nlohmann::json &jsonObject, GroupInformation &groupInfo); +struct GroupsInfo { + std::string groupName; + std::string groupId; + std::string groupOwner; + int32_t groupType; + int32_t groupVisibility; + std::string userId; + GroupsInfo() : groupName(""), groupId(""), groupOwner(""), groupType(0), groupVisibility(0), userId("") + { + } +}; + +void from_json(const nlohmann::json &jsonObject, GroupInformation &groupInfo); +void from_json(const nlohmann::json &jsonObject, GroupsInfo &groupInfo); class HichainListener { public: HichainListener(); ~HichainListener(); void RegisterDataChangeCb(); static void OnHichainDeviceUnBound(const char *peerUdid, const char *groupInfo); - + void DeleteAllGroup(const std::string &localUdid, const std::vector &backgroundUserIds); + int32_t GetRelatedGroups(int32_t userId, const std::string &deviceId, + std::vector &groupList); + int32_t GetRelatedGroupsCommon(int32_t userId, const std::string &deviceId, const char* pkgName, + std::vector &groupList); + int32_t DeleteGroup(const int32_t userId, std::string &groupId); + int32_t GetRelatedGroupsExt(int32_t userId, const std::string &deviceId, std::vector &groupList); + int32_t DeleteGroupExt(int32_t userId, std::string &groupId); + int64_t GenRequestId(); private: const DeviceGroupManager *deviceGroupManager_ = nullptr; }; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 04f369cf722148a95701a1b0d3cbaa6b6a68c31f..80175fb3709a1f0a49a83f238beeea47fd5d44ab 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1936,6 +1936,7 @@ void DeviceManagerService::AccountCommonEventCallback(const std::string commonEv dmAccountInfo.accountName = MultipleUserConnector::GetOhosAccountName(); MultipleUserConnector::SetAccountInfo(currentUserId, dmAccountInfo); if (beforeUserId == -1 || currentUserId == -1) { + HandleUserSwitched(); return; } else if (beforeUserId != -1 && currentUserId != -1) { HandleUserSwitched(currentUserId, beforeUserId); @@ -2045,6 +2046,152 @@ void DeviceManagerService::HandleUserSwitched(int32_t curUserId, int32_t preUser NotifyRemoteLocalUserSwitch(curUserId, preUserId, peerUdids, foregroundUserVec, backgroundUserVec); } +void DeviceManagerService::HandleUserSwitched() +{ + LOGI("onStart, HandleUserSwitched."); + std::vector foregroundUserVec; + foregroundUserVec.clear(); + int32_t retFront = MultipleUserConnector::GetForegroundUserIds(foregroundUserVec); + std::vector backgroundUserVec; + backgroundUserVec.clear(); + int32_t retBack = MultipleUserConnector::GetBackgroundUserIds(backgroundUserVec); + if (retFront != DM_OK || retBack != DM_OK || foregroundUserVec.empty()) { + LOGE("Get userids failed, retFront: %{public}d, retBack: %{public}d, foreground user num: %{public}d", + retFront, retBack, static_cast(foregroundUserVec.size())); + return; + } + char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); + std::string localUdid = std::string(localUdidTemp); + std::map curUserDeviceMap; + std::map preUserDeviceMap; + std::vector peerUdids; + CHECK_NULL_VOID(discoveryMgr_); + if (!discoveryMgr_->IsCommonDependencyReady() || discoveryMgr_->GetCommonDependencyObj() == nullptr) { + LOGE("IsCommonDependencyReady failed or GetCommonDependencyObj() is nullptr."); + return; + } + + if (!discoveryMgr_->GetCommonDependencyObj()->CheckAclByUserId(localUdid, foregroundUserVec, backgroundUserVec)) { + LOGI("no unreasonable data."); + return; + } + + curUserDeviceMap = discoveryMgr_->GetCommonDependencyObj()->GetDeviceIdAndBindLevel(foregroundUserVec, localUdid); + preUserDeviceMap = discoveryMgr_->GetCommonDependencyObj()->GetDeviceIdAndBindLevel(backgroundUserVec, localUdid); + for (const auto &item : curUserDeviceMap) { + peerUdids.push_back(item.first); + } + for (const auto &item : preUserDeviceMap) { + if (find(peerUdids.begin(), peerUdids.end(), item.first) == peerUdids.end()) { + peerUdids.push_back(item.first); + } + } + if (peerUdids.empty()) { + return; + } + NotifyRemoteLocalUserSwitch(localUdid, peerUdids, foregroundUserVec, backgroundUserVec); +} + +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +void DeviceManagerService::NotifyRemoteLocalUserSwitch(const std::string &localUdid, + const std::vector &peerUdids, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds) +{ + LOGI("onstart UserSwitch, foregroundUserIds: %{public}s, backgroundUserIds: %{public}s", + GetIntegerList(foregroundUserIds).c_str(), GetIntegerList(backgroundUserIds).c_str()); + if (peerUdids.empty()) { + return; + } + if (softbusListener_ == nullptr) { + UpdateAclAndDeleteGroup(localUdid, peerUdids, foregroundUserIds, backgroundUserIds); + LOGE("softbusListener_ is null"); + return; + } + std::vector bleUdids; + std::map wifiDevices; + for (const auto &udid : peerUdids) { + std::string netWorkId = ""; + SoftbusCache::GetInstance().GetNetworkIdFromCache(udid, netWorkId); + if (netWorkId.empty()) { + LOGI("netWorkId is empty: %{public}s", GetAnonyString(udid).c_str()); + bleUdids.push_back(udid); + continue; + } + int32_t networkType = 0; + int32_t ret = softbusListener_->GetNetworkTypeByNetworkId(netWorkId.c_str(), networkType); + if (ret != DM_OK || networkType <= 0) { + LOGI("get networkType failed: %{public}s", GetAnonyString(udid).c_str()); + bleUdids.push_back(udid); + continue; + } + if ((static_cast(networkType) & USERID_SYNC_DISCOVERY_TYPE_BLE_MASK) != 0x0) { + bleUdids.push_back(udid); + } else { + wifiDevices.insert(std::pair(udid, netWorkId)); + } + } + if (!bleUdids.empty()) { + UpdateAclAndDeleteGroup(localUdid, peerUdids, foregroundUserIds, backgroundUserIds); + SendUserIdsBroadCast(bleUdids, foregroundUserIds, backgroundUserIds, true); + } + if (!wifiDevices.empty()) { + NotifyRemoteLocalUserSwitchByWifi(localUdid, wifiDevices, foregroundUserIds, backgroundUserIds); + } +} + +void DeviceManagerService::NotifyRemoteLocalUserSwitchByWifi(const std::string &localUdid, + const std::map &wifiDevices, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds) +{ + for (const auto &it : wifiDevices) { + int32_t result = SendUserIdsByWifi(it.second, foregroundUserIds, backgroundUserIds); + if (result != DM_OK) { + LOGE("by wifi failed: %{public}s", GetAnonyString(it.first).c_str()); + std::vector updateUdids; + updateUdids.push_back(it.first); + UpdateAclAndDeleteGroup(localUdid, updateUdids, foregroundUserIds, backgroundUserIds); + continue; + } + if (timer_ == nullptr) { + timer_ = std::make_shared(); + } + std::string udid = it.first; + timer_->StartTimer(std::string(USER_SWITCH_BY_WIFI_TIMEOUT_TASK) + Crypto::Sha256(udid), + USER_SWITCH_BY_WIFI_TIMEOUT_S, + [this, localUdid, foregroundUserIds, backgroundUserIds, udid] (std::string name) { + DeviceManagerService::HandleUserSwitchTimeout(localUdid, foregroundUserIds, backgroundUserIds, udid); + }); + } +} + +void DeviceManagerService::HandleUserSwitchTimeout(const std::string &localUdid, + const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, + const std::string &udid) +{ + LOGI("start udid: %{public}s", GetAnonyString(udid).c_str()); + std::vector updateUdids; + updateUdids.push_back(udid); + UpdateAclAndDeleteGroup(localUdid, updateUdids, foregroundUserIds, backgroundUserIds); +} + +void DeviceManagerService::UpdateAclAndDeleteGroup(const std::string &localUdid, + const std::vector &deviceVec, const std::vector &foregroundUserIds, + const std::vector &backgroundUserIds) +{ + CHECK_NULL_VOID(discoveryMgr_); + if (!discoveryMgr_->IsCommonDependencyReady() || discoveryMgr_->GetCommonDependencyObj() == nullptr) { + LOGE("IsCommonDependencyReady failed or GetCommonDependencyObj() is nullptr."); + return; + } + discoveryMgr_->GetCommonDependencyObj()->HandleUserSwitched(localUdid, deviceVec, + foregroundUserIds, backgroundUserIds); + //delete group + CHECK_NULL_VOID(hichainListener_); + hichainListener_->DeleteAllGroup(localUdid, backgroundUserIds); +} +#endif + void DeviceManagerService::HandleUserRemoved(int32_t removedUserId) { LOGI("PreUserId %{public}d.", removedUserId); diff --git a/services/service/src/hichain/hichain_listener.cpp b/services/service/src/hichain/hichain_listener.cpp index a4422fa7449384dc0adefaa7115c8f094d13faf6..39c8c99d67621a990531910bdc93dd9bbd733501 100644 --- a/services/service/src/hichain/hichain_listener.cpp +++ b/services/service/src/hichain/hichain_listener.cpp @@ -19,6 +19,7 @@ #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_log.h" +#include "dm_random.h" #include "multiple_user_connector.h" namespace OHOS { @@ -27,6 +28,7 @@ namespace DistributedHardware { namespace { constexpr uint32_t MAX_DATA_LEN = 65536; constexpr uint32_t DM_IDENTICAL_ACCOUNT = 1; + constexpr const char* DM_PKG_NAME_EXT = "com.huawei.devicemanager"; } static DataChangeListener dataChangeListener_ = { @@ -49,6 +51,34 @@ void from_json(const nlohmann::json &jsonObject, GroupInformation &groupInfo) } } +void from_json(const nlohmann::json &jsonObject, GroupsInfo &groupInfo) +{ + if (jsonObject.find(FIELD_GROUP_NAME) != jsonObject.end() && jsonObject.at(FIELD_GROUP_NAME).is_string()) { + groupInfo.groupName = jsonObject.at(FIELD_GROUP_NAME).get(); + } + + if (jsonObject.find(FIELD_GROUP_ID) != jsonObject.end() && jsonObject.at(FIELD_GROUP_ID).is_string()) { + groupInfo.groupId = jsonObject.at(FIELD_GROUP_ID).get(); + } + + if (jsonObject.find(FIELD_GROUP_OWNER) != jsonObject.end() && jsonObject.at(FIELD_GROUP_OWNER).is_string()) { + groupInfo.groupOwner = jsonObject.at(FIELD_GROUP_OWNER).get(); + } + + if (jsonObject.find(FIELD_GROUP_TYPE) != jsonObject.end() && jsonObject.at(FIELD_GROUP_TYPE).is_number_integer()) { + groupInfo.groupType = jsonObject.at(FIELD_GROUP_TYPE).get(); + } + + if (jsonObject.find(FIELD_GROUP_VISIBILITY) != jsonObject.end() && + jsonObject.at(FIELD_GROUP_VISIBILITY).is_number_integer()) { + groupInfo.groupVisibility = jsonObject.at(FIELD_GROUP_VISIBILITY).get(); + } + + if (jsonObject.find(FIELD_USER_ID) != jsonObject.end() && jsonObject.at(FIELD_USER_ID).is_string()) { + groupInfo.userId = jsonObject.at(FIELD_USER_ID).get(); + } +} + HichainListener::HichainListener() { LOGI("HichainListener constructor start."); @@ -111,5 +141,127 @@ void HichainListener::OnHichainDeviceUnBound(const char *peerUdid, const char *g return; } } + +void HichainListener::DeleteAllGroup(const std::string &localUdid, const std::vector &backgroundUserIds) +{ + LOGI("OnStart HichainListener::DeleteAllGroup"); + for (auto &userId : backgroundUserIds) { + std::vector groupList; + GetRelatedGroups(userId, localUdid, groupList); + for (auto &iter : groupList) { + if (iter.groupType == GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP) { + continue; + } + if (DeleteGroup(userId, iter.groupId) != DM_OK) { + LOGE("Delete groupId %{public}s failed.", GetAnonyString(iter.groupId).c_str()); + } + } + std::vector groupListExt; + GetRelatedGroupsExt(userId, localUdid, groupListExt); + for (auto &iter : groupListExt) { + if (iter.groupType == GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP) { + continue; + } + if (DeleteGroupExt(userId, iter.groupId) != DM_OK) { + LOGE("DeleteGroupExt groupId %{public}s failed.", GetAnonyString(iter.groupId).c_str()); + } + } + } +} + +int32_t HichainListener::GetRelatedGroups(int32_t userId, const std::string &deviceId, + std::vector &groupList) +{ + return GetRelatedGroupsCommon(userId, deviceId, DM_PKG_NAME, groupList); +} + +int32_t HichainListener::GetRelatedGroupsExt(int32_t userId, const std::string &deviceId, + std::vector &groupList) +{ + return GetRelatedGroupsCommon(userId, deviceId, DM_PKG_NAME_EXT, groupList); +} + +int32_t HichainListener::GetRelatedGroupsCommon(int32_t userId, const std::string &deviceId, const char* pkgName, + std::vector &groupList) +{ + LOGI("Start to get related groups."); + if (userId < 0) { + LOGE("user id failed"); + return ERR_DM_FAILED; + } + uint32_t groupNum = 0; + char *returnGroups = nullptr; + int32_t ret = + deviceGroupManager_->getRelatedGroups(userId, pkgName, deviceId.c_str(), &returnGroups, &groupNum); + if (ret != 0) { + LOGE("[HICHAIN] fail to get related groups with ret:%{public}d.", ret); + deviceGroupManager_->destroyInfo(&returnGroups); + return ERR_DM_FAILED; + } + if (returnGroups == nullptr) { + LOGE("[HICHAIN] return related goups point is nullptr"); + return ERR_DM_FAILED; + } + if (groupNum == 0) { + LOGE("[HICHAIN]return related goups number is zero."); + deviceGroupManager_->destroyInfo(&returnGroups); + return ERR_DM_FAILED; + } + std::string relatedGroups = std::string(returnGroups); + deviceGroupManager_->destroyInfo(&returnGroups); + nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups, nullptr, false); + if (jsonObject.is_discarded()) { + LOGE("returnGroups parse error"); + return ERR_DM_FAILED; + } + if (!jsonObject.is_array()) { + LOGE("jsonObject is not an array."); + return ERR_DM_FAILED; + } + std::vector groupInfos = jsonObject.get>(); + if (groupInfos.empty()) { + LOGE("HichainListener::GetRelatedGroups group failed, groupInfos is empty."); + return ERR_DM_FAILED; + } + groupList = groupInfos; + return DM_OK; +} + +int64_t HichainListener::GenRequestId() +{ + return GenRandLongLong(MIN_REQUEST_ID, MAX_REQUEST_ID); +} + +int32_t HichainListener::DeleteGroup(const int32_t userId, std::string &groupId) +{ + if (userId < 0) { + LOGE("user id failed"); + return ERR_DM_FAILED; + } + 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, 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 HichainListener::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; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file