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 275f15edd04e188156f22db5c37baf445eca1c5f..6d4671aa87304242ea46e4528b075b732a8ebe10 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 b2ec04cb959e9526f67790b362348cf7016a53f8..ffe81a55f64b0085f4747c5e14c4c56856418717 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 2aa0c87c083418b992b7fc11b00a91aab515237f..5140997f0834c380ff89e01e0fb76bf9de328e70 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 5b72ee6ce51118c388a9bd995645d0936a3fea85..8299cf8cbbe33061a6e5d993b000cedd5ab3a0bc 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 dfa132f3977e78adab260d9c63e5d742f7f558b6..d285630111955216b9ff39676c0b40ca528fae01 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 62d01d7c31504dd3e12fd8577d26550f0aa95339..9c75a19b88621a971033c6897dd7028e9af259ee 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 f53c7ce9e488cf14418645ca28b8acfafc3f86de..f7901f746d2397972412f612939ba1616c610b97 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