From c9226f52a47b500197300dfdf59023ecc225406f Mon Sep 17 00:00:00 2001 From: hejiaogirl Date: Fri, 1 Aug 2025 16:45:53 +0800 Subject: [PATCH] fix : widget tip bug Signed-off-by: hejiaogirl Change-Id: I20336853b30ed1c8fde219981fb20c2b0203940c --- frameworks/common/inc/auth_common.h | 6 +- services/context/inc/widget_client.h | 11 +- services/context/inc/widget_context.h | 11 +- services/context/inc/widget_json.h | 1 + services/context/src/widget_client.cpp | 93 ++++++++---- services/context/src/widget_context.cpp | 135 +++--------------- services/context/src/widget_json.cpp | 7 +- services/core/inc/widget_schedule_node.h | 8 +- .../core/inc/widget_schedule_node_callback.h | 2 +- .../core/src/widget_schedule_node_impl.cpp | 35 +++-- services/core/src/widget_schedule_node_impl.h | 5 +- services/ipc/src/user_auth_service.cpp | 1 - test/unittest/services/mocks/mock_context.h | 2 +- .../mocks/mock_widget_schedule_node.h | 2 +- .../mock_widget_schedule_node_callback.h | 2 +- .../services/src/widget_client_test.cpp | 73 ++++++---- .../services/src/widget_context_test.cpp | 80 ----------- 17 files changed, 193 insertions(+), 281 deletions(-) diff --git a/frameworks/common/inc/auth_common.h b/frameworks/common/inc/auth_common.h index a25084c29..ec47c36c5 100644 --- a/frameworks/common/inc/auth_common.h +++ b/frameworks/common/inc/auth_common.h @@ -51,8 +51,10 @@ 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 *EVENT_AUTH_WIDGET_LOADED = "EVENT_AUTH_WIDGET_LOADED"; -constexpr const char *EVENT_AUTH_WIDGET_RELEASED = "EVENT_AUTH_WIDGET_RELEASED"; +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_AUTH_PROCESS_TERMINATE"; +constexpr const char *NOTICE_EVENT_AUTH_SEND_TIP = "EVENT_AUTH_SEND_TIP"; // For API6 enum class AuthenticationResult : int32_t { diff --git a/services/context/inc/widget_client.h b/services/context/inc/widget_client.h index f11aaf733..82cb8a4a2 100644 --- a/services/context/inc/widget_client.h +++ b/services/context/inc/widget_client.h @@ -35,8 +35,7 @@ public: static WidgetClient &Instance(); ~WidgetClient() = default; // sets - void SetWidgetSchedule(const std::shared_ptr &schedule); - void SetWidgetContextId(uint64_t contextId); + void SetWidgetSchedule(uint64_t contextId, const std::shared_ptr &schedule); void SetWidgetParam(const WidgetParamInner ¶m); void SetAuthTypeList(const std::vector &authTypeList); void SetWidgetCallback(const sptr &callback); @@ -66,6 +65,11 @@ private: bool GetAuthTypeList(const WidgetNotice ¬ice, std::vector &authTypeList); bool IsValidNoticeType(const WidgetNotice ¬ice); void ProcessNotice(const WidgetNotice ¬ice, std::vector &authTypeList); + void InsertScheduleNode(uint64_t contextId, std::shared_ptr &scheduleNode); + void RemoveScheduleNode(uint64_t contextId); + std::shared_ptr GetScheduleNode(uint64_t contextId); + void ClearSchedule(uint64_t contextId); + void WidgetRelease(uint64_t contextId, std::vector &authTypeList); private: std::shared_ptr schedule_ {nullptr}; @@ -78,6 +82,9 @@ private: uint32_t authTokenId_ {0}; std::vector challenge_ {}; std::string callingBundleName_ {""}; + std::recursive_mutex mutex_; + /* */ + std::map> scheduleMap_; }; } // namespace UserAuth } // namespace UserIam diff --git a/services/context/inc/widget_context.h b/services/context/inc/widget_context.h index 0f42bf3d5..5f6e9d0ed 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,6 @@ 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 { @@ -166,9 +160,6 @@ 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/inc/widget_json.h b/services/context/inc/widget_json.h index b5ddf41f0..4e4ac4768 100644 --- a/services/context/inc/widget_json.h +++ b/services/context/inc/widget_json.h @@ -49,6 +49,7 @@ struct WidgetNotice { std::vector typeList {}; bool endAfterFirstFail {false}; AuthIntent authIntent {AuthIntent::DEFAULT}; + int32_t tipCode {0}; }; void to_json(nlohmann::json &jsonNotice, const WidgetNotice ¬ice); void from_json(const nlohmann::json &jsonNotice, WidgetNotice ¬ice); diff --git a/services/context/src/widget_client.cpp b/services/context/src/widget_client.cpp index b3ea69856..522a4d2b4 100644 --- a/services/context/src/widget_client.cpp +++ b/services/context/src/widget_client.cpp @@ -45,10 +45,12 @@ WidgetClient &WidgetClient::Instance() return widgetClient; } -void WidgetClient::SetWidgetSchedule(const std::shared_ptr &schedule) +void WidgetClient::SetWidgetSchedule(uint64_t contextId, const std::shared_ptr &schedule) { IF_FALSE_LOGE_AND_RETURN(schedule != nullptr); + widgetContextId_ = contextId; schedule_ = schedule; + InsertScheduleNode(widgetContextId_, schedule_); } ResultCode WidgetClient::OnNotice(NoticeType type, const std::string &eventData) @@ -92,6 +94,7 @@ ResultCode WidgetClient::OnNotice(NoticeType type, const std::string &eventData) void WidgetClient::ProcessNotice(const WidgetNotice ¬ice, std::vector &authTypeList) { + IAM_LOGI("start, event:%{public}s", notice.event.c_str()); if (notice.event == NOTICE_EVENT_AUTH_READY) { schedule_->StartAuthList(authTypeList, notice.endAfterFirstFail, notice.authIntent); } else if (notice.event == NOTICE_EVENT_CANCEL_AUTH) { @@ -116,11 +119,14 @@ void WidgetClient::ProcessNotice(const WidgetNotice ¬ice, std::vectorWidgetReload(notice.orientation, notice.needRotate, notice.alreadyLoad, authTypeList[0]); } - } else if (notice.event == EVENT_AUTH_WIDGET_LOADED) { + } else if (notice.event == NOTICE_EVENT_AUTH_WIDGET_LOADED) { schedule_->SendAuthTipInfo(authTypeList, TIP_CODE_WIDGET_LOADED); - } else if (notice.event == EVENT_AUTH_WIDGET_RELEASED) { - schedule_->SendAuthTipInfo(authTypeList, TIP_CODE_WIDGET_RELEASED); - schedule_->SendAuthResult(); + } else if (notice.event == NOTICE_EVENT_AUTH_WIDGET_RELEASED) { + WidgetRelease(notice.widgetContextId, authTypeList); + } else if (notice.event == NOTICE_EVENT_PROCESS_TERMINATE) { + ClearSchedule(notice.widgetContextId); + } else if (notice.event == NOTICE_EVENT_AUTH_SEND_TIP) { + schedule_->SendAuthTipInfo(authTypeList, notice.tipCode); } } @@ -192,11 +198,6 @@ void WidgetClient::ReportWidgetTip(int32_t tipType, AuthType authType, std::vect SendCommand(widgetCmd); } -void WidgetClient::SetWidgetContextId(uint64_t contextId) -{ - widgetContextId_ = contextId; -} - void WidgetClient::SetWidgetParam(const WidgetParamInner ¶m) { widgetParam_ = param; @@ -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; @@ -239,11 +240,7 @@ 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"); - } + IAM_LOGI("stop auth process forcely by disconnect"); if (schedule_ != nullptr) { schedule_->StopSchedule(); } @@ -290,7 +287,7 @@ bool WidgetClient::GetAuthTypeList(const WidgetNotice ¬ice, std::vector &scheduleNode) +{ + IAM_LOGI("start, contextId:%{public}hx", static_cast(contextId)); + IF_FALSE_LOGE_AND_RETURN(scheduleNode != nullptr); + std::lock_guard lock(mutex_); + scheduleMap_.insert(std::pair>(contextId, scheduleNode)); +} + +void WidgetClient::RemoveScheduleNode(uint64_t contextId) +{ + IAM_LOGI("start, contextId:%{public}hx", static_cast(contextId)); + std::lock_guard lock(mutex_); + scheduleMap_.erase(contextId); +} + +std::shared_ptr WidgetClient::GetScheduleNode(uint64_t contextId) +{ + IAM_LOGI("start, contextId:%{public}hx", static_cast(contextId)); + std::lock_guard lock(mutex_); + std::shared_ptr scheduleNode = nullptr; + auto iter = scheduleMap_.find(contextId); + if (iter != scheduleMap_.end()) { + scheduleNode = iter->second; + IAM_LOGI("success, contextId:%{public}hx", static_cast(contextId)); + } + return scheduleNode; +} + +void WidgetClient::ClearSchedule(uint64_t contextId) +{ + IAM_LOGI("start, contextId:%{public}hx", static_cast(contextId)); + auto schedule = GetScheduleNode(contextId); + if (schedule != nullptr) { + schedule->ClearSchedule(); + if (contextId == widgetContextId_) { + Reset(); + } + RemoveScheduleNode(contextId); + } +} + +void WidgetClient::WidgetRelease(uint64_t contextId, std::vector &authTypeList) +{ + IAM_LOGI("start, contextId:%{public}hx", static_cast(contextId)); + auto schedule = GetScheduleNode(contextId); + if (schedule != nullptr) { + schedule->SendAuthTipInfo(authTypeList, TIP_CODE_WIDGET_RELEASED); + } +} } // 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 74612a3f2..521deff15 100644 --- a/services/context/src/widget_context.cpp +++ b/services/context/src/widget_context.cpp @@ -66,7 +66,6 @@ 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) @@ -227,10 +226,9 @@ bool WidgetContext::OnStart() return false; } IF_FALSE_LOGE_AND_RETURN_VAL(schedule_ != nullptr, false); - WidgetClient::Instance().SetWidgetContextId(GetContextId()); WidgetClient::Instance().SetWidgetParam(para_.widgetParam); WidgetClient::Instance().SetAuthTypeList(para_.authTypeList); - WidgetClient::Instance().SetWidgetSchedule(schedule_); + WidgetClient::Instance().SetWidgetSchedule(GetContextId(), schedule_); WidgetClient::Instance().SetChallenge(para_.challenge); WidgetClient::Instance().SetCallingBundleName(GetCallingBundleName()); schedule_->StartSchedule(); @@ -614,7 +612,7 @@ bool WidgetContext::DisconnectExtension() void WidgetContext::End(const ResultCode &resultCode) { - IAM_LOGD("in End, resultCode: %{public}d", static_cast(resultCode)); + IAM_LOGI("in End, resultCode: %{public}d", static_cast(resultCode)); StopAllRunTask(resultCode); IF_FALSE_LOGE_AND_RETURN(callerCallback_ != nullptr); Attributes attr; @@ -669,7 +667,6 @@ void WidgetContext::StopAllRunTask(const ResultCode &resultCode) IAM_LOGE("failed to release launch widget."); } } - WidgetClient::Instance().Reset(); } void WidgetContext::BuildStartPinSubType(WidgetCmdParameters &widgetCmdParameters) @@ -793,6 +790,7 @@ void WidgetContext::SendAuthTipInfo(int32_t authType, int32_t tipCode) } IF_FALSE_LOGE_AND_RETURN(callerCallback_ != nullptr); + callerCallback_->OnAcquireInfo(ALL_IN_ONE, authType, attr.Serialize()); } @@ -815,6 +813,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); @@ -824,18 +823,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; @@ -850,106 +859,6 @@ 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); @@ -959,19 +868,11 @@ void WidgetContext::OnTipTimerTimeOut(AuthType authType, int32_t freezingTime) } } -void WidgetContext::SendAuthResult() +void WidgetContext::ClearSchedule() { IAM_LOGI("start"); - 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(); - } + auto result = ContextPool::Instance().Delete(GetContextId()); + IAM_LOGI("context ****%{public}hx deleted %{public}s", static_cast(contextId_), result ? "succ" : "fail"); } } // namespace UserAuth } // namespace UserIam diff --git a/services/context/src/widget_json.cpp b/services/context/src/widget_json.cpp index 440972065..88e5dbb13 100644 --- a/services/context/src/widget_json.cpp +++ b/services/context/src/widget_json.cpp @@ -53,6 +53,7 @@ const std::string JSON_AUTH_VERSION = "version"; const std::string JSON_AUTH_PAYLOAD = "payload"; const std::string JSON_AUTH_END_AFTER_FIRST_FAIL = "endAfterFirstFail"; const std::string JSON_AUTH_INTENT = "authIntent"; +const std::string JSON_AUTH_TIP_CODE = "tipCode"; const std::string JSON_ORIENTATION = "orientation"; const std::string JSON_NEED_ROTATE = "needRotate"; const std::string JSON_ALREADY_LOAD = "alreadyLoad"; @@ -365,7 +366,8 @@ void to_json(nlohmann::json &jsonNotice, const WidgetNotice ¬ice) { auto type = nlohmann::json({{JSON_AUTH_TYPE, notice.typeList}, {JSON_AUTH_END_AFTER_FIRST_FAIL, notice.endAfterFirstFail}, - {JSON_AUTH_INTENT, notice.authIntent}}); + {JSON_AUTH_INTENT, notice.authIntent}, + {JSON_AUTH_TIP_CODE, notice.tipCode}}); jsonNotice = nlohmann::json({{JSON_WIDGET_CTX_ID, notice.widgetContextId}, {JSON_AUTH_EVENT, notice.event}, {JSON_ORIENTATION, notice.orientation}, @@ -424,6 +426,9 @@ void from_json(const nlohmann::json &jsonNotice, WidgetNotice ¬ice) if (isNumberItem(jsonNotice[JSON_AUTH_PAYLOAD], JSON_AUTH_INTENT)) { jsonNotice[JSON_AUTH_PAYLOAD].at(JSON_AUTH_INTENT).get_to(notice.authIntent); } + if (isNumberItem(jsonNotice[JSON_AUTH_PAYLOAD], JSON_AUTH_TIP_CODE)) { + jsonNotice[JSON_AUTH_PAYLOAD].at(JSON_AUTH_TIP_CODE).get_to(notice.tipCode); + } } std::string GetConfigRealPath() diff --git a/services/core/inc/widget_schedule_node.h b/services/core/inc/widget_schedule_node.h index fb16dcd8f..3d93090c7 100644 --- a/services/core/inc/widget_schedule_node.h +++ b/services/core/inc/widget_schedule_node.h @@ -38,7 +38,8 @@ public: S_WIDGET_WAITING = 1, S_WIDGET_AUTH_RUNNING = 2, S_WIDGET_AUTH_FINISHED = 3, - S_WIDGET_RELOAD_WAITING = 4 + S_WIDGET_RELOAD_WAITING = 4, + S_WIDGET_RELEASED = 5, }; enum Event : uint32_t { @@ -51,6 +52,7 @@ public: E_WIDGET_PARA_INVALID = 6, E_WIDGET_RELOAD = 7, E_STOP_AUTH = 8, + E_WIDGET_RELEASE = 9, }; virtual ~WidgetScheduleNode() = default; @@ -67,9 +69,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..d869c7e19 100644 --- a/services/core/src/widget_schedule_node_impl.cpp +++ b/services/core/src/widget_schedule_node_impl.cpp @@ -80,6 +80,17 @@ 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(); } @@ -111,6 +122,12 @@ 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) { @@ -269,23 +286,23 @@ void WidgetScheduleNodeImpl::OnWidgetReload(FiniteStateMachine &machine, uint32_ } } -void WidgetScheduleNodeImpl::SendAuthTipInfo(const std::vector &authTypeList, int32_t tipCode) +void WidgetScheduleNodeImpl::OnWidgetRelease(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..73a121c91 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 OnWidgetRelease(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 9f63e1aa0..21321eec5 100644 --- a/services/ipc/src/user_auth_service.cpp +++ b/services/ipc/src/user_auth_service.cpp @@ -1186,7 +1186,6 @@ 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 a1045daa4..7336ffb68 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 \ 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_client_test.cpp b/test/unittest/services/src/widget_client_test.cpp index 16879eacf..00e28daf2 100644 --- a/test/unittest/services/src/widget_client_test.cpp +++ b/test/unittest/services/src/widget_client_test.cpp @@ -85,15 +85,19 @@ std::shared_ptr WidgetClientTest::BuildSchedule() HWTEST_F(WidgetClientTest, WidgetClientTestSetWidgetSchedule_0001, TestSize.Level0) { auto schedule = BuildSchedule(); - WidgetClient::Instance().SetWidgetSchedule(schedule); + uint64_t widgetContextId = 1; + WidgetClient::Instance().SetWidgetSchedule(widgetContextId, schedule); EXPECT_NE(schedule, nullptr); + WidgetClient::Instance().ClearSchedule(widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestSetWidgetSchedule_0002, TestSize.Level0) { std::shared_ptr nullSchedule(nullptr); - WidgetClient::Instance().SetWidgetSchedule(nullSchedule); + uint64_t widgetContextId = 1; + WidgetClient::Instance().SetWidgetSchedule(widgetContextId, nullSchedule); EXPECT_EQ(nullSchedule, nullptr); + WidgetClient::Instance().ClearSchedule(widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestSetWidgetParam, TestSize.Level0) @@ -179,8 +183,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0007, TestSize.Level0) WidgetClient::Instance().Reset(); std::vector authTypeList; WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::INVALID_PARAMETERS); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0008, TestSize.Level0) @@ -194,8 +199,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0008, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::INVALID_PARAMETERS); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0009, TestSize.Level0) @@ -210,8 +216,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0009, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::INVALID_PARAMETERS); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0010, TestSize.Level0) @@ -226,8 +233,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0010, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::FACE); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); - EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::INVALID_PARAMETERS); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); + EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::SUCCESS); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0011, TestSize.Level0) @@ -242,8 +250,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0011, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::SUCCESS); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0012, TestSize.Level0) @@ -258,8 +267,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0012, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::SUCCESS); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0013, TestSize.Level0) @@ -275,8 +285,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0013, TestSize.Level0) authTypeList.emplace_back(AuthType::PIN); authTypeList.emplace_back(AuthType::FACE); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::SUCCESS); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0014, TestSize.Level0) @@ -294,8 +305,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0014, TestSize.Level0) authTypeList.emplace_back(AuthType::FACE); authTypeList.emplace_back(AuthType::FINGERPRINT); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::SUCCESS); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0015, TestSize.Level0) @@ -310,8 +322,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0015, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::SUCCESS); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0016, TestSize.Level0) @@ -326,8 +339,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0016, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::SUCCESS); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0017, TestSize.Level0) @@ -343,8 +357,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestOnNotice_0017, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); - EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::INVALID_PARAMETERS); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); + EXPECT_EQ(WidgetClient::Instance().OnNotice(NoticeType::WIDGET_NOTICE, eventData), ResultCode::SUCCESS); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestReportWidgetResult_0001, TestSize.Level0) @@ -407,8 +422,7 @@ HWTEST_F(WidgetClientTest, WidgetClientTestForceStopAuth_0002, TestSize.Level0) { uint64_t contextId = 6; WidgetClient::Instance().Reset(); - WidgetClient::Instance().SetWidgetContextId(contextId); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(contextId, BuildSchedule()); WidgetClient::Instance().ForceStopAuth(); EXPECT_EQ(WidgetClient::Instance().GetAuthTokenId(), 0); } @@ -433,8 +447,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_001, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList)); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_002, TestSize.Level0) @@ -447,8 +462,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_002, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList)); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_003, TestSize.Level0) @@ -461,8 +477,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_003, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList)); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_004, TestSize.Level0) @@ -475,8 +492,9 @@ HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_004, TestSize.Level0) std::vector authTypeList; authTypeList.emplace_back(AuthType::ALL); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList)); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_005, TestSize.Level0) @@ -490,36 +508,39 @@ HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_005, TestSize.Level0) authTypeList.emplace_back(AuthType::ALL); authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList)); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_006, TestSize.Level0) { WidgetNotice widgetNotice; widgetNotice.widgetContextId = 1; - widgetNotice.event = EVENT_AUTH_WIDGET_LOADED; + widgetNotice.event = NOTICE_EVENT_AUTH_WIDGET_LOADED; widgetNotice.typeList.push_back("pin"); WidgetClient::Instance().Reset(); std::vector authTypeList; authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); - WidgetClient::Instance().SetWidgetSchedule(BuildSchedule()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList)); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_007, TestSize.Level0) { WidgetNotice widgetNotice; widgetNotice.widgetContextId = 1; - widgetNotice.event = EVENT_AUTH_WIDGET_RELEASED; + 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()); + WidgetClient::Instance().SetWidgetSchedule(widgetNotice.widgetContextId, BuildSchedule()); EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList)); + WidgetClient::Instance().ClearSchedule(widgetNotice.widgetContextId); } HWTEST_F(WidgetClientTest, WidgetClientTestSetPinSubType_001, TestSize.Level0) diff --git a/test/unittest/services/src/widget_context_test.cpp b/test/unittest/services/src/widget_context_test.cpp index 19f3e0c0d..481112c24 100644 --- a/test/unittest/services/src/widget_context_test.cpp +++ b/test/unittest/services/src/widget_context_test.cpp @@ -718,86 +718,6 @@ 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; -- Gitee