mirror of
https://github.com/openharmony/device_manager.git
synced 2026-07-19 18:13:32 -04:00
Codedex 重复代码修改
Signed-off-by: @shi-xiaoxiao-iris <shixiaoxiao2@huawei.com>
This commit is contained in:
@@ -202,6 +202,8 @@ private:
|
||||
int32_t GetStrFieldByType(const std::string &reqJsonStr, const std::string &outField, int32_t type);
|
||||
int32_t GetNumsFieldByType(const std::string &reqJsonStr, int32_t &outField, int32_t type);
|
||||
int32_t GetGroupId(const std::string &userId, const int32_t groupType, std::string &groupId);
|
||||
int32_t ParseRemoteCredential(const int32_t groupType, const std::string &userId,
|
||||
const nlohmann::json &jsonDeviceList, std::string ¶ms, int32_t &osAccountUserId);
|
||||
private:
|
||||
const DeviceGroupManager *deviceGroupManager_ = nullptr;
|
||||
DeviceAuthCallback deviceAuthCallback_;
|
||||
|
||||
@@ -775,13 +775,9 @@ int32_t HiChainConnector::GetGroupId(const std::string &userId, const int32_t gr
|
||||
return ERR_DM_FAILED;
|
||||
}
|
||||
|
||||
int32_t HiChainConnector::addMultiMembers(const int32_t groupType, const std::string &userId,
|
||||
const nlohmann::json &jsonDeviceList)
|
||||
int32_t HiChainConnector::ParseRemoteCredential(const int32_t groupType, const std::string &userId,
|
||||
const nlohmann::json &jsonDeviceList, std::string ¶ms, int32_t &osAccountUserId)
|
||||
{
|
||||
if (deviceGroupManager_ == nullptr) {
|
||||
LOGE("HiChainConnector::deviceGroupManager_ is nullptr.");
|
||||
return ERR_DM_INPUT_PARAMETER_EMPTY;
|
||||
}
|
||||
if (userId.empty() || !jsonDeviceList.contains(FIELD_DEVICE_LIST)) {
|
||||
LOGE("userId or deviceList is empty");
|
||||
return ERR_DM_INPUT_PARAMETER_EMPTY;
|
||||
@@ -791,19 +787,35 @@ int32_t HiChainConnector::addMultiMembers(const int32_t groupType, const std::st
|
||||
LOGE("failed to get groupid");
|
||||
return ERR_DM_FAILED;
|
||||
}
|
||||
std::string appId = DM_PKG_NAME;
|
||||
nlohmann::json jsonObj;
|
||||
jsonObj[FIELD_GROUP_ID] = groupId;
|
||||
jsonObj[FIELD_GROUP_TYPE] = groupType;
|
||||
jsonObj[FIELD_DEVICE_LIST] = jsonDeviceList[FIELD_DEVICE_LIST];
|
||||
std::string addParams = jsonObj.dump();
|
||||
int32_t osAccountUserId = MultipleUserConnector::GetCurrentAccountUserID();
|
||||
params = jsonObj.dump();
|
||||
osAccountUserId = MultipleUserConnector::GetCurrentAccountUserID();
|
||||
if (osAccountUserId < 0) {
|
||||
LOGE("get current process account user id failed");
|
||||
return ERR_DM_FAILED;
|
||||
}
|
||||
return DM_OK;
|
||||
}
|
||||
|
||||
int32_t HiChainConnector::addMultiMembers(const int32_t groupType, const std::string &userId,
|
||||
const nlohmann::json &jsonDeviceList)
|
||||
{
|
||||
if (deviceGroupManager_ == nullptr) {
|
||||
LOGE("HiChainConnector::deviceGroupManager_ is nullptr.");
|
||||
return ERR_DM_INPUT_PARAMETER_EMPTY;
|
||||
}
|
||||
std::string addParams;
|
||||
int32_t osAccountUserId = 0;
|
||||
if (ParseRemoteCredential(groupType, userId, jsonDeviceList, addParams, osAccountUserId) != DM_OK) {
|
||||
LOGE("addMultiMembers ParseRemoteCredential failed!");
|
||||
return ERR_DM_FAILED;
|
||||
}
|
||||
|
||||
int32_t ret = deviceGroupManager_->addMultiMembersToGroup(osAccountUserId,
|
||||
appId.c_str(), addParams.c_str());
|
||||
DM_PKG_NAME.c_str(), addParams.c_str());
|
||||
if (ret!= DM_OK) {
|
||||
LOGE("HiChainConnector::addMultiMemberstoGroup failure! ret=%d", ret);
|
||||
return ret;
|
||||
@@ -818,28 +830,16 @@ int32_t HiChainConnector::deleteMultiMembers(const int32_t groupType, const std:
|
||||
LOGE("HiChainConnector::deviceGroupManager_ is nullptr.");
|
||||
return ERR_DM_INPUT_PARAMETER_EMPTY;
|
||||
}
|
||||
if (userId.empty() || !jsonDeviceList.contains(FIELD_DEVICE_LIST)) {
|
||||
LOGE("jsonDeviceList userId or deleteInfo string is empty");
|
||||
return ERR_DM_INPUT_PARAMETER_EMPTY;
|
||||
}
|
||||
std::string groupId;
|
||||
if (GetGroupId(userId, groupType, groupId) != DM_OK) {
|
||||
LOGE("failed to get groupid");
|
||||
return ERR_DM_FAILED;
|
||||
}
|
||||
std::string appId = DM_PKG_NAME;
|
||||
nlohmann::json jsonObj;
|
||||
jsonObj[FIELD_GROUP_ID] = groupId;
|
||||
jsonObj[FIELD_GROUP_TYPE] = groupType;
|
||||
jsonObj[FIELD_DEVICE_LIST] = jsonDeviceList[FIELD_DEVICE_LIST];
|
||||
std::string deleteParams = jsonObj.dump();
|
||||
int32_t osAccountUserId = MultipleUserConnector::GetCurrentAccountUserID();
|
||||
if (osAccountUserId < 0) {
|
||||
LOGE("get current process account user id failed");
|
||||
|
||||
std::string deleteParams;
|
||||
int32_t osAccountUserId = 0;
|
||||
if (ParseRemoteCredential(groupType, userId, jsonDeviceList, deleteParams, osAccountUserId) != DM_OK) {
|
||||
LOGE("deleteMultiMembers ParseRemoteCredential failed!");
|
||||
return ERR_DM_FAILED;
|
||||
}
|
||||
|
||||
int32_t ret = deviceGroupManager_->delMultiMembersFromGroup(osAccountUserId,
|
||||
appId.c_str(), deleteParams.c_str());
|
||||
DM_PKG_NAME.c_str(), deleteParams.c_str());
|
||||
if (ret != DM_OK) {
|
||||
LOGE("HiChainConnector::deleteMultiMembers failure!, ret=%d", ret);
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user