From 4163b6a017b5c3c5244797caaa06abfa81934f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Wed, 15 Jan 2025 17:41:19 +0800 Subject: [PATCH 01/45] =?UTF-8?q?=E5=A4=9A=E5=B1=8F=E5=A4=9A=E7=84=A6?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- interfaces/innerkits/wm/window_manager.h | 2 +- interfaces/innerkits/wm/window_manager_lite.h | 2 +- interfaces/innerkits/wm/wm_common.h | 3 +- .../js_scene_session_manager.cpp | 23 +- .../js_scene_session_manager.h | 4 +- .../include/screen_session_manager_client.h | 8 + .../src/screen_session_manager_client.cpp | 20 + window_scene/session/host/src/session.cpp | 1 - window_scene/session_manager/BUILD.gn | 1 + .../include/scene_session_manager.h | 39 +- .../include/scene_session_manager_lite.h | 6 +- .../include/window_focus_controller.h | 146 ++++++ .../zidl/scene_session_manager_interface.h | 7 +- .../scene_session_manager_lite_interface.h | 7 +- .../zidl/scene_session_manager_lite_proxy.h | 10 +- .../zidl/scene_session_manager_proxy.h | 6 +- .../src/scene_session_manager.cpp | 440 ++++++++++++------ .../src/scene_session_manager_lite.cpp | 12 +- .../src/window_focus_controller.cpp | 165 +++++++ .../zidl/scene_session_manager_lite_proxy.cpp | 22 +- .../zidl/scene_session_manager_lite_stub.cpp | 21 +- .../src/zidl/scene_session_manager_proxy.cpp | 20 +- .../src/zidl/scene_session_manager_stub.cpp | 21 +- .../unittest/intention_event_manager_test.cpp | 10 +- .../unittest/scene_input_manager_test.cpp | 14 +- .../unittest/scene_session_manager_test10.cpp | 16 +- .../unittest/scene_session_manager_test3.cpp | 35 +- .../unittest/scene_session_manager_test4.cpp | 23 +- .../unittest/scene_session_manager_test5.cpp | 120 +++-- .../unittest/scene_session_manager_test8.cpp | 6 +- .../unittest/scene_session_manager_test9.cpp | 19 +- wm/include/window_adapter.h | 2 +- wm/include/window_adapter_lite.h | 2 +- wm/src/window_adapter.cpp | 8 +- wm/src/window_adapter_lite.cpp | 8 +- wm/src/window_manager.cpp | 4 +- wm/src/window_manager_lite.cpp | 4 +- .../include/zidl/window_manager_interface.h | 2 +- .../zidl/window_manager_lite_interface.h | 2 +- wmserver/include/zidl/window_manager_proxy.h | 2 +- wmserver/src/zidl/window_manager_proxy.cpp | 11 +- wmserver/src/zidl/window_manager_stub.cpp | 7 +- 42 files changed, 963 insertions(+), 318 deletions(-) create mode 100644 window_scene/session_manager/include/window_focus_controller.h create mode 100644 window_scene/session_manager/src/window_focus_controller.cpp diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index 7178dc237d..0ae0550a97 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -760,7 +760,7 @@ public: * @param focusInfo Focus window info. * @return FocusChangeInfo object about focus window. */ - void GetFocusWindowInfo(FocusChangeInfo& focusInfo); + void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID); /** * @brief Dump all session info diff --git a/interfaces/innerkits/wm/window_manager_lite.h b/interfaces/innerkits/wm/window_manager_lite.h index 9f47ad185e..14c7c6b40e 100644 --- a/interfaces/innerkits/wm/window_manager_lite.h +++ b/interfaces/innerkits/wm/window_manager_lite.h @@ -87,7 +87,7 @@ public: * @param focusInfo Focus window info. * @return FocusChangeInfo object about focus window. */ - void GetFocusWindowInfo(FocusChangeInfo& focusInfo); + void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID); /** * @brief Register drawingcontent changed listener. diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 4872bd2541..4aba95425f 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -46,6 +46,7 @@ constexpr uint32_t MIN_CLOSE_BUTTON_RIGHT_MARGIN = 8; constexpr uint32_t MAX_CLOSE_BUTTON_RIGHT_MARGIN = 22; } using DisplayId = uint64_t; +constexpr DisplayId DEFAULT_DISPLAY_ID = 0; /** * @brief Enumerates type of window. */ @@ -1253,7 +1254,7 @@ struct WindowLayoutInfo : public Parcelable { return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) && parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_); } - + static WindowLayoutInfo* Unmarshalling(Parcel& parcel) { WindowLayoutInfo* windowLayoutInfo = new WindowLayoutInfo; diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 4023247865..a0830dfb85 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -449,16 +449,17 @@ void JsSceneSessionManager::OnOutsideDownEvent(int32_t x, int32_t y) taskScheduler_->PostMainThreadTask(task, info); } -void JsSceneSessionManager::OnShiftFocus(int32_t persistentId) +void JsSceneSessionManager::OnShiftFocus(int32_t persistentId, DisplayId displayGroupId) { - TLOGD(WmsLogTag::WMS_FOCUS, "[NAPI]"); + TLOGD(WmsLogTag::WMS_FOCUS, "persistentId: %{public}d, displayGroupId: %{public}lu", persistentId, displayGroupId); - auto task = [this, persistentId, jsCallBack = GetJSCallback(SHIFT_FOCUS_CB), env = env_]() { + auto task = [this, persistentId, jsCallBack = GetJSCallback(SHIFT_FOCUS_CB), env = env_, displayGroupId]() { if (jsCallBack == nullptr) { TLOGNE(WmsLogTag::WMS_FOCUS, "jsCallBack is nullptr"); return; } - napi_value argv[] = {CreateJsValue(env, persistentId)}; + napi_value argv[] = { CreateJsValue(env, persistentId), + CreateJsValue(env, static_cast(displayGroupId)) }; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }; taskScheduler_->PostMainThreadTask(task, "OnShiftFocus, PID:" + std::to_string(persistentId)); @@ -570,9 +571,9 @@ void JsSceneSessionManager::ProcessOutsideDownEvent() void JsSceneSessionManager::ProcessShiftFocus() { - ProcessShiftFocusFunc func = [this](int32_t persistentId) { + ProcessShiftFocusFunc func = [this](int32_t persistentId, DisplayId displayGroupId) { TLOGND(WmsLogTag::WMS_FOCUS, "ProcessShiftFocus called"); - this->OnShiftFocus(persistentId); + this->OnShiftFocus(persistentId, displayGroupId); }; NotifySCBAfterUpdateFocusFunc focusedCallback = [this]() { TLOGND(WmsLogTag::WMS_FOCUS, "scb uicontent focus"); @@ -1433,7 +1434,7 @@ static napi_value CreateWindowModes(napi_env env, } return arrayValue; } - + static napi_value CreateWindowSize(napi_env env, const AppExecFwk::AbilityInfo& abilityInfo) { napi_value objValue = nullptr; @@ -1450,7 +1451,7 @@ static napi_value CreateWindowSize(napi_env env, const AppExecFwk::AbilityInfo& napi_set_named_property(env, objValue, "minWindowHeight", CreateJsValue(env, abilityInfo.minWindowHeight)); return objValue; } - + static napi_value CreateAbilityItemInfo(napi_env env, const AppExecFwk::AbilityInfo& abilityInfo) { napi_value objValue = nullptr; @@ -1479,7 +1480,7 @@ static napi_value CreateAbilityItemInfo(napi_env env, const AppExecFwk::AbilityI CreateJsValue(env, abilityInfo.preferMultiWindowOrientation)); return objValue; } - + static napi_value CreateSCBAbilityInfo(napi_env env, const SCBAbilityInfo& scbAbilityInfo) { napi_value objValue = nullptr; @@ -1493,7 +1494,7 @@ static napi_value CreateSCBAbilityInfo(napi_env env, const SCBAbilityInfo& scbAb napi_set_named_property(env, objValue, "codePath", CreateJsValue(env, scbAbilityInfo.codePath_)); return objValue; } - + static napi_value CreateAbilityInfos(napi_env env, const std::vector& scbAbilityInfos) { napi_value arrayValue = nullptr; @@ -3627,7 +3628,7 @@ napi_value JsSceneSessionManager::OnNotifyAboveLockScreen(napi_env env, napi_cal "Input parameter is missing or invalid")); return NapiGetUndefined(env); } - + std::vector windowIds; if (!ConvertInt32ArrayFromJs(env, argv[0], windowIds)) { TLOGE(WmsLogTag::WMS_UIEXT, "Failed to convert windowIds"); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h index ded1b66e93..4afdcba243 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h @@ -130,7 +130,7 @@ public: static napi_value GetInstanceCount(napi_env env, napi_callback_info info); static napi_value GetLastInstanceKey(napi_env env, napi_callback_info info); static napi_value RefreshAppInfo(napi_env env, napi_callback_info info); - + /* * Window Immersive */ @@ -243,7 +243,7 @@ private: void OnCreateKeyboardSession(const sptr& keyboardSession, const sptr& panelSession); void OnOutsideDownEvent(int32_t x, int32_t y); void OnStartUIAbilityError(const uint32_t errorCode); - void OnShiftFocus(int32_t persistentId); + void OnShiftFocus(int32_t persistentId, DisplayId displayGroupId); void OnCallingSessionIdChange(uint32_t callingSessionId); void ProcessCreateSystemSessionRegister(); void ProcessCreateKeyboardSessionRegister(); diff --git a/window_scene/screen_session_manager_client/include/screen_session_manager_client.h b/window_scene/screen_session_manager_client/include/screen_session_manager_client.h index a684744441..44bd870901 100644 --- a/window_scene/screen_session_manager_client/include/screen_session_manager_client.h +++ b/window_scene/screen_session_manager_client/include/screen_session_manager_client.h @@ -39,12 +39,19 @@ public: virtual void OnScreenDisconnected(const sptr& screenSession) = 0; }; +class IScreenConnectionChangeListener : public RefBase { +public: + virtual void OnScreenConnected(const sptr& screenSession) = 0; + virtual void OnScreenDisconnected(const sptr& screenSession) = 0; +}; + class ScreenSessionManagerClient : public ScreenSessionManagerClientStub { WM_DECLARE_SINGLE_INSTANCE_BASE(ScreenSessionManagerClient) public: void RegisterScreenConnectionListener(IScreenConnectionListener* listener); void RegisterDisplayChangeListener(const sptr& listener); + void RegisterScreenConnectionChangeListener(const sptr& listener); sptr GetScreenSession(ScreenId screenId) const; std::map GetAllScreensProperties() const; @@ -119,6 +126,7 @@ private: sptr screenSessionManager_; IScreenConnectionListener* screenConnectionListener_; + sptr screenConnectionChangeListener_; sptr displayChangeListener_; FoldDisplayMode displayMode_ = FoldDisplayMode::UNKNOWN; }; diff --git a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp index c9fd22e73b..a6ab42f808 100644 --- a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp +++ b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp @@ -78,6 +78,18 @@ void ScreenSessionManagerClient::RegisterScreenConnectionListener(IScreenConnect WLOGFI("Success to register screen connection listener"); } +void ScreenSessionManagerClient::RegisterScreenConnectionChangeListener( + const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("Failed to register screen connection change listener, listener is null"); + return; + } + + screenConnectionChangeListener_ = listener; + WLOGFI("Success to register screen connection change listener"); +} + bool ScreenSessionManagerClient::CheckIfNeedConnectScreen(ScreenId screenId, ScreenId rsId, const std::string& name) { if (rsId == SCREEN_ID_INVALID) { @@ -130,6 +142,11 @@ void ScreenSessionManagerClient::OnScreenConnectionChanged(ScreenId screenId, Sc screenId, config.property.GetDensity()); screenSession->SetScreenSceneDpi(config.property.GetDensity()); } + if (screenConnectionChangeListener_) { + screenConnectionChangeListener_->OnScreenConnected(screenSession); + WLOGFI("screenConnectionChangeListener screenId: %{public}" PRIu64 " density: %{public}f ", + screenId, config.property.GetDensity()); + } screenSession->Connect(); return; } @@ -143,6 +160,9 @@ void ScreenSessionManagerClient::OnScreenConnectionChanged(ScreenId screenId, Sc if (screenConnectionListener_) { screenConnectionListener_->OnScreenDisconnected(screenSession); } + if (screenConnectionChangeListener_) { + screenConnectionChangeListener_->OnScreenDisconnected(screenSession); + } { std::lock_guard lock(screenSessionMapMutex_); screenSessionMap_.erase(screenId); diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 1e2d2e04f1..c92829fec1 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -51,7 +51,6 @@ constexpr uint32_t MAX_LIFE_CYCLE_TASK_IN_QUEUE = 15; constexpr int64_t LIFE_CYCLE_TASK_EXPIRED_TIME_LIMIT = 350; static bool g_enableForceUIFirst = system::GetParameter("window.forceUIFirst.enabled", "1") == "1"; constexpr int64_t STATE_DETECT_DELAYTIME = 3 * 1000; -constexpr DisplayId DEFAULT_DISPLAY_ID = 0; constexpr DisplayId VIRTUAL_DISPLAY_ID = 999; constexpr int32_t SUPER_FOLD_DIVIDE_FACTOR = 2; const std::map ATTACH_MAP = { diff --git a/window_scene/session_manager/BUILD.gn b/window_scene/session_manager/BUILD.gn index a118e47298..6a5f6d3b53 100644 --- a/window_scene/session_manager/BUILD.gn +++ b/window_scene/session_manager/BUILD.gn @@ -76,6 +76,7 @@ ohos_shared_library("scene_session_manager") { "src/scene_system_ability_listener.cpp", "src/session_listener_controller.cpp", "src/session_manager_agent_controller.cpp", + "src/window_focus_controller.cpp", "src/window_scene_config.cpp", "src/zidl/scene_session_manager_lite_stub.cpp", "src/zidl/scene_session_manager_stub.cpp", diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index ab6502aa5d..0c2dcb3c41 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -45,12 +45,14 @@ #include "display_info.h" #include "display_change_info.h" #include "display_change_listener.h" +#include "screen_session_manager_client.h" #include "app_debug_listener_interface.h" #include "app_mgr_client.h" #include "include/core/SkRegion.h" #include "ability_info.h" #include "screen_fold_data.h" #include "thread_safety_annotations.h" +#include "window_focus_controller.h" namespace OHOS::AAFwk { class SessionInfo; @@ -107,7 +109,7 @@ using ProcessStatusBarEnabledChangeFunc = std::function; using ProcessOutsideDownEventFunc = std::function; -using ProcessShiftFocusFunc = std::function; +using ProcessShiftFocusFunc = std::function; using NotifySetFocusSessionFunc = std::function& session)>; using DumpRootSceneElementInfoFunc = std::function& params, std::vector& infos)>; @@ -156,6 +158,12 @@ public: void OnScreenFoldStatusChanged(const std::vector& screenFoldInfo) override; }; +class ScreenConnectionChangeListener : public IScreenConnectionChangeListener { +public: + void OnScreenConnected(const sptr& screenSession) override; + void OnScreenDisconnected(const sptr& screenSession) override; +}; + class SceneSessionManager : public SceneSessionManagerStub { WM_DECLARE_SINGLE_INSTANCE_BASE(SceneSessionManager) public: @@ -253,8 +261,8 @@ public: /* * Window Focus */ - WSError SetFocusedSessionId(int32_t persistentId); - int32_t GetFocusedSessionId() const; + WSError SetFocusedSessionId(int32_t persistentId, DisplayId displayId); + int32_t GetFocusedSessionId(DisplayId displayId = DEFAULT_DISPLAY_ID) const; FocusChangeReason GetFocusChangeReason() const { return focusChangeReason_; } WMError RequestFocusStatus(int32_t persistentId, bool isFocused, bool byForeground = true, FocusChangeReason reason = FocusChangeReason::DEFAULT) override; @@ -263,9 +271,11 @@ public: void RequestAllAppSessionUnfocus(); WSError UpdateFocus(int32_t persistentId, bool isFocused); WSError ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId) override; - void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; - WSError GetFocusSessionToken(sptr& token) override; - WSError GetFocusSessionElement(AppExecFwk::ElementName& element) override; + void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override; + WSError GetFocusSessionToken(sptr& token, DisplayId displayId = DEFAULT_DISPLAY_ID) override; + WSError GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId = DEFAULT_DISPLAY_ID) override; + WSError AddFocusGroup(DisplayId displayId); + WSError RemoveFocusGroup(DisplayId displayId); WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode); WSError SendTouchEvent(const std::shared_ptr& pointerEvent, uint32_t zIndex); @@ -690,9 +700,9 @@ private: WSError RequestSessionFocusImmediately(int32_t persistentId); WSError RequestSessionUnfocus(int32_t persistentId, FocusChangeReason reason = FocusChangeReason::DEFAULT); WSError RequestAllAppSessionUnfocusInner(); - WSError RequestFocusBasicCheck(int32_t persistentId); + WSError RequestFocusBasicCheck(int32_t persistentId, sptr& focusGroup); bool CheckLastFocusedAppSessionFocus(sptr& focusedSession, sptr& nextSession); - WSError RequestFocusSpecificCheck(sptr& sceneSession, bool byForeground, + WSError RequestFocusSpecificCheck(DisplayId displayId, sptr& sceneSession, bool byForeground, FocusChangeReason reason = FocusChangeReason::DEFAULT); bool CheckTopmostWindowFocus(sptr& focusedSession, sptr& sceneSession); bool CheckRequestFocusImmdediately(sptr& sceneSession); @@ -701,12 +711,14 @@ private: bool CheckClickFocusIsDownThroughFullScreen(const sptr& focusedSession, const sptr& sceneSession, FocusChangeReason reason); bool IsParentSessionVisible(const sptr& session); - sptr GetNextFocusableSession(int32_t persistentId); - sptr GetTopNearestBlockingFocusSession(uint32_t zOrder, bool includingAppSession); + sptr GetNextFocusableSession(DisplayId displayId, int32_t persistentId); + sptr GetTopNearestBlockingFocusSession(DisplayId displayId, uint32_t zOrder, + bool includingAppSession); sptr GetTopFocusableNonAppSession(); - WSError ShiftFocus(sptr& nextSession, FocusChangeReason reason = FocusChangeReason::DEFAULT); - void UpdateFocusStatus(sptr& sceneSession, bool isFocused); - void NotifyFocusStatus(sptr& sceneSession, bool isFocused); + WSError ShiftFocus(DisplayId displayId, sptr& nextSession, + FocusChangeReason reason = FocusChangeReason::DEFAULT); + void UpdateFocusStatus(DisplayId displayId, sptr& sceneSession, bool isFocused); + void NotifyFocusStatus(sptr& sceneSession, bool isFocused, sptr& focusGroup); int32_t NotifyRssThawApp(const int32_t uid, const std::string& bundleName, const std::string& reason); void NotifyFocusStatusByMission(sptr& prevSession, sptr& currSession); @@ -945,6 +957,7 @@ private: int32_t focusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID; + std::shared_ptr windowFocusController_; int32_t brightnessSessionId_ = INVALID_SESSION_ID; float displayBrightness_ = UNDEFINED_BRIGHTNESS; bool isScreenLocked_ {false}; diff --git a/window_scene/session_manager/include/scene_session_manager_lite.h b/window_scene/session_manager/include/scene_session_manager_lite.h index 398531c019..a17bd28037 100644 --- a/window_scene/session_manager/include/scene_session_manager_lite.h +++ b/window_scene/session_manager/include/scene_session_manager_lite.h @@ -30,8 +30,8 @@ public: WSError PendingSessionToForeground(const sptr& token) override; WSError PendingSessionToBackgroundForDelegator(const sptr& token, bool shouldBackToCaller = true) override; - WSError GetFocusSessionToken(sptr& token) override; - WSError GetFocusSessionElement(AppExecFwk::ElementName& element) override; + WSError GetFocusSessionToken(sptr& token, DisplayId displayId = DEFAULT_DISPLAY_ID) override; + WSError GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId = DEFAULT_DISPLAY_ID) override; WSError RegisterSessionListener(const sptr& listener, bool isRecover = false) override; WSError UnRegisterSessionListener(const sptr& listener) override; WSError GetSessionInfos(const std::string& deviceId, int32_t numMax, @@ -52,7 +52,7 @@ public: WSError MoveSessionsToForeground(const std::vector& sessionIds, int32_t topSessionId) override; WSError MoveSessionsToBackground(const std::vector& sessionIds, std::vector& result) override; - void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; + void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override; WMError RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) override; WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h new file mode 100644 index 0000000000..758e47cadb --- /dev/null +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_FOCUS_CONTROLLER_H +#define OHOS_ROSEN_WINDOW_FOCUS_CONTROLLER_H + +#include +#include +#include +#include + +#include "dm_common.h" +#include "wm_common.h" +#include "ws_common.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { + +/** + * @struct FocusState + * + * @brief Window focus state of a screen + */ +struct FocusGroup : public RefBase +{ +private: + int32_t focusedSessionId_ = INVALID_SESSION_ID; + int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; + int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID; + bool needBlockNotifyFocusStatusUntilForeground_ = false; + bool needBlockNotifyUnfocusStatus_ = false; + DisplayId displayGroupId_ = DISPLAY_ID_INVALID; + +public: + FocusGroup(DisplayId displayGroupId) : displayGroupId_(displayGroupId) {} + WSError UpdateFocusedSessionId(int32_t persistentId) + { + TLOGI(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId_, persistentId); + if (focusedSessionId_ == persistentId) { + TLOGI(WmsLogTag::WMS_FOCUS, "Focus scene not change, id: %{public}d", focusedSessionId_); + return WSError::WS_DO_NOTHING; + } + lastFocusedSessionId_ = focusedSessionId_; + focusedSessionId_ = persistentId; + return WSError::WS_OK; + } + + WSError UpdateFocusedAppSessionId(int32_t persistentId) + { + lastFocusedAppSessionId_ = persistentId; + return WSError::WS_OK; + } + + int32_t GetFocusedSessionId() + { + return focusedSessionId_; + } + + int32_t GetLastFocusedSessionId() + { + return lastFocusedSessionId_; + } + + int32_t GetLastFocusedAppSessionId() + { + return lastFocusedAppSessionId_; + } + + bool GetNeedBlockNotifyFocusStatusUntilForeground() + { + return needBlockNotifyFocusStatusUntilForeground_; + } + + bool GetNeedBlockNotifyUnfocusStatus() + { + return needBlockNotifyUnfocusStatus_; + } + + DisplayId GetDisplayGroupId() + { + return displayGroupId_; + } + + void SetFocusedSessionId(int32_t focusedSessionId) + { + focusedSessionId_ = focusedSessionId; + } + + void SetLastFocusedSessionId(int32_t lastFocusedSessionId) + { + lastFocusedSessionId_ = lastFocusedSessionId; + } + + void SetLastFocusedAppSessionId(int32_t lastFocusedAppSessionId) + { + lastFocusedAppSessionId_ = lastFocusedAppSessionId; + } + + void SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlockNotifyFocusStatusUntilForeground) + { + needBlockNotifyFocusStatusUntilForeground_ = needBlockNotifyFocusStatusUntilForeground; + } + + void SetNeedBlockNotifyUnfocusStatus(bool needBlockNotifyUnfocusStatus) + { + needBlockNotifyUnfocusStatus_ = needBlockNotifyUnfocusStatus; + } +}; + +class WindowFocusController { +public: + WindowFocusController() noexcept; + ~WindowFocusController() = default; + + DisplayId GetDisplayGroupId(DisplayId displayId); + WSError AddFocusGroup(DisplayId displayId); + WSError RemoveFocusGroup(DisplayId displayId); + int32_t GetFocusedSessionId(DisplayId displayId); + sptr GetFocusGroup(DisplayId displayId = DEFAULT_DISPLAY_ID); + sptr GetFocusGroupInner(DisplayId displayId); + std::vector> GetAllFocusedSessionList(); + WSError UpdateFocusedSessionId(DisplayId displayId, int32_t persistentId); + WSError UpdateFocusedAppSessionId(DisplayId displayId, int32_t persistentId); + +private: + std::shared_mutex focusGroupMutex_; + std::unordered_map> focusGroupMap_; + std::unordered_set virtualScreenDisplayIdSet_; + +}; +} +} +#endif // OHOS_ROSEN_WINDOW_FOCUS_CONTROLLER_H diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h index 29b8dd9b82..f79e0b058f 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h @@ -137,8 +137,9 @@ public: 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 GetFocusSessionToken(sptr& token, DisplayId displayId = DEFAULT_DISPLAY_ID) = 0; + virtual WSError GetFocusSessionElement(AppExecFwk::ElementName& element, + DisplayId displayId = DEFAULT_DISPLAY_ID) = 0; virtual WSError RegisterSessionListener(const sptr& listener) = 0; virtual WSError UnRegisterSessionListener(const sptr& listener) = 0; @@ -277,7 +278,7 @@ public: std::vector>& targets) override { return WMError::WM_OK; } void SetMaximizeMode(MaximizeMode maximizeMode) override {} MaximizeMode GetMaximizeMode() override { return MaximizeMode::MODE_AVOID_SYSTEM_BAR; } - void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override {} + void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override {} /** * @brief Raise a window to screen top by id of window. 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 26eab6cdf5..ea9aac9c80 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 @@ -115,10 +115,11 @@ public: virtual WSError GetSessionInfoByContinueSessionId(const std::string& continueSessionId, SessionInfoBean& sessionInfo) = 0; virtual WSError SetSessionContinueState(const sptr& token, const ContinueState& continueState) = 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 GetFocusSessionToken(sptr& token, DisplayId displayId = DEFAULT_DISPLAY_ID) = 0; + virtual WSError GetFocusSessionElement(AppExecFwk::ElementName& element, + DisplayId displayId = DEFAULT_DISPLAY_ID) = 0; virtual WSError GetSessionSnapshot(const std::string& deviceId, int32_t persistentId, SessionSnapshot& snapshot, bool isLowResolution) = 0; virtual WSError LockSession(int32_t sessionId) = 0; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h index 7aa29a84b5..b6b1c25e03 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h @@ -33,8 +33,8 @@ public: WSError PendingSessionToForeground(const sptr& token) override; WSError PendingSessionToBackgroundForDelegator(const sptr& token, bool shouldBackToCaller = true) override; - WSError GetFocusSessionToken(sptr& token) override; - WSError GetFocusSessionElement(AppExecFwk::ElementName& element) override; + WSError GetFocusSessionToken(sptr& token, DisplayId displayId = DEFAULT_DISPLAY_ID) override; + WSError GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId = DEFAULT_DISPLAY_ID) override; WSError RegisterSessionListener(const sptr& listener, bool isRecover = false) override; WSError UnRegisterSessionListener(const sptr& listener) override; WSError GetSessionInfos(const std::string& deviceId, int32_t numMax, @@ -62,8 +62,8 @@ public: WSError MoveSessionsToBackground(const std::vector& sessionIds, std::vector& result) override; WSError ClearSession(int32_t persistentId) override; WSError ClearAllSessions() override; - - void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; + + void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override; WMError RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) override; WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, @@ -96,7 +96,7 @@ public: const std::string& abilityName, int32_t appIndex) override; WMError HasFloatingWindowForeground(const sptr& abilityToken, bool& hasOrNot) override; - + private: template WSError GetParcelableInfos(MessageParcel& reply, std::vector& parcelableInfos); diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h index ed54a6ca7f..7791d2d096 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h @@ -51,7 +51,7 @@ public: WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) override; WMError SetGestureNavigationEnabled(bool enable) override; - void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; + void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override; WSError SetSessionLabel(const sptr& token, const std::string& label) override; WSError SetSessionIcon(const sptr& token, const std::shared_ptr& icon) override; WSError IsValidSessionIds(const std::vector& sessionIds, std::vector& results) override; @@ -62,8 +62,8 @@ public: bool shouldBackToCaller = true) override; WMError GetSessionSnapshotById(int32_t persistentId, SessionSnapshot& snapshot) override; WMError GetSnapshotByWindowId(int32_t persistentId, std::shared_ptr& pixelMap) override; - WSError GetFocusSessionToken(sptr& token) override; - WSError GetFocusSessionElement(AppExecFwk::ElementName& element) override; + WSError GetFocusSessionToken(sptr& token, DisplayId displayId = DEFAULT_DISPLAY_ID) override; + WSError GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId = DEFAULT_DISPLAY_ID) override; WMError CheckWindowId(int32_t windowId, int32_t& pid) override; WSError RegisterSessionListener(const sptr& listener) override; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index e965d1ad3e..7c03b1dac2 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -126,7 +126,6 @@ const int32_t LOGICAL_DISPLACEMENT_32 = 32; constexpr int32_t GET_TOP_WINDOW_DELAY = 100; constexpr char SMALL_FOLD_PRODUCT_TYPE = '2'; constexpr uint32_t MAX_SUB_WINDOW_LEVEL = 10; -constexpr uint64_t DEFAULT_DISPLAY_ID = 0; constexpr uint64_t VIRTUAL_DISPLAY_ID = 999; const std::map STRING_TO_DISPLAY_ORIENTATION_MAP = { @@ -309,6 +308,7 @@ SceneSessionManager::SceneSessionManager() : rsInterface_(RSInterfaces::GetInsta scbDumpSubscriber_ = ScbDumpSubscriber::Subscribe(); listenerController_ = std::make_shared(); + windowFocusController_ = std::make_shared(); } SceneSessionManager::~SceneSessionManager() @@ -335,6 +335,8 @@ void SceneSessionManager::Init() InitPrepareTerminateConfig(); ScreenSessionManagerClient::GetInstance().RegisterDisplayChangeListener(sptr::MakeSptr()); + ScreenSessionManagerClient::GetInstance().RegisterScreenConnectionChangeListener( + sptr::MakeSptr()); // create handler for inner command at server eventLoop_ = AppExecFwk::EventRunner::Create(WINDOW_INFO_REPORT_THREAD); @@ -2466,7 +2468,9 @@ WSError SceneSessionManager::RequestSceneSessionBackground(const sptrGetSessionProperty()->GetDisplayId(); + auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); + UpdateBrightness(focusedSessionId); } if (IsPcSceneSessionLifecycle(sceneSession)) { TLOGNI(WmsLogTag::WMS_MAIN, "Notify session background: %{public}d", persistentId); @@ -3797,14 +3801,21 @@ void SceneSessionManager::UpdateRotateAnimationConfig(const RotateAnimationConfi WSError SceneSessionManager::ProcessBackEvent() { taskScheduler_->PostAsyncTask([this]() { - auto session = GetSceneSession(focusedSessionId_); + auto focusGroup = windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + if (focusGroup == nullptr) { + TLOGNE(WmsLogTag::WMS_MAIN, "focus group is nullptr: %{public}lu", DEFAULT_DISPLAY_ID); + return WSError::WS_ERROR_INVALID_SESSION; + } + auto focusedSessionId = focusGroup->GetFocusedSessionId(); + auto needBlockNotifyFocusStatusUntilForeground = focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground(); + auto session = GetSceneSession(focusedSessionId); if (!session) { - TLOGNE(WmsLogTag::WMS_MAIN, "session is nullptr: %{public}d", focusedSessionId_); + TLOGNE(WmsLogTag::WMS_MAIN, "session is nullptr: %{public}d", focusedSessionId); return WSError::WS_ERROR_INVALID_SESSION; } TLOGNI(WmsLogTag::WMS_MAIN, "ProcessBackEvent session persistentId:%{public}d needBlock:%{public}d", - focusedSessionId_, needBlockNotifyFocusStatusUntilForeground_); - if (needBlockNotifyFocusStatusUntilForeground_) { + focusedSessionId, needBlockNotifyFocusStatusUntilForeground); + if (needBlockNotifyFocusStatusUntilForeground) { TLOGND(WmsLogTag::WMS_MAIN, "RequestSessionBack when start session"); if (session->GetSessionInfo().abilityInfo != nullptr && session->GetSessionInfo().abilityInfo->unclearableMission) { @@ -4588,33 +4599,34 @@ WMError SceneSessionManager::SetGestureNavigationEnabled(bool enable) return taskScheduler_->PostSyncTask(task, "SetGestureNavigationEnabled"); } -WSError SceneSessionManager::SetFocusedSessionId(int32_t persistentId) +WSError SceneSessionManager::SetFocusedSessionId(int32_t persistentId, DisplayId displayId) { - if (focusedSessionId_ == persistentId) { - WLOGI("Focus scene not change, id: %{public}d", focusedSessionId_); + auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); + if (focusedSessionId == persistentId) { + WLOGI("Focus scene not change, id: %{public}d", focusedSessionId); return WSError::WS_DO_NOTHING; } - lastFocusedSessionId_ = focusedSessionId_; - focusedSessionId_ = persistentId; + windowFocusController_->UpdateFocusedSessionId(displayId, persistentId); return WSError::WS_OK; } -int32_t SceneSessionManager::GetFocusedSessionId() const +int32_t SceneSessionManager::GetFocusedSessionId(DisplayId displayId) const { - return focusedSessionId_; + return windowFocusController_->GetFocusedSessionId(displayId); } -void SceneSessionManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo) +void SceneSessionManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId) { if (!SessionPermission::IsSACalling()) { TLOGE(WmsLogTag::WMS_FOCUS, "permission denied!"); return; } - taskScheduler_->PostSyncTask([this, &focusInfo] { - if (auto sceneSession = GetSceneSession(focusedSessionId_)) { + taskScheduler_->PostSyncTask([this, &focusInfo, displayId] { + auto focusGroup = windowFocusController_->GetFocusGroup(displayId); + if (auto sceneSession = GetSceneSession(focusGroup->GetFocusedSessionId())) { TLOGND(WmsLogTag::WMS_FOCUS, "Get focus session info success"); focusInfo.windowId_ = sceneSession->GetWindowId(); - focusInfo.displayId_ = static_cast(0); + focusInfo.displayId_ = static_cast(focusGroup->GetDisplayGroupId()); focusInfo.pid_ = sceneSession->GetCallingPid(); focusInfo.uid_ = sceneSession->GetCallingUid(); focusInfo.windowType_ = sceneSession->GetWindowType(); @@ -4625,6 +4637,16 @@ void SceneSessionManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo) }, __func__); } +WSError SceneSessionManager::AddFocusGroup(DisplayId displayId) +{ + return windowFocusController_->AddFocusGroup(displayId); +} + +WSError SceneSessionManager::RemoveFocusGroup(DisplayId displayId) +{ + return windowFocusController_->RemoveFocusGroup(displayId); +} + static bool IsValidDigitString(const std::string& windowIdStr) { if (windowIdStr.empty()) { @@ -4966,7 +4988,13 @@ WSError SceneSessionManager::GetAllSessionDumpInfo(std::string& dumpInfo) DumpSessionInfo(session, oss); count++; } - oss << "Focus window: " << GetFocusedSessionId() << std::endl; + oss << "Focus window: " << std::endl; + std::vector> allFocusedStateList = windowFocusController_->GetAllFocusedSessionList(); + if (allFocusedStateList.size() > 0) { + for (const auto& focusState : allFocusedStateList) { + oss << "DisplayId: " << focusState.first << " Focus window: " << focusState.second << std::endl; + } + } oss << "SingleHand: X[" << singleHandTransform_.posX << "] Y[" << singleHandTransform_.posY << "] scale[" << singleHandTransform_.scaleX << "]" << std::endl; oss << "Total window num: " << sceneSessionMapCopy.size() << std::endl; @@ -5349,16 +5377,22 @@ void SceneSessionManager::RequestAllAppSessionUnfocus() WSError SceneSessionManager::RequestSessionFocusImmediately(int32_t persistentId) { TLOGD(WmsLogTag::WMS_FOCUS, "id: %{public}d", persistentId); - // base block - WSError basicCheckRet = RequestFocusBasicCheck(persistentId); - if (basicCheckRet != WSError::WS_OK) { - return basicCheckRet; - } auto sceneSession = GetSceneSession(persistentId); if (sceneSession == nullptr) { WLOGFE("[WMSComm]session is nullptr"); return WSError::WS_ERROR_INVALID_SESSION; } + auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); + auto focusGroup = windowFocusController_->GetFocusGroup(displayId); + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}lu", displayId); + return WSError::WS_ERROR_INVALID_SESSION; + } + // base block + WSError basicCheckRet = RequestFocusBasicCheck(persistentId, focusGroup); + if (basicCheckRet != WSError::WS_OK) { + return basicCheckRet; + } if (!sceneSession->CheckFocusable()) { TLOGD(WmsLogTag::WMS_FOCUS, "session is not focusable!"); return WSError::WS_DO_NOTHING; @@ -5370,16 +5404,16 @@ WSError SceneSessionManager::RequestSessionFocusImmediately(int32_t persistentId // specific block FocusChangeReason reason = FocusChangeReason::SCB_START_APP; - WSError specificCheckRet = RequestFocusSpecificCheck(sceneSession, true, reason); + WSError specificCheckRet = RequestFocusSpecificCheck(displayId, sceneSession, true, reason); if (specificCheckRet != WSError::WS_OK) { return specificCheckRet; } - - needBlockNotifyUnfocusStatus_ = needBlockNotifyFocusStatusUntilForeground_; + auto needBlockNotifyFocusStatusUntilForeground = focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground(); + focusGroup->SetNeedBlockNotifyUnfocusStatus(needBlockNotifyFocusStatusUntilForeground); if (!sceneSession->GetSessionInfo().isSystem_ && !IsSessionVisibleForeground(sceneSession)) { - needBlockNotifyFocusStatusUntilForeground_ = true; + focusGroup->SetNeedBlockNotifyFocusStatusUntilForeground(true); } - ShiftFocus(sceneSession, reason); + ShiftFocus(displayId, sceneSession, reason); return WSError::WS_OK; } @@ -5387,15 +5421,21 @@ WSError SceneSessionManager::RequestSessionFocus(int32_t persistentId, bool byFo { TLOGD(WmsLogTag::WMS_FOCUS, "id: %{public}d, by foreground: %{public}d, reason: %{public}d", persistentId, byForeground, reason); - WSError basicCheckRet = RequestFocusBasicCheck(persistentId); - if (basicCheckRet != WSError::WS_OK) { - return basicCheckRet; - } auto sceneSession = GetSceneSession(persistentId); if (sceneSession == nullptr) { WLOGFE("[WMSComm]session is nullptr"); return WSError::WS_ERROR_INVALID_SESSION; } + auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); + auto focusGroup = windowFocusController_->GetFocusGroup(displayId); + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}lu", displayId); + return WSError::WS_ERROR_INVALID_SESSION; + } + WSError basicCheckRet = RequestFocusBasicCheck(persistentId, focusGroup); + if (basicCheckRet != WSError::WS_OK) { + return basicCheckRet; + } if (!sceneSession->CheckFocusable() || !IsSessionVisibleForeground(sceneSession)) { TLOGD(WmsLogTag::WMS_FOCUS, "session is not focusable or not visible!"); return WSError::WS_DO_NOTHING; @@ -5420,14 +5460,13 @@ WSError SceneSessionManager::RequestSessionFocus(int32_t persistentId, bool byFo return WSError::WS_DO_NOTHING; } // specific block - WSError specificCheckRet = RequestFocusSpecificCheck(sceneSession, byForeground, reason); + WSError specificCheckRet = RequestFocusSpecificCheck(displayId, sceneSession, byForeground, reason); if (specificCheckRet != WSError::WS_OK) { return specificCheckRet; } - - needBlockNotifyUnfocusStatus_ = needBlockNotifyFocusStatusUntilForeground_; - needBlockNotifyFocusStatusUntilForeground_ = false; - ShiftFocus(sceneSession, reason); + focusGroup->SetNeedBlockNotifyUnfocusStatus(focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground()); + focusGroup->SetNeedBlockNotifyFocusStatusUntilForeground(false); + ShiftFocus(displayId, sceneSession, reason); return WSError::WS_OK; } @@ -5438,62 +5477,81 @@ WSError SceneSessionManager::RequestSessionUnfocus(int32_t persistentId, FocusCh WLOGFE("id is invalid"); return WSError::WS_ERROR_INVALID_SESSION; } - auto focusedSession = GetSceneSession(focusedSessionId_); - if (persistentId != focusedSessionId_ && + auto sceneSession = GetSceneSession(persistentId); + if (sceneSession == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "session is nullptr"); + return WSError::WS_ERROR_INVALID_SESSION; + } + auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); + auto focusGroup = windowFocusController_->GetFocusGroup(displayId); + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}lu", displayId); + return WSError::WS_ERROR_INVALID_SESSION; + } + auto focusedSession = GetSceneSession(focusGroup->GetFocusedSessionId()); + if (persistentId != focusGroup->GetFocusedSessionId() && !(focusedSession && focusedSession->GetParentPersistentId() == persistentId)) { TLOGD(WmsLogTag::WMS_FOCUS, "session unfocused!"); return WSError::WS_DO_NOTHING; } // if pop menu created by desktop request unfocus, back to desktop - auto lastSession = GetSceneSession(lastFocusedSessionId_); + auto lastSession = GetSceneSession(focusGroup->GetLastFocusedSessionId()); if (focusedSession && focusedSession->GetWindowType() == WindowType::WINDOW_TYPE_SYSTEM_FLOAT && lastSession && lastSession->GetWindowType() == WindowType::WINDOW_TYPE_DESKTOP && - RequestSessionFocus(lastFocusedSessionId_, false) == WSError::WS_OK) { + RequestSessionFocus(focusGroup->GetLastFocusedSessionId(), false) == WSError::WS_OK) { TLOGD(WmsLogTag::WMS_FOCUS, "focus is back to desktop"); return WSError::WS_OK; } - auto nextSession = GetNextFocusableSession(persistentId); + auto nextSession = GetNextFocusableSession(displayId, persistentId); if (nextSession == nullptr) { DumpAllSessionFocusableInfo(persistentId); } - - needBlockNotifyUnfocusStatus_ = needBlockNotifyFocusStatusUntilForeground_; - needBlockNotifyFocusStatusUntilForeground_ = false; + focusGroup->SetNeedBlockNotifyUnfocusStatus(focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground()); + focusGroup->SetNeedBlockNotifyFocusStatusUntilForeground(false); if (CheckLastFocusedAppSessionFocus(focusedSession, nextSession)) { return WSError::WS_OK; } - return ShiftFocus(nextSession, reason); + return ShiftFocus(displayId, nextSession, reason); } WSError SceneSessionManager::RequestAllAppSessionUnfocusInner() { TLOGI(WmsLogTag::WMS_FOCUS, "in"); - auto focusedSession = GetSceneSession(focusedSessionId_); + auto focusGroup = windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + return WSError::WS_ERROR_INVALID_SESSION; + } + auto focusedSession = GetSceneSession(focusGroup->GetFocusedSessionId()); if (!focusedSession) { TLOGE(WmsLogTag::WMS_FOCUS, "focused session is null"); return WSError::WS_DO_NOTHING; } if (!focusedSession->IsAppSession()) { - WLOGW("[WMFocus]Focused session is non app session: %{public}d", focusedSessionId_); + WLOGW("[WMFocus]Focused session is non app session: %{public}d", focusGroup->GetFocusedSessionId()); return WSError::WS_DO_NOTHING; } auto nextSession = GetTopFocusableNonAppSession(); - needBlockNotifyUnfocusStatus_ = needBlockNotifyFocusStatusUntilForeground_; - needBlockNotifyFocusStatusUntilForeground_ = false; - return ShiftFocus(nextSession, FocusChangeReason::WIND); + focusGroup->SetNeedBlockNotifyUnfocusStatus(focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground()); + focusGroup->SetNeedBlockNotifyFocusStatusUntilForeground(false); + return ShiftFocus(DEFAULT_DISPLAY_ID, nextSession, FocusChangeReason::WIND); } -WSError SceneSessionManager::RequestFocusBasicCheck(int32_t persistentId) +WSError SceneSessionManager::RequestFocusBasicCheck(int32_t persistentId, sptr& focusGroup) { // basic focus rule if (persistentId == INVALID_SESSION_ID) { TLOGE(WmsLogTag::WMS_FOCUS, "id is invalid!"); return WSError::WS_ERROR_INVALID_SESSION; } - if (persistentId == focusedSessionId_) { + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + return WSError::WS_ERROR_INVALID_SESSION; + } + if (persistentId == focusGroup->GetFocusedSessionId()) { TLOGD(WmsLogTag::WMS_FOCUS, "request id has been focused!"); return WSError::WS_DO_NOTHING; } @@ -5510,11 +5568,17 @@ bool SceneSessionManager::CheckLastFocusedAppSessionFocus( if (focusedSession == nullptr || nextSession == nullptr) { return false; } - + auto displayId = focusedSession->GetSessionProperty()->GetDisplayId(); + auto focusGroup = windowFocusController_->GetFocusGroup(displayId); + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + return false; + } + auto lastFocusedAppSessionId = focusGroup->GetLastFocusedAppSessionId(); TLOGI(WmsLogTag::WMS_FOCUS, "lastFocusedAppSessionId: %{public}d, nextSceneSession: %{public}d", - lastFocusedAppSessionId_, nextSession->GetPersistentId()); + lastFocusedAppSessionId, nextSession->GetPersistentId()); - if (lastFocusedAppSessionId_ == INVALID_SESSION_ID || nextSession->GetPersistentId() == lastFocusedAppSessionId_) { + if (lastFocusedAppSessionId == INVALID_SESSION_ID || nextSession->GetPersistentId() == lastFocusedAppSessionId) { return false; } @@ -5527,11 +5591,11 @@ bool SceneSessionManager::CheckLastFocusedAppSessionFocus( if (nextSession->IsAppSession() && (mode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || mode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY || mode == WindowMode::WINDOW_MODE_FLOATING)) { - if (RequestSessionFocus(lastFocusedAppSessionId_, false, FocusChangeReason::LAST_FOCUSED_APP) == + if (RequestSessionFocus(lastFocusedAppSessionId, false, FocusChangeReason::LAST_FOCUSED_APP) == WSError::WS_OK) { return true; } - lastFocusedAppSessionId_ = INVALID_SESSION_ID; + focusGroup->SetLastFocusedAppSessionId(INVALID_SESSION_ID); } return false; } @@ -5546,10 +5610,11 @@ bool SceneSessionManager::CheckFocusIsDownThroughBlockingType(sptr { uint32_t requestSessionZOrder = requestSceneSession->GetZOrder(); uint32_t focusedSessionZOrder = focusedSession->GetZOrder(); + auto displayId = requestSceneSession->GetSessionProperty()->GetDisplayId(); TLOGD(WmsLogTag::WMS_FOCUS, "requestSessionZOrder: %{public}d, focusedSessionZOrder: %{public}d", requestSessionZOrder, focusedSessionZOrder); if (requestSessionZOrder < focusedSessionZOrder) { - auto topNearestBlockingFocusSession = GetTopNearestBlockingFocusSession(requestSessionZOrder, + auto topNearestBlockingFocusSession = GetTopNearestBlockingFocusSession(displayId, requestSessionZOrder, includingAppSession); uint32_t topNearestBlockingZOrder = 0; if (topNearestBlockingFocusSession) { @@ -5606,7 +5671,7 @@ bool SceneSessionManager::CheckClickFocusIsDownThroughFullScreen(const sptrGetZOrder() < focusedSession->GetZOrder(); } -WSError SceneSessionManager::RequestFocusSpecificCheck(sptr& sceneSession, bool byForeground, +WSError SceneSessionManager::RequestFocusSpecificCheck(DisplayId displayId, sptr& sceneSession, bool byForeground, FocusChangeReason reason) { TLOGD(WmsLogTag::WMS_FOCUS, "FocusChangeReason: %{public}d", reason); @@ -5620,7 +5685,8 @@ WSError SceneSessionManager::RequestFocusSpecificCheck(sptr& scene return WSError::WS_DO_NOTHING; } // blocking-type session will block lower zOrder request focus - auto focusedSession = GetSceneSession(focusedSessionId_); + auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); + auto focusedSession = GetSceneSession(focusedSessionId); if (focusedSession) { TLOGD(WmsLogTag::WMS_FOCUS, "reason: %{public}d, byForeground: %{public}d", reason, byForeground); @@ -5691,15 +5757,18 @@ void SceneSessionManager::DumpAllSessionFocusableInfo(int32_t persistentId) TraverseSessionTree(func, true); } -sptr SceneSessionManager::GetNextFocusableSession(int32_t persistentId) +sptr SceneSessionManager::GetNextFocusableSession(DisplayId displayId, int32_t persistentId) { TLOGD(WmsLogTag::WMS_FOCUS, "id: %{public}d", persistentId); bool previousFocusedSessionFound = false; sptr ret = nullptr; - auto func = [this, persistentId, &previousFocusedSessionFound, &ret](sptr session) { + auto func = [this, persistentId, &previousFocusedSessionFound, &ret, displayId](sptr session) { if (session == nullptr) { return false; } + if (session->GetSessionProperty()->GetDisplayId() != displayId) { + return false; + } if (session->GetForceHideState() != ForceHideState::NOT_HIDDEN) { TLOGND(WmsLogTag::WMS_FOCUS, "the window hide id: %{public}d", persistentId); return false; @@ -5722,13 +5791,16 @@ sptr SceneSessionManager::GetNextFocusableSession(int32_t persiste * Find the session through the specific zOrder, it is located abve it, its' blockingFocus attribute is true, * and it is the closest; */ -sptr SceneSessionManager::GetTopNearestBlockingFocusSession(uint32_t zOrder, bool includingAppSession) +sptr SceneSessionManager::GetTopNearestBlockingFocusSession(DisplayId displayId, uint32_t zOrder, bool includingAppSession) { sptr ret = nullptr; - auto func = [this, &ret, zOrder, includingAppSession](sptr session) { + auto func = [this, &ret, zOrder, includingAppSession, displayId](sptr session) { if (session == nullptr) { return false; } + if (session->GetSessionProperty()->GetDisplayId() != displayId) { + return false; + } uint32_t sessionZOrder = session->GetZOrder(); if (sessionZOrder <= zOrder) { // must be above the target session return false; @@ -5766,6 +5838,9 @@ sptr SceneSessionManager::GetTopFocusableNonAppSession() if (session == nullptr) { return false; } + if (session->GetSessionProperty()->GetDisplayId() != DEFAULT_DISPLAY_ID) { + return false; + } if (session->IsAppSession()) { return true; } @@ -5817,22 +5892,26 @@ void SceneSessionManager::SetAbilityManagerCollaboratorRegisteredFunc( taskScheduler_->PostAsyncTask(task, __func__); } -WSError SceneSessionManager::ShiftFocus(sptr& nextSession, FocusChangeReason reason) +WSError SceneSessionManager::ShiftFocus(DisplayId displayId, sptr& nextSession, FocusChangeReason reason) { // unfocus - int32_t focusedId = focusedSessionId_; - auto focusedSession = GetSceneSession(focusedSessionId_); - UpdateFocusStatus(focusedSession, false); + auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); + int32_t focusedId = focusedSessionId; + auto focusedSession = GetSceneSession(focusedSessionId); + UpdateFocusStatus(displayId, focusedSession, false); // focus int32_t nextId = INVALID_SESSION_ID; if (nextSession == nullptr) { std::string sessionLog(GetAllSessionFocusInfo()); TLOGW(WmsLogTag::WMS_FOCUS, "next session nullptr! id: %{public}d, info: %{public}s", - focusedSessionId_, sessionLog.c_str()); + focusedSessionId, sessionLog.c_str()); } else { nextId = nextSession->GetPersistentId(); } - UpdateFocusStatus(nextSession, true); + UpdateFocusStatus(displayId, nextSession, true); + if (shiftFocusFunc_ != nullptr) { + shiftFocusFunc_(nextId, displayId); + } bool scbPrevFocus = focusedSession && focusedSession->GetSessionInfo().isSystem_; bool scbCurrFocus = nextSession && nextSession->GetSessionInfo().isSystem_; if (!scbPrevFocus && scbCurrFocus) { @@ -5849,14 +5928,21 @@ WSError SceneSessionManager::ShiftFocus(sptr& nextSession, FocusCh return WSError::WS_OK; } -void SceneSessionManager::UpdateFocusStatus(sptr& sceneSession, bool isFocused) +void SceneSessionManager::UpdateFocusStatus(DisplayId displayId, sptr& sceneSession, bool isFocused) { + auto focusGroup = windowFocusController_->GetFocusGroup(displayId); + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + return; + } + bool needBlockNotifyFocusStatusUntilForeground = focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground(); + bool needBlockNotifyUnfocusStatus = focusGroup->GetNeedBlockNotifyUnfocusStatus(); if (sceneSession == nullptr) { if (isFocused) { - SetFocusedSessionId(INVALID_SESSION_ID); - lastFocusedAppSessionId_ = INVALID_SESSION_ID; - if (!needBlockNotifyFocusStatusUntilForeground_) { - auto prevSession = GetSceneSession(lastFocusedSessionId_); + SetFocusedSessionId(INVALID_SESSION_ID, displayId); + focusGroup->SetLastFocusedAppSessionId(INVALID_SESSION_ID); + if (!needBlockNotifyFocusStatusUntilForeground) { + auto prevSession = GetSceneSession(focusGroup->GetLastFocusedSessionId()); NotifyUnFocusedByMission(prevSession); } } @@ -5866,23 +5952,25 @@ void SceneSessionManager::UpdateFocusStatus(sptr& sceneSession, bo sceneSession->GetWindowNameAllType().c_str(), sceneSession->GetPersistentId(), isFocused); // set focused if (isFocused) { - SetFocusedSessionId(sceneSession->GetPersistentId()); + SetFocusedSessionId(sceneSession->GetPersistentId(), displayId); if (sceneSession->IsAppOrLowerSystemSession()) { - lastFocusedAppSessionId_ = sceneSession->GetPersistentId(); + focusGroup->SetLastFocusedAppSessionId(sceneSession->GetPersistentId()); } } sceneSession->UpdateFocus(isFocused); - if ((isFocused && !needBlockNotifyFocusStatusUntilForeground_) || (!isFocused && !needBlockNotifyUnfocusStatus_)) { - NotifyFocusStatus(sceneSession, isFocused); + if ((isFocused && !needBlockNotifyFocusStatusUntilForeground) || (!isFocused && !needBlockNotifyUnfocusStatus)) { + NotifyFocusStatus(sceneSession, isFocused, focusGroup); } } -void SceneSessionManager::NotifyFocusStatus(sptr& sceneSession, bool isFocused) +void SceneSessionManager::NotifyFocusStatus(sptr& sceneSession, bool isFocused, + sptr& focusGroup) { + auto lastFocusedSessionId = focusGroup->GetLastFocusedSessionId(); if (sceneSession == nullptr) { WLOGFE("[WMSComm]session is nullptr"); if (isFocused) { - auto prevSession = GetSceneSession(lastFocusedSessionId_); + auto prevSession = GetSceneSession(lastFocusedSessionId); NotifyUnFocusedByMission(prevSession); } return; @@ -5899,16 +5987,13 @@ void SceneSessionManager::NotifyFocusStatus(sptr& sceneSession, bo if (IsSessionVisibleForeground(sceneSession)) { NotifyWindowInfoChange(persistentId, WindowUpdateType::WINDOW_UPDATE_FOCUSED); } - UpdateBrightness(focusedSessionId_); + UpdateBrightness(focusGroup->GetFocusedSessionId()); FocusIDChange(sceneSession->GetPersistentId(), sceneSession); - if (shiftFocusFunc_ != nullptr) { - shiftFocusFunc_(persistentId); - } } // notify window manager sptr focusChangeInfo = sptr::MakeSptr( sceneSession->GetWindowId(), - static_cast(0), + static_cast(focusGroup->GetDisplayGroupId()), sceneSession->GetCallingPid(), sceneSession->GetCallingUid(), sceneSession->GetWindowType(), @@ -5917,20 +6002,8 @@ void SceneSessionManager::NotifyFocusStatus(sptr& sceneSession, bo SceneSessionManager::NotifyRssThawApp(focusChangeInfo->uid_, "", "THAW_BY_FOCUS_CHANGED"); SessionManagerAgentController::GetInstance().UpdateFocusChangeInfo(focusChangeInfo, isFocused); sceneSession->NotifyFocusStatus(isFocused); - std::string sName = "FoucusWindow:"; - if (sceneSession->GetSessionInfo().isSystem_) { - sName += sceneSession->GetSessionInfo().abilityName_; - } else { - sName += sceneSession->GetWindowName(); - } - if (isFocused) { - StartAsyncTrace(HITRACE_TAG_WINDOW_MANAGER, sName, sceneSession->GetPersistentId()); - } else { - FinishAsyncTrace(HITRACE_TAG_WINDOW_MANAGER, sName, sceneSession->GetPersistentId()); - } - // notify listenerController - auto prevSession = GetSceneSession(lastFocusedSessionId_); + auto prevSession = GetSceneSession(lastFocusedSessionId); if (isFocused && MissionChanged(prevSession, sceneSession)) { NotifyFocusStatusByMission(prevSession, sceneSession); } @@ -6007,12 +6080,14 @@ WSError SceneSessionManager::UpdateFocus(int32_t persistentId, bool isFocused) TLOGNI(WmsLogTag::WMS_FOCUS, "UpdateFocus, name: %{public}s, id: %{public}d, isFocused: %{public}u", sceneSession->GetWindowName().c_str(), persistentId, static_cast(isFocused)); // focusId change + auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); + auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); if (isFocused) { - SetFocusedSessionId(persistentId); - UpdateBrightness(focusedSessionId_); + SetFocusedSessionId(displayId, persistentId); + UpdateBrightness(focusedSessionId); FocusIDChange(persistentId, sceneSession); } else if (persistentId == GetFocusedSessionId()) { - SetFocusedSessionId(INVALID_SESSION_ID); + SetFocusedSessionId(displayId, INVALID_SESSION_ID); } // notify window manager sptr focusChangeInfo = sptr::MakeSptr( @@ -6508,12 +6583,20 @@ __attribute__((no_sanitize("cfi"))) void SceneSessionManager::OnSessionStateChan void SceneSessionManager::ProcessFocusWhenForeground(sptr& sceneSession) { auto persistentId = sceneSession->GetPersistentId(); + auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); + auto focusGroup = windowFocusController_->GetFocusGroup(displayId); + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + return; + } + bool needBlockNotifyFocusStatusUntilForeground = focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground(); + bool needBlockNotifyUnfocusStatus = focusGroup->GetNeedBlockNotifyUnfocusStatus(); if (sceneSession->GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW && - persistentId == focusedSessionId_) { - if (needBlockNotifyFocusStatusUntilForeground_) { - needBlockNotifyUnfocusStatus_ = false; - needBlockNotifyFocusStatusUntilForeground_ = false; - NotifyFocusStatus(sceneSession, true); + persistentId == focusGroup->GetFocusedSessionId()) { + if (focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground()) { + focusGroup->SetNeedBlockNotifyFocusStatusUntilForeground(false); + focusGroup->SetNeedBlockNotifyUnfocusStatus(false); + NotifyFocusStatus(sceneSession, true, focusGroup); } } else if (!sceneSession->IsFocusedOnShow()) { if (IsSessionVisibleForeground(sceneSession)) { @@ -6690,10 +6773,18 @@ void SceneSessionManager::ProcessSubSessionForeground(sptr& sceneS continue; } NotifyWindowInfoChange(modal->GetPersistentId(), WindowUpdateType::WINDOW_UPDATE_ADDED); - if (modal->GetPersistentId() == focusedSessionId_ && needBlockNotifyFocusStatusUntilForeground_) { - needBlockNotifyUnfocusStatus_ = false; - needBlockNotifyFocusStatusUntilForeground_ = false; - NotifyFocusStatus(modalSession, true); + auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); + auto focusGroup = windowFocusController_->GetFocusGroup(displayId); + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + return; + } + auto focusedSessionId = focusGroup->GetFocusedSessionId(); + bool needBlockNotifyFocusStatusUntilForeground = focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground(); + if (modal->GetPersistentId() == focusedSessionId_ && needBlockNotifyFocusStatusUntilForeground) { + focusGroup->SetNeedBlockNotifyFocusStatusUntilForeground(false); + focusGroup->SetNeedBlockNotifyUnfocusStatus(false); + NotifyFocusStatus(modalSession, true, focusGroup); } HandleKeepScreenOn(modalSession, modalSession->IsKeepScreenOn()); } @@ -6719,10 +6810,12 @@ WSError SceneSessionManager::ProcessModalTopmostRequestFocusImmdediately(sptrGetSessionProperty()->GetDisplayId(); + auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); if (std::find_if(topmostVec.begin(), topmostVec.end(), - [this](sptr& iter) { return iter && iter->GetPersistentId() == focusedSessionId_; }) + [this, focusedSessionId](sptr& iter) { return iter && iter->GetPersistentId() == focusedSessionId; }) != topmostVec.end()) { - TLOGND(WmsLogTag::WMS_SUB, "modal topmost subwindow id: %{public}d has been focused!", focusedSessionId_); + TLOGND(WmsLogTag::WMS_SUB, "modal topmost subwindow id: %{public}d has been focused!", focusedSessionId); return WSError::WS_OK; } WSError ret = WSError::WS_DO_NOTHING; @@ -6752,10 +6845,12 @@ WSError SceneSessionManager::ProcessDialogRequestFocusImmdediately(sptr> dialogVec = mainSession->GetDialogVector(); + auto displayId = mainSession->GetSessionProperty()->GetDisplayId(); + auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); if (std::find_if(dialogVec.begin(), dialogVec.end(), - [this](sptr& iter) { return iter && iter->GetPersistentId() == focusedSessionId_; }) + [this, focusedSessionId](sptr& iter) { return iter && iter->GetPersistentId() == focusedSessionId; }) != dialogVec.end()) { - TLOGND(WmsLogTag::WMS_DIALOG, "dialog id: %{public}d has been focused!", focusedSessionId_); + TLOGND(WmsLogTag::WMS_DIALOG, "dialog id: %{public}d has been focused!", focusedSessionId); return WSError::WS_OK; } WSError ret = WSError::WS_DO_NOTHING; @@ -8175,7 +8270,8 @@ bool SceneSessionManager::FillWindowInfo(std::vectoruiNodeId_ = sceneSession->GetUINodeId(); WSRect wsrect = sceneSession->GetSessionGlobalRect(); // only accessability and mmi need global info->windowRect_ = {wsrect.posX_, wsrect.posY_, wsrect.width_, wsrect.height_ }; - info->focused_ = sceneSession->GetPersistentId() == focusedSessionId_; + auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); + info->focused_ = sceneSession->GetPersistentId() == GetFocusedSessionId(displayId); info->type_ = sceneSession->GetWindowType(); info->mode_ = sceneSession->GetWindowMode(); info->layer_ = sceneSession->GetZOrder(); @@ -8818,15 +8914,17 @@ void SceneSessionManager::ClearDisplayStatusBarTemporarilyFlags() } } -WSError SceneSessionManager::GetFocusSessionToken(sptr& token) +WSError SceneSessionManager::GetFocusSessionToken(sptr& token, DisplayId displayId) { if (!SessionPermission::IsSACalling()) { WLOGFE("permission denied!"); return WSError::WS_ERROR_INVALID_PERMISSION; } - return taskScheduler_->PostSyncTask([this, &token, where = __func__]() { - TLOGND(WmsLogTag::WMS_FOCUS, "%{public}s with focusedSessionId: %{public}d", where, focusedSessionId_); - if (auto sceneSession = GetSceneSession(focusedSessionId_)) { + return taskScheduler_->PostSyncTask([this, &token, where = __func__, displayId]() { + auto focusGroup = windowFocusController_->GetFocusGroup(displayId); + TLOGND(WmsLogTag::WMS_FOCUS, "%{public}s with focusedSessionId: %{public}d", where, + focusGroup->GetFocusedSessionId()); + if (auto sceneSession = GetSceneSession(focusGroup->GetFocusedSessionId())) { token = sceneSession->GetAbilityToken(); if (token == nullptr) { TLOGNE(WmsLogTag::WMS_FOCUS, "token is nullptr"); @@ -8838,7 +8936,7 @@ WSError SceneSessionManager::GetFocusSessionToken(sptr& token) }, __func__); } -WSError SceneSessionManager::GetFocusSessionElement(AppExecFwk::ElementName& element) +WSError SceneSessionManager::GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId) { auto pid = IPCSkeleton::GetCallingRealPid(); AppExecFwk::RunningProcessInfo info; @@ -8847,9 +8945,11 @@ WSError SceneSessionManager::GetFocusSessionElement(AppExecFwk::ElementName& ele WLOGFE("permission denied!"); return WSError::WS_ERROR_INVALID_PERMISSION; } - return taskScheduler_->PostSyncTask([this, &element, where = __func__]() { - TLOGND(WmsLogTag::WMS_FOCUS, "%{public}s with focusedSessionId: %{public}d", where, focusedSessionId_); - if (auto sceneSession = GetSceneSession(focusedSessionId_)) { + return taskScheduler_->PostSyncTask([this, &element, where = __func__, displayId]() { + auto focusGroup = windowFocusController_->GetFocusGroup(displayId); + TLOGND(WmsLogTag::WMS_FOCUS, "%{public}s with focusedSessionId: %{public}d", where, + focusGroup->GetFocusedSessionId()); + if (auto sceneSession = GetSceneSession(focusGroup->GetFocusedSessionId())) { const auto& sessionInfo = sceneSession->GetSessionInfo(); element = AppExecFwk::ElementName("", sessionInfo.bundleName_, sessionInfo.abilityName_, sessionInfo.moduleName_); @@ -9405,6 +9505,41 @@ void DisplayChangeListener::OnDisplayStateChange(DisplayId defaultDisplayId, spt } } +bool CheckIfNeedMultipleFocus(const std::string& name, const ScreenType& screenType) +{ + TLOGI(WmsLogTag::WMS_FOCUS, "name: %{public}s screenType: %{public}u", name.c_str(), screenType); + if (screenType == ScreenType::VIRTUAL && (name == "HiCar" || name == "SuperLauncher" || name == "CastEngine")) { + return true; + } + return false; +} + +void ScreenConnectionChangeListener::OnScreenConnected(const sptr& screenSession) +{ + if (screenSession == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "screenSession connect failed"); + return; + } + TLOGI(WmsLogTag::WMS_FOCUS, "name: %{public}s, screenId: %{public}lu", screenSession->GetName().c_str(), + screenSession->GetScreenId()); + if (CheckIfNeedMultipleFocus(screenSession->GetName(), screenSession->GetScreenProperty().GetScreenType())) { + SceneSessionManager::GetInstance().AddFocusGroup(screenSession->GetScreenId()); + } +} + +void ScreenConnectionChangeListener::OnScreenDisconnected(const sptr& screenSession) +{ + if (screenSession == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "screenSession disconnect failed"); + return; + } + TLOGI(WmsLogTag::WMS_FOCUS, "name: %{public}s, screenId: %{public}lu", screenSession->GetName().c_str(), + screenSession->GetScreenId()); + if (CheckIfNeedMultipleFocus(screenSession->GetName(), screenSession->GetScreenProperty().GetScreenType())) { + SceneSessionManager::GetInstance().RemoveFocusGroup(screenSession->GetScreenId()); + } +} + void DisplayChangeListener::OnScreenshot(DisplayId displayId) { SceneSessionManager::GetInstance().OnScreenshot(displayId); @@ -10133,12 +10268,18 @@ void SceneSessionManager::FlushUIParams(ScreenId screenId, std::unordered_map& zOrderList) { - TLOGD(WmsLogTag::WMS_FOCUS, "last focused app: %{public}d, list size %{public}zu", lastFocusedAppSessionId_, + auto focusGroup = windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + return; + } + auto lastFocusedAppSessionId = focusGroup->GetLastFocusedAppSessionId(); + TLOGD(WmsLogTag::WMS_FOCUS, "last focused app: %{public}d, list size %{public}zu", lastFocusedAppSessionId, zOrderList.size()); - if (lastFocusedAppSessionId_ == INVALID_SESSION_ID || zOrderList.empty()) { + if (lastFocusedAppSessionId == INVALID_SESSION_ID || zOrderList.empty()) { return; } - auto lastFocusedAppSession = GetSceneSession(lastFocusedAppSessionId_); + auto lastFocusedAppSession = GetSceneSession(lastFocusedAppSessionId); if (lastFocusedAppSession == nullptr) { return; } @@ -10148,7 +10289,7 @@ void SceneSessionManager::ProcessUpdateLastFocusedAppId(const std::vectorSetLastFocusedAppSessionId(INVALID_SESSION_ID); } } @@ -10161,7 +10302,8 @@ void SceneSessionManager::ProcessFocusZOrderChange(uint32_t dirty) return; } TLOGD(WmsLogTag::WMS_FOCUS, "has zOrder dirty"); - auto focusedSession = GetSceneSession(focusedSessionId_); + auto focusedSessionId = GetFocusedSessionId(DEFAULT_DISPLAY_ID); + auto focusedSession = GetSceneSession(focusedSessionId); // only when it's from a high zOrder to a low zOrder if (focusedSession == nullptr || focusedSession->GetWindowType() == WindowType::WINDOW_TYPE_VOICE_INTERACTION || focusedSession->GetLastZOrder() <= focusedSession->GetZOrder()) { @@ -10206,18 +10348,20 @@ void SceneSessionManager::PostProcessFocus() std::sort(processingSessions.begin(), processingSessions.end(), cmp); // only change focus one time - bool focusChanged = false; + std::unordered_set focusChangedSet; for (auto iter = processingSessions.begin(); iter != processingSessions.end(); ++iter) { auto session = iter->second; if (session == nullptr) { WLOGFE("session is nullptr"); continue; } + auto displayId = session->GetSessionProperty()->GetDisplayId(); + auto displayGroupId = windowFocusController_->GetDisplayGroupId(displayId); TLOGD(WmsLogTag::WMS_PIPELINE, "id: %{public}d, isFocused: %{public}d, reason: %{public}d, focusableOnShow: %{public}d", session->GetPersistentId(), session->GetPostProcessFocusState().isFocused_, session->GetPostProcessFocusState().reason_, session->IsFocusableOnShow()); - if (focusChanged) { + if (focusChangedSet.find(displayGroupId) != focusChangedSet.end()) { session->ResetPostProcessFocusState(); continue; } @@ -10249,7 +10393,7 @@ void SceneSessionManager::PostProcessFocus() session->ResetPostProcessFocusState(); // if succeed then end process if (ret == WSError::WS_OK) { - focusChanged = true; + focusChangedSet.insert(displayGroupId); } } } @@ -10359,14 +10503,6 @@ WSError SceneSessionManager::RaiseWindowToTop(int32_t persistentId) WSError SceneSessionManager::ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId) { WLOGFI("from id: %{public}d to id: %{public}d", sourcePersistentId, targetPersistentId); - if (sourcePersistentId != focusedSessionId_) { - WLOGFE("source session need be focused"); - return WSError::WS_ERROR_INVALID_OPERATION; - } - if (targetPersistentId == focusedSessionId_) { - WLOGFE("target session has been focused"); - return WSError::WS_DO_NOTHING; - } sptr sourceSession = nullptr; WSError ret = GetAppMainSceneSession(sourceSession, sourcePersistentId); if (ret != WSError::WS_OK) { @@ -10377,6 +10513,17 @@ WSError SceneSessionManager::ShiftAppWindowFocus(int32_t sourcePersistentId, int if (ret != WSError::WS_OK) { return ret; } + auto displayId = sourceSession->GetSessionProperty()->GetDisplayId(); + auto focusedSessionId = GetFocusedSessionId(displayId); + if (sourcePersistentId != focusedSessionId) { + WLOGFE("source session need be focused"); + return WSError::WS_ERROR_INVALID_OPERATION; + } + if (targetPersistentId == focusedSessionId) { + WLOGFE("target session has been focused"); + return WSError::WS_DO_NOTHING; + } + if (sourceSession->GetSessionInfo().bundleName_ != targetSession->GetSessionInfo().bundleName_) { WLOGFE("verify bundle failed, source name is %{public}s but target name is %{public}s)", sourceSession->GetSessionInfo().bundleName_.c_str(), targetSession->GetSessionInfo().bundleName_.c_str()); @@ -11431,14 +11578,15 @@ WMError SceneSessionManager::GetCallingWindowWindowStatus(int32_t persistentId, TLOGE(WmsLogTag::WMS_KEYBOARD, "sceneSession is null, persistentId: %{public}d", persistentId); return WMError::WM_ERROR_NULLPTR; } - + auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); + auto focusedSessionId = GetFocusedSessionId(displayId); TLOGD(WmsLogTag::WMS_KEYBOARD, "persistentId: %{public}d, windowType: %{public}d", persistentId, sceneSession->GetWindowType()); uint32_t callingWindowId = sceneSession->GetSessionProperty()->GetCallingSessionId(); auto callingSession = GetSceneSession(callingWindowId); if (callingSession == nullptr) { TLOGI(WmsLogTag::WMS_KEYBOARD, "callingsSession is null"); - callingSession = GetSceneSession(focusedSessionId_); + callingSession = GetSceneSession(focusedSessionId); if (callingSession == nullptr) { TLOGE(WmsLogTag::WMS_KEYBOARD, "callingsSession obtained through focusedSession fail"); return WMError::WM_ERROR_INVALID_WINDOW; @@ -11466,13 +11614,15 @@ WMError SceneSessionManager::GetCallingWindowRect(int32_t persistentId, Rect& re TLOGE(WmsLogTag::WMS_KEYBOARD, "sceneSession is null, persistentId: %{public}d", persistentId); return WMError::WM_ERROR_NULLPTR; } + auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); + auto focusedSessionId = GetFocusedSessionId(displayId); TLOGD(WmsLogTag::WMS_KEYBOARD, "persistentId: %{public}d, windowType: %{public}d", persistentId, sceneSession->GetWindowType()); uint32_t callingWindowId = sceneSession->GetSessionProperty()->GetCallingSessionId(); auto callingSession = GetSceneSession(callingWindowId); if (callingSession == nullptr) { TLOGI(WmsLogTag::WMS_KEYBOARD, "callingsSession is null"); - callingSession = GetSceneSession(focusedSessionId_); + callingSession = GetSceneSession(focusedSessionId); if (callingSession == nullptr) { TLOGE(WmsLogTag::WMS_KEYBOARD, "callingsSession obtained through focusedSession fail"); return WMError::WM_ERROR_INVALID_WINDOW; @@ -11754,7 +11904,7 @@ WMError SceneSessionManager::MakeScreenFoldData(const std::vector& } AppExecFwk::ElementName element = {}; WSError ret = GetFocusSessionElement(element); - auto sceneSession = GetSceneSession(focusedSessionId_); + auto sceneSession = GetSceneSession(windowFocusController_->GetFocusedSessionId(DEFAULT_DISPLAY_ID)); if (sceneSession == nullptr || ret != WSError::WS_OK) { TLOGI(WmsLogTag::DMS, "Error: fail to get focused package name."); return WMError::WM_DO_NOTHING; diff --git a/window_scene/session_manager/src/scene_session_manager_lite.cpp b/window_scene/session_manager/src/scene_session_manager_lite.cpp index 15e55da5c7..7ae9c0147d 100644 --- a/window_scene/session_manager/src/scene_session_manager_lite.cpp +++ b/window_scene/session_manager/src/scene_session_manager_lite.cpp @@ -119,16 +119,16 @@ WSError SceneSessionManagerLite::PendingSessionToBackgroundForDelegator(const sp return SceneSessionManager::GetInstance().PendingSessionToBackgroundForDelegator(token, shouldBackToCaller); } -WSError SceneSessionManagerLite::GetFocusSessionToken(sptr& token) +WSError SceneSessionManagerLite::GetFocusSessionToken(sptr& token, DisplayId displayId) { WLOGFD("in"); - return SceneSessionManager::GetInstance().GetFocusSessionToken(token); + return SceneSessionManager::GetInstance().GetFocusSessionToken(token, displayId); } -WSError SceneSessionManagerLite::GetFocusSessionElement(AppExecFwk::ElementName& element) +WSError SceneSessionManagerLite::GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId) { WLOGFD("in"); - return SceneSessionManager::GetInstance().GetFocusSessionElement(element); + return SceneSessionManager::GetInstance().GetFocusSessionElement(element, displayId); } WSError SceneSessionManagerLite::ClearSession(int32_t persistentId) @@ -168,9 +168,9 @@ WSError SceneSessionManagerLite::MoveSessionsToBackground(const std::vector lock(focusGroupMutex_); + if (displayId != DEFAULT_DISPLAY_ID && GetFocusGroupInner(displayId) != nullptr) { + TLOGW(WmsLogTag::WMS_FOCUS, "already had displayId: %{public}lu", displayId); + return WSError::WS_DO_NOTHING; + } + sptr focusGroup = sptr::MakeSptr(displayId); + focusGroupMap_.insert(std::make_pair(displayId, focusGroup)); + if (displayId != DEFAULT_DISPLAY_ID) { + virtualScreenDisplayIdSet_.emplace(displayId); + } + return WSError::WS_OK; +} + +WSError WindowFocusController::RemoveFocusGroup(DisplayId displayId) +{ + TLOGI(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu", displayId); + CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); + std::shared_lock lock(focusGroupMutex_); + focusGroupMap_.erase(displayId); + if (displayId != DEFAULT_DISPLAY_ID) { + virtualScreenDisplayIdSet_.erase(displayId); + } + return WSError::WS_OK; +} + +int32_t WindowFocusController::GetFocusedSessionId(DisplayId displayId) +{ + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu", displayId); + CHECK_DISPLAY_ID_RETURN(displayId, INVALID_SESSION_ID); + std::shared_lock lock(focusGroupMutex_); + auto focusGroup = GetFocusGroupInner(displayId); + if(focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}lu", displayId); + return INVALID_SESSION_ID; + } + return focusGroup->GetFocusedSessionId(); +} + +sptr WindowFocusController::GetFocusGroup(DisplayId displayId) +{ + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu", displayId); + if (displayId == DISPLAY_ID_INVALID) { + TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); + return nullptr; + } + std::shared_lock lock(focusGroupMutex_); + auto focusGroup = GetFocusGroupInner(displayId); + return focusGroup; +} + +sptr WindowFocusController::GetFocusGroupInner(DisplayId displayId) +{ + DisplayId displayGroupId = GetDisplayGroupId(displayId); + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu, displayGroupId: %{public}lu", displayId, displayGroupId); + if(displayGroupId == DEFAULT_DISPLAY_ID) { + return focusGroupMap_[DEFAULT_DISPLAY_ID]; + } + auto iter = focusGroupMap_.find(displayGroupId); + if (iter == focusGroupMap_.end()) { + TLOGE(WmsLogTag::WMS_FOCUS, "Not found focus group with displayId: %{public}lu", displayId); + return nullptr; + } + return iter->second; +} + +std::vector> WindowFocusController::GetAllFocusedSessionList() +{ + TLOGI(WmsLogTag::WMS_FOCUS, "in"); + std::unordered_map> focusGroupMapCopy; + { + std::shared_lock lock(focusGroupMutex_); + focusGroupMapCopy = focusGroupMap_; + } + std::vector> allFocusGroup; + for (const auto& elem : focusGroupMapCopy) { + auto curFocusGroup = elem.second; + if (curFocusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null"); + continue; + } + allFocusGroup.emplace_back(std::make_pair(elem.first, curFocusGroup->GetFocusedSessionId())); + } + TLOGD(WmsLogTag::WMS_FOCUS, "success, list size: %{public}lu", allFocusGroup.size()); + return allFocusGroup; +} + +WSError WindowFocusController::UpdateFocusedSessionId(DisplayId displayId, int32_t persistentId) +{ + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu, persistentId: %{public}d", displayId, persistentId); + CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); + std::unique_lock lock(focusGroupMutex_); + auto focusGroup = GetFocusGroupInner(displayId); + if(focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}lu", displayId); + return WSError::WS_ERROR_NULLPTR; + } + return focusGroup->UpdateFocusedSessionId(persistentId); +} + +WSError WindowFocusController::UpdateFocusedAppSessionId(DisplayId displayId, int32_t persistentId) +{ + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu, persistentId: %{public}d", displayId, persistentId); + CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); + std::unique_lock lock(focusGroupMutex_); + auto focusGroup = GetFocusGroupInner(displayId); + if(focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}d", displayId); + return WSError::WS_ERROR_NULLPTR; + } + return focusGroup->UpdateFocusedAppSessionId(persistentId); +} +} +} diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp index cbb3682a82..7dcf0ae1f1 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp @@ -452,7 +452,7 @@ WSError SceneSessionManagerLiteProxy::TerminateSessionNew(const sptr(reply.ReadInt32()); } -WSError SceneSessionManagerLiteProxy::GetFocusSessionToken(sptr& token) +WSError SceneSessionManagerLiteProxy::GetFocusSessionToken(sptr& token, DisplayId displayId) { WLOGFD("run SceneSessionManagerLiteProxy::GetFocusSessionToken"); MessageParcel data; @@ -462,7 +462,10 @@ WSError SceneSessionManagerLiteProxy::GetFocusSessionToken(sptr& WLOGFE("Write interfaceToken failed"); return WSError::WS_ERROR_IPC_FAILED; } - + if (!data.WriteUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); @@ -480,7 +483,7 @@ WSError SceneSessionManagerLiteProxy::GetFocusSessionToken(sptr& return static_cast(reply.ReadInt32()); } -WSError SceneSessionManagerLiteProxy::GetFocusSessionElement(AppExecFwk::ElementName& element) +WSError SceneSessionManagerLiteProxy::GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId) { WLOGFD("run SceneSessionManagerLiteProxy::GetFocusSessionElement"); MessageParcel data; @@ -490,6 +493,10 @@ WSError SceneSessionManagerLiteProxy::GetFocusSessionElement(AppExecFwk::Element WLOGFE("Write interfaceToken failed"); return WSError::WS_ERROR_IPC_FAILED; } + if (!data.WriteUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); @@ -760,7 +767,7 @@ WSError SceneSessionManagerLiteProxy::ClearAllSessions() return static_cast(reply.ReadInt32()); } -void SceneSessionManagerLiteProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo) +void SceneSessionManagerLiteProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId) { WLOGFD("get focus Winow info lite proxy"); MessageParcel data; @@ -770,7 +777,10 @@ void SceneSessionManagerLiteProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo WLOGFE("WriteInterfaceToken failed"); return; } - + if (!data.WriteUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed"); + return; + } sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); @@ -981,7 +991,7 @@ WMError SceneSessionManagerLiteProxy::GetWindowModeType(WindowModeType& windowMo WLOGFE("WriteInterfaceToken failed"); return WMError::WM_ERROR_IPC_FAILED; } - + MessageParcel reply; MessageOption option; sptr remote = Remote(); diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp index e469c76d9d..d50cb1aa48 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp @@ -373,7 +373,12 @@ int SceneSessionManagerLiteStub::HandleGetFocusSessionToken(MessageParcel& data, { WLOGFD("run HandleGetFocusSessionToken!"); sptr token = nullptr; - WSError errCode = GetFocusSessionToken(token); + uint64_t displayId = 0; + if (!data.ReadUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId"); + return ERR_INVALID_DATA; + } + WSError errCode = GetFocusSessionToken(token, displayId); reply.WriteRemoteObject(token); reply.WriteInt32(static_cast(errCode)); return ERR_NONE; @@ -383,7 +388,12 @@ int SceneSessionManagerLiteStub::HandleGetFocusSessionElement(MessageParcel& dat { WLOGFD("run HandleGetFocusSessionElement!"); AppExecFwk::ElementName element; - WSError errCode = GetFocusSessionElement(element); + uint64_t displayId = 0; + if (!data.ReadUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId"); + return ERR_INVALID_DATA; + } + WSError errCode = GetFocusSessionElement(element, displayId); reply.WriteParcelable(&element); reply.WriteInt32(static_cast(errCode)); return ERR_NONE; @@ -514,7 +524,12 @@ int SceneSessionManagerLiteStub::HandleGetFocusSessionInfo(MessageParcel& data, { WLOGFD("run"); FocusChangeInfo focusInfo; - GetFocusWindowInfo(focusInfo); + uint64_t displayId = 0; + if (!data.ReadUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId"); + return ERR_INVALID_DATA; + } + GetFocusWindowInfo(focusInfo, displayId); reply.WriteParcelable(&focusInfo); return ERR_NONE; } diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp index e2bb936eec..221147be76 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp @@ -612,7 +612,7 @@ WMError SceneSessionManagerProxy::SetGestureNavigationEnabled(bool enable) return static_cast(ret); } -void SceneSessionManagerProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo) +void SceneSessionManagerProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId) { MessageParcel data; MessageParcel reply; @@ -621,7 +621,10 @@ void SceneSessionManagerProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo) WLOGFE("WriteInterfaceToken failed"); return; } - + if (!data.WriteUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed"); + return; + } sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); @@ -1155,7 +1158,7 @@ WSError SceneSessionManagerProxy::TerminateSessionNew(const sptr(reply.ReadInt32()); } -WSError SceneSessionManagerProxy::GetFocusSessionToken(sptr& token) +WSError SceneSessionManagerProxy::GetFocusSessionToken(sptr& token, DisplayId displayId) { WLOGFD("run SceneSessionManagerProxy::GetFocusSessionToken"); MessageParcel data; @@ -1165,7 +1168,10 @@ WSError SceneSessionManagerProxy::GetFocusSessionToken(sptr& toke WLOGFE("Write interfaceToken failed"); return WSError::WS_ERROR_IPC_FAILED; } - + if (!data.WriteUint64(displayId)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write displayId failed"); + return WSError::WS_ERROR_IPC_FAILED; + } sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); @@ -1183,7 +1189,7 @@ WSError SceneSessionManagerProxy::GetFocusSessionToken(sptr& toke return static_cast(reply.ReadInt32()); } -WSError SceneSessionManagerProxy::GetFocusSessionElement(AppExecFwk::ElementName& element) +WSError SceneSessionManagerProxy::GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId) { WLOGFD("run SceneSessionManagerProxy::GetFocusSessionElement"); MessageParcel data; @@ -1193,6 +1199,10 @@ WSError SceneSessionManagerProxy::GetFocusSessionElement(AppExecFwk::ElementName WLOGFE("Write interfaceToken failed"); return WSError::WS_ERROR_IPC_FAILED; } + if (!data.WriteUint64(displayId)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write displayId failed"); + return WSError::WS_ERROR_IPC_FAILED; + } sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp index 9c71b18dc6..2943d6b5f9 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp @@ -420,7 +420,12 @@ int SceneSessionManagerStub::HandleGetFocusSessionInfo(MessageParcel& data, Mess { WLOGFD("run HandleGetFocusSessionInfo!"); FocusChangeInfo focusInfo; - GetFocusWindowInfo(focusInfo); + uint64_t displayId = 0; + if (!data.ReadUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId"); + return ERR_INVALID_DATA; + } + GetFocusWindowInfo(focusInfo, displayId); reply.WriteParcelable(&focusInfo); return ERR_NONE; } @@ -660,7 +665,12 @@ int SceneSessionManagerStub::HandleGetFocusSessionToken(MessageParcel& data, Mes { WLOGFD("run HandleGetFocusSessionToken!"); sptr token = nullptr; - WSError errCode = GetFocusSessionToken(token); + uint64_t displayId = 0; + if (!data.ReadUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId"); + return ERR_INVALID_DATA; + } + WSError errCode = GetFocusSessionToken(token, displayId); reply.WriteRemoteObject(token); reply.WriteInt32(static_cast(errCode)); return ERR_NONE; @@ -670,7 +680,12 @@ int SceneSessionManagerStub::HandleGetFocusSessionElement(MessageParcel& data, M { WLOGFD("run HandleGetFocusSessionElement!"); AppExecFwk::ElementName element; - WSError errCode = GetFocusSessionElement(element); + uint64_t displayId = 0; + if (!data.ReadUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId"); + return ERR_INVALID_DATA; + } + WSError errCode = GetFocusSessionElement(element, displayId); reply.WriteParcelable(&element); reply.WriteInt32(static_cast(errCode)); return ERR_NONE; diff --git a/window_scene/test/unittest/intention_event_manager_test.cpp b/window_scene/test/unittest/intention_event_manager_test.cpp index 29e004b542..6febf911e1 100644 --- a/window_scene/test/unittest/intention_event_manager_test.cpp +++ b/window_scene/test/unittest/intention_event_manager_test.cpp @@ -156,11 +156,11 @@ HWTEST_F(IntentionEventManagerTest, OnInputEvent1, Function | MediumTest | Level inputEventListener_->OnInputEvent(keyEvent); SceneSessionManager::GetInstance().SetEnableInputEvent(true); - SceneSessionManager::GetInstance().SetFocusedSessionId(INVALID_SESSION_ID); + SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, INVALID_SESSION_ID); EXPECT_EQ(INVALID_SESSION_ID, SceneSessionManager::GetInstance().GetFocusedSessionId()); inputEventListener_->OnInputEvent(keyEvent); - SceneSessionManager::GetInstance().SetFocusedSessionId(1); + SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, 1); inputEventListener_->OnInputEvent(keyEvent); SessionInfo info; @@ -180,7 +180,7 @@ HWTEST_F(IntentionEventManagerTest, OnInputEvent1, Function | MediumTest | Level sptr sceneSession1 = sptr::MakeSptr(info, callback); EXPECT_NE(nullptr, sceneSession1); SceneSessionManager::GetInstance().sceneSessionMap_.emplace(std::make_pair(2, sceneSession1)); - SceneSessionManager::GetInstance().SetFocusedSessionId(2); + SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, 2); EXPECT_EQ(2, SceneSessionManager::GetInstance().GetFocusedSessionId()); auto focusedSceneSession = SceneSessionManager::GetInstance().GetSceneSession(2); inputEventListener_->OnInputEvent(keyEvent); @@ -197,7 +197,7 @@ HWTEST_F(IntentionEventManagerTest, OnInputEvent2, Function | MediumTest | Level std::shared_ptr keyEvent = MMI::KeyEvent::Create(); EXPECT_NE(nullptr, keyEvent); SceneSessionManager::GetInstance().SetEnableInputEvent(true); - SceneSessionManager::GetInstance().SetFocusedSessionId(1); + SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, 1); SessionInfo info; info.bundleName_ = "IntentionEventManager"; info.moduleName_ = "InputEventListener"; @@ -235,7 +235,7 @@ HWTEST_F(IntentionEventManagerTest, OnInputEvent3, Function | MediumTest | Level std::shared_ptr keyEvent = MMI::KeyEvent::Create(); EXPECT_NE(nullptr, keyEvent); SceneSessionManager::GetInstance().SetEnableInputEvent(true); - SceneSessionManager::GetInstance().SetFocusedSessionId(1); + SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, 1); SessionInfo info; info.bundleName_ = "IntentionEventManager"; info.moduleName_ = "InputEventListener"; diff --git a/window_scene/test/unittest/scene_input_manager_test.cpp b/window_scene/test/unittest/scene_input_manager_test.cpp index a60d2f73c4..20f4a119c3 100644 --- a/window_scene/test/unittest/scene_input_manager_test.cpp +++ b/window_scene/test/unittest/scene_input_manager_test.cpp @@ -345,7 +345,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate1, Function | SmallTest | Level3) std::vector displayInfos; std::vector windowInfoList; int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); SceneInputManager::GetInstance().lastFocusId_ = 1; bool ret1 = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList); ASSERT_TRUE(ret1); @@ -376,7 +376,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate2, Function | SmallTest | Level3) displayInfos.emplace_back(displayinfo); MMI::WindowInfo windowinfo; int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; @@ -442,7 +442,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate3, Function | SmallTest | Level3) MMI::WindowInfo windowinfo; windowInfoList.emplace_back(windowinfo); int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; @@ -498,7 +498,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate4, Function | SmallTest | Level3) MMI::WindowInfo windowinfo; windowInfoList.emplace_back(windowinfo); int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; @@ -551,7 +551,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate5, Function | SmallTest | Level3) MMI::WindowInfo windowinfo; windowInfoList.emplace_back(windowinfo); int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; @@ -603,7 +603,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate6, Function | SmallTest | Level3) MMI::WindowInfo windowinfo; windowInfoList.emplace_back(windowinfo); int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; @@ -659,7 +659,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate7, Function | SmallTest | Level3) MMI::WindowInfo windowinfo; windowInfoList.emplace_back(windowinfo); int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; diff --git a/window_scene/test/unittest/scene_session_manager_test10.cpp b/window_scene/test/unittest/scene_session_manager_test10.cpp index af3deeb717..10890674dd 100644 --- a/window_scene/test/unittest/scene_session_manager_test10.cpp +++ b/window_scene/test/unittest/scene_session_manager_test10.cpp @@ -381,13 +381,14 @@ HWTEST_F(SceneSessionManagerTest10, TestCheckLastFocusedAppSessionFocus_02, Func info2.windowType_ = 1; sptr nextSession = sptr::MakeSptr(info2, nullptr); - ssm_->lastFocusedAppSessionId_ = 124; + ssm_->windowFocusController_->UpdateFocusedAppSessionId(DEFAULT_DISPLAY_ID, 124); focusedSession->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); ASSERT_EQ(false, ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession)); nextSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); ASSERT_EQ(false, ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession)); - ASSERT_EQ(0, ssm_->lastFocusedAppSessionId_); + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + ASSERT_EQ(0, focusGroup->GetLastFocusedAppSessionId()); } /** @@ -897,7 +898,7 @@ HWTEST_F(SceneSessionManagerTest10, ProcessUpdateLastFocusedAppId, Function | Sm { ssm_->sceneSessionMap_.clear(); std::vector zOrderList; - ssm_->lastFocusedAppSessionId_ = INVALID_SESSION_ID; + ssm_->windowFocusController_->UpdateFocusedAppSessionId(DEFAULT_DISPLAY_ID, INVALID_SESSION_ID); ssm_->ProcessUpdateLastFocusedAppId(zOrderList); SessionInfo sessionInfo; @@ -905,15 +906,16 @@ HWTEST_F(SceneSessionManagerTest10, ProcessUpdateLastFocusedAppId, Function | Sm sessionInfo.abilityName_ = "lastFocusedAppSession"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ssm_->sceneSessionMap_.emplace(1, sceneSession); - ssm_->lastFocusedAppSessionId_ = 1; + ssm_->windowFocusController_->UpdateFocusedAppSessionId(DEFAULT_DISPLAY_ID, 1); sceneSession->zOrder_ = 101; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); ssm_->ProcessUpdateLastFocusedAppId(zOrderList); - ASSERT_EQ(1, ssm_->lastFocusedAppSessionId_); + ASSERT_EQ(1, focusGroup->GetLastFocusedAppSessionId()); zOrderList.push_back(103); ssm_->ProcessUpdateLastFocusedAppId(zOrderList); - ASSERT_EQ(INVALID_SESSION_ID, ssm_->lastFocusedAppSessionId_); + ASSERT_EQ(INVALID_SESSION_ID, focusGroup->GetLastFocusedAppSessionId()); } /** @@ -982,7 +984,7 @@ HWTEST_F(SceneSessionManagerTest10, TestIsNeedSkipWindowModeTypeCheck_04, Functi sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sceneSession->SetRSVisible(true); sceneSession->SetSessionState(SessionState::STATE_FOREGROUND); - + DisplayId displayId = 1001; sceneSession->property_->SetDisplayId(displayId); auto ret = ssm_->IsNeedSkipWindowModeTypeCheck(sceneSession, true); diff --git a/window_scene/test/unittest/scene_session_manager_test3.cpp b/window_scene/test/unittest/scene_session_manager_test3.cpp index 24cb0409a6..03185130e6 100644 --- a/window_scene/test/unittest/scene_session_manager_test3.cpp +++ b/window_scene/test/unittest/scene_session_manager_test3.cpp @@ -1319,10 +1319,10 @@ HWTEST_F(SceneSessionManagerTest3, SetFocusedSessionId, Function | SmallTest | L int32_t focusedSession = ssm_->GetFocusedSessionId(); EXPECT_EQ(focusedSession, INVALID_SESSION_ID); int32_t persistentId = INVALID_SESSION_ID; - WSError result01 = ssm_->SetFocusedSessionId(persistentId); + WSError result01 = ssm_->SetFocusedSessionId(DEFAULT_DISPLAY_ID, persistentId); EXPECT_EQ(result01, WSError::WS_DO_NOTHING); persistentId = 10086; - WSError result02 = ssm_->SetFocusedSessionId(persistentId); + WSError result02 = ssm_->SetFocusedSessionId(DEFAULT_DISPLAY_ID, persistentId); EXPECT_EQ(result02, WSError::WS_OK); ASSERT_EQ(ssm_->GetFocusedSessionId(), 10086); } @@ -1386,10 +1386,10 @@ HWTEST_F(SceneSessionManagerTest3, NotifyRequestFocusStatusNotifyManager, Functi HWTEST_F(SceneSessionManagerTest3, GetTopNearestBlockingFocusSession, Function | SmallTest | Level3) { uint32_t zOrder = 9999; - sptr session = ssm_->GetTopNearestBlockingFocusSession(zOrder, true); + sptr session = ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, zOrder, true); EXPECT_EQ(session, nullptr); - session = ssm_->GetTopNearestBlockingFocusSession(zOrder, false); + session = ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, zOrder, false); EXPECT_EQ(session, nullptr); } @@ -1421,16 +1421,29 @@ HWTEST_F(SceneSessionManagerTest3, ShiftAppWindowFocus, Function | SmallTest | L { int32_t focusedSession = ssm_->GetFocusedSessionId(); EXPECT_EQ(focusedSession, 10086); - int32_t sourcePersistentId = INVALID_SESSION_ID; - int32_t targetPersistentId = INVALID_SESSION_ID; + int32_t sourcePersistentId = 1; + int32_t targetPersistentId = 10086; WSError result01 = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); + EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_SESSION); + SessionInfo info; + info.abilityName_ = "ShiftAppWindowFocus"; + info.bundleName_ = "ShiftAppWindowFocus"; + auto sourceSceneSession = sptr::MakeSptr(info, nullptr); + sourceSceneSession->persistent_ = 1; + sourceSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + ssm_->sceneSessionMap_.insert(std::make_pair(1, sourceSceneSession)); + result01 = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); + EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_SESSION); + + auto targetSceneSession = sptr::MakeSptr(info, nullptr); + targetSceneSession->persistent_ = 10086; + targetSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + ssm_->sceneSessionMap_.insert(std::make_pair(10086, sourceSceneSession)); + result01 = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_OPERATION); - targetPersistentId = 1; + sourcePersistentId = 10086; WSError result02 = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); - EXPECT_EQ(result02, WSError::WS_ERROR_INVALID_OPERATION); - sourcePersistentId = 1; - WSError result03 = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); - EXPECT_EQ(result03, WSError::WS_ERROR_INVALID_OPERATION); + EXPECT_EQ(result02, WSError::WS_DO_NOTHING); } /** diff --git a/window_scene/test/unittest/scene_session_manager_test4.cpp b/window_scene/test/unittest/scene_session_manager_test4.cpp index 1ff4c23b22..5e7cb6dda7 100644 --- a/window_scene/test/unittest/scene_session_manager_test4.cpp +++ b/window_scene/test/unittest/scene_session_manager_test4.cpp @@ -1233,23 +1233,18 @@ HWTEST_F(SceneSessionManagerTest4, GetAccessibilityWindowInfo, Function | SmallT HWTEST_F(SceneSessionManagerTest4, ShiftAppWindowFocus02, Function | SmallTest | Level3) { ASSERT_NE(ssm_, nullptr); - ssm_->SetFocusedSessionId(INVALID_SESSION_ID); + ssm_->SetFocusedSessionId(DEFAULT_DISPLAY_ID, INVALID_SESSION_ID); int32_t sourcePersistentId = INVALID_SESSION_ID; - int32_t targetPersistentId = INVALID_SESSION_ID; - auto result = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); - EXPECT_EQ(result, WSError::WS_DO_NOTHING); + int32_t targetPersistentId = 1; - targetPersistentId = 1; - result = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); + auto result = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); EXPECT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); SessionInfo info; info.abilityName_ = "abilityName"; info.bundleName_ = "bundleName"; sptr sceneSession = sptr::MakeSptr(info, nullptr); - ASSERT_NE(sceneSession, nullptr); ssm_->sceneSessionMap_.insert(std::make_pair(INVALID_SESSION_ID, sceneSession)); - ASSERT_NE(sceneSession->property_, nullptr); sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); result = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); EXPECT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); @@ -1258,9 +1253,7 @@ HWTEST_F(SceneSessionManagerTest4, ShiftAppWindowFocus02, Function | SmallTest | info01.abilityName_ = "abilityName01"; info01.bundleName_ = "bundleName01"; sptr sceneSession01 = sptr::MakeSptr(info01, nullptr); - ASSERT_NE(sceneSession01, nullptr); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession01)); - ASSERT_NE(sceneSession01->property_, nullptr); sceneSession01->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); result = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); EXPECT_EQ(result, WSError::WS_ERROR_INVALID_CALLING); @@ -1765,7 +1758,7 @@ HWTEST_F(SceneSessionManagerTest4, GetNextFocusableSession, Function | SmallTest ssm_->sceneSessionMap_.insert(std::make_pair(3, sceneSession03)); ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession04)); ssm_->sceneSessionMap_.insert(std::make_pair(5, sceneSession05)); - sptr result = ssm_->GetNextFocusableSession(1); + sptr result = ssm_->GetNextFocusableSession(DEFAULT_DISPLAY_ID, 1); EXPECT_EQ(result, sceneSession); } @@ -1815,10 +1808,10 @@ HWTEST_F(SceneSessionManagerTest4, GetTopNearestBlockingFocusSession, Function | ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession04)); ssm_->sceneSessionMap_.insert(std::make_pair(8, parentSceneSession)); - sptr ret = ssm_->GetTopNearestBlockingFocusSession(0, true); + sptr ret = ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 0, true); EXPECT_EQ(ret, sceneSession01); - ret = ssm_->GetTopNearestBlockingFocusSession(10, true); + ret = ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 10, true); EXPECT_EQ(ret, nullptr); } @@ -1837,7 +1830,7 @@ HWTEST_F(SceneSessionManagerTest4, RequestFocusSpecificCheck, Function | SmallTe bool byForeground = true; FocusChangeReason reason = FocusChangeReason::CLIENT_REQUEST; sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED); - WSError result = ssm_->RequestFocusSpecificCheck(sceneSession, byForeground, reason); + WSError result = ssm_->RequestFocusSpecificCheck(DEFAULT_DISPLAY_ID, sceneSession, byForeground, reason); EXPECT_EQ(result, WSError::WS_ERROR_INVALID_OPERATION); sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN); @@ -1845,7 +1838,7 @@ HWTEST_F(SceneSessionManagerTest4, RequestFocusSpecificCheck, Function | SmallTe ASSERT_NE(sceneSession01, nullptr); ssm_->sceneSessionMap_.insert(std::make_pair(0, sceneSession01)); sceneSession01->parentSession_ = sceneSession; - result = ssm_->RequestFocusSpecificCheck(sceneSession, byForeground, reason); + result = ssm_->RequestFocusSpecificCheck(DEFAULT_DISPLAY_ID, sceneSession, byForeground, reason); EXPECT_EQ(result, WSError::WS_OK); } diff --git a/window_scene/test/unittest/scene_session_manager_test5.cpp b/window_scene/test/unittest/scene_session_manager_test5.cpp index 1a74b26db2..56245c8b8c 100644 --- a/window_scene/test/unittest/scene_session_manager_test5.cpp +++ b/window_scene/test/unittest/scene_session_manager_test5.cpp @@ -735,13 +735,35 @@ HWTEST_F(SceneSessionManagerTest5, UpdateFocusStatus, Function | SmallTest | Lev info.abilityName_ = "test1"; info.bundleName_ = "test2"; sptr sceneSession = nullptr; - ssm_->UpdateFocusStatus(sceneSession, false); - ssm_->UpdateFocusStatus(sceneSession, true); + ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, false); + ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, true); sptr sceneSession1 = sptr::MakeSptr(info, nullptr); ASSERT_NE(sceneSession1, nullptr); - ssm_->UpdateFocusStatus(sceneSession1, true); - ssm_->UpdateFocusStatus(sceneSession1, false); + ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession1, true); + ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession1, false); +} + +/** + * @tc.name: UpdateFocusStatus01 + * @tc.desc: UpdateFocusStatus + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest5, UpdateFocusStatus01, Function | SmallTest | Level3) +{ + ASSERT_NE(ssm_, nullptr); + sptr sceneSession = nullptr; + ssm_->focusedSessionId_ = 1; + + ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, false); + ASSERT_EQ(ssm_->focusedSessionId_, 1); + ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; + ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, true); + ASSERT_NE(ssm_->focusedSessionId_, 1); + ssm_->focusedSessionId_ = 1; + ssm_->needBlockNotifyFocusStatusUntilForeground_ = true; + ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, true); + ASSERT_NE(ssm_->focusedSessionId_, 1); } /** @@ -770,7 +792,7 @@ HWTEST_F(SceneSessionManagerTest5, RequestSessionUnfocus, Function | SmallTest | sceneSession1->persistentId_ = 1; focusedSession->persistentId_ = 2; focusedSession->property_->parentPersistentId_ = 1; - ssm_->focusedSessionId_ = 1; + ssm_->windowFocusController_->UpdateFocusedSessionId(DEFAULT_DISPLAY_ID, 1); ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1}); ssm_->sceneSessionMap_.insert({focusedSession->GetPersistentId(), focusedSession}); ret = ssm_->RequestSessionUnfocus(1, reason); @@ -796,11 +818,11 @@ HWTEST_F(SceneSessionManagerTest5, RequestFocusSpecificCheck, Function | SmallTe ASSERT_NE(sceneSession1, nullptr); FocusChangeReason reason = FocusChangeReason::MOVE_UP; property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - WSError ret = ssm_->RequestFocusSpecificCheck(sceneSession1, true, reason); + WSError ret = ssm_->RequestFocusSpecificCheck(DEFAULT_DISPLAY_ID, sceneSession1, true, reason); EXPECT_EQ(ret, WSError::WS_OK); FocusChangeReason reason1 = FocusChangeReason::SPLIT_SCREEN; property->SetWindowType(WindowType::APP_WINDOW_BASE); - ret = ssm_->RequestFocusSpecificCheck(sceneSession1, true, reason1); + ret = ssm_->RequestFocusSpecificCheck(DEFAULT_DISPLAY_ID, sceneSession1, true, reason1); EXPECT_EQ(ret, WSError::WS_OK); } @@ -815,12 +837,13 @@ HWTEST_F(SceneSessionManagerTest5, NotifyFocusStatus, Function | SmallTest | Lev info.abilityName_ = "test1"; info.bundleName_ = "test2"; sptr sceneSession = nullptr; - ssm_->NotifyFocusStatus(sceneSession, true); + auto focusGroup = sptr::MakeSptr(DEFAULT_DISPLAY_ID); + ssm_->NotifyFocusStatus(sceneSession, true, focusGroup); sptr sceneSession1 = sptr::MakeSptr(info, nullptr); ASSERT_NE(sceneSession1, nullptr); - ssm_->NotifyFocusStatus(sceneSession1, false); + ssm_->NotifyFocusStatus(sceneSession1, false, focusGroup); info.isSystem_ = true; - ssm_->NotifyFocusStatus(sceneSession1, true); + ssm_->NotifyFocusStatus(sceneSession1, true, focusGroup); } /** @@ -882,12 +905,13 @@ HWTEST_F(SceneSessionManagerTest5, RequestSessionFocusImmediately, Function | Sm sptr sceneSession = nullptr; WSError ret = ssm_->RequestSessionFocusImmediately(0); ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION); - ssm_->RequestFocusBasicCheck(0); + auto focusGroup = sptr::MakeSptr(DEFAULT_DISPLAY_ID); + ssm_->RequestFocusBasicCheck(0, focusGroup); sptr sceneSession1 = sptr::MakeSptr(info, nullptr); ASSERT_NE(sceneSession1, nullptr); ret = ssm_->RequestSessionFocusImmediately(1); ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION); - ssm_->RequestFocusBasicCheck(1); + ssm_->RequestFocusBasicCheck(1, focusGroup); } /** @@ -897,12 +921,16 @@ HWTEST_F(SceneSessionManagerTest5, RequestSessionFocusImmediately, Function | Sm */ HWTEST_F(SceneSessionManagerTest5, RequestFocusBasicCheck, Function | SmallTest | Level3) { - ssm_->focusedSessionId_ = 1; - WSError ret = ssm_->RequestFocusBasicCheck(0); + sptr focusGroup = nullptr; + WSError ret = ssm_->RequestFocusBasicCheck(0, focusGroup); + ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION); + WSError ret = ssm_->RequestFocusBasicCheck(1, focusGroup); ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION); - ret = ssm_->RequestFocusBasicCheck(1); + focusGroup = sptr::MakeSptr(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); + ret = ssm_->RequestFocusBasicCheck(1, focusGroup); ASSERT_EQ(ret, WSError::WS_DO_NOTHING); - ret = ssm_->RequestFocusBasicCheck(2); + ret = ssm_->RequestFocusBasicCheck(2, focusGroup); ASSERT_EQ(ret, WSError::WS_OK); } @@ -1004,7 +1032,7 @@ HWTEST_F(SceneSessionManagerTest5, CheckRequestFocusImmdediately, Function | Sma sptr session = sptr::MakeSptr(info); session->persistentId_ = 1; sceneSession->dialogVec_.push_back(session); - ssm_->focusedSessionId_ = 1; + ssm_->windowFocusController_->UpdateFocusedSessionId(DEFAULT_DISPLAY_ID, 1); ret = ssm_->CheckRequestFocusImmdediately(sceneSession); ASSERT_EQ(ret, true); } @@ -1024,13 +1052,13 @@ HWTEST_F(SceneSessionManagerTest5, GetNextFocusableSession, Function | SmallTest sptr sceneSession = sptr::MakeSptr(info, nullptr); ASSERT_NE(sceneSession, nullptr); - sptr result = ssm_->GetNextFocusableSession(persistentId); + sptr result = ssm_->GetNextFocusableSession(DEFAULT_DISPLAY_ID, persistentId); ASSERT_EQ(result, nullptr); sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); persistentId = 1; - result = ssm_->GetNextFocusableSession(persistentId); + result = ssm_->GetNextFocusableSession(DEFAULT_DISPLAY_ID, persistentId); ASSERT_EQ(result, nullptr); } @@ -1046,19 +1074,19 @@ HWTEST_F(SceneSessionManagerTest5, GetTopNearestBlockingFocusSession, Function | info.abilityName_ = "test1"; info.bundleName_ = "test2"; - ssm_->GetTopNearestBlockingFocusSession(2, true); + ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 2, true); sptr sceneSession = sptr::MakeSptr(info, nullptr); ASSERT_NE(sceneSession, nullptr); - ssm_->GetTopNearestBlockingFocusSession(0, true); + ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 0, true); Session session = Session(info); session.property_ = nullptr; - ssm_->GetTopNearestBlockingFocusSession(0, true); + ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 0, true); sptr session_ = nullptr; - ssm_->GetTopNearestBlockingFocusSession(0, true); + ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 0, true); session_ = sptr::MakeSptr(info, nullptr); ASSERT_NE(session_, nullptr); - ssm_->GetTopNearestBlockingFocusSession(0, true); + ssm_->GetTopNearestBlockingFocusSession(DEFAULT_DISPLAY_ID, 0, true); } /** @@ -1575,18 +1603,54 @@ HWTEST_F(SceneSessionManagerTest5, RequestFocusStatusBySCB, Function | SmallTest ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession}); FocusChangeReason reason = FocusChangeReason::FOREGROUND; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); ssm_->RequestFocusStatusBySCB(1, true, false, reason); usleep(WAIT_SYNC_IN_NS); - ASSERT_EQ(ssm_->focusedSessionId_, 1); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1); reason = FocusChangeReason::CLICK; ssm_->RequestFocusStatusBySCB(1, true, false, reason); usleep(WAIT_SYNC_IN_NS); - ASSERT_EQ(ssm_->focusedSessionId_, 1); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1); +} + +/** + * @tc.name: RequestFocusStatusBySCB01 + * @tc.desc: SceneSessionManager request focus status from SCB + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest5, RequestFocusStatusBySCB01, Function | SmallTest | Level3) +{ + ssm_->sceneSessionMap_.clear(); + SessionInfo info; + info.abilityName_ = "RequestFocusTest"; + info.bundleName_ = "RequestFocusTest"; + sptr property = sptr::MakeSptr(); + property->SetFocusable(true); + property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + sptr sceneSession = sptr::MakeSptr(info, nullptr); + sceneSession->property_ = property; + sceneSession->persistentId_ = 1; + sceneSession->isVisible_ = true; + sceneSession->state_ = SessionState::STATE_ACTIVE; + ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession}); + + sptr sceneSession1 = sptr::MakeSptr(info, nullptr); + sceneSession1->property->SetFocusable(true); + sceneSession1->property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + sceneSession1->persistentId_ = 2; + sceneSession1->isVisible_ = true; + sceneSession1->state_ = SessionState::STATE_ACTIVE; + ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1}); + FocusChangeReason reason = FocusChangeReason::FOREGROUND; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + ssm_->RequestFocusStatusBySCB(2, true, false, reason); + usleep(WAIT_SYNC_IN_NS); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 2); ssm_->RequestFocusStatusBySCB(1, false, false, reason); usleep(WAIT_SYNC_IN_NS); - ASSERT_NE(ssm_->focusedSessionId_, 1); + ASSERT_NE(focusGroup->GetFocusedSessionId(), 1); reason = FocusChangeReason::MOVE_UP; ssm_->RequestFocusStatusBySCB(1, true, false, reason); @@ -1597,7 +1661,7 @@ HWTEST_F(SceneSessionManagerTest5, RequestFocusStatusBySCB, Function | SmallTest reason = FocusChangeReason::DEFAULT; ssm_->RequestFocusStatusBySCB(1, true, false, reason); usleep(WAIT_SYNC_IN_NS); - ASSERT_EQ(ssm_->focusedSessionId_, 1); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1); } } diff --git a/window_scene/test/unittest/scene_session_manager_test8.cpp b/window_scene/test/unittest/scene_session_manager_test8.cpp index 33cbc88d1d..c93156d3c6 100644 --- a/window_scene/test/unittest/scene_session_manager_test8.cpp +++ b/window_scene/test/unittest/scene_session_manager_test8.cpp @@ -50,7 +50,7 @@ void SceneSessionManagerTest8::TearDownTestCase() void SceneSessionManagerTest8::SetUp() { - ssm_ = sptr::MakeSptr(); + ssm_ = &SceneSessionManager::GetInstance(); EXPECT_NE(nullptr, ssm_); ssm_->sceneSessionMap_.clear(); } @@ -556,7 +556,7 @@ HWTEST_F(SceneSessionManagerTest8, SetBrightness, Function | SmallTest | Level3) ssm_->Init(); ASSERT_NE(nullptr, ssm_->eventHandler_); - ssm_->SetFocusedSessionId(2024); + ssm_->SetFocusedSessionId(DEFAULT_DISPLAY_ID, 2024); EXPECT_EQ(2024, ssm_->GetFocusedSessionId()); ret = ssm_->SetBrightness(sceneSession, 3.15f); @@ -890,7 +890,7 @@ HWTEST_F(SceneSessionManagerTest8, OnSessionStateChange01, Function | SmallTest property->SetWindowType(WindowType::APP_MAIN_WINDOW_END); ssm_->OnSessionStateChange(100, state); - + auto ret = ssm_->UpdateMaximizeMode(1, true); EXPECT_EQ(WSError::WS_OK, ret); constexpr uint32_t NOT_WAIT_SYNC_IN_NS = 500000; diff --git a/window_scene/test/unittest/scene_session_manager_test9.cpp b/window_scene/test/unittest/scene_session_manager_test9.cpp index 3f5b69a269..cf0dcd8a0d 100644 --- a/window_scene/test/unittest/scene_session_manager_test9.cpp +++ b/window_scene/test/unittest/scene_session_manager_test9.cpp @@ -208,7 +208,7 @@ HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_04, Functi sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestSessionFocusImmediately02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); - + sceneSession->SetFocusable(true); sceneSession->SetFocusedOnShow(false); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); @@ -230,7 +230,7 @@ HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_05, Functi sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestSessionFocusImmediately02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); - + sceneSession->SetFocusable(true); sceneSession->SetFocusedOnShow(true); sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED); @@ -253,7 +253,7 @@ HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_06, Functi sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestSessionFocusImmediately02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); - + sceneSession->SetFocusable(true); sceneSession->SetFocusedOnShow(true); sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN); @@ -499,15 +499,16 @@ HWTEST_F(SceneSessionManagerTest9, RequestSessionUnfocus02, Function | SmallTest ssm_->sceneSessionMap_.clear(); WSError ret = ssm_->RequestSessionUnfocus(0, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION); - ret = ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT); - ASSERT_EQ(ret, WSError::WS_DO_NOTHING); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestSessionUnfocus02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); - ASSERT_NE(nullptr, sceneSession); - ssm_->focusedSessionId_ = 2; + ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); + ssm_->windowFocusController_->UpdateFocusedSessionId(DEFAULT_DISPLAY_ID, 0); + ret = ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT); + ASSERT_EQ(ret, WSError::WS_DO_NOTHING); + ssm_->windowFocusController_->UpdateFocusedSessionId(DEFAULT_DISPLAY_ID, 2); sceneSession->persistentId_ = 1; sceneSession->SetZOrder(50); sceneSession->state_ = SessionState::STATE_FOREGROUND; @@ -1059,7 +1060,7 @@ HWTEST_F(SceneSessionManagerTest9, CheckClickFocusIsDownThroughFullScreen, Funct ASSERT_NE(sceneSession, nullptr); bool ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, false); - + focusedSession->property_->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH); ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, false); @@ -1092,7 +1093,7 @@ HWTEST_F(SceneSessionManagerTest9, ShiftFocus, Function | SmallTest | Level3) ssm_->sceneSessionMap_.insert({1, focusedSession}); ssm_->sceneSessionMap_.insert({4, nextSession}); ssm_->focusedSessionId_ = 1; - WSError ret = ssm_->ShiftFocus(nextSession, FocusChangeReason::DEFAULT); + WSError ret = ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, nextSession, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_OK); ASSERT_EQ(focusedSession->isFocused_, false); ASSERT_EQ(nextSession->isFocused_, true); diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 5edecc5325..41826999e7 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -94,7 +94,7 @@ public: std::vector>& targets); virtual void SetMaximizeMode(MaximizeMode maximizeMode); virtual MaximizeMode GetMaximizeMode(); - virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo); + virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID); virtual WMError UpdateSessionAvoidAreaListener(int32_t persistentId, bool haveListener); virtual WMError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener); virtual WMError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible); diff --git a/wm/include/window_adapter_lite.h b/wm/include/window_adapter_lite.h index 3df7a12aff..85e052f600 100644 --- a/wm/include/window_adapter_lite.h +++ b/wm/include/window_adapter_lite.h @@ -36,7 +36,7 @@ class WindowAdapterLite { WM_DECLARE_SINGLE_INSTANCE(WindowAdapterLite); public: using WMSConnectionChangedCallbackFunc = std::function; - virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo); + virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID); virtual WMError RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent); virtual WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 5280938ae3..e0281fc0af 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -686,13 +686,17 @@ MaximizeMode WindowAdapter::GetMaximizeMode() return wmsProxy->GetMaximizeMode(); } -void WindowAdapter::GetFocusWindowInfo(FocusChangeInfo& focusInfo) +void WindowAdapter::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId) { INIT_PROXY_CHECK_RETURN(); auto wmsProxy = GetWindowManagerServiceProxy(); CHECK_PROXY_RETURN_IF_NULL(wmsProxy); - wmsProxy->GetFocusWindowInfo(focusInfo); + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + wmsProxy->GetFocusWindowInfo(focusInfo, displayId); + } else { + wmsProxy->GetFocusWindowInfo(focusInfo); + } } WMError WindowAdapter::UpdateSessionAvoidAreaListener(int32_t persistentId, bool haveListener) diff --git a/wm/src/window_adapter_lite.cpp b/wm/src/window_adapter_lite.cpp index 2363cf449e..7a7f65ee99 100644 --- a/wm/src/window_adapter_lite.cpp +++ b/wm/src/window_adapter_lite.cpp @@ -195,14 +195,18 @@ void WMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) SingletonContainer::Get().ClearSessionManagerProxy(); } -void WindowAdapterLite::GetFocusWindowInfo(FocusChangeInfo& focusInfo) +void WindowAdapterLite::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId) { INIT_PROXY_CHECK_RETURN(); WLOGFD("use Foucus window info proxy"); auto wmsProxy = GetWindowManagerServiceProxy(); CHECK_PROXY_RETURN_IF_NULL(wmsProxy); - wmsProxy->GetFocusWindowInfo(focusInfo); + if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { + wmsProxy->GetFocusWindowInfo(focusInfo, displayId); + } else { + wmsProxy->GetFocusWindowInfo(focusInfo); + } } WMError WindowAdapterLite::GetWindowModeType(WindowModeType& windowModeType) diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index 77eaf6998a..c6018ee00e 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -1033,9 +1033,9 @@ WMError WindowManager::NotifyDisplayInfoChange(const sptr& token, return WMError::WM_OK; } -void WindowManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo) +void WindowManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId) { - SingletonContainer::Get().GetFocusWindowInfo(focusInfo); + SingletonContainer::Get().GetFocusWindowInfo(focusInfo, displayId); } void WindowManager::OnWMSConnectionChanged(int32_t userId, int32_t screenId, bool isConnected) const diff --git a/wm/src/window_manager_lite.cpp b/wm/src/window_manager_lite.cpp index 7964ae82d1..aaf93a14f8 100644 --- a/wm/src/window_manager_lite.cpp +++ b/wm/src/window_manager_lite.cpp @@ -389,10 +389,10 @@ WMError WindowManagerLite::UnregisterVisibilityChangedListener(const sptr().GetFocusWindowInfo(focusInfo); + SingletonContainer::Get().GetFocusWindowInfo(focusInfo, displayId); } void WindowManagerLite::UpdateFocusChangeInfo(const sptr& focusChangeInfo, bool focused) const diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index a7e25ad390..b69344601f 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -150,7 +150,7 @@ public: std::vector>& targets) = 0; virtual void SetMaximizeMode(MaximizeMode maximizeMode) = 0; virtual MaximizeMode GetMaximizeMode() = 0; - virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo) = 0; + virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) = 0; virtual WMError CheckWindowId(int32_t windowId, int32_t& pid) { return WMError::WM_OK; } virtual WSError UpdateSessionAvoidAreaListener(int32_t persistentId, bool haveListener) { return WSError::WS_OK; } virtual WSError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener) diff --git a/wmserver/include/zidl/window_manager_lite_interface.h b/wmserver/include/zidl/window_manager_lite_interface.h index fde371a88a..a88866d401 100644 --- a/wmserver/include/zidl/window_manager_lite_interface.h +++ b/wmserver/include/zidl/window_manager_lite_interface.h @@ -38,7 +38,7 @@ public: virtual WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) = 0; virtual WMError GetVisibilityWindowInfo(std::vector>& infos) { return WMError::WM_OK; }; - virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo) = 0; + virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) = 0; virtual WMError CheckWindowId(int32_t windowId, int32_t& pid) = 0; virtual WMError CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName& element, AppExecFwk::ExtensionAbilityType extensionAbilityType, int32_t& pid) = 0; diff --git a/wmserver/include/zidl/window_manager_proxy.h b/wmserver/include/zidl/window_manager_proxy.h index fc82ea4f14..f21f5877b1 100644 --- a/wmserver/include/zidl/window_manager_proxy.h +++ b/wmserver/include/zidl/window_manager_proxy.h @@ -79,7 +79,7 @@ public: std::vector>& targets) override; void SetMaximizeMode(MaximizeMode maximizeMode) override; MaximizeMode GetMaximizeMode() override; - void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; + void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override; private: static inline BrokerDelegator delegator_; }; diff --git a/wmserver/src/zidl/window_manager_proxy.cpp b/wmserver/src/zidl/window_manager_proxy.cpp index 360ebcf9f0..8df95c4705 100644 --- a/wmserver/src/zidl/window_manager_proxy.cpp +++ b/wmserver/src/zidl/window_manager_proxy.cpp @@ -370,7 +370,7 @@ void WindowManagerProxy::NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); @@ -399,7 +399,7 @@ void WindowManagerProxy::ProcessPointDown(uint32_t windowId, bool isPointDown) WLOGFE("Write isPointDown failed"); return; } - + sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); @@ -1262,7 +1262,7 @@ MaximizeMode WindowManagerProxy::GetMaximizeMode() return static_cast(ret); } -void WindowManagerProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo) +void WindowManagerProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId) { MessageParcel data; MessageParcel reply; @@ -1271,7 +1271,10 @@ void WindowManagerProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo) WLOGFE("WriteInterfaceToken failed"); return; } - + if (!data.WriteUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed"); + return; + } sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); diff --git a/wmserver/src/zidl/window_manager_stub.cpp b/wmserver/src/zidl/window_manager_stub.cpp index 6201306c5d..bd3ca96b8d 100644 --- a/wmserver/src/zidl/window_manager_stub.cpp +++ b/wmserver/src/zidl/window_manager_stub.cpp @@ -518,7 +518,12 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, M } case WindowManagerMessage::TRANS_ID_GET_FOCUS_WINDOW_INFO: { FocusChangeInfo focusInfo; - GetFocusWindowInfo(focusInfo); + uint64_t displayId = 0; + if (!data.ReadUint64(displayId)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId"); + return ERR_INVALID_DATA; + } + GetFocusWindowInfo(focusInfo, displayId); reply.WriteParcelable(&focusInfo); break; } -- Gitee From dc7e65b76243bee3fc870b3f06724e99eed617cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Thu, 16 Jan 2025 16:30:43 +0800 Subject: [PATCH 02/45] multi_focus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/test/unittest/scene_session_manager_test3.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/window_scene/test/unittest/scene_session_manager_test3.cpp b/window_scene/test/unittest/scene_session_manager_test3.cpp index 03185130e6..2a91ebd536 100644 --- a/window_scene/test/unittest/scene_session_manager_test3.cpp +++ b/window_scene/test/unittest/scene_session_manager_test3.cpp @@ -1429,16 +1429,16 @@ HWTEST_F(SceneSessionManagerTest3, ShiftAppWindowFocus, Function | SmallTest | L info.abilityName_ = "ShiftAppWindowFocus"; info.bundleName_ = "ShiftAppWindowFocus"; auto sourceSceneSession = sptr::MakeSptr(info, nullptr); - sourceSceneSession->persistent_ = 1; + sourceSceneSession->persistentId_ = 1; sourceSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); ssm_->sceneSessionMap_.insert(std::make_pair(1, sourceSceneSession)); result01 = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_SESSION); auto targetSceneSession = sptr::MakeSptr(info, nullptr); - targetSceneSession->persistent_ = 10086; + targetSceneSession->persistentId_ = 10086; targetSceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - ssm_->sceneSessionMap_.insert(std::make_pair(10086, sourceSceneSession)); + ssm_->sceneSessionMap_.insert(std::make_pair(10086, targetSceneSession)); result01 = ssm_->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); EXPECT_EQ(result01, WSError::WS_ERROR_INVALID_OPERATION); sourcePersistentId = 10086; -- Gitee From 5fc63052a2667153c794b740943fef741efef9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Thu, 16 Jan 2025 19:01:00 +0800 Subject: [PATCH 03/45] delate and update tdd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/scene_session_manager.h | 3 -- .../src/scene_session_manager.cpp | 2 +- .../scene_session_manager_lifecycle_test2.cpp | 5 ++- .../unittest/scene_session_manager_test10.cpp | 3 +- .../unittest/scene_session_manager_test4.cpp | 4 +- .../unittest/scene_session_manager_test5.cpp | 37 +++++++++------- .../unittest/scene_session_manager_test6.cpp | 14 +++--- .../unittest/scene_session_manager_test7.cpp | 18 +++++--- .../unittest/scene_session_manager_test8.cpp | 5 ++- .../unittest/scene_session_manager_test9.cpp | 43 ++++++++++++------- 10 files changed, 79 insertions(+), 55 deletions(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 0c2dcb3c41..e65837d96a 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -954,9 +954,6 @@ private: SystemSessionConfig systemConfig_; FocusChangeReason focusChangeReason_ = FocusChangeReason::DEFAULT; float snapshotScale_ = 0.5; - int32_t focusedSessionId_ = INVALID_SESSION_ID; - int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; - int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID; std::shared_ptr windowFocusController_; int32_t brightnessSessionId_ = INVALID_SESSION_ID; float displayBrightness_ = UNDEFINED_BRIGHTNESS; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 7c03b1dac2..2dfa9d7117 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -6781,7 +6781,7 @@ void SceneSessionManager::ProcessSubSessionForeground(sptr& sceneS } auto focusedSessionId = focusGroup->GetFocusedSessionId(); bool needBlockNotifyFocusStatusUntilForeground = focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground(); - if (modal->GetPersistentId() == focusedSessionId_ && needBlockNotifyFocusStatusUntilForeground) { + if (modal->GetPersistentId() == focusedSessionId && needBlockNotifyFocusStatusUntilForeground) { focusGroup->SetNeedBlockNotifyFocusStatusUntilForeground(false); focusGroup->SetNeedBlockNotifyUnfocusStatus(false); NotifyFocusStatus(modalSession, true, focusGroup); diff --git a/window_scene/test/unittest/scene_session_manager_lifecycle_test2.cpp b/window_scene/test/unittest/scene_session_manager_lifecycle_test2.cpp index 8819d06983..ff8c8101a9 100644 --- a/window_scene/test/unittest/scene_session_manager_lifecycle_test2.cpp +++ b/window_scene/test/unittest/scene_session_manager_lifecycle_test2.cpp @@ -137,7 +137,8 @@ HWTEST_F(SceneSessionManagerLifecycleTest2, OnSessionStateChange, Function | Sma sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END); ASSERT_NE(nullptr, ssm_); ssm_->OnSessionStateChange(1, state); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->OnSessionStateChange(1, state); sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); ASSERT_NE(nullptr, ssm_); @@ -146,7 +147,7 @@ HWTEST_F(SceneSessionManagerLifecycleTest2, OnSessionStateChange, Function | Sma ASSERT_NE(nullptr, ssm_); ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->OnSessionStateChange(1, state); - ssm_->focusedSessionId_ = 0; + focusGroup->SetFocusedSessionId(0); ASSERT_NE(nullptr, ssm_); ssm_->OnSessionStateChange(1, state); } diff --git a/window_scene/test/unittest/scene_session_manager_test10.cpp b/window_scene/test/unittest/scene_session_manager_test10.cpp index 10890674dd..9b495be626 100644 --- a/window_scene/test/unittest/scene_session_manager_test10.cpp +++ b/window_scene/test/unittest/scene_session_manager_test10.cpp @@ -559,7 +559,8 @@ HWTEST_F(SceneSessionManagerTest10, ProcessFocusZOrderChange, Function | SmallTe sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); ssm_->sceneSessionMap_.emplace(1, sceneSession); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->ProcessFocusZOrderChange(97); sceneSession->lastZOrder_ = 2203; diff --git a/window_scene/test/unittest/scene_session_manager_test4.cpp b/window_scene/test/unittest/scene_session_manager_test4.cpp index 5e7cb6dda7..af10963ab5 100644 --- a/window_scene/test/unittest/scene_session_manager_test4.cpp +++ b/window_scene/test/unittest/scene_session_manager_test4.cpp @@ -499,8 +499,8 @@ HWTEST_F(SceneSessionManagerTest4, ReportWindowProfileInfos, Function | SmallTes sceneSession->sessionInfo_.isSystem_ = false; ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->ReportWindowProfileInfos(); - - ssm_->focusedSessionId_ = 123; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(123); ssm_->ReportWindowProfileInfos(); EXPECT_EQ(WSError::WS_ERROR_INVALID_SESSION, ssm_->HandleSecureSessionShouldHide(nullptr)); } diff --git a/window_scene/test/unittest/scene_session_manager_test5.cpp b/window_scene/test/unittest/scene_session_manager_test5.cpp index 56245c8b8c..917526cdb0 100644 --- a/window_scene/test/unittest/scene_session_manager_test5.cpp +++ b/window_scene/test/unittest/scene_session_manager_test5.cpp @@ -558,11 +558,12 @@ HWTEST_F(SceneSessionManagerTest5, RequestSessionFocus, Function | SmallTest | L sceneSession1->focusedOnShow_ = true; sceneSession1->property_->focusable_ = true; sceneSession1->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - ssm_->focusedSessionId_ = 2; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(2); ssm_->sceneSessionMap_.insert({sceneSession1->GetPersistentId(), sceneSession1}); ret = ssm_->RequestSessionFocus(1, true, reason); ASSERT_EQ(ret, WSError::WS_OK); - ASSERT_EQ(ssm_->focusedSessionId_, 1); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1); ssm_->sceneSessionMap_.clear(); } @@ -608,14 +609,15 @@ HWTEST_F(SceneSessionManagerTest5, RequestFocusClient, Function | SmallTest | Le ssm_->sceneSessionMap_.insert({sceneSession2->GetPersistentId(), sceneSession2}); FocusChangeReason reason = FocusChangeReason::CLIENT_REQUEST; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); ssm_->RequestSessionFocus(1, false, reason); - ASSERT_EQ(ssm_->focusedSessionId_, 1); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1); ssm_->RequestSessionFocus(2, false, reason); - ASSERT_EQ(ssm_->focusedSessionId_, 2); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 2); ssm_->RequestSessionUnfocus(2, reason); - ASSERT_EQ(ssm_->focusedSessionId_, 1); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1); ssm_->RequestSessionUnfocus(1, reason); - ASSERT_EQ(ssm_->focusedSessionId_, 0); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 0); ssm_->sceneSessionMap_.clear(); } @@ -680,15 +682,16 @@ HWTEST_F(SceneSessionManagerTest5, RequestFocusClient01, Function | SmallTest | FocusChangeReason reason = FocusChangeReason::CLIENT_REQUEST; ssm_->RequestSessionFocus(1, false, reason); - ASSERT_EQ(ssm_->focusedSessionId_, 1); + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1); ssm_->RequestSessionFocus(3, false, reason); - ASSERT_EQ(ssm_->focusedSessionId_, 3); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 3); ssm_->RequestSessionFocus(2, false, reason); - ASSERT_EQ(ssm_->focusedSessionId_, 2); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 2); auto ret = ssm_->RequestSessionUnfocus(3, reason); ASSERT_EQ(WSError::WS_DO_NOTHING, ret); ssm_->RequestSessionUnfocus(2, reason); - ASSERT_EQ(ssm_->focusedSessionId_, 1); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1); ssm_->sceneSessionMap_.clear(); } @@ -753,17 +756,18 @@ HWTEST_F(SceneSessionManagerTest5, UpdateFocusStatus01, Function | SmallTest | L { ASSERT_NE(ssm_, nullptr); sptr sceneSession = nullptr; - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, false); - ASSERT_EQ(ssm_->focusedSessionId_, 1); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1); ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, true); - ASSERT_NE(ssm_->focusedSessionId_, 1); - ssm_->focusedSessionId_ = 1; + ASSERT_NE(focusGroup->GetFocusedSessionId(), 1); + focusGroup->SetFocusedSessionId(1); ssm_->needBlockNotifyFocusStatusUntilForeground_ = true; ssm_->UpdateFocusStatus(DEFAULT_DISPLAY_ID, sceneSession, true); - ASSERT_NE(ssm_->focusedSessionId_, 1); + ASSERT_NE(focusGroup->GetFocusedSessionId(), 1); } /** @@ -797,7 +801,8 @@ HWTEST_F(SceneSessionManagerTest5, RequestSessionUnfocus, Function | SmallTest | ssm_->sceneSessionMap_.insert({focusedSession->GetPersistentId(), focusedSession}); ret = ssm_->RequestSessionUnfocus(1, reason); ASSERT_EQ(ret, WSError::WS_OK); - ASSERT_NE(ssm_->focusedSessionId_, 1); + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + ASSERT_NE(focusGroup->GetFocusedSessionId(), 1); ssm_->sceneSessionMap_.clear(); } diff --git a/window_scene/test/unittest/scene_session_manager_test6.cpp b/window_scene/test/unittest/scene_session_manager_test6.cpp index 3bf0ba29bc..01e8395ada 100644 --- a/window_scene/test/unittest/scene_session_manager_test6.cpp +++ b/window_scene/test/unittest/scene_session_manager_test6.cpp @@ -727,7 +727,8 @@ HWTEST_F(SceneSessionManagerTest6, OnSessionStateChange, Function | SmallTest | sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END); ASSERT_NE(nullptr, ssm_); ssm_->OnSessionStateChange(1, state); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->OnSessionStateChange(1, state); sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); ASSERT_NE(nullptr, ssm_); @@ -736,7 +737,7 @@ HWTEST_F(SceneSessionManagerTest6, OnSessionStateChange, Function | SmallTest | ASSERT_NE(nullptr, ssm_); ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->OnSessionStateChange(1, state); - ssm_->focusedSessionId_ = 0; + focusGroup->SetFocusedSessionId(0); ASSERT_NE(nullptr, ssm_); ssm_->OnSessionStateChange(1, state); } @@ -1530,7 +1531,8 @@ HWTEST_F(SceneSessionManagerTest6, SetRootSceneProcessBackEventFunc, Function | ASSERT_NE(nullptr, sceneSession); ASSERT_NE(nullptr, ssm_); ssm_->sceneSessionMap_.insert(std::make_pair(sceneSession->GetPersistentId(), sceneSession)); - ssm_->focusedSessionId_ = sceneSession->GetPersistentId(); + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(sceneSession->GetPersistentId()); ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->ProcessBackEvent(); @@ -1642,7 +1644,7 @@ HWTEST_F(SceneSessionManagerTest6, GetSceneSessionBySessionInfo, Function | Smal info4.persistentId_ = 0; info4.isPersistentRecover_ = false; ASSERT_EQ(ssm_->GetSceneSessionBySessionInfo(info4), nullptr); - + SessionInfo info5; info5.persistentId_ = 5; info5.isPersistentRecover_ = true; @@ -1966,7 +1968,7 @@ HWTEST_F(SceneSessionManagerTest6, CheckIfReuseSession04, Function | SmallTest | sptr collaborator = iface_cast(nullptr); ssm_->collaboratorMap_.insert(std::make_pair(1, collaborator)); - + auto ret3 = ssm_->CheckIfReuseSession(sessionInfo); ASSERT_EQ(ret3, BrokerStates::BROKER_UNKOWN); ssm_->abilityInfoMap_.erase(list); @@ -2003,7 +2005,7 @@ HWTEST_F(SceneSessionManagerTest6, CheckIfReuseSession05, Function | SmallTest | sptr collaborator = iface_cast(nullptr); ssm_->collaboratorMap_.insert(std::make_pair(1, collaborator)); - + auto ret4 = ssm_->CheckIfReuseSession(sessionInfo); ASSERT_EQ(ret4, BrokerStates::BROKER_UNKOWN); ssm_->abilityInfoMap_.erase(list); diff --git a/window_scene/test/unittest/scene_session_manager_test7.cpp b/window_scene/test/unittest/scene_session_manager_test7.cpp index 4add14ad49..834f952b1a 100644 --- a/window_scene/test/unittest/scene_session_manager_test7.cpp +++ b/window_scene/test/unittest/scene_session_manager_test7.cpp @@ -294,7 +294,8 @@ HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent, Function | SmallTest | Leve ASSERT_NE(nullptr, sceneSession); ASSERT_NE(nullptr, ssm_); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->needBlockNotifyFocusStatusUntilForeground_ = true; auto ret = ssm_->ProcessBackEvent(); EXPECT_EQ(ret, WSError::WS_OK); @@ -966,7 +967,8 @@ HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent01, Function | SmallTest | Le sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); ASSERT_NE(nullptr, ssm_); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->needBlockNotifyFocusStatusUntilForeground_ = true; auto ret = ssm_->ProcessBackEvent(); @@ -987,7 +989,8 @@ HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent02, Function | SmallTest | Le ASSERT_NE(nullptr, sceneSession); sceneSession->sessionInfo_.isSystem_ = true; ASSERT_NE(nullptr, ssm_); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->rootSceneProcessBackEventFunc_ = nullptr; @@ -1009,7 +1012,8 @@ HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent03, Function | SmallTest | Le ASSERT_NE(nullptr, sceneSession); sceneSession->sessionInfo_.isSystem_ = true; ASSERT_NE(nullptr, ssm_); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; RootSceneProcessBackEventFunc func = [](){}; @@ -1033,7 +1037,8 @@ HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent04, Function | SmallTest | Le ASSERT_NE(nullptr, sceneSession); sceneSession->sessionInfo_.isSystem_ = false; ASSERT_NE(nullptr, ssm_); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->rootSceneProcessBackEventFunc_ = nullptr; @@ -1055,7 +1060,8 @@ HWTEST_F(SceneSessionManagerTest7, ProcessBackEvent05, Function | SmallTest | Le ASSERT_NE(nullptr, sceneSession); sceneSession->sessionInfo_.isSystem_ = false; ASSERT_NE(nullptr, ssm_); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; RootSceneProcessBackEventFunc func = [](){}; diff --git a/window_scene/test/unittest/scene_session_manager_test8.cpp b/window_scene/test/unittest/scene_session_manager_test8.cpp index c93156d3c6..96327544ac 100644 --- a/window_scene/test/unittest/scene_session_manager_test8.cpp +++ b/window_scene/test/unittest/scene_session_manager_test8.cpp @@ -164,7 +164,8 @@ HWTEST_F(SceneSessionManagerTest8, PostProcessFocus, Function | SmallTest | Leve HWTEST_F(SceneSessionManagerTest8, PostProcessFocus01, Function | SmallTest | Level3) { ssm_->sceneSessionMap_.clear(); - ssm_->focusedSessionId_ = 0; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(0); SessionInfo sessionInfo; sessionInfo.bundleName_ = "PostProcessFocus01"; @@ -180,7 +181,7 @@ HWTEST_F(SceneSessionManagerTest8, PostProcessFocus01, Function | SmallTest | Le ssm_->sceneSessionMap_.emplace(1, sceneSession); ssm_->PostProcessFocus(); - EXPECT_NE(1, ssm_->focusedSessionId_); + EXPECT_NE(1, focusGroup->GetFocusedSessionId()); } /** diff --git a/window_scene/test/unittest/scene_session_manager_test9.cpp b/window_scene/test/unittest/scene_session_manager_test9.cpp index cf0dcd8a0d..c2964f4798 100644 --- a/window_scene/test/unittest/scene_session_manager_test9.cpp +++ b/window_scene/test/unittest/scene_session_manager_test9.cpp @@ -524,9 +524,10 @@ HWTEST_F(SceneSessionManagerTest9, RequestSessionUnfocus02, Function | SmallTest ssm_->sceneSessionMap_.insert(std::make_pair(2, sceneSession1)); ret = ssm_->RequestSessionUnfocus(2, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_OK); - ASSERT_EQ(ssm_->focusedSessionId_, 1); + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1); - ssm_->lastFocusedSessionId_ = 4; + focusGroup->SetLastFocusedSessionId(4); sceneSession1->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_SYSTEM_FLOAT); SessionInfo sessionInfo2; sptr sceneSession2 = sptr::MakeSptr(sessionInfo2, nullptr); @@ -539,7 +540,7 @@ HWTEST_F(SceneSessionManagerTest9, RequestSessionUnfocus02, Function | SmallTest ssm_->sceneSessionMap_.insert(std::make_pair(4, sceneSession2)); ret = ssm_->RequestSessionUnfocus(1, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_OK); - ASSERT_EQ(ssm_->focusedSessionId_, 4); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 4); } /** @@ -558,7 +559,8 @@ HWTEST_F(SceneSessionManagerTest9, RequestAllAppSessionUnfocusInner, Function | sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); ASSERT_NE(nullptr, sceneSession); sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); ssm_->RequestAllAppSessionUnfocusInner(); @@ -582,7 +584,8 @@ HWTEST_F(SceneSessionManagerTest9, UpdateFocus04, Function | SmallTest | Level3) ASSERT_NE(nullptr, sceneSession); sceneSession->GetSessionProperty()->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); - ssm_->focusedSessionId_ = 0; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(0); sceneSession->UpdateFocus(false); ssm_->UpdateFocus(1, false); @@ -594,7 +597,7 @@ HWTEST_F(SceneSessionManagerTest9, UpdateFocus04, Function | SmallTest | Level3) ssm_->UpdateFocus(1, true); sessionInfo.isSystem_ = false; - ssm_->focusedSessionId_ = 1; + focusGroup->SetFocusedSessionId(1); sceneSession->UpdateFocus(true); ssm_->UpdateFocus(1, false); @@ -618,7 +621,8 @@ HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForeground, Function | SmallT sceneSession->persistentId_ = 1; ASSERT_NE(nullptr, sceneSession->property_); sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->ProcessFocusWhenForeground(sceneSession); @@ -640,7 +644,8 @@ HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForeground01, Function | Smal sessionInfo.abilityName_ = "ProcessFocusWhenForeground"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); sceneSession->persistentId_ = 1; - ssm_->focusedSessionId_ = 2; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(2); sceneSession->SetFocusedOnShow(false); ssm_->ProcessFocusWhenForeground(sceneSession); EXPECT_EQ(sceneSession->IsFocusedOnShow(), false); @@ -674,7 +679,8 @@ HWTEST_F(SceneSessionManagerTest9, ProcessSubSessionForeground03, Function | Sma sceneSession->GetSubSession().push_back(subSceneSession); ssm_->sceneSessionMap_.insert(std::make_pair(1, subSceneSession)); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->needBlockNotifyFocusStatusUntilForeground_ = true; SessionInfo subSessionInfo1; @@ -706,7 +712,8 @@ HWTEST_F(SceneSessionManagerTest9, ProcessSubSessionForeground03, Function | Sma ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->ProcessSubSessionForeground(sceneSession); - ssm_->focusedSessionId_ = 2; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(2); ssm_->ProcessSubSessionForeground(sceneSession); } @@ -718,7 +725,8 @@ HWTEST_F(SceneSessionManagerTest9, ProcessSubSessionForeground03, Function | Sma HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForegroundScbCore, Function | SmallTest | Level3) { ASSERT_NE(nullptr, ssm_); - ssm_->focusedSessionId_ = 0; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(0); SessionInfo sessionInfo; sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "ProcessFocusWhenForegroundScbCore"; @@ -729,7 +737,7 @@ HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForegroundScbCore, Function | sceneSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); ssm_->ProcessFocusWhenForegroundScbCore(sceneSession); ASSERT_EQ(sceneSession->GetPostProcessFocusState().isFocused_, false); - ASSERT_EQ(ssm_->focusedSessionId_, 0); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 0); sceneSession->SetFocusableOnShow(true); ssm_->ProcessFocusWhenForegroundScbCore(sceneSession); // SetPostProcessFocusState @@ -738,7 +746,7 @@ HWTEST_F(SceneSessionManagerTest9, ProcessFocusWhenForegroundScbCore, Function | sceneSession->isVisible_ = true; sceneSession->SetSessionState(SessionState::STATE_FOREGROUND); ssm_->ProcessFocusWhenForegroundScbCore(sceneSession); // RequestSessionFocus - ASSERT_EQ(ssm_->focusedSessionId_, 1); + ASSERT_EQ(focusGroup->GetFocusedSessionId(), 1); } /** @@ -766,7 +774,8 @@ HWTEST_F(SceneSessionManagerTest9, ProcessModalTopmostRequestFocusImmdediately02 sceneSession->GetSubSession().push_back(subSceneSession); ssm_->sceneSessionMap_.insert(std::make_pair(1, subSceneSession)); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->needBlockNotifyFocusStatusUntilForeground_ = true; SessionInfo subSessionInfo1; @@ -830,7 +839,8 @@ HWTEST_F(SceneSessionManagerTest9, ProcessDialogRequestFocusImmdediately02, Func sceneSession->GetDialogVector().push_back(dialogSceneSession); ssm_->sceneSessionMap_.insert(std::make_pair(1, dialogSceneSession)); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); ssm_->needBlockNotifyFocusStatusUntilForeground_ = true; SessionInfo dialogSessionInfo1; @@ -1092,7 +1102,8 @@ HWTEST_F(SceneSessionManagerTest9, ShiftFocus, Function | SmallTest | Level3) nextSession->persistentId_ = 4; ssm_->sceneSessionMap_.insert({1, focusedSession}); ssm_->sceneSessionMap_.insert({4, nextSession}); - ssm_->focusedSessionId_ = 1; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(1); WSError ret = ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, nextSession, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_OK); ASSERT_EQ(focusedSession->isFocused_, false); -- Gitee From 2d60a70461382a2633fb99eab965d808d58065d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Thu, 16 Jan 2025 19:56:05 +0800 Subject: [PATCH 04/45] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- test/common/mock/mock_window_adapter_lite.h | 2 +- .../session_manager/include/window_focus_controller.h | 8 ++++---- .../unittest/scene_session_manager_lite_stub_test.cpp | 6 +++--- .../test/unittest/scene_session_manager_test10.cpp | 3 ++- .../test/unittest/scene_session_manager_test5.cpp | 4 ++-- wm/test/unittest/window_manager_lite_test.cpp | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/test/common/mock/mock_window_adapter_lite.h b/test/common/mock/mock_window_adapter_lite.h index 59b021d13a..65770a9196 100644 --- a/test/common/mock/mock_window_adapter_lite.h +++ b/test/common/mock/mock_window_adapter_lite.h @@ -23,7 +23,7 @@ namespace OHOS { namespace Rosen { class MockWindowAdapterLite : public WindowAdapterLite { public: - MOCK_METHOD(void, GetFocusWindowInfo, (FocusChangeInfo& focusInfo)); + MOCK_METHOD(void, GetFocusWindowInfo, (FocusChangeInfo& focusInfo, DisplayId displayId)); MOCK_METHOD(void, ClearWindowAdapter, ()); MOCK_METHOD2(RegisterWindowManagerAgent, WMError(WindowManagerAgentType type, const sptr& windowManagerAgent)); diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index 758e47cadb..7cb769198b 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -30,9 +30,9 @@ namespace OHOS { namespace Rosen { /** - * @struct FocusState + * @struct FocusGroup * - * @brief Window focus state of a screen + * @brief Window focus group of a screen */ struct FocusGroup : public RefBase { @@ -48,9 +48,9 @@ public: FocusGroup(DisplayId displayGroupId) : displayGroupId_(displayGroupId) {} WSError UpdateFocusedSessionId(int32_t persistentId) { - TLOGI(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId_, persistentId); + TLOGD(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId_, persistentId); if (focusedSessionId_ == persistentId) { - TLOGI(WmsLogTag::WMS_FOCUS, "Focus scene not change, id: %{public}d", focusedSessionId_); + TLOGD(WmsLogTag::WMS_FOCUS, "Focus scene not change, id: %{public}d", focusedSessionId_); return WSError::WS_DO_NOTHING; } lastFocusedSessionId_ = focusedSessionId_; diff --git a/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp b/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp index d90112121c..228710e411 100644 --- a/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_lite_stub_test.cpp @@ -44,11 +44,11 @@ class MockSceneSessionManagerLiteStub : public SceneSessionManagerLiteStub { { return WSError::WS_OK; } - WSError GetFocusSessionToken(sptr& token) override + WSError GetFocusSessionToken(sptr& token, DisplayId displayId) override { return WSError::WS_OK; } - WSError GetFocusSessionElement(AppExecFwk::ElementName& element) override + WSError GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId) override { return WSError::WS_OK; } @@ -127,7 +127,7 @@ class MockSceneSessionManagerLiteStub : public SceneSessionManagerLiteStub { { return WMError::WM_OK; } - void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override + void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId) override { } WMError CheckWindowId(int32_t windowId, int32_t& pid) override diff --git a/window_scene/test/unittest/scene_session_manager_test10.cpp b/window_scene/test/unittest/scene_session_manager_test10.cpp index 9b495be626..9548992c54 100644 --- a/window_scene/test/unittest/scene_session_manager_test10.cpp +++ b/window_scene/test/unittest/scene_session_manager_test10.cpp @@ -356,7 +356,8 @@ HWTEST_F(SceneSessionManagerTest10, TestCheckLastFocusedAppSessionFocus_01, Func sptr nextSession = sptr::MakeSptr(info2, nullptr); ASSERT_NE(nextSession, nullptr); - ssm_->lastFocusedAppSessionId_ = nextSession->GetPersistentId(); + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetLastFocusedAppSessionId(nextSession->GetPersistentId()) ASSERT_EQ(false, ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession)); } diff --git a/window_scene/test/unittest/scene_session_manager_test5.cpp b/window_scene/test/unittest/scene_session_manager_test5.cpp index 917526cdb0..3b037afcce 100644 --- a/window_scene/test/unittest/scene_session_manager_test5.cpp +++ b/window_scene/test/unittest/scene_session_manager_test5.cpp @@ -708,7 +708,7 @@ HWTEST_F(SceneSessionManagerTest5, SetShiftFocusListener, Function | SmallTest | info.bundleName_ = "test2"; FocusChangeReason reason = FocusChangeReason::SPLIT_SCREEN; sptr sceneSession = nullptr; - ssm_->ShiftFocus(sceneSession, reason); + ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, sceneSession, reason); info.isSystem_ = true; sptr property = sptr::MakeSptr(); ASSERT_NE(property, nullptr); @@ -723,7 +723,7 @@ HWTEST_F(SceneSessionManagerTest5, SetShiftFocusListener, Function | SmallTest | ssm_->SetCallingSessionIdSessionListenser(func1); ProcessStartUIAbilityErrorFunc func2; ssm_->SetStartUIAbilityErrorListener(func2); - ssm_->ShiftFocus(sceneSession1, reason); + ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, sceneSession1, reason); } /** diff --git a/wm/test/unittest/window_manager_lite_test.cpp b/wm/test/unittest/window_manager_lite_test.cpp index 23381a7c6a..50481ab5b0 100644 --- a/wm/test/unittest/window_manager_lite_test.cpp +++ b/wm/test/unittest/window_manager_lite_test.cpp @@ -115,7 +115,7 @@ HWTEST_F(WindowManagerLiteTest, GetFocusWindowInfo, Function | SmallTest | Level infosResult.uid_ = 11; infosResult.displayId_ = 12; infosResult.windowId_ = 13; - EXPECT_CALL(m->Mock(), GetFocusWindowInfo(_)).Times(1).WillOnce(DoAll(SetArgReferee<0>(infosResult), Return())); + EXPECT_CALL(m->Mock(), GetFocusWindowInfo(_, _)).Times(1).WillOnce(DoAll(SetArgReferee<0>(infosResult), Return())); WindowManagerLite::GetInstance().GetFocusWindowInfo(infosInput); ASSERT_EQ(infosInput.windowId_, infosResult.windowId_); ASSERT_EQ(infosInput.uid_, infosResult.uid_); -- Gitee From 96aaad42a5d5e52deba0247fa73dce7956e54ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Thu, 16 Jan 2025 20:28:26 +0800 Subject: [PATCH 05/45] tdd fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/test/unittest/scene_session_manager_test5.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/window_scene/test/unittest/scene_session_manager_test5.cpp b/window_scene/test/unittest/scene_session_manager_test5.cpp index 3b037afcce..c9aea4b190 100644 --- a/window_scene/test/unittest/scene_session_manager_test5.cpp +++ b/window_scene/test/unittest/scene_session_manager_test5.cpp @@ -1641,8 +1641,8 @@ HWTEST_F(SceneSessionManagerTest5, RequestFocusStatusBySCB01, Function | SmallTe ssm_->sceneSessionMap_.insert({sceneSession->GetPersistentId(), sceneSession}); sptr sceneSession1 = sptr::MakeSptr(info, nullptr); - sceneSession1->property->SetFocusable(true); - sceneSession1->property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + sceneSession1->property_->SetFocusable(true); + sceneSession1->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); sceneSession1->persistentId_ = 2; sceneSession1->isVisible_ = true; sceneSession1->state_ = SessionState::STATE_ACTIVE; -- Gitee From c3bcaecd232a57073abad4ab908f08999273eb10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Fri, 17 Jan 2025 10:37:38 +0800 Subject: [PATCH 06/45] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../session_manager/src/scene_session_manager.cpp | 8 ++++---- .../session_manager/src/window_focus_controller.cpp | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 2dfa9d7117..77d9ad81d9 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5923,8 +5923,8 @@ WSError SceneSessionManager::ShiftFocus(DisplayId displayId, sptr& notifySCBAfterUnfocusedFunc_(); } } - TLOGI(WmsLogTag::WMS_FOCUS, "focusedId: %{public}d, nextId: %{public}d, reason: %{public}d", - focusedId, nextId, reason); + TLOGI(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu, focusedId: %{public}d, nextId: %{public}d, reason: %{public}d", + displayId, focusedId, nextId, reason); return WSError::WS_OK; } @@ -5948,8 +5948,8 @@ void SceneSessionManager::UpdateFocusStatus(DisplayId displayId, sptrGetWindowNameAllType().c_str(), sceneSession->GetPersistentId(), isFocused); + TLOGD(WmsLogTag::WMS_FOCUS, "name: %{public}s, id: %{public}d, isFocused: %{public}d, displayId: %{public}lu", + sceneSession->GetWindowNameAllType().c_str(), sceneSession->GetPersistentId(), isFocused, displayId); // set focused if (isFocused) { SetFocusedSessionId(sceneSession->GetPersistentId(), displayId); diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index b0ed1bca26..157e9eaa38 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -51,10 +51,6 @@ WSError WindowFocusController::AddFocusGroup(DisplayId displayId) TLOGI(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu", displayId); CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); std::shared_lock lock(focusGroupMutex_); - if (displayId != DEFAULT_DISPLAY_ID && GetFocusGroupInner(displayId) != nullptr) { - TLOGW(WmsLogTag::WMS_FOCUS, "already had displayId: %{public}lu", displayId); - return WSError::WS_DO_NOTHING; - } sptr focusGroup = sptr::MakeSptr(displayId); focusGroupMap_.insert(std::make_pair(displayId, focusGroup)); if (displayId != DEFAULT_DISPLAY_ID) { -- Gitee From aedc648f082d62f59dc1c9e1a9220d185fd7c5f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Fri, 17 Jan 2025 16:13:03 +0800 Subject: [PATCH 07/45] tdd fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/test/unittest/scene_session_manager_test10.cpp | 2 +- window_scene/test/unittest/scene_session_manager_test5.cpp | 2 +- window_scene/test/unittest/scene_session_manager_test9.cpp | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/window_scene/test/unittest/scene_session_manager_test10.cpp b/window_scene/test/unittest/scene_session_manager_test10.cpp index 9548992c54..4981fc0923 100644 --- a/window_scene/test/unittest/scene_session_manager_test10.cpp +++ b/window_scene/test/unittest/scene_session_manager_test10.cpp @@ -357,7 +357,7 @@ HWTEST_F(SceneSessionManagerTest10, TestCheckLastFocusedAppSessionFocus_01, Func ASSERT_NE(nextSession, nullptr); auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); - focusGroup->SetLastFocusedAppSessionId(nextSession->GetPersistentId()) + focusGroup->SetLastFocusedAppSessionId(nextSession->GetPersistentId()); ASSERT_EQ(false, ssm_->CheckLastFocusedAppSessionFocus(focusedSession, nextSession)); } diff --git a/window_scene/test/unittest/scene_session_manager_test5.cpp b/window_scene/test/unittest/scene_session_manager_test5.cpp index c9aea4b190..4707dc5abf 100644 --- a/window_scene/test/unittest/scene_session_manager_test5.cpp +++ b/window_scene/test/unittest/scene_session_manager_test5.cpp @@ -929,7 +929,7 @@ HWTEST_F(SceneSessionManagerTest5, RequestFocusBasicCheck, Function | SmallTest sptr focusGroup = nullptr; WSError ret = ssm_->RequestFocusBasicCheck(0, focusGroup); ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION); - WSError ret = ssm_->RequestFocusBasicCheck(1, focusGroup); + ret = ssm_->RequestFocusBasicCheck(1, focusGroup); ASSERT_EQ(ret, WSError::WS_ERROR_INVALID_SESSION); focusGroup = sptr::MakeSptr(DEFAULT_DISPLAY_ID); focusGroup->SetFocusedSessionId(1); diff --git a/window_scene/test/unittest/scene_session_manager_test9.cpp b/window_scene/test/unittest/scene_session_manager_test9.cpp index c2964f4798..39c2c14210 100644 --- a/window_scene/test/unittest/scene_session_manager_test9.cpp +++ b/window_scene/test/unittest/scene_session_manager_test9.cpp @@ -712,7 +712,6 @@ HWTEST_F(SceneSessionManagerTest9, ProcessSubSessionForeground03, Function | Sma ssm_->needBlockNotifyFocusStatusUntilForeground_ = false; ssm_->ProcessSubSessionForeground(sceneSession); - auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); focusGroup->SetFocusedSessionId(2); ssm_->ProcessSubSessionForeground(sceneSession); } -- Gitee From 02b6ef774082a01b5eca94ff41fef7e6afc94247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Fri, 17 Jan 2025 17:22:11 +0800 Subject: [PATCH 08/45] bug fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/window_focus_controller.h | 6 ++---- .../src/window_focus_controller.cpp | 10 +++++----- .../src/zidl/scene_session_manager_lite_proxy.cpp | 4 ++-- .../test/unittest/intention_event_manager_test.cpp | 10 +++++----- .../test/unittest/scene_input_manager_test.cpp | 14 +++++++------- .../test/unittest/scene_session_manager_test3.cpp | 4 ++-- .../test/unittest/scene_session_manager_test4.cpp | 2 +- .../test/unittest/scene_session_manager_test8.cpp | 2 +- 8 files changed, 25 insertions(+), 27 deletions(-) diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index 7cb769198b..7398e5eedb 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -34,8 +34,7 @@ namespace Rosen { * * @brief Window focus group of a screen */ -struct FocusGroup : public RefBase -{ +struct FocusGroup : public RefBase { private: int32_t focusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; @@ -45,7 +44,7 @@ private: DisplayId displayGroupId_ = DISPLAY_ID_INVALID; public: - FocusGroup(DisplayId displayGroupId) : displayGroupId_(displayGroupId) {} + FocusGroup(DisplayId displayGroupId) : displayGroupId_(displayGroupId) explicit {} WSError UpdateFocusedSessionId(int32_t persistentId) { TLOGD(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId_, persistentId); @@ -139,7 +138,6 @@ private: std::shared_mutex focusGroupMutex_; std::unordered_map> focusGroupMap_; std::unordered_set virtualScreenDisplayIdSet_; - }; } } diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index 157e9eaa38..301e3f1793 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -22,7 +22,7 @@ namespace { #define CHECK_DISPLAY_ID_RETURN(displayId, ret) \ do { \ - if (displayId == DISPLAY_ID_INVALID) { \ + if ((displayId) == DISPLAY_ID_INVALID) { \ TLOGE(WmsLogTag::WMS_FOCUS, "display id is invalid."); \ return ret; \ } \ @@ -77,7 +77,7 @@ int32_t WindowFocusController::GetFocusedSessionId(DisplayId displayId) CHECK_DISPLAY_ID_RETURN(displayId, INVALID_SESSION_ID); std::shared_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); - if(focusGroup == nullptr) { + if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}lu", displayId); return INVALID_SESSION_ID; } @@ -100,7 +100,7 @@ sptr WindowFocusController::GetFocusGroupInner(DisplayId displayId) { DisplayId displayGroupId = GetDisplayGroupId(displayId); TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu, displayGroupId: %{public}lu", displayId, displayGroupId); - if(displayGroupId == DEFAULT_DISPLAY_ID) { + if (displayGroupId == DEFAULT_DISPLAY_ID) { return focusGroupMap_[DEFAULT_DISPLAY_ID]; } auto iter = focusGroupMap_.find(displayGroupId); @@ -138,7 +138,7 @@ WSError WindowFocusController::UpdateFocusedSessionId(DisplayId displayId, int32 CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); std::unique_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); - if(focusGroup == nullptr) { + if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}lu", displayId); return WSError::WS_ERROR_NULLPTR; } @@ -151,7 +151,7 @@ WSError WindowFocusController::UpdateFocusedAppSessionId(DisplayId displayId, in CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); std::unique_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); - if(focusGroup == nullptr) { + if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}d", displayId); return WSError::WS_ERROR_NULLPTR; } diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp index 7dcf0ae1f1..01bdd4428b 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp @@ -464,7 +464,7 @@ WSError SceneSessionManagerLiteProxy::GetFocusSessionToken(sptr& } if (!data.WriteUint64(displayId)) { TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed"); - return WMError::WM_ERROR_IPC_FAILED; + return WSError::WS_ERROR_IPC_FAILED; } sptr remote = Remote(); if (remote == nullptr) { @@ -495,7 +495,7 @@ WSError SceneSessionManagerLiteProxy::GetFocusSessionElement(AppExecFwk::Element } if (!data.WriteUint64(displayId)) { TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed"); - return WMError::WM_ERROR_IPC_FAILED; + return WSError::WS_ERROR_IPC_FAILED; } sptr remote = Remote(); if (remote == nullptr) { diff --git a/window_scene/test/unittest/intention_event_manager_test.cpp b/window_scene/test/unittest/intention_event_manager_test.cpp index 6febf911e1..8791d62bf1 100644 --- a/window_scene/test/unittest/intention_event_manager_test.cpp +++ b/window_scene/test/unittest/intention_event_manager_test.cpp @@ -156,11 +156,11 @@ HWTEST_F(IntentionEventManagerTest, OnInputEvent1, Function | MediumTest | Level inputEventListener_->OnInputEvent(keyEvent); SceneSessionManager::GetInstance().SetEnableInputEvent(true); - SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, INVALID_SESSION_ID); + SceneSessionManager::GetInstance().SetFocusedSessionId(INVALID_SESSION_ID, DEFAULT_DISPLAY_ID); EXPECT_EQ(INVALID_SESSION_ID, SceneSessionManager::GetInstance().GetFocusedSessionId()); inputEventListener_->OnInputEvent(keyEvent); - SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, 1); + SceneSessionManager::GetInstance().SetFocusedSessionId(1, DEFAULT_DISPLAY_ID); inputEventListener_->OnInputEvent(keyEvent); SessionInfo info; @@ -180,7 +180,7 @@ HWTEST_F(IntentionEventManagerTest, OnInputEvent1, Function | MediumTest | Level sptr sceneSession1 = sptr::MakeSptr(info, callback); EXPECT_NE(nullptr, sceneSession1); SceneSessionManager::GetInstance().sceneSessionMap_.emplace(std::make_pair(2, sceneSession1)); - SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, 2); + SceneSessionManager::GetInstance().SetFocusedSessionId(2, DEFAULT_DISPLAY_ID); EXPECT_EQ(2, SceneSessionManager::GetInstance().GetFocusedSessionId()); auto focusedSceneSession = SceneSessionManager::GetInstance().GetSceneSession(2); inputEventListener_->OnInputEvent(keyEvent); @@ -197,7 +197,7 @@ HWTEST_F(IntentionEventManagerTest, OnInputEvent2, Function | MediumTest | Level std::shared_ptr keyEvent = MMI::KeyEvent::Create(); EXPECT_NE(nullptr, keyEvent); SceneSessionManager::GetInstance().SetEnableInputEvent(true); - SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, 1); + SceneSessionManager::GetInstance().SetFocusedSessionId(1, DEFAULT_DISPLAY_ID); SessionInfo info; info.bundleName_ = "IntentionEventManager"; info.moduleName_ = "InputEventListener"; @@ -235,7 +235,7 @@ HWTEST_F(IntentionEventManagerTest, OnInputEvent3, Function | MediumTest | Level std::shared_ptr keyEvent = MMI::KeyEvent::Create(); EXPECT_NE(nullptr, keyEvent); SceneSessionManager::GetInstance().SetEnableInputEvent(true); - SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, 1); + SceneSessionManager::GetInstance().SetFocusedSessionId(1, DEFAULT_DISPLAY_ID); SessionInfo info; info.bundleName_ = "IntentionEventManager"; info.moduleName_ = "InputEventListener"; diff --git a/window_scene/test/unittest/scene_input_manager_test.cpp b/window_scene/test/unittest/scene_input_manager_test.cpp index 20f4a119c3..490f0e5228 100644 --- a/window_scene/test/unittest/scene_input_manager_test.cpp +++ b/window_scene/test/unittest/scene_input_manager_test.cpp @@ -345,7 +345,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate1, Function | SmallTest | Level3) std::vector displayInfos; std::vector windowInfoList; int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId, DEFAULT_DISPLAY_ID); SceneInputManager::GetInstance().lastFocusId_ = 1; bool ret1 = SceneInputManager::GetInstance().CheckNeedUpdate(displayInfos, windowInfoList); ASSERT_TRUE(ret1); @@ -376,7 +376,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate2, Function | SmallTest | Level3) displayInfos.emplace_back(displayinfo); MMI::WindowInfo windowinfo; int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId, DEFAULT_DISPLAY_ID); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; @@ -442,7 +442,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate3, Function | SmallTest | Level3) MMI::WindowInfo windowinfo; windowInfoList.emplace_back(windowinfo); int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId, DEFAULT_DISPLAY_ID); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; @@ -498,7 +498,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate4, Function | SmallTest | Level3) MMI::WindowInfo windowinfo; windowInfoList.emplace_back(windowinfo); int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId, DEFAULT_DISPLAY_ID); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; @@ -551,7 +551,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate5, Function | SmallTest | Level3) MMI::WindowInfo windowinfo; windowInfoList.emplace_back(windowinfo); int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId, DEFAULT_DISPLAY_ID); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; @@ -603,7 +603,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate6, Function | SmallTest | Level3) MMI::WindowInfo windowinfo; windowInfoList.emplace_back(windowinfo); int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId, DEFAULT_DISPLAY_ID); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; @@ -659,7 +659,7 @@ HWTEST_F(SceneInputManagerTest, CheckNeedUpdate7, Function | SmallTest | Level3) MMI::WindowInfo windowinfo; windowInfoList.emplace_back(windowinfo); int32_t focusId = 0; - Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(DEFAULT_DISPLAY_ID, focusId); + Rosen::SceneSessionManager::GetInstance().SetFocusedSessionId(focusId, DEFAULT_DISPLAY_ID); SceneInputManager::GetInstance().lastFocusId_ = 0; SceneInputManager::GetInstance().lastDisplayInfos_ = displayInfos; SceneInputManager::GetInstance().lastWindowInfoList_ = windowInfoList; diff --git a/window_scene/test/unittest/scene_session_manager_test3.cpp b/window_scene/test/unittest/scene_session_manager_test3.cpp index 2a91ebd536..3f1af7f14e 100644 --- a/window_scene/test/unittest/scene_session_manager_test3.cpp +++ b/window_scene/test/unittest/scene_session_manager_test3.cpp @@ -1319,10 +1319,10 @@ HWTEST_F(SceneSessionManagerTest3, SetFocusedSessionId, Function | SmallTest | L int32_t focusedSession = ssm_->GetFocusedSessionId(); EXPECT_EQ(focusedSession, INVALID_SESSION_ID); int32_t persistentId = INVALID_SESSION_ID; - WSError result01 = ssm_->SetFocusedSessionId(DEFAULT_DISPLAY_ID, persistentId); + WSError result01 = ssm_->SetFocusedSessionId(persistentId, DEFAULT_DISPLAY_ID); EXPECT_EQ(result01, WSError::WS_DO_NOTHING); persistentId = 10086; - WSError result02 = ssm_->SetFocusedSessionId(DEFAULT_DISPLAY_ID, persistentId); + WSError result02 = ssm_->SetFocusedSessionId(persistentId, DEFAULT_DISPLAY_ID); EXPECT_EQ(result02, WSError::WS_OK); ASSERT_EQ(ssm_->GetFocusedSessionId(), 10086); } diff --git a/window_scene/test/unittest/scene_session_manager_test4.cpp b/window_scene/test/unittest/scene_session_manager_test4.cpp index af10963ab5..b1115c0a65 100644 --- a/window_scene/test/unittest/scene_session_manager_test4.cpp +++ b/window_scene/test/unittest/scene_session_manager_test4.cpp @@ -1233,7 +1233,7 @@ HWTEST_F(SceneSessionManagerTest4, GetAccessibilityWindowInfo, Function | SmallT HWTEST_F(SceneSessionManagerTest4, ShiftAppWindowFocus02, Function | SmallTest | Level3) { ASSERT_NE(ssm_, nullptr); - ssm_->SetFocusedSessionId(DEFAULT_DISPLAY_ID, INVALID_SESSION_ID); + ssm_->SetFocusedSessionId(INVALID_SESSION_ID, DEFAULT_DISPLAY_ID); int32_t sourcePersistentId = INVALID_SESSION_ID; int32_t targetPersistentId = 1; diff --git a/window_scene/test/unittest/scene_session_manager_test8.cpp b/window_scene/test/unittest/scene_session_manager_test8.cpp index 96327544ac..74841595f6 100644 --- a/window_scene/test/unittest/scene_session_manager_test8.cpp +++ b/window_scene/test/unittest/scene_session_manager_test8.cpp @@ -557,7 +557,7 @@ HWTEST_F(SceneSessionManagerTest8, SetBrightness, Function | SmallTest | Level3) ssm_->Init(); ASSERT_NE(nullptr, ssm_->eventHandler_); - ssm_->SetFocusedSessionId(DEFAULT_DISPLAY_ID, 2024); + ssm_->SetFocusedSessionId(2024, DEFAULT_DISPLAY_ID); EXPECT_EQ(2024, ssm_->GetFocusedSessionId()); ret = ssm_->SetBrightness(sceneSession, 3.15f); -- Gitee From bcc20dc0938606051795e9386f64008c7a0fb052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Fri, 17 Jan 2025 10:47:34 +0000 Subject: [PATCH 09/45] update window_scene/session_manager/include/window_focus_controller.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/session_manager/include/window_focus_controller.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index 7398e5eedb..4fcfaac2ef 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -44,7 +44,7 @@ private: DisplayId displayGroupId_ = DISPLAY_ID_INVALID; public: - FocusGroup(DisplayId displayGroupId) : displayGroupId_(displayGroupId) explicit {} + explicit FocusGroup(DisplayId displayGroupId) : displayGroupId_(displayGroupId) {} WSError UpdateFocusedSessionId(int32_t persistentId) { TLOGD(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId_, persistentId); -- Gitee From 2d5a0226844d40fd9d71628cda8e3dd75fbfb4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Fri, 17 Jan 2025 19:51:07 +0800 Subject: [PATCH 10/45] fix displayId MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../src/scene_session_manager.cpp | 37 ++++++++++--------- .../src/window_focus_controller.cpp | 23 ++++++------ 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 77d9ad81d9..395d070803 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -3803,7 +3803,7 @@ WSError SceneSessionManager::ProcessBackEvent() taskScheduler_->PostAsyncTask([this]() { auto focusGroup = windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); if (focusGroup == nullptr) { - TLOGNE(WmsLogTag::WMS_MAIN, "focus group is nullptr: %{public}lu", DEFAULT_DISPLAY_ID); + TLOGNE(WmsLogTag::WMS_MAIN, "focus group is nullptr: %{public}" PRIu64, DEFAULT_DISPLAY_ID); return WSError::WS_ERROR_INVALID_SESSION; } auto focusedSessionId = focusGroup->GetFocusedSessionId(); @@ -5385,7 +5385,7 @@ WSError SceneSessionManager::RequestSessionFocusImmediately(int32_t persistentId auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}lu", displayId); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); return WSError::WS_ERROR_INVALID_SESSION; } // base block @@ -5429,7 +5429,7 @@ WSError SceneSessionManager::RequestSessionFocus(int32_t persistentId, bool byFo auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}lu", displayId); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); return WSError::WS_ERROR_INVALID_SESSION; } WSError basicCheckRet = RequestFocusBasicCheck(persistentId, focusGroup); @@ -5485,7 +5485,7 @@ WSError SceneSessionManager::RequestSessionUnfocus(int32_t persistentId, FocusCh auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}lu", displayId); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); return WSError::WS_ERROR_INVALID_SESSION; } auto focusedSession = GetSceneSession(focusGroup->GetFocusedSessionId()); @@ -5671,8 +5671,8 @@ bool SceneSessionManager::CheckClickFocusIsDownThroughFullScreen(const sptrGetZOrder() < focusedSession->GetZOrder(); } -WSError SceneSessionManager::RequestFocusSpecificCheck(DisplayId displayId, sptr& sceneSession, bool byForeground, - FocusChangeReason reason) +WSError SceneSessionManager::RequestFocusSpecificCheck(DisplayId displayId, sptr& sceneSession, + bool byForeground,FocusChangeReason reason) { TLOGD(WmsLogTag::WMS_FOCUS, "FocusChangeReason: %{public}d", reason); int32_t persistentId = sceneSession->GetPersistentId(); @@ -5791,7 +5791,8 @@ sptr SceneSessionManager::GetNextFocusableSession(DisplayId displa * Find the session through the specific zOrder, it is located abve it, its' blockingFocus attribute is true, * and it is the closest; */ -sptr SceneSessionManager::GetTopNearestBlockingFocusSession(DisplayId displayId, uint32_t zOrder, bool includingAppSession) +sptr SceneSessionManager::GetTopNearestBlockingFocusSession(DisplayId displayId, uint32_t zOrder, + bool includingAppSession) { sptr ret = nullptr; auto func = [this, &ret, zOrder, includingAppSession, displayId](sptr session) { @@ -5923,8 +5924,8 @@ WSError SceneSessionManager::ShiftFocus(DisplayId displayId, sptr& notifySCBAfterUnfocusedFunc_(); } } - TLOGI(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu, focusedId: %{public}d, nextId: %{public}d, reason: %{public}d", - displayId, focusedId, nextId, reason); + TLOGI(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64 + ", focusedId: %{public}d, nextId: %{public}d, reason: %{public}d", displayId, focusedId, nextId, reason); return WSError::WS_OK; } @@ -5948,8 +5949,8 @@ void SceneSessionManager::UpdateFocusStatus(DisplayId displayId, sptrGetWindowNameAllType().c_str(), sceneSession->GetPersistentId(), isFocused, displayId); + TLOGD(WmsLogTag::WMS_FOCUS, "name: %{public}s, id: %{public}d, isFocused: %{public}d, displayId: %{public}" PRIu64, + sceneSession->GetWindowNameAllType().c_str(), sceneSession->GetPersistentId(), isFocused, displayId); // set focused if (isFocused) { SetFocusedSessionId(sceneSession->GetPersistentId(), displayId); @@ -9517,11 +9518,12 @@ bool CheckIfNeedMultipleFocus(const std::string& name, const ScreenType& screenT void ScreenConnectionChangeListener::OnScreenConnected(const sptr& screenSession) { if (screenSession == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "screenSession connect failed"); + TLOGE(WmsLogTag::WMS_FOCUS, "screenSession is nullptr"); return; } - TLOGI(WmsLogTag::WMS_FOCUS, "name: %{public}s, screenId: %{public}lu", screenSession->GetName().c_str(), - screenSession->GetScreenId()); + TLOGI(WmsLogTag::WMS_FOCUS, "name: %{public}s, screenId: %{public}" PRIu64 ", screenType: %{public}u", + screenSession->GetName().c_str(), screenSession->GetScreenId(), + screenSession->GetScreenProperty().GetScreenType()); if (CheckIfNeedMultipleFocus(screenSession->GetName(), screenSession->GetScreenProperty().GetScreenType())) { SceneSessionManager::GetInstance().AddFocusGroup(screenSession->GetScreenId()); } @@ -9530,11 +9532,12 @@ void ScreenConnectionChangeListener::OnScreenConnected(const sptr void ScreenConnectionChangeListener::OnScreenDisconnected(const sptr& screenSession) { if (screenSession == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "screenSession disconnect failed"); + TLOGE(WmsLogTag::WMS_FOCUS, "screenSession is nullptr"); return; } - TLOGI(WmsLogTag::WMS_FOCUS, "name: %{public}s, screenId: %{public}lu", screenSession->GetName().c_str(), - screenSession->GetScreenId()); + TLOGI(WmsLogTag::WMS_FOCUS, "name: %{public}s, screenId: %{public}" PRIu64 ", screenType: %{public}u", + screenSession->GetName().c_str(), screenSession->GetScreenId(), + screenSession->GetScreenProperty().GetScreenType()); if (CheckIfNeedMultipleFocus(screenSession->GetName(), screenSession->GetScreenProperty().GetScreenType())) { SceneSessionManager::GetInstance().RemoveFocusGroup(screenSession->GetScreenId()); } diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index 301e3f1793..a2dd056a92 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -36,7 +36,7 @@ WindowFocusController::WindowFocusController() noexcept DisplayId WindowFocusController::GetDisplayGroupId(DisplayId displayId) { - TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu", displayId); + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64, displayId); if (displayId == DEFAULT_DISPLAY_ID || virtualScreenDisplayIdSet_.size() == 0) { return DEFAULT_DISPLAY_ID; } @@ -48,7 +48,7 @@ DisplayId WindowFocusController::GetDisplayGroupId(DisplayId displayId) WSError WindowFocusController::AddFocusGroup(DisplayId displayId) { - TLOGI(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu", displayId); + TLOGI(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64, displayId); CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); std::shared_lock lock(focusGroupMutex_); sptr focusGroup = sptr::MakeSptr(displayId); @@ -61,7 +61,7 @@ WSError WindowFocusController::AddFocusGroup(DisplayId displayId) WSError WindowFocusController::RemoveFocusGroup(DisplayId displayId) { - TLOGI(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu", displayId); + TLOGI(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64, displayId); CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); std::shared_lock lock(focusGroupMutex_); focusGroupMap_.erase(displayId); @@ -73,12 +73,12 @@ WSError WindowFocusController::RemoveFocusGroup(DisplayId displayId) int32_t WindowFocusController::GetFocusedSessionId(DisplayId displayId) { - TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu", displayId); + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64, displayId); CHECK_DISPLAY_ID_RETURN(displayId, INVALID_SESSION_ID); std::shared_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}lu", displayId); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}" PRIu64, displayId); return INVALID_SESSION_ID; } return focusGroup->GetFocusedSessionId(); @@ -86,7 +86,7 @@ int32_t WindowFocusController::GetFocusedSessionId(DisplayId displayId) sptr WindowFocusController::GetFocusGroup(DisplayId displayId) { - TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu", displayId); + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64, displayId); if (displayId == DISPLAY_ID_INVALID) { TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); return nullptr; @@ -99,13 +99,14 @@ sptr WindowFocusController::GetFocusGroup(DisplayId displayId) sptr WindowFocusController::GetFocusGroupInner(DisplayId displayId) { DisplayId displayGroupId = GetDisplayGroupId(displayId); - TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu, displayGroupId: %{public}lu", displayId, displayGroupId); + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64 ", displayGroupId: %{public}" PRIu64, + displayId, displayGroupId); if (displayGroupId == DEFAULT_DISPLAY_ID) { return focusGroupMap_[DEFAULT_DISPLAY_ID]; } auto iter = focusGroupMap_.find(displayGroupId); if (iter == focusGroupMap_.end()) { - TLOGE(WmsLogTag::WMS_FOCUS, "Not found focus group with displayId: %{public}lu", displayId); + TLOGE(WmsLogTag::WMS_FOCUS, "Not found focus group with displayId: %{public}" PRIu64, displayId); return nullptr; } return iter->second; @@ -134,12 +135,12 @@ std::vector> WindowFocusController::GetAllFocusedS WSError WindowFocusController::UpdateFocusedSessionId(DisplayId displayId, int32_t persistentId) { - TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu, persistentId: %{public}d", displayId, persistentId); + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64 ", persistentId: %{public}d", displayId, persistentId); CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); std::unique_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}lu", displayId); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}" PRIu64, displayId); return WSError::WS_ERROR_NULLPTR; } return focusGroup->UpdateFocusedSessionId(persistentId); @@ -147,7 +148,7 @@ WSError WindowFocusController::UpdateFocusedSessionId(DisplayId displayId, int32 WSError WindowFocusController::UpdateFocusedAppSessionId(DisplayId displayId, int32_t persistentId) { - TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}lu, persistentId: %{public}d", displayId, persistentId); + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64 ", persistentId: %{public}d", displayId, persistentId); CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); std::unique_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); -- Gitee From 0e389dbf79bf83c1a12bce6d5b8047b46ce25e58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Fri, 17 Jan 2025 21:51:17 +0800 Subject: [PATCH 11/45] fix code check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/screen_session_manager_client.h | 3 ++ .../src/screen_session_manager_client.cpp | 31 +++++++++++----- .../include/scene_session_manager.h | 1 + .../include/window_focus_controller.h | 4 +- .../src/scene_session_manager.cpp | 20 ++++++---- .../src/window_focus_controller.cpp | 37 +++++++++++-------- 6 files changed, 61 insertions(+), 35 deletions(-) diff --git a/window_scene/screen_session_manager_client/include/screen_session_manager_client.h b/window_scene/screen_session_manager_client/include/screen_session_manager_client.h index 44bd870901..ea7072d6ec 100644 --- a/window_scene/screen_session_manager_client/include/screen_session_manager_client.h +++ b/window_scene/screen_session_manager_client/include/screen_session_manager_client.h @@ -119,6 +119,9 @@ private: void SetDisplayNodeScreenId(ScreenId screenId, ScreenId displayNodeScreenId) override; void ScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName) override; + void NotifyScreenConnect(const sptr& screenSession); + void NotifyScreenDisconnect(const sptr& screenSession); + mutable std::mutex screenSessionMapMutex_; std::map> screenSessionMap_; std::function switchingToAnotherUserFunc_ = nullptr; diff --git a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp index a6ab42f808..3f21dee3ae 100644 --- a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp +++ b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp @@ -90,6 +90,26 @@ void ScreenSessionManagerClient::RegisterScreenConnectionChangeListener( WLOGFI("Success to register screen connection change listener"); } +void ScreenSessionManagerClient::NotifyScreenConnect(const sptr& screenSession) +{ + if (screenConnectionListener_) { + screenConnectionListener_->OnScreenConnected(screenSession); + } + if (screenConnectionChangeListener_) { + screenConnectionChangeListener_->OnScreenConnected(screenSession); + } +} + +void ScreenSessionManagerClient::NotifyScreenDisconnect(const sptr& screenSession) +{ + if (screenConnectionListener_) { + screenConnectionListener_->OnScreenDisconnected(screenSession); + } + if (screenConnectionChangeListener_) { + screenConnectionChangeListener_->OnScreenDisconnected(screenSession); + } +} + bool ScreenSessionManagerClient::CheckIfNeedConnectScreen(ScreenId screenId, ScreenId rsId, const std::string& name) { if (rsId == SCREEN_ID_INVALID) { @@ -136,17 +156,12 @@ void ScreenSessionManagerClient::OnScreenConnectionChanged(ScreenId screenId, Sc screenSessionMap_.emplace(screenId, screenSession); } screenSession->SetIsExtend(isExtend); + NotifyScreenConnect(); if (screenConnectionListener_) { - screenConnectionListener_->OnScreenConnected(screenSession); WLOGFI("screenId: %{public}" PRIu64 " density: %{public}f ", screenId, config.property.GetDensity()); screenSession->SetScreenSceneDpi(config.property.GetDensity()); } - if (screenConnectionChangeListener_) { - screenConnectionChangeListener_->OnScreenConnected(screenSession); - WLOGFI("screenConnectionChangeListener screenId: %{public}" PRIu64 " density: %{public}f ", - screenId, config.property.GetDensity()); - } screenSession->Connect(); return; } @@ -160,9 +175,7 @@ void ScreenSessionManagerClient::OnScreenConnectionChanged(ScreenId screenId, Sc if (screenConnectionListener_) { screenConnectionListener_->OnScreenDisconnected(screenSession); } - if (screenConnectionChangeListener_) { - screenConnectionChangeListener_->OnScreenDisconnected(screenSession); - } + NotifyScreenDisconnect(screenSession); { std::lock_guard lock(screenSessionMapMutex_); screenSessionMap_.erase(screenId); diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index e65837d96a..a89af64412 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -1171,6 +1171,7 @@ private: std::shared_ptr scbDumpSubscriber_; RunnableFuture> dumpInfoFuture_; void DumpSessionInfo(const sptr& session, std::ostringstream& oss); + void DumpFocusInfo(std::ostringstream& oss); void DumpSessionElementInfo(const sptr& session, const std::vector& params, std::string& dumpInfo); void DumpAllSessionFocusableInfo(int32_t persistentId); diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index 4fcfaac2ef..dd21267a2c 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -39,8 +39,8 @@ private: int32_t focusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID; - bool needBlockNotifyFocusStatusUntilForeground_ = false; - bool needBlockNotifyUnfocusStatus_ = false; + bool needBlockNotifyFocusStatusUntilForeground_ { false }; + bool needBlockNotifyUnfocusStatus_ { false }; DisplayId displayGroupId_ = DISPLAY_ID_INVALID; public: diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 395d070803..cd970e1e26 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -4944,6 +4944,17 @@ void SceneSessionManager::DumpSessionInfo(const sptr& session, std << std::endl; } +void SceneSessionManager::DumpFocusInfo(std::ostringstream& oss) +{ + oss << "Focus window: " << std::endl; + std::vector> allFocusedStateList = windowFocusController_->GetAllFocusedSessionList(); + if (allFocusedStateList.size() > 0) { + for (const auto& focusState : allFocusedStateList) { + oss << "DisplayId: " << focusState.first << " Focus window: " << focusState.second << std::endl; + } + } +} + WSError SceneSessionManager::GetAllSessionDumpInfo(std::string& dumpInfo) { int32_t screenGroupId = 0; @@ -4988,13 +4999,7 @@ WSError SceneSessionManager::GetAllSessionDumpInfo(std::string& dumpInfo) DumpSessionInfo(session, oss); count++; } - oss << "Focus window: " << std::endl; - std::vector> allFocusedStateList = windowFocusController_->GetAllFocusedSessionList(); - if (allFocusedStateList.size() > 0) { - for (const auto& focusState : allFocusedStateList) { - oss << "DisplayId: " << focusState.first << " Focus window: " << focusState.second << std::endl; - } - } + DumpFocusInfo(oss); oss << "SingleHand: X[" << singleHandTransform_.posX << "] Y[" << singleHandTransform_.posY << "] scale[" << singleHandTransform_.scaleX << "]" << std::endl; oss << "Total window num: " << sceneSessionMapCopy.size() << std::endl; @@ -9508,7 +9513,6 @@ void DisplayChangeListener::OnDisplayStateChange(DisplayId defaultDisplayId, spt bool CheckIfNeedMultipleFocus(const std::string& name, const ScreenType& screenType) { - TLOGI(WmsLogTag::WMS_FOCUS, "name: %{public}s screenType: %{public}u", name.c_str(), screenType); if (screenType == ScreenType::VIRTUAL && (name == "HiCar" || name == "SuperLauncher" || name == "CastEngine")) { return true; } diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index a2dd056a92..7fa3f28f94 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -17,16 +17,6 @@ namespace OHOS { namespace Rosen { -namespace { -} - -#define CHECK_DISPLAY_ID_RETURN(displayId, ret) \ - do { \ - if ((displayId) == DISPLAY_ID_INVALID) { \ - TLOGE(WmsLogTag::WMS_FOCUS, "display id is invalid."); \ - return ret; \ - } \ - } while (false) \ WindowFocusController::WindowFocusController() noexcept { @@ -49,7 +39,10 @@ DisplayId WindowFocusController::GetDisplayGroupId(DisplayId displayId) WSError WindowFocusController::AddFocusGroup(DisplayId displayId) { TLOGI(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64, displayId); - CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); + if (displayId == DISPLAY_ID_INVALID) { + TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); + return WSError::WS_ERROR_INVALID_PARAM; + } std::shared_lock lock(focusGroupMutex_); sptr focusGroup = sptr::MakeSptr(displayId); focusGroupMap_.insert(std::make_pair(displayId, focusGroup)); @@ -62,7 +55,10 @@ WSError WindowFocusController::AddFocusGroup(DisplayId displayId) WSError WindowFocusController::RemoveFocusGroup(DisplayId displayId) { TLOGI(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64, displayId); - CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); + if (displayId == DISPLAY_ID_INVALID) { + TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); + return WSError::WS_ERROR_INVALID_PARAM; + } std::shared_lock lock(focusGroupMutex_); focusGroupMap_.erase(displayId); if (displayId != DEFAULT_DISPLAY_ID) { @@ -74,7 +70,10 @@ WSError WindowFocusController::RemoveFocusGroup(DisplayId displayId) int32_t WindowFocusController::GetFocusedSessionId(DisplayId displayId) { TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64, displayId); - CHECK_DISPLAY_ID_RETURN(displayId, INVALID_SESSION_ID); + if (displayId == DISPLAY_ID_INVALID) { + TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); + return INVALID_SESSION_ID; + } std::shared_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); if (focusGroup == nullptr) { @@ -136,7 +135,10 @@ std::vector> WindowFocusController::GetAllFocusedS WSError WindowFocusController::UpdateFocusedSessionId(DisplayId displayId, int32_t persistentId) { TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64 ", persistentId: %{public}d", displayId, persistentId); - CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); + if (displayId == DISPLAY_ID_INVALID) { + TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); + return WSError::WS_ERROR_INVALID_PARAM; + } std::unique_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); if (focusGroup == nullptr) { @@ -149,11 +151,14 @@ WSError WindowFocusController::UpdateFocusedSessionId(DisplayId displayId, int32 WSError WindowFocusController::UpdateFocusedAppSessionId(DisplayId displayId, int32_t persistentId) { TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64 ", persistentId: %{public}d", displayId, persistentId); - CHECK_DISPLAY_ID_RETURN(displayId, WSError::WS_ERROR_INVALID_PARAM); + if (displayId == DISPLAY_ID_INVALID) { + TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); + return WSError::WS_ERROR_INVALID_PARAM; + } std::unique_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}d", displayId); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}" PRIu64, displayId); return WSError::WS_ERROR_NULLPTR; } return focusGroup->UpdateFocusedAppSessionId(persistentId); -- Gitee From b2b447be9246f5f09a21209a143947025a96c76d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Fri, 17 Jan 2025 22:20:07 +0800 Subject: [PATCH 12/45] fix lu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../js_scene_session_manager.cpp | 2 +- .../src/screen_session_manager_client.cpp | 2 +- .../include/window_focus_controller.h | 12 ++++++------ .../session_manager/src/window_focus_controller.cpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index a0830dfb85..31de033dd0 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -451,7 +451,7 @@ void JsSceneSessionManager::OnOutsideDownEvent(int32_t x, int32_t y) void JsSceneSessionManager::OnShiftFocus(int32_t persistentId, DisplayId displayGroupId) { - TLOGD(WmsLogTag::WMS_FOCUS, "persistentId: %{public}d, displayGroupId: %{public}lu", persistentId, displayGroupId); + TLOGD(WmsLogTag::WMS_FOCUS, "persistentId: %{public}d, displayGroupId: %{public}" PRIu64, persistentId, displayGroupId); auto task = [this, persistentId, jsCallBack = GetJSCallback(SHIFT_FOCUS_CB), env = env_, displayGroupId]() { if (jsCallBack == nullptr) { diff --git a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp index 3f21dee3ae..b00e42e4bf 100644 --- a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp +++ b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp @@ -156,7 +156,7 @@ void ScreenSessionManagerClient::OnScreenConnectionChanged(ScreenId screenId, Sc screenSessionMap_.emplace(screenId, screenSession); } screenSession->SetIsExtend(isExtend); - NotifyScreenConnect(); + NotifyScreenConnect(screenSession); if (screenConnectionListener_) { WLOGFI("screenId: %{public}" PRIu64 " density: %{public}f ", screenId, config.property.GetDensity()); diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index dd21267a2c..ae1e967685 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -39,8 +39,8 @@ private: int32_t focusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID; - bool needBlockNotifyFocusStatusUntilForeground_ { false }; - bool needBlockNotifyUnfocusStatus_ { false }; + bool needBlockNotifyFocusStatusUntilForeground { false }; + bool needBlockNotifyUnfocusStatus { false }; DisplayId displayGroupId_ = DISPLAY_ID_INVALID; public: @@ -80,12 +80,12 @@ public: bool GetNeedBlockNotifyFocusStatusUntilForeground() { - return needBlockNotifyFocusStatusUntilForeground_; + return needBlockNotifyFocusStatusUntilForeground; } bool GetNeedBlockNotifyUnfocusStatus() { - return needBlockNotifyUnfocusStatus_; + return needBlockNotifyUnfocusStatus; } DisplayId GetDisplayGroupId() @@ -110,12 +110,12 @@ public: void SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlockNotifyFocusStatusUntilForeground) { - needBlockNotifyFocusStatusUntilForeground_ = needBlockNotifyFocusStatusUntilForeground; + needBlockNotifyFocusStatusUntilForeground = needBlockNotifyFocusStatusUntilForeground; } void SetNeedBlockNotifyUnfocusStatus(bool needBlockNotifyUnfocusStatus) { - needBlockNotifyUnfocusStatus_ = needBlockNotifyUnfocusStatus; + needBlockNotifyUnfocusStatus = needBlockNotifyUnfocusStatus; } }; diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index 7fa3f28f94..e3052d0f63 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -128,7 +128,7 @@ std::vector> WindowFocusController::GetAllFocusedS } allFocusGroup.emplace_back(std::make_pair(elem.first, curFocusGroup->GetFocusedSessionId())); } - TLOGD(WmsLogTag::WMS_FOCUS, "success, list size: %{public}lu", allFocusGroup.size()); + TLOGD(WmsLogTag::WMS_FOCUS, "success, list size: %{public}u", allFocusGroup.size()); return allFocusGroup; } -- Gitee From 9b54879cf5b41636cc795e13c562c1ad7e7be056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Fri, 17 Jan 2025 22:33:12 +0800 Subject: [PATCH 13/45] fix error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../scene_session_manager/js_scene_session_manager.cpp | 3 ++- .../session_manager/include/window_focus_controller.h | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 31de033dd0..9d210a91df 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -451,7 +451,8 @@ void JsSceneSessionManager::OnOutsideDownEvent(int32_t x, int32_t y) void JsSceneSessionManager::OnShiftFocus(int32_t persistentId, DisplayId displayGroupId) { - TLOGD(WmsLogTag::WMS_FOCUS, "persistentId: %{public}d, displayGroupId: %{public}" PRIu64, persistentId, displayGroupId); + TLOGD(WmsLogTag::WMS_FOCUS, "persistentId: %{public}d, displayGroupId: %{public}" PRIu64, + persistentId, displayGroupId); auto task = [this, persistentId, jsCallBack = GetJSCallback(SHIFT_FOCUS_CB), env = env_, displayGroupId]() { if (jsCallBack == nullptr) { diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index ae1e967685..1651b880a5 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -108,14 +108,14 @@ public: lastFocusedAppSessionId_ = lastFocusedAppSessionId; } - void SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlockNotifyFocusStatusUntilForeground) + void SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlock) { - needBlockNotifyFocusStatusUntilForeground = needBlockNotifyFocusStatusUntilForeground; + needBlockNotifyFocusStatusUntilForeground = needBlock; } - void SetNeedBlockNotifyUnfocusStatus(bool needBlockNotifyUnfocusStatus) + void SetNeedBlockNotifyUnfocusStatus(bool needBlock) { - needBlockNotifyUnfocusStatus = needBlockNotifyUnfocusStatus; + needBlockNotifyUnfocusStatus = needBlock; } }; -- Gitee From bc8023020400f56c3257345d0cbb22790ac9f104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sat, 18 Jan 2025 10:27:24 +0800 Subject: [PATCH 14/45] fix getfocuswindowinfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- wmserver/include/window_manager_service.h | 4 ++-- wmserver/src/window_manager_service.cpp | 4 ++-- wmserver/test/unittest/window_manager_stub_impl.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 1fc770d5a8..b8037850ed 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -152,7 +152,7 @@ public: void PostAsyncTask(Task task, const std::string& taskName = "WMSTask", uint32_t delay = 0); void SetMaximizeMode(MaximizeMode maximizeMode) override; MaximizeMode GetMaximizeMode() override; - void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; + void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override; protected: WindowManagerService(); @@ -166,7 +166,7 @@ private: void OnWindowEvent(Event event, const sptr& remoteObject); void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type); - WMError GetFocusWindowInfo(sptr& abilityToken); + WMError GetFocusWindowInfo(sptr& abilityToken, DisplayId displayId = DEFAULT_DISPLAY_ID); bool CheckSystemWindowPermission(const sptr& property) const; bool CheckAnimationPermission(const sptr& property) const; void LoadWindowParameter(); diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index f724f86bc1..a518db963e 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -827,7 +827,7 @@ void WindowManagerService::NotifyAnimationAbilityDied(sptr PostAsyncTask(task, "NotifyAnimationAbilityDied"); } -WMError WindowManagerService::GetFocusWindowInfo(sptr& abilityToken) +WMError WindowManagerService::GetFocusWindowInfo(sptr& abilityToken, DisplayId displayId) { auto task = [this, &abilityToken]() { return windowController_->GetFocusWindowInfo(abilityToken); @@ -1635,7 +1635,7 @@ MaximizeMode WindowManagerService::GetMaximizeMode() return maximizeMode_; } -void WindowManagerService::GetFocusWindowInfo(FocusChangeInfo& focusInfo) +void WindowManagerService::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId) { WLOGFD("Get Focus window info in wms"); windowController_->GetFocusWindowInfo(focusInfo); diff --git a/wmserver/test/unittest/window_manager_stub_impl.h b/wmserver/test/unittest/window_manager_stub_impl.h index 3ecba7b84c..1a2632c8f5 100644 --- a/wmserver/test/unittest/window_manager_stub_impl.h +++ b/wmserver/test/unittest/window_manager_stub_impl.h @@ -157,7 +157,7 @@ MaximizeMode GetMaximizeMode() override { return MaximizeMode::MODE_FULL_FILL; } -void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override {} +void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override {} }; } } -- Gitee From f8abab4c57f03d75a9e748fd8cd25b91f49936af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sat, 18 Jan 2025 13:39:01 +0800 Subject: [PATCH 15/45] fix focusedSessionId_ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../unittest/scene_session_dirty_manager_test2.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/window_scene/test/unittest/scene_session_dirty_manager_test2.cpp b/window_scene/test/unittest/scene_session_dirty_manager_test2.cpp index 1013456328..d83300c5dd 100644 --- a/window_scene/test/unittest/scene_session_dirty_manager_test2.cpp +++ b/window_scene/test/unittest/scene_session_dirty_manager_test2.cpp @@ -595,7 +595,8 @@ HWTEST_F(SceneSessionDirtyManagerTest2, GetWindowInfoWithSameInfo, Function | Sm std::vector currWindowInfoList; currDisplayInfos.emplace_back(currDisplayedInfo); currWindowInfoList.emplace_back(currWindowInfo); - ssm_->focusedSessionId_ = focusedSession; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(focusedSession); bool checkNeedUpdateFlag = true; // check the same information checkNeedUpdateFlag = sim_->CheckNeedUpdate(currDisplayInfos, currWindowInfoList); @@ -631,7 +632,8 @@ HWTEST_F(SceneSessionDirtyManagerTest2, GetWindowInfoWithPidDiff, Function | Sma std::vector currWindowInfoList; currDisplayInfos.emplace_back(currDisplayedInfo); currWindowInfoList.emplace_back(currWindowInfo); - ssm_->focusedSessionId_ = focusedSession; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(focusedSession); bool checkNeedUpdateFlag = false; checkNeedUpdateFlag = sim_->CheckNeedUpdate(currDisplayInfos, currWindowInfoList); ASSERT_EQ(checkNeedUpdateFlag, true); @@ -666,7 +668,8 @@ HWTEST_F(SceneSessionDirtyManagerTest2, GetWindowInfoWithAreaDiff, Function | Sm std::vector currWindowInfoList; currDisplayInfos.emplace_back(currDisplayedInfo); currWindowInfoList.emplace_back(currWindowInfo); - ssm_->focusedSessionId_ = focusedSession; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(focusedSession); bool checkNeedUpdateFlag = false; checkNeedUpdateFlag = sim_->CheckNeedUpdate(currDisplayInfos, currWindowInfoList); ASSERT_EQ(checkNeedUpdateFlag, true); @@ -701,7 +704,8 @@ HWTEST_F(SceneSessionDirtyManagerTest2, GetWindowInfoWithzOrderDiff, Function | std::vector currWindowInfoList; currDisplayInfos.emplace_back(currDisplayedInfo); currWindowInfoList.emplace_back(currWindowInfo); - ssm_->focusedSessionId_ = focusedSession; + auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); + focusGroup->SetFocusedSessionId(focusedSession); bool checkNeedUpdateFlag = false; checkNeedUpdateFlag = sim_->CheckNeedUpdate(currDisplayInfos, currWindowInfoList); ASSERT_EQ(checkNeedUpdateFlag, true); -- Gitee From 3fa09724cb7673675abdefde3df87f61d2e99637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sat, 18 Jan 2025 14:23:48 +0800 Subject: [PATCH 16/45] fix onshiftfocus uint64_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../napi/scene_session_manager/js_scene_session_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 9d210a91df..44dc319eea 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -460,7 +460,7 @@ void JsSceneSessionManager::OnShiftFocus(int32_t persistentId, DisplayId display return; } napi_value argv[] = { CreateJsValue(env, persistentId), - CreateJsValue(env, static_cast(displayGroupId)) }; + CreateJsValue(env, static_cast(displayGroupId)) }; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }; taskScheduler_->PostMainThreadTask(task, "OnShiftFocus, PID:" + std::to_string(persistentId)); -- Gitee From e76af891de9a4ebb3daa87fc436c0242abd19768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sat, 18 Jan 2025 14:53:15 +0800 Subject: [PATCH 17/45] fix displayid uint64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../napi/scene_session_manager/js_scene_session_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 44dc319eea..9d210a91df 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -460,7 +460,7 @@ void JsSceneSessionManager::OnShiftFocus(int32_t persistentId, DisplayId display return; } napi_value argv[] = { CreateJsValue(env, persistentId), - CreateJsValue(env, static_cast(displayGroupId)) }; + CreateJsValue(env, static_cast(displayGroupId)) }; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }; taskScheduler_->PostMainThreadTask(task, "OnShiftFocus, PID:" + std::to_string(persistentId)); -- Gitee From 1c55e88a9681b54a4c62ac356d2bdb186f743d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sat, 18 Jan 2025 15:22:08 +0800 Subject: [PATCH 18/45] fix screen client and format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../src/screen_session_manager_client.cpp | 8 ++------ .../include/zidl/scene_session_manager_lite_interface.h | 1 - .../include/zidl/scene_session_manager_lite_proxy.h | 2 -- .../src/zidl/scene_session_manager_lite_proxy.cpp | 1 - .../test/unittest/scene_session_manager_test10.cpp | 1 - .../test/unittest/scene_session_manager_test6.cpp | 2 -- .../test/unittest/scene_session_manager_test8.cpp | 1 - .../test/unittest/scene_session_manager_test9.cpp | 4 ---- wmserver/src/zidl/window_manager_proxy.cpp | 2 -- 9 files changed, 2 insertions(+), 20 deletions(-) diff --git a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp index b00e42e4bf..f13bd32aa4 100644 --- a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp +++ b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp @@ -82,12 +82,11 @@ void ScreenSessionManagerClient::RegisterScreenConnectionChangeListener( const sptr& listener) { if (listener == nullptr) { - WLOGFE("Failed to register screen connection change listener, listener is null"); + TLOGE(WmsLogTag::DMS, "Failed to register screen connection change listener, listener is null"); return; } - screenConnectionChangeListener_ = listener; - WLOGFI("Success to register screen connection change listener"); + TLOGE(WmsLogTag::DMS, "Success to register screen connection change listener"); } void ScreenSessionManagerClient::NotifyScreenConnect(const sptr& screenSession) @@ -172,9 +171,6 @@ void ScreenSessionManagerClient::OnScreenConnectionChanged(ScreenId screenId, Sc return; } screenSession->DestroyScreenScene(); - if (screenConnectionListener_) { - screenConnectionListener_->OnScreenDisconnected(screenSession); - } NotifyScreenDisconnect(screenSession); { std::lock_guard lock(screenSessionMapMutex_); 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 ea9aac9c80..48d6378b35 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 @@ -115,7 +115,6 @@ public: virtual WSError GetSessionInfoByContinueSessionId(const std::string& continueSessionId, SessionInfoBean& sessionInfo) = 0; virtual WSError SetSessionContinueState(const sptr& token, const ContinueState& continueState) = 0; - virtual WSError IsValidSessionIds(const std::vector& sessionIds, std::vector& results) = 0; virtual WSError GetFocusSessionToken(sptr& token, DisplayId displayId = DEFAULT_DISPLAY_ID) = 0; virtual WSError GetFocusSessionElement(AppExecFwk::ElementName& element, diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h index b6b1c25e03..e4ac50c277 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_lite_proxy.h @@ -62,7 +62,6 @@ public: WSError MoveSessionsToBackground(const std::vector& sessionIds, std::vector& result) override; WSError ClearSession(int32_t persistentId) override; WSError ClearAllSessions() override; - void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override; WMError RegisterWindowManagerAgent(WindowManagerAgentType type, const sptr& windowManagerAgent) override; @@ -96,7 +95,6 @@ public: const std::string& abilityName, int32_t appIndex) override; WMError HasFloatingWindowForeground(const sptr& abilityToken, bool& hasOrNot) override; - private: template WSError GetParcelableInfos(MessageParcel& reply, std::vector& parcelableInfos); diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp index 01bdd4428b..31e327004f 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_proxy.cpp @@ -991,7 +991,6 @@ WMError SceneSessionManagerLiteProxy::GetWindowModeType(WindowModeType& windowMo WLOGFE("WriteInterfaceToken failed"); return WMError::WM_ERROR_IPC_FAILED; } - MessageParcel reply; MessageOption option; sptr remote = Remote(); diff --git a/window_scene/test/unittest/scene_session_manager_test10.cpp b/window_scene/test/unittest/scene_session_manager_test10.cpp index 4981fc0923..0096118473 100644 --- a/window_scene/test/unittest/scene_session_manager_test10.cpp +++ b/window_scene/test/unittest/scene_session_manager_test10.cpp @@ -986,7 +986,6 @@ HWTEST_F(SceneSessionManagerTest10, TestIsNeedSkipWindowModeTypeCheck_04, Functi sceneSession->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sceneSession->SetRSVisible(true); sceneSession->SetSessionState(SessionState::STATE_FOREGROUND); - DisplayId displayId = 1001; sceneSession->property_->SetDisplayId(displayId); auto ret = ssm_->IsNeedSkipWindowModeTypeCheck(sceneSession, true); diff --git a/window_scene/test/unittest/scene_session_manager_test6.cpp b/window_scene/test/unittest/scene_session_manager_test6.cpp index 01e8395ada..55a04efdd1 100644 --- a/window_scene/test/unittest/scene_session_manager_test6.cpp +++ b/window_scene/test/unittest/scene_session_manager_test6.cpp @@ -1968,7 +1968,6 @@ HWTEST_F(SceneSessionManagerTest6, CheckIfReuseSession04, Function | SmallTest | sptr collaborator = iface_cast(nullptr); ssm_->collaboratorMap_.insert(std::make_pair(1, collaborator)); - auto ret3 = ssm_->CheckIfReuseSession(sessionInfo); ASSERT_EQ(ret3, BrokerStates::BROKER_UNKOWN); ssm_->abilityInfoMap_.erase(list); @@ -2005,7 +2004,6 @@ HWTEST_F(SceneSessionManagerTest6, CheckIfReuseSession05, Function | SmallTest | sptr collaborator = iface_cast(nullptr); ssm_->collaboratorMap_.insert(std::make_pair(1, collaborator)); - auto ret4 = ssm_->CheckIfReuseSession(sessionInfo); ASSERT_EQ(ret4, BrokerStates::BROKER_UNKOWN); ssm_->abilityInfoMap_.erase(list); diff --git a/window_scene/test/unittest/scene_session_manager_test8.cpp b/window_scene/test/unittest/scene_session_manager_test8.cpp index 74841595f6..3452905cbd 100644 --- a/window_scene/test/unittest/scene_session_manager_test8.cpp +++ b/window_scene/test/unittest/scene_session_manager_test8.cpp @@ -891,7 +891,6 @@ HWTEST_F(SceneSessionManagerTest8, OnSessionStateChange01, Function | SmallTest property->SetWindowType(WindowType::APP_MAIN_WINDOW_END); ssm_->OnSessionStateChange(100, state); - auto ret = ssm_->UpdateMaximizeMode(1, true); EXPECT_EQ(WSError::WS_OK, ret); constexpr uint32_t NOT_WAIT_SYNC_IN_NS = 500000; diff --git a/window_scene/test/unittest/scene_session_manager_test9.cpp b/window_scene/test/unittest/scene_session_manager_test9.cpp index 39c2c14210..ed32c015b5 100644 --- a/window_scene/test/unittest/scene_session_manager_test9.cpp +++ b/window_scene/test/unittest/scene_session_manager_test9.cpp @@ -208,7 +208,6 @@ HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_04, Functi sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestSessionFocusImmediately02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); - sceneSession->SetFocusable(true); sceneSession->SetFocusedOnShow(false); ssm_->sceneSessionMap_.insert(std::make_pair(1, sceneSession)); @@ -230,7 +229,6 @@ HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_05, Functi sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestSessionFocusImmediately02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); - sceneSession->SetFocusable(true); sceneSession->SetFocusedOnShow(true); sceneSession->SetForceHideState(ForceHideState::HIDDEN_WHEN_FOCUSED); @@ -253,7 +251,6 @@ HWTEST_F(SceneSessionManagerTest9, TestRequestSessionFocusImmediately_06, Functi sessionInfo.bundleName_ = "SceneSessionManagerTest9"; sessionInfo.abilityName_ = "RequestSessionFocusImmediately02"; sptr sceneSession = sptr::MakeSptr(sessionInfo, nullptr); - sceneSession->SetFocusable(true); sceneSession->SetFocusedOnShow(true); sceneSession->SetForceHideState(ForceHideState::NOT_HIDDEN); @@ -1073,7 +1070,6 @@ HWTEST_F(SceneSessionManagerTest9, CheckClickFocusIsDownThroughFullScreen, Funct focusedSession->property_->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH); ret = ssm_->CheckClickFocusIsDownThroughFullScreen(focusedSession, sceneSession, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, false); - sceneSession->SetZOrder(50); focusedSession->SetZOrder(100); focusedSession->blockingFocus_ = true; diff --git a/wmserver/src/zidl/window_manager_proxy.cpp b/wmserver/src/zidl/window_manager_proxy.cpp index 8df95c4705..812f9f0dbc 100644 --- a/wmserver/src/zidl/window_manager_proxy.cpp +++ b/wmserver/src/zidl/window_manager_proxy.cpp @@ -370,7 +370,6 @@ void WindowManagerProxy::NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); @@ -399,7 +398,6 @@ void WindowManagerProxy::ProcessPointDown(uint32_t windowId, bool isPointDown) WLOGFE("Write isPointDown failed"); return; } - sptr remote = Remote(); if (remote == nullptr) { WLOGFE("remote is null"); -- Gitee From 28ea2f49b8ad56bf903f2bebb578c4c9bc1a775d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sat, 18 Jan 2025 15:23:54 +0800 Subject: [PATCH 19/45] fix scene_session_manager.h include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/session_manager/include/scene_session_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index a89af64412..7fe26cc589 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -45,12 +45,12 @@ #include "display_info.h" #include "display_change_info.h" #include "display_change_listener.h" -#include "screen_session_manager_client.h" #include "app_debug_listener_interface.h" #include "app_mgr_client.h" #include "include/core/SkRegion.h" #include "ability_info.h" #include "screen_fold_data.h" +#include "screen_session_manager_client.h" #include "thread_safety_annotations.h" #include "window_focus_controller.h" -- Gitee From 0419f452eb103e657244b82a01b378abeecf11ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sat, 18 Jan 2025 15:44:47 +0800 Subject: [PATCH 20/45] fix window focus controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/scene_session_manager.h | 2 +- .../include/window_focus_controller.h | 103 ++++++------------ .../src/window_focus_controller.cpp | 32 +++--- 3 files changed, 48 insertions(+), 89 deletions(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 7fe26cc589..d8c74bcfab 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -954,7 +954,7 @@ private: SystemSessionConfig systemConfig_; FocusChangeReason focusChangeReason_ = FocusChangeReason::DEFAULT; float snapshotScale_ = 0.5; - std::shared_ptr windowFocusController_; + sptr windowFocusController_; int32_t brightnessSessionId_ = INVALID_SESSION_ID; float displayBrightness_ = UNDEFINED_BRIGHTNESS; bool isScreenLocked_ {false}; diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index 1651b880a5..ac1bf1a2ff 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -35,88 +35,46 @@ namespace Rosen { * @brief Window focus group of a screen */ struct FocusGroup : public RefBase { -private: - int32_t focusedSessionId_ = INVALID_SESSION_ID; - int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; - int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID; - bool needBlockNotifyFocusStatusUntilForeground { false }; - bool needBlockNotifyUnfocusStatus { false }; - DisplayId displayGroupId_ = DISPLAY_ID_INVALID; - public: - explicit FocusGroup(DisplayId displayGroupId) : displayGroupId_(displayGroupId) {} + explicit FocusGroup(DisplayId displayGroupId) : displayGroupId(displayGroupId) {} + + int32_t GetFocusedSessionId() { return focusedSessionId; } + int32_t GetLastFocusedSessionId() { return lastFocusedSessionId; } + int32_t GetLastFocusedAppSessionId() { return lastFocusedAppSessionId; } + bool GetNeedBlockNotifyFocusStatusUntilForeground() { return needBlockNotifyFocusStatusUntilForeground; } + bool GetNeedBlockNotifyUnfocusStatus() { return needBlockNotifyUnfocusStatus; } + DisplayId GetDisplayGroupId() { return displayGroupId; } + void SetFocusedSessionId(int32_t persistentId) { focusedSessionId = persistentId; } + void SetLastFocusedSessionId(int32_t persistentId) { lastFocusedSessionId = persistentId; } + void SetLastFocusedAppSessionId(int32_t persistentId) { lastFocusedAppSessionId = persistentId; } + void SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlock) { + needBlockNotifyFocusStatusUntilForeground = needBlock; + } + void SetNeedBlockNotifyUnfocusStatus(bool needBlock) { needBlockNotifyUnfocusStatus = needBlock; } WSError UpdateFocusedSessionId(int32_t persistentId) { - TLOGD(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId_, persistentId); - if (focusedSessionId_ == persistentId) { - TLOGD(WmsLogTag::WMS_FOCUS, "Focus scene not change, id: %{public}d", focusedSessionId_); + TLOGD(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId, persistentId); + if (focusedSessionId == persistentId) { + TLOGD(WmsLogTag::WMS_FOCUS, "Focus scene not change, id: %{public}d", focusedSessionId); return WSError::WS_DO_NOTHING; } - lastFocusedSessionId_ = focusedSessionId_; - focusedSessionId_ = persistentId; + lastFocusedSessionId = focusedSessionId; + focusedSessionId = persistentId; return WSError::WS_OK; } - WSError UpdateFocusedAppSessionId(int32_t persistentId) { - lastFocusedAppSessionId_ = persistentId; + lastFocusedAppSessionId = persistentId; return WSError::WS_OK; } - int32_t GetFocusedSessionId() - { - return focusedSessionId_; - } - - int32_t GetLastFocusedSessionId() - { - return lastFocusedSessionId_; - } - - int32_t GetLastFocusedAppSessionId() - { - return lastFocusedAppSessionId_; - } - - bool GetNeedBlockNotifyFocusStatusUntilForeground() - { - return needBlockNotifyFocusStatusUntilForeground; - } - - bool GetNeedBlockNotifyUnfocusStatus() - { - return needBlockNotifyUnfocusStatus; - } - - DisplayId GetDisplayGroupId() - { - return displayGroupId_; - } - - void SetFocusedSessionId(int32_t focusedSessionId) - { - focusedSessionId_ = focusedSessionId; - } - - void SetLastFocusedSessionId(int32_t lastFocusedSessionId) - { - lastFocusedSessionId_ = lastFocusedSessionId; - } - - void SetLastFocusedAppSessionId(int32_t lastFocusedAppSessionId) - { - lastFocusedAppSessionId_ = lastFocusedAppSessionId; - } - - void SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlock) - { - needBlockNotifyFocusStatusUntilForeground = needBlock; - } - - void SetNeedBlockNotifyUnfocusStatus(bool needBlock) - { - needBlockNotifyUnfocusStatus = needBlock; - } +private: + int32_t focusedSessionId = INVALID_SESSION_ID; + int32_t lastFocusedSessionId = INVALID_SESSION_ID; + int32_t lastFocusedAppSessionId = INVALID_SESSION_ID; + bool needBlockNotifyFocusStatusUntilForeground { false }; + bool needBlockNotifyUnfocusStatus { false }; + DisplayId displayGroupId = DISPLAY_ID_INVALID; }; class WindowFocusController { @@ -129,15 +87,16 @@ public: WSError RemoveFocusGroup(DisplayId displayId); int32_t GetFocusedSessionId(DisplayId displayId); sptr GetFocusGroup(DisplayId displayId = DEFAULT_DISPLAY_ID); - sptr GetFocusGroupInner(DisplayId displayId); std::vector> GetAllFocusedSessionList(); WSError UpdateFocusedSessionId(DisplayId displayId, int32_t persistentId); WSError UpdateFocusedAppSessionId(DisplayId displayId, int32_t persistentId); private: - std::shared_mutex focusGroupMutex_; + std::shared_mutex focusGroupMutex_; // Above guarded by focusGroupMutex_ std::unordered_map> focusGroupMap_; std::unordered_set virtualScreenDisplayIdSet_; + + sptr GetFocusGroupInner(DisplayId displayId); }; } } diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index e3052d0f63..c17e34d89b 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -67,6 +67,22 @@ WSError WindowFocusController::RemoveFocusGroup(DisplayId displayId) return WSError::WS_OK; } +sptr WindowFocusController::GetFocusGroupInner(DisplayId displayId) +{ + DisplayId displayGroupId = GetDisplayGroupId(displayId); + TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64 ", displayGroupId: %{public}" PRIu64, + displayId, displayGroupId); + if (displayGroupId == DEFAULT_DISPLAY_ID) { + return focusGroupMap_[DEFAULT_DISPLAY_ID]; + } + auto iter = focusGroupMap_.find(displayGroupId); + if (iter == focusGroupMap_.end()) { + TLOGE(WmsLogTag::WMS_FOCUS, "Not found focus group with displayId: %{public}" PRIu64, displayId); + return nullptr; + } + return iter->second; +} + int32_t WindowFocusController::GetFocusedSessionId(DisplayId displayId) { TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64, displayId); @@ -95,22 +111,6 @@ sptr WindowFocusController::GetFocusGroup(DisplayId displayId) return focusGroup; } -sptr WindowFocusController::GetFocusGroupInner(DisplayId displayId) -{ - DisplayId displayGroupId = GetDisplayGroupId(displayId); - TLOGD(WmsLogTag::WMS_FOCUS, "displayId: %{public}" PRIu64 ", displayGroupId: %{public}" PRIu64, - displayId, displayGroupId); - if (displayGroupId == DEFAULT_DISPLAY_ID) { - return focusGroupMap_[DEFAULT_DISPLAY_ID]; - } - auto iter = focusGroupMap_.find(displayGroupId); - if (iter == focusGroupMap_.end()) { - TLOGE(WmsLogTag::WMS_FOCUS, "Not found focus group with displayId: %{public}" PRIu64, displayId); - return nullptr; - } - return iter->second; -} - std::vector> WindowFocusController::GetAllFocusedSessionList() { TLOGI(WmsLogTag::WMS_FOCUS, "in"); -- Gitee From 879251a34ea04104820f252dcf6895066b940f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sat, 18 Jan 2025 16:06:37 +0800 Subject: [PATCH 21/45] fix focus controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/session_manager/include/scene_session_manager.h | 2 +- window_scene/session_manager/src/window_focus_controller.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index d8c74bcfab..7fe26cc589 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -954,7 +954,7 @@ private: SystemSessionConfig systemConfig_; FocusChangeReason focusChangeReason_ = FocusChangeReason::DEFAULT; float snapshotScale_ = 0.5; - sptr windowFocusController_; + std::shared_ptr windowFocusController_; int32_t brightnessSessionId_ = INVALID_SESSION_ID; float displayBrightness_ = UNDEFINED_BRIGHTNESS; bool isScreenLocked_ {false}; diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index c17e34d89b..9693f317b3 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -128,7 +128,6 @@ std::vector> WindowFocusController::GetAllFocusedS } allFocusGroup.emplace_back(std::make_pair(elem.first, curFocusGroup->GetFocusedSessionId())); } - TLOGD(WmsLogTag::WMS_FOCUS, "success, list size: %{public}u", allFocusGroup.size()); return allFocusGroup; } -- Gitee From a713bd1369a667e97449f6d2ab7f947a7a66f7c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sat, 18 Jan 2025 16:59:58 +0800 Subject: [PATCH 22/45] remove focusGroupMutex_ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/window_focus_controller.h | 1 - .../src/scene_session_manager.cpp | 46 +++++++++++-------- .../src/window_focus_controller.cpp | 14 +----- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index ac1bf1a2ff..d15174a8db 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -92,7 +92,6 @@ public: WSError UpdateFocusedAppSessionId(DisplayId displayId, int32_t persistentId); private: - std::shared_mutex focusGroupMutex_; // Above guarded by focusGroupMutex_ std::unordered_map> focusGroupMap_; std::unordered_set virtualScreenDisplayIdSet_; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index cd970e1e26..d0803366dd 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5479,12 +5479,12 @@ WSError SceneSessionManager::RequestSessionUnfocus(int32_t persistentId, FocusCh { TLOGD(WmsLogTag::WMS_FOCUS, "id: %{public}d", persistentId); if (persistentId == INVALID_SESSION_ID) { - WLOGFE("id is invalid"); + TLOGE(WmsLogTag::WMS_FOCUS, "id is invalid"); return WSError::WS_ERROR_INVALID_SESSION; } auto sceneSession = GetSceneSession(persistentId); if (sceneSession == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "session is nullptr"); + TLOGE(WmsLogTag::WMS_FOCUS, "session is nullptr: %{public}d", persistentId); return WSError::WS_ERROR_INVALID_SESSION; } auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); @@ -5526,7 +5526,7 @@ WSError SceneSessionManager::RequestAllAppSessionUnfocusInner() TLOGI(WmsLogTag::WMS_FOCUS, "in"); auto focusGroup = windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, DEFAULT_DISPLAY_ID); return WSError::WS_ERROR_INVALID_SESSION; } auto focusedSession = GetSceneSession(focusGroup->GetFocusedSessionId()); @@ -5535,7 +5535,7 @@ WSError SceneSessionManager::RequestAllAppSessionUnfocusInner() return WSError::WS_DO_NOTHING; } if (!focusedSession->IsAppSession()) { - WLOGW("[WMFocus]Focused session is non app session: %{public}d", focusGroup->GetFocusedSessionId()); + TLOGW(WmsLogTag::WMS_FOCUS, "Focused session is non app: %{public}d", focusGroup->GetFocusedSessionId()); return WSError::WS_DO_NOTHING; } auto nextSession = GetTopFocusableNonAppSession(); @@ -5576,7 +5576,7 @@ bool SceneSessionManager::CheckLastFocusedAppSessionFocus( auto displayId = focusedSession->GetSessionProperty()->GetDisplayId(); auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); return false; } auto lastFocusedAppSessionId = focusGroup->GetLastFocusedAppSessionId(); @@ -5938,7 +5938,7 @@ void SceneSessionManager::UpdateFocusStatus(DisplayId displayId, sptrGetFocusGroup(displayId); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); return; } bool needBlockNotifyFocusStatusUntilForeground = focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground(); @@ -6592,7 +6592,7 @@ void SceneSessionManager::ProcessFocusWhenForeground(sptr& sceneSe auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); return; } bool needBlockNotifyFocusStatusUntilForeground = focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground(); @@ -6782,7 +6782,7 @@ void SceneSessionManager::ProcessSubSessionForeground(sptr& sceneS auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); return; } auto focusedSessionId = focusGroup->GetFocusedSessionId(); @@ -8928,8 +8928,12 @@ WSError SceneSessionManager::GetFocusSessionToken(sptr& token, Di } return taskScheduler_->PostSyncTask([this, &token, where = __func__, displayId]() { auto focusGroup = windowFocusController_->GetFocusGroup(displayId); - TLOGND(WmsLogTag::WMS_FOCUS, "%{public}s with focusedSessionId: %{public}d", where, - focusGroup->GetFocusedSessionId()); + if (focusGroup == nullptr) { + TLOGNE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); + return WSError::WS_ERROR_INVALID_SESSION; + } + TLOGND(WmsLogTag::WMS_FOCUS, "%{public}s with focusedSessionId: %{public}d", + where, focusGroup->GetFocusedSessionId()); if (auto sceneSession = GetSceneSession(focusGroup->GetFocusedSessionId())) { token = sceneSession->GetAbilityToken(); if (token == nullptr) { @@ -8953,8 +8957,12 @@ WSError SceneSessionManager::GetFocusSessionElement(AppExecFwk::ElementName& ele } return taskScheduler_->PostSyncTask([this, &element, where = __func__, displayId]() { auto focusGroup = windowFocusController_->GetFocusGroup(displayId); - TLOGND(WmsLogTag::WMS_FOCUS, "%{public}s with focusedSessionId: %{public}d", where, - focusGroup->GetFocusedSessionId()); + if (focusGroup == nullptr) { + TLOGNE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); + return WSError::WS_ERROR_INVALID_SESSION; + } + TLOGND(WmsLogTag::WMS_FOCUS, "%{public}s with focusedSessionId: %{public}d", + where, focusGroup->GetFocusedSessionId()); if (auto sceneSession = GetSceneSession(focusGroup->GetFocusedSessionId())) { const auto& sessionInfo = sceneSession->GetSessionInfo(); element = AppExecFwk::ElementName("", sessionInfo.bundleName_, @@ -10277,12 +10285,12 @@ void SceneSessionManager::ProcessUpdateLastFocusedAppId(const std::vectorGetFocusGroup(DEFAULT_DISPLAY_ID); if (focusGroup == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, DEFAULT_DISPLAY_ID); return; } auto lastFocusedAppSessionId = focusGroup->GetLastFocusedAppSessionId(); - TLOGD(WmsLogTag::WMS_FOCUS, "last focused app: %{public}d, list size %{public}zu", lastFocusedAppSessionId, - zOrderList.size()); + TLOGD(WmsLogTag::WMS_FOCUS, "last focused app: %{public}d, list size %{public}zu", + lastFocusedAppSessionId, zOrderList.size()); if (lastFocusedAppSessionId == INVALID_SESSION_ID || zOrderList.empty()) { return; } @@ -10509,7 +10517,7 @@ WSError SceneSessionManager::RaiseWindowToTop(int32_t persistentId) WSError SceneSessionManager::ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId) { - WLOGFI("from id: %{public}d to id: %{public}d", sourcePersistentId, targetPersistentId); + TLOGI(WmsLogTag::WMS_FOCUS, "from id: %{public}d to id: %{public}d", sourcePersistentId, targetPersistentId); sptr sourceSession = nullptr; WSError ret = GetAppMainSceneSession(sourceSession, sourcePersistentId); if (ret != WSError::WS_OK) { @@ -10523,16 +10531,16 @@ WSError SceneSessionManager::ShiftAppWindowFocus(int32_t sourcePersistentId, int auto displayId = sourceSession->GetSessionProperty()->GetDisplayId(); auto focusedSessionId = GetFocusedSessionId(displayId); if (sourcePersistentId != focusedSessionId) { - WLOGFE("source session need be focused"); + TLOGE(WmsLogTag::WMS_FOCUS, "source session need be focused, focusedSessionId: %{public}d", focusedSessionId); return WSError::WS_ERROR_INVALID_OPERATION; } if (targetPersistentId == focusedSessionId) { - WLOGFE("target session has been focused"); + TLOGE(WmsLogTag::WMS_FOCUS, "target session has been focused, focusedSessionId: %{public}d", focusedSessionId); return WSError::WS_DO_NOTHING; } if (sourceSession->GetSessionInfo().bundleName_ != targetSession->GetSessionInfo().bundleName_) { - WLOGFE("verify bundle failed, source name is %{public}s but target name is %{public}s)", + TLOGE(WmsLogTag::WMS_FOCUS, "verify bundle failed, source name is %{public}s but target name is %{public}s)", sourceSession->GetSessionInfo().bundleName_.c_str(), targetSession->GetSessionInfo().bundleName_.c_str()); return WSError::WS_ERROR_INVALID_CALLING; } diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index 9693f317b3..2e67e59014 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "../include/window_focus_controller.h" +#include "session_manager/include/window_focus_controller.h" namespace OHOS { namespace Rosen { @@ -43,7 +43,6 @@ WSError WindowFocusController::AddFocusGroup(DisplayId displayId) TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); return WSError::WS_ERROR_INVALID_PARAM; } - std::shared_lock lock(focusGroupMutex_); sptr focusGroup = sptr::MakeSptr(displayId); focusGroupMap_.insert(std::make_pair(displayId, focusGroup)); if (displayId != DEFAULT_DISPLAY_ID) { @@ -59,7 +58,6 @@ WSError WindowFocusController::RemoveFocusGroup(DisplayId displayId) TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); return WSError::WS_ERROR_INVALID_PARAM; } - std::shared_lock lock(focusGroupMutex_); focusGroupMap_.erase(displayId); if (displayId != DEFAULT_DISPLAY_ID) { virtualScreenDisplayIdSet_.erase(displayId); @@ -90,7 +88,6 @@ int32_t WindowFocusController::GetFocusedSessionId(DisplayId displayId) TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); return INVALID_SESSION_ID; } - std::shared_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}" PRIu64, displayId); @@ -106,7 +103,6 @@ sptr WindowFocusController::GetFocusGroup(DisplayId displayId) TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); return nullptr; } - std::shared_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); return focusGroup; } @@ -114,11 +110,7 @@ sptr WindowFocusController::GetFocusGroup(DisplayId displayId) std::vector> WindowFocusController::GetAllFocusedSessionList() { TLOGI(WmsLogTag::WMS_FOCUS, "in"); - std::unordered_map> focusGroupMapCopy; - { - std::shared_lock lock(focusGroupMutex_); - focusGroupMapCopy = focusGroupMap_; - } + std::unordered_map> focusGroupMapCopy = focusGroupMap_; std::vector> allFocusGroup; for (const auto& elem : focusGroupMapCopy) { auto curFocusGroup = elem.second; @@ -138,7 +130,6 @@ WSError WindowFocusController::UpdateFocusedSessionId(DisplayId displayId, int32 TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); return WSError::WS_ERROR_INVALID_PARAM; } - std::unique_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}" PRIu64, displayId); @@ -154,7 +145,6 @@ WSError WindowFocusController::UpdateFocusedAppSessionId(DisplayId displayId, in TLOGE(WmsLogTag::WMS_FOCUS, "displayId id invalid"); return WSError::WS_ERROR_INVALID_PARAM; } - std::unique_lock lock(focusGroupMutex_); auto focusGroup = GetFocusGroupInner(displayId); if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null, displayId: %{public}" PRIu64, displayId); -- Gitee From c30c75d24988c4d8a8fc1d9defca5125928a2591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sat, 18 Jan 2025 17:34:09 +0800 Subject: [PATCH 23/45] fix topmost and dialog format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../src/scene_session_manager.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index d0803366dd..2d800d3975 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -6819,10 +6819,10 @@ WSError SceneSessionManager::ProcessModalTopmostRequestFocusImmdediately(sptrGetSessionProperty()->GetDisplayId(); auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); if (std::find_if(topmostVec.begin(), topmostVec.end(), - [this, focusedSessionId](sptr& iter) { return iter && iter->GetPersistentId() == focusedSessionId; }) - != topmostVec.end()) { - TLOGND(WmsLogTag::WMS_SUB, "modal topmost subwindow id: %{public}d has been focused!", focusedSessionId); - return WSError::WS_OK; + [this, focusedSessionId](sptr& iter) { return iter && + iter->GetPersistentId() == focusedSessionId; }) != topmostVec.end()) { + TLOGND(WmsLogTag::WMS_SUB, "modal topmost subwindow id: %{public}d has been focused!", focusedSessionId); + return WSError::WS_OK; } WSError ret = WSError::WS_DO_NOTHING; for (auto topmostSession : topmostVec) { @@ -6854,10 +6854,10 @@ WSError SceneSessionManager::ProcessDialogRequestFocusImmdediately(sptrGetSessionProperty()->GetDisplayId(); auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); if (std::find_if(dialogVec.begin(), dialogVec.end(), - [this, focusedSessionId](sptr& iter) { return iter && iter->GetPersistentId() == focusedSessionId; }) - != dialogVec.end()) { - TLOGND(WmsLogTag::WMS_DIALOG, "dialog id: %{public}d has been focused!", focusedSessionId); - return WSError::WS_OK; + [this, focusedSessionId](sptr& iter) { return iter && + iter->GetPersistentId() == focusedSessionId; }) != dialogVec.end()) { + TLOGND(WmsLogTag::WMS_DIALOG, "dialog id: %{public}d has been focused!", focusedSessionId); + return WSError::WS_OK; } WSError ret = WSError::WS_DO_NOTHING; for (auto dialog : dialogVec) { -- Gitee From 397b89cf69f9cb6ce8cb0608ada4569998e89bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sat, 18 Jan 2025 17:58:27 +0800 Subject: [PATCH 24/45] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/session_manager/include/window_focus_controller.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index d15174a8db..80786ab02c 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -47,7 +47,8 @@ public: void SetFocusedSessionId(int32_t persistentId) { focusedSessionId = persistentId; } void SetLastFocusedSessionId(int32_t persistentId) { lastFocusedSessionId = persistentId; } void SetLastFocusedAppSessionId(int32_t persistentId) { lastFocusedAppSessionId = persistentId; } - void SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlock) { + void SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlock) + { needBlockNotifyFocusStatusUntilForeground = needBlock; } void SetNeedBlockNotifyUnfocusStatus(bool needBlock) { needBlockNotifyUnfocusStatus = needBlock; } -- Gitee From 9ef4669d02e2c9ba9cdeb1c6492254bbd08bd424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sun, 19 Jan 2025 11:26:46 +0800 Subject: [PATCH 25/45] fix windowFocusController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/scene_session_manager.h | 15 +++---- .../include/window_focus_controller.h | 40 +++++-------------- .../src/scene_session_manager.cpp | 2 +- .../src/window_focus_controller.cpp | 22 ++++++++-- 4 files changed, 38 insertions(+), 41 deletions(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 7fe26cc589..4177ddd3bd 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -688,13 +688,18 @@ private: void ResetWantInfo(const sptr& sceneSession); void ResetSceneSessionInfoWant(const sptr& sceneSessionInfo); - /* - * Window Focus - */ std::vector>> GetSceneSessionVector(CmpFunc cmp); void TraverseSessionTree(TraverseFunc func, bool isFromTopToBottom); void TraverseSessionTreeFromTopToBottom(TraverseFunc func); void TraverseSessionTreeFromBottomToTop(TraverseFunc func); + + /* + * Window Focus + */ + sptr windowFocusController_; + FocusChangeReason focusChangeReason_ = FocusChangeReason::DEFAULT; + bool needBlockNotifyFocusStatusUntilForeground_ {false}; + bool needBlockNotifyUnfocusStatus_ {false}; WSError RequestSessionFocus(int32_t persistentId, bool byForeground = true, FocusChangeReason reason = FocusChangeReason::DEFAULT); WSError RequestSessionFocusImmediately(int32_t persistentId); @@ -952,14 +957,10 @@ private: NotifyStartPiPFailedFunc startPiPFailedFunc_; SystemSessionConfig systemConfig_; - FocusChangeReason focusChangeReason_ = FocusChangeReason::DEFAULT; float snapshotScale_ = 0.5; - std::shared_ptr windowFocusController_; int32_t brightnessSessionId_ = INVALID_SESSION_ID; float displayBrightness_ = UNDEFINED_BRIGHTNESS; bool isScreenLocked_ {false}; - bool needBlockNotifyFocusStatusUntilForeground_ {false}; - bool needBlockNotifyUnfocusStatus_ {false}; bool isPrepareTerminateEnable_ {false}; /* diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index 80786ab02c..3adc014779 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -28,22 +28,16 @@ namespace OHOS { namespace Rosen { - -/** - * @struct FocusGroup - * - * @brief Window focus group of a screen - */ -struct FocusGroup : public RefBase { +class FocusGroup : public RefBase { public: explicit FocusGroup(DisplayId displayGroupId) : displayGroupId(displayGroupId) {} - int32_t GetFocusedSessionId() { return focusedSessionId; } - int32_t GetLastFocusedSessionId() { return lastFocusedSessionId; } - int32_t GetLastFocusedAppSessionId() { return lastFocusedAppSessionId; } - bool GetNeedBlockNotifyFocusStatusUntilForeground() { return needBlockNotifyFocusStatusUntilForeground; } - bool GetNeedBlockNotifyUnfocusStatus() { return needBlockNotifyUnfocusStatus; } - DisplayId GetDisplayGroupId() { return displayGroupId; } + int32_t GetFocusedSessionId() const { return focusedSessionId; } + int32_t GetLastFocusedSessionId() const { return lastFocusedSessionId; } + int32_t GetLastFocusedAppSessionId() const { return lastFocusedAppSessionId; } + bool GetNeedBlockNotifyFocusStatusUntilForeground() const { return needBlockNotifyFocusStatusUntilForeground; } + bool GetNeedBlockNotifyUnfocusStatus() const { return needBlockNotifyUnfocusStatus; } + DisplayId GetDisplayGroupId() const { return displayGroupId; } void SetFocusedSessionId(int32_t persistentId) { focusedSessionId = persistentId; } void SetLastFocusedSessionId(int32_t persistentId) { lastFocusedSessionId = persistentId; } void SetLastFocusedAppSessionId(int32_t persistentId) { lastFocusedAppSessionId = persistentId; } @@ -52,22 +46,8 @@ public: needBlockNotifyFocusStatusUntilForeground = needBlock; } void SetNeedBlockNotifyUnfocusStatus(bool needBlock) { needBlockNotifyUnfocusStatus = needBlock; } - WSError UpdateFocusedSessionId(int32_t persistentId) - { - TLOGD(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId, persistentId); - if (focusedSessionId == persistentId) { - TLOGD(WmsLogTag::WMS_FOCUS, "Focus scene not change, id: %{public}d", focusedSessionId); - return WSError::WS_DO_NOTHING; - } - lastFocusedSessionId = focusedSessionId; - focusedSessionId = persistentId; - return WSError::WS_OK; - } - WSError UpdateFocusedAppSessionId(int32_t persistentId) - { - lastFocusedAppSessionId = persistentId; - return WSError::WS_OK; - } + WSError UpdateFocusedSessionId(int32_t persistentId); + WSError UpdateFocusedAppSessionId(int32_t persistentId); private: int32_t focusedSessionId = INVALID_SESSION_ID; @@ -78,7 +58,7 @@ private: DisplayId displayGroupId = DISPLAY_ID_INVALID; }; -class WindowFocusController { +class WindowFocusController : public RefBase { public: WindowFocusController() noexcept; ~WindowFocusController() = default; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 2d800d3975..878a9b2c25 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -308,7 +308,7 @@ SceneSessionManager::SceneSessionManager() : rsInterface_(RSInterfaces::GetInsta scbDumpSubscriber_ = ScbDumpSubscriber::Subscribe(); listenerController_ = std::make_shared(); - windowFocusController_ = std::make_shared(); + windowFocusController_ = sptr::MakeSptr(); } SceneSessionManager::~SceneSessionManager() diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index 2e67e59014..d2d30a110a 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -18,6 +18,24 @@ namespace OHOS { namespace Rosen { +WSError FocusGroup::UpdateFocusedSessionId() +{ + TLOGD(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId, persistentId); + if (focusedSessionId == persistentId) { + TLOGD(WmsLogTag::WMS_FOCUS, "Focus scene not change, id: %{public}d", focusedSessionId); + return WSError::WS_DO_NOTHING; + } + lastFocusedSessionId = focusedSessionId; + focusedSessionId = persistentId; + return WSError::WS_OK; +} + +WSError FocusGroup::UpdateFocusedAppSessionId() +{ + lastFocusedAppSessionId = persistentId; + return WSError::WS_OK; +} + WindowFocusController::WindowFocusController() noexcept { TLOGI(WmsLogTag::WMS_FOCUS, "constructor"); @@ -109,10 +127,8 @@ sptr WindowFocusController::GetFocusGroup(DisplayId displayId) std::vector> WindowFocusController::GetAllFocusedSessionList() { - TLOGI(WmsLogTag::WMS_FOCUS, "in"); - std::unordered_map> focusGroupMapCopy = focusGroupMap_; std::vector> allFocusGroup; - for (const auto& elem : focusGroupMapCopy) { + for (const auto& elem : focusGroupMap_) { auto curFocusGroup = elem.second; if (curFocusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is null"); -- Gitee From 5e11c19bdfb58bddae975918427079874d1c23fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sun, 19 Jan 2025 11:27:18 +0800 Subject: [PATCH 26/45] fix format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- interfaces/innerkits/wm/wm_common.h | 3 ++- .../src/screen_session_manager_client.cpp | 4 ++-- .../src/zidl/scene_session_manager_lite_stub.cpp | 12 ++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 4aba95425f..a1ffe2077c 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -46,7 +46,8 @@ constexpr uint32_t MIN_CLOSE_BUTTON_RIGHT_MARGIN = 8; constexpr uint32_t MAX_CLOSE_BUTTON_RIGHT_MARGIN = 22; } using DisplayId = uint64_t; -constexpr DisplayId DEFAULT_DISPLAY_ID = 0; +inline constexpr DisplayId DEFAULT_DISPLAY_ID = 0; + /** * @brief Enumerates type of window. */ diff --git a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp index f13bd32aa4..77e09f6f3e 100644 --- a/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp +++ b/window_scene/screen_session_manager_client/src/screen_session_manager_client.cpp @@ -82,11 +82,11 @@ void ScreenSessionManagerClient::RegisterScreenConnectionChangeListener( const sptr& listener) { if (listener == nullptr) { - TLOGE(WmsLogTag::DMS, "Failed to register screen connection change listener, listener is null"); + TLOGE(WmsLogTag::DMS, "Failed: listener is null"); return; } screenConnectionChangeListener_ = listener; - TLOGE(WmsLogTag::DMS, "Success to register screen connection change listener"); + TLOGI(WmsLogTag::DMS, "Success"); } void ScreenSessionManagerClient::NotifyScreenConnect(const sptr& screenSession) diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp index d50cb1aa48..2b42912880 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp @@ -371,13 +371,13 @@ int SceneSessionManagerLiteStub::HandleTerminateSessionNew(MessageParcel& data, int SceneSessionManagerLiteStub::HandleGetFocusSessionToken(MessageParcel& data, MessageParcel& reply) { - WLOGFD("run HandleGetFocusSessionToken!"); - sptr token = nullptr; + TLOGD(WmsLogTag::WMS_FOCUS, "run"); uint64_t displayId = 0; if (!data.ReadUint64(displayId)) { TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId"); return ERR_INVALID_DATA; } + sptr token = nullptr; WSError errCode = GetFocusSessionToken(token, displayId); reply.WriteRemoteObject(token); reply.WriteInt32(static_cast(errCode)); @@ -386,13 +386,13 @@ int SceneSessionManagerLiteStub::HandleGetFocusSessionToken(MessageParcel& data, int SceneSessionManagerLiteStub::HandleGetFocusSessionElement(MessageParcel& data, MessageParcel& reply) { - WLOGFD("run HandleGetFocusSessionElement!"); - AppExecFwk::ElementName element; + TLOGD(WmsLogTag::WMS_FOCUS, "run"); uint64_t displayId = 0; if (!data.ReadUint64(displayId)) { TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId"); return ERR_INVALID_DATA; } + AppExecFwk::ElementName element; WSError errCode = GetFocusSessionElement(element, displayId); reply.WriteParcelable(&element); reply.WriteInt32(static_cast(errCode)); @@ -522,13 +522,13 @@ int SceneSessionManagerLiteStub::HandleMoveSessionsToBackground(MessageParcel& d int SceneSessionManagerLiteStub::HandleGetFocusSessionInfo(MessageParcel& data, MessageParcel& reply) { - WLOGFD("run"); - FocusChangeInfo focusInfo; + TLOGD("run"); uint64_t displayId = 0; if (!data.ReadUint64(displayId)) { TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId"); return ERR_INVALID_DATA; } + FocusChangeInfo focusInfo; GetFocusWindowInfo(focusInfo, displayId); reply.WriteParcelable(&focusInfo); return ERR_NONE; -- Gitee From 1d0aac38ec381a9473d8172bbd1255c93a7d4a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sun, 19 Jan 2025 11:42:16 +0800 Subject: [PATCH 27/45] fix sptr& MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/scene_session_manager.h | 34 +++++++++--------- .../src/scene_session_manager.cpp | 36 +++++++++---------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 4177ddd3bd..7440be7354 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -705,32 +705,32 @@ private: WSError RequestSessionFocusImmediately(int32_t persistentId); WSError RequestSessionUnfocus(int32_t persistentId, FocusChangeReason reason = FocusChangeReason::DEFAULT); WSError RequestAllAppSessionUnfocusInner(); - WSError RequestFocusBasicCheck(int32_t persistentId, sptr& focusGroup); - bool CheckLastFocusedAppSessionFocus(sptr& focusedSession, sptr& nextSession); - WSError RequestFocusSpecificCheck(DisplayId displayId, sptr& sceneSession, bool byForeground, + WSError RequestFocusBasicCheck(int32_t persistentId, sptr focusGroup); + bool CheckLastFocusedAppSessionFocus(sptr focusedSession, sptr nextSession); + WSError RequestFocusSpecificCheck(DisplayId displayId, sptr sceneSession, bool byForeground, FocusChangeReason reason = FocusChangeReason::DEFAULT); - bool CheckTopmostWindowFocus(sptr& focusedSession, sptr& sceneSession); - bool CheckRequestFocusImmdediately(sptr& sceneSession); - bool CheckFocusIsDownThroughBlockingType(sptr& requestSceneSession, - sptr& focusedSession, bool includingAppSession); - bool CheckClickFocusIsDownThroughFullScreen(const sptr& focusedSession, - const sptr& sceneSession, FocusChangeReason reason); - bool IsParentSessionVisible(const sptr& session); + bool CheckTopmostWindowFocus(sptr focusedSession, sptr sceneSession); + bool CheckRequestFocusImmdediately(sptr sceneSession); + bool CheckFocusIsDownThroughBlockingType(sptr requestSceneSession, + sptr focusedSession, bool includingAppSession); + bool CheckClickFocusIsDownThroughFullScreen(sptr focusedSession, + sptr sceneSession, FocusChangeReason reason); + bool IsParentSessionVisible(sptr session); sptr GetNextFocusableSession(DisplayId displayId, int32_t persistentId); sptr GetTopNearestBlockingFocusSession(DisplayId displayId, uint32_t zOrder, bool includingAppSession); sptr GetTopFocusableNonAppSession(); - WSError ShiftFocus(DisplayId displayId, sptr& nextSession, + WSError ShiftFocus(DisplayId displayId, sptr nextSession, FocusChangeReason reason = FocusChangeReason::DEFAULT); - void UpdateFocusStatus(DisplayId displayId, sptr& sceneSession, bool isFocused); - void NotifyFocusStatus(sptr& sceneSession, bool isFocused, sptr& focusGroup); + void UpdateFocusStatus(DisplayId displayId, sptr sceneSession, bool isFocused); + void NotifyFocusStatus(sptr sceneSession, bool isFocused, sptr focusGroup); int32_t NotifyRssThawApp(const int32_t uid, const std::string& bundleName, const std::string& reason); - void NotifyFocusStatusByMission(sptr& prevSession, sptr& currSession); - void NotifyUnFocusedByMission(sptr& sceneSession); - bool MissionChanged(sptr& prevSession, sptr& currSession); + void NotifyFocusStatusByMission(sptr prevSession, sptr currSession); + void NotifyUnFocusedByMission(sptr sceneSession); + bool MissionChanged(sptr prevSession, sptr currSession); std::string GetAllSessionFocusInfo(); - void RegisterRequestFocusStatusNotifyManagerFunc(sptr& sceneSession); + void RegisterRequestFocusStatusNotifyManagerFunc(sptr sceneSession); void ProcessUpdateLastFocusedAppId(const std::vector& zOrderList); void RegisterGetStateFromManagerFunc(sptr& sceneSession); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 878a9b2c25..a069770f8b 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5545,7 +5545,7 @@ WSError SceneSessionManager::RequestAllAppSessionUnfocusInner() return ShiftFocus(DEFAULT_DISPLAY_ID, nextSession, FocusChangeReason::WIND); } -WSError SceneSessionManager::RequestFocusBasicCheck(int32_t persistentId, sptr& focusGroup) +WSError SceneSessionManager::RequestFocusBasicCheck(int32_t persistentId, sptr focusGroup) { // basic focus rule if (persistentId == INVALID_SESSION_ID) { @@ -5568,7 +5568,7 @@ WSError SceneSessionManager::RequestFocusBasicCheck(int32_t persistentId, sptr& focusedSession, sptr& nextSession) + sptr focusedSession, sptr nextSession) { if (focusedSession == nullptr || nextSession == nullptr) { return false; @@ -5610,8 +5610,8 @@ bool SceneSessionManager::CheckLastFocusedAppSessionFocus( * * @return true: traversed downwards, false: not. */ -bool SceneSessionManager::CheckFocusIsDownThroughBlockingType(sptr& requestSceneSession, - sptr& focusedSession, bool includingAppSession) +bool SceneSessionManager::CheckFocusIsDownThroughBlockingType(sptr requestSceneSession, + sptr focusedSession, bool includingAppSession) { uint32_t requestSessionZOrder = requestSceneSession->GetZOrder(); uint32_t focusedSessionZOrder = focusedSession->GetZOrder(); @@ -5637,7 +5637,7 @@ bool SceneSessionManager::CheckFocusIsDownThroughBlockingType(sptr return false; } -bool SceneSessionManager::CheckTopmostWindowFocus(sptr& focusedSession, sptr& sceneSession) +bool SceneSessionManager::CheckTopmostWindowFocus(sptr focusedSession, sptr sceneSession) { bool isFocusedMainSessionTopmost = focusedSession->GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW && focusedSession->IsTopmost(); @@ -5651,7 +5651,7 @@ bool SceneSessionManager::CheckTopmostWindowFocus(sptr& focusedSes return false; } -bool SceneSessionManager::CheckRequestFocusImmdediately(sptr& sceneSession) +bool SceneSessionManager::CheckRequestFocusImmdediately(sptr sceneSession) { if ((sceneSession->GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW || (SessionHelper::IsSubWindow(sceneSession->GetWindowType()) && !sceneSession->IsModal())) && @@ -5663,8 +5663,8 @@ bool SceneSessionManager::CheckRequestFocusImmdediately(sptr& scen return false; } -bool SceneSessionManager::CheckClickFocusIsDownThroughFullScreen(const sptr& focusedSession, - const sptr& sceneSession, FocusChangeReason reason) +bool SceneSessionManager::CheckClickFocusIsDownThroughFullScreen(sptr focusedSession, + sptr sceneSession, FocusChangeReason reason) { if (focusedSession->GetWindowType() != WindowType::WINDOW_TYPE_GLOBAL_SEARCH && focusedSession->GetWindowType() != WindowType::WINDOW_TYPE_NEGATIVE_SCREEN) { @@ -5676,7 +5676,7 @@ bool SceneSessionManager::CheckClickFocusIsDownThroughFullScreen(const sptrGetZOrder() < focusedSession->GetZOrder(); } -WSError SceneSessionManager::RequestFocusSpecificCheck(DisplayId displayId, sptr& sceneSession, +WSError SceneSessionManager::RequestFocusSpecificCheck(DisplayId displayId, sptr sceneSession, bool byForeground,FocusChangeReason reason) { TLOGD(WmsLogTag::WMS_FOCUS, "FocusChangeReason: %{public}d", reason); @@ -5734,7 +5734,7 @@ WSError SceneSessionManager::RequestFocusSpecificCheck(DisplayId displayId, sptr return WSError::WS_OK; } -bool SceneSessionManager::IsParentSessionVisible(const sptr& session) +bool SceneSessionManager::IsParentSessionVisible(sptr session) { if (WindowHelper::IsSubWindow(session->GetWindowType()) || session->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) { @@ -5898,7 +5898,7 @@ void SceneSessionManager::SetAbilityManagerCollaboratorRegisteredFunc( taskScheduler_->PostAsyncTask(task, __func__); } -WSError SceneSessionManager::ShiftFocus(DisplayId displayId, sptr& nextSession, FocusChangeReason reason) +WSError SceneSessionManager::ShiftFocus(DisplayId displayId, sptr nextSession, FocusChangeReason reason) { // unfocus auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); @@ -5934,7 +5934,7 @@ WSError SceneSessionManager::ShiftFocus(DisplayId displayId, sptr& return WSError::WS_OK; } -void SceneSessionManager::UpdateFocusStatus(DisplayId displayId, sptr& sceneSession, bool isFocused) +void SceneSessionManager::UpdateFocusStatus(DisplayId displayId, sptr sceneSession, bool isFocused) { auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { @@ -5969,8 +5969,8 @@ void SceneSessionManager::UpdateFocusStatus(DisplayId displayId, sptr& sceneSession, bool isFocused, - sptr& focusGroup) +void SceneSessionManager::NotifyFocusStatus(sptr sceneSession, bool isFocused, + sptr focusGroup) { auto lastFocusedSessionId = focusGroup->GetLastFocusedSessionId(); if (sceneSession == nullptr) { @@ -6027,7 +6027,7 @@ int32_t SceneSessionManager::NotifyRssThawApp(const int32_t uid, const std::stri return ResourceSchedule::ResSchedClient::GetInstance().ReportSyncEvent(resType, 0, payload, reply); } -void SceneSessionManager::NotifyFocusStatusByMission(sptr& prevSession, sptr& currSession) +void SceneSessionManager::NotifyFocusStatusByMission(sptr prevSession, sptr currSession) { if (prevSession && !prevSession->GetSessionInfo().isSystem_) { TLOGD(WmsLogTag::WMS_FOCUS, "Unfocused, id: %{public}d", prevSession->GetMissionId()); @@ -6039,7 +6039,7 @@ void SceneSessionManager::NotifyFocusStatusByMission(sptr& prevSes } } -void SceneSessionManager::NotifyUnFocusedByMission(sptr& sceneSession) +void SceneSessionManager::NotifyUnFocusedByMission(sptr sceneSession) { if (sceneSession && !sceneSession->GetSessionInfo().isSystem_) { TLOGD(WmsLogTag::WMS_FOCUS, "id: %{public}d", sceneSession->GetMissionId()); @@ -6047,7 +6047,7 @@ void SceneSessionManager::NotifyUnFocusedByMission(sptr& sceneSess } } -bool SceneSessionManager::MissionChanged(sptr& prevSession, sptr& currSession) +bool SceneSessionManager::MissionChanged(sptr prevSession, sptr currSession) { if (prevSession == nullptr && currSession == nullptr) { return false; @@ -6451,7 +6451,7 @@ void SceneSessionManager::RegisterSessionInfoChangeNotifyManagerFunc(sptr& sceneSession) +void SceneSessionManager::RegisterRequestFocusStatusNotifyManagerFunc(sptr sceneSession) { if (sceneSession == nullptr) { WLOGFE("session is nullptr"); -- Gitee From 5613401d8aa1640038c9508e2ab0e419be7c2233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sun, 19 Jan 2025 12:01:01 +0800 Subject: [PATCH 28/45] fix tlog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../src/zidl/scene_session_manager_lite_stub.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp index 2b42912880..50c1266bd1 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_lite_stub.cpp @@ -522,7 +522,7 @@ int SceneSessionManagerLiteStub::HandleMoveSessionsToBackground(MessageParcel& d int SceneSessionManagerLiteStub::HandleGetFocusSessionInfo(MessageParcel& data, MessageParcel& reply) { - TLOGD("run"); + TLOGD(WmsLogTag::WMS_FOCUS, "run"); uint64_t displayId = 0; if (!data.ReadUint64(displayId)) { TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId"); -- Gitee From 795557c81d49e82d5ac858d7f28f4528611fb806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Sun, 19 Jan 2025 12:42:01 +0800 Subject: [PATCH 29/45] fix UpdateFocusedSessionId MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/session_manager/src/window_focus_controller.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index d2d30a110a..c9a2a07e69 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -18,7 +18,7 @@ namespace OHOS { namespace Rosen { -WSError FocusGroup::UpdateFocusedSessionId() +WSError FocusGroup::UpdateFocusedSessionId(int32_t persistentId) { TLOGD(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId, persistentId); if (focusedSessionId == persistentId) { @@ -30,7 +30,7 @@ WSError FocusGroup::UpdateFocusedSessionId() return WSError::WS_OK; } -WSError FocusGroup::UpdateFocusedAppSessionId() +WSError FocusGroup::UpdateFocusedAppSessionId(int32_t persistentId) { lastFocusedAppSessionId = persistentId; return WSError::WS_OK; -- Gitee From 1b0ade7cf2fce8cd552de7fc608b2c5472f1cbbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Mon, 20 Jan 2025 14:22:57 +0800 Subject: [PATCH 30/45] fix: remove ) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/session_manager/src/scene_session_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index a069770f8b..a0cff5e265 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -12619,7 +12619,7 @@ WMError SceneSessionManager::ShiftAppWindowPointerEvent(int32_t sourcePersistent return WMError::WM_ERROR_INVALID_CALLING; } if (sourceSession->GetSessionInfo().bundleName_ != targetSession->GetSessionInfo().bundleName_) { - TLOGE(WmsLogTag::WMS_PC, "verify bundle failed, source name is %{public}s but target name is %{public}s)", + TLOGE(WmsLogTag::WMS_PC, "verify bundle failed, source name is %{public}s but target name is %{public}s", sourceSession->GetSessionInfo().bundleName_.c_str(), targetSession->GetSessionInfo().bundleName_.c_str()); return WMError::WM_ERROR_INVALID_CALLING; } -- Gitee From 2a8ba83373abc3db1a3d447344ae6455ae5e1bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Tue, 21 Jan 2025 09:46:17 +0800 Subject: [PATCH 31/45] fix const sptr& MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/scene_session_manager.h | 39 ++++++++--------- .../src/scene_session_manager.cpp | 42 ++++++++++--------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 7440be7354..fd612d0ce2 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -705,32 +705,33 @@ private: WSError RequestSessionFocusImmediately(int32_t persistentId); WSError RequestSessionUnfocus(int32_t persistentId, FocusChangeReason reason = FocusChangeReason::DEFAULT); WSError RequestAllAppSessionUnfocusInner(); - WSError RequestFocusBasicCheck(int32_t persistentId, sptr focusGroup); - bool CheckLastFocusedAppSessionFocus(sptr focusedSession, sptr nextSession); - WSError RequestFocusSpecificCheck(DisplayId displayId, sptr sceneSession, bool byForeground, + WSError RequestFocusBasicCheck(int32_t persistentId, const sptr& focusGroup); + bool CheckLastFocusedAppSessionFocus(const sptr& focusedSession, + const sptr& nextSession); + WSError RequestFocusSpecificCheck(DisplayId displayId, const sptr& sceneSession, bool byForeground, FocusChangeReason reason = FocusChangeReason::DEFAULT); - bool CheckTopmostWindowFocus(sptr focusedSession, sptr sceneSession); - bool CheckRequestFocusImmdediately(sptr sceneSession); - bool CheckFocusIsDownThroughBlockingType(sptr requestSceneSession, - sptr focusedSession, bool includingAppSession); - bool CheckClickFocusIsDownThroughFullScreen(sptr focusedSession, - sptr sceneSession, FocusChangeReason reason); - bool IsParentSessionVisible(sptr session); + bool CheckTopmostWindowFocus(const sptr& focusedSession, const sptr& sceneSession); + bool CheckRequestFocusImmdediately(const sptr& sceneSession); + bool CheckFocusIsDownThroughBlockingType(const sptr& requestSceneSession, + const sptr& focusedSession, bool includingAppSession); + bool CheckClickFocusIsDownThroughFullScreen(const sptr& focusedSession, + const sptr& sceneSession, FocusChangeReason reason); + bool IsParentSessionVisible(const sptr& session); sptr GetNextFocusableSession(DisplayId displayId, int32_t persistentId); sptr GetTopNearestBlockingFocusSession(DisplayId displayId, uint32_t zOrder, bool includingAppSession); sptr GetTopFocusableNonAppSession(); - WSError ShiftFocus(DisplayId displayId, sptr nextSession, + WSError ShiftFocus(DisplayId displayId, const sptr& nextSession, FocusChangeReason reason = FocusChangeReason::DEFAULT); - void UpdateFocusStatus(DisplayId displayId, sptr sceneSession, bool isFocused); - void NotifyFocusStatus(sptr sceneSession, bool isFocused, sptr focusGroup); - int32_t NotifyRssThawApp(const int32_t uid, const std::string& bundleName, - const std::string& reason); - void NotifyFocusStatusByMission(sptr prevSession, sptr currSession); - void NotifyUnFocusedByMission(sptr sceneSession); - bool MissionChanged(sptr prevSession, sptr currSession); + void UpdateFocusStatus(DisplayId displayId, const sptr& sceneSession, bool isFocused); + void NotifyFocusStatus(const sptr& sceneSession, bool isFocused, + const sptr& focusGroup); + int32_t NotifyRssThawApp(const int32_t uid, const std::string& bundleName, const std::string& reason); + void NotifyFocusStatusByMission(const sptr& prevSession, const sptr& currSession); + void NotifyUnFocusedByMission(const sptr& sceneSession); + bool MissionChanged(const sptr& prevSession, const sptr& currSession); std::string GetAllSessionFocusInfo(); - void RegisterRequestFocusStatusNotifyManagerFunc(sptr sceneSession); + void RegisterRequestFocusStatusNotifyManagerFunc(const sptr& sceneSession); void ProcessUpdateLastFocusedAppId(const std::vector& zOrderList); void RegisterGetStateFromManagerFunc(sptr& sceneSession); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index a0cff5e265..12650bdac7 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5545,7 +5545,7 @@ WSError SceneSessionManager::RequestAllAppSessionUnfocusInner() return ShiftFocus(DEFAULT_DISPLAY_ID, nextSession, FocusChangeReason::WIND); } -WSError SceneSessionManager::RequestFocusBasicCheck(int32_t persistentId, sptr focusGroup) +WSError SceneSessionManager::RequestFocusBasicCheck(int32_t persistentId, const sptr& focusGroup) { // basic focus rule if (persistentId == INVALID_SESSION_ID) { @@ -5567,8 +5567,8 @@ WSError SceneSessionManager::RequestFocusBasicCheck(int32_t persistentId, sptr focusedSession, sptr nextSession) +bool SceneSessionManager::CheckLastFocusedAppSessionFocus(const sptr& focusedSession, + const sptr& nextSession) { if (focusedSession == nullptr || nextSession == nullptr) { return false; @@ -5610,8 +5610,8 @@ bool SceneSessionManager::CheckLastFocusedAppSessionFocus( * * @return true: traversed downwards, false: not. */ -bool SceneSessionManager::CheckFocusIsDownThroughBlockingType(sptr requestSceneSession, - sptr focusedSession, bool includingAppSession) +bool SceneSessionManager::CheckFocusIsDownThroughBlockingType(const sptr& requestSceneSession, + const sptr& focusedSession, bool includingAppSession) { uint32_t requestSessionZOrder = requestSceneSession->GetZOrder(); uint32_t focusedSessionZOrder = focusedSession->GetZOrder(); @@ -5637,7 +5637,8 @@ bool SceneSessionManager::CheckFocusIsDownThroughBlockingType(sptr return false; } -bool SceneSessionManager::CheckTopmostWindowFocus(sptr focusedSession, sptr sceneSession) +bool SceneSessionManager::CheckTopmostWindowFocus(const sptr& focusedSession, + const sptr& sceneSession) { bool isFocusedMainSessionTopmost = focusedSession->GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW && focusedSession->IsTopmost(); @@ -5651,7 +5652,7 @@ bool SceneSessionManager::CheckTopmostWindowFocus(sptr focusedSess return false; } -bool SceneSessionManager::CheckRequestFocusImmdediately(sptr sceneSession) +bool SceneSessionManager::CheckRequestFocusImmdediately(const sptr& sceneSession) { if ((sceneSession->GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW || (SessionHelper::IsSubWindow(sceneSession->GetWindowType()) && !sceneSession->IsModal())) && @@ -5663,8 +5664,8 @@ bool SceneSessionManager::CheckRequestFocusImmdediately(sptr scene return false; } -bool SceneSessionManager::CheckClickFocusIsDownThroughFullScreen(sptr focusedSession, - sptr sceneSession, FocusChangeReason reason) +bool SceneSessionManager::CheckClickFocusIsDownThroughFullScreen(const sptr& focusedSession, + const sptr& sceneSession, FocusChangeReason reason) { if (focusedSession->GetWindowType() != WindowType::WINDOW_TYPE_GLOBAL_SEARCH && focusedSession->GetWindowType() != WindowType::WINDOW_TYPE_NEGATIVE_SCREEN) { @@ -5676,7 +5677,7 @@ bool SceneSessionManager::CheckClickFocusIsDownThroughFullScreen(sptrGetZOrder() < focusedSession->GetZOrder(); } -WSError SceneSessionManager::RequestFocusSpecificCheck(DisplayId displayId, sptr sceneSession, +WSError SceneSessionManager::RequestFocusSpecificCheck(DisplayId displayId, const sptr& sceneSession, bool byForeground,FocusChangeReason reason) { TLOGD(WmsLogTag::WMS_FOCUS, "FocusChangeReason: %{public}d", reason); @@ -5734,7 +5735,7 @@ WSError SceneSessionManager::RequestFocusSpecificCheck(DisplayId displayId, sptr return WSError::WS_OK; } -bool SceneSessionManager::IsParentSessionVisible(sptr session) +bool SceneSessionManager::IsParentSessionVisible(const sptr& session) { if (WindowHelper::IsSubWindow(session->GetWindowType()) || session->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG) { @@ -5898,7 +5899,8 @@ void SceneSessionManager::SetAbilityManagerCollaboratorRegisteredFunc( taskScheduler_->PostAsyncTask(task, __func__); } -WSError SceneSessionManager::ShiftFocus(DisplayId displayId, sptr nextSession, FocusChangeReason reason) +WSError SceneSessionManager::ShiftFocus(DisplayId displayId, const sptr& nextSession, + FocusChangeReason reason) { // unfocus auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); @@ -5934,7 +5936,8 @@ WSError SceneSessionManager::ShiftFocus(DisplayId displayId, sptr return WSError::WS_OK; } -void SceneSessionManager::UpdateFocusStatus(DisplayId displayId, sptr sceneSession, bool isFocused) +void SceneSessionManager::UpdateFocusStatus(DisplayId displayId, const sptr& sceneSession, + bool isFocused) { auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { @@ -5969,8 +5972,8 @@ void SceneSessionManager::UpdateFocusStatus(DisplayId displayId, sptr sceneSession, bool isFocused, - sptr focusGroup) +void SceneSessionManager::NotifyFocusStatus(const sptr& sceneSession, bool isFocused, + const sptr& focusGroup) { auto lastFocusedSessionId = focusGroup->GetLastFocusedSessionId(); if (sceneSession == nullptr) { @@ -6027,7 +6030,8 @@ int32_t SceneSessionManager::NotifyRssThawApp(const int32_t uid, const std::stri return ResourceSchedule::ResSchedClient::GetInstance().ReportSyncEvent(resType, 0, payload, reply); } -void SceneSessionManager::NotifyFocusStatusByMission(sptr prevSession, sptr currSession) +void SceneSessionManager::NotifyFocusStatusByMission(const sptr& prevSession, + const sptr& currSession) { if (prevSession && !prevSession->GetSessionInfo().isSystem_) { TLOGD(WmsLogTag::WMS_FOCUS, "Unfocused, id: %{public}d", prevSession->GetMissionId()); @@ -6039,7 +6043,7 @@ void SceneSessionManager::NotifyFocusStatusByMission(sptr prevSess } } -void SceneSessionManager::NotifyUnFocusedByMission(sptr sceneSession) +void SceneSessionManager::NotifyUnFocusedByMission(const sptr& sceneSession) { if (sceneSession && !sceneSession->GetSessionInfo().isSystem_) { TLOGD(WmsLogTag::WMS_FOCUS, "id: %{public}d", sceneSession->GetMissionId()); @@ -6047,7 +6051,7 @@ void SceneSessionManager::NotifyUnFocusedByMission(sptr sceneSessi } } -bool SceneSessionManager::MissionChanged(sptr prevSession, sptr currSession) +bool SceneSessionManager::MissionChanged(const sptr& prevSession, const sptr& currSession) { if (prevSession == nullptr && currSession == nullptr) { return false; @@ -6451,7 +6455,7 @@ void SceneSessionManager::RegisterSessionInfoChangeNotifyManagerFunc(sptr sceneSession) +void SceneSessionManager::RegisterRequestFocusStatusNotifyManagerFunc(const sptr& sceneSession) { if (sceneSession == nullptr) { WLOGFE("session is nullptr"); -- Gitee From 7fe6ca7b3abe5bc80ea2e789cf307c7810b3a97f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Tue, 21 Jan 2025 09:54:11 +0800 Subject: [PATCH 32/45] fix: FocusGroup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/window_focus_controller.h | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index 3adc014779..24e1d5b332 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -30,32 +30,32 @@ namespace OHOS { namespace Rosen { class FocusGroup : public RefBase { public: - explicit FocusGroup(DisplayId displayGroupId) : displayGroupId(displayGroupId) {} + explicit FocusGroup(DisplayId displayGroupId) : displayGroupId_(displayGroupId) {} - int32_t GetFocusedSessionId() const { return focusedSessionId; } - int32_t GetLastFocusedSessionId() const { return lastFocusedSessionId; } - int32_t GetLastFocusedAppSessionId() const { return lastFocusedAppSessionId; } - bool GetNeedBlockNotifyFocusStatusUntilForeground() const { return needBlockNotifyFocusStatusUntilForeground; } - bool GetNeedBlockNotifyUnfocusStatus() const { return needBlockNotifyUnfocusStatus; } - DisplayId GetDisplayGroupId() const { return displayGroupId; } - void SetFocusedSessionId(int32_t persistentId) { focusedSessionId = persistentId; } - void SetLastFocusedSessionId(int32_t persistentId) { lastFocusedSessionId = persistentId; } - void SetLastFocusedAppSessionId(int32_t persistentId) { lastFocusedAppSessionId = persistentId; } + int32_t GetFocusedSessionId() const { return focusedSessionId_; } + int32_t GetLastFocusedSessionId() const { return lastFocusedSessionId_; } + int32_t GetLastFocusedAppSessionId() const { return lastFocusedAppSessionId_; } + bool GetNeedBlockNotifyFocusStatusUntilForeground() const { return needBlockNotifyFocusStatusUntilForeground_; } + bool GetNeedBlockNotifyUnfocusStatus() const { return needBlockNotifyUnfocusStatus_; } + DisplayId GetDisplayGroupId() const { return displayGroupId_; } + void SetFocusedSessionId(int32_t persistentId) { focusedSessionId_ = persistentId; } + void SetLastFocusedSessionId(int32_t persistentId) { lastFocusedSessionId_ = persistentId; } + void SetLastFocusedAppSessionId(int32_t persistentId) { lastFocusedAppSessionId_ = persistentId; } void SetNeedBlockNotifyFocusStatusUntilForeground(bool needBlock) { - needBlockNotifyFocusStatusUntilForeground = needBlock; + needBlockNotifyFocusStatusUntilForeground_ = needBlock; } - void SetNeedBlockNotifyUnfocusStatus(bool needBlock) { needBlockNotifyUnfocusStatus = needBlock; } + void SetNeedBlockNotifyUnfocusStatus(bool needBlock) { needBlockNotifyUnfocusStatus_ = needBlock; } WSError UpdateFocusedSessionId(int32_t persistentId); WSError UpdateFocusedAppSessionId(int32_t persistentId); private: - int32_t focusedSessionId = INVALID_SESSION_ID; - int32_t lastFocusedSessionId = INVALID_SESSION_ID; - int32_t lastFocusedAppSessionId = INVALID_SESSION_ID; - bool needBlockNotifyFocusStatusUntilForeground { false }; - bool needBlockNotifyUnfocusStatus { false }; - DisplayId displayGroupId = DISPLAY_ID_INVALID; + int32_t focusedSessionId_ = INVALID_SESSION_ID; + int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; + int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID; + bool needBlockNotifyFocusStatusUntilForeground_ { false }; + bool needBlockNotifyUnfocusStatus_ { false }; + DisplayId displayGroupId_ = DISPLAY_ID_INVALID; }; class WindowFocusController : public RefBase { @@ -73,10 +73,10 @@ public: WSError UpdateFocusedAppSessionId(DisplayId displayId, int32_t persistentId); private: + sptr GetFocusGroupInner(DisplayId displayId); + std::unordered_map> focusGroupMap_; std::unordered_set virtualScreenDisplayIdSet_; - - sptr GetFocusGroupInner(DisplayId displayId); }; } } -- Gitee From 352051c6ca5ed80925d2a458725557c18d78aa0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Tue, 21 Jan 2025 10:09:32 +0800 Subject: [PATCH 33/45] fix: scene_session_manager include order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/scene_session_manager.h | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index fd612d0ce2..380bc94588 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -27,32 +27,31 @@ #ifndef SUPPORT_SCREEN #define SUPPORT_SCREEN #endif -#include "mission_snapshot.h" -#include "transaction/rs_interfaces.h" - +#include "ability_info.h" #include "agent_death_recipient.h" +#include "app_debug_listener_interface.h" +#include "app_mgr_client.h" #include "common/include/task_scheduler.h" -#include "future.h" -#include "interfaces/include/ws_common.h" -#include "session_listener_controller.h" -#include "scene_session_converter.h" -#include "scb_session_handler.h" -#include "session/host/include/root_scene_session.h" -#include "session/host/include/keyboard_session.h" -#include "session_manager/include/zidl/scene_session_manager_stub.h" -#include "wm_single_instance.h" -#include "window_scene_config.h" -#include "display_info.h" #include "display_change_info.h" #include "display_change_listener.h" -#include "app_debug_listener_interface.h" -#include "app_mgr_client.h" +#include "display_info.h" +#include "future.h" #include "include/core/SkRegion.h" -#include "ability_info.h" +#include "interfaces/include/ws_common.h" +#include "mission_snapshot.h" +#include "scb_session_handler.h" +#include "scene_session_converter.h" #include "screen_fold_data.h" #include "screen_session_manager_client.h" +#include "session/host/include/keyboard_session.h" +#include "session/host/include/root_scene_session.h" +#include "session_listener_controller.h" +#include "session_manager/include/zidl/scene_session_manager_stub.h" #include "thread_safety_annotations.h" +#include "transaction/rs_interfaces.h" #include "window_focus_controller.h" +#include "window_scene_config.h" +#include "wm_single_instance.h" namespace OHOS::AAFwk { class SessionInfo; -- Gitee From c93f5fde53f9435a0ac3ea6808994d5bdf50d9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Tue, 21 Jan 2025 15:55:52 +0800 Subject: [PATCH 34/45] fix: const sptr& MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../session_manager/include/scene_session_manager.h | 4 ++-- .../session_manager/src/scene_session_manager.cpp | 6 +++--- .../session_manager/src/window_focus_controller.cpp | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 380bc94588..83dad5e210 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -732,6 +732,8 @@ private: std::string GetAllSessionFocusInfo(); void RegisterRequestFocusStatusNotifyManagerFunc(const sptr& sceneSession); void ProcessUpdateLastFocusedAppId(const std::vector& zOrderList); + WSError ProcessDialogRequestFocusImmdediately(const sptr& sceneSession); + WSError ProcessModalTopmostRequestFocusImmdediately(const sptr& sceneSession); void RegisterGetStateFromManagerFunc(sptr& sceneSession); void RegisterSessionChangeByActionNotifyManagerFunc(sptr& sceneSession); @@ -1013,8 +1015,6 @@ private: void ProcessFocusWhenForegroundScbCore(sptr& sceneSession); void ProcessSubSessionForeground(sptr& sceneSession); void ProcessSubSessionBackground(sptr& sceneSession); - WSError ProcessDialogRequestFocusImmdediately(sptr& sceneSession); - WSError ProcessModalTopmostRequestFocusImmdediately(sptr& sceneSession); sptr FindSessionByToken(const sptr& token); void CheckAndNotifyWaterMarkChangedResult(); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 12650bdac7..28b6853678 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5211,7 +5211,7 @@ bool SceneSessionManager::GetStatusBarDefaultVisibilityByDisplayId(DisplayId dis statusBarDefaultVisibilityPerDisplay_[displayId] : true; } -void FocusIDChange(int32_t persistentId, sptr& sceneSession) +void FocusIDChange(int32_t persistentId, const sptr& sceneSession) { // notify RS WLOGFD("current focus session: windowId: %{public}d, windowName: %{public}s, bundleName: %{public}s, " @@ -6800,7 +6800,7 @@ void SceneSessionManager::ProcessSubSessionForeground(sptr& sceneS } } -WSError SceneSessionManager::ProcessModalTopmostRequestFocusImmdediately(sptr& sceneSession) +WSError SceneSessionManager::ProcessModalTopmostRequestFocusImmdediately(const sptr& sceneSession) { // focus must on modal topmost subwindow when APP_MAIN_WINDOW or sub winodw request focus sptr mainSession = nullptr; @@ -6841,7 +6841,7 @@ WSError SceneSessionManager::ProcessModalTopmostRequestFocusImmdediately(sptr& sceneSession) +WSError SceneSessionManager::ProcessDialogRequestFocusImmdediately(const sptr& sceneSession) { // focus must on dialog when APP_MAIN_WINDOW or sub winodw request focus sptr mainSession = nullptr; diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index c9a2a07e69..d8db496141 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -20,19 +20,19 @@ namespace Rosen { WSError FocusGroup::UpdateFocusedSessionId(int32_t persistentId) { - TLOGD(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId, persistentId); - if (focusedSessionId == persistentId) { - TLOGD(WmsLogTag::WMS_FOCUS, "Focus scene not change, id: %{public}d", focusedSessionId); + TLOGD(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId_, persistentId); + if (focusedSessionId_ == persistentId) { + TLOGD(WmsLogTag::WMS_FOCUS, "Focus scene not change, id: %{public}d", focusedSessionId_); return WSError::WS_DO_NOTHING; } - lastFocusedSessionId = focusedSessionId; - focusedSessionId = persistentId; + lastFocusedSessionId_ = focusedSessionId_; + focusedSessionId_ = persistentId; return WSError::WS_OK; } WSError FocusGroup::UpdateFocusedAppSessionId(int32_t persistentId) { - lastFocusedAppSessionId = persistentId; + lastFocusedAppSessionId_ = persistentId; return WSError::WS_OK; } -- Gitee From 81f2b00406c9734aaa6e6eb66dd919c56163a133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Tue, 21 Jan 2025 18:04:22 +0800 Subject: [PATCH 35/45] fix: scene_session_manager format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../session_manager/include/scene_session_manager.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 83dad5e210..14c6f8c34f 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -695,10 +695,6 @@ private: /* * Window Focus */ - sptr windowFocusController_; - FocusChangeReason focusChangeReason_ = FocusChangeReason::DEFAULT; - bool needBlockNotifyFocusStatusUntilForeground_ {false}; - bool needBlockNotifyUnfocusStatus_ {false}; WSError RequestSessionFocus(int32_t persistentId, bool byForeground = true, FocusChangeReason reason = FocusChangeReason::DEFAULT); WSError RequestSessionFocusImmediately(int32_t persistentId); @@ -965,6 +961,14 @@ private: bool isScreenLocked_ {false}; bool isPrepareTerminateEnable_ {false}; + /* + * Window Focus + */ + sptr windowFocusController_; + FocusChangeReason focusChangeReason_ = FocusChangeReason::DEFAULT; + bool needBlockNotifyFocusStatusUntilForeground_ {false}; + bool needBlockNotifyUnfocusStatus_ {false}; + /* * DFX */ -- Gitee From 5912e4f276e06e10b8aca978e012d15c4131c1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Tue, 21 Jan 2025 18:07:46 +0800 Subject: [PATCH 36/45] fix: scene_session_manager format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/session_manager/include/scene_session_manager.h | 1 + 1 file changed, 1 insertion(+) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 14c6f8c34f..1a3a8f474d 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -27,6 +27,7 @@ #ifndef SUPPORT_SCREEN #define SUPPORT_SCREEN #endif + #include "ability_info.h" #include "agent_death_recipient.h" #include "app_debug_listener_interface.h" -- Gitee From 24b4391c64291b33e089a6720af8f9449053082d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Wed, 22 Jan 2025 11:09:56 +0800 Subject: [PATCH 37/45] fix: GetAllFocusedSessionList add const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/session_manager/include/window_focus_controller.h | 2 +- window_scene/session_manager/src/window_focus_controller.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/window_scene/session_manager/include/window_focus_controller.h b/window_scene/session_manager/include/window_focus_controller.h index 24e1d5b332..e06efc7d1b 100644 --- a/window_scene/session_manager/include/window_focus_controller.h +++ b/window_scene/session_manager/include/window_focus_controller.h @@ -68,7 +68,7 @@ public: WSError RemoveFocusGroup(DisplayId displayId); int32_t GetFocusedSessionId(DisplayId displayId); sptr GetFocusGroup(DisplayId displayId = DEFAULT_DISPLAY_ID); - std::vector> GetAllFocusedSessionList(); + std::vector> GetAllFocusedSessionList() const; WSError UpdateFocusedSessionId(DisplayId displayId, int32_t persistentId); WSError UpdateFocusedAppSessionId(DisplayId displayId, int32_t persistentId); diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index d8db496141..4634418c67 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -125,7 +125,7 @@ sptr WindowFocusController::GetFocusGroup(DisplayId displayId) return focusGroup; } -std::vector> WindowFocusController::GetAllFocusedSessionList() +std::vector> WindowFocusController::GetAllFocusedSessionList() const { std::vector> allFocusGroup; for (const auto& elem : focusGroupMap_) { -- Gitee From b1c5670336a5afb39ac08e27a587587c57e5215c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Wed, 22 Jan 2025 17:24:28 +0800 Subject: [PATCH 38/45] fix: format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/scene_session_manager.h | 10 +++++----- .../session_manager/src/scene_session_manager.cpp | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 1a3a8f474d..a374fac77e 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -959,21 +959,21 @@ private: float snapshotScale_ = 0.5; int32_t brightnessSessionId_ = INVALID_SESSION_ID; float displayBrightness_ = UNDEFINED_BRIGHTNESS; - bool isScreenLocked_ {false}; - bool isPrepareTerminateEnable_ {false}; + bool isScreenLocked_ { false }; + bool isPrepareTerminateEnable_ { false }; /* * Window Focus */ sptr windowFocusController_; FocusChangeReason focusChangeReason_ = FocusChangeReason::DEFAULT; - bool needBlockNotifyFocusStatusUntilForeground_ {false}; - bool needBlockNotifyUnfocusStatus_ {false}; + bool needBlockNotifyFocusStatusUntilForeground_ { false }; + bool needBlockNotifyUnfocusStatus_ { false }; /* * DFX */ - bool openDebugTrace_ {false}; + bool openDebugTrace_ { false }; std::atomic enableInputEvent_ = true; std::vector alivePersistentIds_ = {}; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 28b6853678..edbf9f333b 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -4623,6 +4623,10 @@ void SceneSessionManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo, Display } taskScheduler_->PostSyncTask([this, &focusInfo, displayId] { auto focusGroup = windowFocusController_->GetFocusGroup(displayId); + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); + return WSError::WS_ERROR_DESTROYED_OBJECT; + } if (auto sceneSession = GetSceneSession(focusGroup->GetFocusedSessionId())) { TLOGND(WmsLogTag::WMS_FOCUS, "Get focus session info success"); focusInfo.windowId_ = sceneSession->GetWindowId(); @@ -4947,7 +4951,8 @@ void SceneSessionManager::DumpSessionInfo(const sptr& session, std void SceneSessionManager::DumpFocusInfo(std::ostringstream& oss) { oss << "Focus window: " << std::endl; - std::vector> allFocusedStateList = windowFocusController_->GetAllFocusedSessionList(); + std::vector>& allFocusedStateList = + windowFocusController_->GetAllFocusedSessionList(); if (allFocusedStateList.size() > 0) { for (const auto& focusState : allFocusedStateList) { oss << "DisplayId: " << focusState.first << " Focus window: " << focusState.second << std::endl; @@ -5678,7 +5683,7 @@ bool SceneSessionManager::CheckClickFocusIsDownThroughFullScreen(const sptr& sceneSession, - bool byForeground,FocusChangeReason reason) + bool byForeground, FocusChangeReason reason) { TLOGD(WmsLogTag::WMS_FOCUS, "FocusChangeReason: %{public}d", reason); int32_t persistentId = sceneSession->GetPersistentId(); @@ -5932,7 +5937,7 @@ WSError SceneSessionManager::ShiftFocus(DisplayId displayId, const sptr& sceneSession, bool isFocused, const sptr& focusGroup) { + if (focusGroup == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); + return; + } auto lastFocusedSessionId = focusGroup->GetLastFocusedSessionId(); if (sceneSession == nullptr) { WLOGFE("[WMSComm]session is nullptr"); -- Gitee From 938e5ce6ab7e0d6d37d9e1cbffd93416ebb0f002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Wed, 22 Jan 2025 17:40:35 +0800 Subject: [PATCH 39/45] fix: wm_common format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- interfaces/innerkits/wm/wm_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index a1ffe2077c..4a3caeebec 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -1255,7 +1255,7 @@ struct WindowLayoutInfo : public Parcelable { return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) && parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_); } - + static WindowLayoutInfo* Unmarshalling(Parcel& parcel) { WindowLayoutInfo* windowLayoutInfo = new WindowLayoutInfo; -- Gitee From 7345e487320b22dbe4c8cf2b6035c91dbb076227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Wed, 22 Jan 2025 18:18:45 +0800 Subject: [PATCH 40/45] fix: get all focus session list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../scene_session_manager/js_scene_session_manager.cpp | 10 +++++----- .../session_manager/src/scene_session_manager.cpp | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 9d210a91df..f8837814a4 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -1435,7 +1435,7 @@ static napi_value CreateWindowModes(napi_env env, } return arrayValue; } - + static napi_value CreateWindowSize(napi_env env, const AppExecFwk::AbilityInfo& abilityInfo) { napi_value objValue = nullptr; @@ -1452,7 +1452,7 @@ static napi_value CreateWindowSize(napi_env env, const AppExecFwk::AbilityInfo& napi_set_named_property(env, objValue, "minWindowHeight", CreateJsValue(env, abilityInfo.minWindowHeight)); return objValue; } - + static napi_value CreateAbilityItemInfo(napi_env env, const AppExecFwk::AbilityInfo& abilityInfo) { napi_value objValue = nullptr; @@ -1481,7 +1481,7 @@ static napi_value CreateAbilityItemInfo(napi_env env, const AppExecFwk::AbilityI CreateJsValue(env, abilityInfo.preferMultiWindowOrientation)); return objValue; } - + static napi_value CreateSCBAbilityInfo(napi_env env, const SCBAbilityInfo& scbAbilityInfo) { napi_value objValue = nullptr; @@ -1495,7 +1495,7 @@ static napi_value CreateSCBAbilityInfo(napi_env env, const SCBAbilityInfo& scbAb napi_set_named_property(env, objValue, "codePath", CreateJsValue(env, scbAbilityInfo.codePath_)); return objValue; } - + static napi_value CreateAbilityInfos(napi_env env, const std::vector& scbAbilityInfos) { napi_value arrayValue = nullptr; @@ -3629,7 +3629,7 @@ napi_value JsSceneSessionManager::OnNotifyAboveLockScreen(napi_env env, napi_cal "Input parameter is missing or invalid")); return NapiGetUndefined(env); } - + std::vector windowIds; if (!ConvertInt32ArrayFromJs(env, argv[0], windowIds)) { TLOGE(WmsLogTag::WMS_UIEXT, "Failed to convert windowIds"); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index d608e1c78f..6e20ad6cba 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5011,10 +5011,10 @@ void SceneSessionManager::DumpSessionInfo(const sptr& session, std void SceneSessionManager::DumpFocusInfo(std::ostringstream& oss) { oss << "Focus window: " << std::endl; - std::vector>& allFocusedStateList = + std::vector> allFocusedSessionList = windowFocusController_->GetAllFocusedSessionList(); - if (allFocusedStateList.size() > 0) { - for (const auto& focusState : allFocusedStateList) { + if (allFocusedSessionList.size() > 0) { + for (const auto& focusState : allFocusedSessionList) { oss << "DisplayId: " << focusState.first << " Focus window: " << focusState.second << std::endl; } } -- Gitee From 4f59d29103bb580d37db1b62db429bbaa2b373ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Thu, 23 Jan 2025 09:45:46 +0800 Subject: [PATCH 41/45] fix: scene_session_manager format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../include/scene_session_manager.h | 2 +- .../src/scene_session_manager.cpp | 34 ++++++++----------- .../src/window_focus_controller.cpp | 2 +- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 16f007fc2c..5051175b42 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -265,7 +265,7 @@ public: /* * Window Focus */ - WSError SetFocusedSessionId(int32_t persistentId, DisplayId displayId); + WSError SetFocusedSessionId(const int32_t persistentId, const DisplayId displayId); int32_t GetFocusedSessionId(DisplayId displayId = DEFAULT_DISPLAY_ID) const; FocusChangeReason GetFocusChangeReason() const { return focusChangeReason_; } WMError RequestFocusStatus(int32_t persistentId, bool isFocused, bool byForeground = true, diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 6e20ad6cba..326e23354b 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -4659,15 +4659,9 @@ WMError SceneSessionManager::SetGestureNavigationEnabled(bool enable) return taskScheduler_->PostSyncTask(task, "SetGestureNavigationEnabled"); } -WSError SceneSessionManager::SetFocusedSessionId(int32_t persistentId, DisplayId displayId) +WSError SceneSessionManager::SetFocusedSessionId(const int32_t persistentId, const DisplayId displayId) { - auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); - if (focusedSessionId == persistentId) { - WLOGI("Focus scene not change, id: %{public}d", focusedSessionId); - return WSError::WS_DO_NOTHING; - } - windowFocusController_->UpdateFocusedSessionId(displayId, persistentId); - return WSError::WS_OK; + return windowFocusController_->UpdateFocusedSessionId(displayId, persistentId); } int32_t SceneSessionManager::GetFocusedSessionId(DisplayId displayId) const @@ -4685,12 +4679,12 @@ void SceneSessionManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo, Display auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); - return WSError::WS_ERROR_DESTROYED_OBJECT; + return WSError::WS_ERROR_NULLPTR; } if (auto sceneSession = GetSceneSession(focusGroup->GetFocusedSessionId())) { TLOGND(WmsLogTag::WMS_FOCUS, "Get focus session info success"); focusInfo.windowId_ = sceneSession->GetWindowId(); - focusInfo.displayId_ = static_cast(focusGroup->GetDisplayGroupId()); + focusInfo.displayId_ = focusGroup->GetDisplayGroupId(); focusInfo.pid_ = sceneSession->GetCallingPid(); focusInfo.uid_ = sceneSession->GetCallingUid(); focusInfo.windowType_ = sceneSession->GetWindowType(); @@ -6891,10 +6885,11 @@ WSError SceneSessionManager::ProcessModalTopmostRequestFocusImmdediately(const s } auto displayId = mainSession->GetSessionProperty()->GetDisplayId(); auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); - if (std::find_if(topmostVec.begin(), topmostVec.end(), - [this, focusedSessionId](sptr& iter) { return iter && - iter->GetPersistentId() == focusedSessionId; }) != topmostVec.end()) { - TLOGND(WmsLogTag::WMS_SUB, "modal topmost subwindow id: %{public}d has been focused!", focusedSessionId); + auto conditionFunc = [this, focusedSessionId](const sptr& iter) { + return iter && iter->GetPersistentId() == focusedSessionId; + }; + if (std::find_if(topmostVec.begin(), topmostVec.end(), conditionFunc) != topmostVec.end()) { + TLOGD(WmsLogTag::WMS_SUB, "modal topmost subwindow id: %{public}d has been focused!", focusedSessionId); return WSError::WS_OK; } WSError ret = WSError::WS_DO_NOTHING; @@ -6926,10 +6921,11 @@ WSError SceneSessionManager::ProcessDialogRequestFocusImmdediately(const sptr> dialogVec = mainSession->GetDialogVector(); auto displayId = mainSession->GetSessionProperty()->GetDisplayId(); auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); - if (std::find_if(dialogVec.begin(), dialogVec.end(), - [this, focusedSessionId](sptr& iter) { return iter && - iter->GetPersistentId() == focusedSessionId; }) != dialogVec.end()) { - TLOGND(WmsLogTag::WMS_DIALOG, "dialog id: %{public}d has been focused!", focusedSessionId); + auto conditionFunc = [this, focusedSessionId](const sptr& iter) { + return iter && iter->GetPersistentId() == focusedSessionId; + }; + if (std::find_if(dialogVec.begin(), dialogVec.end(), conditionFunc) != dialogVec.end()) { + TLOGD(WmsLogTag::WMS_DIALOG, "dialog id: %{public}d has been focused!", focusedSessionId); return WSError::WS_OK; } WSError ret = WSError::WS_DO_NOTHING; @@ -9594,7 +9590,7 @@ void DisplayChangeListener::OnDisplayStateChange(DisplayId defaultDisplayId, spt bool CheckIfNeedMultipleFocus(const std::string& name, const ScreenType& screenType) { - if (screenType == ScreenType::VIRTUAL && (name == "HiCar" || name == "SuperLauncher" || name == "CastEngine")) { + if (screenType == ScreenType::VIRTUAL && (name == "HiCar" || name == "SuperLauncher" || name == "CeliaView")) { return true; } return false; diff --git a/window_scene/session_manager/src/window_focus_controller.cpp b/window_scene/session_manager/src/window_focus_controller.cpp index 7b4a0d0427..4c4c4217c4 100644 --- a/window_scene/session_manager/src/window_focus_controller.cpp +++ b/window_scene/session_manager/src/window_focus_controller.cpp @@ -22,7 +22,7 @@ WSError FocusGroup::UpdateFocusedSessionId(int32_t persistentId) { TLOGD(WmsLogTag::WMS_FOCUS, "focusedId change: %{public}d -> %{public}d", focusedSessionId_, persistentId); if (focusedSessionId_ == persistentId) { - TLOGD(WmsLogTag::WMS_FOCUS, "Focus scene not change, id: %{public}d", focusedSessionId_); + TLOGD(WmsLogTag::WMS_FOCUS, "focus scene not change, id: %{public}d", focusedSessionId_); return WSError::WS_DO_NOTHING; } lastFocusedSessionId_ = focusedSessionId_; -- Gitee From 8b0107725ce27b8e7650915aa5a0d867574c7dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Thu, 23 Jan 2025 16:15:38 +0800 Subject: [PATCH 42/45] fix: nullptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- .../session_manager/src/scene_session_manager.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 326e23354b..db6eeacd9f 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -3864,7 +3864,7 @@ WSError SceneSessionManager::ProcessBackEvent() auto focusGroup = windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); if (focusGroup == nullptr) { TLOGNE(WmsLogTag::WMS_MAIN, "focus group is nullptr: %{public}" PRIu64, DEFAULT_DISPLAY_ID); - return WSError::WS_ERROR_INVALID_SESSION; + return WSError::WS_ERROR_NULLPTR; } auto focusedSessionId = focusGroup->GetFocusedSessionId(); auto needBlockNotifyFocusStatusUntilForeground = focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground(); @@ -4679,7 +4679,7 @@ void SceneSessionManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo, Display auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); - return WSError::WS_ERROR_NULLPTR; + return WSError::WS_ERROR_DESTROYED_OBJECT; } if (auto sceneSession = GetSceneSession(focusGroup->GetFocusedSessionId())) { TLOGND(WmsLogTag::WMS_FOCUS, "Get focus session info success"); @@ -5538,7 +5538,7 @@ WSError SceneSessionManager::RequestSessionUnfocus(int32_t persistentId, FocusCh { TLOGD(WmsLogTag::WMS_FOCUS, "id: %{public}d", persistentId); if (persistentId == INVALID_SESSION_ID) { - TLOGE(WmsLogTag::WMS_FOCUS, "id is invalid"); + TLOGE(WmsLogTag::WMS_FOCUS, "id is invalid: %{public}d", persistentId); return WSError::WS_ERROR_INVALID_SESSION; } auto sceneSession = GetSceneSession(persistentId); @@ -5586,7 +5586,7 @@ WSError SceneSessionManager::RequestAllAppSessionUnfocusInner() auto focusGroup = windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, DEFAULT_DISPLAY_ID); - return WSError::WS_ERROR_INVALID_SESSION; + return WSError::WS_ERROR_NULLPTR; } auto focusedSession = GetSceneSession(focusGroup->GetFocusedSessionId()); if (!focusedSession) { @@ -5613,7 +5613,7 @@ WSError SceneSessionManager::RequestFocusBasicCheck(int32_t persistentId, const } if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr"); - return WSError::WS_ERROR_INVALID_SESSION; + return WSError::WS_ERROR_NULLPTR; } if (persistentId == focusGroup->GetFocusedSessionId()) { TLOGD(WmsLogTag::WMS_FOCUS, "request id has been focused!"); @@ -6888,7 +6888,7 @@ WSError SceneSessionManager::ProcessModalTopmostRequestFocusImmdediately(const s auto conditionFunc = [this, focusedSessionId](const sptr& iter) { return iter && iter->GetPersistentId() == focusedSessionId; }; - if (std::find_if(topmostVec.begin(), topmostVec.end(), conditionFunc) != topmostVec.end()) { + if (std::find_if(topmostVec.begin(), topmostVec.end(), std::move(conditionFunc)) != topmostVec.end()) { TLOGD(WmsLogTag::WMS_SUB, "modal topmost subwindow id: %{public}d has been focused!", focusedSessionId); return WSError::WS_OK; } @@ -6924,7 +6924,7 @@ WSError SceneSessionManager::ProcessDialogRequestFocusImmdediately(const sptr& iter) { return iter && iter->GetPersistentId() == focusedSessionId; }; - if (std::find_if(dialogVec.begin(), dialogVec.end(), conditionFunc) != dialogVec.end()) { + if (std::find_if(dialogVec.begin(), dialogVec.end(), std::move(conditionFunc)) != dialogVec.end()) { TLOGD(WmsLogTag::WMS_DIALOG, "dialog id: %{public}d has been focused!", focusedSessionId); return WSError::WS_OK; } -- Gitee From 841a17f4a034bc6c5a6eef6876d18ec87df3cebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Thu, 23 Jan 2025 16:21:45 +0800 Subject: [PATCH 43/45] fix: nullptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/session_manager/src/scene_session_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index db6eeacd9f..c3e29f59e8 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5494,7 +5494,7 @@ WSError SceneSessionManager::RequestSessionFocus(int32_t persistentId, bool byFo auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); - return WSError::WS_ERROR_INVALID_SESSION; + return WSError::WS_ERROR_NULLPTR; } WSError basicCheckRet = RequestFocusBasicCheck(persistentId, focusGroup); if (basicCheckRet != WSError::WS_OK) { -- Gitee From 8045d084ce90926546016c575118abc6b3c2f8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Thu, 23 Jan 2025 16:22:25 +0800 Subject: [PATCH 44/45] fix: nullptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/session_manager/src/scene_session_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index c3e29f59e8..9062e753db 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5544,7 +5544,7 @@ WSError SceneSessionManager::RequestSessionUnfocus(int32_t persistentId, FocusCh auto sceneSession = GetSceneSession(persistentId); if (sceneSession == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "session is nullptr: %{public}d", persistentId); - return WSError::WS_ERROR_INVALID_SESSION; + return WSError::WS_ERROR_NULLPTR; } auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); auto focusGroup = windowFocusController_->GetFocusGroup(displayId); -- Gitee From 962fc1474c6845ca0b76b247f27f4a31b7e223a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=99=97?= Date: Thu, 23 Jan 2025 16:27:02 +0800 Subject: [PATCH 45/45] fix: nullptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡晗 --- window_scene/session_manager/src/scene_session_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 9062e753db..6300c342b1 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5450,7 +5450,7 @@ WSError SceneSessionManager::RequestSessionFocusImmediately(int32_t persistentId auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); - return WSError::WS_ERROR_INVALID_SESSION; + return WSError::WS_ERROR_NULLPTR; } // base block WSError basicCheckRet = RequestFocusBasicCheck(persistentId, focusGroup); @@ -5544,13 +5544,13 @@ WSError SceneSessionManager::RequestSessionUnfocus(int32_t persistentId, FocusCh auto sceneSession = GetSceneSession(persistentId); if (sceneSession == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "session is nullptr: %{public}d", persistentId); - return WSError::WS_ERROR_NULLPTR; + return WSError::WS_ERROR_INVALID_SESSION; } auto displayId = sceneSession->GetSessionProperty()->GetDisplayId(); auto focusGroup = windowFocusController_->GetFocusGroup(displayId); if (focusGroup == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "focus group is nullptr: %{public}" PRIu64, displayId); - return WSError::WS_ERROR_INVALID_SESSION; + return WSError::WS_ERROR_NULLPTR; } auto focusedSession = GetSceneSession(focusGroup->GetFocusedSessionId()); if (persistentId != focusGroup->GetFocusedSessionId() && -- Gitee