From 16ffd18c3d70794617fb2fa76867924593dc9e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=9C=9C?= Date: Thu, 15 May 2025 16:47:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=BA=94=E7=94=A8=E6=8A=A2=E5=8D=A0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李蜜 --- services/context/inc/context_factory.h | 3 +- services/context/inc/widget_client.h | 6 ---- services/context/inc/widget_context.h | 4 ++- services/context/src/context_factory.cpp | 4 +-- services/context/src/widget_client.cpp | 32 ------------------- services/context/src/widget_context.cpp | 18 +++++++---- services/ipc/inc/user_auth_service.h | 2 +- services/ipc/src/user_auth_service.cpp | 9 ++---- .../services/src/context_factory_test.cpp | 4 +-- .../src/widget_context_callback_impl_test.cpp | 4 +-- .../services/src/widget_context_test.cpp | 8 ++--- .../src/widget_schedule_node_impl_test.cpp | 2 +- 12 files changed, 32 insertions(+), 64 deletions(-) diff --git a/services/context/inc/context_factory.h b/services/context/inc/context_factory.h index 575a47178..84f8ef85d 100644 --- a/services/context/inc/context_factory.h +++ b/services/context/inc/context_factory.h @@ -27,6 +27,7 @@ #include "context.h" #include "context_callback.h" #include "identification_impl.h" +#include "imodal_callback.h" #include "remote_auth_context.h" #include "remote_auth_invoker_context.h" @@ -71,7 +72,7 @@ public: const std::shared_ptr &callback, bool needSubscribeAppState); static std::shared_ptr CreateWidgetAuthContext(std::shared_ptr callback); static std::shared_ptr CreateWidgetContext(const AuthWidgetContextPara ¶, - std::shared_ptr callback); + std::shared_ptr callback, const sptr &modalCallback); static std::shared_ptr CreateScheduleHolderContext(std::shared_ptr scheduleNode); }; } // namespace UserAuth diff --git a/services/context/inc/widget_client.h b/services/context/inc/widget_client.h index 924b7effe..75181f281 100644 --- a/services/context/inc/widget_client.h +++ b/services/context/inc/widget_client.h @@ -54,16 +54,11 @@ public: void SetSensorInfo(const std::string &info); void Reset(); void ForceStopAuth(); - void CancelAuth(); // extra info void SetChallenge(const std::vector &challenge); void SetCallingBundleName(const std::string &callingBundleName); - void SetModalCallback(const sptr &callback); - void LaunchModal(const std::string &commandData); - void ReleaseModal(); - private: WidgetClient() = default; void SendCommand(const WidgetCommand &command); @@ -82,7 +77,6 @@ private: uint32_t authTokenId_ {0}; std::vector challenge_ {}; std::string callingBundleName_ {""}; - sptr modalCallback_ {nullptr}; }; } // namespace UserAuth } // namespace UserIam diff --git a/services/context/inc/widget_context.h b/services/context/inc/widget_context.h index 61ac3a5ce..a3dd9b374 100644 --- a/services/context/inc/widget_context.h +++ b/services/context/inc/widget_context.h @@ -33,6 +33,7 @@ #include "context_factory.h" #include "in_process_call_wrapper.h" #include "iiam_callback.h" +#include "imodal_callback.h" #include "nocopyable.h" #include "widget_json.h" #include "widget_schedule_node.h" @@ -50,7 +51,7 @@ class WidgetContext : public WidgetScheduleNodeCallback, public NoCopyable { public: WidgetContext(uint64_t contextId, const ContextFactory::AuthWidgetContextPara ¶, - std::shared_ptr callback); + std::shared_ptr callback, const sptr &modalCallback); ~WidgetContext() override; // Context API @@ -134,6 +135,7 @@ private: int32_t latestError_ {ResultCode::GENERAL_ERROR}; ContextFactory::AuthWidgetContextPara para_ {}; std::shared_ptr schedule_ {nullptr}; + sptr modalCallback_ {nullptr}; std::recursive_mutex mutex_; std::list runTaskInfoList_; sptr connection_ {nullptr}; diff --git a/services/context/src/context_factory.cpp b/services/context/src/context_factory.cpp index 7ae3823d5..afd65b0a6 100644 --- a/services/context/src/context_factory.cpp +++ b/services/context/src/context_factory.cpp @@ -76,11 +76,11 @@ std::shared_ptr ContextFactory::CreateWidgetAuthContext(std::shared_ptr } std::shared_ptr ContextFactory::CreateWidgetContext(const AuthWidgetContextPara ¶, - std::shared_ptr callback) + std::shared_ptr callback, const sptr &modalCallback) { IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); uint64_t newContextId = ContextPool::GetNewContextId(); - return Common::MakeShared(newContextId, para, callback); + return Common::MakeShared(newContextId, para, callback, modalCallback); } std::shared_ptr ContextFactory::CreateRemoteAuthContext(const Authentication::AuthenticationPara ¶, diff --git a/services/context/src/widget_client.cpp b/services/context/src/widget_client.cpp index 902bad774..6e943e719 100644 --- a/services/context/src/widget_client.cpp +++ b/services/context/src/widget_client.cpp @@ -227,7 +227,6 @@ void WidgetClient::Reset() widgetCallback_ = nullptr; pinSubType_.clear(); sensorInfo_.clear(); - modalCallback_ = nullptr; } void WidgetClient::ForceStopAuth() @@ -242,14 +241,6 @@ void WidgetClient::ForceStopAuth() } } -void WidgetClient::CancelAuth() -{ - IAM_LOGE("cancel auth process forcely"); - if (schedule_ != nullptr) { - schedule_->StopSchedule(); - } -} - void WidgetClient::SetPinSubType(const PinSubType &subType) { pinSubType_ = PIN_SUB_TYPE_SIX; @@ -334,29 +325,6 @@ void WidgetClient::SetCallingBundleName(const std::string &callingBundleName) { callingBundleName_ = callingBundleName; } - -void WidgetClient::SetModalCallback(const sptr &callback) -{ - IAM_LOGI("set modal callback"); - modalCallback_ = callback; -} - -void WidgetClient::LaunchModal(const std::string &commandData) -{ - IAM_LOGI("launch modal command: %{public}s", commandData.c_str()); - if (modalCallback_ != nullptr) { - modalCallback_->SendCommand(widgetContextId_, commandData); - } -} - -void WidgetClient::ReleaseModal() -{ - IAM_LOGI("release modal"); - if (modalCallback_ != nullptr) { - std::string cmdData = ""; - modalCallback_->SendCommand(widgetContextId_, cmdData); - } -} } // namespace UserAuth } // namespace UserIam } // 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 4f0cb9d35..ec5fc19c7 100644 --- a/services/context/src/widget_context.cpp +++ b/services/context/src/widget_context.cpp @@ -62,9 +62,10 @@ const std::string SUPPORT_FOLLOW_CALLER_UI = "const.useriam.authWidget.supportFo const std::string FIND_PROCESS_NAME = "findnetwork"; WidgetContext::WidgetContext(uint64_t contextId, const ContextFactory::AuthWidgetContextPara ¶, - std::shared_ptr callback) + std::shared_ptr callback, const sptr &modalCallback) : contextId_(contextId), description_("UserAuthWidget"), callerCallback_(callback), hasStarted_(false), - latestError_(ResultCode::GENERAL_ERROR), para_(para), schedule_(nullptr), connection_(nullptr) + latestError_(ResultCode::GENERAL_ERROR), para_(para), schedule_(nullptr), modalCallback_(modalCallback), + connection_(nullptr) { AddDeathRecipient(callerCallback_, contextId_); if (!para.isBackgroundApplication) { @@ -504,7 +505,9 @@ bool WidgetContext::ConnectExtension(const WidgetRotatePara &widgetRotatePara) if (para_.widgetParam.hasContext && IsSupportFollowCallerUi()) { // As modal application // No need do anything, caller death has process; only process timeout for widget. - WidgetClient::Instance().LaunchModal(commandData); + if (modalCallback_ != nullptr) { + modalCallback_->SendCommand(contextId_, commandData); + } return true; } // Default as modal system @@ -526,8 +529,11 @@ bool WidgetContext::DisconnectExtension() IAM_LOGI("has context: %{public}d", para_.widgetParam.hasContext); if (para_.widgetParam.hasContext && IsSupportFollowCallerUi()) { // As modal application release. - WidgetClient::Instance().CancelAuth(); - WidgetClient::Instance().ReleaseModal(); + schedule_->StopSchedule(); + if (modalCallback_ != nullptr) { + std::string cmdData = ""; + modalCallback_->SendCommand(contextId_, cmdData); + } return true; } // Default as modal system release. @@ -535,7 +541,7 @@ bool WidgetContext::DisconnectExtension() IAM_LOGE("invalid connection handle"); return false; } - WidgetClient::Instance().CancelAuth(); + schedule_->StopSchedule(); connection_->ReleaseUIExtensionComponent(); ErrCode ret = AAFwk::ExtensionManagerClient::GetInstance().DisconnectAbility(connection_); connection_ = nullptr; diff --git a/services/ipc/inc/user_auth_service.h b/services/ipc/inc/user_auth_service.h index 655d27048..295400d46 100644 --- a/services/ipc/inc/user_auth_service.h +++ b/services/ipc/inc/user_auth_service.h @@ -91,7 +91,7 @@ private: bool isBackgroundApplication); uint64_t StartWidgetContext(const std::shared_ptr &contextCallback, const AuthParamInner &authParam, const WidgetParamInner &widgetParam, std::vector &validType, - ContextFactory::AuthWidgetContextPara ¶); + ContextFactory::AuthWidgetContextPara ¶, const sptr &modalCallback); uint64_t StartAuthContext(int32_t apiVersion, Authentication::AuthenticationPara para, const std::shared_ptr &contextCallback, bool needSubscribeAppState); uint64_t AuthRemoteUser(AuthParamInner &authParam, Authentication::AuthenticationPara ¶, diff --git a/services/ipc/src/user_auth_service.cpp b/services/ipc/src/user_auth_service.cpp index ae5799958..4e3a9d12e 100644 --- a/services/ipc/src/user_auth_service.cpp +++ b/services/ipc/src/user_auth_service.cpp @@ -1102,7 +1102,7 @@ int32_t UserAuthService::CheckWindowMode(const WidgetParamInner &widgetParam) uint64_t UserAuthService::StartWidgetContext(const std::shared_ptr &contextCallback, const AuthParamInner &authParam, const WidgetParamInner &widgetParam, std::vector &validType, - ContextFactory::AuthWidgetContextPara ¶) + ContextFactory::AuthWidgetContextPara ¶, const sptr &modalCallback) { Attributes extraInfo; para.tokenId = IpcCommon::GetAccessTokenId(*this); @@ -1113,7 +1113,7 @@ uint64_t UserAuthService::StartWidgetContext(const std::shared_ptrOnResult(ResultCode::GENERAL_ERROR, extraInfo); return BAD_CONTEXT_ID; } - auto context = ContextFactory::CreateWidgetContext(para, contextCallback); + auto context = ContextFactory::CreateWidgetContext(para, contextCallback, modalCallback); if (context == nullptr || !Insert2ContextPool(context)) { contextCallback->SetTraceAuthFinishReason("UserAuthService AuthWidget insert context fail"); contextCallback->OnResult(ResultCode::GENERAL_ERROR, extraInfo); @@ -1230,11 +1230,8 @@ int32_t UserAuthService::StartAuthWidget(AuthParamInner &authParam, WidgetParamI } ProcessPinExpired(checkRet, authParam, validType, para); ProcessWidgetSessionExclusive(); - if (modalCallback != nullptr && widgetParam.hasContext) { - WidgetClient::Instance().SetModalCallback(modalCallback); - } - contextId = StartWidgetContext(contextCallback, authParam, widgetParam, validType, para); + contextId = StartWidgetContext(contextCallback, authParam, widgetParam, validType, para, modalCallback); if (contextId == BAD_CONTEXT_ID) { IAM_LOGE("StartWidgetContext fail"); return GENERAL_ERROR; diff --git a/test/unittest/services/src/context_factory_test.cpp b/test/unittest/services/src/context_factory_test.cpp index a604381f0..3deec62bf 100644 --- a/test/unittest/services/src/context_factory_test.cpp +++ b/test/unittest/services/src/context_factory_test.cpp @@ -154,7 +154,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateWidgetContext_001, TestSize.Lev ASSERT_NE(callback, nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); ContextFactory::AuthWidgetContextPara para = {}; - auto context = factory->CreateWidgetContext(para, contextCallback); + auto context = factory->CreateWidgetContext(para, contextCallback, nullptr); ASSERT_NE(context, nullptr); } @@ -166,7 +166,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateWidgetContext_002, TestSize.Lev sptr callback(nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); ContextFactory::AuthWidgetContextPara para = {}; - auto context = factory->CreateWidgetContext(para, contextCallback); + auto context = factory->CreateWidgetContext(para, contextCallback, nullptr); ASSERT_EQ(context, nullptr); } diff --git a/test/unittest/services/src/widget_context_callback_impl_test.cpp b/test/unittest/services/src/widget_context_callback_impl_test.cpp index ba55b90d0..a028b4d6b 100644 --- a/test/unittest/services/src/widget_context_callback_impl_test.cpp +++ b/test/unittest/services/src/widget_context_callback_impl_test.cpp @@ -60,7 +60,7 @@ HWTEST_F(WidgetContextCallbackImplTest, WidgetContextCallbackImplOnResult_001, T uint64_t contextId = 1; ContextFactory::AuthWidgetContextPara para; std::shared_ptr callback = Common::MakeShared(); - WidgetContext *widgetContext = new WidgetContext(contextId, para, callback); + WidgetContext *widgetContext = new WidgetContext(contextId, para, callback, nullptr); int32_t authType = 0; auto contextCallback = Common::MakeShared(std::shared_ptr(widgetContext), authType); @@ -87,7 +87,7 @@ HWTEST_F(WidgetContextCallbackImplTest, WidgetContextCallbackImplOnAcquireInfo_0 uint64_t contextId = 1; ContextFactory::AuthWidgetContextPara para; std::shared_ptr callback = Common::MakeShared(); - WidgetContext *widgetContext = new WidgetContext(contextId, para, callback); + WidgetContext *widgetContext = new WidgetContext(contextId, para, callback, nullptr); int32_t authType = 0; auto contextCallback = Common::MakeShared(std::shared_ptr(widgetContext), authType); diff --git a/test/unittest/services/src/widget_context_test.cpp b/test/unittest/services/src/widget_context_test.cpp index 524da7701..82a78c519 100644 --- a/test/unittest/services/src/widget_context_test.cpp +++ b/test/unittest/services/src/widget_context_test.cpp @@ -61,7 +61,7 @@ void WidgetContextTest::TearDown() std::shared_ptr CreateWidgetContext(uint64_t contextId, ContextFactory::AuthWidgetContextPara para) { std::shared_ptr contextCallback = Common::MakeShared(); - return Common::MakeShared(contextId, para, contextCallback); + return Common::MakeShared(contextId, para, contextCallback, nullptr); } HWTEST_F(WidgetContextTest, WidgetContextTestStart, TestSize.Level0) @@ -428,7 +428,7 @@ HWTEST_F(WidgetContextTest, WidgetContextTestExecuteAuthList_0001, TestSize.Leve { uint64_t contextId = 1; ContextFactory::AuthWidgetContextPara para; - auto widgetContext = Common::MakeShared(contextId, para, nullptr); + auto widgetContext = Common::MakeShared(contextId, para, nullptr, nullptr); std::set authTypeList; widgetContext->ExecuteAuthList(authTypeList, false, AuthIntent::DEFAULT); EXPECT_NE(widgetContext, nullptr); @@ -440,7 +440,7 @@ HWTEST_F(WidgetContextTest, WidgetContextTestExecuteAuthList_0002, TestSize.Leve { uint64_t contextId = 1; ContextFactory::AuthWidgetContextPara para; - auto widgetContext = Common::MakeShared(contextId, para, nullptr); + auto widgetContext = Common::MakeShared(contextId, para, nullptr, nullptr); std::set authTypeList; authTypeList.insert(AuthType::PIN); widgetContext->ExecuteAuthList(authTypeList, true, AuthIntent::DEFAULT); @@ -456,7 +456,7 @@ HWTEST_F(WidgetContextTest, WidgetContextTestExecuteAuthList_0003, TestSize.Leve para.challenge = {0, 1}; para.atl = AuthTrustLevel::ATL1; auto contextCallback = Common::MakeShared(); - auto widgetContext = Common::MakeShared(contextId, para, contextCallback); + auto widgetContext = Common::MakeShared(contextId, para, contextCallback, nullptr); std::set authTypeList; authTypeList.insert(AuthType::PIN); widgetContext->ExecuteAuthList(authTypeList, false, AuthIntent::DEFAULT); diff --git a/test/unittest/services/src/widget_schedule_node_impl_test.cpp b/test/unittest/services/src/widget_schedule_node_impl_test.cpp index 0c2831c30..34bc7ba1a 100644 --- a/test/unittest/services/src/widget_schedule_node_impl_test.cpp +++ b/test/unittest/services/src/widget_schedule_node_impl_test.cpp @@ -50,7 +50,7 @@ void WidgetScheduleNodeImplTest::SetUpTestCase() uint64_t contextId = 1; ContextFactory::AuthWidgetContextPara para; std::shared_ptr callback = Common::MakeShared(); - widgetContext = Common::MakeShared(contextId, para, callback); + widgetContext = Common::MakeShared(contextId, para, callback, nullptr); } void WidgetScheduleNodeImplTest::TearDownTestCase() -- Gitee