diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 0e2db2ae870d594875e7b6be1ca29d41693c816b..c17ce023016c93de4aaa90c6334b1f73c41dfcd0 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -1219,14 +1219,21 @@ void SceneSession::NotifyUpdateAppUseControl(ControlAppType type, const ControlI session->appUseControlMap_[type] = controlInfo; if (session->onUpdateAppUseControlFunc_) { bool isAppUseControl = (controlInfo.isNeedControl && !controlInfo.isControlRecentOnly); + bool isAppUseControlChanged = (session->isAppUseControl_ != isAppUseControl); session->isAppUseControl_ = isAppUseControl; session->onUpdateAppUseControlFunc_(type, controlInfo.isNeedControl, controlInfo.isControlRecentOnly); if (session->sessionStage_ == nullptr || type == ControlAppType::PRIVACY_WINDOW) { TLOGNW(WmsLogTag::WMS_LIFE, "%{public}s sessionStage is nullptr or privacy mode control", where); return; } - TLOGNI(WmsLogTag::WMS_LIFE, "%{public}s isAppUseControl: %{public}d, persistentId: %{public}d", where, - isAppUseControl, session->GetPersistentId()); + auto state = session->GetSessionState(); + TLOGNI(WmsLogTag::WMS_LIFE, + "%{public}s isAppUseControl: %{public}d, persistentId: %{public}d, state: %{public}d, " + "isAppUseControlChanged: %{public}d", where, isAppUseControl, session->GetPersistentId(), state, + isAppUseControlChanged); + if (state == SessionState::STATE_BACKGROUND && !isAppUseControlChanged) { + return; + } session->sessionStage_->NotifyAppUseControlStatus(isAppUseControl); } }, __func__); diff --git a/window_scene/test/unittest/scene_session_test3.cpp b/window_scene/test/unittest/scene_session_test3.cpp index 0c05c9b33d7575d2f044e788524c138fc97d9f2e..d15d6818ebdb598e7f90d2301f6cab7f9489a38e 100644 --- a/window_scene/test/unittest/scene_session_test3.cpp +++ b/window_scene/test/unittest/scene_session_test3.cpp @@ -1216,7 +1216,15 @@ HWTEST_F(SceneSessionTest3, NotifyUpdateAppUseControl, Function | SmallTest | Le .isControlRecentOnly = false }; sceneSession->NotifyUpdateAppUseControl(type, controlInfoSec); - EXPECT_TRUE(logMsg.find("begin call pause") == std::string::npos); + + sceneSession->Session::SetSessionState(SessionState::STATE_BACKGROUND); + sceneSession->NotifyUpdateAppUseControl(type, controlInfoSec); + ControlInfo controlInfoThd = { + .isNeedControl = true, + .isControlRecentOnly = false + }; + sceneSession->NotifyUpdateAppUseControl(type, controlInfoThd); + EXPECT_TRUE(logMsg.find("isAppUseControl:") != std::string::npos); LOG_SetCallback(nullptr); }