diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index de210e85d6399e8e313c24fdea4ea7ff03a6d014..e759e8c4b85994c15c98a05c47a2dcff9d333ded 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -175,13 +175,13 @@ int32_t DmAuthManager::UnAuthenticateDevice(const std::string &pkgName, const st int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) { LOGI("DmAuthManager::VerifyAuthentication"); - timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); - std::shared_ptr ptr; - if (authenticationMap_.find(1) == authenticationMap_.end()) { + if (authenticationMap_.find(1) == authenticationMap_.end() && timerMap_[INPUT_TIMEOUT_TASK] == nullptr) { LOGE("DmAuthManager::authenticationMap_ is null"); return DM_FAILED; } + timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); + ptr = authenticationMap_[1]; int32_t ret = ptr->VerifyAuthentication(authRequestContext_->token, authResponseContext_->code, authParam); switch (ret) { @@ -269,7 +269,8 @@ void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message) } switch (authResponseContext_->msgType) { case MSG_TYPE_NEGOTIATE: - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_INIT) { + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_INIT + && timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK] != nullptr) { timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); authResponseState_->TransitionTo(std::make_shared()); } else { @@ -277,7 +278,8 @@ void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message) } break; case MSG_TYPE_REQ_AUTH: - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_NEGOTIATE) { + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_NEGOTIATE + && timerMap_[WAIT_REQUEST_TIMEOUT_TASK] != nullptr) { timerMap_[WAIT_REQUEST_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); authResponseState_->TransitionTo(std::make_shared()); } else { @@ -337,7 +339,7 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) { LOGE("DmAuthManager OnMemberJoin start"); - if (authRequestState_ != nullptr) { + if (authRequestState_ != nullptr && timerMap_[ADD_TIMEOUT_TASK] != nullptr) { timerMap_[ADD_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); if (status != DM_OK || authResponseContext_->requestId != requestId) { if (authRequestState_ != nullptr) { @@ -444,6 +446,9 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) void DmAuthManager::SendAuthRequest(const int32_t &sessionId) { LOGE("DmAuthManager::EstablishAuthChannel session id"); + if (timerMap_[NEGOTIATE_TIMEOUT_TASK] == nullptr) { + return; + } timerMap_[NEGOTIATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); if (authResponseContext_->cryptoSupport == true) { isCryptoSupport_ = true; @@ -479,6 +484,9 @@ int32_t DmAuthManager::StartAuthProcess(const int32_t &action) void DmAuthManager::StartRespAuthProcess() { LOGI("DmAuthManager::StartRespAuthProcess StartRespAuthProcess", authResponseContext_->sessionId); + if (timerMap_[CONFIRM_TIMEOUT_TASK] == nullptr) { + return; + } timerMap_[CONFIRM_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); if (authResponseContext_->reply == USER_OPERATION_TYPE_ALLOW_AUTH) { std::shared_ptr inputStartTimer = std::make_shared(INPUT_TIMEOUT_TASK); @@ -535,6 +543,9 @@ std::string DmAuthManager::GetConnectAddr(std::string deviceId) int32_t DmAuthManager::JoinNetwork() { LOGE("DmAuthManager JoinNetwork start"); + if (timerMap_[AUTHENTICATE_TIMEOUT_TASK] == nullptr) { + return DM_FAILED; + } timerMap_[AUTHENTICATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = DM_OK; @@ -787,6 +798,9 @@ void DmAuthManager::UserSwitchEventCallback (int32_t userId) void DmAuthManager::VerifyPinAuthAuthentication(const std::string &action) { LOGI("DmAuthManager::VerifyPinAuthAuthentication"); + if (timerMap_[INPUT_TIMEOUT_TASK] == nullptr) { + return; + } timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); if (action == "0") { authRequestState_->TransitionTo(std::make_shared()); diff --git a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp index 4a489935acded72f03002e2f712f1165ceb3f7f1..f48689431b9de61d7542b476b8ee9910f766459d 100644 --- a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp +++ b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp @@ -73,14 +73,14 @@ int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, con int32_t DmDiscoveryManager::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) { - if (!discoveryQueue_.empty()) { - discoveryQueue_.pop(); - } - if (!discoveryContextMap_.empty()) { - discoveryContextMap_.erase(pkgName); - softbusConnector_->UnRegisterSoftbusDiscoveryCallback(pkgName); - discoveryTimer_->Stop(SESSION_CANCEL_TIMEOUT); + if (discoveryQueue_.empty()) { + LOGE("discovery is not start"); + return DM_FAILED; } + discoveryQueue_.pop(); + discoveryContextMap_.erase(pkgName); + softbusConnector_->UnRegisterSoftbusDiscoveryCallback(pkgName); + discoveryTimer_->Stop(SESSION_CANCEL_TIMEOUT); return softbusConnector_->StopDiscovery(subscribeId); }