• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "hichain_connector.h"
17 
18 #include <securec.h>
19 
20 #include <cstdlib>
21 #include <ctime>
22 #include <functional>
23 
24 #include "dm_anonymous.h"
25 #include "dm_constants.h"
26 #include "dm_log.h"
27 #include "dm_random.h"
28 #include "hichain_connector_callback.h"
29 #include "multiple_user_connector.h"
30 #include "nlohmann/json.hpp"
31 #include "parameter.h"
32 
33 namespace OHOS {
34 namespace DistributedHardware {
from_json(const nlohmann::json & jsonObject,GroupInfo & groupInfo)35 void from_json(const nlohmann::json &jsonObject, GroupInfo &groupInfo)
36 {
37     if (jsonObject.find(FIELD_GROUP_NAME) != jsonObject.end()) {
38         groupInfo.groupName = jsonObject.at(FIELD_GROUP_NAME).get<std::string>();
39     }
40 
41     if (jsonObject.find(FIELD_GROUP_ID) != jsonObject.end()) {
42         groupInfo.groupId = jsonObject.at(FIELD_GROUP_ID).get<std::string>();
43     }
44 
45     if (jsonObject.find(FIELD_GROUP_OWNER) != jsonObject.end()) {
46         groupInfo.groupOwner = jsonObject.at(FIELD_GROUP_OWNER).get<std::string>();
47     }
48 
49     if (jsonObject.find(FIELD_GROUP_TYPE) != jsonObject.end()) {
50         groupInfo.groupType = jsonObject.at(FIELD_GROUP_TYPE).get<int32_t>();
51     }
52 
53     if (jsonObject.find(FIELD_GROUP_VISIBILITY) != jsonObject.end()) {
54         groupInfo.groupVisibility = jsonObject.at(FIELD_GROUP_VISIBILITY).get<int32_t>();
55     }
56 }
57 
58 std::shared_ptr<IHiChainConnectorCallback> HiChainConnector::hiChainConnectorCallback_ = nullptr;
59 
HiChainConnector()60 HiChainConnector::HiChainConnector()
61 {
62     LOGI("HiChainConnector::constructor");
63     deviceAuthCallback_ = {.onTransmit = nullptr,
64                            .onFinish = HiChainConnector::onFinish,
65                            .onError = HiChainConnector::onError,
66                            .onRequest = HiChainConnector::onRequest};
67     InitDeviceAuthService();
68     deviceGroupManager_ = GetGmInstance();
69     if (deviceGroupManager_ == nullptr) {
70         LOGI("HiChainConnector::constructor, failed to init group manager!");
71         return;
72     }
73     deviceGroupManager_->regCallback(DM_PKG_NAME.c_str(), &deviceAuthCallback_);
74     LOGI("HiChainConnector::constructor success.");
75 }
76 
~HiChainConnector()77 HiChainConnector::~HiChainConnector()
78 {
79     LOGI("HiChainConnector::destructor.");
80 }
81 
RegisterHiChainCallback(std::shared_ptr<IHiChainConnectorCallback> callback)82 int32_t HiChainConnector::RegisterHiChainCallback(std::shared_ptr<IHiChainConnectorCallback> callback)
83 {
84     hiChainConnectorCallback_ = callback;
85     return DM_OK;
86 }
87 
UnRegisterHiChainCallback()88 int32_t HiChainConnector::UnRegisterHiChainCallback()
89 {
90     hiChainConnectorCallback_ = nullptr;
91     return DM_OK;
92 }
93 
CreateGroup(int64_t requestId,const std::string & groupName)94 int32_t HiChainConnector::CreateGroup(int64_t requestId, const std::string &groupName)
95 {
96     if (deviceGroupManager_ == nullptr) {
97         LOGE("HiChainConnector::CreateGroup group manager is null, requestId %lld.", requestId);
98         return DM_INVALID_VALUE;
99     }
100     GroupInfo groupInfo;
101     if (IsGroupCreated(groupName, groupInfo)) {
102         DeleteGroup(groupInfo.groupId);
103     }
104     LOGI("HiChainConnector::CreateGroup requestId %lld", requestId);
105     char localDeviceId[DEVICE_UUID_LENGTH] = {0};
106     GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
107     std::string sLocalDeviceID = localDeviceId;
108     nlohmann::json jsonObj;
109     jsonObj[FIELD_GROUP_TYPE] = GROUP_TYPE_PEER_TO_PEER_GROUP;
110     jsonObj[FIELD_DEVICE_ID] = sLocalDeviceID;
111     jsonObj[FIELD_GROUP_NAME] = groupName;
112     jsonObj[FIELD_USER_TYPE] = 0;
113     jsonObj[FIELD_GROUP_VISIBILITY] = GROUP_VISIBILITY_PUBLIC;
114     jsonObj[FIELD_EXPIRE_TIME] = FIELD_EXPIRE_TIME_VALUE;
115     int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
116     if (userId < 0) {
117         LOGE("get current process account user id failed");
118         return DM_FAILED;
119     }
120 
121     int32_t ret = deviceGroupManager_->createGroup(userId, requestId, DM_PKG_NAME.c_str(), jsonObj.dump().c_str());
122     if (ret != 0) {
123         LOGE("Failed to start CreateGroup task, ret: %d, requestId %lld.", ret, requestId);
124         return DM_HICHAIN_GROUP_CREATE_FAILED;
125     }
126     return DM_OK;
127 }
128 
IsGroupCreated(std::string groupName,GroupInfo & groupInfo)129 bool HiChainConnector::IsGroupCreated(std::string groupName, GroupInfo &groupInfo)
130 {
131     nlohmann::json jsonObj;
132     jsonObj[FIELD_GROUP_NAME] = groupName.c_str();
133     std::string queryParams = jsonObj.dump();
134     std::vector<GroupInfo> groupList;
135     if (GetGroupInfo(queryParams, groupList)) {
136         groupInfo = groupList[0];
137         return true;
138     }
139     return false;
140 }
141 
GetGroupInfo(const std::string & queryParams,std::vector<GroupInfo> & groupList)142 bool HiChainConnector::GetGroupInfo(const std::string &queryParams, std::vector<GroupInfo> &groupList)
143 {
144     char *groupVec = nullptr;
145     uint32_t num = 0;
146     int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
147     if (userId < 0) {
148         LOGE("get current process account user id failed");
149         return false;
150     }
151     int32_t ret = deviceGroupManager_->getGroupInfo(userId, DM_PKG_NAME.c_str(), queryParams.c_str(), &groupVec, &num);
152     if (ret != 0) {
153         LOGE("HiChainConnector::GetGroupInfo failed , ret: %d.", ret);
154         return false;
155     }
156     if (groupVec == nullptr) {
157         LOGE("HiChainConnector::GetGroupInfo failed , returnGroups is nullptr");
158         return false;
159     }
160     if (num == 0) {
161         LOGE("HiChainConnector::GetGroupInfo group failed, groupNum is 0.");
162         return false;
163     }
164     LOGI("HiChainConnector::GetGroupInfo group(%s), groupNum(%u)", groupVec, num);
165     std::string relatedGroups = std::string(groupVec);
166     deviceGroupManager_->destroyInfo(&groupVec);
167     nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups);
168     if (jsonObject.is_discarded()) {
169         LOGE("returnGroups parse error");
170         return false;
171     }
172     std::vector<GroupInfo> groupInfos = jsonObject.get<std::vector<GroupInfo>>();
173     if (groupInfos.size() == 0) {
174         LOGE("HiChainConnector::GetGroupInfo group failed, groupInfos is empty.");
175         return false;
176     }
177     groupList = groupInfos;
178     return true;
179 }
180 
GetGroupInfo(const int32_t userId,std::string queryParams,std::vector<GroupInfo> & groupList)181 int32_t HiChainConnector::GetGroupInfo(const int32_t userId, std::string queryParams, std::vector<GroupInfo> &groupList)
182 {
183     char *groupVec = nullptr;
184     uint32_t num = 0;
185     int32_t ret = deviceGroupManager_->getGroupInfo(userId, DM_PKG_NAME.c_str(), queryParams.c_str(), &groupVec, &num);
186     if (ret != 0) {
187         LOGE("HiChainConnector::GetGroupInfo failed , ret: %d.", ret);
188         return false;
189     }
190     if (groupVec == nullptr) {
191         LOGE("HiChainConnector::GetGroupInfo failed , returnGroups is nullptr.");
192         return false;
193     }
194     if (num == 0) {
195         LOGE("HiChainConnector::GetGroupInfo group failed, groupNum is 0.");
196         return false;
197     }
198     LOGI("HiChainConnector::GetGroupInfo group(%s), groupNum(%d)", groupVec, num);
199     std::string relatedGroups = std::string(groupVec);
200     deviceGroupManager_->destroyInfo(&groupVec);
201     nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups);
202     if (jsonObject.is_discarded()) {
203         LOGE("returnGroups parse error");
204         return false;
205     }
206     std::vector<GroupInfo> groupInfos = jsonObject.get<std::vector<GroupInfo>>();
207     if (groupInfos.size() == 0) {
208         LOGE("HiChainConnector::GetGroupInfo group failed, groupInfos is empty.");
209         return false;
210     }
211     groupList = groupInfos;
212     return true;
213 }
214 
AddMember(std::string deviceId,std::string & connectInfo)215 int32_t HiChainConnector::AddMember(std::string deviceId, std::string &connectInfo)
216 {
217     LOGI("HiChainConnector::AddMember");
218     if (deviceGroupManager_ == nullptr) {
219         LOGI("HiChainConnector::AddMember group manager is null.");
220         return -1;
221     }
222     nlohmann::json jsonObject = nlohmann::json::parse(connectInfo, nullptr, false);
223     if (jsonObject.is_discarded()) {
224         LOGE("DecodeRequestAuth jsonStr error");
225         return DM_FAILED;
226     }
227     char localDeviceId[DEVICE_UUID_LENGTH] = {0};
228     GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
229     std::string connectInfomation = GetConnectPara(deviceId, jsonObject[TAG_DEVICE_ID]);
230 
231     int32_t pinCode = jsonObject[PIN_CODE_KEY];
232     std::string groupId = jsonObject[TAG_GROUP_ID];
233     nlohmann::json jsonObj;
234     jsonObj[FIELD_GROUP_ID] = groupId;
235     jsonObj[FIELD_GROUP_TYPE] = GROUP_TYPE_PEER_TO_PEER_GROUP;
236     jsonObj[FIELD_PIN_CODE] = std::to_string(pinCode).c_str();
237     jsonObj[FIELD_IS_ADMIN] = false;
238     jsonObj[FIELD_DEVICE_ID] = localDeviceId;
239     jsonObj[FIELD_GROUP_NAME] = jsonObject[TAG_GROUP_NAME];
240     jsonObj[FIELD_CONNECT_PARAMS] = connectInfomation.c_str();
241     std::string tmpStr = jsonObj.dump();
242     int64_t requestId = jsonObject[TAG_REQUEST_ID];
243     int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
244     if (userId < 0) {
245         LOGE("get current process account user id failed");
246         return DM_FAILED;
247     }
248     int32_t ret = deviceGroupManager_->addMemberToGroup(userId, requestId, DM_PKG_NAME.c_str(), tmpStr.c_str());
249     LOGI("HiChainConnector::AddMember completed");
250     return ret;
251 }
252 
onFinish(int64_t requestId,int operationCode,const char * returnData)253 void HiChainConnector::onFinish(int64_t requestId, int operationCode, const char *returnData)
254 {
255     std::string data = "";
256     if (returnData != nullptr) {
257         data = std::string(returnData);
258     }
259     LOGI("HiChainConnector::onFinish reqId:%lld, operation:%d", requestId, operationCode);
260     if (operationCode == GroupOperationCode::MEMBER_JOIN) {
261         LOGI("Add Member To Group success");
262         if (hiChainConnectorCallback_ != nullptr) {
263             hiChainConnectorCallback_->OnMemberJoin(requestId, DM_OK);
264         }
265     }
266     if (operationCode == GroupOperationCode::GROUP_CREATE) {
267         LOGI("Create group success");
268         if (hiChainConnectorCallback_ != nullptr) {
269             hiChainConnectorCallback_->OnGroupCreated(requestId, data);
270         }
271     }
272     if (operationCode == GroupOperationCode::MEMBER_DELETE) {
273         LOGI("Delete Member from group success");
274     }
275     if (operationCode == GroupOperationCode::GROUP_DISBAND) {
276         LOGI("Disband group success");
277     }
278 }
279 
onError(int64_t requestId,int operationCode,int errorCode,const char * errorReturn)280 void HiChainConnector::onError(int64_t requestId, int operationCode, int errorCode, const char *errorReturn)
281 {
282     (void)errorReturn;
283     LOGI("HichainAuthenCallBack::onError reqId:%lld, operation:%d, errorCode:%d.", requestId, operationCode, errorCode);
284     if (operationCode == GroupOperationCode::MEMBER_JOIN) {
285         LOGE("Add Member To Group failed");
286         if (hiChainConnectorCallback_ != nullptr) {
287             hiChainConnectorCallback_->OnMemberJoin(requestId, DM_FAILED);
288         }
289     }
290     if (operationCode == GroupOperationCode::GROUP_CREATE) {
291         LOGE("Create group failed");
292         if (hiChainConnectorCallback_ != nullptr) {
293             hiChainConnectorCallback_->OnGroupCreated(requestId, "{}");
294         }
295     }
296     if (operationCode == GroupOperationCode::MEMBER_DELETE) {
297         LOGE("Delete Member from group failed");
298     }
299     if (operationCode == GroupOperationCode::GROUP_DISBAND) {
300         LOGE("Disband group failed");
301     }
302 }
303 
onRequest(int64_t requestId,int operationCode,const char * reqParams)304 char *HiChainConnector::onRequest(int64_t requestId, int operationCode, const char *reqParams)
305 {
306     if (operationCode != GroupOperationCode::MEMBER_JOIN) {
307         LOGE("HiChainAuthCallBack::onRequest operationCode %d", operationCode);
308         return nullptr;
309     }
310     if (hiChainConnectorCallback_ == nullptr) {
311         LOGE("HiChainAuthCallBack::hiChain connector callback is nullptr");
312         return nullptr;
313     }
314     int32_t pinCode = 0;
315     pinCode = hiChainConnectorCallback_->GetPinCode();
316     nlohmann::json jsonObj;
317     if (pinCode == DM_FAILED) {
318         jsonObj[FIELD_CONFIRMATION] = REQUEST_REJECTED;
319     } else {
320         jsonObj[FIELD_CONFIRMATION] = REQUEST_ACCEPTED;
321     }
322     jsonObj[FIELD_PIN_CODE] = std::to_string(pinCode).c_str();
323     char localDeviceId[DEVICE_UUID_LENGTH] = {0};
324     GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
325     jsonObj[FIELD_DEVICE_ID] = localDeviceId;
326 
327     std::string jsonStr = jsonObj.dump();
328     char *buffer = strdup(jsonStr.c_str());
329     return buffer;
330 }
331 
GenRequestId()332 int64_t HiChainConnector::GenRequestId()
333 {
334     return GenRandLongLong(MIN_REQUEST_ID, MAX_REQUEST_ID);
335 }
336 
GetConnectPara(std::string deviceId,std::string reqDeviceId)337 std::string HiChainConnector::GetConnectPara(std::string deviceId, std::string reqDeviceId)
338 {
339     if (hiChainConnectorCallback_ == nullptr) {
340         LOGE("GetConnectPara::hiChain connector callback is nullptr");
341         return "";
342     }
343     std::string connectAddr = "";
344     connectAddr = hiChainConnectorCallback_->GetConnectAddr(deviceId);
345     LOGE("HiChainConnector::GetConnectPara get addrInfo");
346     nlohmann::json jsonObject = nlohmann::json::parse(connectAddr, nullptr, false);
347     if (jsonObject.is_discarded()) {
348         LOGE("DecodeRequestAuth jsonStr error");
349         return connectAddr;
350     }
351     jsonObject[DEVICE_ID] = reqDeviceId;
352 
353     return jsonObject.dump();
354 }
355 
GetRelatedGroups(std::string deviceId,std::vector<GroupInfo> & groupList)356 int32_t HiChainConnector::GetRelatedGroups(std::string deviceId, std::vector<GroupInfo> &groupList)
357 {
358     LOGI("HiChainConnector::GetRelatedGroups Start to get local related groups.");
359     uint32_t groupNum = 0;
360     char *returnGroups = nullptr;
361     int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
362     if (userId < 0) {
363         LOGE("get current process account user id failed");
364         return DM_FAILED;
365     }
366     int32_t ret =
367         deviceGroupManager_->getRelatedGroups(userId, DM_PKG_NAME.c_str(), deviceId.c_str(), &returnGroups, &groupNum);
368     if (ret != 0) {
369         LOGE("HiChainConnector::GetRelatedGroups faild , ret: %d.", ret);
370         return DM_FAILED;
371     }
372     if (returnGroups == nullptr) {
373         LOGE("HiChainConnector::GetRelatedGroups failed , returnGroups is nullptr");
374         return DM_FAILED;
375     }
376     if (groupNum == 0) {
377         LOGE("HiChainConnector::GetRelatedGroups group failed, groupNum is 0.");
378         return DM_FAILED;
379     }
380     std::string relatedGroups = std::string(returnGroups);
381     nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups);
382     if (jsonObject.is_discarded()) {
383         LOGE("returnGroups parse error");
384         return DM_FAILED;
385     }
386     std::vector<GroupInfo> groupInfos = jsonObject.get<std::vector<GroupInfo>>();
387     if (groupInfos.size() == 0) {
388         LOGE("HiChainConnector::GetRelatedGroups group failed, groupInfos is empty.");
389         return DM_FAILED;
390     }
391     groupList = groupInfos;
392     return DM_OK;
393 }
394 
GetSyncGroupList(std::vector<GroupInfo> & groupList,std::vector<std::string> & syncGroupList)395 int32_t HiChainConnector::GetSyncGroupList(std::vector<GroupInfo> &groupList, std::vector<std::string> &syncGroupList)
396 {
397     if (groupList.empty()) {
398         LOGE("groupList is empty.");
399         return DM_FAILED;
400     }
401     for (auto group : groupList) {
402         if (IsGroupInfoInvalid(group)) {
403             continue;
404         }
405         syncGroupList.push_back(group.groupId);
406     }
407     return DM_OK;
408 }
409 
IsDevicesInGroup(std::string hostDevice,std::string peerDevice)410 bool HiChainConnector::IsDevicesInGroup(std::string hostDevice, std::string peerDevice)
411 {
412     LOGE("HiChainConnector::IsDevicesInGroup");
413     std::vector<GroupInfo> hostGroupInfoList;
414     GetRelatedGroups(hostDevice, hostGroupInfoList);
415     std::vector<GroupInfo> peerGroupInfoList;
416     GetRelatedGroups(peerDevice, peerGroupInfoList);
417     for (auto &hostGroupInfo : hostGroupInfoList) {
418         for (auto &peerGroupInfo : peerGroupInfoList) {
419             if (hostGroupInfo.groupId == peerGroupInfo.groupId && hostGroupInfo.groupName == peerGroupInfo.groupName) {
420                 LOGE("these are authenticated");
421                 return false;
422             }
423         }
424     }
425     return true;
426 }
427 
IsGroupInfoInvalid(GroupInfo & group)428 bool HiChainConnector::IsGroupInfoInvalid(GroupInfo &group)
429 {
430     if (group.groupType == GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP || group.groupVisibility == GROUP_VISIBILITY_PUBLIC ||
431         group.groupOwner != DM_PKG_NAME) {
432         return true;
433     }
434     return false;
435 }
436 
SyncGroups(std::string deviceId,std::vector<std::string> & remoteGroupIdList)437 int32_t HiChainConnector::SyncGroups(std::string deviceId, std::vector<std::string> &remoteGroupIdList)
438 {
439     std::vector<GroupInfo> groupInfoList;
440     GetRelatedGroups(deviceId, groupInfoList);
441     for (auto &groupInfo : groupInfoList) {
442         if (IsGroupInfoInvalid(groupInfo)) {
443             continue;
444         }
445         auto iter = std::find(remoteGroupIdList.begin(), remoteGroupIdList.end(), groupInfo.groupId);
446         if (iter == remoteGroupIdList.end()) {
447             (void)DelMemberFromGroup(groupInfo.groupId, deviceId);
448         }
449     }
450     return DM_OK;
451 }
452 
DelMemberFromGroup(std::string groupId,std::string deviceId)453 int32_t HiChainConnector::DelMemberFromGroup(std::string groupId, std::string deviceId)
454 {
455     int64_t requestId = GenRequestId();
456     LOGI("Start to delete memeber from group, requestId %lld, deviceId %s, groupId %s", requestId,
457          GetAnonyString(deviceId).c_str(), GetAnonyString(groupId).c_str());
458     nlohmann::json jsonObj;
459     jsonObj[FIELD_GROUP_ID] = groupId;
460     jsonObj[FIELD_DELETE_ID] = deviceId;
461     std::string deleteParams = jsonObj.dump();
462     int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
463     if (userId < 0) {
464         LOGE("get current process account user id failed");
465         return DM_FAILED;
466     }
467     int32_t ret = deviceGroupManager_->deleteMemberFromGroup(userId, requestId,
468         DM_PKG_NAME.c_str(), deleteParams.c_str());
469     if (ret != 0) {
470         LOGE("HiChainConnector::DelMemberFromGroup failed , ret: %d.", ret);
471         return ret;
472     }
473     return DM_OK;
474 }
475 
DeleteGroup(std::string & groupId)476 int32_t HiChainConnector::DeleteGroup(std::string &groupId)
477 {
478     int64_t requestId = GenRequestId();
479     nlohmann::json jsonObj;
480     jsonObj[FIELD_GROUP_ID] = groupId;
481     std::string disbandParams = jsonObj.dump();
482     int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
483     if (userId < 0) {
484         LOGE("get current process account user id failed");
485         return DM_FAILED;
486     }
487 
488     int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME.c_str(), disbandParams.c_str());
489     if (ret != 0) {
490         LOGE("HiChainConnector::DeleteGroup failed , ret: %d.", ret);
491         return DM_FAILED;
492     }
493     return DM_OK;
494 }
495 
DeleteGroup(const int32_t userId,std::string & groupId)496 int32_t HiChainConnector::DeleteGroup(const int32_t userId, std::string &groupId)
497 {
498     int64_t requestId = GenRequestId();
499     nlohmann::json jsonObj;
500     jsonObj[FIELD_GROUP_ID] = groupId;
501     std::string disbandParams = jsonObj.dump();
502     int32_t ret = deviceGroupManager_->deleteGroup(userId, requestId, DM_PKG_NAME.c_str(), disbandParams.c_str());
503     if (ret != 0) {
504         LOGE("HiChainConnector::DeleteGroup failed , ret: %d.", ret);
505         return DM_FAILED;
506     }
507     return DM_OK;
508 }
509 
DeleteTimeOutGroup(const char * deviceId)510 int32_t HiChainConnector::DeleteTimeOutGroup(const char* deviceId)
511 {
512     LOGE("HiChainConnector::DeleteTimeOutGroup start");
513     int32_t userId = MultipleUserConnector::GetCurrentAccountUserID();
514     if (userId < 0) {
515         LOGE("get current process account user id failed");
516         return DM_FAILED;
517     }
518     std::vector<GroupInfo> peerGroupInfoList;
519     GetRelatedGroups(deviceId, peerGroupInfoList);
520     char localDeviceId[DEVICE_UUID_LENGTH] = {0};
521     GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH);
522     for (auto &group : peerGroupInfoList) {
523         if (deviceGroupManager_->isDeviceInGroup(userId, DM_PKG_NAME.c_str(), group.groupId.c_str(), localDeviceId)) {
524             DeleteGroup(group.groupId);
525             return DM_OK;
526         }
527     }
528     return DM_FAILED;
529 }
530 } // namespace DistributedHardware
531 } // namespace OHOS
532