From d19b4243dfb13f1a4ce409594210c48078c4a7ac Mon Sep 17 00:00:00 2001 From: koroltang Date: Mon, 14 Apr 2025 17:49:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=9C=A8=E5=89=8D=E5=8F=B0?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E6=89=8D=E9=80=9A=E7=9F=A5=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=A0=91=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: koroltang --- .../js_scene_session.cpp | 2 +- .../src/zidl/session_stage_proxy.cpp | 2 +- window_scene/session/host/include/session.h | 9 ++- .../session/host/src/scene_session.cpp | 2 +- window_scene/session/host/src/session.cpp | 5 -- .../test/unittest/scene_session_test6.cpp | 15 +++++ .../window_scene_session_impl_test4.cpp | 66 +++++++++++++++++++ 7 files changed, 90 insertions(+), 11 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index 275f15edd0..6d4671aa87 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -5689,7 +5689,7 @@ napi_value JsSceneSession::OnAddSnapshot(napi_env env, napi_callback_info info) } } - TLOGI(WmsLogTag::WMS_PATTERN, "argc: %{public}u, useFfrt: %{public}u, needPersist: %{public}u", + TLOGI(WmsLogTag::WMS_PATTERN, "argc: %{public}zu, useFfrt: %{public}d, needPersist: %{public}d", argc, useFfrt, needPersist); auto session = weakSession_.promote(); if (session == nullptr) { diff --git a/window_scene/session/container/src/zidl/session_stage_proxy.cpp b/window_scene/session/container/src/zidl/session_stage_proxy.cpp index b2ec04cb95..ffe81a55f6 100644 --- a/window_scene/session/container/src/zidl/session_stage_proxy.cpp +++ b/window_scene/session/container/src/zidl/session_stage_proxy.cpp @@ -1719,7 +1719,7 @@ WSError SessionStageProxy::NotifyWindowAttachStateChange(bool isAttach) { MessageParcel data; MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER); + MessageOption option(MessageOption::TF_ASYNC); if (!data.WriteInterfaceToken(GetDescriptor())) { TLOGE(WmsLogTag::WMS_SUB, "WriteInterfaceToken failed"); return WSError::WS_ERROR_IPC_FAILED; diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 2aa0c87c08..5140997f08 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -564,7 +564,6 @@ public: void SetAttachState(bool isAttach, WindowMode windowMode = WindowMode::WINDOW_MODE_UNDEFINED); bool GetAttachState() const; void RegisterDetachCallback(const sptr& callback); - void SetNeedNotifyAttachState(bool needNotify); SystemSessionConfig GetSystemConfig() const; void RectCheckProcess(); @@ -867,6 +866,12 @@ protected: * Window Hierarchy */ NotifyClickModalWindowOutsideFunc clickModalWindowOutsideFunc_; + + /* + * Window Pattern + */ + std::atomic isAttach_ { false }; + std::atomic needNotifyAttachState_ = { false }; /* * Window Pipeline @@ -971,7 +976,6 @@ private: */ void RecordWindowStateAttachExceptionEvent(bool isAttached); - std::atomic isAttach_ { false }; std::atomic isPendingToBackgroundState_ { false }; std::atomic isActivatedAfterScreenLocked_ { true }; sptr detachCallback_ = nullptr; @@ -1013,7 +1017,6 @@ private: std::mutex saveSnapshotCallbackMutex_; std::mutex removeSnapshotCallbackMutex_; std::mutex addSnapshotCallbackMutex_; - std::atomic needNotifyAttachState_ = { false }; /* * Window Pattern diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 5b72ee6ce5..8299cf8cbb 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -7728,7 +7728,7 @@ void SceneSession::ModifyRSAnimatableProperty(bool isDefaultSidebarBlur, bool is void SceneSession::NotifyWindowAttachStateListenerRegistered(bool registered) { - SetNeedNotifyAttachState(registered); + needNotifyAttachState_.store(registered); } void SceneSession::NotifyKeyboardAnimationCompleted(bool isShowAnimation, diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index dfa132f397..d285630111 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -1653,11 +1653,6 @@ void Session::SetAttachState(bool isAttach, WindowMode windowMode) CreateDetectStateTask(isAttach, windowMode); } -void Session::SetNeedNotifyAttachState(bool needNotify) -{ - needNotifyAttachState_.store(needNotify); -} - void Session::CreateDetectStateTask(bool isAttach, WindowMode windowMode) { if (!IsSupportDetectWindow(isAttach)) { diff --git a/window_scene/test/unittest/scene_session_test6.cpp b/window_scene/test/unittest/scene_session_test6.cpp index 62d01d7c31..9c75a19b88 100644 --- a/window_scene/test/unittest/scene_session_test6.cpp +++ b/window_scene/test/unittest/scene_session_test6.cpp @@ -373,6 +373,21 @@ HWTEST_F(SceneSessionTest6, GetSystemAvoidArea, Function | SmallTest | Level1) int32_t height = session->GetStatusBarHeight(); EXPECT_EQ(height, avoidArea.topRect_.height_); } + +/** + * @tc.name: NotifyWindowAttachStateListenerRegistered + * @tc.desc: NotifyWindowAttachStateListenerRegistered about session + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest6, NotifyWindowAttachStateListenerRegistered_session, Function | SmallTest | Level1) +{ + SessionInfo info; + sptr sceneSession = sptr::MakeSptr(info, nullptr); + sceneSession->NotifyWindowAttachStateListenerRegistered(true); + EXPECT_EQ(sceneSession->needNotifyAttachState_, true); + sceneSession->NotifyWindowAttachStateListenerRegistered(false); + EXPECT_EQ(sceneSession->needNotifyAttachState_, false); +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wm/test/unittest/window_scene_session_impl_test4.cpp b/wm/test/unittest/window_scene_session_impl_test4.cpp index f53c7ce9e4..f7901f746d 100644 --- a/wm/test/unittest/window_scene_session_impl_test4.cpp +++ b/wm/test/unittest/window_scene_session_impl_test4.cpp @@ -669,6 +669,72 @@ HWTEST_F(WindowSceneSessionImplTest4, RegisterKeyboardPanelInfoChangeListener, T EXPECT_EQ(WMError::WM_ERROR_INVALID_OPERATION, ret); } +/** + * @tc.name: RegisterWindowAttachStateChangeListener + * @tc.desc: RegisterWindowAttachStateChangeListener + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest4, RegisterWindowAttachStateChangeListener, TestSize.Level1) +{ + sptr option = sptr::MakeSptr(); + option->SetWindowName("RegisterKeyboardPanelInfoChangeListener"); + sptr windowSceneSessionImpl = sptr::MakeSptr(option); + windowSceneSessionImpl->windowAttachStateChangeListener_ = sptr::MakeSptr(); + + SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; + sptr session = sptr::MakeSptr(sessionInfo); + windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; + windowSceneSessionImpl->hostSession_ = session; + + // case1: listener is nullptr + sptr listener = nullptr; + auto ret = windowSceneSessionImpl->RegisterWindowAttachStateChangeListener(listener); + EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); + + // case2: listener is not nullptr + listener = sptr::MakeSptr(); + ret = windowSceneSessionImpl->RegisterWindowAttachStateChangeListener(listener); + EXPECT_EQ(WMError::WM_OK, ret); + + // case3: host session is nullptr + windowSceneSessionImpl->hostSession_ = nullptr; + ret = windowSceneSessionImpl->RegisterWindowAttachStateChangeListener(listener); + EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); +} + +/** + * @tc.name: UnregisterWindowAttachStateChangeListener + * @tc.desc: UnregisterWindowAttachStateChangeListener + * @tc.type: FUNC + */ +HWTEST_F(WindowSceneSessionImplTest4, UnregisterWindowAttachStateChangeListener, TestSize.Level1) +{ + sptr option = sptr::MakeSptr(); + option->SetWindowName("UnregisterWindowAttachStateChangeListener"); + sptr windowSceneSessionImpl = sptr::MakeSptr(option); + windowSceneSessionImpl->windowAttachStateChangeListener_ = sptr::MakeSptr(); + + SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; + sptr session = sptr::MakeSptr(sessionInfo); + windowSceneSessionImpl->state_ = WindowState::STATE_SHOWN; + windowSceneSessionImpl->hostSession_ = session; + + // case1: register listener + sptr listener = sptr::MakeSptr(); + auto ret = windowSceneSessionImpl->RegisterWindowAttachStateChangeListener(listener); + EXPECT_EQ(WMError::WM_OK, ret); + + // case2: unregister success + ret = windowSceneSessionImpl->UnregisterWindowAttachStateChangeListener(); + EXPECT_EQ(WMError::WM_OK, ret); + EXPECT_EQ(windowSceneSessionImpl->windowAttachStateChangeListener_, nullptr); + + // case3: host session is nullptr + windowSceneSessionImpl->hostSession_ = nullptr; + ret = windowSceneSessionImpl->UnregisterWindowAttachStateChangeListener(); + EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); +} + /** * @tc.name: GetSystemBarPropertyByType * @tc.desc: GetSystemBarPropertyByType -- Gitee