From b8bbf8db517dfdc6db25ebdc0f94366a862584dc Mon Sep 17 00:00:00 2001 From: nzy Date: Sat, 21 Dec 2024 11:02:14 +0800 Subject: [PATCH] =?UTF-8?q?NotifySessionForegroud/NotifySessionBackgroud?= =?UTF-8?q?=E4=BC=98=E5=8C=96&=E6=97=A5=E5=BF=97=E4=BC=98=E5=8C=96&?= =?UTF-8?q?=E5=A4=B4=E6=96=87=E4=BB=B6=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nzy --- .../session/host/src/scene_session.cpp | 11 ++- .../scene_session_manager_lite_interface.h | 34 ++++---- .../src/scene_session_manager.cpp | 80 +++++++++---------- wm/src/window_scene_session_impl.cpp | 40 +++++----- 4 files changed, 84 insertions(+), 81 deletions(-) diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index d51c96eef5..94231c54d6 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -131,7 +131,7 @@ WSError SceneSession::ConnectInner(const sptr& sessionStage, session->NotifyPropertyWhenConnect(); return ret; }; - return PostSyncTask(task, "ConnectInner"); + return PostSyncTask(task, __func__); } WSError SceneSession::Connect(const sptr& sessionStage, const sptr& eventChannel, @@ -386,7 +386,7 @@ WSError SceneSession::ForegroundTask(const sptr& property TLOGNI(WmsLogTag::WMS_LIFE, "foreground specific callback does not take effect, callback function null"); } return WSError::WS_OK; - }, "Foreground"); + }, __func__); return WSError::WS_OK; } @@ -472,7 +472,7 @@ WSError SceneSession::BackgroundTask(const bool isSaveSnapshot) session->UpdateGestureBackEnabled(); } return WSError::WS_OK; - }, "Background"); + }, __func__); return WSError::WS_OK; } @@ -578,8 +578,7 @@ WSError SceneSession::DisconnectTask(bool isFromClient, bool isSaveSnapshot) session->isEnableGestureBackHadSet_ = false; } return WSError::WS_OK; - }, - "Disconnect"); + }, __func__); return WSError::WS_OK; } @@ -4007,7 +4006,7 @@ WSError SceneSession::PendingSessionActivation(const sptr ab session->pendingSessionActivationFunc_(info); } return WSError::WS_OK; - }, "PendingSessionActivation"); + }, __func__); return WSError::WS_OK; } diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h b/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h index 494b0e5952..f3a55d3531 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_lite_interface.h @@ -85,14 +85,24 @@ public: TRANS_ID_NOTIFY_APP_USE_CONTROL_LIST, }; - virtual WSError SetSessionLabel(const sptr& token, const std::string& label) = 0; - virtual WSError SetSessionIcon(const sptr& token, const std::shared_ptr& icon) = 0; - virtual WSError IsValidSessionIds(const std::vector& sessionIds, std::vector& results) = 0; + /* + * Window Lifecycle + */ virtual WSError PendingSessionToForeground(const sptr& token) = 0; virtual WSError PendingSessionToBackgroundForDelegator(const sptr& token, bool shouldBackToCaller = true) = 0; - virtual WSError GetFocusSessionToken(sptr& token) = 0; - virtual WSError GetFocusSessionElement(AppExecFwk::ElementName& element) = 0; + virtual WSError MoveSessionsToForeground(const std::vector& sessionIds, int32_t topSessionId) = 0; + virtual WSError MoveSessionsToBackground(const std::vector& sessionIds, + std::vector& result) = 0; + virtual WSError TerminateSessionNew( + const sptr info, bool needStartCaller, bool isFromBroker = false) = 0; + virtual WSError ClearSession(int32_t persistentId) = 0; + virtual WSError ClearAllSessions() = 0; + virtual WSError SetSessionLabel(const sptr& token, const std::string& label) = 0; + virtual WSError SetSessionIcon(const sptr& token, const std::shared_ptr& icon) = 0; + virtual WSError RegisterIAbilityManagerCollaborator(int32_t type, + const sptr& impl) = 0; + virtual WSError UnregisterIAbilityManagerCollaborator(int32_t type) = 0; virtual WSError RegisterSessionListener(const sptr& listener, bool isRecover = false) = 0; virtual WSError UnRegisterSessionListener(const sptr& listener) = 0; virtual WSError GetSessionInfos(const std::string& deviceId, @@ -101,21 +111,15 @@ public: virtual WSError GetSessionInfoByContinueSessionId(const std::string& continueSessionId, SessionInfoBean& sessionInfo) = 0; virtual WSError SetSessionContinueState(const sptr& token, const ContinueState& continueState) = 0; - virtual WSError TerminateSessionNew( - const sptr info, bool needStartCaller, bool isFromBroker = false) = 0; + + virtual WSError IsValidSessionIds(const std::vector& sessionIds, std::vector& results) = 0; + virtual WSError GetFocusSessionToken(sptr& token) = 0; + virtual WSError GetFocusSessionElement(AppExecFwk::ElementName& element) = 0; virtual WSError GetSessionSnapshot(const std::string& deviceId, int32_t persistentId, SessionSnapshot& snapshot, bool isLowResolution) = 0; - virtual WSError ClearSession(int32_t persistentId) = 0; - virtual WSError ClearAllSessions() = 0; virtual WSError LockSession(int32_t sessionId) = 0; virtual WSError UnlockSession(int32_t sessionId) = 0; - virtual WSError MoveSessionsToForeground(const std::vector& sessionIds, int32_t topSessionId) = 0; - virtual WSError MoveSessionsToBackground(const std::vector& sessionIds, - std::vector& result) = 0; virtual WSError RaiseWindowToTop(int32_t persistentId) = 0; - virtual WSError RegisterIAbilityManagerCollaborator(int32_t type, - const sptr& impl) = 0; - virtual WSError UnregisterIAbilityManagerCollaborator(int32_t type) = 0; virtual WMError GetWindowStyleType(WindowStyleType& windowStyleType) = 0; /** diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index f3792a67ad..38435aac16 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -2611,7 +2611,7 @@ WSError SceneSessionManager::RequestSceneSessionDestruction(const sptrGetPersistentId(); @@ -6857,52 +6857,53 @@ void SceneSessionManager::NotifySessionMovedToFront(int32_t persistentId) WSError SceneSessionManager::SetSessionLabel(const sptr& token, const std::string& label) { - TLOGI(WmsLogTag::WMS_LIFE, "Enter"); - auto task = [this, &token, &label]() { + TLOGI(WmsLogTag::WMS_MAIN, "in"); + const char* const where = __func__; + auto task = [this, &token, &label, where]() { auto sceneSession = FindSessionByToken(token); if (sceneSession == nullptr) { - WLOGFI("fail to find session by token"); + TLOGNE(WmsLogTag::WMS_MAIN, "fail to find session by token"); return WSError::WS_ERROR_SET_SESSION_LABEL_FAILED; } sceneSession->SetSessionLabel(label); - WLOGI("NotifySessionLabelUpdated, id: %{public}d, system: %{public}d", sceneSession->GetPersistentId(), - sceneSession->GetSessionInfo().isSystem_); + TLOGNI(WmsLogTag::WMS_MAIN, "%{public}s id: %{public}d, system: %{public}d", + where, sceneSession->GetPersistentId(), sceneSession->GetSessionInfo().isSystem_); if (!sceneSession->GetSessionInfo().isSystem_) { - WLOGD("NotifySessionLabelUpdated, id: %{public}d", sceneSession->GetPersistentId()); + TLOGND(WmsLogTag::WMS_MAIN, "%{public}s id: %{public}d", where, sceneSession->GetPersistentId()); listenerController_->NotifySessionLabelUpdated(sceneSession->GetPersistentId()); } return WSError::WS_OK; }; - return taskScheduler_->PostSyncTask(task, "SetSessionLabel"); + return taskScheduler_->PostSyncTask(task, where); } WSError SceneSessionManager::SetSessionIcon(const sptr& token, const std::shared_ptr& icon) { - WLOGFI("in"); + TLOGI(WmsLogTag::WMS_MAIN, "in"); if (!SessionPermission::JudgeCallerIsAllowedToUseSystemAPI()) { - WLOGFE("The caller is not system-app, can not use system-api"); + TLOGE(WmsLogTag::WMS_MAIN, "The caller is not system-app, can not use system-api"); return WSError::WS_ERROR_NOT_SYSTEM_APP; } - - auto task = [this, &token, &icon]() { + const char* const where = __func__; + auto task = [this, &token, &icon, where]() { auto sceneSession = FindSessionByToken(token); if (sceneSession == nullptr) { - WLOGFI("fail to find session by token"); + TLOGNE(WmsLogTag::WMS_MAIN, "fail to find session by token"); return WSError::WS_ERROR_SET_SESSION_LABEL_FAILED; } sceneSession->SetSessionIcon(icon); - WLOGI("NotifySessionIconChanged, id: %{public}d, system: %{public}d", sceneSession->GetPersistentId(), - sceneSession->GetSessionInfo().isSystem_); + TLOGNI(WmsLogTag::WMS_MAIN, "%{public}s id: %{public}d, system: %{public}d", + where, sceneSession->GetPersistentId(), sceneSession->GetSessionInfo().isSystem_); if (!sceneSession->GetSessionInfo().isSystem_ && sceneSession->GetSessionInfo().abilityInfo && !(sceneSession->GetSessionInfo().abilityInfo)->excludeFromMissions) { - WLOGD("NotifySessionIconChanged, id: %{public}d", sceneSession->GetPersistentId()); + TLOGND(WmsLogTag::WMS_MAIN, "%{public}s id: %{public}d", where, sceneSession->GetPersistentId()); listenerController_->NotifySessionIconChanged(sceneSession->GetPersistentId(), icon); } return WSError::WS_OK; }; - return taskScheduler_->PostSyncTask(task, "SetSessionIcon"); + return taskScheduler_->PostSyncTask(task, where); } WSError SceneSessionManager::IsValidSessionIds( @@ -7610,19 +7611,18 @@ WSError SceneSessionManager::RequestSceneSessionByCall(const sptr& auto task = [this, weakSceneSession = wptr(sceneSession), where] { auto sceneSession = weakSceneSession.promote(); if (sceneSession == nullptr) { - WLOGFE("session is nullptr"); + TLOGNE(WmsLogTag::WMS_MAIN, "%{public}s: session is nullptr", where); return WSError::WS_ERROR_NULLPTR; } auto persistentId = sceneSession->GetPersistentId(); if (!GetSceneSession(persistentId)) { - WLOGFE("session is invalid with %{public}d", persistentId); + TLOGNE(WmsLogTag::WMS_MAIN, "%{public}s: session is invalid, id:%{public}d", where, persistentId); return WSError::WS_ERROR_INVALID_SESSION; } auto sessionInfo = sceneSession->GetSessionInfo(); auto abilitySessionInfo = SetAbilitySessionInfo(sceneSession); if (!abilitySessionInfo) { - TLOGNE(WmsLogTag::WMS_MAIN, - "%{public}s abilitySessionInfo is null, id:%{public}d", where, persistentId); + TLOGNE(WmsLogTag::WMS_MAIN, "%{public}s: abilitySessionInfo is null, id:%{public}d", where, persistentId); return WSError::WS_ERROR_NULLPTR; } TLOGNI(WmsLogTag::WMS_MAIN, "%{public}s: state:%{public}d, id:%{public}d", @@ -8733,7 +8733,7 @@ WSError SceneSessionManager::PendingSessionToForeground(const sptrPostSyncTask(task, "PendingSessionToForeground"); + return taskScheduler_->PostSyncTask(task, __func__); } WSError SceneSessionManager::PendingSessionToBackgroundForDelegator(const sptr& token, @@ -8747,7 +8747,7 @@ WSError SceneSessionManager::PendingSessionToBackgroundForDelegator(const sptrPostSyncTask(task, "PendingSessionToBackgroundForDelegator"); + return taskScheduler_->PostSyncTask(task, __func__); } void SceneSessionManager::ClearDisplayStatusBarTemporarilyFlags() @@ -9392,9 +9392,9 @@ void SceneSessionManager::OnScreenshot(DisplayId displayId) WSError SceneSessionManager::ClearSession(int32_t persistentId) { - WLOGFI("id: %{public}d", persistentId); + TLOGI(WmsLogTag::WMS_LIFE, "id: %{public}d", persistentId); if (!SessionPermission::JudgeCallerIsAllowedToUseSystemAPI()) { - WLOGFE("The caller is not system-app, can not use system-api"); + TLOGE(WmsLogTag::WMS_LIFE, "The caller is not system-app, can not use system-api"); return WSError::WS_ERROR_NOT_SYSTEM_APP; } if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { @@ -9411,13 +9411,13 @@ WSError SceneSessionManager::ClearSession(int32_t persistentId) WSError SceneSessionManager::ClearSession(sptr sceneSession) { - WLOGFD("in"); + TLOGD(WmsLogTag::WMS_LIFE, "in"); if (sceneSession == nullptr) { - WLOGFE("session is nullptr"); + TLOGE(WmsLogTag::WMS_LIFE, "session is nullptr"); return WSError::WS_ERROR_INVALID_SESSION; } if (!IsSessionClearable(sceneSession)) { - WLOGFI("session cannot be clear, Id %{public}d.", sceneSession->GetPersistentId()); + TLOGE(WmsLogTag::WMS_LIFE, "session cannot be clear, Id %{public}d.", sceneSession->GetPersistentId()); return WSError::WS_ERROR_INVALID_SESSION; } const WSError errCode = sceneSession->Clear(); @@ -9426,9 +9426,9 @@ WSError SceneSessionManager::ClearSession(sptr sceneSession) WSError SceneSessionManager::ClearAllSessions() { - WLOGFD("in"); + TLOGD(WmsLogTag::WMS_LIFE, "in"); if (!SessionPermission::JudgeCallerIsAllowedToUseSystemAPI()) { - WLOGFE("The caller is not system-app, can not use system-api"); + TLOGE(WmsLogTag::WMS_LIFE, "The caller is not system-app, can not use system-api"); return WSError::WS_ERROR_NOT_SYSTEM_APP; } if (!SessionPermission::VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGE_MISSION)) { @@ -9443,13 +9443,13 @@ WSError SceneSessionManager::ClearAllSessions() } return WSError::WS_OK; }; - taskScheduler_->PostAsyncTask(task, "ClearAllSessions"); + taskScheduler_->PostAsyncTask(task, __func__); return WSError::WS_OK; } void SceneSessionManager::GetAllClearableSessions(std::vector>& sessionVector) { - WLOGFD("in"); + TLOGD(WmsLogTag::WMS_LIFE, "in"); std::shared_lock lock(sceneSessionMapMutex_); for (const auto &item : sceneSessionMap_) { auto sceneSession = item.second; @@ -9542,28 +9542,28 @@ WSError SceneSessionManager::MoveSessionsToBackground(const std::vector bool SceneSessionManager::IsSessionClearable(sptr sceneSession) { if (sceneSession == nullptr) { - WLOGFI("sceneSession is nullptr"); + TLOGI(WmsLogTag::WMS_MAIN, "sceneSession is nullptr"); return false; } SessionInfo sessionInfo = sceneSession->GetSessionInfo(); if (sessionInfo.abilityInfo == nullptr) { - WLOGFI("sceneSession abilityInfo is nullptr"); + TLOGI(WmsLogTag::WMS_MAIN, "sceneSession abilityInfo is nullptr"); return false; } if (sessionInfo.abilityInfo->excludeFromMissions && !sceneSession->IsAnco()) { - WLOGFI("persistentId %{public}d is excludeFromMissions", sceneSession->GetPersistentId()); + TLOGI(WmsLogTag::WMS_MAIN, "persistentId %{public}d is excludeFromMissions", sceneSession->GetPersistentId()); return false; } if (sessionInfo.abilityInfo->unclearableMission) { - WLOGFI("persistentId %{public}d is unclearable", sceneSession->GetPersistentId()); + TLOGI(WmsLogTag::WMS_MAIN, "persistentId %{public}d is unclearable", sceneSession->GetPersistentId()); return false; } if (sessionInfo.isSystem_) { - WLOGFI("persistentId %{public}d is system app", sceneSession->GetPersistentId()); + TLOGI(WmsLogTag::WMS_MAIN, "persistentId %{public}d is system app", sceneSession->GetPersistentId()); return false; } if (sessionInfo.lockedState) { - WLOGFI("persistentId %{public}d is in lockedState", sceneSession->GetPersistentId()); + TLOGI(WmsLogTag::WMS_MAIN, "persistentId %{public}d is in lockedState", sceneSession->GetPersistentId()); return false; } @@ -9630,7 +9630,7 @@ WSError SceneSessionManager::UnregisterIAbilityManagerCollaborator(int32_t type) void SceneSessionManager::ClearAllCollaboratorSessions() { - TLOGI(WmsLogTag::DEFAULT, "run"); + TLOGI(WmsLogTag::WMS_MAIN, "in"); std::vector> collaboratorSessions; { std::shared_lock lock(sceneSessionMapMutex_); @@ -9648,7 +9648,7 @@ void SceneSessionManager::ClearAllCollaboratorSessions() bool SceneSessionManager::CheckCollaboratorType(int32_t type) { if (type != CollaboratorType::RESERVE_TYPE && type != CollaboratorType::OTHERS_TYPE) { - WLOGFD("type is invalid"); + TLOGD(WmsLogTag::WMS_MAIN, "type is invalid"); return false; } return true; diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index 1b40f318a1..8e9cc12e65 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -3778,35 +3778,35 @@ WSError WindowSceneSessionImpl::NotifyCompatibleModeEnableInPad(bool enable) void WindowSceneSessionImpl::NotifySessionForeground(uint32_t reason, bool withAnimation) { TLOGI(WmsLogTag::WMS_LIFE, "in"); - if (handler_) { - handler_->PostTask([weakThis = wptr(this), reason, withAnimation] { - auto window = weakThis.promote(); - if (!window) { - TLOGNE(WmsLogTag::WMS_LIFE, "window is nullptr"); - return; - } - window->Show(reason, withAnimation); - }, __func__); + if (!handler_) { + TLOGE(WmsLogTag::WMS_LIFE, "handler is nullptr"); return; } - Show(reason, withAnimation); + handler_->PostTask([weakThis = wptr(this), reason, withAnimation] { + auto window = weakThis.promote(); + if (!window) { + TLOGNE(WmsLogTag::WMS_LIFE, "window is nullptr"); + return; + } + window->Show(reason, withAnimation); + }, __func__); } void WindowSceneSessionImpl::NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits) { TLOGI(WmsLogTag::WMS_LIFE, "in"); - if (handler_) { - handler_->PostTask([weakThis = wptr(this), reason, withAnimation, isFromInnerkits] { - auto window = weakThis.promote(); - if (!window) { - TLOGNE(WmsLogTag::WMS_LIFE, "window is nullptr"); - return; - } - window->Hide(reason, withAnimation, isFromInnerkits); - }, __func__); + if (!handler_) { + TLOGE(WmsLogTag::WMS_LIFE, "handler is nullptr"); return; } - Hide(reason, withAnimation, isFromInnerkits); + handler_->PostTask([weakThis = wptr(this), reason, withAnimation, isFromInnerkits] { + auto window = weakThis.promote(); + if (!window) { + TLOGNE(WmsLogTag::WMS_LIFE, "window is nullptr"); + return; + } + window->Hide(reason, withAnimation, isFromInnerkits); + }, __func__); } WMError WindowSceneSessionImpl::NotifyPrepareClosePiPWindow() -- Gitee