From 9f2de148a801e1a81eda0ddf86ca8557113343ce Mon Sep 17 00:00:00 2001 From: chaos Date: Fri, 29 Aug 2025 14:27:39 +0800 Subject: [PATCH] fix Signed-off-by: chaos --- .../src/screen_session_manager.cpp | 8 +++++-- .../screen_session_manager_test2.cpp | 22 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/window_scene/screen_session_manager/src/screen_session_manager.cpp b/window_scene/screen_session_manager/src/screen_session_manager.cpp index fe13d91b18..b5c7d97f89 100644 --- a/window_scene/screen_session_manager/src/screen_session_manager.cpp +++ b/window_scene/screen_session_manager/src/screen_session_manager.cpp @@ -576,7 +576,10 @@ DMError ScreenSessionManager::RegisterDisplayManagerAgent( if (type == DisplayManagerAgentType::DISPLAY_EVENT_LISTENER) { auto uid = IPCSkeleton::GetCallingUid(); auto pid = IPCSkeleton::GetCallingPid(); - uidAndPidMap_[uid] = pid; + { + std::shared_lock lock(hookInfoMutex_); + uidAndPidMap_[uid] = pid; + } } return dmAgentContainer_.RegisterAgent(displayManagerAgent, type) ? DMError::DM_OK :DMError::DM_ERROR_NULLPTR; } @@ -2285,9 +2288,9 @@ void ScreenSessionManager::NotifyDisplayChangedByUidInner(sptr disp if (agents.empty()) { return; } + auto iter = uidAndPidMap_.find(uid); for (const auto& agent : agents) { int32_t agentPid = dmAgentContainer_.GetAgentPid(agent); - auto iter = uidAndPidMap_.find(uid); if (iter == uidAndPidMap_.end() || iter->second != agentPid) { TLOGND(WmsLogTag::DMS, "no notify"); continue; @@ -2299,6 +2302,7 @@ void ScreenSessionManager::NotifyDisplayChangedByUidInner(sptr disp } }; taskScheduler_->PostAsyncTask(task, "NotifyDisplayChanged"); + TLOGI(WmsLogTag::DMS, "notify end"); } void ScreenSessionManager::GetDisplayHookInfo(int32_t uid, DMHookInfo& hookInfo) diff --git a/window_scene/test/dms_unittest/screen_session_manager_test2.cpp b/window_scene/test/dms_unittest/screen_session_manager_test2.cpp index f318ae02bc..9f1c93bdba 100644 --- a/window_scene/test/dms_unittest/screen_session_manager_test2.cpp +++ b/window_scene/test/dms_unittest/screen_session_manager_test2.cpp @@ -91,6 +91,9 @@ namespace { */ HWTEST_F(ScreenSessionManagerTest, SetScreenPowerForFold01, TestSize.Level1) { + if (!FoldScreenStateInternel::IsFoldScreenDevice()) { + GTEST_SKIP(); + } // 内屏预上电 g_errLog.clear(); LOG_SetCallback(MyLogCallback); @@ -115,6 +118,9 @@ HWTEST_F(ScreenSessionManagerTest, SetScreenPowerForFold01, TestSize.Level1) */ HWTEST_F(ScreenSessionManagerTest, SetScreenPowerForFold02, TestSize.Level1) { + if (!FoldScreenStateInternel::IsFoldScreenDevice()) { + GTEST_SKIP(); + } g_errLog.clear(); LOG_SetCallback(MyLogCallback); sptr ssm = sptr::MakeSptr(); @@ -133,6 +139,9 @@ HWTEST_F(ScreenSessionManagerTest, SetScreenPowerForFold02, TestSize.Level1) */ HWTEST_F(ScreenSessionManagerTest, SetScreenPowerForFold03, TestSize.Level1) { + if (!FoldScreenStateInternel::IsFoldScreenDevice()) { + GTEST_SKIP(); + } g_errLog.clear(); LOG_SetCallback(MyLogCallback); sptr ssm = sptr::MakeSptr(); @@ -1094,7 +1103,6 @@ HWTEST_F(ScreenSessionManagerTest, SetLandscapeLockStatus01, TestSize.Level1) EXPECT_TRUE(g_errLog.find("permission denied!") != std::string::npos); } -chaos /** * @tc.name: NotifyDisplayChangedByUid * @tc.desc: NotifyDisplayChangedByUid test @@ -1103,7 +1111,7 @@ chaos HWTEST_F(ScreenSessionManagerTest, NotifyDisplayChangedByUid, TestSize.Level1) { g_errLog.clear(); - ASSERT_NE(ssm, nullptr); + ASSERT_NE(ssm_, nullptr); ssm_->screenSessionMap_.clear(); ScreenId screenId = 1050; sptr screenSession = new (std::nothrow) ScreenSession(screenId, ScreenProperty(), 0); @@ -1111,8 +1119,10 @@ HWTEST_F(ScreenSessionManagerTest, NotifyDisplayChangedByUid, TestSize.Level1) ssm_->screenSessionMap_[screenId] = screenSession; std::map> screenSessionMapCopy = ssm_->screenSessionMap_; ssm_->NotifyDisplayChangedByUid(screenSessionMapCopy, DisplayChangeEvent::DISPLAY_SIZE_CHANGED, 2002); + ssm_->screenSessionMap_.clear(); ssm_->screenSessionMap_[1051] = nullptr; - ssm_->NotifyDisplayChangedByUid(screenSessionMapCopy, DisplayChangeEvent::DISPLAY_SIZE_CHANGED, 2002); + std::map> screenSessionMapCopy1 = ssm_->screenSessionMap_; + ssm_->NotifyDisplayChangedByUid(screenSessionMapCopy1, DisplayChangeEvent::DISPLAY_SIZE_CHANGED, 2002); EXPECT_TRUE(g_errLog.find("screenSession is nullptr") != std::string::npos); } @@ -1124,13 +1134,13 @@ HWTEST_F(ScreenSessionManagerTest, NotifyDisplayChangedByUid, TestSize.Level1) HWTEST_F(ScreenSessionManagerTest, NotifyDisplayChangedByUidInner, TestSize.Level1) { g_errLog.clear(); - ASSERT_NE(ssm, nullptr); + ASSERT_NE(ssm_, nullptr); ScreenId screenId = 1050; sptr screenSession = new (std::nothrow) ScreenSession(screenId, ScreenProperty(), 0); ASSERT_NE(screenSession, nullptr); - ssm_->NotifyDisplayChangedByUid((screenSession->ConvertToDisplayInfo(), + ssm_->NotifyDisplayChangedByUidInner(screenSession->ConvertToDisplayInfo(), DisplayChangeEvent::DISPLAY_SIZE_CHANGED, 2002); - EXPECT_TRUE(g_errLog.find("uid") != std::string::npos); + EXPECT_TRUE(g_errLog.find("notify end") != std::string::npos); } /** -- Gitee