diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index 0be4d6ee5a74ca33cd2b674d1e102d3ab3430d1a..a143ba4b011fbdc025fb003d44918660b5d6963b 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -730,6 +730,14 @@ public: WMError GetUnreliableWindowInfo(int32_t windowId, std::vector>& infos) const; + /** + * @brief Get window layout info. + * + * @param infos window layout infos + * @return WM_OK means get success, others means get failed. + */ + WMError GetAllWindowLayoutInfo(DisplayId displayId, std::vector>& infos) const; + /** * @brief Get visibility window info. * diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 447d6e6a8f2b7275f25c77d0e37460a54de2c015..7d28807b4ddd56e17563a73af6e25f07b4857898 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -1189,6 +1189,34 @@ struct TitleButtonRect { } }; +/* + * @struct WindowLayoutInfo + * + * @brief Layout info for all windows on the screen. + */ +struct WindowLayoutInfo : public Parcelable { + Rect rect = { 0, 0, 0, 0 }; + + bool Marshalling(Parcel& parcel) const override + { + 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; + if (!parcel.ReadInt32(windowLayoutInfo->rect.posX_) || + !parcel.ReadInt32(windowLayoutInfo->rect.posY_) || + !parcel.ReadUint32(windowLayoutInfo->rect.width_) || + !parcel.ReadUint32(windowLayoutInfo->rect.height_)) { + delete windowLayoutInfo; + return nullptr; + } + return windowLayoutInfo; + } +}; + /** * Config of keyboard animation */ diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp index 898074065af9bfd960c839718ddff823bb27fc95..5793e4b8047ff505cb5c25cedbad3f1fe02090f8 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp @@ -153,6 +153,12 @@ napi_value JsWindowManager::ShiftAppWindowFocus(napi_env env, napi_callback_info return (me != nullptr) ? me->OnShiftAppWindowFocus(env, info) : nullptr; } +napi_value JsWindowManager::GetAllWindowLayoutInfo(napi_env env, napi_callback_info info) +{ + JsWindowManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnGetAllWindowLayoutInfo(env, info) : nullptr; +} + napi_value JsWindowManager::GetVisibleWindowInfo(napi_env env, napi_callback_info info) { JsWindowManager* me = CheckParamsAndGetThis(env, info); @@ -1183,6 +1189,46 @@ napi_value JsWindowManager::OnShiftAppWindowFocus(napi_env env, napi_callback_in return result; } +napi_value JsWindowManager::OnGetAllWindowLayoutInfo(napi_env env, napi_callback_info info) +{ + size_t argc = ARGC_FOUR; + napi_value argv[ARGC_FOUR] = { nullptr }; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc != ARGC_ONE) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Argc is invalid: %{public}zu", argc); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + int64_t displayId = static_cast(DISPLAY_ID_INVALID); + if (!ConvertFromJsValue(env, argv[INDEX_ZERO], displayId)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to convert parameter to displayId"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + if (displayId < 0 || + SingletonContainer::Get().GetDisplayById(static_cast(displayId)) == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "invalid displayId"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + napi_value result = nullptr; + std::shared_ptr napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result); + auto asyncTask = [env, task = napiAsyncTask, displayId, where = __func__] { + std::vector> infos; + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at( + SingletonContainer::Get().GetAllWindowLayoutInfo(static_cast(displayId), infos)); + if (ret == WmErrorCode::WM_OK) { + task->Resolve(env, CreateJsWindowLayoutInfoArrayObject(env, infos)); + TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s success", where); + } else { + task->Reject(env, JsErrUtils::CreateJsError(env, ret, "failed")); + TLOGNE(WmsLogTag::WMS_ATTRIBUTE, "%{public}s failed", where); + } + }; + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + napiAsyncTask->Reject(env, + CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + } + return result; +} + napi_value JsWindowManager::OnGetVisibleWindowInfo(napi_env env, napi_callback_info info) { size_t argc = 4; @@ -1306,6 +1352,7 @@ napi_value JsWindowManagerInit(napi_env env, napi_value exportObj) JsWindowManager::SetGestureNavigationEnabled); BindNativeFunction(env, exportObj, "setWaterMarkImage", moduleName, JsWindowManager::SetWaterMarkImage); BindNativeFunction(env, exportObj, "shiftAppWindowFocus", moduleName, JsWindowManager::ShiftAppWindowFocus); + BindNativeFunction(env, exportObj, "getAllWindowLayoutInfo", moduleName, JsWindowManager::GetAllWindowLayoutInfo); BindNativeFunction(env, exportObj, "getVisibleWindowInfo", moduleName, JsWindowManager::GetVisibleWindowInfo); BindNativeFunction(env, exportObj, "getWindowsByCoordinate", moduleName, JsWindowManager::GetWindowsByCoordinate); return NapiGetUndefined(env); diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.h b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.h index 4c364372da9b2339cba1f4c31b759f92465c7bef..8f9187ff8ede9c674f3ae120376375fb30eae9df 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.h +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.h @@ -46,6 +46,7 @@ public: static napi_value SetGestureNavigationEnabled(napi_env env, napi_callback_info info); static napi_value SetWaterMarkImage(napi_env env, napi_callback_info info); static napi_value ShiftAppWindowFocus(napi_env env, napi_callback_info info); + static napi_value GetAllWindowLayoutInfo(napi_env env, napi_callback_info info); static napi_value GetVisibleWindowInfo(napi_env env, napi_callback_info info); static napi_value GetWindowsByCoordinate(napi_env env, napi_callback_info info); @@ -65,6 +66,7 @@ private: static napi_value OnSetGestureNavigationEnabled(napi_env env, napi_callback_info info); static napi_value OnSetWaterMarkImage(napi_env env, napi_callback_info info); static napi_value OnShiftAppWindowFocus(napi_env env, napi_callback_info info); + static napi_value OnGetAllWindowLayoutInfo(napi_env env, napi_callback_info info); static napi_value OnGetVisibleWindowInfo(napi_env env, napi_callback_info info); static napi_value OnGetWindowsByCoordinate(napi_env env, napi_callback_info info); static bool ParseRequiredConfigOption( diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp index 75b87a90e1be61341c4c6171bd69a4f3a0f0acec..cf07c6d7d9461449a8c14a8a13be3bf8ce2ed45f 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp @@ -544,6 +544,20 @@ static napi_value CreateJsSystemBarRegionTintObject(napi_env env, const SystemBa return objValue; } +napi_value CreateJsWindowLayoutInfoArrayObject(napi_env env, const std::vector>& infos) +{ + napi_value arrayValue = nullptr; + napi_create_array_with_length(env, infos.size(), &arrayValue); + if (arrayValue == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "arrayValue is null"); + return nullptr; + } + for (size_t i = 0; i < infos.size(); i++) { + napi_set_element(env, arrayValue, i, CreateJsWindowLayoutInfoObject(env, infos[i])); + } + return arrayValue; +} + napi_value CreateJsWindowInfoArrayObject(napi_env env, const std::vector>& infos) { napi_value arrayValue = nullptr; @@ -603,6 +617,14 @@ bool ConvertDecorButtonStyleFromJs(napi_env env, napi_value jsObject, DecorButto return !emptyParam; } +napi_value CreateJsWindowLayoutInfoObject(napi_env env, const sptr& info) +{ + napi_value objValue = nullptr; + CHECK_NAPI_CREATE_OBJECT_RETURN_IF_NULL(env, objValue); + napi_set_named_property(env, objValue, "rect", GetRectAndConvertToJsValue(env, info->rect)); + return objValue; +} + napi_value CreateJsWindowInfoObject(napi_env env, const sptr& info) { napi_value objValue = nullptr; diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h index 45b889d7297049017ef0d949257cb7b2beddd2e9..acea4aca790fb4d4a0df4cf6765eac47659076a4 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.h @@ -286,6 +286,8 @@ inline const std::map JS_TO_NATIVE_MODALITY_TYPE_ { ApiModalityType::APPLICATION_MODALITY, ModalityType::APPLICATION_MODALITY }, }; + napi_value CreateJsWindowLayoutInfoArrayObject(napi_env env, const std::vector>& infos); + napi_value CreateJsWindowLayoutInfoObject(napi_env env, const sptr& info); napi_value CreateJsWindowInfoArrayObject(napi_env env, const std::vector>& infos); napi_value CreateJsWindowInfoObject(napi_env env, const sptr& window); napi_value GetRectAndConvertToJsValue(napi_env env, const Rect& rect); diff --git a/previewer/include/wm_common.h b/previewer/include/wm_common.h index 91b3d392e405a4265ebeaf05d741a3f3b51e72bc..9bf543cd3ce23dc0bf14b9c9881c92eba31a90cd 100644 --- a/previewer/include/wm_common.h +++ b/previewer/include/wm_common.h @@ -797,6 +797,34 @@ struct TitleButtonRect { } }; +/* + * @struct WindowLayoutInfo + * + * @brief Layout info for all windows on the screen. + */ +struct WindowLayoutInfo : public Parcelable { + Rect rect = { 0, 0, 0, 0 }; + + bool Marshalling(Parcel& parcel) const override + { + 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; + if (!parcel.ReadInt32(windowLayoutInfo->rect.posX_) || + !parcel.ReadInt32(windowLayoutInfo->rect.posY_) || + !parcel.ReadUint32(windowLayoutInfo->rect.width_) || + !parcel.ReadUint32(windowLayoutInfo->rect.height_)) { + delete windowLayoutInfo; + return nullptr; + } + return windowLayoutInfo; + } +}; + /** * Config of keyboard animation */ diff --git a/previewer/mock/window_manager_napi/js_window_manager.cpp b/previewer/mock/window_manager_napi/js_window_manager.cpp index 31bce3007d0cef987980f3358b9029452e87cf03..c41353a57c9bc253441a12ceee878b8552fc31a8 100644 --- a/previewer/mock/window_manager_napi/js_window_manager.cpp +++ b/previewer/mock/window_manager_napi/js_window_manager.cpp @@ -104,6 +104,12 @@ napi_value JsWindowManager::ToggleShownStateForAllAppWindows(napi_env env, napi_ return nullptr; } +napi_value JsWindowManager::GetAllWindowLayoutInfo(napi_env env, napi_callback_info info) +{ + TLOGI(WmsLogTag::WMS_ATTRIBUTE, "mock"); + return nullptr; +} + napi_value JsWindowManager::SetWindowLayoutMode(napi_env env, napi_callback_info info) { WLOGI("mock: SetWindowLayoutMode"); @@ -242,6 +248,7 @@ napi_value JsWindowManagerInit(napi_env env, napi_value exportObj) BindNativeFunction(env, exportObj, "minimizeAll", moduleName, JsWindowManager::MinimizeAll); BindNativeFunction(env, exportObj, "toggleShownStateForAllAppWindows", moduleName, JsWindowManager::ToggleShownStateForAllAppWindows); + BindNativeFunction(env, exportObj, "getAllWindowLayoutInfo", moduleName, JsWindowManager::GetAllWindowLayoutInfo); BindNativeFunction(env, exportObj, "setWindowLayoutMode", moduleName, JsWindowManager::SetWindowLayoutMode); BindNativeFunction(env, exportObj, "setGestureNavigationEnabled", moduleName, JsWindowManager::SetGestureNavigationEnabled); diff --git a/previewer/mock/window_manager_napi/js_window_manager.h b/previewer/mock/window_manager_napi/js_window_manager.h index 94af38c538109c86796c6be2c9c3b852ebb0c658..e8af0f22d25925cbb0d10876afbbbfe0142aded4 100644 --- a/previewer/mock/window_manager_napi/js_window_manager.h +++ b/previewer/mock/window_manager_napi/js_window_manager.h @@ -41,6 +41,7 @@ public: static napi_value UnregisterWindowMangerCallback(napi_env env, napi_callback_info info); static napi_value GetTopWindow(napi_env env, napi_callback_info info); static napi_value GetLastWindow(napi_env env, napi_callback_info info); + static napi_value GetAllWindowLayoutInfo(napi_env env, napi_callback_info info); static napi_value SetWindowLayoutMode(napi_env env, napi_callback_info info); static napi_value SetGestureNavigationEnabled(napi_env env, napi_callback_info info); static napi_value SetWaterMarkImage(napi_env env, napi_callback_info info); diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 48357b4b77881dc1f43a7f6b3d6b0e02d5a66c32..cb181c7d04f640105a5021e37a5ea2072d54694a 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -448,6 +448,7 @@ public: */ WMError ReleaseForegroundSessionScreenLock() override; void DealwithDrawingContentChange(const std::vector>& drawingContentChangeInfo); + WMError GetAllWindowLayoutInfo(DisplayId displayId, std::vector>& infos) override; /* * Multi Window @@ -747,6 +748,10 @@ private: void UpdateWindowDrawingData(uint64_t surfaceId, int32_t pid, int32_t uid); bool GetSpecifiedDrawingData(uint64_t surfaceId, int32_t& pid, int32_t& uid); void RemoveSpecifiedDrawingData(uint64_t surfaceId); + void FilterForGetAllWindowLayoutInfo(DisplayId displayId, bool isVirtualDisplay, + std::vector>& filteredSessions); + bool IsGetWindowLayoutInfoNeeded(const sptr& session) const; + int32_t GetFoldLowerScreenPosY() const; /* * Window Rotate Animation 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 b72d04337a59e25770b50117a88e6f7548cd263c..94cf2ab3ceb855c50cf70bae0a77de08b94469bf 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 @@ -96,6 +96,7 @@ public: TRANS_ID_GET_UI_CONTENT_REMOTE_OBJ, TRANS_ID_UPDATE_WINDOW_VISIBILITY_LISTENER, TRANS_ID_SHIFT_APP_WINDOW_FOCUS, + TRANS_ID_GET_WINDOW_LAYOUT_INFO, TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID, TRANS_ID_ADD_EXTENSION_WINDOW_STAGE_TO_SCB, TRANS_ID_REMOVE_EXTENSION_WINDOW_STAGE_FROM_SCB, @@ -222,6 +223,8 @@ public: { return WMError::WM_OK; } + WMError GetAllWindowLayoutInfo(DisplayId displayId, + std::vector>& infos) override { return WMError::WM_OK; } WMError GetVisibilityWindowInfo(std::vector>& infos) override { return WMError::WM_OK; } WMError SetWindowAnimationController(const sptr& controller) override { 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 ade82912494addf705cb768da88f08bcd6528f01..206aaaa98775f34451b902dd74d77709243ddbd0 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 @@ -99,6 +99,7 @@ public: WSError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible) override; WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override; WMError GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId) override; + WMError GetAllWindowLayoutInfo(DisplayId displayId, std::vector>& infos) override; WMError GetVisibilityWindowInfo(std::vector>& infos) override; WSError ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId) override; void AddExtensionWindowStageToSCB(const sptr& sessionStage, diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_stub.h b/window_scene/session_manager/include/zidl/scene_session_manager_stub.h index b69f2781730be4ad8723c88c05a214a273769890..44dd9ea65cb7bc35a2aa3b23455a02d0c9a8bbe9 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_stub.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_stub.h @@ -85,6 +85,7 @@ private: int HandleGetParentMainWindowId(MessageParcel& data, MessageParcel& reply); int HandleUpdateSessionWindowVisibilityListener(MessageParcel& data, MessageParcel& reply); int HandleShiftAppWindowFocus(MessageParcel& data, MessageParcel& reply); + int HandleGetAllWindowLayoutInfo(MessageParcel& data, MessageParcel& reply); int HandleGetVisibilityWindowInfo(MessageParcel& data, MessageParcel& reply); int HandleAddExtensionWindowStageToSCB(MessageParcel& data, MessageParcel& reply); int HandleRemoveExtensionWindowStageFromSCB(MessageParcel& data, MessageParcel& reply); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index c20eeff24dc67192b36510627a53bf1727b08337..09b68e6e31796c94c8d9de25fb258b08a79d49ea 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -64,6 +64,7 @@ #include "anomaly_detection.h" #include "session/host/include/ability_info_manager.h" #include "session/host/include/multi_instance_manager.h" +#include "common/include/fold_screen_state_internel.h" #include "hidump_controller.h" @@ -123,6 +124,8 @@ 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 = { {"unspecified", OHOS::AppExecFwk::DisplayOrientation::UNSPECIFIED}, @@ -142,6 +145,11 @@ const std::map STRING_TO_DISP {"follow_desktop", OHOS::AppExecFwk::DisplayOrientation::FOLLOW_DESKTOP}, }; +const std::unordered_set LAYOUT_INFO_WHITELIST = { + "SCBSmartDock", + "SCBExtScreenDock" +}; + const std::chrono::milliseconds WAIT_TIME(10 * 1000); // 10 * 1000 wait for 10s std::string GetCurrentTime() @@ -10497,6 +10505,87 @@ void SceneSessionManager::NotifyUpdateRectAfterLayout() taskScheduler_->PostAsyncTask(task, __func__); } +WMError SceneSessionManager::GetAllWindowLayoutInfo(DisplayId displayId, + std::vector>& infos) +{ + auto task = [this, displayId, &infos]() mutable { + bool isVirtualDisplay = false; + if (displayId == VIRTUAL_DISPLAY_ID) { + displayId = DEFAULT_DISPLAY_ID; + isVirtualDisplay = true; + } + std::vector> filteredSessions; + FilterForGetAllWindowLayoutInfo(displayId, isVirtualDisplay, filteredSessions); + for (const auto& session : filteredSessions) { + Rect globalScaledRect; + session->GetGlobalScaledRect(globalScaledRect); + if (isVirtualDisplay) { + globalScaledRect.posY_ -= GetFoldLowerScreenPosY(); + } + auto windowLayoutInfo = sptr::MakeSptr(); + windowLayoutInfo->rect = globalScaledRect; + infos.emplace_back(windowLayoutInfo); + } + return WMError::WM_OK; + }; + return taskScheduler_->PostSyncTask(task, __func__); +} + +void SceneSessionManager::FilterForGetAllWindowLayoutInfo(DisplayId displayId, bool isVirtualDisplay, + std::vector>& filteredSessions) +{ + { + std::shared_lock lock(sceneSessionMapMutex_); + for (const auto& [_, session] : sceneSessionMap_) { + if (session == nullptr) { + continue; + } + if (session->GetSessionRect().IsInvalid()) { + continue; + } + if (PcFoldScreenManager::GetInstance().GetScreenFoldStatus() == SuperFoldStatus::HALF_FOLDED && + session->GetSessionProperty()->GetDisplayId() == DEFAULT_DISPLAY_ID && + displayId == DEFAULT_DISPLAY_ID) { + if (isVirtualDisplay && + session->GetSessionRect().posY_ + session->GetSessionRect().height_ < GetFoldLowerScreenPosY()) { + continue; + } + if (!isVirtualDisplay && session->GetSessionRect().posY_ >= GetFoldLowerScreenPosY()) { + continue; + } + } + if (IsGetWindowLayoutInfoNeeded(session) && session->GetSessionProperty()->GetDisplayId() == displayId && + session->GetVisibilityState() != WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION) { + filteredSessions.emplace_back(session); + } + } + } + std::sort(filteredSessions.begin(), filteredSessions.end(), + [](const sptr& lhs, const sptr& rhs) { + return lhs->GetZOrder() > rhs->GetZOrder(); + }); +} + +int32_t SceneSessionManager::GetFoldLowerScreenPosY() const +{ + const auto& [defaultDisplayRect, virtualDisplayRect, foldCreaseRect] = + PcFoldScreenManager::GetInstance().GetDisplayRects(); + constexpr int32_t SUPER_FOLD_DIVIDE_FACTOR = 2; + return foldCreaseRect.height_ != 0 ? + defaultDisplayRect.height_ - foldCreaseRect.height_ / SUPER_FOLD_DIVIDE_FACTOR + foldCreaseRect.height_ : + defaultDisplayRect.height_; +} + +bool SceneSessionManager::IsGetWindowLayoutInfoNeeded(const sptr& session) const +{ + constexpr int32_t GROUP_ONE = 1; + std::string name = session->GetWindowName(); + std::regex pattern("^(.*?)(\\d*)$"); // Remove last digit + std::smatch matches; + name = std::regex_search(name, matches, pattern) ? matches[GROUP_ONE] : name; + return !session->GetSessionInfo().isSystem_ || LAYOUT_INFO_WHITELIST.find(name) != LAYOUT_INFO_WHITELIST.end(); +} + WMError SceneSessionManager::GetVisibilityWindowInfo(std::vector>& infos) { if (!SessionPermission::IsSystemCalling()) { 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 9053a0891898a660ee7b1ffba8ae26b2948e63a9..d72597fbe94d66ea4ea6db0cc48812188ea5fc11 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 @@ -1772,6 +1772,41 @@ WMError SceneSessionManagerProxy::GetParentMainWindowId(int32_t windowId, int32_ return static_cast(ret); } +WMError SceneSessionManagerProxy::GetAllWindowLayoutInfo(DisplayId displayId, + std::vector>& infos) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write interfaceToken failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteUint64(displayId)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write displayId failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "remote is null"); + return WMError::WM_ERROR_IPC_FAILED; + } + if (remote->SendRequest(static_cast( + SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_LAYOUT_INFO), data, reply, option) != ERR_NONE) { + return WMError::WM_ERROR_IPC_FAILED; + } + if (!MarshallingHelper::UnmarshallingVectorParcelableObj(reply, infos)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read window layout info failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + int32_t errCode = 0; + if (!reply.ReadInt32(errCode)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read errcode failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + return static_cast(errCode); +} + WMError SceneSessionManagerProxy::GetVisibilityWindowInfo(std::vector>& infos) { MessageParcel data; 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 7780ae82ebf7baf0641f995320d9c24314930d9e..b63bd8a0f89cc717719ee81c0cd82d3ebe7d725a 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 @@ -142,6 +142,8 @@ int SceneSessionManagerStub::ProcessRemoteRequest(uint32_t code, MessageParcel& return HandleUpdateSessionWindowVisibilityListener(data, reply); case static_cast(SceneSessionManagerMessage::TRANS_ID_SHIFT_APP_WINDOW_FOCUS): return HandleShiftAppWindowFocus(data, reply); + case static_cast(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_LAYOUT_INFO): + return HandleGetAllWindowLayoutInfo(data, reply); case static_cast(SceneSessionManagerMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID): return HandleGetVisibilityWindowInfo(data, reply); case static_cast(SceneSessionManagerMessage::TRANS_ID_ADD_EXTENSION_WINDOW_STAGE_TO_SCB): @@ -1096,6 +1098,26 @@ int SceneSessionManagerStub::HandleShiftAppWindowFocus(MessageParcel& data, Mess return ERR_NONE; } +int SceneSessionManagerStub::HandleGetAllWindowLayoutInfo(MessageParcel& data, MessageParcel& reply) +{ + uint64_t displayId = 0; + if (!data.ReadUint64(displayId)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to read displayId"); + return ERR_INVALID_DATA; + } + std::vector> infos; + WMError errCode = GetAllWindowLayoutInfo(displayId, infos); + if (!MarshallingHelper::MarshallingVectorParcelableObj(reply, infos)) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to write window layout info"); + return ERR_INVALID_DATA; + } + if (!reply.WriteInt32(static_cast(errCode))) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write errCode fail"); + return ERR_INVALID_DATA; + } + return ERR_NONE; +} + int SceneSessionManagerStub::HandleGetVisibilityWindowInfo(MessageParcel& data, MessageParcel& reply) { std::vector> infos; diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index a3f7ae9f550809d58aeaf83347c233b8457dafe7..cc563a50edc5ae247d025c789222f7b6e28352ae 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -75,6 +75,7 @@ public: virtual WMError GetAccessibilityWindowInfo(std::vector>& infos); virtual WMError GetUnreliableWindowInfo(int32_t windowId, std::vector>& infos); + virtual WMError GetAllWindowLayoutInfo(DisplayId displayId, std::vector>& infos); virtual WMError GetVisibilityWindowInfo(std::vector>& infos); virtual void MinimizeWindowsByLauncher(std::vector windowIds, bool isAnimated, sptr& finishCallback); diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index b15a19a78e5dfac9a16d85d52a9168374ba7b98f..f297edfde145898ec27bb7e49bd8852a8be83676 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -185,6 +185,14 @@ WMError WindowAdapter::GetUnreliableWindowInfo(int32_t windowId, return wmsProxy->GetUnreliableWindowInfo(windowId, infos); } +WMError WindowAdapter::GetAllWindowLayoutInfo(DisplayId displayId, std::vector>& infos) +{ + INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); + auto wmsProxy = GetWindowManagerServiceProxy(); + CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR); + return wmsProxy->GetAllWindowLayoutInfo(displayId, infos); +} + WMError WindowAdapter::GetVisibilityWindowInfo(std::vector>& infos) { INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index bdf7d89b29ed536f15bb3beb60433ee31b149a5a..20543c0a245033c0b7e168cf586d341aa46b3608 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -1119,6 +1119,15 @@ WMError WindowManager::GetUnreliableWindowInfo(int32_t windowId, return ret; } +WMError WindowManager::GetAllWindowLayoutInfo(DisplayId displayId, std::vector>& infos) const +{ + WMError ret = SingletonContainer::Get().GetAllWindowLayoutInfo(displayId, infos); + if (ret != WMError::WM_OK) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed"); + } + return ret; +} + WMError WindowManager::GetVisibilityWindowInfo(std::vector>& infos) const { WMError ret = SingletonContainer::Get().GetVisibilityWindowInfo(infos); diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index 5df5b0db18c250afb8b972906c294949ae9ad7c6..7887820d372811713b0d36c257ddaeb944bcd527 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -61,6 +61,7 @@ public: TRANS_ID_UPDATE_LAYOUT_MODE, TRANS_ID_UPDATE_PROPERTY, TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID, + TRANS_ID_GET_WINDOW_LAYOUT_INFO, TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID, TRANS_ID_ANIMATION_SET_CONTROLLER, TRANS_ID_GET_SYSTEM_CONFIG, @@ -117,6 +118,8 @@ public: const sptr& windowManagerAgent) = 0; virtual WMError GetAccessibilityWindowInfo(std::vector>& infos) = 0; virtual WMError GetUnreliableWindowInfo(int32_t windowId, std::vector>& infos) = 0; + virtual WMError GetAllWindowLayoutInfo(DisplayId displayId, + std::vector>& infos) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } virtual WMError GetVisibilityWindowInfo(std::vector>& infos) = 0; virtual WMError SetWindowAnimationController(const sptr& controller) = 0; virtual WMError GetSystemConfig(SystemConfig& systemConfig) = 0;