diff --git a/frameworks/common/inc/auth_common.h b/frameworks/common/inc/auth_common.h index 517db15f1bd6d5433e8aaa20c6ebf9ed78594bc8..64697fb0e32d9d8bf9d6c79b80401fdac167f787 100644 --- a/frameworks/common/inc/auth_common.h +++ b/frameworks/common/inc/auth_common.h @@ -50,9 +50,8 @@ constexpr const char *NOTICE_EVENT_USER_NAVIGATION = "EVENT_AUTH_USER_NAVIGATION constexpr const char *NOTICE_EVENT_WIDGET_PARA_INVALID = "EVENT_AUTH_WIDGET_PARA_INVALID"; constexpr const char *NOTICE_EVENT_END = "EVENT_AUTH_END"; constexpr const char *NOTICE_EVENT_RELOAD = "EVENT_AUTH_RELOAD"; -constexpr const char *NOTICE_EVENT_AUTH_WIDGET_LOADED = "EVENT_AUTH_WIDGET_LOADED"; -constexpr const char *NOTICE_EVENT_AUTH_WIDGET_RELEASED = "EVENT_AUTH_WIDGET_RELEASED"; -constexpr const char *NOTICE_EVENT_PROCESS_TERMINATE = "EVENT_PROCESS_TERMINATE"; +constexpr const char *EVENT_AUTH_WIDGET_LOADED = "EVENT_AUTH_WIDGET_LOADED"; +constexpr const char *EVENT_AUTH_WIDGET_RELEASED = "EVENT_AUTH_WIDGET_RELEASED"; // For API6 enum class AuthenticationResult : int32_t { diff --git a/services/context/inc/widget_context.h b/services/context/inc/widget_context.h index 5f6e9d0edce6647cb0c9adf3ac05f01834826616..0f42bf3d5f5e999440e6cb7a5bafbf2ad659a23d 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 ClearSchedule() override; + void SendAuthResult() override; void SendAuthTipInfo(int32_t authType, int32_t tipInfo) override; protected: @@ -123,6 +123,12 @@ 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); private: struct TaskInfo { @@ -160,6 +166,9 @@ private: WidgetAuthResultInfo authResultInfo_ {}; int32_t faceReload_ {0}; uint32_t widgetAlreadyLoad_ {0}; + uint32_t onResultTimerId_ {0}; + uint32_t onTipTimerId_ {0}; + ResultInfo resultInfo_{0}; nlohmann::json jsonBuf_ = {}; }; } // namespace UserAuth diff --git a/services/context/src/widget_client.cpp b/services/context/src/widget_client.cpp index 6d49af4d6348c29487e113b773d8013549101154..b3ea698563c45a6367954e1788058c546e5d6a37 100644 --- a/services/context/src/widget_client.cpp +++ b/services/context/src/widget_client.cpp @@ -116,12 +116,11 @@ void WidgetClient::ProcessNotice(const WidgetNotice ¬ice, std::vectorWidgetReload(notice.orientation, notice.needRotate, notice.alreadyLoad, authTypeList[0]); } - } else if (notice.event == NOTICE_EVENT_AUTH_WIDGET_LOADED) { + } else if (notice.event == EVENT_AUTH_WIDGET_LOADED) { schedule_->SendAuthTipInfo(authTypeList, TIP_CODE_WIDGET_LOADED); - } else if (notice.event == NOTICE_EVENT_AUTH_WIDGET_RELEASED) { + } else if (notice.event == EVENT_AUTH_WIDGET_RELEASED) { schedule_->SendAuthTipInfo(authTypeList, TIP_CODE_WIDGET_RELEASED); - } else if (notice.event == NOTICE_EVENT_PROCESS_TERMINATE) { - schedule_->ClearSchedule(); + schedule_->SendAuthResult(); } } @@ -241,9 +240,12 @@ void WidgetClient::Reset() void WidgetClient::ForceStopAuth() { IAM_LOGE("stop auth process forcely by disconnect"); + if (widgetContextId_ != 0) { + IAM_LOGE("widget context id hasn't been reset"); + UserIam::UserAuth::ReportSystemFault(Common::GetNowTimeString(), "AuthWidget"); + } if (schedule_ != nullptr) { schedule_->StopSchedule(); - schedule_->ClearSchedule(); } } @@ -317,9 +319,8 @@ bool WidgetClient::IsValidNoticeType(const WidgetNotice ¬ice) notice.event != NOTICE_EVENT_WIDGET_PARA_INVALID && notice.event != NOTICE_EVENT_RELOAD && notice.event != NOTICE_EVENT_END && - notice.event != NOTICE_EVENT_AUTH_WIDGET_LOADED && - notice.event != NOTICE_EVENT_AUTH_WIDGET_RELEASED && - notice.event != NOTICE_EVENT_PROCESS_TERMINATE) { + notice.event != EVENT_AUTH_WIDGET_LOADED && + notice.event != EVENT_AUTH_WIDGET_RELEASED) { return false; } return true; @@ -336,4 +337,4 @@ void WidgetClient::SetCallingBundleName(const std::string &callingBundleName) } } // namespace UserAuth } // namespace UserIam -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/context/src/widget_context.cpp b/services/context/src/widget_context.cpp index 2b227620e0680393bfe343a3b67213dd727247dd..74612a3f271503e857f0d5d70ea7405ad1801fb1 100644 --- a/services/context/src/widget_context.cpp +++ b/services/context/src/widget_context.cpp @@ -66,6 +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; WidgetContext::WidgetContext(uint64_t contextId, const ContextFactory::AuthWidgetContextPara ¶, std::shared_ptr callback, const sptr &modalCallback) @@ -668,6 +669,7 @@ void WidgetContext::StopAllRunTask(const ResultCode &resultCode) IAM_LOGE("failed to release launch widget."); } } + WidgetClient::Instance().Reset(); } void WidgetContext::BuildStartPinSubType(WidgetCmdParameters &widgetCmdParameters) @@ -813,7 +815,6 @@ 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); @@ -823,28 +824,18 @@ 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; @@ -859,6 +850,106 @@ 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; + } + + RelativeTimer::GetInstance().Unregister(onResultTimerId_); + onResultTimerId_ = 0; +} + +void WidgetContext::OnResultTimerTimeOut(int32_t resultCode, AuthType authType, int32_t freezingTime) +{ + 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}); + } + } +} + +void WidgetContext::StartOnTipTimer(AuthType authType, int32_t freezingTime) +{ + 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"); + return; + } + + onTipTimerId_ = RelativeTimer::GetInstance().Register( + [weakSelf = weak_from_this(), authType, freezingTime] { + auto self = weakSelf.lock(); + if (self == nullptr) { + IAM_LOGE("context is released"); + return; + } + self->OnTipTimerTimeOut(authType, freezingTime); + }, + RESULT_TIMER_LEN_MS); +} + +void WidgetContext::StopOnTipTimer() +{ + IAM_LOGI("start"); + std::lock_guard lock(mutex_); + if (onTipTimerId_ == 0) { + IAM_LOGI("onTip 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); @@ -868,12 +959,19 @@ void WidgetContext::ProcAuthTipInfo(int32_t tip, AuthType authType, const std::v } } -void WidgetContext::ClearSchedule() +void WidgetContext::SendAuthResult() { IAM_LOGI("start"); - WidgetClient::Instance().Reset(); - auto result = ContextPool::Instance().Delete(GetContextId()); - IAM_LOGI("context ****%{public}hx deleted %{public}s", static_cast(contextId_), result ? "succ" : "fail"); + 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(); + } } } // namespace UserAuth } // namespace UserIam diff --git a/services/core/inc/widget_schedule_node.h b/services/core/inc/widget_schedule_node.h index 3d93090c77f1bd09a3ea1a1515b5b532d7fdb431..fb16dcd8f040dc19f10ec034f7400a61b56f6e0c 100644 --- a/services/core/inc/widget_schedule_node.h +++ b/services/core/inc/widget_schedule_node.h @@ -38,8 +38,7 @@ public: S_WIDGET_WAITING = 1, S_WIDGET_AUTH_RUNNING = 2, S_WIDGET_AUTH_FINISHED = 3, - S_WIDGET_RELOAD_WAITING = 4, - S_WIDGET_RELEASED = 5, + S_WIDGET_RELOAD_WAITING = 4 }; enum Event : uint32_t { @@ -52,7 +51,6 @@ public: E_WIDGET_PARA_INVALID = 6, E_WIDGET_RELOAD = 7, E_STOP_AUTH = 8, - E_WIDGET_RELEASE = 9, }; virtual ~WidgetScheduleNode() = default; @@ -69,9 +67,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 bool ClearSchedule() = 0; + virtual void SendAuthResult() = 0; }; } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // IAM_WIDGET_SCHEDULE_NODE_H +#endif // IAM_WIDGET_SCHEDULE_NODE_H \ No newline at end of file diff --git a/services/core/inc/widget_schedule_node_callback.h b/services/core/inc/widget_schedule_node_callback.h index 2c64b092be09d5ebc5a6300bb7b9b4ee7dcbc515..2f409317f5fcd3a452dd229a6ac643a1909676a1 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 ClearSchedule() = 0; + virtual void SendAuthResult() = 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 d869c7e19e2b953d14c0cdb1e7a1d91d327aaf68..0f6cf98c52b1fc5e5efd85264660118494311a42 100644 --- a/services/core/src/widget_schedule_node_impl.cpp +++ b/services/core/src/widget_schedule_node_impl.cpp @@ -80,17 +80,6 @@ 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_INIT, E_WIDGET_RELEASE, S_WIDGET_RELEASED, - [this](FiniteStateMachine &machine, uint32_t event) { OnWidgetRelease(machine, event); }); - builder->MakeTransition(S_WIDGET_WAITING, E_WIDGET_RELEASE, S_WIDGET_RELEASED, - [this](FiniteStateMachine &machine, uint32_t event) { OnWidgetRelease(machine, event); }); - builder->MakeTransition(S_WIDGET_AUTH_RUNNING, E_WIDGET_RELEASE, S_WIDGET_RELEASED, - [this](FiniteStateMachine &machine, uint32_t event) { OnWidgetRelease(machine, event); }); - builder->MakeTransition(S_WIDGET_AUTH_FINISHED, E_WIDGET_RELEASE, S_WIDGET_RELEASED, - [this](FiniteStateMachine &machine, uint32_t event) { OnWidgetRelease(machine, event); }); - builder->MakeTransition(S_WIDGET_RELOAD_WAITING, E_WIDGET_RELEASE, S_WIDGET_RELEASED, - [this](FiniteStateMachine &machine, uint32_t event) { OnWidgetRelease(machine, event); }); - return builder->Build(); } @@ -122,12 +111,6 @@ bool WidgetScheduleNodeImpl::StopSchedule() return TryKickMachine(E_CANCEL_AUTH); } -bool WidgetScheduleNodeImpl::ClearSchedule() -{ - std::lock_guard lock(mutex_); - return TryKickMachine(E_WIDGET_RELEASE); -} - bool WidgetScheduleNodeImpl::StartAuthList(const std::vector &authTypeList, bool endAfterFirstFail, AuthIntent authIntent) { @@ -286,14 +269,6 @@ void WidgetScheduleNodeImpl::OnWidgetReload(FiniteStateMachine &machine, uint32_ } } -void WidgetScheduleNodeImpl::OnWidgetRelease(FiniteStateMachine &machine, uint32_t event) -{ - auto callback = callback_.lock(); - IF_FALSE_LOGE_AND_RETURN(callback != nullptr); - IAM_LOGI("clear schedule"); - callback->ClearSchedule(); -} - void WidgetScheduleNodeImpl::SendAuthTipInfo(const std::vector &authTypeList, int32_t tipCode) { auto callback = callback_.lock(); @@ -303,6 +278,14 @@ void WidgetScheduleNodeImpl::SendAuthTipInfo(const std::vector &authTy callback->SendAuthTipInfo(authType, tipCode); } } + +void WidgetScheduleNodeImpl::SendAuthResult() +{ + auto callback = callback_.lock(); + IF_FALSE_LOGE_AND_RETURN(callback != nullptr); + IAM_LOGI("send auth result"); + callback->SendAuthResult(); +} } // namespace UserAuth } // namespace UserIam -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/core/src/widget_schedule_node_impl.h b/services/core/src/widget_schedule_node_impl.h index 73a121c9139fccbcc9a26fa435243fd68d9aea3f..69456e0ad8d3c0b105bae749c284e9ef8767f2de 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; - bool ClearSchedule() override; + void SendAuthResult() override; protected: void OnStartSchedule(FiniteStateMachine &machine, uint32_t event); @@ -63,7 +63,6 @@ protected: void OnWidgetReload(FiniteStateMachine &machine, uint32_t event); void OnWidgetReloadInit(FiniteStateMachine &machine, uint32_t event); void OnFailAuth(FiniteStateMachine &machine, uint32_t event); - void OnWidgetRelease(FiniteStateMachine &machine, uint32_t event); private: std::shared_ptr MakeFiniteStateMachine(); @@ -90,4 +89,4 @@ private: } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // IAM_WIDGET_SCHEDULE_NODE_IMPL_H +#endif // IAM_WIDGET_SCHEDULE_NODE_IMPL_H \ No newline at end of file diff --git a/services/ipc/src/user_auth_service.cpp b/services/ipc/src/user_auth_service.cpp index 973e84a75be7e2656bbfe7ec53b70edfaa447d72..0eee2ac1f7cdec1412593bcb05692f93a7c323cf 100644 --- a/services/ipc/src/user_auth_service.cpp +++ b/services/ipc/src/user_auth_service.cpp @@ -1171,6 +1171,7 @@ uint64_t UserAuthService::StartWidgetContext(const std::shared_ptrSetTraceRequestContextId(context->GetContextId()); + contextCallback->SetCleaner(ContextHelper::Cleaner(context)); 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 7336ffb68185cd8fb56006c95b105b6b5521135f..a1045daa45f47c554adbe42435b9ef1456567a13 100644 --- a/test/unittest/services/mocks/mock_context.h +++ b/test/unittest/services/mocks/mock_context.h @@ -142,4 +142,4 @@ protected: } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // IAM_MOCK_CONTEXT_H +#endif // IAM_MOCK_CONTEXT_H \ No newline at end of file diff --git a/test/unittest/services/mocks/mock_widget_schedule_node.h b/test/unittest/services/mocks/mock_widget_schedule_node.h index 274f53dbf1a398377938f1dba7fb6c68fbf58a93..5b7a15550782b802ac8e418baf542ae22e0a8698 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(ClearSchedule, bool()); + MOCK_METHOD0(SendAuthResult, void()); }; } // 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 79b072cdbccc9297840361c481731c9b88e6792d..4963fa6ffcf4642587eb66d8b9c5d974cf53bb76 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(ClearSchedule, void()); + MOCK_METHOD0(SendAuthResult, 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_client_test.cpp b/test/unittest/services/src/widget_client_test.cpp index 29821e5a7f1ae21010b6bc858f278918acb8b2f8..16879eacf1ff72b240b5c0b8394a3b223b08d158 100644 --- a/test/unittest/services/src/widget_client_test.cpp +++ b/test/unittest/services/src/widget_client_test.cpp @@ -498,7 +498,7 @@ HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_006, TestSize.Level0) { WidgetNotice widgetNotice; widgetNotice.widgetContextId = 1; - widgetNotice.event = NOTICE_EVENT_AUTH_WIDGET_LOADED; + widgetNotice.event = EVENT_AUTH_WIDGET_LOADED; widgetNotice.typeList.push_back("pin"); WidgetClient::Instance().Reset(); std::vector authTypeList; @@ -512,21 +512,7 @@ HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_007, TestSize.Level0) { WidgetNotice widgetNotice; widgetNotice.widgetContextId = 1; - widgetNotice.event = NOTICE_EVENT_AUTH_WIDGET_RELEASED; - widgetNotice.typeList.push_back("pin"); - WidgetClient::Instance().Reset(); - std::vector authTypeList; - authTypeList.emplace_back(AuthType::PIN); - WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); - EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList)); -} - -HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_008, TestSize.Level0) -{ - WidgetNotice widgetNotice; - widgetNotice.widgetContextId = 1; - widgetNotice.event = NOTICE_EVENT_PROCESS_TERMINATE; + widgetNotice.event = EVENT_AUTH_WIDGET_RELEASED; widgetNotice.typeList.push_back("pin"); WidgetClient::Instance().Reset(); std::vector authTypeList; diff --git a/test/unittest/services/src/widget_context_test.cpp b/test/unittest/services/src/widget_context_test.cpp index 481112c2473ad4e650497a803c5bd88d24704b8a..19f3e0c0d99ed172771b6101ae588cf78837a32c 100644 --- a/test/unittest/services/src/widget_context_test.cpp +++ b/test/unittest/services/src/widget_context_test.cpp @@ -718,6 +718,86 @@ 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) +{ + 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()); +} + +HWTEST_F(WidgetContextTest, WidgetContextTestOnTipTimerTimeOut, 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->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()); +} + HWTEST_F(WidgetContextTest, WidgetContextTestSetSysDialogZOrder, TestSize.Level0) { uint64_t contextId = 1;