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 f60e67936a71b23814e3e634953005b9cc0da5dd..022171c33dd6f4301d9866a7864b138db48b8f7a 100644 --- a/window_scene/screen_session_manager/src/screen_session_manager.cpp +++ b/window_scene/screen_session_manager/src/screen_session_manager.cpp @@ -10287,13 +10287,17 @@ void ScreenSessionManager::CreateExtendVirtualScreen(ScreenId screenId) rsConfig.screenId = rsScreenId; screenSession->CreateDisplayNode(rsConfig); screenSession->SetDisplayNodeScreenId(rsScreenId); + screenSession->SetDisplayNodeSecurity(); screenSession->SetIsCurrentInUse(true); screenSession->SetIsExtend(true); screenSession->SetScreenCombination(ScreenCombination::SCREEN_MIRROR); screenSession->SetIsExtendVirtual(true); + screenSession->SetDisplayGroupId(DISPLAY_GROUP_ID_DEFAULT); + screenSession->SetMainDisplayIdOfGroup(DISPLAY_GROUP_ID_DEFAULT); TLOGI(WmsLogTag::DMS, "screenId: %{public}" PRIu64", rsScreenId:%{public}" PRIu64"", screenId, rsScreenId); } + NotifyDisplayCreate(screenSession->ConvertToDisplayInfo()); } DMError ScreenSessionManager::SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions, diff --git a/window_scene/session/screen/include/screen_session.h b/window_scene/session/screen/include/screen_session.h index 5f1cb39c652d5597dac2f792557b31821fb41b6a..0b407a04673ca8e2bbca29290cfb5bc2088f0662 100644 --- a/window_scene/session/screen/include/screen_session.h +++ b/window_scene/session/screen/include/screen_session.h @@ -161,6 +161,7 @@ public: DisplayOrientation CalcDeviceOrientationWithBounds(Rotation rotation, FoldDisplayMode foldDisplayMode, const RRect& bounds); void FillScreenInfo(sptr info) const; + void SetDisplayNodeSecurity(); void InitRSDisplayNode(RSDisplayNodeConfig& config, Point& startPoint, bool isExtend = false, float positionX = 0, float positionY = 0); diff --git a/window_scene/session/screen/src/screen_session.cpp b/window_scene/session/screen/src/screen_session.cpp index 1b17b3f61f5818ef412bee0a08ce6ed46c39deeb..8bdaac6cc9b19047e090aa044805c577994a853e 100644 --- a/window_scene/session/screen/src/screen_session.cpp +++ b/window_scene/session/screen/src/screen_session.cpp @@ -1857,6 +1857,23 @@ void ScreenSession::SetPrivateSessionForeground(bool hasPrivate) { hasPrivateWindowForeground_ = hasPrivate; } +void ScreenSession::SetDisplayNodeSecurity() +{ + std::unique_lock displayNodeLock(displayNodeMutex_); + if (displayNode_ == nullptr) { + TLOGE(WmsLogTag::DMS, "displayNode is null"); + return; + } + RSScreenType screenType; + DmsXcollie dmsXcollie("DMS:InitRSDisplayNode:GetScreenType", XCOLLIE_TIMEOUT_5S); + auto ret = RSInterfaces::GetInstance().GetScreenType(rsId_, screenType); + if (ret == StatusCode::SUCCESS && screenType == RSScreenType::VIRTUAL_TYPE_SCREEN) { + displayNode_->SetSecurityDisplay(isSecurity_); + TLOGI(WmsLogTag::DMS, "virtualScreen SetSecurityDisplay success, isSecurity:%{public}d", isSecurity_); + } + RSTransactionAdapter::FlushImplicitTransaction(GetRSUIContext()); + TLOGI(WmsLogTag::DMS, "end"); +} void ScreenSession::InitRSDisplayNode(RSDisplayNodeConfig& config, Point& startPoint, bool isExtend, float positionX, float positionY) 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 f88edbefb0fd6dc1bb07d6ebe0c3dc496f44078d..b7e28ddc1b3ddd21bc7672ee7d6910f56de26ee5 100644 --- a/window_scene/test/dms_unittest/screen_session_manager_test2.cpp +++ b/window_scene/test/dms_unittest/screen_session_manager_test2.cpp @@ -17,6 +17,7 @@ #include #include +#include "common_test_utils.h" #include "display_manager_agent_default.h" #include "screen_session_manager/include/screen_session_manager.h" #include "screen_scene_config.h" @@ -60,6 +61,7 @@ public: void TearDown() override; static sptr ssm_; + sptr InitTestScreenSession(std::string name, ScreenId& screenId); }; sptr ScreenSessionManagerTest::ssm_ = nullptr; @@ -67,6 +69,10 @@ sptr ScreenSessionManagerTest::ssm_ = nullptr; void ScreenSessionManagerTest::SetUpTestCase() { ssm_ = new ScreenSessionManager(); + CommonTestUtils::InjectTokenInfoByHapName(0, "com.ohos.systemui", 0); + const char** perms = new const char *[1]; + perms[0] = "ohos.permission.CAPTURE_SCREEN"; + CommonTestUtils::SetAceessTokenPermission("foundation", perms, 1); } void ScreenSessionManagerTest::TearDownTestCase() @@ -154,6 +160,37 @@ HWTEST_F(ScreenSessionManagerTest, SetScreenPowerForFold03, TestSize.Level1) EXPECT_TRUE(g_errLog.find("set advancedOn powerStatus off") == std::string::npos); } +/** + * @tc.name: SetDisplayNodeSecurity + * @tc.desc: SetDisplayNodeSecurity test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionManagerTest, SetDisplayNodeSecurity, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + sptr displayManagerAgent = new(std::nothrow) DisplayManagerAgentDefault(); + VirtualScreenOption virtualOption; + virtualOption.name_ = "createVirtualOption"; + virtualOption.width_ = 200; + virtualOption.height_ = 100; + virtualOption.isSecurity_ = true; + auto screenId = ssm_->CreateVirtualScreen(virtualOption, displayManagerAgent->AsObject()); + sptr screenSession = ssm_->GetScreenSession(screenId); + ASSERT_NE(screenSession, nullptr); + screenSession->SetDisplayNodeSecurity(); + EXPECT_TRUE(g_errLog.find("displayNode is null") != std::string::npos); + + Rosen::RSDisplayNodeConfig rsConfig; + ScreenId rsScreenId = screenSession->GetRSScreenId(); + rsConfig.screenId = rsScreenId; + screenSession->CreateDisplayNode(rsConfig); + screenSession->SetDisplayNodeSecurity(); + EXPECT_TRUE(g_errLog.find("SetSecurityDisplay success") != std::string::npos); + ssm->DestroyVirtualScreen(screenId); +} + /** * @tc.name: SwitchScrollParam01 * @tc.desc: SwitchScrollParam test