diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 15c52772ca41c5f8de857b05d52db09ebfe4d026..5ed774e88f3ed672729e94a1d1d54166276c99b4 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -26,6 +26,7 @@ namespace DistributedHardware { const int32_t MAX_VERIFY_TIMES = 3; PinAuth::PinAuth() { + pinAuthUi_ = std::make_shared(); LOGI("PinAuth constructor"); } diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 204ef0fe7eeec2ac1a40d9fdd25aa51eff6c8f3f..7d049ea36b0fea3759f33e368da8ec6904c5f379 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -157,9 +157,9 @@ public: int32_t HandleAuthenticateTimeout(); void CancelDisplay(); int32_t GeneratePincode(); - void ShowConfigDialog(); - void ShowAuthInfoDialog(); - void ShowStartAuthDialog(); + int32_t ShowConfigDialog(); + int32_t ShowAuthInfoDialog(); + int32_t ShowStartAuthDialog(); int32_t GetAuthenticationParam(DmAuthParam &authParam); int32_t OnUserOperation(int32_t action); void UserSwitchEventCallback(int32_t userId); diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 359721a012625694e3d529ffe5d02a4862b7e301..260ac69bcffd0af45477dd3dc570cd84bea09561 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -175,6 +175,10 @@ int32_t DmAuthManager::UnAuthenticateDevice(const std::string &pkgName, const st int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) { LOGI("DmAuthManager::VerifyAuthentication"); + if (authRequestState_ == nullptr && authResponseState_ == nullptr) { + LOGI("DmAuthManager::AuthenticateDevice is start"); + return DM_NOT_INIT; + } std::shared_ptr ptr; if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end() || timerMap_.find(INPUT_TIMEOUT_TASK) == timerMap_.end()) { @@ -380,6 +384,10 @@ int32_t DmAuthManager::HandleAuthenticateTimeout() int32_t DmAuthManager::EstablishAuthChannel(const std::string &deviceId) { + if (authRequestState_ == nullptr && authResponseState_ == nullptr) { + LOGI("DmAuthManager::AuthenticateDevice is start"); + return DM_NOT_INIT; + } int32_t sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); if (sessionId < 0) { LOGE("OpenAuthSession failed, stop the authentication"); @@ -510,6 +518,10 @@ void DmAuthManager::StartRespAuthProcess() int32_t DmAuthManager::CreateGroup() { LOGI("DmAuthManager:: CreateGroup"); + if (authRequestState_ == nullptr && authResponseState_ == nullptr) { + LOGI("DmAuthManager::AuthenticateDevice is start"); + return DM_NOT_INIT; + } authResponseContext_->groupName = GenerateGroupName(); authResponseContext_->requestId = GenRandLongLong(MIN_REQUEST_ID, MAX_REQUEST_ID); hiChainConnector_->CreateGroup(authResponseContext_->requestId, authResponseContext_->groupName); @@ -519,6 +531,10 @@ int32_t DmAuthManager::CreateGroup() int32_t DmAuthManager::AddMember(const std::string &deviceId) { LOGI("DmAuthManager::AddMember start"); + if (authRequestState_ == nullptr && authResponseState_ == nullptr) { + LOGI("DmAuthManager::AuthenticateDevice is start"); + return DM_NOT_INIT; + } nlohmann::json jsonObj = nlohmann::json::parse(authResponseContext_->authToken, nullptr, false); if (jsonObj.is_discarded()) { LOGE("DecodeRequestAuth jsonStr error"); @@ -679,6 +695,10 @@ int32_t DmAuthManager::SetAuthResponseState(std::shared_ptr a int32_t DmAuthManager::GetPinCode() { + if (authRequestState_ == nullptr && authResponseState_ == nullptr) { + LOGI("DmAuthManager::AuthenticateDevice is start"); + return DM_NOT_INIT; + } nlohmann::json jsonObj = nlohmann::json::parse(authResponseContext_->authToken, nullptr, false); if (jsonObj.is_discarded()) { LOGE("DecodeRequestAuth jsonStr error"); @@ -687,9 +707,13 @@ int32_t DmAuthManager::GetPinCode() return jsonObj[PIN_CODE_KEY]; } -void DmAuthManager::ShowConfigDialog() +int32_t DmAuthManager::ShowConfigDialog() { LOGI("ShowConfigDialog start"); + if (authRequestState_ == nullptr && authResponseState_ == nullptr) { + LOGI("DmAuthManager::AuthenticateDevice is start"); + return DM_NOT_INIT; + } nlohmann::json jsonObj; jsonObj[TAG_AUTH_TYPE] = AUTH_TYPE_PIN; jsonObj[TAG_TOKEN] = authResponseContext_->token; @@ -709,35 +733,50 @@ void DmAuthManager::ShowConfigDialog() authMgr_->StartAuthProcess(atoi(params.c_str())); }); LOGI("ShowConfigDialog end"); + return DM_OK; } -void DmAuthManager::ShowAuthInfoDialog() +int32_t DmAuthManager::ShowAuthInfoDialog() { LOGI("DmAuthManager::ShowAuthInfoDialog start"); + if (authRequestState_ == nullptr && authResponseState_ == nullptr) { + LOGI("DmAuthManager::AuthenticateDevice is start"); + return DM_NOT_INIT; + } std::shared_ptr ptr; if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { LOGE("DmAuthManager::authenticationMap_ is null"); - return; + return DM_AUTH_NOT_SUPPORT; } ptr = authenticationMap_[authResponseContext_->authType]; LOGI("ShowAuthInfoDialog authToken:%s", authResponseContext_->authToken.c_str()); ptr->ShowAuthInfo(authResponseContext_->authToken, shared_from_this()); + return DM_OK; } -void DmAuthManager::ShowStartAuthDialog() +int32_t DmAuthManager::ShowStartAuthDialog() { LOGI("DmAuthManager::ShowStartAuthDialog start"); + if (authRequestState_ == nullptr && authResponseState_ == nullptr) { + LOGI("DmAuthManager::AuthenticateDevice is start"); + return DM_NOT_INIT; + } std::shared_ptr ptr; if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { LOGE("DmAuthManager::authenticationMap_ is null"); - return; + return DM_AUTH_NOT_SUPPORT; } ptr = authenticationMap_[authResponseContext_->authType]; ptr->StartAuth(authResponseContext_->authToken, shared_from_this()); + return DM_OK; } int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) { + if (authRequestState_ == nullptr && authResponseState_ == nullptr) { + LOGI("DmAuthManager::AuthenticateDevice is start"); + return DM_NOT_INIT; + } if (dmAbilityMgr_ == nullptr) { LOGI("dmAbilityMgr_ is nullptr"); return DM_POINT_NULL; @@ -762,6 +801,10 @@ int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) int32_t DmAuthManager::OnUserOperation(int32_t action) { + if (authRequestState_ == nullptr && authResponseState_ == nullptr) { + LOGI("DmAuthManager::AuthenticateDevice is start"); + return DM_NOT_INIT; + } switch (action) { case USER_OPERATION_TYPE_ALLOW_AUTH: case USER_OPERATION_TYPE_CANCEL_AUTH: @@ -820,6 +863,10 @@ void DmAuthManager::UserSwitchEventCallback (int32_t userId) int32_t DmAuthManager::SetPageId(int32_t pageId) { + if (authRequestState_ == nullptr && authResponseState_ == nullptr) { + LOGI("DmAuthManager::AuthenticateDevice is start"); + return DM_NOT_INIT; + } authResponseContext_->pageId = pageId; return DM_OK; }