From 06ab166907d594b157deba2711443b652f7aabe3 Mon Sep 17 00:00:00 2001 From: hejiaogirl Date: Fri, 25 Jul 2025 18:13:36 +0800 Subject: [PATCH] fix : widget tip bug Signed-off-by: hejiaogirl Change-Id: I6d6a4b78ecb58d607e39a5ac38b8c6b36ac4deb1 --- services/context/inc/context_callback.h | 4 +- services/context/inc/widget_client.h | 6 +- services/context/inc/widget_context.h | 15 +- .../context/src/context_callback_impl.cpp | 16 +- services/context/src/context_callback_impl.h | 5 +- services/context/src/widget_client.cpp | 31 +++- services/context/src/widget_context.cpp | 158 +++++++----------- services/core/inc/widget_schedule_node.h | 5 +- .../core/inc/widget_schedule_node_callback.h | 2 +- .../core/src/widget_schedule_node_impl.cpp | 31 +++- services/core/src/widget_schedule_node_impl.h | 5 +- services/ipc/src/user_auth_service.cpp | 1 + test/unittest/services/mocks/mock_context.h | 4 +- .../mocks/mock_widget_schedule_node.h | 2 +- .../mock_widget_schedule_node_callback.h | 2 +- .../services/src/widget_context_test.cpp | 96 ++--------- 16 files changed, 167 insertions(+), 216 deletions(-) diff --git a/services/context/inc/context_callback.h b/services/context/inc/context_callback.h index f96ce4945..ddca9101e 100644 --- a/services/context/inc/context_callback.h +++ b/services/context/inc/context_callback.h @@ -75,6 +75,7 @@ public: virtual ~ContextCallback() = default; virtual void OnResult(int32_t resultCode, const Attributes &finalResult) = 0; virtual void OnAcquireInfo(ExecutorRole src, int32_t moduleType, const std::vector &acquireMsg) = 0; + virtual void OnClear(); virtual void SetTraceCallerName(const std::string &callerName) = 0; virtual void SetTraceRequestContextId(uint64_t requestContextId) = 0; virtual void SetTraceAuthContextId(uint64_t authContextId) = 0; @@ -95,6 +96,7 @@ public: virtual void SetTraceConnectionName(const std::string &connectionName) = 0; virtual void SetTraceAuthFinishReason(const std::string &authFinishReason) = 0; virtual void SetTraceIsBackgroundApplication(bool isBackgroundApplication) = 0; + virtual void SetDestroyContextFlag(bool destroyContextFlag) = 0; virtual int32_t ParseAuthTipInfo(int32_t tip, const std::vector &extraInfo, int32_t &authResult, int32_t &freezingTime) = 0; virtual void ProcessAuthResult(int32_t tip, const std::vector &extraInfo) = 0; @@ -104,4 +106,4 @@ public: } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // IAM_CONTEXT_CALLBACK_H \ No newline at end of file +#endif // IAM_CONTEXT_CALLBACK_H diff --git a/services/context/inc/widget_client.h b/services/context/inc/widget_client.h index f11aaf733..625f1458a 100644 --- a/services/context/inc/widget_client.h +++ b/services/context/inc/widget_client.h @@ -66,6 +66,7 @@ private: bool GetAuthTypeList(const WidgetNotice ¬ice, std::vector &authTypeList); bool IsValidNoticeType(const WidgetNotice ¬ice); void ProcessNotice(const WidgetNotice ¬ice, std::vector &authTypeList); + void ProcWidgetRelease(std::vector &authTypeList); private: std::shared_ptr schedule_ {nullptr}; @@ -78,8 +79,11 @@ private: uint32_t authTokenId_ {0}; std::vector challenge_ {}; std::string callingBundleName_ {""}; + + std::recursive_mutex mutex_; + std::vector curAuthTypeList_ {}; }; } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // IAM_WIDGET_CLIENT_H \ No newline at end of file +#endif // IAM_WIDGET_CLIENT_H diff --git a/services/context/inc/widget_context.h b/services/context/inc/widget_context.h index 1f1be28a6..f35f7007c 100644 --- a/services/context/inc/widget_context.h +++ b/services/context/inc/widget_context.h @@ -82,7 +82,7 @@ public: void AuthResult(int32_t resultCode, int32_t authType, const Attributes &finalResult); void AuthTipInfo(int32_t tipInfo, int32_t authType, const Attributes &extraInfo); - void SendAuthResult() override; + void ClearSchedule() override; void SendAuthTipInfo(int32_t authType, int32_t tipInfo) override; protected: @@ -123,12 +123,9 @@ private: void ProcAuthResult(int32_t resultCode, AuthType authType, int32_t freezingTime, const Attributes &finalResult); void ProcAuthTipInfo(int32_t tip, AuthType authType, const std::vector &extraInfo); - void StartOnResultTimer(int32_t resultCode, AuthType authType, int32_t freezingTime); - void StopOnResultTimer(); - void OnResultTimerTimeOut(int32_t resultCode, AuthType authType, int32_t freezingTime); - void StartOnTipTimer(AuthType authType, int32_t freezingTime); - void StopOnTipTimer(); - void OnTipTimerTimeOut(AuthType authType, int32_t freezingTime); + void StartClearTimer(); + void StopClearTimer(); + void OnClearTimeOut(); private: struct TaskInfo { @@ -166,9 +163,7 @@ private: WidgetAuthResultInfo authResultInfo_ {}; int32_t faceReload_ {0}; uint32_t widgetAlreadyLoad_ {0}; - uint32_t onResultTimerId_ {0}; - uint32_t onTipTimerId_ {0}; - ResultInfo resultInfo_{0}; + uint32_t clearTimerId_ {0}; }; } // namespace UserAuth } // namespace UserIam diff --git a/services/context/src/context_callback_impl.cpp b/services/context/src/context_callback_impl.cpp index e43c7eab3..f0cb43d6e 100644 --- a/services/context/src/context_callback_impl.cpp +++ b/services/context/src/context_callback_impl.cpp @@ -136,7 +136,7 @@ void ContextCallbackImpl::OnResult(int32_t resultCode, const Attributes &finalRe HandleAuthSuccessResult(resultCode, finalResult); ContextCallbackNotifyListener::GetInstance().Process(metaData_, TRACE_FLAG_DEFAULT); - if (stopCallback_ != nullptr) { + if (destroyContextFlag_ && stopCallback_ != nullptr) { stopCallback_(); } } @@ -160,6 +160,13 @@ void ContextCallbackImpl::HandleAuthSuccessResult(int32_t resultCode, const Attr static_cast(metaData_.authType.value()), metaData_.callerType.value(), metaData_.callerName.value()); } +void ContextCallbackImpl::OnClear() +{ + if (stopCallback_ != nullptr) { + stopCallback_(); + } +} + void ContextCallbackImpl::SetTraceUserId(int32_t userId) { metaData_.userId = userId; @@ -255,6 +262,11 @@ void ContextCallbackImpl::SetTraceIsBackgroundApplication(bool isBackgroundAppli metaData_.isBackgroundApplication = isBackgroundApplication; } +void ContextCallbackImpl::SetDestroyContextFlag(bool destroyContextFlag) +{ + destroyContextFlag_ = destroyContextFlag; +} + void ContextCallbackImpl::SetCleaner(Context::ContextStopCallback callback) { stopCallback_ = callback; @@ -338,4 +350,4 @@ std::shared_ptr ContextCallback::NewDummyInstance(OperationType } } // namespace UserAuth } // namespace UserIam -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/context/src/context_callback_impl.h b/services/context/src/context_callback_impl.h index d87d7a025..a324d47f6 100644 --- a/services/context/src/context_callback_impl.h +++ b/services/context/src/context_callback_impl.h @@ -30,6 +30,7 @@ public: ~ContextCallbackImpl() override = default; void OnResult(int32_t resultCode, const Attributes &finalResult) override; void OnAcquireInfo(ExecutorRole src, int32_t moduleType, const std::vector &acquireMsg) override; + void OnClear() override; void SetTraceCallerName(const std::string &callerName) override; void SetTraceRequestContextId(uint64_t requestContextId) override; void SetTraceAuthContextId(uint64_t authContextId) override; @@ -50,6 +51,7 @@ public: void SetTraceAuthFinishReason(const std::string &authFinishReason) override; void SetTraceIsBackgroundApplication(bool isBackgroundApplication) override; void SetCleaner(Context::ContextStopCallback callback) override; + void SetDestroyContextFlag(bool destroyContextFlag) override; int32_t ParseAuthTipInfo(int32_t tip, const std::vector &extraInfo, int32_t &authResult, int32_t &freezingTime) override; void ProcessAuthResult(int32_t tip, const std::vector &extraInfo) override; @@ -62,8 +64,9 @@ private: Context::ContextStopCallback stopCallback_ {nullptr}; ContextCallbackNotifyListener::MetaData metaData_; std::shared_ptr iamHitraceHelper_; + bool destroyContextFlag_ {true}; }; } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // CONTEXT_CALLBACK_IMPL_H \ No newline at end of file +#endif // CONTEXT_CALLBACK_IMPL_H diff --git a/services/context/src/widget_client.cpp b/services/context/src/widget_client.cpp index b3ea69856..78891d07c 100644 --- a/services/context/src/widget_client.cpp +++ b/services/context/src/widget_client.cpp @@ -119,8 +119,7 @@ void WidgetClient::ProcessNotice(const WidgetNotice ¬ice, std::vectorSendAuthTipInfo(authTypeList, TIP_CODE_WIDGET_LOADED); } else if (notice.event == EVENT_AUTH_WIDGET_RELEASED) { - schedule_->SendAuthTipInfo(authTypeList, TIP_CODE_WIDGET_RELEASED); - schedule_->SendAuthResult(); + ProcWidgetRelease(authTypeList); } } @@ -204,7 +203,9 @@ void WidgetClient::SetWidgetParam(const WidgetParamInner ¶m) void WidgetClient::SetAuthTypeList(const std::vector &authTypeList) { + std::lock_guard lock(mutex_); authTypeList_ = authTypeList; + curAuthTypeList_ = authTypeList; } void WidgetClient::SetWidgetCallback(const sptr &callback) @@ -225,7 +226,7 @@ uint32_t WidgetClient::GetAuthTokenId() const void WidgetClient::Reset() { - IAM_LOGD("WidgetClient Reset"); + IAM_LOGI("WidgetClient Reset"); widgetParam_.title.clear(); widgetParam_.navigationButtonText.clear(); widgetParam_.windowMode = WindowModeType::DIALOG_BOX; @@ -335,6 +336,28 @@ void WidgetClient::SetCallingBundleName(const std::string &callingBundleName) { callingBundleName_ = callingBundleName; } + +void WidgetClient::ProcWidgetRelease(std::vector &authTypeList) +{ + IF_FALSE_LOGE_AND_RETURN(schedule_ != nullptr); + schedule_->SendAuthTipInfo(authTypeList, TIP_CODE_WIDGET_RELEASED); + + std::lock_guard lock(mutex_); + for (auto &authType : authTypeList) { + std::vector::iterator it; + for (it = curAuthTypeList_.begin(); it != curAuthTypeList_.end();) { + if (*it == authType) { + it = curAuthTypeList_.erase(it); + } else { + it++; + } + } + } + + if (curAuthTypeList_.empty()) { + schedule_->ClearSchedule(); + } +} } // namespace UserAuth } // namespace UserIam -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/context/src/widget_context.cpp b/services/context/src/widget_context.cpp index 41bd350ba..cd5056a5f 100644 --- a/services/context/src/widget_context.cpp +++ b/services/context/src/widget_context.cpp @@ -66,7 +66,7 @@ const std::string TO_PORTRAIT = "90"; const std::string TO_INVERTED = "180"; const std::string TO_PORTRAIT_INVERTED = "270"; const std::string SUPPORT_FOLLOW_CALLER_UI = "const.useriam.authWidget.supportFollowCallerUi"; -static constexpr uint32_t RESULT_TIMER_LEN_MS = 100; +static constexpr uint32_t CLEAR_TIMER_LEN_MS = 1000; WidgetContext::WidgetContext(uint64_t contextId, const ContextFactory::AuthWidgetContextPara ¶, std::shared_ptr callback, const sptr &modalCallback) @@ -241,6 +241,10 @@ bool WidgetContext::OnStart() void WidgetContext::OnResult(int32_t resultCode, const std::shared_ptr &scheduleResultAttr) { IAM_LOGI("%{public}s receive result code %{public}d", description_.c_str(), resultCode); + IF_FALSE_LOGE_AND_RETURN(scheduleResultAttr != nullptr); + IF_FALSE_LOGE_AND_RETURN(callerCallback_ != nullptr); + callerCallback_->OnResult(resultCode, *scheduleResultAttr); + StartClearTimer(); } bool WidgetContext::OnStop() @@ -422,6 +426,7 @@ void WidgetContext::StopAuthList(const std::vector &authTypeList) runTaskInfoList_.erase(it); } } + StopClearTimer(); } void WidgetContext::SuccessAuth(AuthType authType) @@ -541,6 +546,7 @@ bool WidgetContext::ConnectExtension(const WidgetRotatePara &widgetRotatePara) if (IsSingleFaceOrFingerPrintAuth() && para_.skipLockedBiometricAuth && para_.authProfileMap[para_.authTypeList[0]].remainTimes == 0) { Attributes attr; + IF_FALSE_LOGE_AND_RETURN_VAL(callerCallback_ != nullptr, false); callerCallback_->OnResult(ResultCode::LOCKED, attr); return true; } @@ -610,38 +616,39 @@ void WidgetContext::End(const ResultCode &resultCode) IAM_LOGD("in End, resultCode: %{public}d", static_cast(resultCode)); StopAllRunTask(resultCode); IF_FALSE_LOGE_AND_RETURN(callerCallback_ != nullptr); - Attributes attr; + std::shared_ptr attr = Common::MakeShared(); + IF_FALSE_LOGE_AND_RETURN(attr != nullptr); if (resultCode == ResultCode::SUCCESS || authResultInfo_.token.size() != 0) { - if (!attr.SetInt32Value(Attributes::ATTR_AUTH_TYPE, authResultInfo_.authType)) { + if (!attr->SetInt32Value(Attributes::ATTR_AUTH_TYPE, authResultInfo_.authType)) { IAM_LOGE("set auth type failed."); callerCallback_->SetTraceAuthFinishReason("WidgetContext End set authType fail"); - callerCallback_->OnResult(ResultCode::GENERAL_ERROR, attr); + OnResult(ResultCode::GENERAL_ERROR, attr); return; } if (authResultInfo_.token.size() > 0) { - if (!attr.SetUint8ArrayValue(Attributes::ATTR_SIGNATURE, authResultInfo_.token)) { + if (!attr->SetUint8ArrayValue(Attributes::ATTR_SIGNATURE, authResultInfo_.token)) { IAM_LOGE("set signature token failed."); callerCallback_->SetTraceAuthFinishReason("WidgetContext End set token fail"); - callerCallback_->OnResult(ResultCode::GENERAL_ERROR, attr); + OnResult(ResultCode::GENERAL_ERROR, attr); return; } } IAM_LOGI("in End, token size: %{public}zu.", authResultInfo_.token.size()); - if (!attr.SetUint64Value(Attributes::ATTR_CREDENTIAL_DIGEST, authResultInfo_.credentialDigest)) { + if (!attr->SetUint64Value(Attributes::ATTR_CREDENTIAL_DIGEST, authResultInfo_.credentialDigest)) { IAM_LOGE("set credential digest failed."); callerCallback_->SetTraceAuthFinishReason("WidgetContext End set credentialDigest fail"); - callerCallback_->OnResult(ResultCode::GENERAL_ERROR, attr); + OnResult(ResultCode::GENERAL_ERROR, attr); return; } - if (!attr.SetUint16Value(Attributes::ATTR_CREDENTIAL_COUNT, authResultInfo_.credentialCount)) { + if (!attr->SetUint16Value(Attributes::ATTR_CREDENTIAL_COUNT, authResultInfo_.credentialCount)) { IAM_LOGE("set credential count failed."); callerCallback_->SetTraceAuthFinishReason("WidgetContext End set credentialCount fail"); - callerCallback_->OnResult(ResultCode::GENERAL_ERROR, attr); + OnResult(ResultCode::GENERAL_ERROR, attr); return; } } callerCallback_->SetTraceAuthFinishReason("WidgetContext End fail"); - callerCallback_->OnResult(resultCode, attr); + OnResult(resultCode, attr); } void WidgetContext::StopAllRunTask(const ResultCode &resultCode) @@ -662,7 +669,6 @@ void WidgetContext::StopAllRunTask(const ResultCode &resultCode) IAM_LOGE("failed to release launch widget."); } } - WidgetClient::Instance().Reset(); } void WidgetContext::BuildStartPinSubType(WidgetCmdParameters &widgetCmdParameters) @@ -808,6 +814,7 @@ void WidgetContext::ProcAuthResult(int32_t resultCode, AuthType authType, int32_ const Attributes &finalResult) { IAM_LOGI("recv task result: %{public}d, authType: %{public}d", resultCode, authType); + IF_FALSE_LOGE_AND_RETURN(schedule_ != nullptr); if (resultCode == ResultCode::SUCCESS || resultCode == ResultCode::COMPLEXITY_CHECK_FAILED) { finalResult.GetUint8ArrayValue(Attributes::ATTR_SIGNATURE, authResultInfo_.token); finalResult.GetUint64Value(Attributes::ATTR_CREDENTIAL_DIGEST, authResultInfo_.credentialDigest); @@ -817,18 +824,28 @@ void WidgetContext::ProcAuthResult(int32_t resultCode, AuthType authType, int32_ if (resultCode != ResultCode::SUCCESS) { SetLatestError(resultCode); } + schedule_->SuccessAuth(authType); } else { SetLatestError(resultCode); if (resultCode != ResultCode::CANCELED) { SendAuthTipInfo(authType, GetAuthTipCode(resultCode, freezingTime)); } + if (para_.skipLockedBiometricAuth && freezingTime > 0) { + if (IsSingleFaceOrFingerPrintAuth()) { + schedule_->FailAuth(authType); + } else if (IsNavigationAuth()) { + schedule_->NaviPinAuth(); + } + } else { + schedule_->StopAuthList({authType}); + } } - StartOnResultTimer(resultCode, authType, freezingTime); } void WidgetContext::ProcAuthTipInfo(int32_t tip, AuthType authType, const std::vector &extraInfo) { IAM_LOGI("authType:%{public}d, tip:%{public}d", authType, tip); + IF_FALSE_LOGE_AND_RETURN(schedule_ != nullptr); IF_FALSE_LOGE_AND_RETURN(callerCallback_ != nullptr); int32_t resultCode = ResultCode::GENERAL_ERROR; int32_t freezingTime = -1; @@ -843,127 +860,64 @@ void WidgetContext::ProcAuthTipInfo(int32_t tip, AuthType authType, const std::v if (resultCode != ResultCode::CANCELED) { SendAuthTipInfo(authType, GetAuthTipCode(resultCode, freezingTime)); } - StartOnTipTimer(authType, freezingTime); -} - -void WidgetContext::StartOnResultTimer(int32_t resultCode, AuthType authType, int32_t freezingTime) -{ - IAM_LOGI("start"); - std::lock_guard lock(mutex_); - resultInfo_.resultCode = resultCode; - resultInfo_.authType = authType; - resultInfo_.freezingTime = freezingTime; - if (onResultTimerId_ != 0) { - IAM_LOGI("onResult timer is already start"); - return; - } - - onResultTimerId_ = RelativeTimer::GetInstance().Register( - [weakSelf = weak_from_this(), resultCode, authType, freezingTime] { - auto self = weakSelf.lock(); - if (self == nullptr) { - IAM_LOGE("context is released"); - return; - } - self->OnResultTimerTimeOut(resultCode, authType, freezingTime); - }, - RESULT_TIMER_LEN_MS); -} - -void WidgetContext::StopOnResultTimer() -{ - IAM_LOGI("start"); - std::lock_guard lock(mutex_); - if (onResultTimerId_ == 0) { - IAM_LOGI("onResult timer is already stop"); - return; + if (para_.skipLockedBiometricAuth && freezingTime > 0) { + if (IsSingleFaceOrFingerPrintAuth()) { + schedule_->FailAuth(authType); + } else if (IsNavigationAuth()) { + schedule_->NaviPinAuth(); + } } - - RelativeTimer::GetInstance().Unregister(onResultTimerId_); - onResultTimerId_ = 0; } -void WidgetContext::OnResultTimerTimeOut(int32_t resultCode, AuthType authType, int32_t freezingTime) +void WidgetContext::ClearSchedule() { IAM_LOGI("start"); - IF_FALSE_LOGE_AND_RETURN(schedule_ != nullptr); - if (resultCode == ResultCode::SUCCESS || resultCode == ResultCode::COMPLEXITY_CHECK_FAILED) { - schedule_->SuccessAuth(authType); - } else { - if (para_.skipLockedBiometricAuth && freezingTime > 0) { - if (IsSingleFaceOrFingerPrintAuth()) { - schedule_->FailAuth(authType); - } else if (IsNavigationAuth()) { - schedule_->NaviPinAuth(); - } - } else { - schedule_->StopAuthList({authType}); - } - } + WidgetClient::Instance().Reset(); + OnClearTimeOut(); + StopClearTimer(); } -void WidgetContext::StartOnTipTimer(AuthType authType, int32_t freezingTime) +void WidgetContext::StartClearTimer() { IAM_LOGI("start"); std::lock_guard lock(mutex_); - resultInfo_.resultCode = FAIL; - resultInfo_.authType = authType; - resultInfo_.freezingTime = freezingTime; - if (onTipTimerId_ != 0) { - IAM_LOGI("onTip timer is already start"); + if (clearTimerId_ != 0) { + IAM_LOGI("clear timer is already start"); return; } - onTipTimerId_ = RelativeTimer::GetInstance().Register( - [weakSelf = weak_from_this(), authType, freezingTime] { + clearTimerId_ = RelativeTimer::GetInstance().Register( + [weakSelf = weak_from_this()] { auto self = weakSelf.lock(); if (self == nullptr) { IAM_LOGE("context is released"); return; } - self->OnTipTimerTimeOut(authType, freezingTime); + self->OnClearTimeOut(); }, - RESULT_TIMER_LEN_MS); + CLEAR_TIMER_LEN_MS); } -void WidgetContext::StopOnTipTimer() +void WidgetContext::StopClearTimer() { IAM_LOGI("start"); std::lock_guard lock(mutex_); - if (onTipTimerId_ == 0) { - IAM_LOGI("onTip timer is already stop"); + if (clearTimerId_ == 0) { + IAM_LOGI("clear timer is already stop"); return; } - RelativeTimer::GetInstance().Unregister(onTipTimerId_); - onTipTimerId_ = 0; -} - -void WidgetContext::OnTipTimerTimeOut(AuthType authType, int32_t freezingTime) -{ - IAM_LOGI("start"); - IF_FALSE_LOGE_AND_RETURN(schedule_ != nullptr); - if (para_.skipLockedBiometricAuth && freezingTime > 0) { - if (IsSingleFaceOrFingerPrintAuth()) { - schedule_->FailAuth(authType); - } else if (IsNavigationAuth()) { - schedule_->NaviPinAuth(); - } - } + RelativeTimer::GetInstance().Unregister(clearTimerId_); + clearTimerId_ = 0; } -void WidgetContext::SendAuthResult() +void WidgetContext::OnClearTimeOut() { IAM_LOGI("start"); + IF_FALSE_LOGE_AND_RETURN(callerCallback_ != nullptr); std::lock_guard lock(mutex_); - if (onTipTimerId_ != 0 && resultInfo_.resultCode != SUCCESS) { - OnTipTimerTimeOut(resultInfo_.authType, resultInfo_.freezingTime); - StopOnTipTimer(); - } - - if (onResultTimerId_ != 0) { - OnResultTimerTimeOut(resultInfo_.resultCode, resultInfo_.authType, resultInfo_.freezingTime); - StopOnResultTimer(); + if (clearTimerId_ != 0) { + callerCallback_->OnClear(); } } } // namespace UserAuth diff --git a/services/core/inc/widget_schedule_node.h b/services/core/inc/widget_schedule_node.h index fb16dcd8f..471742c5c 100644 --- a/services/core/inc/widget_schedule_node.h +++ b/services/core/inc/widget_schedule_node.h @@ -51,6 +51,7 @@ public: E_WIDGET_PARA_INVALID = 6, E_WIDGET_RELOAD = 7, E_STOP_AUTH = 8, + E_CLEAR_AUTH = 9, }; virtual ~WidgetScheduleNode() = default; @@ -67,9 +68,9 @@ public: AuthType &rotateAuthType) = 0; virtual void SetCallback(std::shared_ptr callback) = 0; virtual void SendAuthTipInfo(const std::vector &authTypeList, int32_t tipCode) = 0; - virtual void SendAuthResult() = 0; + virtual bool ClearSchedule() = 0; }; } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // IAM_WIDGET_SCHEDULE_NODE_H \ No newline at end of file +#endif // IAM_WIDGET_SCHEDULE_NODE_H diff --git a/services/core/inc/widget_schedule_node_callback.h b/services/core/inc/widget_schedule_node_callback.h index 2f409317f..2c64b092b 100644 --- a/services/core/inc/widget_schedule_node_callback.h +++ b/services/core/inc/widget_schedule_node_callback.h @@ -44,7 +44,7 @@ public: AuthType &rotateAuthType) = 0; virtual void AuthWidgetReloadInit() = 0; virtual void SendAuthTipInfo(int32_t authType, int32_t tipInfo) = 0; - virtual void SendAuthResult() = 0; + virtual void ClearSchedule() = 0; }; } // namespace UserAuth } // namespace UserIam diff --git a/services/core/src/widget_schedule_node_impl.cpp b/services/core/src/widget_schedule_node_impl.cpp index 0f6cf98c5..5a65bbc56 100644 --- a/services/core/src/widget_schedule_node_impl.cpp +++ b/services/core/src/widget_schedule_node_impl.cpp @@ -80,6 +80,13 @@ std::shared_ptr WidgetScheduleNodeImpl::MakeFiniteStateMachi builder->MakeTransition(S_WIDGET_RELOAD_WAITING, E_CANCEL_AUTH, S_WIDGET_WAITING, [this](FiniteStateMachine &machine, uint32_t event) { OnWidgetReload(machine, event); }); + builder->MakeTransition(S_WIDGET_WAITING, E_CLEAR_AUTH, S_WIDGET_INIT, + [this](FiniteStateMachine &machine, uint32_t event) { OnClearSchedule(machine, event); }); + builder->MakeTransition(S_WIDGET_AUTH_RUNNING, E_CLEAR_AUTH, S_WIDGET_INIT, + [this](FiniteStateMachine &machine, uint32_t event) { OnClearSchedule(machine, event); }); + builder->MakeTransition(S_WIDGET_AUTH_FINISHED, E_CLEAR_AUTH, S_WIDGET_INIT, + [this](FiniteStateMachine &machine, uint32_t event) { OnClearSchedule(machine, event); }); + return builder->Build(); } @@ -111,6 +118,12 @@ bool WidgetScheduleNodeImpl::StopSchedule() return TryKickMachine(E_CANCEL_AUTH); } +bool WidgetScheduleNodeImpl::ClearSchedule() +{ + std::lock_guard lock(mutex_); + return TryKickMachine(E_CLEAR_AUTH); +} + bool WidgetScheduleNodeImpl::StartAuthList(const std::vector &authTypeList, bool endAfterFirstFail, AuthIntent authIntent) { @@ -269,23 +282,23 @@ void WidgetScheduleNodeImpl::OnWidgetReload(FiniteStateMachine &machine, uint32_ } } -void WidgetScheduleNodeImpl::SendAuthTipInfo(const std::vector &authTypeList, int32_t tipCode) +void WidgetScheduleNodeImpl::OnClearSchedule(FiniteStateMachine &machine, uint32_t event) { auto callback = callback_.lock(); IF_FALSE_LOGE_AND_RETURN(callback != nullptr); - IAM_LOGI("send mid auth result"); - for (auto &authType : authTypeList) { - callback->SendAuthTipInfo(authType, tipCode); - } + IAM_LOGI("clear schedule"); + callback->ClearSchedule(); } -void WidgetScheduleNodeImpl::SendAuthResult() +void WidgetScheduleNodeImpl::SendAuthTipInfo(const std::vector &authTypeList, int32_t tipCode) { auto callback = callback_.lock(); IF_FALSE_LOGE_AND_RETURN(callback != nullptr); - IAM_LOGI("send auth result"); - callback->SendAuthResult(); + IAM_LOGI("send mid auth result"); + for (auto &authType : authTypeList) { + callback->SendAuthTipInfo(authType, tipCode); + } } } // namespace UserAuth } // namespace UserIam -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/core/src/widget_schedule_node_impl.h b/services/core/src/widget_schedule_node_impl.h index 69456e0ad..ec8ee7228 100644 --- a/services/core/src/widget_schedule_node_impl.h +++ b/services/core/src/widget_schedule_node_impl.h @@ -50,7 +50,7 @@ public: AuthType &rotateAuthType) override; void SetCallback(std::shared_ptr callback) override; void SendAuthTipInfo(const std::vector &authTypeList, int32_t tipCode) override; - void SendAuthResult() override; + bool ClearSchedule() override; protected: void OnStartSchedule(FiniteStateMachine &machine, uint32_t event); @@ -63,6 +63,7 @@ protected: void OnWidgetReload(FiniteStateMachine &machine, uint32_t event); void OnWidgetReloadInit(FiniteStateMachine &machine, uint32_t event); void OnFailAuth(FiniteStateMachine &machine, uint32_t event); + void OnClearSchedule(FiniteStateMachine &machine, uint32_t event); private: std::shared_ptr MakeFiniteStateMachine(); @@ -89,4 +90,4 @@ private: } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // IAM_WIDGET_SCHEDULE_NODE_IMPL_H \ No newline at end of file +#endif // IAM_WIDGET_SCHEDULE_NODE_IMPL_H diff --git a/services/ipc/src/user_auth_service.cpp b/services/ipc/src/user_auth_service.cpp index 0eee2ac1f..4ed18742b 100644 --- a/services/ipc/src/user_auth_service.cpp +++ b/services/ipc/src/user_auth_service.cpp @@ -1172,6 +1172,7 @@ uint64_t UserAuthService::StartWidgetContext(const std::shared_ptrSetTraceRequestContextId(context->GetContextId()); contextCallback->SetCleaner(ContextHelper::Cleaner(context)); + contextCallback->SetDestroyContextFlag(false); if (!context->Start()) { int32_t errorCode = context->GetLatestError(); IAM_LOGE("start widget context fail %{public}d", errorCode); diff --git a/test/unittest/services/mocks/mock_context.h b/test/unittest/services/mocks/mock_context.h index a1045daa4..165fa52c7 100644 --- a/test/unittest/services/mocks/mock_context.h +++ b/test/unittest/services/mocks/mock_context.h @@ -62,6 +62,8 @@ public: MOCK_METHOD1(SetTraceConnectionName, void(const std::string &connectionName)); MOCK_METHOD1(SetTraceAuthFinishReason, void(const std::string &authFinishReason)); MOCK_METHOD1(SetTraceIsBackgroundApplication, void(const bool isBackgroundApplication)); + MOCK_METHOD1(SetDestroyContextFlag, void(bool destroyContextFlag)); + MOCK_METHOD0(OnClear, void()); }; class MockContext final : public Context { @@ -142,4 +144,4 @@ protected: } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // IAM_MOCK_CONTEXT_H \ No newline at end of file +#endif // IAM_MOCK_CONTEXT_H diff --git a/test/unittest/services/mocks/mock_widget_schedule_node.h b/test/unittest/services/mocks/mock_widget_schedule_node.h index 5b7a15550..274f53dbf 100644 --- a/test/unittest/services/mocks/mock_widget_schedule_node.h +++ b/test/unittest/services/mocks/mock_widget_schedule_node.h @@ -37,7 +37,7 @@ public: MOCK_METHOD4(WidgetReload, bool(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad, AuthType &rotateAuthType)); MOCK_METHOD2(SendAuthTipInfo, void(const std::vector &authTypeList, int32_t tipCode)); - MOCK_METHOD0(SendAuthResult, void()); + MOCK_METHOD0(ClearSchedule, bool()); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/mocks/mock_widget_schedule_node_callback.h b/test/unittest/services/mocks/mock_widget_schedule_node_callback.h index 4963fa6ff..79b072cdb 100644 --- a/test/unittest/services/mocks/mock_widget_schedule_node_callback.h +++ b/test/unittest/services/mocks/mock_widget_schedule_node_callback.h @@ -37,7 +37,7 @@ public: MOCK_METHOD1(SuccessAuth, void(AuthType authType)); MOCK_METHOD1(FailAuth, void(AuthType authType)); MOCK_METHOD2(SendAuthTipInfo, void(int32_t authType, int32_t tipInfo)); - MOCK_METHOD0(SendAuthResult, void()); + MOCK_METHOD0(ClearSchedule, void()); MOCK_METHOD4(AuthWidgetReload, bool(uint32_t orientation, uint32_t needRotate, uint32_t alreadyLoad, AuthType &rotateAuthType)); MOCK_METHOD0(AuthWidgetReloadInit, void()); diff --git a/test/unittest/services/src/widget_context_test.cpp b/test/unittest/services/src/widget_context_test.cpp index 19f3e0c0d..e67056688 100644 --- a/test/unittest/services/src/widget_context_test.cpp +++ b/test/unittest/services/src/widget_context_test.cpp @@ -718,110 +718,50 @@ HWTEST_F(WidgetContextTest, WidgetContextTestProcAuthTipInfo, TestSize.Level0) EXPECT_NO_THROW(widgetContext->ProcAuthTipInfo(0, PIN, extraInfo)); } -HWTEST_F(WidgetContextTest, WidgetContextTestStopOnResultTimer, TestSize.Level0) -{ - uint64_t contextId = 1; - ContextFactory::AuthWidgetContextPara para; - auto widgetContext = CreateWidgetContext(contextId, para); - EXPECT_NE(widgetContext, nullptr); - EXPECT_NO_THROW(widgetContext->StopOnResultTimer()); - widgetContext->onResultTimerId_ = 1; - EXPECT_NO_THROW(widgetContext->StopOnResultTimer()); -} - -HWTEST_F(WidgetContextTest, WidgetContextTestOnResultTimerTimeOut, TestSize.Level0) -{ - uint64_t contextId = 1; - ContextFactory::AuthWidgetContextPara para; - auto widgetContext = CreateWidgetContext(contextId, para); - int32_t resultCode = 0; - AuthType authType = AuthType::ALL; - int32_t freezingTime = 0; - widgetContext->BuildSchedule(); - EXPECT_NO_THROW(widgetContext->OnResultTimerTimeOut(resultCode, authType, freezingTime)); - resultCode = 1; - EXPECT_NO_THROW(widgetContext->OnResultTimerTimeOut(resultCode, authType, freezingTime)); - freezingTime = 1; - widgetContext->para_.skipLockedBiometricAuth = true; - EXPECT_NO_THROW(widgetContext->OnResultTimerTimeOut(resultCode, authType, freezingTime)); - widgetContext->para_.widgetParam.navigationButtonText = "1"; - EXPECT_NO_THROW(widgetContext->OnResultTimerTimeOut(resultCode, authType, freezingTime)); - widgetContext->para_.widgetParam.navigationButtonText = ""; - authType = AuthType::FACE; - widgetContext->para_.authTypeList.emplace_back(authType); - EXPECT_NO_THROW(widgetContext->OnResultTimerTimeOut(resultCode, authType, freezingTime)); -} - -HWTEST_F(WidgetContextTest, WidgetContextTestStopOnTipTimer, TestSize.Level0) +HWTEST_F(WidgetContextTest, WidgetContextTestSetSysDialogZOrder, TestSize.Level0) { uint64_t contextId = 1; ContextFactory::AuthWidgetContextPara para; auto widgetContext = CreateWidgetContext(contextId, para); EXPECT_NE(widgetContext, nullptr); - EXPECT_NO_THROW(widgetContext->StopOnTipTimer()); - widgetContext->onTipTimerId_ = 1; - EXPECT_NO_THROW(widgetContext->StopOnTipTimer()); + WidgetCmdParameters widgetCmdParameters = {}; + EXPECT_NO_THROW(widgetContext->SetSysDialogZOrder(widgetCmdParameters)); + widgetContext->para_.callerName = "findnetwork"; + widgetContext->para_.callerType = Security::AccessToken::TOKEN_NATIVE; + EXPECT_NO_THROW(widgetContext->SetSysDialogZOrder(widgetCmdParameters)); } -HWTEST_F(WidgetContextTest, WidgetContextTestOnTipTimerTimeOut, TestSize.Level0) +HWTEST_F(WidgetContextTest, WidgetContextTestConnectExtension, TestSize.Level0) { uint64_t contextId = 1; ContextFactory::AuthWidgetContextPara para; auto widgetContext = CreateWidgetContext(contextId, para); EXPECT_NE(widgetContext, nullptr); - AuthType authType = AuthType::ALL; - int32_t freezingTime = 0; - widgetContext->BuildSchedule(); - EXPECT_NO_THROW(widgetContext->OnTipTimerTimeOut(authType, freezingTime)); - widgetContext->para_.skipLockedBiometricAuth = true; - freezingTime = 1; - EXPECT_NO_THROW(widgetContext->OnTipTimerTimeOut(authType, freezingTime)); - widgetContext->para_.widgetParam.navigationButtonText = "1"; - EXPECT_NO_THROW(widgetContext->OnTipTimerTimeOut(authType, freezingTime)); - widgetContext->para_.widgetParam.navigationButtonText = ""; - authType = AuthType::FACE; + WidgetContext::WidgetRotatePara widgetRotatePara = {}; + widgetRotatePara.isReload = true; + AuthType authType = AuthType::FACE; widgetContext->para_.authTypeList.emplace_back(authType); - EXPECT_NO_THROW(widgetContext->OnTipTimerTimeOut(authType, freezingTime)); -} - -HWTEST_F(WidgetContextTest, WidgetContextTestSendAuthResult, TestSize.Level0) -{ - uint64_t contextId = 1; - ContextFactory::AuthWidgetContextPara para; - auto widgetContext = CreateWidgetContext(contextId, para); - EXPECT_NE(widgetContext, nullptr); - EXPECT_NO_THROW(widgetContext->SendAuthResult()); - widgetContext->onTipTimerId_ = 1; - widgetContext->resultInfo_.resultCode = 1; - EXPECT_NO_THROW(widgetContext->SendAuthResult()); - widgetContext->onResultTimerId_ = 1; - EXPECT_NO_THROW(widgetContext->SendAuthResult()); + EXPECT_EQ(widgetContext->ConnectExtension(widgetRotatePara), false); } -HWTEST_F(WidgetContextTest, WidgetContextTestSetSysDialogZOrder, TestSize.Level0) +HWTEST_F(WidgetContextTest, WidgetContextTestSelfDestructTimer, TestSize.Level0) { uint64_t contextId = 1; ContextFactory::AuthWidgetContextPara para; auto widgetContext = CreateWidgetContext(contextId, para); EXPECT_NE(widgetContext, nullptr); - WidgetCmdParameters widgetCmdParameters = {}; - EXPECT_NO_THROW(widgetContext->SetSysDialogZOrder(widgetCmdParameters)); - widgetContext->para_.callerName = "findnetwork"; - widgetContext->para_.callerType = Security::AccessToken::TOKEN_NATIVE; - EXPECT_NO_THROW(widgetContext->SetSysDialogZOrder(widgetCmdParameters)); + EXPECT_NO_THROW(widgetContext->StopClearTimer()); + widgetContext->clearTimerId_ = 1; + EXPECT_NO_THROW(widgetContext->StopClearTimer()); } -HWTEST_F(WidgetContextTest, WidgetContextTestConnectExtension, TestSize.Level0) +HWTEST_F(WidgetContextTest, WidgetContextTestSelfDestructTimerTimeOut, TestSize.Level0) { uint64_t contextId = 1; ContextFactory::AuthWidgetContextPara para; auto widgetContext = CreateWidgetContext(contextId, para); - EXPECT_NE(widgetContext, nullptr); - WidgetContext::WidgetRotatePara widgetRotatePara = {}; - widgetRotatePara.isReload = true; - AuthType authType = AuthType::FACE; - widgetContext->para_.authTypeList.emplace_back(authType); - EXPECT_EQ(widgetContext->ConnectExtension(widgetRotatePara), false); + widgetContext->BuildSchedule(); + EXPECT_NO_THROW(widgetContext->OnClearTimeOut()); } } // namespace UserAuth } // namespace UserIam -- Gitee