diff --git a/services/implementation/include/dependency/hichain/hichain_connector.h b/services/implementation/include/dependency/hichain/hichain_connector.h index ec99c924e9ebe5ef3b5463c55d2c459cb1b6805c..c5b2c45e78685a00a9798512b3866fe28e15d1a0 100644 --- a/services/implementation/include/dependency/hichain/hichain_connector.h +++ b/services/implementation/include/dependency/hichain/hichain_connector.h @@ -242,7 +242,6 @@ public: int32_t GetRelatedGroupsCommon(int32_t userId, const std::string &deviceId, const char* pkgName, std::vector &groupList); void DeleteAllGroupByUdid(const std::string &udid); - void DeleteP2PGroup(int32_t switchUserId); int32_t DeleteGroupByACL(std::vector> &delACLInfoVec, std::vector &userIdVec); bool IsNeedDelete(std::string &groupName, int32_t userId, diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 651ddc55e8a331d923cda093a293c66c7cd61405..14cfe510286a406fd908c49a8562bc4ce0485f64 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -243,6 +243,7 @@ void DmAuthManager::InitAuthState(const std::string &pkgName, int32_t authType, if (authenticationMap_.find(authType) != authenticationMap_.end()) { authPtr_ = authenticationMap_[authType]; } + if (timer_ == nullptr) { timer_ = std::make_shared(); } @@ -527,8 +528,6 @@ void DmAuthManager::ProcessSinkMsg() timer_->DeleteTimer(std::string(WAIT_NEGOTIATE_TIMEOUT_TASK)); } authResponseState_->TransitionTo(std::make_shared()); - } else { - LOGE("Device manager auth state error"); } break; case MSG_TYPE_REQ_AUTH: @@ -537,8 +536,6 @@ void DmAuthManager::ProcessSinkMsg() timer_->DeleteTimer(std::string(WAIT_REQUEST_TIMEOUT_TASK)); } authResponseState_->TransitionTo(std::make_shared()); - } else { - LOGE("Device manager auth state error"); } break; case MSG_TYPE_REQ_AUTH_TERMINATE: @@ -2051,6 +2048,7 @@ void DmAuthManager::AuthDeviceFinish(int64_t requestId) if (timer_ != nullptr) { timer_->DeleteTimer(std::string(AUTH_DEVICE_TIMEOUT_TASK)); } + if (authRequestState_ != nullptr && authResponseState_ == nullptr) { PutAccessControlList(); SrcAuthDeviceFinish(); @@ -2079,6 +2077,7 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) if (timer_ != nullptr) { timer_->DeleteTimer(std::string(AUTH_DEVICE_TIMEOUT_TASK)); } + if (errorCode != DM_OK || requestId != authResponseContext_->requestId) { if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; @@ -2277,17 +2276,11 @@ int32_t DmAuthManager::DeleteGroup(const std::string &pkgName, const std::string return ERR_DM_FAILED; } std::vector groupList; + CHECK_NULL_RETURN(hiChainConnector_, ERR_DM_POINT_NULL); hiChainConnector_->GetRelatedGroups(deviceId, groupList); - if (groupList.size() > 0) { - std::string groupId = ""; - groupId = groupList.front().groupId; + for (const auto &item : groupList) { + std::string groupId = item.groupId; hiChainConnector_->DeleteGroup(groupId); - } else { - LOGE("DmAuthManager::UnAuthenticateDevice groupList.size = 0"); - return ERR_DM_FAILED; - } - if (softbusConnector_ != nullptr) { - softbusConnector_->EraseUdidFromMap(deviceId); } return DM_OK; } diff --git a/services/implementation/src/dependency/hichain/hichain_connector.cpp b/services/implementation/src/dependency/hichain/hichain_connector.cpp index 7e2ae818cf98498cafbf9175be715a57752ec4f2..7a00f3859989989e3849269c30dc258b66c4e502 100644 --- a/services/implementation/src/dependency/hichain/hichain_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_connector.cpp @@ -1180,6 +1180,7 @@ int32_t HiChainConnector::GetRelatedGroupsCommon(int32_t userId, const std::stri deviceGroupManager_->getRelatedGroups(userId, pkgName, deviceId.c_str(), &returnGroups, &groupNum); if (ret != 0) { LOGE("[HICHAIN] fail to get related groups with ret:%{public}d.", ret); + delete[] returnGroups; returnGroups = nullptr; return ERR_DM_FAILED; } @@ -1189,10 +1190,12 @@ int32_t HiChainConnector::GetRelatedGroupsCommon(int32_t userId, const std::stri } if (groupNum == 0) { LOGE("[HICHAIN]return related goups number is zero."); + delete[] returnGroups; returnGroups = nullptr; return ERR_DM_FAILED; } std::string relatedGroups = std::string(returnGroups); + delete[] returnGroups; returnGroups = nullptr; nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups, nullptr, false); if (jsonObject.is_discarded()) { @@ -1231,37 +1234,6 @@ void HiChainConnector::DeleteAllGroupByUdid(const std::string &udid) } } -void HiChainConnector::DeleteP2PGroup(int32_t switchUserId) -{ - LOGI("switchuserId: %{public}d", switchUserId); - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_TYPE] = GROUP_TYPE_PEER_TO_PEER_GROUP; - std::string queryParams = jsonObj.dump(); - std::vector groupList; - - if (!GetGroupInfo(switchUserId, queryParams, groupList)) { - LOGE("failed to get the switch user id groups"); - return; - } - for (auto iter = groupList.begin(); iter != groupList.end(); iter++) { - if (DeleteGroup(switchUserId, iter->groupId) != DM_OK) { - LOGE("failed to delete the old user id group %{public}s", GetAnonyString(iter->groupId).c_str()); - } - } - - int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); - LOGI("userId: %{public}d", userId); - if (!GetGroupInfo(userId, queryParams, groupList)) { - LOGE("failed to get the user id groups"); - return; - } - for (auto iter = groupList.begin(); iter != groupList.end(); iter++) { - if (DeleteGroup(userId, iter->groupId) != DM_OK) { - LOGE("failed to delete the user id group %{public}s", GetAnonyString(iter->groupId).c_str()); - } - } -} - int32_t HiChainConnector::DeleteGroupByACL(std::vector> &delACLInfoVec, std::vector &userIdVec) { diff --git a/services/implementation/src/dependency/softbus/softbus_connector.cpp b/services/implementation/src/dependency/softbus/softbus_connector.cpp index 2f1124e400bd29ea9f8a5da88db07da5408f280e..b89de1c22bcef58f5ac74e7c84fe9711ebf0c644 100644 --- a/services/implementation/src/dependency/softbus/softbus_connector.cpp +++ b/services/implementation/src/dependency/softbus/softbus_connector.cpp @@ -268,6 +268,7 @@ void SoftbusConnector::JoinLnn(const std::string &deviceId) if (memcpy_s(addrInfo->info.ble.udidHash, UDID_HASH_LEN, remoteUdidHash_.c_str(), remoteUdidHash_.length()) != 0) { LOGE("memcpy remoteUdid hash failed, remoteUdidHash_: %{public}s.", GetAnonyString(remoteUdidHash_).c_str()); + return; } int32_t ret = ::JoinLNN(DM_PKG_NAME, addrInfo, OnSoftbusJoinLNNResult); if (ret != DM_OK) { diff --git a/services/implementation/src/discovery/dm_discovery_manager.cpp b/services/implementation/src/discovery/dm_discovery_manager.cpp index a9ccaee3a3a19ec9997feb80e8117f1922a5a60d..a872d4f02bc77e16c05380074e8c53888753e6b6 100644 --- a/services/implementation/src/discovery/dm_discovery_manager.cpp +++ b/services/implementation/src/discovery/dm_discovery_manager.cpp @@ -130,7 +130,9 @@ int32_t DmDiscoveryManager::StopDeviceDiscovery(const std::string &pkgName, uint } if (!discoveryContextMap_.empty()) { discoveryContextMap_.erase(pkgName); - timer_->DeleteTimer(std::string(DISCOVERY_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(DISCOVERY_TIMEOUT_TASK)); + } } } softbusConnector_->UnRegisterSoftbusDiscoveryCallback(pkgName); @@ -238,7 +240,9 @@ void DmDiscoveryManager::OnDiscoveryFailed(const std::string &pkgName, int32_t s } if (!discoveryContextMap_.empty()) { discoveryContextMap_.erase(pkgName); - timer_->DeleteTimer(std::string(DISCOVERY_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(DISCOVERY_TIMEOUT_TASK)); + } } } softbusConnector_->StopDiscovery(subscribeId); diff --git a/services/implementation/src/publish/dm_publish_manager.cpp b/services/implementation/src/publish/dm_publish_manager.cpp index 81fef1b9ffabb954434a027cfa04cc239d7961d2..b093981612ff778c6d9277ddcbe0df2bc013fe2a 100644 --- a/services/implementation/src/publish/dm_publish_manager.cpp +++ b/services/implementation/src/publish/dm_publish_manager.cpp @@ -93,7 +93,9 @@ int32_t DmPublishManager::UnPublishDeviceDiscovery(const std::string &pkgName, i if (!publishContextMap_.empty()) { publishContextMap_.erase(pkgName); softbusConnector_->UnRegisterSoftbusPublishCallback(pkgName); - timer_->DeleteTimer(std::string(PUBLISH_DISCOVERY_TIMEOUT_TASK)); + if (timer_ != nullptr) { + timer_->DeleteTimer(std::string(PUBLISH_DISCOVERY_TIMEOUT_TASK)); + } } return softbusConnector_->UnPublishDiscovery(publishId); } diff --git a/services/service/include/devicenamemgr/local_device_name_mgr.h b/services/service/include/devicenamemgr/local_device_name_mgr.h index 56fc6b89d804297ee7754103a277ca50aa36f0d0..bd12387fccbe20144faabf13a75c2d3157505903 100644 --- a/services/service/include/devicenamemgr/local_device_name_mgr.h +++ b/services/service/include/devicenamemgr/local_device_name_mgr.h @@ -47,7 +47,7 @@ private: std::string &deviceName); int32_t GetActiveOsAccountIds(); private: - std::mutex devNameMtx_; + static std::mutex devNameMtx_; std::string localDeviceName_; std::string localDisplayName_; }; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index bc606b109b1eca96fe689ab495c901cfe3727bd3..c13f4a445cb1751dd81945fd1c89b08c43d84f14 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -76,6 +76,7 @@ namespace { constexpr uint32_t USERID_CHECKSUM_DISCOVERY_TYPE_WIFI_MASK = 0b0010; const std::string DHARD_WARE_PKG_NAME = "ohos.dhardware"; } + DeviceManagerService::~DeviceManagerService() { LOGI("DeviceManagerService destructor"); diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index b98d3442d815df850fd958cc9a8cf383e018c697..b94ea071ed42cbc11cf2d8d3c25e06f7171c4425 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -446,8 +446,8 @@ int32_t DeviceManagerServiceListener::ConvertUdidHashToAnoyDeviceId(const std::s void DeviceManagerServiceListener::OnDeviceTrustChange(const std::string &udid, const std::string &uuid, DmAuthForm authForm) { - LOGI("udid %{public}s, uuid %{public}s, authForm %{public}d.", GetAnonyString(udid).c_str(), - GetAnonyString(uuid).c_str(), authForm); + LOGI("udid %{public}s, authForm %{public}d, uuid %{public}s.", GetAnonyString(udid).c_str(), + authForm, GetAnonyString(uuid).c_str()); std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); int32_t userId = -1; diff --git a/services/service/src/devicenamemgr/account_boot_listener.cpp b/services/service/src/devicenamemgr/account_boot_listener.cpp index 29e4eb9320b0a2f55ff40793b4af91729cc53679..7f0dfa3fc1fdb615183c74bb137c388043473caf 100644 --- a/services/service/src/devicenamemgr/account_boot_listener.cpp +++ b/services/service/src/devicenamemgr/account_boot_listener.cpp @@ -161,11 +161,19 @@ void AccountBootListener::DataShareCallback() std::string AccountBootListener::GetLocalDisplayName() const { + if (localDeviceMgr_ == nullptr) { + LOGE("logcalDeviceMgr_ is null"); + return ""; + } return localDeviceMgr_->GetLocalDisplayName(); } std::string AccountBootListener::GetLocalDeviceName() const { + if (localDeviceMgr_ == nullptr) { + LOGE("logcalDeviceMgr_ is null"); + return ""; + } return localDeviceMgr_->GetLocalDeviceName(); } } // namespace DistributedHardware diff --git a/services/service/src/devicenamemgr/local_device_name_mgr.cpp b/services/service/src/devicenamemgr/local_device_name_mgr.cpp index 22227f15bad032258b87aa7096391874c7189de8..9564ee56fa2eaad93db32abcc6132be0b6c469ce 100644 --- a/services/service/src/devicenamemgr/local_device_name_mgr.cpp +++ b/services/service/src/devicenamemgr/local_device_name_mgr.cpp @@ -45,6 +45,8 @@ namespace { constexpr const char *DISPLAY_DEVICE_NAME_STRING = "settings.general.display_device_name"; } +std::mutex LocalDeviceNameMgr::devNameMtx_; + LocalDeviceNameMgr::LocalDeviceNameMgr() : localDeviceName_(""), localDisplayName_("") { LOGI("Ctor LocalDeviceNameMgr"); @@ -286,11 +288,13 @@ void LocalDeviceNameMgr::RegisterDisplayNameChangeCb() std::string LocalDeviceNameMgr::GetLocalDisplayName() const { + std::lock_guard lock(devNameMtx_); return localDisplayName_; } std::string LocalDeviceNameMgr::GetLocalDeviceName() const { + std::lock_guard lock(devNameMtx_); return localDeviceName_; } } // namespace DistributedHardware