From d7395eb928570821ef46566a59b719a351ca44e0 Mon Sep 17 00:00:00 2001 From: hejunfei Date: Tue, 9 Sep 2025 19:15:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=96=B0=E5=B1=8F=E5=B9=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hejunfei --- dm/src/display_manager.cpp | 25 +++++++ dm/test/unittest/display_manager_test.cpp | 86 +++++++++++++++++++++++ interfaces/innerkits/dm/display_manager.h | 8 +++ wm/src/window_session_impl.cpp | 17 +++-- 4 files changed, 131 insertions(+), 5 deletions(-) diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index d4c862fa2a..2c3665f821 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -989,6 +989,31 @@ void DisplayManager::RemoveDisplayIdFromAms(const wptr& abilityTo ShowDisplayIdList(false); } +void DisplayManager::UpdateDisplayIdFromAms(DisplayId displayId, const wptr& abilityToken) +{ + TLOGI(WmsLogTag::DMS, "start"); + if (abilityToken == nullptr || displayId == DISPLAY_ID_INVALID) { + TLOGE(WmsLogTag::DMS, "abilityToken is nullptr or display id invalid. displayId: %{public}" PRIu64, displayId); + return; + } + std::lock_guard lock(displayOperateMutex_); + if (displayIdList_.empty()) { + TLOGI(WmsLogTag::DMS, "displayIdList_ is empty. add displayId directly."); + displayIdList_.push_back(std::make_pair(abilityToken, displayId)); + return; + } + displayIdList_.erase( + std::remove_if(displayIdList_.begin(), displayIdList_.end(), + [abilityToken](const auto &item) -> bool { + TLOGI(WmsLogTag::DMS, "item second: displayId: %{public}" PRIu64, item.second); + return item.first == abilityToken; + }), + displayIdList_.end() + ); + displayIdList_.push_back(std::make_pair(abilityToken, displayId)); + ShowDisplayIdList(false); +} + DisplayId DisplayManager::GetCallingAbilityDisplayId() { DisplayId displayId = DISPLAY_ID_INVALID; diff --git a/dm/test/unittest/display_manager_test.cpp b/dm/test/unittest/display_manager_test.cpp index a33680fa0f..b23b8009b2 100644 --- a/dm/test/unittest/display_manager_test.cpp +++ b/dm/test/unittest/display_manager_test.cpp @@ -2828,6 +2828,92 @@ HWTEST_F(DisplayManagerTest, NotifyScreenshot, TestSize.Level1) EXPECT_TRUE(g_errLog.find("NotifyScreenshot trigger") != std::string::npos); g_errLog.clear(); } + +/** + * @tc.name: UpdateDisplayIdFromAms_Null_AbilityToken + * @tc.desc: Test UpdateDisplayIdFromAms with null abilityToken + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, UpdateDisplayIdFromAms_Null_AbilityToken, TestSize.Level1) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + DisplayId displayId = 0; + wptr abilityToken = nullptr; + SingletonContainer::Get().UpdateDisplayIdFromAms(displayId, abilityToken); + EXPECT_TRUE(g_errLog.find("abilityToken is nullptr") != std::string::npos); + g_errLog.clear(); + + sptr obj; + if (SceneBoardJudgement::IsSceneBoardEnabled()) { + ASSERT_NE(SingletonContainer::Get().screenSessionManagerServiceProxy_, nullptr); + obj = SingletonContainer::Get().screenSessionManagerServiceProxy_->AsObject(); + } else { + ASSERT_NE(SingletonContainer::Get().displayManagerServiceProxy_, nullptr); + obj = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); + } + abilityToken = obj; + displayId = -1; + SingletonContainer::Get().UpdateDisplayIdFromAms(displayId, abilityToken); + EXPECT_TRUE(g_errLog.find("display id invalid") != std::string::npos); + g_errLog.clear(); +} + +/** + * @tc.name: UpdateDisplayIdFromAms_displayIdList_empty + * @tc.desc: Test UpdateDisplayIdFromAms with empty displayIdList + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, UpdateDisplayIdFromAms_displayIdList_empty, TestSize.Level1) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + DisplayManager displayManager; + displayManager.displayIdList_.clear(); + DisplayId displayId = 123; + sptr obj; + if (SceneBoardJudgement::IsSceneBoardEnabled()) { + ASSERT_NE(SingletonContainer::Get().screenSessionManagerServiceProxy_, nullptr); + obj = SingletonContainer::Get().screenSessionManagerServiceProxy_->AsObject(); + } else { + ASSERT_NE(SingletonContainer::Get().displayManagerServiceProxy_, nullptr); + obj = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); + } + wptr abilityToken = obj; + displayManager.UpdateDisplayIdFromAms(displayId, abilityToken); + EXPECT_TRUE(g_errLog.find("displayIdList_ is empty") != std::string::npos); + EXPECT_EQ(displayManager.GetCallingAbilityDisplayId(), displayId); + g_errLog.clear(); +} + +/** + * @tc.name: UpdateDisplayIdFromAms_Success + * @tc.desc: Test UpdateDisplayIdFromAms success + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, UpdateDisplayIdFromAms_Success, TestSize.Level1) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + DisplayManager displayManager; + displayManager.displayIdList_.clear(); + sptr obj; + if (SceneBoardJudgement::IsSceneBoardEnabled()) { + ASSERT_NE(SingletonContainer::Get().screenSessionManagerServiceProxy_, nullptr); + obj = SingletonContainer::Get().screenSessionManagerServiceProxy_->AsObject(); + } else { + ASSERT_NE(SingletonContainer::Get().displayManagerServiceProxy_, nullptr); + obj = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); + } + wptr abilityToken = obj; + displayManager.displayIdList_.emplace_back(abilityToken, 111); + displayManager.displayIdList_.emplace_back(abilityToken, 222); + displayManager.displayIdList_.emplace_back(abilityToken, 333); + DisplayId displayId2 = 123; + displayManager.UpdateDisplayIdFromAms(displayId2, abilityToken); + EXPECT_EQ(displayManager.GetCallingAbilityDisplayId(), displayId2); + g_errLog.clear(); +} } } // namespace Rosen } // namespace OHOS diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index b1f5f8d605..91f2d37a68 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -836,6 +836,14 @@ public: */ void RemoveDisplayIdFromAms(const wptr& abilityToken); + /** + * @brief update displayId for current ability through Ability Management. + * + * @param displayId Identifier of the current display. + * @param abilityToken Token of the ability. + */ + void UpdateDisplayIdFromAms(DisplayId displayId, const wptr& abilityToken); + /** * @brief Get primary display object by means of sync. * diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 8a31c8bd25..71678e79a0 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -5334,13 +5334,20 @@ EnableIfSame>> W void WindowSessionImpl::NotifyDisplayMove(DisplayId from, DisplayId to) { WLOGFD("from %{public}" PRIu64 " to %{public}" PRIu64, from, to); - std::lock_guard lockListener(displayMoveListenerMutex_); - auto displayMoveListeners = GetListeners(); - for (auto& listener : displayMoveListeners) { - if (listener != nullptr) { - listener->OnDisplayMove(from, to); + { + std::lock_guard lockListener(displayMoveListenerMutex_); + auto displayMoveListeners = GetListeners(); + for (auto& listener : displayMoveListeners) { + if (listener != nullptr) { + listener->OnDisplayMove(from, to); + } } } + auto context = GetContext(); + if (context != nullptr) { + TLOGI(WmsLogTag::WMS_MAIN, "update display move to dms"); + DisplayManager::GetInstance().UpdateDisplayIdFromAms(to, context->GetToken()); + } } WSError WindowSessionImpl::NotifyCloseExistPipWindow() -- Gitee From 04bc87f09e686bf56f9d4295e4d495551a51fdbf Mon Sep 17 00:00:00 2001 From: hejunfei Date: Wed, 10 Sep 2025 03:01:42 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hejunfei --- dm/src/display_manager.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 2c3665f821..589612949a 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -991,21 +991,20 @@ void DisplayManager::RemoveDisplayIdFromAms(const wptr& abilityTo void DisplayManager::UpdateDisplayIdFromAms(DisplayId displayId, const wptr& abilityToken) { - TLOGI(WmsLogTag::DMS, "start"); + TLOGI(WmsLogTag::DMS, "start, displayId: %{public}" PRIu64, displayId); if (abilityToken == nullptr || displayId == DISPLAY_ID_INVALID) { TLOGE(WmsLogTag::DMS, "abilityToken is nullptr or display id invalid. displayId: %{public}" PRIu64, displayId); return; } std::lock_guard lock(displayOperateMutex_); if (displayIdList_.empty()) { - TLOGI(WmsLogTag::DMS, "displayIdList_ is empty. add displayId directly."); + TLOGI(WmsLogTag::DMS, "displayIdList is empty. add displayId directly."); displayIdList_.push_back(std::make_pair(abilityToken, displayId)); return; } displayIdList_.erase( std::remove_if(displayIdList_.begin(), displayIdList_.end(), [abilityToken](const auto &item) -> bool { - TLOGI(WmsLogTag::DMS, "item second: displayId: %{public}" PRIu64, item.second); return item.first == abilityToken; }), displayIdList_.end() -- Gitee