diff --git a/services/implementation/include/authentication_v2/dm_auth_state_machine.h b/services/implementation/include/authentication_v2/dm_auth_state_machine.h index 48288a3a39b1cdb3442c6eb14ed68855fab13262..0a5ef25cbeb94ca6846090c71dad8fde43095afa 100644 --- a/services/implementation/include/authentication_v2/dm_auth_state_machine.h +++ b/services/implementation/include/authentication_v2/dm_auth_state_machine.h @@ -74,6 +74,8 @@ public: // Stop the thread void Stop(); + bool IsWaitEvent(); + private: // Loop to wait for state transitions and execute actions void Run(std::shared_ptr context); @@ -123,6 +125,8 @@ private: // Thread for state machine execution std::thread thread_; + + std::atomic isWait_ = false; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/auth_ui_state_manager.cpp b/services/implementation/src/authentication/auth_ui_state_manager.cpp index f234237946e6da2b6808d9e4e3fa346fdf5ca32d..e04098aec8d8277e60be628f48d910e825bbbbdd 100644 --- a/services/implementation/src/authentication/auth_ui_state_manager.cpp +++ b/services/implementation/src/authentication/auth_ui_state_manager.cpp @@ -67,8 +67,8 @@ void AuthUiStateManager::UpdateUiState(const DmUiStateMsg msg) std::lock_guard lock(pkgSetMutex_); if (pkgSet_.empty()) { LOGW("pkgSet_ is empty"); - if (msg == MSG_CANCEL_CONFIRM_SHOW) { - LOGW("cancel confirm dialog"); + if (msg == MSG_CANCEL_CONFIRM_SHOW || msg == MSG_CANCEL_PIN_CODE_INPUT || msg == MSG_CANCEL_PIN_CODE_SHOW) { + LOGW("cancel confirm or input pin code dialog"); DmDialogManager::GetInstance().CloseDialog(); return; } diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index 4b85bd8fa48abb5307a6a0499d4c599763ef5eb8..edf6452a9b94fa537afb5b6820e3ff4a63350c14 100644 --- a/services/implementation/src/authentication_v2/auth_manager.cpp +++ b/services/implementation/src/authentication_v2/auth_manager.cpp @@ -246,11 +246,17 @@ int32_t AuthManager::StopAuthenticateDevice(const std::string &pkgName) LOGI("AuthManager::StopAuthenticateDevice start"); context_->reason = STOP_BIND; + if (context_->authStateMachine->IsWaitEvent()) { + context_->authStateMachine->NotifyEventFinish(DmEventType::ON_FAIL); + return DM_OK; + } + if (context_->direction == DM_AUTH_SOURCE) { context_->authStateMachine->TransitionTo(std::make_shared()); } else { context_->authStateMachine->TransitionTo(std::make_shared()); } + context_->authStateMachine->NotifyEventFinish(DmEventType::ON_FAIL); return DM_OK; } diff --git a/services/implementation/src/authentication_v2/dm_auth_state_machine.cpp b/services/implementation/src/authentication_v2/dm_auth_state_machine.cpp index 106a7f8c279b79bfaef4bbcefdac0fc2382524cf..e5e72bb7c57fdb7da8ef9821d2af59e451ce1d5f 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state_machine.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state_machine.cpp @@ -287,9 +287,11 @@ DmEventType DmAuthStateMachine::WaitExpectEvent(DmEventType eventType) std::unique_lock lock(eventMutex_); auto startTime = std::chrono::high_resolution_clock::now(); while (running_.load()) { + isWait_.store(true); eventCv_.wait(lock, [&] { return !running_.load() || !eventQueue_.empty(); }); + isWait_.store(false); if (!running_.load()) { return DmEventType::ON_FAIL; } @@ -404,6 +406,11 @@ void DmAuthStateMachine::Stop() } } +bool DmAuthStateMachine::IsWaitEvent() +{ + return isWait_.load(); +} + void DmAuthStateMachine::SetCurState(DmAuthStateType state) { LOGI("DmAuthStateMachine::SetCurState state: %{public}d", state);