From b38efd783b4a9754a19134e7c07b4cf60cebd492 Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Tue, 15 Mar 2022 17:09:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=85=E6=BA=90=E6=A3=80?= =?UTF-8?q?=E8=A7=86=E4=BB=A3=E7=A0=81=20Signed-off-by:=20renguang1116=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ipc/standard/ipc_cmd_parser.cpp | 5 +- .../src/authentication/dm_auth_manager.cpp | 121 ++++++++++-------- 2 files changed, 68 insertions(+), 58 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index 38a52f75a..1c5733782 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -130,10 +130,9 @@ ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO, MessageParcel &reply, std::shared_pt { std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); DmDeviceInfo *localDeviceInfo = (DmDeviceInfo *)reply.ReadRawData(sizeof(DmDeviceInfo)); - if (localDeviceInfo == nullptr) { - LOGE("write subscribe info failed"); + if (localDeviceInfo != nullptr) { + pRsp->SetLocalDeviceInfo(*localDeviceInfo); } - pRsp->SetLocalDeviceInfo(*localDeviceInfo); pRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 2fc6956ca..22208ad68 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -251,72 +251,83 @@ void DmAuthManager::OnSessionClosed(int32_t sessionId) void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message) { - LOGI("DmAuthManager::OnDataReceived start"); - if (authRequestState_ == nullptr && authResponseState_ == nullptr) { - LOGI("DmAuthManager::GetAuthState failed"); + if (authResponseContext_ == nullptr || authMessageProcessor_ == nullptr) { + LOGE("OnDataReceived failed, authResponseContext or authMessageProcessor_ is nullptr."); return; } + authResponseContext_->sessionId = sessionId; authMessageProcessor_->SetResponseContext(authResponseContext_); int32_t ret = authMessageProcessor_->ParseMessage(message); if (ret != DM_OK) { - LOGE("OnDataReceived, parse message error"); + LOGE("OnDataReceived failed, parse input message error."); return; } - authResponseContext_ = authMessageProcessor_->GetResponseContext(); - if (authResponseState_ == nullptr) { + + if ((authRequestState_ != nullptr) && (authResponseState_ == nullptr)) { + // source device auth process authRequestContext_ = authMessageProcessor_->GetRequestContext(); authRequestState_->SetAuthContext(authRequestContext_); - } else { + LOGI("OnDataReceived for source device, authResponseContext msgType=%d, authRequestState stateType=%d", + authResponseContext_->msgType, authRequestState_->GetStateType()); + + switch (authResponseContext_->msgType) { + case MSG_TYPE_RESP_AUTH: + if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE_DONE) { + authRequestState_->TransitionTo(std::make_shared()); + } + break; + case MSG_TYPE_RESP_NEGOTIATE: + if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE) { + authRequestState_->TransitionTo(std::make_shared()); + } + break; + case MSG_TYPE_REQ_AUTH_TERMINATE: + if (authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) { + isFinishOfLocal_ = false; + authResponseContext_->state = authRequestState_->GetStateType(); + authRequestState_->TransitionTo(std::make_shared()); + } + break; + default: + break; + } + } else if ((authResponseState_ != nullptr) && (authRequestState_ == nullptr)) { + // sink device auth process authResponseState_->SetAuthContext(authResponseContext_); - } - switch (authResponseContext_->msgType) { - case MSG_TYPE_NEGOTIATE: - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_INIT - && timerMap_.find(WAIT_NEGOTIATE_TIMEOUT_TASK) != timerMap_.end()) { - timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); - authResponseState_->TransitionTo(std::make_shared()); - } else { - LOGE("Device manager auth state error"); - } - break; - case MSG_TYPE_REQ_AUTH: - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_NEGOTIATE - && timerMap_.find(WAIT_REQUEST_TIMEOUT_TASK) != timerMap_.end()) { - timerMap_[WAIT_REQUEST_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); - authResponseState_->TransitionTo(std::make_shared()); - } else { - LOGE("Device manager auth state error"); - } - break; - case MSG_TYPE_RESP_AUTH: - if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE_DONE) { - authRequestState_->TransitionTo(std::make_shared()); - } else { - LOGE("Device manager auth state error"); - } - break; - case MSG_TYPE_RESP_NEGOTIATE: - if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE) { - authRequestState_->TransitionTo(std::make_shared()); - } else { - LOGE("Device manager auth state error"); - } - break; - case MSG_TYPE_REQ_AUTH_TERMINATE: - if (authResponseState_ != nullptr && - authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) { - isFinishOfLocal_ = false; - authResponseState_->TransitionTo(std::make_shared()); - } else if (authRequestState_ != nullptr && - authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) { - isFinishOfLocal_ = false; - authResponseContext_->state = authRequestState_->GetStateType(); - authRequestState_->TransitionTo(std::make_shared()); - } - break; - default: - break; + LOGI("OnDataReceived for sink device, authResponseContext msgType=%d, authResponseState stateType=%d", + authResponseContext_->msgType, authResponseState_->GetStateType()); + + switch (authResponseContext_->msgType) { + case MSG_TYPE_NEGOTIATE: + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_INIT + && timerMap_.find(WAIT_NEGOTIATE_TIMEOUT_TASK) != timerMap_.end()) { + timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); + authResponseState_->TransitionTo(std::make_shared()); + } else { + LOGE("Device manager auth state error"); + } + break; + case MSG_TYPE_REQ_AUTH: + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_NEGOTIATE + && timerMap_.find(WAIT_REQUEST_TIMEOUT_TASK) != timerMap_.end()) { + timerMap_[WAIT_REQUEST_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); + authResponseState_->TransitionTo(std::make_shared()); + } else { + LOGE("Device manager auth state error"); + } + break; + case MSG_TYPE_REQ_AUTH_TERMINATE: + if (authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) { + isFinishOfLocal_ = false; + authResponseState_->TransitionTo(std::make_shared()); + } + break; + default: + break; + } + } else { + LOGE("DmAuthManager::OnDataReceived failed, authRequestState_ or authResponseState_ is invalid."); } } -- Gitee