From 12f7dfa7b027fc81f9d5292e9492f76ddaa30e12 Mon Sep 17 00:00:00 2001 From: hubijie Date: Wed, 11 Jun 2025 16:09:56 +0800 Subject: [PATCH] =?UTF-8?q?rk=E6=9D=BF=E9=80=8F=E4=BC=A0=E6=84=8F=E5=9B=BE?= =?UTF-8?q?=20Signed-off-by:=20hubijie=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wm/include/window_impl.h | 9 +++++ wm/include/window_session_impl.h | 1 + wm/src/window_impl.cpp | 30 +++++++++++++++++ wm/src/window_session_impl.cpp | 15 ++++++--- .../unittest/window_session_impl_test5.cpp | 33 +++++++++++++++++++ 5 files changed, 83 insertions(+), 5 deletions(-) diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 55432dcb69..e98befe135 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -181,6 +181,8 @@ public: void UpdateSpecificSystemBarEnabled(bool systemBarEnable, bool systemBarEnableAnimation, SystemBarProperty& property) override; + WMError SetIntentParam(const std::string& intentParam, const std::function& loadPageCallback, + bool isColdStart) override; WMError Create(uint32_t parentId, const std::shared_ptr& context = nullptr); virtual WMError Destroy(uint32_t reason = 0) override; @@ -589,6 +591,13 @@ private: * RS Client Multi Instance */ std::shared_ptr rsUIDirector_; + + /* + * Window Lifecycle + */ + std::string intentParam_; + std::function loadPageCallback_; + bool isIntentColdStart_ = true; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index 919bf2758f..2af1d40536 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -694,6 +694,7 @@ protected: std::string intentParam_; std::function loadPageCallback_; bool isColdStart_ = true; + bool isIntentColdStart_ = true; std::string navDestinationInfo_; /* diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 6c0f668fec..4b715688c3 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -719,6 +719,11 @@ WMError WindowImpl::SetUIContentInner(const std::string& contentInfo, void* env, TLOGI(WmsLogTag::WMS_LIFE, "Restore router stack succeed."); break; } + if (!intentParam_.empty()) { + TLOGI(WmsLogTag::WMS_LIFE, "Default setIntentParam, isColdStart:%{public}u", isIntentColdStart_); + uiContent->SetIntentParam(intentParam_, std::move(loadPageCallback_), isIntentColdStart_); + intentParam_ = ""; + } aceRet = UIContentInit(uiContent.get(), contentInfo, storage, isAni); break; } @@ -726,6 +731,11 @@ WMError WindowImpl::SetUIContentInner(const std::string& contentInfo, void* env, aceRet = UIContentRestore(uiContent.get(), contentInfo, storage, GetAceContentInfoType(restoreType), isAni); break; case WindowSetUIContentType::BY_NAME: + if (!intentParam_.empty()) { + TLOGI(WmsLogTag::WMS_LIFE, "By name setIntentParam, isColdStart:%{public}u", isIntentColdStart_); + uiContent->SetIntentParam(intentParam_, std::move(loadPageCallback_), isIntentColdStart_); + intentParam_ = ""; + } aceRet = UIContentInitByName(uiContent.get(), contentInfo, storage, isAni); break; case WindowSetUIContentType::BY_ABC: @@ -4122,6 +4132,16 @@ void WindowImpl::NotifyAfterForeground(bool needNotifyListeners, bool needNotify if (needNotifyUiContent) { CALL_UI_CONTENT(Foreground); } + if (!intentParam_.empty()) { + auto uiContent = GetUIContent(); + if (uiContent != nullptr) { + TLOGI(WmsLogTag::WMS_LIFE, "SetIntentParam, isColdStart:%{public}u", isIntentColdStart_); + uiContent->SetIntentParam(intentParam_, std::move(loadPageCallback_), isIntentColdStart_); + intentParam_ = ""; + } else { + TLOGE(WmsLogTag::WMS_LIFE, "uiContent is nullptr."); + } + } } void WindowImpl::NotifyAfterDidForeground(uint32_t reason) @@ -4765,5 +4785,15 @@ std::shared_ptr WindowImpl::GetRSUIContext() const RSAdapterUtil::RSUIContextToStr(rsUIContext).c_str(), GetWindowId()); return rsUIContext; } + +WMError WindowImpl::SetIntentParam(const std::string& intentParam, + const std::function& loadPageCallback, bool isColdStart) +{ + TLOGI(WmsLogTag::WMS_LIFE, "in"); + intentParam_ = intentParam; + loadPageCallback_ = loadPageCallback; + isIntentColdStart_ = isColdStart; + return WMError::WM_OK; +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 8ec247d51b..20a22cf89e 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1928,8 +1928,8 @@ WMError WindowSessionImpl::InitUIContent(const std::string& contentInfo, void* e } } if (!intentParam_.empty()) { - TLOGI(WmsLogTag::WMS_LIFE, "SetIntentParam, isColdStart:%{public}u", isColdStart_); - uiContent->SetIntentParam(intentParam_, std::move(loadPageCallback_), isColdStart_); + TLOGI(WmsLogTag::WMS_LIFE, "Default SetIntentParam, isColdStart:%{public}u", isIntentColdStart_); + uiContent->SetIntentParam(intentParam_, std::move(loadPageCallback_), isIntentColdStart_); intentParam_ = ""; } aceRet = UIContentInit(uiContent.get(), contentInfo, storage, isAni); @@ -1939,6 +1939,11 @@ WMError WindowSessionImpl::InitUIContent(const std::string& contentInfo, void* e aceRet = UIContentRestore(uiContent.get(), contentInfo, storage, GetAceContentInfoType(restoreType), isAni); break; case WindowSetUIContentType::BY_NAME: + if (!intentParam_.empty()) { + TLOGI(WmsLogTag::WMS_LIFE, "By name setIntentParam, isColdStart:%{public}u", isIntentColdStart_); + uiContent->SetIntentParam(intentParam_, std::move(loadPageCallback_), isIntentColdStart_); + intentParam_ = ""; + } aceRet = UIContentInitByName(uiContent.get(), contentInfo, storage, isAni); break; case WindowSetUIContentType::BY_SHARED: @@ -4476,8 +4481,8 @@ void WindowSessionImpl::NotifyAfterForeground(bool needNotifyListeners, bool nee if (!intentParam_.empty()) { std::shared_ptr uiContent = GetUIContentSharedPtr(); if (uiContent != nullptr) { - TLOGI(WmsLogTag::WMS_LIFE, "SetIntentParam, isColdStart:%{public}u", isColdStart_); - uiContent->SetIntentParam(intentParam_, std::move(loadPageCallback_), isColdStart_); + TLOGI(WmsLogTag::WMS_LIFE, "SetIntentParam, isColdStart:%{public}u", isIntentColdStart_); + uiContent->SetIntentParam(intentParam_, std::move(loadPageCallback_), isIntentColdStart_); intentParam_ = ""; } else { TLOGE(WmsLogTag::WMS_LIFE, "uiContent is nullptr."); @@ -7403,7 +7408,7 @@ WMError WindowSessionImpl::SetIntentParam(const std::string& intentParam, TLOGI(WmsLogTag::WMS_LIFE, "in"); intentParam_ = intentParam; loadPageCallback_ = loadPageCallback; - isColdStart_ = isColdStart; + isIntentColdStart_ = isColdStart; return WMError::WM_OK; } } // namespace Rosen diff --git a/wm/test/unittest/window_session_impl_test5.cpp b/wm/test/unittest/window_session_impl_test5.cpp index 6cc1aacf20..6e88458962 100644 --- a/wm/test/unittest/window_session_impl_test5.cpp +++ b/wm/test/unittest/window_session_impl_test5.cpp @@ -1265,6 +1265,39 @@ HWTEST_F(WindowSessionImplTest5, HideTitleButton03, Function | SmallTest | Level EXPECT_FALSE(hideCloseButton); } +/** + * @tc.name: SetUIContentByName + * @tc.desc: SetUIContentByName, load content by name + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest5, SetUIContentByName, Function | SmallTest | Level2) +{ + sptr option = sptr::MakeSptr(); + option->SetWindowName("SetUIContentByName"); + sptr window = sptr::MakeSptr(option); + + SessionInfo sessionInfo = {"SetUIContentByName", "SetUIContentByName", "SetUIContentByName"}; + auto hostSession = sptr::MakeSptr(sessionInfo); + sptr property = sptr::MakeSptr(); + property->SetPersistentId(1); + window->property_ = property; + window->hostSession_ = hostSession; + sptr token; + window->state_ = WindowState::STATE_SHOWN; + + auto testCallback = [](){}; + bool isColdStart = true; + std::string intentParam = "test"; + window->SetIntentParam(intentParam, testCallback, isColdStart); + + window->SetUIContentByName("info", (napi_env)nullptr, nullptr, nullptr); + EXPECT_EQ(window->intentParam_, ""); + + intentParam = ""; + window->SetUIContentByName("info", (napi_env)nullptr, nullptr, nullptr); + EXPECT_EQ(window->intentParam_, ""); +} + /** * @tc.name: HideTitleButton04 * @tc.desc: HideTitleButton04 -- Gitee