From 035bb4b40aa3921c68a8ae62b1f28554cb838c71 Mon Sep 17 00:00:00 2001 From: Laiganlu Date: Wed, 10 Sep 2025 11:35:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=AA=E5=9B=BE=E7=BC=93=E5=AD=98=E6=81=A2?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Laiganlu --- window_scene/session/host/src/session.cpp | 13 +++++++--- .../include/scene_session_manager.h | 1 + .../src/scene_session_manager.cpp | 25 ++++++++++++++++++- .../src/window_manager_lru.cpp | 6 ++--- .../unittest/scene_session_manager_test5.cpp | 21 ++++++++++++++++ 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 7978d48e45..b80ead6e7d 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2789,6 +2789,10 @@ void Session::SaveSnapshot(bool useFfrt, bool needPersist, std::shared_ptraddSnapshotCallback_(); } session->SetAddSnapshotCallback([]() {}); + { + std::lock_guard lock(session->saveSnapshotCallbackMutex_); + session->saveSnapshotCallback_(); + } if (!requirePersist) { return; } @@ -2806,12 +2810,13 @@ void Session::SaveSnapshot(bool useFfrt, bool needPersist, std::shared_ptrscenePersistence_->ResetSnapshotCache(); + Task removeSnapshotCallback = []() {}; { - std::lock_guard lock(session->saveSnapshotCallbackMutex_); - saveSnapshotCallback = session->saveSnapshotCallback_; + std::lock_guard lock(session->removeSnapshotCallbackMutex_); + removeSnapshotCallback = session->removeSnapshotCallback_; } - session->scenePersistence_->SaveSnapshot(pixelMap, saveSnapshotCallback, key, rotate, + session->scenePersistence_->SaveSnapshot(pixelMap, removeSnapshotCallback, key, rotate, session->freeMultiWindow_.load()); if (updateSnapshot) { session->SetExitSplitOnBackground(false); diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 3e4c672245..b8488c0c14 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -791,6 +791,7 @@ public: std::shared_ptr GetPreLoadStartingWindow(const SessionInfo& sessionInfo); void RemovePreLoadStartingWindowFromMap(const SessionInfo& sessionInfo); WSError RegisterSaveSnapshotFunc(const sptr& sceneSession); + WSError RegisterRemoveSnapshotFunc(const sptr& sceneSession); std::shared_ptr GetPixelMap(uint32_t resourceId, std::shared_ptr abilityInfo); bool GetPersistentImageFit(int32_t persistentId, int32_t& imageFit); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 426d574ec9..1282aebf9f 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -147,7 +147,7 @@ constexpr uint64_t VIRTUAL_DISPLAY_ID = 999; constexpr uint32_t DEFAULT_LOCK_SCREEN_ZORDER = 2000; constexpr int32_t MAX_LOCK_STATUS_CACHE_SIZE = 1000; constexpr std::size_t MAX_SNAPSHOT_IN_RECENT_PC = 50; -constexpr std::size_t MAX_SNAPSHOT_IN_RECENT_PAD = 0; +constexpr std::size_t MAX_SNAPSHOT_IN_RECENT_PAD = 8; constexpr std::size_t MAX_SNAPSHOT_IN_RECENT_PHONE = 1; constexpr uint64_t NOTIFY_START_ABILITY_TIMEOUT = 4000; constexpr uint64_t START_UI_ABILITY_TIMEOUT = 5000; @@ -2786,6 +2786,9 @@ void SceneSessionManager::InitSceneSession(sptr& sceneSession, con if (systemConfig_.IsPcOrPcMode()) { RegisterGetStartWindowConfigCallback(sceneSession); } + if (systemConfig_.windowUIType_ == WindowUIType::PAD_WINDOW) { + RegisterRemoveSnapshotFunc(sceneSession); + } // Skip FillSessionInfo when atomicService free-install start. if (!IsAtomicServiceFreeInstall(sessionInfo)) { FillSessionInfo(sceneSession); @@ -3305,6 +3308,23 @@ WSError SceneSessionManager::RegisterSaveSnapshotFunc(const sptr& return WSError::WS_OK; } +WSError SceneSessionManager::RegisterRemoveSnapshotFunc(const sptr& sceneSession) +{ + if (sceneSession == nullptr) { + TLOGE(WmsLogTag::WMS_PATTERN, "session is nullptr"); + return WSError::WS_ERROR_NULLPTR; + } + if (!WindowHelper::IsMainWindow(sceneSession->GetWindowType())) { + return WSError::WS_ERROR_INVALID_WINDOW; + } + auto persistentId = sceneSession->GetPersistentId(); + sceneSession->SetRemoveSnapshotCallback([this, persistentId]() { + this->RemoveSnapshotFromCache(persistentId); + }); + return WSError::WS_OK; +} + + void SceneSessionManager::ConfigSupportSnapshotAllSessionStatus() { TLOGI(WmsLogTag::WMS_PATTERN, "support"); @@ -3608,6 +3628,9 @@ WSError SceneSessionManager::RequestSceneSessionDestruction(const sptrGetSessionInfo(), ActionType::SINGLE_CLOSE); + sceneSession->SetRemoveSnapshotCallback([this, persistentId]() { + this->RemoveSnapshotFromCache(persistentId); + }); sceneSession->DisconnectTask(false, isSaveSnapshot); ClearWatermarkRecordWhenAppExit(sceneSession); if (!GetSceneSession(persistentId)) { diff --git a/window_scene/session_manager/src/window_manager_lru.cpp b/window_scene/session_manager/src/window_manager_lru.cpp index 2d5d4484de..eb0af7940b 100644 --- a/window_scene/session_manager/src/window_manager_lru.cpp +++ b/window_scene/session_manager/src/window_manager_lru.cpp @@ -36,13 +36,13 @@ int32_t LruCache::Put(int32_t key) int32_t lastRemovedKey = UNDEFINED_REMOVED_KEY; std::lock_guard lock(lruCacheMutex_); if (!LocalVisit(key)) { - cacheList_.push_front(key); - cacheMap_[key] = cacheList_.begin(); - if (cacheList_.size() > capacity_) { + if (cacheList_.size() >= capacity_) { lastRemovedKey = cacheList_.back(); cacheList_.pop_back(); cacheMap_.erase(lastRemovedKey); } + cacheList_.push_front(key); + cacheMap_[key] = cacheList_.begin(); } return lastRemovedKey; } diff --git a/window_scene/test/unittest/scene_session_manager_test5.cpp b/window_scene/test/unittest/scene_session_manager_test5.cpp index f435141354..9a11a8c1fd 100644 --- a/window_scene/test/unittest/scene_session_manager_test5.cpp +++ b/window_scene/test/unittest/scene_session_manager_test5.cpp @@ -1773,6 +1773,27 @@ HWTEST_F(SceneSessionManagerTest5, RegisterSaveSnapshotFunc, TestSize.Level1) ASSERT_EQ(WSError::WS_OK, ssm_->RegisterSaveSnapshotFunc(sceneSession)); } +/** + * @tc.name: RegisterRemoveSnapshotFunc + * @tc.desc: RegisterRemoveSnapshotFunc Test + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest5, RegisterRemoveSnapshotFunc, TestSize.Level1) +{ + ASSERT_NE(ssm_, nullptr); + sptr sceneSession = nullptr; + ASSERT_EQ(WSError::WS_ERROR_NULLPTR, ssm_->RegisterSaveSnapshotFunc(sceneSession)); + + SessionInfo info; + info.windowType_ = 1000; + sceneSession = sptr::MakeSptr(info, nullptr); + sceneSession->property_->SetPersistentId(1); + ASSERT_EQ(WSError::WS_ERROR_INVALID_WINDOW, ssm_->RegisterSaveSnapshotFunc(sceneSession)); + + sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); + ASSERT_EQ(WSError::WS_OK, ssm_->RegisterSaveSnapshotFunc(sceneSession)); +} + /** * @tc.name: GetDelayRemoveSnapshot * @tc.desc: GetDelayRemoveSnapshot Test -- Gitee