From e2b4ae1cfd251d672976dbb525edb2f994afa71f Mon Sep 17 00:00:00 2001 From: xiongyonglong Date: Tue, 30 Apr 2024 17:30:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9BSCB=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E4=B8=BB=E7=AA=97=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E8=8E=B7=E7=84=A6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiongyonglong --- .../js_root_scene_session.cpp | 3 ++ .../js_scene_session.cpp | 32 +++++++++++++------ .../scene_session_manager/js_scene_session.h | 1 + .../scene_session_manager/js_scene_utils.cpp | 2 ++ window_scene/session/host/include/session.h | 3 ++ window_scene/session/host/src/session.cpp | 23 +++++++++++++ .../src/scene_session_manager.cpp | 24 +++++++++++++- 7 files changed, 78 insertions(+), 10 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp index 5dd827dda..e18131ac4 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_root_scene_session.cpp @@ -271,6 +271,9 @@ void JsRootSceneSession::PendingSessionActivation(SessionInfo& info) info.callerPersistentId_ = 0; } + auto focusedOnShow = info.want->GetBoolParam(AAFwk::Want::PARAM_RESV_WINDOW_FOCUSED, true); + sceneSession->SetFocusedOnShow(focusedOnShow); + std::string continueSessionId = info.want->GetStringParam(Rosen::PARAM_KEY::PARAM_DMS_CONTINUE_SESSION_ID_KEY); if (!continueSessionId.empty()) { info.continueSessionId_ = continueSessionId; diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index 75d9c4588..1571c8e0a 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -1759,23 +1759,19 @@ void JsSceneSession::ChangeSessionVisibilityWithStatusBarInner(std::shared_ptrGetNapiValue(), ArraySize(argv), argv, nullptr); } -void JsSceneSession::PendingSessionActivation(SessionInfo& info) +sptr JsSceneSession::GenSceneSession(SessionInfo& info) { - TLOGI(WmsLogTag::WMS_LIFE, "[NAPI]bundleName %{public}s, moduleName %{public}s, abilityName %{public}s, \ - appIndex %{public}d, reuse %{public}d", info.bundleName_.c_str(), info.moduleName_.c_str(), - info.abilityName_.c_str(), info.appIndex_, info.reuse); sptr sceneSession = nullptr; if (info.persistentId_ == 0) { auto result = SceneSessionManager::GetInstance().CheckIfReuseSession(info); if (result == BrokerStates::BROKER_NOT_START) { TLOGE(WmsLogTag::WMS_LIFE, "[NAPI]BrokerStates not started"); - return; + return nullptr; } if (info.reuse) { TLOGI(WmsLogTag::WMS_LIFE, "session need to be reusesd."); if (SceneSessionManager::GetInstance().CheckCollaboratorType(info.collaboratorType_)) { - sceneSession = SceneSessionManager::GetInstance().FindSessionByAffinity( - info.sessionAffinity); + sceneSession = SceneSessionManager::GetInstance().FindSessionByAffinity(info.sessionAffinity); } else { sceneSession = SceneSessionManager::GetInstance().GetSceneSessionByName( info.bundleName_, info.moduleName_, info.abilityName_, info.appIndex_); @@ -1786,7 +1782,7 @@ void JsSceneSession::PendingSessionActivation(SessionInfo& info) sceneSession = SceneSessionManager::GetInstance().RequestSceneSession(info); if (sceneSession == nullptr) { TLOGE(WmsLogTag::WMS_LIFE, "RequestSceneSession return nullptr"); - return; + return nullptr; } } else { sceneSession->SetSessionInfo(info); @@ -1800,7 +1796,7 @@ void JsSceneSession::PendingSessionActivation(SessionInfo& info) sceneSession = SceneSessionManager::GetInstance().RequestSceneSession(info); if (sceneSession == nullptr) { TLOGE(WmsLogTag::WMS_LIFE, "retry RequestSceneSession return nullptr"); - return; + return nullptr; } info.persistentId_ = sceneSession->GetPersistentId(); sceneSession->SetSessionInfoPersistentId(sceneSession->GetPersistentId()); @@ -1808,6 +1804,24 @@ void JsSceneSession::PendingSessionActivation(SessionInfo& info) sceneSession->SetSessionInfo(info); } } + return sceneSession; +} + +void JsSceneSession::PendingSessionActivation(SessionInfo& info) +{ + TLOGI(WmsLogTag::WMS_LIFE, "[NAPI]bundleName %{public}s, moduleName %{public}s, abilityName %{public}s, \ + appIndex %{public}d, reuse %{public}d", info.bundleName_.c_str(), info.moduleName_.c_str(), + info.abilityName_.c_str(), info.appIndex_, info.reuse); + auto sceneSession = GenSceneSession(info); + if (sceneSession == nullptr) { + TLOGE(WmsLogTag::WMS_LIFE, "GenSceneSession failed"); + return; + } + + if (info.want != nullptr) { + auto focusedOnShow = info.want->GetBoolParam(AAFwk::Want::PARAM_RESV_WINDOW_FOCUSED, true); + sceneSession->SetFocusedOnShow(focusedOnShow); + } std::shared_ptr sessionInfo = std::make_shared(info); auto task = [this, sessionInfo]() { PendingSessionActivationInner(sessionInfo); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h index b3b26bfaa..4f4b264b6 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h @@ -126,6 +126,7 @@ private: void ChangeSessionVisibilityWithStatusBar(SessionInfo& info, bool visible); void ChangeSessionVisibilityWithStatusBarInner(std::shared_ptr sessionInfo, bool visible); + sptr GenSceneSession(SessionInfo& info); void PendingSessionActivation(SessionInfo& info); void PendingSessionActivationInner(std::shared_ptr sessionInfo); void OnSessionStateChange(const SessionState& state); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp index 155da8fea..36f8a38ce 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp @@ -775,6 +775,8 @@ void SetJsSessionInfoByWant(napi_env env, const SessionInfo& sessionInfo, napi_v sessionInfo.want->GetIntParam(AAFwk::Want::PARAM_RESV_WINDOW_HEIGHT, INVALID_VAL))); napi_set_named_property(env, objValue, "withAnimation", CreateJsValue(env, sessionInfo.want->GetBoolParam(AAFwk::Want::PARAM_RESV_WITH_ANIMATION, true))); + napi_set_named_property(env, objValue, "focusedOnShow", + CreateJsValue(env, sessionInfo.want->GetBoolParam(AAFwk::Want::PARAM_RESV_WINDOW_FOCUSED, true))); } } diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index c6e744df4..9499f6efd 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -192,6 +192,8 @@ public: WindowType GetWindowType() const; float GetAspectRatio() const; WSError SetAspectRatio(float ratio) override; + void SetFocusedOnShow(bool focusedOnShow); + bool IsFocusedOnShow() const; WSError SetSessionProperty(const sptr& property) override; sptr GetSessionProperty() const; void SetSessionRect(const WSRect& rect); @@ -577,6 +579,7 @@ private: mutable std::shared_mutex uiRequestFocusMutex_; mutable std::shared_mutex uiLostFocusMutex_; + bool focusedOnShow_ = true; bool showRecent_ = false; bool bufferAvailable_ = false; WSRect preRect_; diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 17e6850e6..aea2f0e5f 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -89,6 +89,12 @@ Session::Session(const SessionInfo& info) : sessionInfo_(info) WLOGFE("Failed to insert area:%{public}d", area); } } + + if (info.want != nullptr) { + auto focusedOnShow = info.want->GetBoolParam(AAFwk::Want::PARAM_RESV_WINDOW_FOCUSED, true); + TLOGI(WmsLogTag::WMS_FOCUS, "focusedOnShow:%{public}d", focusedOnShow); + SetFocusedOnShow(focusedOnShow); + } } void Session::SetEventHandler(const std::shared_ptr& handler, @@ -480,6 +486,21 @@ WSError Session::SetTouchable(bool touchable) return WSError::WS_OK; } +void Session::SetFocusedOnShow(bool focusedOnShow) +{ + if (focusedOnShow == focusedOnShow_) { + return; + } + TLOGI(WmsLogTag::WMS_FOCUS, "SetFocusedOnShow:%{public}d", focusedOnShow); + focusedOnShow_ = focusedOnShow; +} + +bool Session::IsFocusedOnShow() const +{ + TLOGD(WmsLogTag::WMS_FOCUS, "IsFocusedOnShow:%{public}d", focusedOnShow_); + return focusedOnShow_; +} + bool Session::GetTouchable() const { return GetSessionProperty()->GetTouchable(); @@ -1518,6 +1539,7 @@ WSError Session::RaiseToAppTopForPointDown() void Session::PresentFocusIfPointDown() { WLOGFI("PresentFocusIfPointDown, id: %{public}d, type: %{public}d", GetPersistentId(), GetWindowType()); + SetFocusedOnShow(true); if (!isFocused_ && GetFocusable()) { NotifyRequestFocusStatusNotifyManager(true, false); } @@ -1936,6 +1958,7 @@ void Session::PresentFoucusIfNeed(int32_t pointerAction) WLOGFD("OnClick down, id: %{public}d", GetPersistentId()); if (pointerAction == MMI::PointerEvent::POINTER_ACTION_DOWN || pointerAction == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN) { + SetFocusedOnShow(true); if (!isFocused_ && GetFocusable()) { NotifyRequestFocusStatusNotifyManager(true, false); } diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index c7ed329f3..153719a02 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -1566,7 +1566,7 @@ WSError SceneSessionManager::RequestSceneSessionActivationInner( { auto persistentId = scnSession->GetPersistentId(); RequestInputMethodCloseKeyboard(persistentId); - if (WindowHelper::IsMainWindow(scnSession->GetWindowType())) { + if (WindowHelper::IsMainWindow(scnSession->GetWindowType()) && scnSession->IsFocusedOnShow()) { RequestSessionFocusImmediately(persistentId); } if (scnSession->GetSessionInfo().ancoSceneState < AncoSceneState::NOTIFY_CREATE) { @@ -4054,6 +4054,16 @@ WSError SceneSessionManager::RequestSessionFocusImmediately(int32_t persistentId TLOGD(WmsLogTag::WMS_FOCUS, "session is not focusable!"); return WSError::WS_DO_NOTHING; } + if (!sceneSession->IsFocusedOnShow()) { + TLOGD(WmsLogTag::WMS_FOCUS, "session is not focused on show!"); + return WSError::WS_DO_NOTHING; + } + auto parentSession = GetSceneSession(sceneSession->GetParentPersistentId()); + while (parentSession != nullptr) { + parentSession->SetFocusedOnShow(true); + parentSession = GetSceneSession(parentSession->GetParentPersistentId()); + } + // specific block WSError specificCheckRet = RequestFocusSpecificCheck(sceneSession, true); if (specificCheckRet != WSError::WS_OK) { @@ -4085,6 +4095,16 @@ WSError SceneSessionManager::RequestSessionFocus(int32_t persistentId, bool byFo TLOGD(WmsLogTag::WMS_FOCUS, "session is not focusable or not visible!"); return WSError::WS_DO_NOTHING; } + if (!sceneSession->IsFocusedOnShow()) { + TLOGD(WmsLogTag::WMS_FOCUS, "session is not focused on show!"); + return WSError::WS_DO_NOTHING; + } + auto parentSession = GetSceneSession(sceneSession->GetParentPersistentId()); + while (parentSession != nullptr) { + parentSession->SetFocusedOnShow(true); + parentSession = GetSceneSession(parentSession->GetParentPersistentId()); + } + // subwindow/dialog state block if ((WindowHelper::IsSubWindow(sceneSession->GetWindowType()) || sceneSession->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) && @@ -4732,6 +4752,8 @@ __attribute__((no_sanitize("cfi"))) void SceneSessionManager::OnSessionStateChan needBlockNotifyFocusStatusUntilForeground_ = false; NotifyFocusStatus(sceneSession, true); } + } else if (!sceneSession->IsFocusedOnShow()) { + sceneSession->SetFocusedOnShow(true); } else { RequestSessionFocus(persistentId, true, FocusChangeReason::APP_FOREGROUND); } -- Gitee