diff --git a/dm/BUILD.gn b/dm/BUILD.gn index 2994415c..309c3fb0 100644 --- a/dm/BUILD.gn +++ b/dm/BUILD.gn @@ -45,8 +45,8 @@ ohos_shared_library("libdm") { public_configs = [ ":libdm_public_config" ] deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_base:librender_service_base", - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/utils:libwmutil", ] diff --git a/dm/test/fuzztest/displaymanager_fuzzer/BUILD.gn b/dm/test/fuzztest/displaymanager_fuzzer/BUILD.gn index 31e21eac..16003c1d 100644 --- a/dm/test/fuzztest/displaymanager_fuzzer/BUILD.gn +++ b/dm/test/fuzztest/displaymanager_fuzzer/BUILD.gn @@ -24,7 +24,7 @@ ohos_fuzztest("DisplayManagerFuzzTest") { include_dirs = [ "//foundation/windowmanager/interfaces/innerkits/dm", "//utils/native/base/include", - "//foundation/graphic/graphic/interfaces/innerkits/surface", + "//foundation/graphic/graphic_2d/interfaces/innerkits/surface", ] cflags = [ "-g", @@ -34,7 +34,7 @@ ohos_fuzztest("DisplayManagerFuzzTest") { ] sources = [ "displaymanager_fuzzer.cpp" ] deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//utils/native/base:utils", ] diff --git a/dm/test/fuzztest/displaymanager_fuzzer/displaymanager_fuzzer.cpp b/dm/test/fuzztest/displaymanager_fuzzer/displaymanager_fuzzer.cpp index 5b6c8adb..90a094f5 100644 --- a/dm/test/fuzztest/displaymanager_fuzzer/displaymanager_fuzzer.cpp +++ b/dm/test/fuzztest/displaymanager_fuzzer/displaymanager_fuzzer.cpp @@ -15,6 +15,7 @@ #include "displaymanager_fuzzer.h" +#include #include "display_manager.h" namespace OHOS ::Rosen { @@ -45,8 +46,7 @@ size_t GetObject(T &object, const uint8_t *data, size_t size) if (objectSize > size) { return 0; } - std::memcpy(&object, data, objectSize); - return objectSize; + return memcpy_s(&object, objectSize, data, objectSize) == EOK ? objectSize : 0; } bool DisplayFuzzTest(const uint8_t* data, size_t size) diff --git a/dm/test/fuzztest/displaymanageripc_fuzzer/BUILD.gn b/dm/test/fuzztest/displaymanageripc_fuzzer/BUILD.gn index f89e0989..156ba034 100644 --- a/dm/test/fuzztest/displaymanageripc_fuzzer/BUILD.gn +++ b/dm/test/fuzztest/displaymanageripc_fuzzer/BUILD.gn @@ -34,7 +34,7 @@ ohos_fuzztest("DisplayManagerIPCFuzzTest") { ] sources = [ "displaymanageripc_fuzzer.cpp" ] deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", ] external_deps = [ "samgr_standard:samgr_proxy" ] diff --git a/dm/test/fuzztest/displaymanageripc_fuzzer/displaymanageripc_fuzzer.cpp b/dm/test/fuzztest/displaymanageripc_fuzzer/displaymanageripc_fuzzer.cpp index 1e0ad7c1..3f4fc1f7 100644 --- a/dm/test/fuzztest/displaymanageripc_fuzzer/displaymanageripc_fuzzer.cpp +++ b/dm/test/fuzztest/displaymanageripc_fuzzer/displaymanageripc_fuzzer.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include "display_manager_interface.h" @@ -33,8 +34,7 @@ size_t GetObject(T &object, const uint8_t *data, size_t size) if (objectSize > size) { return 0; } - std::memcpy(&object, data, objectSize); - return objectSize; + return memcpy_s(&object, objectSize, data, objectSize) == EOK ? objectSize : 0; } std::pair, sptr> GetProxy() diff --git a/dm/test/fuzztest/screen_fuzzer/BUILD.gn b/dm/test/fuzztest/screen_fuzzer/BUILD.gn index a7dbb8ac..1a1c17e3 100644 --- a/dm/test/fuzztest/screen_fuzzer/BUILD.gn +++ b/dm/test/fuzztest/screen_fuzzer/BUILD.gn @@ -23,7 +23,7 @@ ohos_fuzztest("ScreenFuzzTest") { include_dirs = [ "//foundation/windowmanager/interfaces/innerkits/dm", "//utils/native/base/include", - "//foundation/graphic/graphic/interfaces/innerkits/surface", + "//foundation/graphic/graphic_2d/interfaces/innerkits/surface", ] cflags = [ "-g", @@ -33,7 +33,7 @@ ohos_fuzztest("ScreenFuzzTest") { ] sources = [ "screen_fuzzer.cpp" ] deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//utils/native/base:utils", ] diff --git a/dm/test/fuzztest/screen_fuzzer/screen_fuzzer.cpp b/dm/test/fuzztest/screen_fuzzer/screen_fuzzer.cpp index 0facdf93..a9442345 100644 --- a/dm/test/fuzztest/screen_fuzzer/screen_fuzzer.cpp +++ b/dm/test/fuzztest/screen_fuzzer/screen_fuzzer.cpp @@ -16,6 +16,7 @@ #include "screen_fuzzer.h" #include +#include #include "display_manager.h" #include "display.h" @@ -31,8 +32,7 @@ size_t GetObject(T &object, const uint8_t *data, size_t size) if (objectSize > size) { return 0; } - std::memcpy(&object, data, objectSize); - return objectSize; + return memcpy_s(&object, objectSize, data, objectSize) == EOK ? objectSize : 0; } bool ScreenFuzzTest(const uint8_t *data, size_t size) diff --git a/dm/test/fuzztest/screenmanager_fuzzer/BUILD.gn b/dm/test/fuzztest/screenmanager_fuzzer/BUILD.gn index f0889c9f..1fae025d 100644 --- a/dm/test/fuzztest/screenmanager_fuzzer/BUILD.gn +++ b/dm/test/fuzztest/screenmanager_fuzzer/BUILD.gn @@ -24,7 +24,7 @@ ohos_fuzztest("ScreenManagerFuzzTest") { include_dirs = [ "//foundation/windowmanager/interfaces/innerkits/dm", "//utils/native/base/include", - "//foundation/graphic/graphic/interfaces/innerkits/surface", + "//foundation/graphic/graphic_2d/interfaces/innerkits/surface", ] cflags = [ "-g", @@ -34,7 +34,7 @@ ohos_fuzztest("ScreenManagerFuzzTest") { ] sources = [ "screenmanager_fuzzer.cpp" ] deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//utils/native/base:utils", ] diff --git a/dm/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp b/dm/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp index 737d74e7..0ce9ff02 100644 --- a/dm/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp +++ b/dm/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp @@ -16,6 +16,7 @@ #include "screenmanager_fuzzer.h" #include +#include #include "dm_common.h" #include "screen.h" @@ -51,8 +52,7 @@ size_t GetObject(T &object, const uint8_t *data, size_t size) if (objectSize > size) { return 0; } - std::memcpy(&object, data, objectSize); - return objectSize; + return memcpy_s(&object, objectSize, data, objectSize) == EOK ? objectSize : 0; } bool ScreenPowerFuzzTest(const uint8_t *data, size_t size) diff --git a/dm/test/systemtest/BUILD.gn b/dm/test/systemtest/BUILD.gn index e4f1c3c1..4b370c53 100644 --- a/dm/test/systemtest/BUILD.gn +++ b/dm/test/systemtest/BUILD.gn @@ -119,8 +119,8 @@ config("dm_systemtest_common_public_config") { "//foundation/windowmanager/utils/include", # RSSurface - "//foundation/graphic/graphic/interfaces/inner_api/surface", - "//foundation/graphic/graphic/rosen/modules/render_service_client", + "//foundation/graphic/graphic_2d/interfaces/inner_api/surface", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client", ] } @@ -133,7 +133,7 @@ ohos_static_library("dm_systemtest_common") { public_configs = [ ":dm_systemtest_common_public_config" ] public_deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", diff --git a/dm/test/systemtest/screenshot_cmd_test.cpp b/dm/test/systemtest/screenshot_cmd_test.cpp index 39e719b5..86be27b3 100644 --- a/dm/test/systemtest/screenshot_cmd_test.cpp +++ b/dm/test/systemtest/screenshot_cmd_test.cpp @@ -13,9 +13,10 @@ * limitations under the License. */ -// gtest +#include #include #include + #include "display_test_utils.h" #include "pixel_map.h" @@ -51,7 +52,7 @@ void ScreenshotCmdTest::SetUpTestCase() WLOGFE("GetDefaultDisplay: failed!\n"); return; } - WLOGFI("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), + WLOGFI("GetDefaultDisplay: id %" PRIu64", w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), display->GetHeight(), display->GetRefreshRate()); defaultId_ = display->GetId(); diff --git a/dm/test/systemtest/screenshot_test.cpp b/dm/test/systemtest/screenshot_test.cpp index 5c9aa3fc..fa833316 100644 --- a/dm/test/systemtest/screenshot_test.cpp +++ b/dm/test/systemtest/screenshot_test.cpp @@ -13,8 +13,9 @@ * limitations under the License. */ -// gtest +#include #include + #include "display_test_utils.h" #include "pixel_map.h" @@ -52,7 +53,7 @@ void ScreenshotTest::SetUpTestCase() WLOGFE("GetDefaultDisplay: failed!\n"); return; } - WLOGFI("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), + WLOGFI("GetDefaultDisplay: id %" PRIu64", w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), display->GetHeight(), display->GetRefreshRate()); defaultId_ = display->GetId(); diff --git a/dm/test/unittest/BUILD.gn b/dm/test/unittest/BUILD.gn index bc75c499..42f453af 100644 --- a/dm/test/unittest/BUILD.gn +++ b/dm/test/unittest/BUILD.gn @@ -111,7 +111,7 @@ config("dm_unittest_common_public_config") { "//foundation/windowmanager/snapshot", "//foundation/windowmanager/interfaces/innerkits/dm", "//foundation/windowmanager/utils/include", - "//foundation/graphic/graphic/rosen/modules/render_service_client", # RSSurface + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client", # RSSurface ] } @@ -122,7 +122,7 @@ ohos_static_library("dm_unittest_common") { public_configs = [ ":dm_unittest_common_public_config" ] public_deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", # PixelMap "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/windowmanager/dm:libdm", diff --git a/dmserver/BUILD.gn b/dmserver/BUILD.gn index 23ffa01f..68fc4b65 100644 --- a/dmserver/BUILD.gn +++ b/dmserver/BUILD.gn @@ -65,10 +65,12 @@ ohos_shared_library("libdms") { "//foundation/windowmanager/utils:libwmutil", # RSSurface - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", ] external_deps = [ + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", "graphic_standard:surface", "hilog_native:libhilog", "hitrace_native:hitrace_meter", diff --git a/dmserver/include/display_manager_stub.h b/dmserver/include/display_manager_stub.h index d88c4a0c..32488a7c 100644 --- a/dmserver/include/display_manager_stub.h +++ b/dmserver/include/display_manager_stub.h @@ -27,6 +27,9 @@ public: ~DisplayManagerStub() = default; virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; +private: + bool CheckCallingPermission(const std::string &permission); + bool IsStartByHdcd(); }; } // namespace OHOS::Rosen diff --git a/dmserver/src/abstract_screen.cpp b/dmserver/src/abstract_screen.cpp index 2ac0556b..e625408b 100644 --- a/dmserver/src/abstract_screen.cpp +++ b/dmserver/src/abstract_screen.cpp @@ -66,11 +66,12 @@ sptr AbstractScreen::ConvertToScreenInfo() const void AbstractScreen::UpdateRSTree(std::shared_ptr& surfaceNode, bool isAdd) { - if (rsDisplayNode_ == nullptr) { - WLOGFE("rsDisplayNode_ is nullptr"); + if (rsDisplayNode_ == nullptr || surfaceNode == nullptr) { + WLOGFE("node is nullptr"); return; } - WLOGFI("AbstractScreen::UpdateRSTree"); + WLOGFI("%{public}s surface: %{public}s, %{public}" PRIu64"", (isAdd ? "add" : "remove"), + surfaceNode->GetName().c_str(), surfaceNode->GetId()); if (isAdd) { rsDisplayNode_->AddChild(surfaceNode, -1); diff --git a/dmserver/src/abstract_screen_controller.cpp b/dmserver/src/abstract_screen_controller.cpp index 0be759a1..d40f8716 100644 --- a/dmserver/src/abstract_screen_controller.cpp +++ b/dmserver/src/abstract_screen_controller.cpp @@ -508,29 +508,24 @@ ScreenId AbstractScreenController::CreateVirtualScreen(VirtualScreenOption optio ScreenId dmsScreenId = SCREEN_ID_INVALID; if (!screenIdManager_.ConvertToDmsScreenId(rsId, dmsScreenId)) { dmsScreenId = screenIdManager_.CreateAndGetNewScreenId(rsId); - if (!option.isForShot_) { - WLOGI("CreateVirtualScreen is not shot"); - sptr absScreen = new(std::nothrow) AbstractScreen(this, option.name_, dmsScreenId, rsId); - sptr info = new(std::nothrow) SupportedScreenModes(); - if (absScreen == nullptr || info == nullptr) { - WLOGFI("new AbstractScreen or SupportedScreenModes failed"); - screenIdManager_.DeleteScreenId(dmsScreenId); - return SCREEN_ID_INVALID; - } - info->width_ = option.width_; - info->height_ = option.height_; - auto defaultScreen = GetAbstractScreen(GetDefaultAbstractScreenId()); - if (defaultScreen != nullptr && defaultScreen->GetActiveScreenMode() != nullptr) { - info->refreshRate_ = defaultScreen->GetActiveScreenMode()->refreshRate_; - } - absScreen->modes_.emplace_back(info); - absScreen->activeIdx_ = 0; - absScreen->type_ = ScreenType::VIRTUAL; - dmsScreenMap_.insert(std::make_pair(dmsScreenId, absScreen)); - NotifyScreenConnected(absScreen->ConvertToScreenInfo()); - } else { - WLOGI("CreateVirtualScreen is shot"); + sptr absScreen = new(std::nothrow) AbstractScreen(this, option.name_, dmsScreenId, rsId); + sptr info = new(std::nothrow) SupportedScreenModes(); + if (absScreen == nullptr || info == nullptr) { + WLOGFI("new AbstractScreen or SupportedScreenModes failed"); + screenIdManager_.DeleteScreenId(dmsScreenId); + return SCREEN_ID_INVALID; } + info->width_ = option.width_; + info->height_ = option.height_; + auto defaultScreen = GetAbstractScreen(GetDefaultAbstractScreenId()); + if (defaultScreen != nullptr && defaultScreen->GetActiveScreenMode() != nullptr) { + info->refreshRate_ = defaultScreen->GetActiveScreenMode()->refreshRate_; + } + absScreen->modes_.emplace_back(info); + absScreen->activeIdx_ = 0; + absScreen->type_ = ScreenType::VIRTUAL; + dmsScreenMap_.insert(std::make_pair(dmsScreenId, absScreen)); + NotifyScreenConnected(absScreen->ConvertToScreenInfo()); } else { WLOGFI("id: %{public}" PRIu64" appears in screenIdManager_. ", rsId); } diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index 05ee1558..8aa37932 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -19,6 +19,8 @@ #include +#include "accesstoken_kit.h" +#include "bundle_constants.h" #include "marshalling_helper.h" #include "window_manager_hilog.h" @@ -29,6 +31,27 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerStub"}; } +bool DisplayManagerStub::CheckCallingPermission(const std::string &permission) +{ + if (Security::AccessToken::AccessTokenKit::VerifyAccessToken(IPCSkeleton::GetCallingTokenID(), permission) != + AppExecFwk::Constants::PERMISSION_GRANTED) { + return false; + } + return true; +} + +bool DisplayManagerStub::IsStartByHdcd() +{ + OHOS::Security::AccessToken::NativeTokenInfo info; + if (Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(IPCSkeleton::GetCallingTokenID(), info) != 0) { + return false; + } + if (info.processName.compare("hdcd") == 0) { + return true; + } + return false; +} + int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { @@ -110,9 +133,14 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, break; } case DisplayManagerMessage::TRANS_ID_GET_DISPLAY_SNAPSHOT: { - DisplayId displayId = data.ReadUint64(); - std::shared_ptr displaySnapshot = GetDisplaySnapshot(displayId); - reply.WriteParcelable(displaySnapshot == nullptr ? nullptr : displaySnapshot.get()); + if (CheckCallingPermission("ohos.permission.CAPTURE_SCREEN") || IsStartByHdcd()) { + DisplayId displayId = data.ReadUint64(); + std::shared_ptr displaySnapshot = GetDisplaySnapshot(displayId); + reply.WriteParcelable(displaySnapshot == nullptr ? nullptr : displaySnapshot.get()); + break; + } + WLOGFE("check permission failed!"); + reply.WriteParcelable(nullptr); break; } case DisplayManagerMessage::TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT: { diff --git a/extension/extension_connection/BUILD.gn b/extension/extension_connection/BUILD.gn index b35f9bae..83c7efda 100644 --- a/extension/extension_connection/BUILD.gn +++ b/extension/extension_connection/BUILD.gn @@ -41,7 +41,7 @@ ohos_shared_library("libwindow_extension_client") { configs = [ ":libwindow_extension_client_private_config" ] deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/extension/window_extension:libwindow_extension", "//foundation/windowmanager/wm:libwm", ] diff --git a/extension/extension_connection/include/zidl/window_extension_client_interface.h b/extension/extension_connection/include/zidl/window_extension_client_interface.h index bb68d53a..b7b79474 100644 --- a/extension/extension_connection/include/zidl/window_extension_client_interface.h +++ b/extension/extension_connection/include/zidl/window_extension_client_interface.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef WINDOW_EXTENSION_CLIENT_INTERFACE -#define WINDOW_EXTENSION_CLIENT_INTERFACE +#ifndef WINDOW_EXTENSION_CLIENT_INTERFACE_H +#define WINDOW_EXTENSION_CLIENT_INTERFACE_H #include #include @@ -40,4 +40,4 @@ public: }; } // namespace Rosen } // namespace OHOS -#endif // WINDOW_EXTENSION_CLIENT_INTERFACE \ No newline at end of file +#endif // WINDOW_EXTENSION_CLIENT_INTERFACE_H \ No newline at end of file diff --git a/extension/extension_connection/include/zidl/window_extension_client_proxy.h b/extension/extension_connection/include/zidl/window_extension_client_proxy.h index 2b1dbc82..6fb38af8 100644 --- a/extension/extension_connection/include/zidl/window_extension_client_proxy.h +++ b/extension/extension_connection/include/zidl/window_extension_client_proxy.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef WINODW_EXTENSION_CLIENT_PROXY -#define WINODW_EXTENSION_CLIENT_PROXY +#ifndef WINODW_EXTENSION_CLIENT_PROXY_H +#define WINODW_EXTENSION_CLIENT_PROXY_H #include #include "window_extension_client_interface.h" @@ -35,4 +35,4 @@ private: }; } // namespace Rosen } // namespace OHOS -#endif // WINODW_EXTENSION_CLIENT_PROXY \ No newline at end of file +#endif // WINODW_EXTENSION_CLIENT_PROXY_H \ No newline at end of file diff --git a/extension/extension_connection/include/zidl/window_extension_client_stub.h b/extension/extension_connection/include/zidl/window_extension_client_stub.h index 903241ff..8b297122 100644 --- a/extension/extension_connection/include/zidl/window_extension_client_stub.h +++ b/extension/extension_connection/include/zidl/window_extension_client_stub.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef WINDOW_EXTENSION_CLIENT_STUB -#define WINDOW_EXTENSION_CLIENT_STUB +#ifndef WINDOW_EXTENSION_CLIENT_STUB_H +#define WINDOW_EXTENSION_CLIENT_STUB_H #include #include "window_extension_client_interface.h" @@ -31,4 +31,4 @@ public: }; } // namespace Rosen } // namespace OHOS -#endif // WINDOW_EXTENSION_CLIENT_STUB \ No newline at end of file +#endif // WINDOW_EXTENSION_CLIENT_STUB_H \ No newline at end of file diff --git a/extension/extension_connection/src/window_extension_connection.cpp b/extension/extension_connection/src/window_extension_connection.cpp index e00571c8..3f5060e0 100644 --- a/extension/extension_connection/src/window_extension_connection.cpp +++ b/extension/extension_connection/src/window_extension_connection.cpp @@ -196,7 +196,6 @@ void WindowExtensionConnection::Impl::OnAbilityDisconnectDone(const AppExecFwk:: WLOGFI("end"); } -// WindowExtensionConnection int WindowExtensionConnection::ConnectExtension(const AppExecFwk::ElementName& element, const Rect& rect, uint32_t uid, const sptr& callback) const { diff --git a/extension/window_extension/BUILD.gn b/extension/window_extension/BUILD.gn index 15c8b462..9ced9c8d 100644 --- a/extension/window_extension/BUILD.gn +++ b/extension/window_extension/BUILD.gn @@ -43,7 +43,7 @@ ohos_shared_library("libwindow_extension") { deps = [ "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common", - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/interfaces/kits/napi/window_runtime:window_native_kit", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index 224724ba..d6397fac 100644 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -25,7 +25,7 @@ ohos_shared_library("wm_interface") { public_deps = [ "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//utils/native/base:utils", diff --git a/interfaces/innerkits/dm/screen.h b/interfaces/innerkits/dm/screen.h index e2bc396e..cef0d717 100644 --- a/interfaces/innerkits/dm/screen.h +++ b/interfaces/innerkits/dm/screen.h @@ -42,7 +42,7 @@ struct SupportedScreenModes : public RefBase { }; struct VirtualScreenOption { - const std::string name_; + std::string name_; uint32_t width_; uint32_t height_; float density_; diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 1dd90f34..7b9c3fa5 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -58,6 +58,7 @@ public: virtual void AfterBackground() = 0; virtual void AfterFocused() = 0; virtual void AfterUnfocused() = 0; + virtual void ForegroundFailed() {} virtual void AfterActive() {} virtual void AfterInactive() {} }; @@ -119,6 +120,11 @@ public: virtual void OnPointerInputEvent(std::shared_ptr& pointerEvent) = 0; }; +class IOutsidePressedListener : virtual public RefBase { +public: + virtual void OnOutsidePressed() = 0; +}; + class Window : public RefBase { public: static sptr Create(const std::string& windowName, @@ -200,6 +206,7 @@ public: virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) = 0; virtual void RegisterOccupiedAreaChangeListener(const sptr& listener) = 0; virtual void UnregisterOccupiedAreaChangeListener(const sptr& listener) = 0; + virtual void RegisterOutsidePressedListener(const sptr& listener) = 0; virtual void SetAceAbilityHandler(const sptr& handler) = 0; virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false, AppExecFwk::Ability* ability = nullptr) = 0; @@ -208,6 +215,7 @@ public: virtual void OnNewWant(const AAFwk::Want& want) = 0; virtual void SetRequestedOrientation(Orientation) = 0; virtual Orientation GetRequestedOrientation() = 0; + virtual void SetModeSupportInfo(uint32_t modeSupportInfo) = 0; virtual bool IsDecorEnable() const = 0; virtual WMError Maximize() = 0; diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index 6deb8322..8b0f81dc 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -136,7 +136,7 @@ public: void RegisterVisibilityChangedListener(const sptr& listener); void UnregisterVisibilityChangedListener(const sptr& listener); void MinimizeAllAppWindows(DisplayId displayId); - void ToggleShownStateForAllAppWindows(); + WMError ToggleShownStateForAllAppWindows(); WMError SetWindowLayoutMode(WindowLayoutMode mode); WMError GetAccessibilityWindowInfo(sptr& windowInfo) const; diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 0cb5acb6..12807285 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -58,6 +58,7 @@ enum class WindowType : uint32_t { WINDOW_TYPE_LAUNCHER_DOCK, WINDOW_TYPE_BOOT_ANIMATION, WINDOW_TYPE_FREEZE_DISPLAY, + WINDOW_TYPE_VOICE_INTERACTION, ABOVE_APP_SYSTEM_WINDOW_END, SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END, @@ -72,6 +73,19 @@ enum class WindowMode : uint32_t { WINDOW_MODE_PIP }; +enum WindowModeSupport : uint32_t { + WINDOW_MODE_SUPPORT_FULLSCREEN = 1 << 0, + WINDOW_MODE_SUPPORT_FLOATING = 1 << 1, + WINDOW_MODE_SUPPORT_SPLIT_PRIMARY = 1 << 2, + WINDOW_MODE_SUPPORT_SPLIT_SECONDARY = 1 << 3, + WINDOW_MODE_SUPPORT_PIP = 1 << 4, + WINDOW_MODE_SUPPORT_ALL = WINDOW_MODE_SUPPORT_FULLSCREEN | + WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | + WINDOW_MODE_SUPPORT_SPLIT_SECONDARY | + WINDOW_MODE_SUPPORT_FLOATING | + WINDOW_MODE_SUPPORT_PIP +}; + enum class WindowBlurLevel : uint32_t { WINDOW_BLUR_OFF = 0, WINDOW_BLUR_LOW, @@ -101,7 +115,8 @@ enum class WindowFlag : uint32_t { WINDOW_FLAG_NEED_AVOID = 1, WINDOW_FLAG_PARENT_LIMIT = 1 << 1, WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2, - WINDOW_FLAG_END = 1 << 3, + WINDOW_FLAG_FORBID_SPLIT_MOVE = 1 << 3, + WINDOW_FLAG_END = 1 << 4, }; enum class WindowSizeChangeReason : uint32_t { @@ -149,6 +164,8 @@ namespace { constexpr float UNDEFINED_BRIGHTNESS = -1.0f; constexpr float MINIMUM_BRIGHTNESS = 0.0f; constexpr float MAXIMUM_BRIGHTNESS = 1.0f; + constexpr int32_t INVALID_PID = -1; + constexpr int32_t INVALID_UID = -1; } struct SystemBarProperty { diff --git a/interfaces/kits/napi/display_runtime/BUILD.gn b/interfaces/kits/napi/display_runtime/BUILD.gn index 9a1c676a..d046ab9e 100644 --- a/interfaces/kits/napi/display_runtime/BUILD.gn +++ b/interfaces/kits/napi/display_runtime/BUILD.gn @@ -39,7 +39,7 @@ ohos_shared_library("display_napi") { "${aafwk_kits_path}/appkit:app_context", "${aafwk_kits_path}/appkit:appkit_native", "../common:wm_napi_common", - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/utils:libwmutil", ] diff --git a/interfaces/kits/napi/screen_runtime/BUILD.gn b/interfaces/kits/napi/screen_runtime/BUILD.gn index 217336ac..03285272 100644 --- a/interfaces/kits/napi/screen_runtime/BUILD.gn +++ b/interfaces/kits/napi/screen_runtime/BUILD.gn @@ -40,7 +40,7 @@ ohos_shared_library("screen_napi") { "${aafwk_kits_path}/ability/native:abilitykit_native", "${aafwk_kits_path}/appkit:app_context", "${aafwk_kits_path}/appkit:appkit_native", - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/utils:libwmutil", diff --git a/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts b/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts index 301ac4c4..8c35b9d5 100644 --- a/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts +++ b/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts @@ -57,6 +57,31 @@ declare namespace screen { function makeMirror(mainScreen:number, mirrorScreen:Array, callback: AsyncCallback): void; function makeMirror(mainScreen:number, mirrorScreen:Array): Promise; + /** + * Create virtual screen. + * @param option Indicates the option of the virtual screen. + * @since 9 + */ + function createVirtualScreen(option:VirtualScreenOption, callback: AsyncCallback): void; + function createVirtualScreen(option:VirtualScreenOption): Promise; + + /** + * Destroy virtual screen. + * @param screenId Indicates the screen id of the virtual screen. + * @since 9 + */ + function destroyVirtualScreen(screenId:number, callback: AsyncCallback): void; + function destroyVirtualScreen(screenId:number): Promise; + + /** + * Set surface for the virtual screen. + * @param screenId Indicates the screen id of the virtual screen. + * @param surfaceId Indicates the surface id. + * @since 9 + */ + function setVirtualScreenSurface(screenId:number, surfaceId: string, callback: AsyncCallback): void; + function setVirtualScreenSurface(screenId:number, surfaceId: string): Promise; + /** * the parameter of making expand screen * @syscap SystemCapability.WindowManager.WindowManager.Core @@ -79,6 +104,38 @@ declare namespace screen { startY: number; } + /** + * The parameter for creating virtual screen. + * @syscap SystemCapability.WindowManager.WindowManager.Core + * @since 9 + */ + interface VirtualScreenOption { + /** + * Indicates the name of the virtual screen. + */ + name: string + + /** + * Indicates the width of the virtual screen. + */ + width: number + + /** + * Indicates the height of the virtual screen. + */ + height: number + + /** + * Indicates the density of the virtual screen. + */ + density: number + + /** + * Indicates the surface id of the virtual screen. + */ + surfaceId: string + } + /** * interface for screen * @syscap SystemCapability.WindowManager.WindowManager.Core diff --git a/interfaces/kits/napi/screen_runtime/napi/js_screen.cpp b/interfaces/kits/napi/screen_runtime/napi/js_screen.cpp index 75515ed2..d5710235 100644 --- a/interfaces/kits/napi/screen_runtime/napi/js_screen.cpp +++ b/interfaces/kits/napi/screen_runtime/napi/js_screen.cpp @@ -230,9 +230,12 @@ NativeValue* CreateJsScreenObject(NativeEngine& engine, sptr& screen) } std::unique_ptr jsScreen = std::make_unique(screen); object->SetNativePointer(jsScreen.release(), JsScreen::Finalizer, nullptr); - - object->SetProperty("id", CreateJsValue(engine, static_cast(screen->GetId()))); - object->SetProperty("parent", CreateJsValue(engine, static_cast(screen->GetParentId()))); + ScreenId screenId = screen->GetId(); + object->SetProperty("id", + CreateJsValue(engine, screenId == SCREEN_ID_INVALID ? -1 : static_cast(screenId))); + ScreenId parentId = screen->GetParentId(); + object->SetProperty("parent", + CreateJsValue(engine, parentId == SCREEN_ID_INVALID ? -1 : static_cast(parentId))); object->SetProperty("orientation", CreateJsValue(engine, screen->GetOrientation())); object->SetProperty("activeModeIndex", CreateJsValue(engine, screen->GetModeId())); object->SetProperty("supportedModeInfo", CreateJsScreenModeArrayObject(engine, screen->GetSupportedModes())); @@ -241,7 +244,6 @@ NativeValue* CreateJsScreenObject(NativeEngine& engine, sptr& screen) std::shared_ptr JsScreenRef; JsScreenRef.reset(engine.CreateReference(objValue, 1)); - ScreenId screenId = screen->GetId(); std::lock_guard lock(g_mutex); g_JsScreenMap[screenId] = JsScreenRef; BindNativeFunction(engine, *object, "setScreenActiveMode", JsScreen::SetScreenActiveMode); diff --git a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp index d179664b..b8fcda0e 100644 --- a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp +++ b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp @@ -19,12 +19,13 @@ #include #include #include "js_runtime_utils.h" +#include "js_screen.h" #include "js_screen_listener.h" #include "native_engine/native_reference.h" #include "screen_manager.h" -#include "window_manager_hilog.h" #include "singleton_container.h" -#include "js_screen.h" +#include "surface_utils.h" +#include "window_manager_hilog.h" namespace OHOS { namespace Rosen { @@ -80,6 +81,23 @@ static NativeValue* MakeExpand(NativeEngine* engine, NativeCallbackInfo* info) return (me != nullptr) ? me->OnMakeExpand(*engine, *info) : nullptr; } +static NativeValue* CreateVirtualScreen(NativeEngine* engine, NativeCallbackInfo* info) +{ + JsScreenManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnCreateVirtualScreen(*engine, *info) : nullptr; +} + +static NativeValue* DestroyVirtualScreen(NativeEngine* engine, NativeCallbackInfo* info) +{ + JsScreenManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnDestroyVirtualScreen(*engine, *info) : nullptr; +} + +static NativeValue* SetVirtualScreenSurface(NativeEngine* engine, NativeCallbackInfo* info) +{ + JsScreenManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetVirtualScreenSurface(*engine, *info) : nullptr; +} private: std::map, sptr>> jsCbMap_; std::mutex mtx_; @@ -392,6 +410,200 @@ int32_t GetExpandOptionFromJs(NativeEngine& engine, NativeObject* optionObject, option = {screenId, startX, startY}; return 0; } + +NativeValue* OnCreateVirtualScreen(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsScreenManager::OnCreateVirtualScreen is called"); + DMError errCode = DMError::DM_OK; + VirtualScreenOption option; + if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) { + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); + errCode = DMError::DM_ERROR_INVALID_PARAM; + } else { + NativeObject* object = ConvertNativeValueTo(info.argv[0]); + if (object == nullptr) { + WLOGFE("Failed to convert parameter to VirtualScreenOption."); + errCode = DMError::DM_ERROR_INVALID_PARAM; + } else { + errCode = GetVirtualScreenOptionFromJs(engine, object, option); + } + } + AsyncTask::CompleteCallback complete = + [option, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + if (errCode != DMError::DM_OK) { + task.Reject(engine, CreateJsError(engine, static_cast(errCode), + "JsScreenManager::OnCreateVirtualScreen, Invalidate params.")); + WLOGFE("JsScreenManager::OnCreateVirtualScreen failed, Invalidate params."); + } else { + auto screenId = SingletonContainer::Get().CreateVirtualScreen(option); + auto screen = SingletonContainer::Get().GetScreenById(screenId); + if (screen == nullptr) { + task.Reject(engine, CreateJsError(engine, static_cast(DMError::DM_ERROR_UNKNOWN), + "ScreenManager::CreateVirtualScreen failed.")); + WLOGFE("ScreenManager::CreateVirtualScreen failed."); + return; + } + task.Resolve(engine, CreateJsScreenObject(engine, screen)); + WLOGFI("JsScreenManager::OnCreateVirtualScreen success"); + } + }; + NativeValue* lastParam = nullptr; + if (info.argc == ARGC_TWO && info.argv[ARGC_TWO - 1] != nullptr && + info.argv[ARGC_TWO - 1]->TypeOf() == NATIVE_FUNCTION) { + lastParam = info.argv[ARGC_TWO - 1]; + } + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +DMError GetVirtualScreenOptionFromJs(NativeEngine& engine, NativeObject* optionObject, VirtualScreenOption& option) +{ + NativeValue* name = optionObject->GetProperty("name"); + if (!ConvertFromJsValue(engine, name, option.name_)) { + WLOGFE("Failed to convert parameter to name."); + return DMError::DM_ERROR_INVALID_PARAM; + } + NativeValue* width = optionObject->GetProperty("width"); + if (!ConvertFromJsValue(engine, width, option.width_)) { + WLOGFE("Failed to convert parameter to width."); + return DMError::DM_ERROR_INVALID_PARAM; + } + NativeValue* height = optionObject->GetProperty("height"); + if (!ConvertFromJsValue(engine, height, option.height_)) { + WLOGFE("Failed to convert parameter to height."); + return DMError::DM_ERROR_INVALID_PARAM; + } + NativeValue* density = optionObject->GetProperty("density"); + double densityValue; + if (!ConvertFromJsValue(engine, density, densityValue)) { + WLOGFE("Failed to convert parameter to density."); + return DMError::DM_ERROR_INVALID_PARAM; + } + option.density_ = static_cast(densityValue); + + NativeValue* surfaceIdNativeValue = optionObject->GetProperty("surfaceId"); + if (!GetSurfaceFromJs(engine, surfaceIdNativeValue, option.surface_)) { + return DMError::DM_ERROR_INVALID_PARAM; + } + return DMError::DM_OK; +} + +bool GetSurfaceFromJs(NativeEngine& engine, NativeValue* surfaceIdNativeValue, sptr& surface) +{ + if (surfaceIdNativeValue == nullptr || surfaceIdNativeValue->TypeOf() != NATIVE_STRING) { + WLOGFE("Failed to convert parameter to surface. Invalidate params."); + return false; + } + char buffer[PATH_MAX]; + size_t length = 0; + uint64_t surfaceId = 0; + napi_env env = reinterpret_cast(&engine); + napi_value surfaceIdValue = reinterpret_cast(surfaceIdNativeValue); + if (napi_get_value_string_utf8(env, surfaceIdValue, buffer, PATH_MAX, &length) != napi_ok) { + WLOGFE("Failed to convert parameter to surface."); + return false; + } + std::istringstream inputStream(buffer); + inputStream >> surfaceId; + surface = SurfaceUtils::GetInstance()->GetSurface(surfaceId); + if (surface == nullptr) { + WLOGFI("GetSurfaceFromJs failed, surfaceId:%{public}" PRIu64"", surfaceId); + } + return true; +} + +NativeValue* OnDestroyVirtualScreen(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsScreenManager::OnDestroyVirtualScreen is called"); + DMError errCode = DMError::DM_OK; + int64_t screenId = -1LL; + if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) { + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); + errCode = DMError::DM_ERROR_INVALID_PARAM; + } else { + if (!ConvertFromJsValue(engine, info.argv[0], screenId)) { + WLOGFE("Failed to convert parameter to screen id."); + errCode = DMError::DM_ERROR_INVALID_PARAM; + } + } + AsyncTask::CompleteCallback complete = + [screenId, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + if (errCode != DMError::DM_OK || screenId == -1LL) { + task.Reject(engine, CreateJsError(engine, static_cast(DMError::DM_ERROR_INVALID_PARAM), + "JsScreenManager::OnDestroyVirtualScreen, Invalidate params.")); + WLOGFE("JsScreenManager::OnDestroyVirtualScreen failed, Invalidate params."); + } else { + auto res = SingletonContainer::Get().DestroyVirtualScreen(screenId); + if (res != DMError::DM_OK) { + task.Reject(engine, CreateJsError(engine, static_cast(res), + "ScreenManager::DestroyVirtualScreen failed.")); + WLOGFE("ScreenManager::DestroyVirtualScreen failed."); + return; + } + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsScreenManager::OnDestroyVirtualScreen success"); + } + }; + NativeValue* lastParam = nullptr; + if (info.argc == ARGC_TWO && info.argv[ARGC_TWO - 1] != nullptr && + info.argv[ARGC_TWO - 1]->TypeOf() == NATIVE_FUNCTION) { + lastParam = info.argv[ARGC_TWO - 1]; + } + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* OnSetVirtualScreenSurface(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsScreenManager::OnSetVirtualScreenSurface is called"); + DMError errCode = DMError::DM_OK; + int64_t screenId = -1LL; + sptr surface; + if (info.argc != ARGC_TWO && info.argc != ARGC_THREE) { + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); + errCode = DMError::DM_ERROR_INVALID_PARAM; + } else { + if (!ConvertFromJsValue(engine, info.argv[0], screenId)) { + WLOGFE("Failed to convert parameter to screen id."); + errCode = DMError::DM_ERROR_INVALID_PARAM; + } + if (!GetSurfaceFromJs(engine, info.argv[1], surface)) { + WLOGFE("Failed to convert parameter to surface"); + errCode = DMError::DM_ERROR_INVALID_PARAM; + } + } + AsyncTask::CompleteCallback complete = + [screenId, surface, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + if (errCode != DMError::DM_OK || surface == nullptr) { + task.Reject(engine, CreateJsError(engine, static_cast(DMError::DM_ERROR_INVALID_PARAM), + "JsScreenManager::OnSetVirtualScreenSurface, Invalidate params.")); + WLOGFE("JsScreenManager::OnSetVirtualScreenSurface failed, Invalidate params."); + } else { + auto res = SingletonContainer::Get().SetVirtualScreenSurface(screenId, surface); + if (res != DMError::DM_OK) { + task.Reject(engine, CreateJsError(engine, static_cast(res), + "ScreenManager::SetVirtualScreenSurface failed.")); + WLOGFE("ScreenManager::SetVirtualScreenSurface failed."); + return; + } + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsScreenManager::OnSetVirtualScreenSurface success"); + } + }; + NativeValue* lastParam = nullptr; + if (info.argc == ARGC_THREE && info.argv[ARGC_TWO - 1] != nullptr && + info.argv[ARGC_THREE - 1]->TypeOf() == NATIVE_FUNCTION) { + lastParam = info.argv[ARGC_THREE - 1]; + } + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} }; NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj) @@ -417,6 +629,9 @@ NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj) BindNativeFunction(*engine, *object, "off", JsScreenManager::UnregisterScreenMangerCallback); BindNativeFunction(*engine, *object, "makeMirror", JsScreenManager::MakeMirror); BindNativeFunction(*engine, *object, "makeExpand", JsScreenManager::MakeExpand); + BindNativeFunction(*engine, *object, "createVirtualScreen", JsScreenManager::CreateVirtualScreen); + BindNativeFunction(*engine, *object, "destroyVirtualScreen", JsScreenManager::DestroyVirtualScreen); + BindNativeFunction(*engine, *object, "setVirtualScreenSurface", JsScreenManager::SetVirtualScreenSurface); return engine->CreateUndefined(); } } // namespace Rosen diff --git a/interfaces/kits/napi/screenshot/native_screenshot_module.cpp b/interfaces/kits/napi/screenshot/native_screenshot_module.cpp index f22dd550..7d9beb09 100644 --- a/interfaces/kits/napi/screenshot/native_screenshot_module.cpp +++ b/interfaces/kits/napi/screenshot/native_screenshot_module.cpp @@ -164,13 +164,6 @@ static void GetScreenshotParam(napi_env env, std::unique_ptr ¶m, napi static void AsyncGetScreenshot(napi_env env, std::unique_ptr ¶m) { - if (!CheckCallingPermission("ohos.permission.CAPTURE_SCREEN")) { - WLOGFE("Get Screenshot failed. Do not have permission!"); - param->image = nullptr; - param->wret = WMError::WM_ERROR_INVALID_PERMISSION; - param->errMessage = "Get Screenshot Failed: Do not have ohos.permission.CAPTURE_SCREEN"; - return; - } if (!param->validInputParam) { WLOGFE("Invalid Input Param!"); param->image = nullptr; diff --git a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts index e13cc2b5..ef6cea81 100644 --- a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -933,6 +933,24 @@ declare namespace window { * @return The dump info array. */ dump(params: Array): Array; + + /** + * set the flag of the window is forbidden to move in split screen mode + * @param isForbidSplitMove the flag of the window is forbidden to move in split screen mode + * @syscap SystemCapability.WindowManager.WindowManager.Core + * @systemapi + * @since 9 + */ + setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback): void; + + /** + * set the flag of the window is forbidden to move in split screen mode + * @param isForbidSplitMove the flag of the window is forbidden to move in split screen mode + * @syscap SystemCapability.WindowManager.WindowManager.Core + * @systemapi + * @since 9 + */ + setForbidSplitMove(isForbidSplitMove: boolean): Promise; } enum WindowStageEventType { 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 d94633e3..e238d7fa 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 @@ -370,9 +370,14 @@ NativeValue* JsWindowManager::OnToggleShownStateForAllAppWindows(NativeEngine& e task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params")); return; } - SingletonContainer::Get().ToggleShownStateForAllAppWindows(); - task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("[NAPI]OnToggleShownStateForAllAppWindows success"); + WMError ret = SingletonContainer::Get().ToggleShownStateForAllAppWindows(); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("[NAPI]OnToggleShownStateForAllAppWindows success"); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), + "OnToggleShownStateForAllAppWindows failed")); + } }; NativeValue* lastParam = (info.argc <= 0) ? nullptr : (info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index e64b52f7..f8825562 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -299,6 +299,13 @@ NativeValue* JsWindow::Dump(NativeEngine* engine, NativeCallbackInfo* info) return (me != nullptr) ? me->OnDump(*engine, *info) : nullptr; } +NativeValue* JsWindow::SetForbidSplitMove(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("[NAPI]SetForbidSplitMove"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetForbidSplitMove(*engine, *info) : nullptr; +} + NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info) { WMError errCode = WMError::WM_OK; @@ -306,21 +313,23 @@ NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info) WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - WMError ret = windowToken_->Show(); + WMError ret = weakWindow->Show(); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window show failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] show end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -338,22 +347,23 @@ NativeValue* JsWindow::OnDestroy(NativeEngine& engine, NativeCallbackInfo& info) WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - WMError ret = windowToken_->Destroy(); + WMError ret = weakWindow->Destroy(); WLOGFI("[NAPI]Window [%{public}u, %{public}s] destroy end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); if (ret != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window destroy failed")); return; } - windowToken_ = nullptr; task.Resolve(engine, engine.CreateUndefined()); }; @@ -372,21 +382,23 @@ NativeValue* JsWindow::OnHide(NativeEngine& engine, NativeCallbackInfo& info) WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - WMError ret = windowToken_->Hide(); + WMError ret = weakWindow->Hide(); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window hide failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] hide end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -416,21 +428,23 @@ NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info) errCode = WMError::WM_ERROR_INVALID_PARAM; } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, errCode, x, y](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - WMError ret = windowToken_->MoveTo(x, y); + WMError ret = weakWindow->MoveTo(x, y); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window move failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] move end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); }; // 2: params num; 2: index of callback NativeValue* lastParam = (info.argc <= 2) ? nullptr : @@ -459,21 +473,23 @@ NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info) WLOGFE("[NAPI]Failed to convert parameter to height"); errCode = WMError::WM_ERROR_INVALID_PARAM; } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, errCode, width, height](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - WMError ret = windowToken_->Resize(width, height); + WMError ret = weakWindow->Resize(width, height); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window resize failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] resize end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); }; // 2: params num; 2: index of callback NativeValue* lastParam = (info.argc <= 2) ? nullptr : @@ -511,21 +527,23 @@ NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, winType, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - WMError ret = windowToken_->SetWindowType(winType); + WMError ret = weakWindow->SetWindowType(winType); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window set type failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set type end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -563,14 +581,16 @@ NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, winMode, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - WMError ret = windowToken_->SetWindowMode(winMode); + WMError ret = weakWindow->SetWindowMode(winMode); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { @@ -578,7 +598,7 @@ NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& CreateJsError(engine, static_cast(ret), "Window set mode failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set type end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc == 1) ? nullptr : @@ -596,14 +616,16 @@ NativeValue* JsWindow::OnGetProperties(NativeEngine& engine, NativeCallbackInfo& WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - auto objValue = CreateJsWindowPropertiesObject(engine, windowToken_); + auto objValue = CreateJsWindowPropertiesObject(engine, weakWindow); if (objValue != nullptr) { task.Resolve(engine, objValue); } else { @@ -611,7 +633,7 @@ NativeValue* JsWindow::OnGetProperties(NativeEngine& engine, NativeCallbackInfo& static_cast(WMError::WM_ERROR_NULLPTR), "Window get properties failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] get properties end, objValue = %{public}p", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), objValue); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), objValue); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -675,6 +697,23 @@ NativeValue* JsWindow::OnUnregisterWindowCallback(NativeEngine& engine, NativeCa return engine.CreateUndefined(); } +static void LoadContentTask(std::weak_ptr contentStorage, std::string contextUrl, + sptr weakWindow, NativeEngine& engine, AsyncTask& task) +{ + NativeValue* nativeStorage = (contentStorage.lock() == nullptr) ? nullptr : contentStorage.lock()->Get(); + AppExecFwk::Ability* ability = nullptr; + GetAPI7Ability(engine, ability); + WMError ret = weakWindow->SetUIContent(contextUrl, &engine, nativeStorage, false, ability); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + } else { + task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window load content failed")); + } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] load content end, ret = %{public}d", + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); + return; +} + NativeValue* JsWindow::OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info) { WMError errCode = WMError::WM_OK; @@ -701,26 +740,18 @@ NativeValue* JsWindow::OnLoadContent(NativeEngine& engine, NativeCallbackInfo& i // 2: index of callback callBack = (info.argv[2]->TypeOf() == NATIVE_FUNCTION ? info.argv[2] : nullptr); } - std::shared_ptr contentStorage = (storage == nullptr) ? nullptr : + std::weak_ptr contentStorage = (storage == nullptr) ? nullptr : std::shared_ptr(engine.CreateReference(storage, 1)); + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, contentStorage, contextUrl, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]Window is nullptr or get invalid param"); return; } - NativeValue* nativeStorage = (contentStorage == nullptr) ? nullptr : contentStorage->Get(); - AppExecFwk::Ability* ability = nullptr; - GetAPI7Ability(engine, ability); - WMError ret = windowToken_->SetUIContent(contextUrl, &engine, nativeStorage, false, ability); - if (ret == WMError::WM_OK) { - task.Resolve(engine, engine.CreateUndefined()); - } else { - task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window load content failed")); - } - WLOGFI("[NAPI]Window [%{public}u, %{public}s] load content end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + LoadContentTask(contentStorage, contextUrl, weakWindow, engine, task); }; NativeValue* result = nullptr; AsyncTask::Schedule( @@ -746,20 +777,22 @@ NativeValue* JsWindow::OnSetFullScreen(NativeEngine& engine, NativeCallbackInfo& } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, isFullScreen, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); return; } - WMError ret = windowToken_->SetFullScreen(isFullScreen); + WMError ret = weakWindow->SetFullScreen(isFullScreen); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window SetFullScreen failed.")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set full screen end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -787,13 +820,15 @@ NativeValue* JsWindow::OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbac isLayoutFullScreen = static_cast(*nativeVal); } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, isLayoutFullScreen, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); return; } - WMError ret = windowToken_->SetLayoutFullScreen(isLayoutFullScreen); + WMError ret = weakWindow->SetLayoutFullScreen(isLayoutFullScreen); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { @@ -801,7 +836,7 @@ NativeValue* JsWindow::OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbac static_cast(ret), "Window OnSetLayoutFullScreen failed.")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set layout full screen end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr); @@ -822,16 +857,18 @@ NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallback if (errCode == WMError::WM_OK && !GetSystemBarStatus(systemBarProperties, engine, info, windowToken_)) { errCode = WMError::WM_ERROR_INVALID_PARAM; } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, systemBarProperties, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - WMError ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, + WMError ret = weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, systemBarProperties.at(WindowType::WINDOW_TYPE_STATUS_BAR)); - ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, + ret = weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, systemBarProperties.at(WindowType::WINDOW_TYPE_NAVIGATION_BAR)); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); @@ -840,7 +877,7 @@ NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallback static_cast(ret), "JsWindow::OnSetSystemBarEnable failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set system bar enable end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); }; NativeValue* lastParam = nullptr; if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_FUNCTION) { @@ -874,15 +911,17 @@ NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCall } } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, systemBarProperties, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); } - WMError ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, + WMError ret = weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, systemBarProperties.at(WindowType::WINDOW_TYPE_STATUS_BAR)); - ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, + ret = weakWindow->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, systemBarProperties.at(WindowType::WINDOW_TYPE_NAVIGATION_BAR)); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); @@ -891,7 +930,7 @@ NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCall static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnSetSystemBarProperties failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set system bar properties end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -920,16 +959,18 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& avoidAreaType = static_cast(static_cast(*nativeMode)); } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, errCode, avoidAreaType](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } // getAvoidRect by avoidAreaType AvoidArea avoidArea; - WMError ret = windowToken_->GetAvoidAreaByType(avoidAreaType, avoidArea); + WMError ret = weakWindow->GetAvoidAreaByType(avoidAreaType, avoidArea); if (ret != WMError::WM_OK) { avoidArea = { g_emptyRect, g_emptyRect, g_emptyRect, g_emptyRect }; // left, top, right, bottom } @@ -942,7 +983,7 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnGetAvoidArea failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] get avoid area end, ret = %{public}d", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr); @@ -959,17 +1000,19 @@ NativeValue* JsWindow::OnIsShowing(NativeEngine& engine, NativeCallbackInfo& inf WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - bool state = windowToken_->GetShowState(); + bool state = weakWindow->GetShowState(); task.Resolve(engine, CreateJsValue(engine, state)); WLOGFI("[NAPI]Window [%{public}u, %{public}s] get show state end, state = %{public}u", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), state); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), state); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -987,17 +1030,19 @@ NativeValue* JsWindow::OnIsSupportWideGamut(NativeEngine& engine, NativeCallback WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - bool flag = windowToken_->IsSupportWideGamut(); + bool flag = weakWindow->IsSupportWideGamut(); task.Resolve(engine, CreateJsValue(engine, flag)); WLOGFI("[NAPI]Window [%{public}u, %{public}s] OnIsSupportWideGamut end, ret = %{public}u", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), flag); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), flag); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -1021,13 +1066,15 @@ NativeValue* JsWindow::OnSetBackgroundColor(NativeEngine& engine, NativeCallback errCode = WMError::WM_ERROR_INVALID_PARAM; } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, color, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); return; } - WMError ret = windowToken_->SetBackgroundColor(color); + WMError ret = weakWindow->SetBackgroundColor(color); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { @@ -1035,7 +1082,7 @@ NativeValue* JsWindow::OnSetBackgroundColor(NativeEngine& engine, NativeCallback "Window set background color failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set background color end", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -1064,20 +1111,22 @@ NativeValue* JsWindow::OnSetBrightness(NativeEngine& engine, NativeCallbackInfo& } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, brightness, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); return; } - WMError ret = windowToken_->SetBrightness(brightness); + WMError ret = weakWindow->SetBrightness(brightness); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window set brightness failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set brightness end", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -1091,7 +1140,7 @@ NativeValue* JsWindow::OnSetBrightness(NativeEngine& engine, NativeCallbackInfo& NativeValue* JsWindow::OnSetDimBehind(NativeEngine& engine, NativeCallbackInfo& info) { AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { + [](NativeEngine& engine, AsyncTask& task, int32_t status) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); }; @@ -1121,20 +1170,22 @@ NativeValue* JsWindow::OnSetFocusable(NativeEngine& engine, NativeCallbackInfo& } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, focusable, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); return; } - WMError ret = windowToken_->SetFocusable(focusable); + WMError ret = weakWindow->SetFocusable(focusable); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window set focusable failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set focusable end", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -1163,13 +1214,15 @@ NativeValue* JsWindow::OnSetKeepScreenOn(NativeEngine& engine, NativeCallbackInf } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, keepScreenOn, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); return; } - WMError ret = windowToken_->SetKeepScreenOn(keepScreenOn); + WMError ret = weakWindow->SetKeepScreenOn(keepScreenOn); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { @@ -1177,7 +1230,7 @@ NativeValue* JsWindow::OnSetKeepScreenOn(NativeEngine& engine, NativeCallbackInf "Window set keep screen on failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set keep screen on end", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -1191,7 +1244,7 @@ NativeValue* JsWindow::OnSetKeepScreenOn(NativeEngine& engine, NativeCallbackInf NativeValue* JsWindow::OnSetOutsideTouchable(NativeEngine& engine, NativeCallbackInfo& info) { AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { + [](NativeEngine& engine, AsyncTask& task, int32_t status) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); }; @@ -1221,16 +1274,18 @@ NativeValue* JsWindow::OnSetPrivacyMode(NativeEngine& engine, NativeCallbackInfo } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, isPrivacyMode, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params")); return; } - windowToken_->SetPrivacyMode(isPrivacyMode); + weakWindow->SetPrivacyMode(isPrivacyMode); task.Resolve(engine, engine.CreateUndefined()); WLOGFI("[NAPI]Window [%{public}u, %{public}s] set privacy mode end, mode = %{public}u", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), isPrivacyMode); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), isPrivacyMode); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -1259,20 +1314,22 @@ NativeValue* JsWindow::OnSetTouchable(NativeEngine& engine, NativeCallbackInfo& } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, touchable, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); return; } - WMError ret = windowToken_->SetTouchable(touchable); + WMError ret = weakWindow->SetTouchable(touchable); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window set touchable failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set touchable end", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -1301,20 +1358,22 @@ NativeValue* JsWindow::OnSetTransparent(NativeEngine& engine, NativeCallbackInfo } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, isTransparent, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); return; } - WMError ret = windowToken_->SetTransparent(isTransparent); + WMError ret = weakWindow->SetTransparent(isTransparent); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window set transparent failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set transparent end", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -1343,13 +1402,15 @@ NativeValue* JsWindow::OnSetCallingWindow(NativeEngine& engine, NativeCallbackIn } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, callingWindow, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); return; } - WMError ret = windowToken_->SetCallingWindow(callingWindow); + WMError ret = weakWindow->SetCallingWindow(callingWindow); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { @@ -1357,7 +1418,7 @@ NativeValue* JsWindow::OnSetCallingWindow(NativeEngine& engine, NativeCallbackIn "Window set calling window failed")); } WLOGFI("[NAPI]Window [%{public}u, %{public}s] set calling window end", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str()); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -1400,17 +1461,19 @@ NativeValue* JsWindow::OnSetColorSpace(NativeEngine& engine, NativeCallbackInfo& } } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, colorSpace, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode), "OnSetColorSpace failed")); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - windowToken_->SetColorSpace(colorSpace); + weakWindow->SetColorSpace(colorSpace); task.Resolve(engine, engine.CreateUndefined()); WLOGFI("[NAPI]Window [%{public}u, %{public}s] OnSetColorSpace end, colorSpace = %{public}u", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), static_cast(colorSpace)); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), static_cast(colorSpace)); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -1428,17 +1491,19 @@ NativeValue* JsWindow::OnGetColorSpace(NativeEngine& engine, NativeCallbackInfo& WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } + wptr weakToken(windowToken_); AsyncTask::CompleteCallback complete = - [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowToken_ == nullptr || errCode != WMError::WM_OK) { + [weakToken, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } - ColorSpace colorSpace = windowToken_->GetColorSpace(); + ColorSpace colorSpace = weakWindow->GetColorSpace(); task.Resolve(engine, CreateJsValue(engine, static_cast(colorSpace))); WLOGFI("[NAPI]Window [%{public}u, %{public}s] OnGetColorSpace end, colorSpace = %{public}u", - windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), static_cast(colorSpace)); + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), static_cast(colorSpace)); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -1473,6 +1538,54 @@ NativeValue* JsWindow::OnDump(NativeEngine& engine, NativeCallbackInfo& info) return dumpInfoValue; } +NativeValue* JsWindow::OnSetForbidSplitMove(NativeEngine& engine, NativeCallbackInfo& info) +{ + WMError errCode = WMError::WM_OK; + if (info.argc < 1 || info.argc > 2) { // 2: maximum params num + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); + errCode = WMError::WM_ERROR_INVALID_PARAM; + } + bool isForbidSplitMove = false; + if (errCode == WMError::WM_OK) { + NativeBoolean* nativeVal = ConvertNativeValueTo(info.argv[0]); + if (nativeVal == nullptr) { + WLOGFE("[NAPI]Failed to convert parameter to isForbidSplitMove"); + errCode = WMError::WM_ERROR_INVALID_PARAM; + } else { + isForbidSplitMove = static_cast(*nativeVal); + } + } + wptr weakToken(windowToken_); + AsyncTask::CompleteCallback complete = + [weakToken, isForbidSplitMove, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr || errCode != WMError::WM_OK) { + task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); + return; + } + WMError ret; + if (isForbidSplitMove) { + ret = weakWindow->AddWindowFlag(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE); + } else { + ret = weakWindow->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE); + } + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(ret), "Window OnSetForbidSplitMove failed.")); + } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] set forbid split move end, ret = %{public}d", + weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str(), ret); + }; + NativeValue* lastParam = (info.argc <= 1) ? nullptr : + (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr); + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + std::shared_ptr FindJsWindowObject(std::string windowName) { WLOGFI("[NAPI]Try to find window %{public}s in g_jsWindowMap", windowName.c_str()); @@ -1533,6 +1646,7 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) BindNativeFunction(engine, *object, "setCallingWindow", JsWindow::SetCallingWindow); BindNativeFunction(engine, *object, "disableWindowDecor", JsWindow::DisableWindowDecor); BindNativeFunction(engine, *object, "dump", JsWindow::Dump); + BindNativeFunction(engine, *object, "setForbidSplitMove", JsWindow::SetForbidSplitMove); std::shared_ptr jsWindowRef; jsWindowRef.reset(engine.CreateReference(objValue, 1)); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.h b/interfaces/kits/napi/window_runtime/window_napi/js_window.h index ad791578..9d26d9f5 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -66,6 +66,7 @@ public: static NativeValue* SetColorSpace(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* GetColorSpace(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* Dump(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetForbidSplitMove(NativeEngine* engine, NativeCallbackInfo* info); private: std::string GetWindowName(); @@ -103,6 +104,7 @@ private: NativeValue* OnSetCallingWindow(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnDisableWindowDecor(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnDump(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetForbidSplitMove(NativeEngine& engine, NativeCallbackInfo& info); sptr windowToken_ = nullptr; std::unique_ptr registerManager_ = nullptr; diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp index d2d0e374..a6c8c354 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp @@ -176,5 +176,19 @@ void JsWindowListener::OnSizeChange(const sptr& info) std::unique_ptr execute = nullptr; AsyncTask::Schedule(*engine_, std::make_unique(callback, std::move(execute), std::move(complete))); } + +void JsWindowListener::OnOutsidePressed() +{ + std::unique_ptr complete = std::make_unique ( + [=] (NativeEngine &engine, AsyncTask &task, int32_t status) { + CallJsMethod(OUTSIDE_PRESSED_CB.c_str(), nullptr, 0); + } + ); + + NativeReference* callback = nullptr; + std::unique_ptr execute = nullptr; + AsyncTask::Schedule(*engine_, std::make_unique(callback, std::move(execute), std::move(complete))); + WLOGFI("CALLED"); +} } // namespace Rosen } // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h index c755257c..8268b385 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h @@ -34,12 +34,14 @@ const std::string SYSTEM_AVOID_AREA_CHANGE_CB = "systemAvoidAreaChange"; const std::string LIFECYCLE_EVENT_CB = "lifeCycleEvent"; const std::string WINDOW_STAGE_EVENT_CB = "windowStageEvent"; const std::string KEYBOARD_HEIGHT_CHANGE_CB = "keyboardHeightChange"; +const std::string OUTSIDE_PRESSED_CB = "outsidePressed"; class JsWindowListener : public IWindowChangeListener, public ISystemBarChangedListener, public IAvoidAreaChangedListener, public IWindowLifeCycle, - public IOccupiedAreaChangeListener { + public IOccupiedAreaChangeListener, + public IOutsidePressedListener { public: JsWindowListener(NativeEngine* engine, std::shared_ptr callback) : engine_(engine), jsCallBack_(callback) {} @@ -53,6 +55,7 @@ public: void AfterFocused() override; void AfterUnfocused() override; void OnSizeChange(const sptr& info) override; + void OnOutsidePressed() override; private: void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0); void LifeCycleCallBack(LifeCycleEventType eventType); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp index 6cd9d9d8..e2b05a84 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp @@ -33,7 +33,8 @@ JsWindowRegisterManager::JsWindowRegisterManager() {WINDOW_SIZE_CHANGE_CB, &JsWindowRegisterManager::ProcessWindowChangeRegister }, {SYSTEM_AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessAvoidAreaChangeRegister }, {LIFECYCLE_EVENT_CB, &JsWindowRegisterManager::ProcessLifeCycleEventRegister }, - {KEYBOARD_HEIGHT_CHANGE_CB, &JsWindowRegisterManager::ProcesOccupiedAreaChangeRegister } + {KEYBOARD_HEIGHT_CHANGE_CB, &JsWindowRegisterManager::ProcesOccupiedAreaChangeRegister }, + {OUTSIDE_PRESSED_CB, &JsWindowRegisterManager::ProcessOutsidePressedRegister } }; // white register list for window stage listenerProcess_[CaseType::CASE_STAGE] = { @@ -121,6 +122,22 @@ bool JsWindowRegisterManager::ProcessSystemBarChangeRegister(sptr listener, + sptr window, bool isRegister) +{ + WLOGFI("called"); + if (window == nullptr) { + return false; + } + if (isRegister) { + sptr thisListener(listener); + window->RegisterOutsidePressedListener(thisListener); + } else { + window->RegisterOutsidePressedListener(nullptr); + } + return true; +} + bool JsWindowRegisterManager::IsCallbackRegistered(std::string type, NativeValue* jsListenerObject) { if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h index 06e50790..e3b7b764 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h @@ -44,6 +44,7 @@ private: bool ProcessLifeCycleEventRegister(sptr listener, sptr window, bool isRegister); bool ProcesOccupiedAreaChangeRegister(sptr listener, sptr window, bool isRegister); bool ProcessSystemBarChangeRegister(sptr listener, sptr window, bool isRegister); + bool ProcessOutsidePressedRegister(sptr listener, sptr window, bool isRegister); using Func_t = bool(JsWindowRegisterManager::*)(sptr, sptr window, bool); std::map, sptr>> jsCbMap_; std::mutex mtx_; diff --git a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp index 3687ebe8..3999678d 100644 --- a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp +++ b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp @@ -106,6 +106,13 @@ NativeValue* JsWindowStage::SetShowOnLockScreen(NativeEngine* engine, NativeCall return (me != nullptr) ? me->OnSetShowOnLockScreen(*engine, *info) : nullptr; } +NativeValue* JsWindowStage::DisableWindowDecor(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("[NAPI]DisableWindowDecor"); + JsWindowStage* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnDisableWindowDecor(*engine, *info) : nullptr; +} + NativeValue* JsWindowStage::OnSetUIContent(NativeEngine& engine, NativeCallbackInfo& info) { if (info.argc < 2) { // 2: minimum param num @@ -252,9 +259,9 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn std::shared_ptr(engine.CreateReference(storage, 1)); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (windowScene_ == nullptr) { - task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); - WLOGFE("[NAPI]windowScene_ is nullptr"); + if (windowScene_ == nullptr || errCode != WMError::WM_OK) { + task.Reject(engine, CreateJsError(engine, static_cast(errCode))); + WLOGFE("[NAPI]Window scene is null or get invalid param"); return; } auto win = windowScene_->GetMainWindow(); @@ -417,6 +424,20 @@ NativeValue* JsWindowStage::OnSetShowOnLockScreen(NativeEngine& engine, NativeCa return CreateJsValue(engine, static_cast(ret)); } +NativeValue* JsWindowStage::OnDisableWindowDecor(NativeEngine& engine, NativeCallbackInfo& info) +{ + if (windowScene_ == nullptr || windowScene_->GetMainWindow() == nullptr) { + WLOGFE("[NAPI]WindowScene is null or window is null"); + return CreateJsValue(engine, static_cast(WMError::WM_ERROR_NULLPTR)); + } + + auto window = windowScene_->GetMainWindow(); + window->DisableAppWindowDecor(); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] disable app window decor end", + window->GetWindowId(), window->GetWindowName().c_str()); + return engine.CreateUndefined(); +} + NativeValue* CreateJsWindowStage(NativeEngine& engine, std::shared_ptr windowScene) { @@ -443,6 +464,8 @@ NativeValue* CreateJsWindowStage(NativeEngine& engine, BindNativeFunction(engine, *object, "off", JsWindowStage::Off); BindNativeFunction(engine, *object, "setShowOnLockScreen", JsWindowStage::SetShowOnLockScreen); + BindNativeFunction(engine, + *object, "disableWindowDecor", JsWindowStage::DisableWindowDecor); return objValue; } diff --git a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h index 8f61c671..2e853332 100644 --- a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h +++ b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.h @@ -38,6 +38,7 @@ public: static NativeValue* CreateSubWindow(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* GetSubWindow(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* SetShowOnLockScreen(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* DisableWindowDecor(NativeEngine* engine, NativeCallbackInfo* info); private: NativeValue* CreateJsSubWindowArrayObject(NativeEngine& engine, std::vector> subWinVec); @@ -50,6 +51,7 @@ private: NativeValue* OnCreateSubWindow(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetSubWindow(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnSetShowOnLockScreen(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnDisableWindowDecor(NativeEngine& engine, NativeCallbackInfo& info); std::shared_ptr windowScene_; }; diff --git a/interfaces/kits/napi/window_runtime/window_stage_napi/window_stage.js b/interfaces/kits/napi/window_runtime/window_stage_napi/window_stage.js index 639f4537..99c3fa1d 100644 --- a/interfaces/kits/napi/window_runtime/window_stage_napi/window_stage.js +++ b/interfaces/kits/napi/window_runtime/window_stage_napi/window_stage.js @@ -53,6 +53,10 @@ class WindowStage { setShowOnLockScreen(showOnLockScreen) { return this.__window_stage__.setShowOnLockScreen(showOnLockScreen) } + + disableWindowDecor() { + return this.__window_stage__.disableWindowDecor() + } } export default WindowStage diff --git a/resources/rk3568/display_manager_config.xml b/resources/rk3568/display_manager_config.xml index 5f22a0d9..c46c1479 100644 --- a/resources/rk3568/display_manager_config.xml +++ b/resources/rk3568/display_manager_config.xml @@ -15,5 +15,5 @@ --> - 160 - \ No newline at end of file + 240 + diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn index 6e84ceae..3c5f8073 100644 --- a/snapshot/BUILD.gn +++ b/snapshot/BUILD.gn @@ -53,7 +53,7 @@ ohos_executable("snapshot_virtual_screen") { configs = [ ":snapshot_config" ] deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", diff --git a/utils/BUILD.gn b/utils/BUILD.gn index ea44c46f..0f24e2b2 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -12,7 +12,7 @@ # limitations under the License. import("//build/ohos.gni") -import("//foundation/graphic/graphic/graphic_config.gni") +import("//foundation/graphic/graphic_2d/graphic_config.gni") config("libwmutil_private_config") { include_dirs = [ "include", @@ -51,8 +51,8 @@ ohos_shared_library("libwmutil") { public_configs = [ ":libwmutil_public_config" ] deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_base:librender_service_base", - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//third_party/flutter/build/skia:ace_skia_ohos", ] diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index 4dd9641c..e91b446b 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -59,11 +59,26 @@ public: return ((IsMainWindow(type)) && (mode == WindowMode::WINDOW_MODE_FLOATING)); } + static inline bool IsMainFullScreenWindow(WindowType type, WindowMode mode) + { + return ((IsMainWindow(type)) && (mode == WindowMode::WINDOW_MODE_FULLSCREEN)); + } + + static inline bool IsFloatintWindow(WindowMode mode) + { + return mode == WindowMode::WINDOW_MODE_FLOATING; + } + static inline bool IsAvoidAreaWindow(WindowType type) { return (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR); } + static inline bool IsFullScreenWindow(WindowMode mode) + { + return mode == WindowMode::WINDOW_MODE_FULLSCREEN; + } + static inline bool IsSplitWindowMode(WindowMode mode) { return mode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || mode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY; @@ -86,6 +101,45 @@ public: return (r.posX_ == 0 && r.posY_ == 0 && r.width_ == 0 && r.height_ == 0); } + static bool IsWindowModeSupported(uint32_t modeSupportInfo, WindowMode mode) + { + switch (mode) { + case WindowMode::WINDOW_MODE_FULLSCREEN: + return WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN & modeSupportInfo; + case WindowMode::WINDOW_MODE_FLOATING: + return WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING & modeSupportInfo; + case WindowMode::WINDOW_MODE_SPLIT_PRIMARY: + return WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY & modeSupportInfo; + case WindowMode::WINDOW_MODE_SPLIT_SECONDARY: + return WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY & modeSupportInfo; + case WindowMode::WINDOW_MODE_PIP: + return WindowModeSupport::WINDOW_MODE_SUPPORT_PIP & modeSupportInfo; + default: + return true; + } + } + + static WindowMode GetWindowModeFromModeSupportInfo(uint32_t modeSupportInfo) + { + // get the binary number consists of the last 1 and 0 behind it + uint32_t windowModeSupport = modeSupportInfo & (~modeSupportInfo + 1); + + switch (windowModeSupport) { + case WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN: + return WindowMode::WINDOW_MODE_FULLSCREEN; + case WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING: + return WindowMode::WINDOW_MODE_FLOATING; + case WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY: + return WindowMode::WINDOW_MODE_SPLIT_PRIMARY; + case WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY: + return WindowMode::WINDOW_MODE_SPLIT_SECONDARY; + case WindowModeSupport::WINDOW_MODE_SUPPORT_PIP: + return WindowMode::WINDOW_MODE_PIP; + default: + return WindowMode::WINDOW_MODE_UNDEFINED; + } + } + static Rect GetFixedWindowRectByLimitSize(const Rect& oriDstRect, const Rect& lastRect, bool isVertical, float virtualPixelRatio) { diff --git a/utils/include/window_property.h b/utils/include/window_property.h index 0cd4d7c6..776f5884 100644 --- a/utils/include/window_property.h +++ b/utils/include/window_property.h @@ -66,6 +66,9 @@ public: void SetAnimationFlag(uint32_t animationFlag); void SetWindowSizeChangeReason(WindowSizeChangeReason reason); void SetTokenState(bool hasToken); + void SetWindowPid(int32_t pid); + void SetWindowUid(int32_t uid); + void SetModeSupportInfo(uint32_t modeSupportInfo); WindowSizeChangeReason GetWindowSizeChangeReason() const; const std::string& GetWindowName() const; @@ -96,6 +99,9 @@ public: bool GetDecorEnable() const; const PointInfo& GetHitOffset() const; uint32_t GetAnimationFlag() const; + int32_t GetWindowPid() const; + int32_t GetWindowUid() const; + uint32_t GetModeSupportInfo() const; virtual bool Marshalling(Parcel& parcel) const override; static WindowProperty* Unmarshalling(Parcel& parcel); @@ -128,12 +134,15 @@ private: uint32_t parentId_ { 0 }; PointInfo hitOffset_ { 0, 0 }; uint32_t animationFlag_ { static_cast(WindowAnimation::DEFAULT) }; + uint32_t modeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL}; WindowSizeChangeReason windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED; std::unordered_map sysBarPropMap_ { { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, }; bool isDecorEnable_ { false }; + int32_t pid_ { INVALID_PID }; + int32_t uid_ { INVALID_UID }; DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED); }; } diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index 3403ba74..83b6f223 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -75,6 +75,7 @@ enum class PropertyChangeAction : uint32_t { ACTION_UPDATE_TURN_SCREEN_ON = 1 << 8, ACTION_UPDATE_KEEP_SCREEN_ON = 1 << 9, ACTION_UPDATE_SET_BRIGHTNESS = 1 << 10, + ACTION_UPDATE_MODE_SUPPORT_INFO = 1 << 11, }; struct ModeChangeHotZonesConfig { diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index 04264759..85a25dc4 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -165,6 +165,16 @@ void WindowProperty::SetWindowSizeChangeReason(WindowSizeChangeReason reason) windowSizeChangeReason_ = reason; } +void WindowProperty::SetWindowPid(int32_t pid) +{ + pid_ = pid; +} + +void WindowProperty::SetWindowUid(int32_t uid) +{ + uid_ = uid; +} + WindowSizeChangeReason WindowProperty::GetWindowSizeChangeReason() const { return windowSizeChangeReason_; @@ -300,6 +310,11 @@ void WindowProperty::SetTokenState(bool hasToken) tokenState_ = hasToken; } +void WindowProperty::SetModeSupportInfo(uint32_t modeSupportInfo) +{ + modeSupportInfo_ = modeSupportInfo; +} + uint32_t WindowProperty::GetWindowId() const { return windowId_; @@ -320,11 +335,26 @@ uint32_t WindowProperty::GetAnimationFlag() const return animationFlag_; } +uint32_t WindowProperty::GetModeSupportInfo() const +{ + return modeSupportInfo_; +} + bool WindowProperty::GetTokenState() const { return tokenState_; } +int32_t WindowProperty::GetWindowPid() const +{ + return pid_; +} + +int32_t WindowProperty::GetWindowUid() const +{ + return uid_; +} + bool WindowProperty::MapMarshalling(Parcel& parcel) const { auto size = sysBarPropMap_.size(); @@ -373,7 +403,9 @@ bool WindowProperty::Marshalling(Parcel& parcel) const parcel.WriteInt32(hitOffset_.x) && parcel.WriteInt32(hitOffset_.y) && parcel.WriteUint32(animationFlag_) && parcel.WriteUint32(static_cast(windowSizeChangeReason_)) && parcel.WriteBool(tokenState_) && parcel.WriteUint32(callingWindow_) && parcel.WriteUint32(static_cast(requestedOrientation_)) && - parcel.WriteBool(turnScreenOn_) && parcel.WriteBool(keepScreenOn_); + parcel.WriteBool(turnScreenOn_) && parcel.WriteBool(keepScreenOn_) && + parcel.WriteInt32(pid_) && parcel.WriteInt32(uid_) && + parcel.WriteUint32(modeSupportInfo_); } WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel) @@ -414,6 +446,9 @@ WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel) property->SetRequestedOrientation(static_cast(parcel.ReadUint32())); property->SetTurnScreenOn(parcel.ReadBool()); property->SetKeepScreenOn(parcel.ReadBool()); + property->SetWindowPid(parcel.ReadInt32()); + property->SetWindowUid(parcel.ReadInt32()); + property->SetModeSupportInfo(parcel.ReadUint32()); return property; } @@ -448,6 +483,9 @@ void WindowProperty::CopyFrom(const sptr& property) requestedOrientation_ = property->requestedOrientation_; turnScreenOn_ = property->turnScreenOn_; keepScreenOn_ = property->keepScreenOn_; + pid_ = property->pid_; + uid_ = property->uid_; + modeSupportInfo_ = property->modeSupportInfo_; } } } diff --git a/wm/BUILD.gn b/wm/BUILD.gn index 8c63e40a..eb74ce04 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -61,12 +61,12 @@ ohos_shared_library("libwm") { public_configs = [ ":libwm_public_config" ] deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/utils:libwmutil", # vsync - "//foundation/graphic/graphic/rosen/modules/composer:libcomposer", + "//foundation/graphic/graphic_2d/rosen/modules/composer:libcomposer", ] external_deps = [ diff --git a/wm/include/input_transfer_station.h b/wm/include/input_transfer_station.h index c069a9cb..6e6b9848 100644 --- a/wm/include/input_transfer_station.h +++ b/wm/include/input_transfer_station.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_INPUT_TRANSFER_STATION -#define OHOS_INPUT_TRANSFER_STATION +#ifndef OHOS_INPUT_TRANSFER_STATION_H +#define OHOS_INPUT_TRANSFER_STATION_H #include "input_manager.h" #include "pointer_event.h" @@ -53,4 +53,4 @@ public: } // namespace OHOS -#endif // OHOS_INPUT_TRANSFER_STATION +#endif // OHOS_INPUT_TRANSFER_STATION_H diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index a707f5d4..ce62e387 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -48,7 +48,7 @@ public: virtual void ProcessPointDown(uint32_t windowId, bool isStartDrag = false); virtual void ProcessPointUp(uint32_t windowId); virtual void MinimizeAllAppWindows(DisplayId displayId); - virtual void ToggleShownStateForAllAppWindows(); + virtual WMError ToggleShownStateForAllAppWindows(); virtual WMError MaxmizeWindow(uint32_t windowId); virtual WMError SetWindowLayoutMode(WindowLayoutMode mode); virtual WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action); diff --git a/wm/include/window_agent.h b/wm/include/window_agent.h index 8bd401bd..2ba25439 100644 --- a/wm/include/window_agent.h +++ b/wm/include/window_agent.h @@ -37,6 +37,8 @@ public: void UpdateOccupiedAreaChangeInfo(const sptr& info) override; void UpdateActiveStatus(bool isActive) override; sptr GetWindowProperty() override; + void NotifyOutsidePressed() override; + void DumpInfo(const std::vector& params, std::vector& info) override; private: sptr window_; }; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 4ab1e92a..5afc42c4 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -94,6 +94,7 @@ public: virtual const std::string& GetWindowName() const override; virtual uint32_t GetWindowId() const override; virtual uint32_t GetWindowFlags() const override; + uint32_t GetModeSupportInfo() const; inline NotifyNativeWinDestroyFunc GetNativeDestroyCallback() { return notifyNativefunc_; @@ -163,7 +164,9 @@ public: virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) override; virtual void RegisterOccupiedAreaChangeListener(const sptr& listener) override; virtual void UnregisterOccupiedAreaChangeListener(const sptr& listener) override; + virtual void RegisterOutsidePressedListener(const sptr& listener) override; virtual void SetAceAbilityHandler(const sptr& handler) override; + virtual void SetModeSupportInfo(uint32_t modeSupportInfo) override; void UpdateRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason); void UpdateMode(WindowMode mode); virtual void ConsumeKeyEvent(std::shared_ptr& inputEvent) override; @@ -178,6 +181,7 @@ public: void UpdateDisplayId(DisplayId from, DisplayId to); void UpdateOccupiedAreaChangeInfo(const sptr& info); void UpdateActiveStatus(bool isActive); + void NotifyOutsidePressed(); virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed, AppExecFwk::Ability* ability) override; @@ -244,6 +248,10 @@ private: { CALL_LIFECYCLE_LISTENER(AfterInactive); } + inline void NotifyForegroundFailed() const + { + CALL_LIFECYCLE_LISTENER(ForegroundFailed); + } void DestroyFloatingWindow(); void DestroySubWindow(); void SetDefaultOption(); // for api7 @@ -286,6 +294,7 @@ private: WindowState state_ { WindowState::STATE_INITIAL }; WindowTag windowTag_; sptr aceAbilityHandler_; + sptr outsidePressListener_; std::vector> lifecycleListeners_; std::vector> windowChangeListeners_; std::vector> avoidAreaChangeListeners_; diff --git a/wm/include/window_input_channel.h b/wm/include/window_input_channel.h index 3bd1b5b1..528c779e 100644 --- a/wm/include/window_input_channel.h +++ b/wm/include/window_input_channel.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef OHOS_WINDOW_INPUT_CHANNEL -#define OHOS_WINDOW_INPUT_CHANNEL +#ifndef OHOS_WINDOW_INPUT_CHANNEL_H +#define OHOS_WINDOW_INPUT_CHANNEL_H #include #include @@ -47,4 +47,4 @@ private: } -#endif // OHOS_WINDOW_INPUT_CHANNEL +#endif // OHOS_WINDOW_INPUT_CHANNEL_H diff --git a/wm/include/zidl/window_interface.h b/wm/include/zidl/window_interface.h index 2a77a41c..e45a5534 100644 --- a/wm/include/zidl/window_interface.h +++ b/wm/include/zidl/window_interface.h @@ -39,6 +39,8 @@ public: TRANS_ID_UPDATE_OCCUPIED_AREA, TRANS_ID_UPDATE_ACTIVE_STATUS, TRANS_ID_GET_WINDOW_PROPERTY, + TRANS_ID_NOTIFY_OUTSIDE_PRESSED, + TRANS_ID_DUMP_INFO, }; virtual void UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) = 0; @@ -51,6 +53,8 @@ public: virtual void UpdateOccupiedAreaChangeInfo(const sptr& info) = 0; virtual void UpdateActiveStatus(bool isActive) = 0; virtual sptr GetWindowProperty() = 0; + virtual void NotifyOutsidePressed() = 0; + virtual void DumpInfo(const std::vector& params, std::vector& info) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/zidl/window_proxy.h b/wm/include/zidl/window_proxy.h index 285ab02c..ac0c1d3f 100644 --- a/wm/include/zidl/window_proxy.h +++ b/wm/include/zidl/window_proxy.h @@ -38,6 +38,8 @@ public: void UpdateOccupiedAreaChangeInfo(const sptr& info) override; void UpdateActiveStatus(bool isActive) override; sptr GetWindowProperty() override; + void NotifyOutsidePressed() override; + void DumpInfo(const std::vector& params, std::vector& info) override; private: static inline BrokerDelegator delegator_; }; diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 69ad5917..34947653 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -142,11 +142,11 @@ void WindowAdapter::MinimizeAllAppWindows(DisplayId displayId) windowManagerServiceProxy_->MinimizeAllAppWindows(displayId); } -void WindowAdapter::ToggleShownStateForAllAppWindows() +WMError WindowAdapter::ToggleShownStateForAllAppWindows() { - INIT_PROXY_CHECK_RETURN(); + INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); - windowManagerServiceProxy_->ToggleShownStateForAllAppWindows(); + return windowManagerServiceProxy_->ToggleShownStateForAllAppWindows(); } WMError WindowAdapter::MaxmizeWindow(uint32_t windowId) diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp index f25c9579..b524fa39 100644 --- a/wm/src/window_agent.cpp +++ b/wm/src/window_agent.cpp @@ -117,5 +117,24 @@ sptr WindowAgent::GetWindowProperty() } return window_->GetWindowProperty(); } + +void WindowAgent::NotifyOutsidePressed() +{ + if (window_ == nullptr) { + WLOGFI("window is null"); + return; + } + WLOGFI("called"); + window_->NotifyOutsidePressed(); +} + +void WindowAgent::DumpInfo(const std::vector& params, std::vector& info) +{ + if (window_ == nullptr) { + WLOGFE("window_ is nullptr"); + return; + } + window_->DumpInfo(params, info); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index ab37258d..a818b22a 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -33,6 +33,7 @@ namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowImpl"}; + const std::string PARAM_DUMP_HELP = "-h"; } const WindowImpl::ColorSpaceConvertMap WindowImpl::colorSpaceConvertMap[] = { @@ -251,6 +252,11 @@ uint32_t WindowImpl::GetWindowFlags() const return property_->GetWindowFlags(); } +uint32_t WindowImpl::GetModeSupportInfo() const +{ + return property_->GetModeSupportInfo(); +} + SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) const { auto curProperties = property_->GetSystemBarProperty(); @@ -303,12 +309,19 @@ WMError WindowImpl::SetWindowMode(WindowMode mode) if (!IsWindowValid()) { return WMError::WM_ERROR_INVALID_WINDOW; } + if (!WindowHelper::IsWindowModeSupported(GetModeSupportInfo(), mode)) { + WLOGFI("window %{public}u do not support window mode: %{public}u", + property_->GetWindowId(), static_cast(mode)); + return WMError::WM_DO_NOTHING; + } if (state_ == WindowState::STATE_CREATED || state_ == WindowState::STATE_HIDDEN) { UpdateMode(mode); } else if (state_ == WindowState::STATE_SHOWN) { + WindowMode lastMode = property_->GetWindowMode(); property_->SetWindowMode(mode); WMError ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_MODE); if (ret != WMError::WM_OK) { + property_->SetWindowMode(lastMode); return ret; } // set client window mode if success. @@ -490,7 +503,12 @@ ColorSpace WindowImpl::GetColorSpace() void WindowImpl::DumpInfo(const std::vector& params, std::vector& info) { - WLOGFI("Ace:DumpInfo"); + if (params.size() == 1 && params[0] == PARAM_DUMP_HELP) { // 1: params num + WLOGFI("Dump ArkUI help Info"); + Ace::UIContent::ShowDumpHelp(info); + return; + } + WLOGFI("ArkUI:DumpInfo"); if (uiContent_ != nullptr) { uiContent_->DumpInfo(params, info); } @@ -752,12 +770,6 @@ WMError WindowImpl::Show(uint32_t reason) return WMError::WM_ERROR_INVALID_WINDOW; } - if ((GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED)) && - WindowHelper::IsSplitWindowMode(GetMode())) { - WLOGFE("show when locked window does not support split mode, windowId: %{public}u", property_->GetWindowId()); - return WMError::WM_ERROR_INVALID_WINDOW; - } - WindowStateChangeReason stateChangeReason = static_cast(reason); if (stateChangeReason == WindowStateChangeReason::KEYGUARD || stateChangeReason == WindowStateChangeReason::TOGGLING) { @@ -790,7 +802,8 @@ WMError WindowImpl::Show(uint32_t reason) state_ = WindowState::STATE_SHOWN; NotifyAfterForeground(); } else { - WLOGFE("show errCode:%{public}d for winId:%{public}u", static_cast(ret), property_->GetWindowId()); + NotifyForegroundFailed(); + WLOGFE("show window id:%{public}u errCode:%{public}d", property_->GetWindowId(), static_cast(ret)); } return ret; } @@ -1326,6 +1339,12 @@ void WindowImpl::UnregisterOccupiedAreaChangeListener(const sptr& listener) +{ + std::lock_guard lock(mutex_); + outsidePressListener_ = listener; +} + void WindowImpl::SetAceAbilityHandler(const sptr& handler) { if (handler == nullptr) { @@ -1335,6 +1354,22 @@ void WindowImpl::SetAceAbilityHandler(const sptr& handler) aceAbilityHandler_ = handler; } +void WindowImpl::SetModeSupportInfo(uint32_t modeSupportInfo) +{ + property_->SetModeSupportInfo(modeSupportInfo); + UpdateProperty(PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO); + if (!WindowHelper::IsWindowModeSupported(modeSupportInfo, GetMode())) { + WLOGFI("currunt window mode is not supported, force to transform to appropriate mode. window id:%{public}u", + GetWindowId()); + WindowMode mode = WindowHelper::GetWindowModeFromModeSupportInfo(modeSupportInfo); + if (mode != WindowMode::WINDOW_MODE_UNDEFINED) { + SetWindowMode(mode); + } else { + WLOGFE("invalid modeSupportInfo %{public}u", modeSupportInfo); + } + } +} + void WindowImpl::UpdateRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) { auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId()); @@ -1355,8 +1390,8 @@ void WindowImpl::UpdateRect(const struct Rect& rect, bool decoStatus, WindowSize // update originRect when window show for the first time. if (!isStretchableSet_) { - originRect_ = rect; - isStretchableSet_ = true; + originRect_ = rect; + isStretchableSet_ = true; } Rect rectToAce = rect; @@ -1884,6 +1919,20 @@ void WindowImpl::UpdateActiveStatus(bool isActive) } } +void WindowImpl::NotifyOutsidePressed() +{ + sptr outsidePressListener; + { + std::lock_guard lock(mutex_); + outsidePressListener = outsidePressListener_; + } + + if (outsidePressListener != nullptr) { + WLOGFI("called"); + outsidePressListener->OnOutsidePressed(); + } +} + Rect WindowImpl::GetSystemAlarmWindowDefaultSize(Rect defaultRect) { auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId()); @@ -1957,6 +2006,10 @@ void WindowImpl::SetDefaultOption() property_->SetFocusable(false); break; } + case WindowType::WINDOW_TYPE_VOICE_INTERACTION: { + property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + break; + } default: break; } diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index a06307d9..ba19af05 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -310,10 +310,10 @@ void WindowManager::MinimizeAllAppWindows(DisplayId displayId) SingletonContainer::Get().MinimizeAllAppWindows(displayId); } -void WindowManager::ToggleShownStateForAllAppWindows() +WMError WindowManager::ToggleShownStateForAllAppWindows() { WLOGFI("ToggleShownStateForAllAppWindows"); - SingletonContainer::Get().ToggleShownStateForAllAppWindows(); + return SingletonContainer::Get().ToggleShownStateForAllAppWindows(); } WMError WindowManager::SetWindowLayoutMode(WindowLayoutMode mode) diff --git a/wm/src/zidl/window_proxy.cpp b/wm/src/zidl/window_proxy.cpp index f9cae9ef..c05ea8f6 100644 --- a/wm/src/zidl/window_proxy.cpp +++ b/wm/src/zidl/window_proxy.cpp @@ -246,6 +246,44 @@ sptr WindowProxy::GetWindowProperty() } return reply.ReadParcelable(); } + +void WindowProxy::NotifyOutsidePressed() +{ + MessageParcel data; + MessageParcel replay; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + + if (Remote()->SendRequest(static_cast(WindowMessage::TRANS_ID_NOTIFY_OUTSIDE_PRESSED), + data, replay, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } +} + +void WindowProxy::DumpInfo(const std::vector& params, std::vector& info) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + if (!data.WriteStringVector(params)) { + WLOGFE("Write params failed"); + return; + } + if (Remote()->SendRequest(static_cast(WindowMessage::TRANS_ID_DUMP_INFO), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } + if (!reply.ReadStringVector(&info)) { + WLOGFE("Read info failed"); + } +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/zidl/window_stub.cpp b/wm/src/zidl/window_stub.cpp index 893bba86..53f7c34e 100644 --- a/wm/src/zidl/window_stub.cpp +++ b/wm/src/zidl/window_stub.cpp @@ -107,6 +107,22 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce reply.WriteParcelable(property.GetRefPtr()); break; } + case WindowMessage::TRANS_ID_NOTIFY_OUTSIDE_PRESSED: { + NotifyOutsidePressed(); + break; + } + case WindowMessage::TRANS_ID_DUMP_INFO: { + std::vector params; + if (!data.ReadStringVector(¶ms)) { + WLOGFE("Fail to read params"); + } + std::vector info; + DumpInfo(params, info); + if (!reply.WriteStringVector(info)) { + WLOGFE("Fail to write info"); + } + break; + } default: break; } diff --git a/wm/test/fuzztest/windowipc_fuzzer/BUILD.gn b/wm/test/fuzztest/windowipc_fuzzer/BUILD.gn index 3c6e7665..ec509916 100644 --- a/wm/test/fuzztest/windowipc_fuzzer/BUILD.gn +++ b/wm/test/fuzztest/windowipc_fuzzer/BUILD.gn @@ -35,7 +35,7 @@ ohos_fuzztest("WindowIPCFuzzTest") { ] sources = [ "windowipc_fuzzer.cpp" ] deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/wm:libwm", ] external_deps = [ "samgr_standard:samgr_proxy" ] diff --git a/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp b/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp index 528d7bae..07d78dac 100644 --- a/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp +++ b/wm/test/fuzztest/windowipc_fuzzer/windowipc_fuzzer.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include "zidl/window_manager_proxy.h" @@ -33,8 +34,7 @@ size_t GetObject(T &object, const uint8_t *data, size_t size) if (objectSize > size) { return 0; } - std::memcpy(&object, data, objectSize); - return objectSize; + return memcpy_s(&object, objectSize, data, objectSize) == EOK ? objectSize : 0; } std::pair, sptr> GetProxy() diff --git a/wm/test/fuzztest/windowscene_fuzzer/BUILD.gn b/wm/test/fuzztest/windowscene_fuzzer/BUILD.gn index dc8b6ea2..50840542 100644 --- a/wm/test/fuzztest/windowscene_fuzzer/BUILD.gn +++ b/wm/test/fuzztest/windowscene_fuzzer/BUILD.gn @@ -25,7 +25,7 @@ ohos_fuzztest("WindowSceneFuzzTest") { "//foundation/windowmanager/wmserver/include", "//foundation/windowmanager/interfaces/innerkits/dm", "//foundation/windowmanager/interfaces/innerkits/wm", - "//foundation/graphic/graphic/interfaces/innerkits/surface", + "//foundation/graphic/graphic_2d/interfaces/innerkits/surface", "//utils/native/base/include", ] cflags = [ @@ -36,7 +36,7 @@ ohos_fuzztest("WindowSceneFuzzTest") { ] sources = [ "windowscene_fuzzer.cpp" ] deps = [ - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", diff --git a/wm/test/fuzztest/windowscene_fuzzer/windowscene_fuzzer.cpp b/wm/test/fuzztest/windowscene_fuzzer/windowscene_fuzzer.cpp index 20c7804c..c0faa60d 100644 --- a/wm/test/fuzztest/windowscene_fuzzer/windowscene_fuzzer.cpp +++ b/wm/test/fuzztest/windowscene_fuzzer/windowscene_fuzzer.cpp @@ -13,6 +13,10 @@ * limitations under the License. */ +#include "windowscene_fuzzer.h" + +#include + #include "display_manager.h" #include "window.h" #include "window_manager.h" @@ -55,8 +59,7 @@ size_t GetObject(T &object, const uint8_t *data, size_t size) if (objectSize > size) { return 0; } - std::memcpy(&object, data, objectSize); - return objectSize; + return memcpy_s(&object, objectSize, data, objectSize) == EOK ? objectSize : 0; } size_t InitWindowOption1(WindowOption &windowOption, const uint8_t *data, size_t size) diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 440942b8..297d744e 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -255,7 +255,7 @@ ohos_static_library("wm_systemtest_common") { # need delete it for abilitycontext "${aafwk_inner_api_path}/ability_manager:ability_manager", "//foundation/arkui/napi:ace_napi", - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", diff --git a/wm/test/systemtest/window_immersive_test.cpp b/wm/test/systemtest/window_immersive_test.cpp index 557ae017..39c46d72 100644 --- a/wm/test/systemtest/window_immersive_test.cpp +++ b/wm/test/systemtest/window_immersive_test.cpp @@ -517,6 +517,38 @@ HWTEST_F(WindowImmersiveTest, OnAvoidAreaChangedTest02, Function | MediumTest | window->UnregisterAvoidAreaChangeListener(thisListener); ASSERT_EQ(WMError::WM_OK, window->Hide()); } + +/** + * @tc.name: DockWindowTest01 + * @tc.desc: Add unexistavoid and remove this avoid. Test OnAvoidAreaChanged listener + * @tc.type: FUNC + */ +HWTEST_F(WindowImmersiveTest, DockWindowTest01, Function | MediumTest | Level3) +{ + const sptr& dockWindow = utils::CreateDockWindow(); + ASSERT_EQ(WMError::WM_OK, dockWindow->Show()); + + const sptr& window = utils::CreateTestWindow(fullScreenAppinfo_); + + usleep(WAIT_ASYNC_US); + auto act = testSystemBarChangedListener_->tints_; + for (SystemBarRegionTint tint : act) { + if (tint.type_ == WindowType::WINDOW_TYPE_LAUNCHER_DOCK) { + ASSERT_FALSE(tint.prop_.enable_); + } + } + + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + usleep(WAIT_ASYNC_US); + act = testSystemBarChangedListener_->tints_; + for (SystemBarRegionTint tint : act) { + if (tint.type_ == WindowType::WINDOW_TYPE_LAUNCHER_DOCK) { + ASSERT_TRUE(tint.prop_.enable_); + } + } + ASSERT_EQ(WMError::WM_OK, dockWindow->Destroy()); +} } } // namespace Rosen } // namespace OHOS diff --git a/wm/test/systemtest/window_split_test.cpp b/wm/test/systemtest/window_split_test.cpp index 2fb088b7..217de449 100644 --- a/wm/test/systemtest/window_split_test.cpp +++ b/wm/test/systemtest/window_split_test.cpp @@ -204,6 +204,61 @@ HWTEST_F(WindowSplitTest, SplitCreen04, Function | MediumTest | Level3) ASSERT_EQ(WMError::WM_OK, secWindow->Hide()); sleep(SPLIT_TEST_SLEEP_S); } + +/** + * @tc.name: SplitCreen05 + * @tc.desc: forbid dock slive to move test + * @tc.type: FUNC + */ +HWTEST_F(WindowSplitTest, SplitCreen05, Function | MediumTest | Level3) +{ + fullInfo_.name = "fullscreen.5"; + splitInfo_.name = "primary.5"; + splitInfo_.mode = WindowMode::WINDOW_MODE_SPLIT_PRIMARY; + + const sptr& fullWindow = utils::CreateTestWindow(fullInfo_); + activeWindows_.push_back(fullWindow); + ASSERT_EQ(WMError::WM_OK, fullWindow->Show()); + sleep(SPLIT_TEST_SLEEP_S); + + const sptr& priWindow = utils::CreateTestWindow(splitInfo_); + activeWindows_.push_back(priWindow); + ASSERT_EQ(WMError::WM_OK, priWindow->Show()); + sleep(SPLIT_TEST_SLEEP_S); + + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, priWindow->GetMode()); + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_SECONDARY, fullWindow->GetMode()); + + utils::TestWindowInfo dividerInfo; + dividerInfo.name = "divider0"; + dividerInfo.type = WindowType::WINDOW_TYPE_DOCK_SLICE; + dividerInfo.mode = WindowMode::WINDOW_MODE_FLOATING; + dividerInfo.focusable_ = false; + + const sptr& divider = utils::CreateTestWindow(dividerInfo); + activeWindows_.push_back(divider); + ASSERT_EQ(WMError::WM_OK, divider->Show()); + sleep(SPLIT_TEST_SLEEP_S); + + Rect lastRect = divider->GetRect(); + WMError ret = divider->MoveTo(lastRect.posX_ + 10, lastRect.posY_ + 10); + sleep(SPLIT_TEST_SLEEP_S); + Rect rect = divider->GetRect(); + ASSERT_TRUE(lastRect.posX_ != rect.posX_ || lastRect.posY_ != rect.posY_); + + ret = fullWindow->AddWindowFlag(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE); + sleep(SPLIT_TEST_SLEEP_S); + ret = divider->MoveTo(rect.posX_ + 10, rect.posY_ + 10); + sleep(SPLIT_TEST_SLEEP_S); + Rect NewRect = divider->GetRect(); + ASSERT_TRUE(rect.posX_ == NewRect.posX_ && rect.posY_ == NewRect.posY_); + + ASSERT_EQ(WMError::WM_OK, priWindow->Hide()); + sleep(SPLIT_TEST_SLEEP_S); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, fullWindow->GetMode()); + ASSERT_EQ(WMError::WM_OK, fullWindow->Hide()); + sleep(SPLIT_TEST_SLEEP_S); +} } } // namespace Rosen } // namespace OHOS diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp index 18518125..7fb00c4e 100644 --- a/wm/test/systemtest/window_test_utils.cpp +++ b/wm/test/systemtest/window_test_utils.cpp @@ -28,6 +28,7 @@ Rect WindowTestUtils::statusBarRect_ = {0, 0, 0, 0}; Rect WindowTestUtils::naviBarRect_ = {0, 0, 0, 0}; Rect WindowTestUtils::customAppRect_ = {0, 0, 0, 0}; Rect WindowTestUtils::limitDisplayRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::dockWindowRect_ = {0, 0, 0, 0}; SplitRects WindowTestUtils::splitRects_ = { .primaryRect = {0, 0, 0, 0}, .secondaryRect = {0, 0, 0, 0}, @@ -60,10 +61,29 @@ sptr WindowTestUtils::CreateTestWindow(const TestWindowInfo& info) } else { option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); } + if (info.forbidSplitMove) { + option->AddWindowFlag(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE); + } else { + option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE); + } sptr window = Window::Create(info.name, option); return window; } +sptr WindowTestUtils::CreateDockWindow() +{ + TestWindowInfo info = { + .name = "dockWindow", + .rect = dockWindowRect_, + .type = WindowType::WINDOW_TYPE_LAUNCHER_DOCK, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }; + return CreateTestWindow(info); +} + sptr WindowTestUtils::CreateStatusBarWindow() { TestWindowInfo info = { @@ -188,6 +208,7 @@ void WindowTestUtils::InitByDisplayRect(const Rect& displayRect) } statusBarRect_ = {0, 0, displayRect_.width_, displayRect_.height_ * barRatio}; naviBarRect_ = {0, displayRect_.height_ * (1 - barRatio), displayRect_.width_, displayRect_.height_ * barRatio}; + dockWindowRect_ = {0, displayRect_.height_ * (1 - barRatio), displayRect_.width_, displayRect_.height_ * barRatio}; customAppRect_ = { displayRect_.width_ * spaceRation, displayRect_.height_ * spaceRation, diff --git a/wm/test/systemtest/window_test_utils.h b/wm/test/systemtest/window_test_utils.h index de54b074..dd3cd05b 100644 --- a/wm/test/systemtest/window_test_utils.h +++ b/wm/test/systemtest/window_test_utils.h @@ -40,6 +40,7 @@ public: WindowMode mode; bool needAvoid; bool parentLimit; + bool forbidSplitMove {false}; std::string parentName; bool focusable_ { true }; Orientation orientation_ { Orientation::UNSPECIFIED }; @@ -50,6 +51,7 @@ public: static Rect naviBarRect_; static Rect customAppRect_; static Rect customAppDecoRect_; + static Rect dockWindowRect_; static SplitRects splitRects_; static bool isVerticalDisplay_; static Rect singleTileRect_; @@ -60,6 +62,7 @@ public: static sptr CreateTestWindow(const TestWindowInfo& info); static sptr CreateStatusBarWindow(); static sptr CreateNavigationBarWindow(); + static sptr CreateDockWindow(); static sptr CreateWindowScene(); static bool RectEqualTo(const sptr& window, const Rect& r); static bool InitSplitRects(); diff --git a/wm/test/systemtest/window_visibility_info_test.cpp b/wm/test/systemtest/window_visibility_info_test.cpp index 858fa8ce..ccd688d6 100644 --- a/wm/test/systemtest/window_visibility_info_test.cpp +++ b/wm/test/systemtest/window_visibility_info_test.cpp @@ -15,6 +15,13 @@ // gtest #include + +#include +#include +#include +#include + +#include "display_manager.h" #include "wm_common.h" #include "window_manager.h" #include "window_test_utils.h" @@ -29,23 +36,54 @@ namespace { } using utils = WindowTestUtils; -constexpr int WAIT_ASYNC_US = 200000; // 200ms +constexpr int WAIT_ASYNC_MS_TIME_OUT = 1500; // 1500ms + +#define CHECK_DISPLAY_POWER_STATE_RETURN() \ + do { \ + if (!displayPowerEventListener_->isDisplayPowerValid.load()) { \ + WLOGFE("isDisplayPowerValid false!"); \ + goto end; \ + } \ + } while (false) class VisibilityChangedListenerImpl : public IVisibilityChangedListener { public: + VisibilityChangedListenerImpl(std::mutex& mutex, std::condition_variable& cv) : mutex_(mutex), cv_(cv) {} void OnWindowVisibilityChanged(const std::vector>& windowVisibilityInfo) override; std::vector> windowVisibilityInfos_; + bool isCallbackCalled_ { false }; +private: + std::mutex& mutex_; + std::condition_variable& cv_; +}; + +class DisplayPowerEventListenerImpl : public IDisplayPowerEventListener { +public: + DisplayPowerEventListenerImpl() + { + auto displayId = DisplayManager::GetInstance().GetDefaultDisplayId(); + auto state = DisplayManager::GetInstance().GetDisplayState(displayId); + isDisplayPowerValid = state == DisplayState::ON; + } + void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override + { + isDisplayPowerValid.store(false); + } + std::atomic_bool isDisplayPowerValid; }; void VisibilityChangedListenerImpl::OnWindowVisibilityChanged( const std::vector>& windowVisibilityInfo) { + std::unique_lock lock(mutex_); + isCallbackCalled_ = true; WLOGFI("size:%{public}zu", windowVisibilityInfo.size()); windowVisibilityInfos_ = std::move(windowVisibilityInfo); for (auto& info : windowVisibilityInfos_) { WLOGFI("windowId:%{public}u, covered:%{public}d, pid:%{public}d, uid:%{public}d", info->windowId_, info->isVisible_, info->pid_, info->uid_); } + cv_.notify_all(); } class WindowVisibilityInfoTest : public testing::Test { @@ -58,7 +96,20 @@ public: virtual void TearDown() override; - static inline sptr visibilityChangedListener_ = new VisibilityChangedListenerImpl(); + static inline std::mutex mutex_; + static inline std::condition_variable cv_; + static inline sptr visibilityChangedListener_ = + new VisibilityChangedListenerImpl(mutex_, cv_); + static inline sptr displayPowerEventListener_ = + new DisplayPowerEventListenerImpl(); + + static inline void ResetCallbackCalledFLag() + { + std::unique_lock lock(mutex_); + visibilityChangedListener_->isCallbackCalled_ = false; + } + + static void WaitForCallback(); utils::TestWindowInfo fullScreenAppInfo_; utils::TestWindowInfo floatAppInfo_; utils::TestWindowInfo subAppInfo_; @@ -74,11 +125,13 @@ void WindowVisibilityInfoTest::SetUpTestCase() static_cast(display->GetWidth()), static_cast(display->GetHeight())}; utils::InitByDisplayRect(displayRect); WindowManager::GetInstance().RegisterVisibilityChangedListener(visibilityChangedListener_); + DisplayManager::GetInstance().RegisterDisplayPowerEventListener(displayPowerEventListener_); } void WindowVisibilityInfoTest::TearDownTestCase() { WindowManager::GetInstance().UnregisterVisibilityChangedListener(visibilityChangedListener_); + DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(displayPowerEventListener_); } void WindowVisibilityInfoTest::SetUp() @@ -116,6 +169,16 @@ void WindowVisibilityInfoTest::TearDown() { } +void WindowVisibilityInfoTest::WaitForCallback() +{ + std::unique_lock lock(mutex_); + auto now = std::chrono::system_clock::now(); + if (!cv_.wait_until(lock, now + std::chrono::milliseconds(WAIT_ASYNC_MS_TIME_OUT), + []() { return visibilityChangedListener_->isCallbackCalled_; })) { + WLOGFI("wait_until time out"); + } +} + namespace { /** * @tc.name: WindowVisibilityInfoTest01 @@ -134,33 +197,48 @@ HWTEST_F(WindowVisibilityInfoTest, WindowVisibilityInfoTest01, Function | Medium sptr subWindow1 = utils::CreateTestWindow(subAppInfo_); ASSERT_EQ(WMError::WM_OK, window1->Show()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(1, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); ASSERT_EQ(WMError::WM_OK, subWindow1->Show()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(1, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); ASSERT_EQ(WMError::WM_OK, window1->Hide()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(2, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); ASSERT_EQ(WMError::WM_OK, window1->Show()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(2, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); ASSERT_EQ(WMError::WM_OK, subWindow1->Hide()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(1, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); ASSERT_EQ(WMError::WM_OK, window1->Hide()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(1, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); ASSERT_EQ(WMError::WM_OK, window1->Show()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(1, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); +end: window1->Destroy(); subWindow1->Destroy(); } @@ -179,13 +257,18 @@ HWTEST_F(WindowVisibilityInfoTest, WindowVisibilityInfoTest02, Function | Medium sptr window2 = utils::CreateTestWindow(fullScreenAppInfo_); ASSERT_EQ(WMError::WM_OK, window1->Show()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(2, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); ASSERT_EQ(WMError::WM_OK, window2->Show()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(2, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); +end: window1->Destroy(); window2->Destroy(); } @@ -207,7 +290,6 @@ HWTEST_F(WindowVisibilityInfoTest, WindowVisibilityInfoTest03, Function | Medium sptr subWindow1 = utils::CreateTestWindow(subAppInfo_); floatAppInfo_.name = "window2"; - floatAppInfo_.rect = {50, 150, 240, 426}; sptr window2 = utils::CreateTestWindow(floatAppInfo_); subAppInfo_.name = "subWindow2"; @@ -216,21 +298,30 @@ HWTEST_F(WindowVisibilityInfoTest, WindowVisibilityInfoTest03, Function | Medium sptr subWindow2 = utils::CreateTestWindow(subAppInfo_); ASSERT_EQ(WMError::WM_OK, window2->Show()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(1, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); ASSERT_EQ(WMError::WM_OK, subWindow2->Show()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(1, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); ASSERT_EQ(WMError::WM_OK, window1->Show()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(2, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); ASSERT_EQ(WMError::WM_OK, subWindow1->Show()); - usleep(WAIT_ASYNC_US); + WaitForCallback(); + CHECK_DISPLAY_POWER_STATE_RETURN(); ASSERT_EQ(2, visibilityChangedListener_->windowVisibilityInfos_.size()); + ResetCallbackCalledFLag(); +end: window1->Destroy(); subWindow1->Destroy(); window2->Destroy(); diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 9803ab3b..bf08369b 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -178,7 +178,7 @@ ohos_static_library("wm_unittest_common") { "//foundation/arkui/ace_engine/interfaces/inner_api/ace:ace_uicontent", "//foundation/arkui/napi:ace_napi", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk", - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 61cf38b5..d751ccc8 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -12,7 +12,7 @@ # limitations under the License. import("//build/ohos.gni") -import("//foundation/graphic/graphic/graphic_config.gni") +import("//foundation/graphic/graphic_2d/graphic_config.gni") ## Build libwms.so config("libwms_config") { @@ -70,6 +70,7 @@ ohos_shared_library("libwms") { "../wm/src/zidl/window_proxy.cpp", "src/avoid_area_controller.cpp", "src/display_group_controller.cpp", + "src/display_group_info.cpp", "src/drag_controller.cpp", "src/freeze_controller.cpp", "src/input_window_monitor.cpp", @@ -92,6 +93,7 @@ ohos_shared_library("libwms") { "src/window_snapshot/snapshot_controller.cpp", "src/window_snapshot/snapshot_proxy.cpp", "src/window_snapshot/snapshot_stub.cpp", + "src/window_task_looper.cpp", "src/window_zorder_policy.cpp", "src/zidl/window_manager_stub.cpp", ] @@ -102,7 +104,7 @@ ohos_shared_library("libwms") { ":window_divider_image", ":window_manager_config", ":window_starting_image", - "//foundation/graphic/graphic/rosen/modules/render_service_client:librender_service_client", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/utils:libwmutil", diff --git a/wmserver/include/display_group_controller.h b/wmserver/include/display_group_controller.h index 7d0eac1b..63fb9a09 100644 --- a/wmserver/include/display_group_controller.h +++ b/wmserver/include/display_group_controller.h @@ -19,6 +19,7 @@ #include #include "avoid_area_controller.h" +#include "display_group_info.h" #include "display_info.h" #include "display_manager_service_inner.h" #include "window_layout_policy.h" @@ -36,25 +37,24 @@ class WindowNodeContainer; class DisplayGroupController : public RefBase { public: DisplayGroupController(const sptr& windowNodeContainer, - std::map& displayRectMap, std::map>& displayInfosMap) - : windowNodeContainer_(windowNodeContainer), displayRectMap_(displayRectMap), - displayInfosMap_(displayInfosMap) {} + const sptr& displayGroupInfo) + : windowNodeContainer_(windowNodeContainer), displayGroupInfo_(displayGroupInfo) {} ~DisplayGroupController() = default; void InitNewDisplay(DisplayId displayId); - void UpdateWindowNodeMaps(); + void UpdateDisplayGroupWindowTree(); void PreProcessWindowNode(const sptr& node, WindowUpdateType type); void ProcessDisplayCreate(DisplayId displayId, - const std::map>& displayInfoMap); + const std::map& displayRectMap); void ProcessDisplayDestroy(DisplayId displayId, - const std::map>& displayInfoMap, + const std::map& displayRectMap, std::vector& windowIds); void ProcessDisplayChange(DisplayId displayId, - const std::map>& displayInfoMap, + const std::map& displayRectMap, DisplayStateChangeType type); sptr GetWindowPairByDisplayId(DisplayId displayId); - WindowNodeMaps windowNodeMaps_; + DisplayGroupWindowTree displayGroupWindowTree_; std::map sysBarNodeMaps_; std::map sysBarTintMaps_; @@ -63,7 +63,7 @@ private: void AddWindowNodeOnWindowTree(sptr& node, WindowRootNodeType rootType); void ProcessNotCrossNodesOnDestroiedDisplay(DisplayId displayId, std::vector& windowIds); void ProcessDisplaySizeChangeOrRotation(DisplayId displayId, - const std::map>& displayInfoMap, DisplayStateChangeType type); + const std::map& displayRectMap, DisplayStateChangeType type); void ProcessCrossNodes(DisplayStateChangeType type); void MoveCrossNodeToTargetDisplay(const sptr& node, DisplayId targetDisplayId); void MoveNotCrossNodeToDefaultDisplay(const sptr& node, DisplayId displayId); @@ -73,15 +73,11 @@ private: void UpdateWindowDisplayId(const sptr& node, DisplayId newDisplayId); void ClearMapOfDestroiedDisplay(DisplayId displayId); void ChangeToRectInDisplayGroup(const sptr& node); - void FindMaxAndMinPosXDisplay(); sptr windowNodeContainer_; - std::map& displayRectMap_; - std::map>& displayInfosMap_; + sptr displayGroupInfo_; std::map> windowPairMap_; DisplayId defaultDisplayId_ { 0 }; - DisplayId maxPosXDisplay_ { 0 }; - DisplayId minPosXDisplay_ { 0 }; }; } // namespace Rosen } // namespace OHOS diff --git a/wmserver/include/display_group_info.h b/wmserver/include/display_group_info.h new file mode 100644 index 00000000..2520cf52 --- /dev/null +++ b/wmserver/include/display_group_info.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 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_DISPLAY_GROUP_INFO_H +#define OHOS_ROSEN_DISPLAY_GROUP_INFO_H + +#include +#include + +#include "display_info.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class DisplayGroupInfo : public RefBase { +public: + DisplayGroupInfo(ScreenId displayGroupId, const sptr& displayInfo); + ~DisplayGroupInfo() = default; + void AddDisplayInfo(const sptr& displayInfo); + void RemoveDisplayInfo(DisplayId displayId); + void UpdateLeftAndRightDisplayId(); + + void SetDisplayRotation(DisplayId displayId, Rotation rotation); + void SetDisplayVirtualPixelRatio(DisplayId displayId, float vpr); + void SetDisplayRect(DisplayId displayId, Rect displayRect); + + Rotation GetDisplayRotation(DisplayId displayId) const; + float GetDisplayVirtualPixelRatio(DisplayId displayId) const; + std::map GetAllDisplayRects() const; + Rect GetDisplayRect(DisplayId displayId) const; + sptr GetDisplayInfo(DisplayId displayId) const; + DisplayId GetLeftDisplayId() const; + DisplayId GetRightDisplayId() const; + +private: + ScreenId displayGroupId_; + DisplayId leftDisplayId_ { 0 }; + DisplayId rightDisplayId_ { 0 }; + mutable std::map> displayInfosMap_; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_ROSEN_DISPLAY_GROUP_INFO_H + diff --git a/wmserver/include/minimize_app.h b/wmserver/include/minimize_app.h index dda33e12..2b0c4dee 100644 --- a/wmserver/include/minimize_app.h +++ b/wmserver/include/minimize_app.h @@ -51,7 +51,7 @@ private: reason == MinimizeReason::MAX_APP_COUNT || reason == MinimizeReason::LAYOUT_TILE); } - static std::map>> needMinimizeAppNodes_; + static std::map>> needMinimizeAppNodes_; static bool isMinimizedByOtherWindow_; static std::recursive_mutex mutex_; }; diff --git a/wmserver/include/starting_window.h b/wmserver/include/starting_window.h index 6cb9c904..0fc85e83 100644 --- a/wmserver/include/starting_window.h +++ b/wmserver/include/starting_window.h @@ -32,7 +32,7 @@ public: static sptr CreateWindowNode(sptr info, uint32_t winId); static void HandleClientWindowCreate(sptr& node, sptr& window, - uint32_t& windowId, const std::shared_ptr& surfaceNode); + uint32_t& windowId, const std::shared_ptr& surfaceNode, sptr& property); static void DrawStartingWindow(sptr& node, sptr pixelMap, uint32_t bkgColor, bool isColdStart); static void UpdateRSTree(sptr& node); diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 7295c623..bb94e30b 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -49,7 +49,7 @@ public: WMError ProcessPointDown(uint32_t windowId, bool isStartDrag); WMError ProcessPointUp(uint32_t windowId); void MinimizeAllAppWindows(DisplayId displayId); - void ToggleShownStateForAllAppWindows(); + WMError ToggleShownStateForAllAppWindows(); WMError MaxmizeWindow(uint32_t windowId); WMError SetWindowLayoutMode(WindowLayoutMode mode); WMError UpdateProperty(sptr& property, PropertyChangeAction action); @@ -75,7 +75,8 @@ private: void ReSizeSystemBarPropertySizeIfNeed(sptr node); void HandleTurnScreenOn(const sptr& node); void ProcessSystemBarChange(const sptr& displayInfo); - + void NotifyOutsidePressed(const sptr& node); + uint32_t GetEmbedNodeId(const std::vector>& windowNodes, const sptr& node); sptr windowRoot_; sptr inputWindowMonitor_; std::atomic windowId_ { INVALID_WINDOW_ID }; diff --git a/wmserver/include/window_dumper.h b/wmserver/include/window_dumper.h index 39e2a93e..4c3e1315 100644 --- a/wmserver/include/window_dumper.h +++ b/wmserver/include/window_dumper.h @@ -23,22 +23,26 @@ namespace OHOS { namespace Rosen { enum DumpType : uint32_t { DUMP_ALL = 0, - + DUMP_WINDOW, DUMP_NONE = 100, }; class WindowDumper : public RefBase { public: - WindowDumper(const sptr& root, std::recursive_mutex& mutex) : windowRoot_(root), mutex_(mutex) {} + WindowDumper(const sptr& root) : windowRoot_(root) {} WMError Dump(int fd, const std::vector& args) const; private: WMError DumpWindowInfo(const std::vector& args, std::string& dumpInfo) const; WMError DumpAllWindowInfo(std::string& dumpInfo) const; - WMError DumpDisplayWindowInfo(DisplayId displayId, std::string& dumpInfo) const; + WMError DumpScreenGroupWindowInfo(ScreenId screenGroupId, const sptr& windowNodeContainer, + std::string& dumpInfo) const; + bool IsValidDigitString(const std::string& windowIdStr) const; + WMError DumpSpecifiedWindowInfo(uint32_t windowId, const std::vector& params, + std::string& dumpInfo) const; void ShowHelpInfo(std::string& dumpInfo) const; - void ShowIllegalArgsInfo(std::string& dumpInfo) const; + void ShowAceDumpHelp(std::string& dumpInfo) const; + void ShowIllegalArgsInfo(std::string& dumpInfo, WMError errCode) const; const sptr windowRoot_; - std::recursive_mutex& mutex_; }; } } diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index 45d5b84a..3cb0470e 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -20,6 +20,7 @@ #include #include +#include "display_group_info.h" #include "display_info.h" #include "window_node.h" #include "wm_common.h" @@ -27,13 +28,19 @@ namespace OHOS { namespace Rosen { -using WindowNodeMaps = std::map>>>>; +enum class DockWindowShowState : uint32_t { + NOT_SHOWN = 0, + SHOWN_IN_BOTTOM = 1, + SHOWN_IN_LEFT = 2, + SHOWN_IN_RIGHT = 3, + SHOWN_IN_TOP = 4, +}; class WindowLayoutPolicy : public RefBase { public: WindowLayoutPolicy() = delete; - WindowLayoutPolicy(const std::map& displayRectMap, WindowNodeMaps& windowNodeMaps, - std::map>& displayInfosMap); + WindowLayoutPolicy(const sptr& displayGroupInfo, DisplayGroupWindowTree& displayGroupWindowTree); ~WindowLayoutPolicy() = default; virtual void Launch(); virtual void Clean(); @@ -44,6 +51,7 @@ public: virtual void RemoveWindowNode(const sptr& node); virtual void UpdateWindowNode(const sptr& node, bool isAddWindow = false); virtual void UpdateLayoutRect(const sptr& node) = 0; + virtual void SetSplitDividerWindowRects(std::map dividerWindowRects) {}; float GetVirtualPixelRatio(DisplayId displayId) const; void UpdateClientRectAndResetReason(const sptr& node, const Rect& lastLayoutRect, const Rect& winRect); Rect GetDisplayGroupRect() const; @@ -59,6 +67,7 @@ protected: AvoidPosType GetAvoidPosType(const Rect& rect, DisplayId displayId) const; void CalcAndSetNodeHotZone(Rect layoutOutRect, const sptr& node) const; void LimitFloatingWindowSize(const sptr& node, const Rect& displayRect, Rect& winRect) const; + void LimitMainFloatingWindowPositionWithDrag(const sptr& node, Rect& winRect) const; void LimitMainFloatingWindowPosition(const sptr& node, Rect& winRect) const; void ComputeDecoratedRequestRect(const sptr& node) const; bool IsVerticalDisplay(DisplayId displayId) const; @@ -66,25 +75,26 @@ protected: void LayoutWindowNodesByRootType(const std::vector>& nodeVec); void UpdateSurfaceBounds(const sptr& node, const Rect& winRect); void UpdateRectInDisplayGroupForAllNodes(DisplayId displayId, - const Rect& srcDisplayRect, - const Rect& dstDisplayRect); + const Rect& oriDisplayRect, + const Rect& newDisplayRect); void UpdateRectInDisplayGroup(const sptr& node, - const Rect& srcDisplayRect, - const Rect& dstDisplayRect); + const Rect& oriDisplayRect, + const Rect& newDisplayRect); void LimitWindowToBottomRightCorner(const sptr& node); void UpdateDisplayGroupRect(); void UpdateDisplayGroupLimitRect_(); void UpdateMultiDisplayFlag(); void PostProcessWhenDisplayChange(); + void UpdateDisplayRectAndDisplayGroupInfo(const std::map& displayRectMap); + DockWindowShowState GetDockWindowShowState(DisplayId displayId, Rect& dockWinRect) const; const std::set avoidTypes_ { WindowType::WINDOW_TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR, }; - mutable std::map displayRectMap_; + sptr displayGroupInfo_; mutable std::map limitRectMap_; - WindowNodeMaps& windowNodeMaps_; - std::map>& displayInfosMap_; + DisplayGroupWindowTree& displayGroupWindowTree_; Rect displayGroupRect_; Rect displayGroupLimitRect_; bool isMultiDisplay_ = false; diff --git a/wmserver/include/window_layout_policy_cascade.h b/wmserver/include/window_layout_policy_cascade.h index 8ce346c0..858e307e 100644 --- a/wmserver/include/window_layout_policy_cascade.h +++ b/wmserver/include/window_layout_policy_cascade.h @@ -29,8 +29,8 @@ namespace Rosen { class WindowLayoutPolicyCascade : public WindowLayoutPolicy { public: WindowLayoutPolicyCascade() = delete; - WindowLayoutPolicyCascade(const std::map& displayRectMap, - WindowNodeMaps& windowNodeMaps, std::map>& displayInfosMap); + WindowLayoutPolicyCascade(const sptr& displayGroupInfo, + DisplayGroupWindowTree& displayGroupWindowTree); ~WindowLayoutPolicyCascade() = default; void Launch() override; void Clean() override; @@ -39,6 +39,7 @@ public: void AddWindowNode(const sptr& node) override; void UpdateWindowNode(const sptr& node, bool isAddWindow = false) override; void UpdateLayoutRect(const sptr& node) override; + void SetSplitDividerWindowRects(std::map dividerWindowRects) override; void RemoveWindowNode(const sptr& node) override; private: @@ -70,6 +71,7 @@ private: Rect firstCascadeRect_; }; mutable std::map cascadeRectsMap_; + std::map restoringDividerWindowRects_; }; } } diff --git a/wmserver/include/window_layout_policy_tile.h b/wmserver/include/window_layout_policy_tile.h index 4895a28a..4136f544 100644 --- a/wmserver/include/window_layout_policy_tile.h +++ b/wmserver/include/window_layout_policy_tile.h @@ -30,8 +30,8 @@ namespace Rosen { class WindowLayoutPolicyTile : public WindowLayoutPolicy { public: WindowLayoutPolicyTile() = delete; - WindowLayoutPolicyTile(const std::map& displayRectMap, WindowNodeMaps& windowNodeMaps, - std::map>& displayInfosMap); + WindowLayoutPolicyTile(const sptr& displayGroupInfo, + DisplayGroupWindowTree& displayGroupWindowTree); ~WindowLayoutPolicyTile() = default; void Launch() override; void AddWindowNode(const sptr& node) override; diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index f00a88ce..577cdc37 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -32,6 +32,7 @@ #include "zidl/window_manager_stub.h" #include "window_dumper.h" #include "window_root.h" +#include "window_task_looper.h" #include "snapshot_controller.h" namespace OHOS { @@ -78,7 +79,7 @@ public: void ProcessPointUp(uint32_t windowId) override; WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override; void MinimizeAllAppWindows(DisplayId displayId) override; - void ToggleShownStateForAllAppWindows() override; + WMError ToggleShownStateForAllAppWindows() override; WMError MaxmizeWindow(uint32_t windowId) override; WMError SetWindowLayoutMode(WindowLayoutMode mode) override; WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action) override; @@ -103,13 +104,12 @@ private: bool Init(); void RegisterSnapshotHandler(); void RegisterWindowManagerServiceHandler(); - void OnWindowEvent(Event event, uint32_t windowId); + void OnWindowEvent(Event event, const sptr& remoteObject); void NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type); WMError GetFocusWindowInfo(sptr& abilityToken); void ConfigureWindowManagerService(); static inline SingletonDelegator delegator; - std::recursive_mutex mutex_; sptr windowRoot_; sptr windowController_; sptr inputWindowMonitor_; @@ -120,6 +120,8 @@ private: sptr windowDumper_; SystemConfig systemConfig_; ModeChangeHotZonesConfig hotZonesConfig_ { false, 0, 0, 0 }; + std::unique_ptr wmsTaskLooper_; + bool startingOpen_ = true; }; } } diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index e33a692d..e6f6809f 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -31,20 +31,14 @@ public: std::shared_ptr surfaceNode) : surfaceNode_(surfaceNode), property_(property), windowToken_(window) { - callingPid_ = IPCSkeleton::GetCallingPid(); - callingUid_ = IPCSkeleton::GetCallingUid(); } WindowNode() : property_(new WindowProperty()) { - callingPid_ = IPCSkeleton::GetCallingPid(); - callingUid_ = IPCSkeleton::GetCallingUid(); } explicit WindowNode(const sptr& property) : property_(property) { - callingPid_ = IPCSkeleton::GetCallingPid(); - callingUid_ = IPCSkeleton::GetCallingUid(); } - ~WindowNode() = default; + ~WindowNode(); void SetDisplayId(DisplayId displayId); void SetHotZoneRect(const Rect& rect); @@ -62,13 +56,14 @@ public: void SetTurnScreenOn(bool turnScreenOn); void SetKeepScreenOn(bool keepScreenOn); void SetCallingWindow(uint32_t windowId); - void SetCallingPid(); - void SetCallingUid(); + void SetCallingPid(int32_t pid); + void SetCallingUid(int32_t uid); void SetWindowToken(sptr window); uint32_t GetCallingWindow() const; void SetWindowSizeChangeReason(WindowSizeChangeReason reason); void SetRequestedOrientation(Orientation orientation); void SetShowingDisplays(const std::vector& displayIdVec); + void SetModeSupportInfo(uint32_t modeSupportInfo); const sptr& GetWindowToken() const; uint32_t GetWindowId() const; uint32_t GetParentId() const; @@ -94,6 +89,7 @@ public: WindowSizeChangeReason GetWindowSizeChangeReason() const; Orientation GetRequestedOrientation() const; std::vector GetShowingDisplays() const; + uint32_t GetModeSupportInfo() const; void ResetWindowSizeChangeReason(); sptr parent_; @@ -117,8 +113,6 @@ private: sptr property_ = nullptr; sptr windowToken_ = nullptr; Rect hotZoneRect_ { 0, 0, 0, 0 }; - int32_t callingPid_; - int32_t callingUid_; WindowSizeChangeReason windowSizeChangeReason_ {WindowSizeChangeReason::UNDEFINED}; }; } // Rosen diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 6399c53f..26cc2dca 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -21,6 +21,7 @@ #include "display_info.h" #include "minimize_app.h" #include "display_group_controller.h" +#include "display_group_info.h" #include "window_layout_policy.h" #include "window_manager.h" #include "window_node.h" @@ -34,11 +35,12 @@ namespace Rosen { using WindowNodeOperationFunc = std::function)>; // return true indicates to stop traverse class WindowNodeContainer : public RefBase { public: - WindowNodeContainer(const sptr& displayInfo); + WindowNodeContainer(const sptr& displayInfo, ScreenId displayGroupId); ~WindowNodeContainer(); WMError ShowStartingWindow(sptr& node); WMError AddWindowNode(sptr& node, sptr& parentNode); WMError RemoveWindowNode(sptr& node); + WMError HandleRemoveWindow(sptr& node); WMError UpdateWindowNode(sptr& node, WindowUpdateReason reason); WMError DestroyWindowNode(sptr& node, std::vector& windowIds); const std::vector& Destroy(); @@ -62,6 +64,7 @@ public: std::unordered_map GetExpectImmersiveProperty() const; void NotifyAccessibilityWindowInfo(const sptr& windowId, WindowUpdateType type) const; int GetWindowCountByType(WindowType windowType); + bool IsForbidDockSliceMove(DisplayId displayId) const; void OnAvoidAreaChange(const std::vector& avoidAreas, DisplayId displayId); bool isVerticalDisplay(DisplayId displayId) const; @@ -70,7 +73,8 @@ public: sptr GetNextActiveWindow(uint32_t windowId) const; void MinimizeAllAppWindows(DisplayId displayId); void MinimizeOldestAppWindow(); - void ToggleShownStateForAllAppWindows(std::function restoreFunc, bool restore); + void ToggleShownStateForAllAppWindows(std::function restoreFunc, bool restore); + void RestoreAllAppWindows(std::function restoreFunc); bool IsAppWindowsEmpty() const; void ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason); void NotifySystemBarTints(std::vector displayIdVec); @@ -98,6 +102,7 @@ public: sptr GetAvoidController() const; sptr GetMutiDisplayController() const; sptr GetRootNode(WindowRootNodeType type) const; + void NotifyDockWindowStateChanged(sptr& node, bool isEnable); private: void TraverseWindowNode(sptr& root, std::vector>& windowNodes) const; @@ -129,8 +134,9 @@ private: static bool ReadIsWindowAnimationEnabledProperty(); void DumpScreenWindowTree(); void RaiseInputMethodWindowPriorityIfNeeded(const sptr& node) const; + void ReZOrderShowWhenLockedWindowIfNeeded(const sptr& node); void RaiseShowWhenLockedWindowIfNeeded(const sptr& node); - void ReZOrderShowWhenLockedWindows(const sptr& node, bool up); + void ReZOrderShowWhenLockedWindows(bool up); WMError AddWindowNodeOnWindowTree(sptr& node, const sptr& parentNode); void RemoveWindowNodeFromWindowTree(sptr& node); @@ -143,8 +149,11 @@ private: uint32_t zOrder_ { 0 }; uint32_t focusedWindow_ { INVALID_WINDOW_ID }; uint32_t activeWindow_ = INVALID_WINDOW_ID; + bool isScreenLocked_ = false; std::vector backupWindowIds_; + std::map backupWindowMode_; + std::map backupDividerWindowRect_; sptr zorderPolicy_ = new WindowZorderPolicy(); std::unordered_map> layoutPolicys_; WindowLayoutMode layoutMode_ = WindowLayoutMode::CASCADE; @@ -157,9 +166,7 @@ private: sptr layoutPolicy_; sptr avoidController_; sptr displayGroupController_; - - std::map displayRectMap_; - std::map> displayInfosMap_; + sptr displayGroupInfo_; }; } // namespace Rosen } // namespace OHOS diff --git a/wmserver/include/window_pair.h b/wmserver/include/window_pair.h index 19ce011f..336c6c99 100644 --- a/wmserver/include/window_pair.h +++ b/wmserver/include/window_pair.h @@ -54,7 +54,7 @@ public: * @param displayId the disply of window pair * @param appNode the window root of app window */ - WindowPair(const DisplayId& displayId, WindowNodeMaps& windowNodeMaps); + WindowPair(const DisplayId& displayId, DisplayGroupWindowTree& displayGroupWindowTree); /** * Deconstructor used to deconstruct. @@ -153,6 +153,20 @@ public: */ std::vector> GetPairedWindows(); + /** + * Get whether dock slice is forbidden to move. + * + * @return whether dock slice is forbidden to move + */ + bool IsForbidDockSliceMove() const; + + /** + * Set all app windows are restoring. + * + * @param ratio Indicates whether all app windows are restoring. + */ + void SetAllAppWindowsRestoring(bool isAllAppWindowsRestoring); + private: /** * Gets whether the window is related to split window. @@ -232,7 +246,8 @@ private: sptr secondary_; sptr divider_; WindowPairStatus status_ = {WindowPairStatus::STATUS_EMPTY}; - WindowNodeMaps& windowNodeMaps_; + DisplayGroupWindowTree& displayGroupWindowTree_; + bool isAllAppWindowsRestoring_ { false }; }; } // namespace Rosen } // namespace OHOS diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 44414fca..a0f532d8 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -30,10 +30,10 @@ enum class Event : uint32_t { }; class WindowRoot : public RefBase { -using Callback = std::function; +using Callback = std::function& remoteObject)>; public: - WindowRoot(std::recursive_mutex& mutex, Callback callback) : mutex_(mutex), callback_(callback) {} + explicit WindowRoot(Callback callback) : callback_(callback) {} ~WindowRoot() = default; sptr GetOrCreateWindowNodeContainer(DisplayId displayId); @@ -48,6 +48,7 @@ public: WMError DestroyWindow(uint32_t windowId, bool onlySelf); WMError UpdateWindowNode(uint32_t windowId, WindowUpdateReason reason); bool isVerticalDisplay(sptr& node) const; + bool IsForbidDockSliceMove(DisplayId displayId) const; WMError RequestFocus(uint32_t windowId); WMError RequestActiveWindow(uint32_t windowId); @@ -80,7 +81,9 @@ public: WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config); std::vector GetAllDisplayIds() const; - std::map> GetWindowNodeMap(); + uint32_t GetTotalWindowNum() const; + uint32_t GetWindowIdByObject(const sptr& remoteObject); + sptr GetWindowForDumpAceHelpInfo() const; private: void OnRemoteDied(const sptr& remoteObject); WMError DestroyWindowInner(sptr& node); @@ -96,9 +99,11 @@ private: ScreenId GetScreenGroupId(DisplayId displayId, bool& isRecordedDisplay); void ProcessExpandDisplayCreate(DisplayId displayId, ScreenId screenGroupId); std::map> GetAllDisplayInfos(const std::vector& displayIdVec); + std::map GetAllDisplayRects(const std::vector& displayIdVec); void MoveNotShowingWindowToDefaultDisplay(DisplayId displayId); - - std::recursive_mutex& mutex_; + void DestroyLeakStartingWindow(); + WMError PostProcessAddWindowNode(sptr& node, sptr& parentNode, + sptr& container); std::map> windowNodeMap_; std::map, uint32_t> windowIdMap_; std::map> windowNodeContainerMap_; diff --git a/wmserver/include/window_task_looper.h b/wmserver/include/window_task_looper.h new file mode 100644 index 00000000..9a85f948 --- /dev/null +++ b/wmserver/include/window_task_looper.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022 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_TASK_LOOPER_H +#define OHOS_ROSEN_WINDOW_TASK_LOOPER_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace OHOS { +namespace Rosen { +template +class ScheduledTask : public RefBase { +public: + static auto Create(SyncTask&& task) + { + sptr> t(new ScheduledTask(std::forward(task))); + return std::make_pair(t, t->task_.get_future()); + } + + void Run() + { + task_(); + } + +private: + explicit ScheduledTask(SyncTask&& task) : task_(std::move(task)) {} + ~ScheduledTask() {} + + using Return = std::invoke_result_t; + std::packaged_task task_; +}; + +class WindowTaskLooper { +public: + using Task = std::function; + WindowTaskLooper() = default; + ~WindowTaskLooper(); + + template> + std::future ScheduleTask(SyncTask&& task) + { + auto [scheduledTask, taskFuture] = ScheduledTask::Create(std::forward(task)); + PostTask([t(std::move(scheduledTask))]() { t->Run(); }); + return std::move(taskFuture); + } + void PostTask(const Task& task); + void WakeUp(); + void Start() noexcept; + bool IsRunning(); + +private: + void WaitTask(); + void TaskProcessThread(); + void ExecuteAllTask(); + +private: + mutable std::mutex mtx_; + bool wakeUp_ = false; + std::condition_variable taskCond_; + mutable std::atomic running_ { false }; + std::vector taskQ_; + std::unique_ptr taskProcessThread_; +}; +} // namespace Rosen +} // namespace OHOS +#endif \ No newline at end of file diff --git a/wmserver/include/window_zorder_policy.h b/wmserver/include/window_zorder_policy.h index 2b218aea..af41d1e8 100644 --- a/wmserver/include/window_zorder_policy.h +++ b/wmserver/include/window_zorder_policy.h @@ -59,10 +59,11 @@ private: { WindowType::WINDOW_TYPE_NAVIGATION_BAR, 113 }, { WindowType::WINDOW_TYPE_KEYGUARD, 114 }, // reserve 115 for app window above keyguard, 116 for input method window above keyguard - { WindowType::WINDOW_TYPE_DRAGGING_EFFECT, 117 }, - { WindowType::WINDOW_TYPE_POINTER, 118 }, - { WindowType::WINDOW_TYPE_BOOT_ANIMATION, 119 }, - { WindowType::WINDOW_TYPE_FREEZE_DISPLAY, 120 }, + { WindowType::WINDOW_TYPE_VOICE_INTERACTION, 117 }, + { WindowType::WINDOW_TYPE_DRAGGING_EFFECT, 118 }, + { WindowType::WINDOW_TYPE_POINTER, 119 }, + { WindowType::WINDOW_TYPE_BOOT_ANIMATION, 120 }, + { WindowType::WINDOW_TYPE_FREEZE_DISPLAY, 121 }, }; }; } diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index ae128ee4..4500eca1 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -73,7 +73,7 @@ public: virtual void ProcessPointDown(uint32_t windowId, bool isStartDrag) = 0; virtual void ProcessPointUp(uint32_t windowId) = 0; virtual void MinimizeAllAppWindows(DisplayId displayId) = 0; - virtual void ToggleShownStateForAllAppWindows() = 0; + virtual WMError ToggleShownStateForAllAppWindows() = 0; virtual WMError MaxmizeWindow(uint32_t windowId) = 0; virtual WMError SetWindowLayoutMode(WindowLayoutMode mode) = 0; virtual WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action) = 0; diff --git a/wmserver/include/zidl/window_manager_proxy.h b/wmserver/include/zidl/window_manager_proxy.h index 407dfd58..27e4ddc7 100644 --- a/wmserver/include/zidl/window_manager_proxy.h +++ b/wmserver/include/zidl/window_manager_proxy.h @@ -42,7 +42,7 @@ public: void ProcessPointDown(uint32_t windowId, bool isStartDrag) override; void ProcessPointUp(uint32_t windowId) override; void MinimizeAllAppWindows(DisplayId displayId) override; - void ToggleShownStateForAllAppWindows() override; + WMError ToggleShownStateForAllAppWindows() override; WMError MaxmizeWindow(uint32_t windowId) override; WMError SetWindowLayoutMode(WindowLayoutMode mode) override; WMError UpdateProperty(sptr& windowProperty, PropertyChangeAction action) override; diff --git a/wmserver/src/display_group_controller.cpp b/wmserver/src/display_group_controller.cpp index 37a03290..6e21e883 100644 --- a/wmserver/src/display_group_controller.cpp +++ b/wmserver/src/display_group_controller.cpp @@ -39,27 +39,27 @@ void DisplayGroupController::InitNewDisplay(DisplayId displayId) sysBarTintMaps_.insert(std::make_pair(displayId, sysBarTintMap)); // window node maps for display - std::map>>> windowRootNodeMap; - windowRootNodeMap.insert(std::make_pair(WindowRootNodeType::APP_WINDOW_NODE, + std::map>>> displayWindowTree; + displayWindowTree.insert(std::make_pair(WindowRootNodeType::APP_WINDOW_NODE, std::make_unique>>())); - windowRootNodeMap.insert(std::make_pair(WindowRootNodeType::ABOVE_WINDOW_NODE, + displayWindowTree.insert(std::make_pair(WindowRootNodeType::ABOVE_WINDOW_NODE, std::make_unique>>())); - windowRootNodeMap.insert(std::make_pair(WindowRootNodeType::BELOW_WINDOW_NODE, + displayWindowTree.insert(std::make_pair(WindowRootNodeType::BELOW_WINDOW_NODE, std::make_unique>>())); - windowNodeMaps_.insert(std::make_pair(displayId, std::move(windowRootNodeMap))); + displayGroupWindowTree_.insert(std::make_pair(displayId, std::move(displayWindowTree))); // window pair for display - auto windowPair = new WindowPair(displayId, windowNodeMaps_); + auto windowPair = new WindowPair(displayId, displayGroupWindowTree_); windowPairMap_.insert(std::make_pair(displayId, windowPair)); } std::vector>* DisplayGroupController::GetWindowNodesByDisplayIdAndRootType(DisplayId displayId, WindowRootNodeType type) { - if (windowNodeMaps_.find(displayId) != windowNodeMaps_.end()) { - auto& rootNodemap = windowNodeMaps_[displayId]; - if (rootNodemap.find(type) != rootNodemap.end()) { - return rootNodemap[type].get(); + if (displayGroupWindowTree_.find(displayId) != displayGroupWindowTree_.end()) { + auto& displayWindowTree = displayGroupWindowTree_[displayId]; + if (displayWindowTree.find(type) != displayWindowTree.end()) { + return displayWindowTree[type].get(); } } return nullptr; @@ -79,10 +79,10 @@ void DisplayGroupController::AddWindowNodeOnWindowTree(sptr& node, W } } -void DisplayGroupController::UpdateWindowNodeMaps() +void DisplayGroupController::UpdateDisplayGroupWindowTree() { - // clear ori windowNodeMaps - for (auto& elem : windowNodeMaps_) { + // clear ori window tree of displayGroup + for (auto& elem : displayGroupWindowTree_) { for (auto& nodeVec : elem.second) { auto emptyVector = std::vector>(); nodeVec.second->swap(emptyVector); @@ -108,7 +108,7 @@ void DisplayGroupController::UpdateWindowNodeMaps() void DisplayGroupController::ProcessCrossNodes(DisplayStateChangeType type) { defaultDisplayId_ = DisplayManagerServiceInner::GetInstance().GetDefaultDisplayId(); - for (auto& iter : windowNodeMaps_) { + for (auto& iter : displayGroupWindowTree_) { auto& nodeVec = *(iter.second[WindowRootNodeType::APP_WINDOW_NODE]); for (auto& node : nodeVec) { if (node->isShowingOnMultiDisplays_) { @@ -136,28 +136,13 @@ void DisplayGroupController::ProcessCrossNodes(DisplayStateChangeType type) } } -void DisplayGroupController::FindMaxAndMinPosXDisplay() -{ - minPosXDisplay_ = displayRectMap_.begin()->first; - maxPosXDisplay_ = displayRectMap_.begin()->first; - for (auto& elem : displayRectMap_) { - auto& curDisplayRect = elem.second; - if (curDisplayRect.posX_ < displayRectMap_[minPosXDisplay_].posX_) { - minPosXDisplay_ = elem.first; - } - if ((curDisplayRect.posX_ + static_cast(curDisplayRect.width_)) > - (displayRectMap_[maxPosXDisplay_].posX_ + static_cast(displayRectMap_[maxPosXDisplay_].width_))) { - maxPosXDisplay_ = elem.first; - } - } - WLOGFI("max posX displayId: %{public}" PRIu64", min posX displayId: %{public}" PRIu64"", - maxPosXDisplay_, minPosXDisplay_); -} - void DisplayGroupController::UpdateWindowShowingDisplays(const sptr& node, const Rect& requestRect) { + auto leftDisplayId = displayGroupInfo_->GetLeftDisplayId(); + auto rightDisplayId = displayGroupInfo_->GetRightDisplayId(); + auto displayRectMap = displayGroupInfo_->GetAllDisplayRects(); auto showingDisplays = std::vector(); - for (auto& elem : displayRectMap_) { + for (auto& elem : displayRectMap) { auto& curDisplayRect = elem.second; // if window is showing in display region @@ -170,12 +155,12 @@ void DisplayGroupController::UpdateWindowShowingDisplays(const sptr& // if window is not showing on any display, maybe in the left of minPosX display, or the right of maxPosX display if (showingDisplays.empty()) { if (((requestRect.posX_ + static_cast(requestRect.width_)) <= - displayRectMap_[minPosXDisplay_].posX_)) { - showingDisplays.push_back(minPosXDisplay_); + displayRectMap[leftDisplayId].posX_)) { + showingDisplays.push_back(leftDisplayId); } if (requestRect.posX_ >= - (displayRectMap_[maxPosXDisplay_].posX_ + static_cast(displayRectMap_[maxPosXDisplay_].width_))) { - showingDisplays.push_back(maxPosXDisplay_); + (displayRectMap[rightDisplayId].posX_ + static_cast(displayRectMap[rightDisplayId].width_))) { + showingDisplays.push_back(rightDisplayId); } } @@ -197,7 +182,8 @@ void DisplayGroupController::UpdateWindowDisplayIdIfNeeded(const sptrGetRequestRect(); int32_t halfWidth = static_cast(requestRect.width_ * 0.5); - for (auto& elem : displayRectMap_) { + const auto& displayRectMap = displayGroupInfo_->GetAllDisplayRects(); + for (auto& elem : displayRectMap) { auto& displayRect = elem.second; if ((requestRect.posX_ < displayRect.posX_) && (requestRect.posX_ + static_cast(requestRect.width_) > @@ -227,7 +213,7 @@ void DisplayGroupController::UpdateWindowDisplayIdIfNeeded(const sptr& node) { Rect requestRect = node->GetRequestRect(); - const Rect& displayRect = displayRectMap_[node->GetDisplayId()]; + const Rect& displayRect = displayGroupInfo_->GetDisplayRect(node->GetDisplayId()); requestRect.posX_ += displayRect.posX_; requestRect.posY_ += displayRect.posY_; node->SetRequestRect(requestRect); @@ -311,8 +297,8 @@ void DisplayGroupController::MoveNotCrossNodeToDefaultDisplay(const sptrGetWindowId(), displayId); // update new rect in display group - Rect srcDisplayRect = displayRectMap_[displayId]; - Rect dstDisplayRect = displayRectMap_[defaultDisplayId_]; + const Rect& srcDisplayRect = displayGroupInfo_->GetDisplayRect(displayId); + const Rect& dstDisplayRect = displayGroupInfo_->GetDisplayRect(defaultDisplayId_); Rect newRect = node->GetRequestRect(); newRect.posX_ = newRect.posX_ - srcDisplayRect.posX_ + dstDisplayRect.posX_; newRect.posY_ = newRect.posY_ - srcDisplayRect.posY_ + dstDisplayRect.posY_; @@ -342,7 +328,7 @@ void DisplayGroupController::ProcessNotCrossNodesOnDestroiedDisplay(DisplayId di WindowRootNodeType::BELOW_WINDOW_NODE }; for (size_t index = 0; index < rootNodeType.size(); ++index) { - auto& nodesVec = *(windowNodeMaps_[displayId][rootNodeType[index]]); + auto& nodesVec = *(displayGroupWindowTree_[displayId][rootNodeType[index]]); for (auto& node : nodesVec) { if (node->GetDisplayId() != displayId || node->isShowingOnMultiDisplays_) { continue; @@ -366,106 +352,60 @@ void DisplayGroupController::ProcessNotCrossNodesOnDestroiedDisplay(DisplayId di } void DisplayGroupController::ProcessDisplayCreate(DisplayId displayId, - const std::map>& displayInfoMap) + const std::map& displayRectMap) { - if (displayInfosMap_.find(displayId) != displayInfosMap_.end() || - displayInfoMap.size() != (displayInfosMap_.size() + 1)) { - WLOGFE("current display is exited or displayInfo map size is error, displayId: %{public}" PRIu64"", displayId); - return; - } - defaultDisplayId_ = DisplayManagerServiceInner::GetInstance().GetDefaultDisplayId(); WLOGFI("defaultDisplay, displayId: %{public}" PRIu64"", defaultDisplayId_); windowNodeContainer_->GetAvoidController()->UpdateAvoidNodesMap(displayId, true); InitNewDisplay(displayId); - // window pair for split window - auto windowPair = new WindowPair(displayId, windowNodeMaps_); + // add displayInfo in displayGroupInfo + auto displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); + displayGroupInfo_->AddDisplayInfo(displayInfo); + + // create new window pair for split window + auto windowPair = new WindowPair(displayId, displayGroupWindowTree_); windowPairMap_.insert(std::make_pair(displayId, windowPair)); - // modify RSTree and windowNodeMaps for cross-display nodes + // modify RSTree and window tree of displayGroup for cross-display nodes ProcessCrossNodes(DisplayStateChangeType::CREATE); - UpdateWindowNodeMaps(); - - for (auto& elem : displayInfoMap) { - auto iter = displayInfosMap_.find(elem.first); - const auto& displayInfo = elem.second; - Rect displayRect = { displayInfo->GetOffsetX(), displayInfo->GetOffsetY(), - displayInfo->GetWidth(), displayInfo->GetHeight() }; - if (iter != displayInfosMap_.end()) { - displayRectMap_[elem.first] = displayRect; - displayInfosMap_[elem.first] = displayInfo; - } else { - displayRectMap_.insert(std::make_pair(elem.first, displayRect)); - displayInfosMap_.insert(std::make_pair(elem.first, displayInfo)); - } - WLOGFI("displayId: %{public}" PRIu64", displayRect: [ %{public}d, %{public}d, %{public}d, %{public}d]", - elem.first, displayRect.posX_, displayRect.posY_, displayRect.width_, displayRect.height_); - } - FindMaxAndMinPosXDisplay(); - windowNodeContainer_->GetLayoutPolicy()->ProcessDisplayCreate(displayId, displayRectMap_); + UpdateDisplayGroupWindowTree(); + windowNodeContainer_->GetLayoutPolicy()->ProcessDisplayCreate(displayId, displayRectMap); } void DisplayGroupController::ProcessDisplayDestroy(DisplayId displayId, - const std::map>& displayInfoMap, + const std::map& displayRectMap, std::vector& windowIds) { - if (displayInfosMap_.find(displayId) == displayInfosMap_.end() || - (displayInfoMap.size() + 1) != displayInfosMap_.size()) { - WLOGFE("can not find current display or displayInfo map size is error, displayId: %{public}" PRIu64"", - displayId); - return; - } - windowNodeContainer_->GetAvoidController()->UpdateAvoidNodesMap(displayId, false); // delete nodes and map element of deleted display ProcessNotCrossNodesOnDestroiedDisplay(displayId, windowIds); - // modify RSTree and windowNodeMaps for cross-display nodes + // modify RSTree and window tree of displayGroup for cross-display nodes ProcessCrossNodes(DisplayStateChangeType::DESTROY); - UpdateWindowNodeMaps(); + UpdateDisplayGroupWindowTree(); ClearMapOfDestroiedDisplay(displayId); - - for (auto& elem : displayInfoMap) { - auto iter = displayInfosMap_.find(elem.first); - const auto& displayInfo = elem.second; - Rect displayRect = { displayInfo->GetOffsetX(), displayInfo->GetOffsetY(), - displayInfo->GetWidth(), displayInfo->GetHeight() }; - if (iter != displayInfosMap_.end()) { - displayRectMap_[elem.first] = displayRect; - displayInfosMap_[elem.first] = displayInfo; - WLOGFI("displayId: %{public}" PRIu64", displayRect: [ %{public}d, %{public}d, %{public}d, %{public}d]", - elem.first, displayRect.posX_, displayRect.posY_, displayRect.width_, displayRect.height_); - } - } - FindMaxAndMinPosXDisplay(); - windowNodeContainer_->GetLayoutPolicy()->ProcessDisplayDestroy(displayId, displayRectMap_); + windowNodeContainer_->GetLayoutPolicy()->ProcessDisplayDestroy(displayId, displayRectMap); } void DisplayGroupController::ProcessDisplayChange(DisplayId displayId, - const std::map>& displayInfoMap, + const std::map& displayRectMap, DisplayStateChangeType type) { const sptr displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); - if (displayInfosMap_.find(displayId) == displayInfosMap_.end()) { - WLOGFE("can not find current display, displayId: %{public}" PRIu64", type: %{public}d", displayId, type); - return; - } WLOGFI("display change, displayId: %{public}" PRIu64", type: %{public}d", displayId, type); switch (type) { case DisplayStateChangeType::UPDATE_ROTATION: { - displayInfosMap_[displayId]->SetRotation(displayInfo->GetRotation()); + displayGroupInfo_->SetDisplayRotation(displayId, displayInfo->GetRotation()); [[fallthrough]]; } case DisplayStateChangeType::SIZE_CHANGE: { - displayInfosMap_[displayId]->SetWidth(displayInfo->GetWidth()); - displayInfosMap_[displayId]->SetHeight(displayInfo->GetHeight()); - ProcessDisplaySizeChangeOrRotation(displayId, displayInfoMap, type); + ProcessDisplaySizeChangeOrRotation(displayId, displayRectMap, type); break; } case DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE: { - displayInfosMap_[displayId]->SetVirtualPixelRatio(displayInfo->GetVirtualPixelRatio()); + displayGroupInfo_->SetDisplayVirtualPixelRatio(displayId, displayInfo->GetVirtualPixelRatio()); windowNodeContainer_->GetLayoutPolicy()->LayoutWindowTree(displayId); break; } @@ -473,37 +413,23 @@ void DisplayGroupController::ProcessDisplayChange(DisplayId displayId, break; } } - FindMaxAndMinPosXDisplay(); } void DisplayGroupController::ProcessDisplaySizeChangeOrRotation(DisplayId displayId, - const std::map>& displayInfoMap, DisplayStateChangeType type) + const std::map& displayRectMap, DisplayStateChangeType type) { - // modify RSTree and windowNodeMaps for cross-display nodes + // modify RSTree and window tree of displayGroup for cross-display nodes ProcessCrossNodes(type); - UpdateWindowNodeMaps(); - for (auto& elem : displayInfoMap) { - auto iter = displayInfosMap_.find(elem.first); - const auto& displayInfo = elem.second; - Rect displayRect = { displayInfo->GetOffsetX(), displayInfo->GetOffsetY(), - displayInfo->GetWidth(), displayInfo->GetHeight() }; - if (iter != displayInfosMap_.end()) { - displayRectMap_[elem.first] = displayRect; - displayInfosMap_[elem.first] = displayInfo; - WLOGFI("displayId: %{public}" PRIu64", displayRect: [ %{public}d, %{public}d, %{public}d, %{public}d]", - elem.first, displayRect.posX_, displayRect.posY_, displayRect.width_, displayRect.height_); - } - } - windowNodeContainer_->GetLayoutPolicy()->ProcessDisplaySizeChangeOrRotation(displayId, displayRectMap_); + UpdateDisplayGroupWindowTree(); + windowNodeContainer_->GetLayoutPolicy()->ProcessDisplaySizeChangeOrRotation(displayId, displayRectMap); } void DisplayGroupController::ClearMapOfDestroiedDisplay(DisplayId displayId) { sysBarTintMaps_.erase(displayId); sysBarNodeMaps_.erase(displayId); - windowNodeMaps_.erase(displayId); - displayRectMap_.erase(displayId); - displayInfosMap_.erase(displayId); + displayGroupWindowTree_.erase(displayId); + displayGroupInfo_->RemoveDisplayInfo(displayId); windowPairMap_.erase(displayId); } @@ -514,5 +440,5 @@ sptr DisplayGroupController::GetWindowPairByDisplayId(DisplayId disp } return nullptr; } -} -} +} // namespace Rosen +} // namespace OHOS diff --git a/wmserver/src/display_group_info.cpp b/wmserver/src/display_group_info.cpp new file mode 100644 index 00000000..dabd37c1 --- /dev/null +++ b/wmserver/src/display_group_info.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "display_group_info.h" + +#include +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "DisplayGroupInfo"}; +} + +DisplayGroupInfo::DisplayGroupInfo(ScreenId displayGroupId, const sptr& displayInfo) +{ + displayGroupId_ = displayGroupId; + AddDisplayInfo(displayInfo); +} + +void DisplayGroupInfo::AddDisplayInfo(const sptr& displayInfo) +{ + DisplayId displayId = displayInfo->GetDisplayId(); + if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) { + WLOGFE("current display is exits, displayId: %{public}" PRIu64"", displayId); + return; + } + displayInfosMap_.insert(std::make_pair(displayId, displayInfo)); +} + +void DisplayGroupInfo::RemoveDisplayInfo(DisplayId displayId) +{ + if (displayInfosMap_.find(displayId) == displayInfosMap_.end()) { + WLOGFE("current display is not exits, displayId: %{public}" PRIu64"", displayId); + return; + } + displayInfosMap_.erase(displayId); +} + +void DisplayGroupInfo::UpdateLeftAndRightDisplayId() +{ + auto displayRectMap = GetAllDisplayRects(); + leftDisplayId_ = displayRectMap.begin()->first; + rightDisplayId_ = displayRectMap.begin()->first; + for (auto& elem : displayRectMap) { + auto& curDisplayRect = elem.second; + if (curDisplayRect.posX_ < displayRectMap[leftDisplayId_].posX_) { + leftDisplayId_ = elem.first; + } + if ((curDisplayRect.posX_ + static_cast(curDisplayRect.width_)) > + (displayRectMap[rightDisplayId_].posX_ + static_cast(displayRectMap[rightDisplayId_].width_))) { + rightDisplayId_ = elem.first; + } + } + WLOGFI("max posX displayId: %{public}" PRIu64", min posX displayId: %{public}" PRIu64"", + rightDisplayId_, leftDisplayId_); +} + +void DisplayGroupInfo::SetDisplayRotation(DisplayId displayId, Rotation rotation) +{ + if (displayInfosMap_.find(displayId) == displayInfosMap_.end()) { + WLOGFE("current display is not exits, displayId: %{public}" PRIu64"", displayId); + return; + } + displayInfosMap_[displayId]->SetRotation(rotation); +} + +void DisplayGroupInfo::SetDisplayVirtualPixelRatio(DisplayId displayId, float vpr) +{ + if (displayInfosMap_.find(displayId) == displayInfosMap_.end()) { + WLOGFE("current display is not exits, displayId: %{public}" PRIu64"", displayId); + return; + } + displayInfosMap_[displayId]->SetVirtualPixelRatio(vpr); +} + +void DisplayGroupInfo::SetDisplayRect(DisplayId displayId, Rect displayRect) +{ + if (displayInfosMap_.find(displayId) == displayInfosMap_.end()) { + WLOGFE("current display is not exits, displayId: %{public}" PRIu64"", displayId); + return; + } + auto& displayInfo = displayInfosMap_[displayId]; + displayInfo->SetOffsetX(displayRect.posX_); + displayInfo->SetOffsetY(displayRect.posY_); + displayInfo->SetWidth(displayRect.width_); + displayInfo->SetHeight(displayRect.height_); +} + +Rotation DisplayGroupInfo::GetDisplayRotation(DisplayId displayId) const +{ + Rotation rotation = Rotation::ROTATION_0; + if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) { + auto& displayInfo = displayInfosMap_[displayId]; + rotation = displayInfo->GetRotation(); + } + return rotation; +} + +float DisplayGroupInfo::GetDisplayVirtualPixelRatio(DisplayId displayId) const +{ + float vpr = 1.0; + if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) { + auto& displayInfo = displayInfosMap_[displayId]; + vpr = displayInfo->GetVirtualPixelRatio(); + } + return vpr; +} + +std::map DisplayGroupInfo::GetAllDisplayRects() const +{ + std::map displayRectMap; + for (auto elem : displayInfosMap_) { + auto& displayInfo = elem.second; + Rect displayRect = { displayInfo->GetOffsetX(), displayInfo->GetOffsetY(), + displayInfo->GetWidth(), displayInfo->GetHeight() }; + displayRectMap.insert(std::make_pair(elem.first, displayRect)); + } + return displayRectMap; +} + +Rect DisplayGroupInfo::GetDisplayRect(DisplayId displayId) const +{ + Rect rect; + if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) { + auto& displayInfo = displayInfosMap_[displayId]; + rect = { displayInfo->GetOffsetX(), displayInfo->GetOffsetY(), + displayInfo->GetWidth(), displayInfo->GetHeight() }; + } + return rect; +} + +sptr DisplayGroupInfo::GetDisplayInfo(DisplayId displayId) const +{ + if (displayInfosMap_.find(displayId) != displayInfosMap_.end()) { + return displayInfosMap_[displayId]; + } + return nullptr; +} + +DisplayId DisplayGroupInfo::GetLeftDisplayId() const +{ + return leftDisplayId_; +} + +DisplayId DisplayGroupInfo::GetRightDisplayId() const +{ + return rightDisplayId_; +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmserver/src/minimize_app.cpp b/wmserver/src/minimize_app.cpp index 57ad4c5c..79be8b04 100644 --- a/wmserver/src/minimize_app.cpp +++ b/wmserver/src/minimize_app.cpp @@ -24,15 +24,20 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "MinimizeApp"}; } -std::map>> MinimizeApp::needMinimizeAppNodes_; +std::map>> MinimizeApp::needMinimizeAppNodes_; bool MinimizeApp::isMinimizedByOtherWindow_ = true; std::recursive_mutex MinimizeApp::mutex_; void MinimizeApp::AddNeedMinimizeApp(const sptr& node, MinimizeReason reason) { std::lock_guard lock(mutex_); + bool isFromUser = IsFromUser(reason); + if (!isMinimizedByOtherWindow_ && !isFromUser) { + return; + } + wptr weakNode(node); WLOGFI("[Minimize] Add Window %{public}u to minimize list, reason %{public}u", node->GetWindowId(), reason); - needMinimizeAppNodes_[reason].emplace_back(node); + needMinimizeAppNodes_[reason].emplace_back(weakNode); } void MinimizeApp::ExecuteMinimizeAll() @@ -40,14 +45,12 @@ void MinimizeApp::ExecuteMinimizeAll() std::lock_guard lock(mutex_); for (auto& appNodes: needMinimizeAppNodes_) { bool isFromUser = IsFromUser(appNodes.first); - if (!isMinimizedByOtherWindow_ && !isFromUser) { - continue; - } - for (auto& node : appNodes.second) { - if (node->abilityToken_ != nullptr) { - WLOGFI("[Minimize] Minimize Window %{public}u, reason %{public}u", node->GetWindowId(), appNodes.first); - AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(node->abilityToken_, isFromUser); + auto weakNode = node.promote(); + if (weakNode != nullptr && weakNode->abilityToken_ != nullptr && !weakNode->startingWindowShown_) { + WLOGFI("[Minimize] Minimize Window %{public}u, reason %{public}u", + weakNode->GetWindowId(), appNodes.first); + AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(weakNode->abilityToken_, isFromUser); } } appNodes.second.clear(); @@ -83,13 +86,11 @@ void MinimizeApp::ExecuteMinimizeTargetReason(MinimizeReason reason) std::lock_guard lock(mutex_); if (needMinimizeAppNodes_.find(reason) != needMinimizeAppNodes_.end()) { bool isFromUser = IsFromUser(reason); - if (!isMinimizedByOtherWindow_ && !isFromUser) { - return; - } for (auto& node : needMinimizeAppNodes_.at(reason)) { - if (node->abilityToken_ != nullptr) { - WLOGFI("[Minimize] Minimize Window %{public}u, reason %{public}u", node->GetWindowId(), reason); - AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(node->abilityToken_, isFromUser); + auto weakNode = node.promote(); + if (weakNode != nullptr && weakNode->abilityToken_ != nullptr && !weakNode->startingWindowShown_) { + WLOGFI("[Minimize] Minimize Window %{public}u, reason %{public}u", weakNode->GetWindowId(), reason); + AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(weakNode->abilityToken_, isFromUser); } } needMinimizeAppNodes_.at(reason).clear(); diff --git a/wmserver/src/starting_window.cpp b/wmserver/src/starting_window.cpp index ecad1c9e..7502fd9b 100644 --- a/wmserver/src/starting_window.cpp +++ b/wmserver/src/starting_window.cpp @@ -30,8 +30,6 @@ namespace { SurfaceDraw StartingWindow::surfaceDraw_; static bool g_hasInit = false; std::recursive_mutex StartingWindow::mutex_; -static bool g_initStart = false; -static std::shared_ptr g_startingWinSurfaceNode = nullptr; sptr StartingWindow::CreateWindowNode(sptr info, uint32_t winId) { @@ -69,18 +67,15 @@ WMError StartingWindow::CreateLeashAndStartingSurfaceNode(sptr& node WLOGFE("create leashWinSurfaceNode failed"); return WMError::WM_ERROR_NULLPTR; } - if (!g_initStart) { - rsSurfaceNodeConfig.SurfaceNodeName = "startingWindow"; - g_startingWinSurfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig); - if (g_startingWinSurfaceNode == nullptr) { - WLOGFE("create startingWinSurfaceNode failed"); - node->leashWinSurfaceNode_ = nullptr; - return WMError::WM_ERROR_NULLPTR; - } - g_initStart = true; + + rsSurfaceNodeConfig.SurfaceNodeName = "startingWindow" + std::to_string(node->GetWindowId()); + node->startingWinSurfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig); + if (node->startingWinSurfaceNode_ == nullptr) { + WLOGFE("create startingWinSurfaceNode failed"); + node->leashWinSurfaceNode_ = nullptr; + return WMError::WM_ERROR_NULLPTR; } - node->startingWinSurfaceNode_ = g_startingWinSurfaceNode; - WLOGFI("Create leashWinSurfaceNode and startingWinSurfaceNode success!"); + WLOGFI("Create leashWinSurfaceNode and startingWinSurfaceNode success with id:%{public}u!", node->GetWindowId()); return WMError::WM_OK; } @@ -108,29 +103,31 @@ void StartingWindow::DrawStartingWindow(sptr& node, } void StartingWindow::HandleClientWindowCreate(sptr& node, sptr& window, - uint32_t& windowId, const std::shared_ptr& surfaceNode) + uint32_t& windowId, const std::shared_ptr& surfaceNode, sptr& property) { node->surfaceNode_ = surfaceNode; node->SetWindowToken(window); - node->SetCallingPid(); - node->SetCallingUid(); + node->SetCallingPid(property->GetWindowPid()); + node->SetCallingUid(property->GetWindowUid()); windowId = node->GetWindowId(); WLOGFI("after set Id:%{public}u, requestRect:[%{public}d, %{public}d, %{public}u, %{public}u]", node->GetWindowId(), node->GetRequestRect().posX_, node->GetRequestRect().posY_, node->GetRequestRect().width_, node->GetRequestRect().height_); // Register FirstFrame Callback to rs, replace startwin - auto firstFrameCompleteCallback = [node]() { + wptr weak = node; + auto firstFrameCompleteCallback = [weak]() { std::lock_guard lock(mutex_); - if (node->leashWinSurfaceNode_ == nullptr) { - WLOGFE("leashWinSurfaceNode_ is nullptr"); + auto weakNode = weak.promote(); + if (weakNode == nullptr || weakNode->leashWinSurfaceNode_ == nullptr) { + WLOGFE("windowNode or leashWinSurfaceNode_ is nullptr"); return; } - WLOGFI("StartingWindow::Replace surfaceNode, id: %{public}u", node->GetWindowId()); - node->leashWinSurfaceNode_->RemoveChild(node->startingWinSurfaceNode_); - node->leashWinSurfaceNode_->AddChild(node->surfaceNode_, -1); - node->startingWinSurfaceNode_ = nullptr; - AAFwk::AbilityManagerClient::GetInstance()->CompleteFirstFrameDrawing(node->abilityToken_); + WLOGFI("StartingWindow::Replace surfaceNode, id: %{public}u", weakNode->GetWindowId()); + weakNode->leashWinSurfaceNode_->RemoveChild(weakNode->startingWinSurfaceNode_); + weakNode->leashWinSurfaceNode_->AddChild(weakNode->surfaceNode_, -1); + weakNode->startingWinSurfaceNode_ = nullptr; + AAFwk::AbilityManagerClient::GetInstance()->CompleteFirstFrameDrawing(weakNode->abilityToken_); RSTransaction::FlushImplicitTransaction(); }; node->surfaceNode_->SetBufferAvailableCallback(firstFrameCompleteCallback); @@ -141,13 +138,17 @@ void StartingWindow::ReleaseStartWinSurfaceNode(sptr& node) { std::lock_guard lock(mutex_); if (!node->leashWinSurfaceNode_) { + WLOGFI("cannot release leashwindow since leash is null, id:%{public}u", node->GetWindowId()); return; } + auto leashName = node->leashWinSurfaceNode_->GetName(); node->leashWinSurfaceNode_->RemoveChild(node->startingWinSurfaceNode_); node->leashWinSurfaceNode_->RemoveChild(node->surfaceNode_); node->leashWinSurfaceNode_ = nullptr; node->startingWinSurfaceNode_ = nullptr; - WLOGFI("Release startwindow surfaceNode end id:%{public}u", node->GetWindowId()); + WLOGFI("Release startwindow surfaceNode end id: %{public}u, [%{public}s]: use_count: %{public}ld, \ + [startWinSurface]: use_count: %{public}ld ", node->GetWindowId(), leashName.c_str(), + node->leashWinSurfaceNode_.use_count(), node->startingWinSurfaceNode_.use_count()); } void StartingWindow::UpdateRSTree(sptr& node) diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 9a35201e..a70f7d0d 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -78,18 +78,23 @@ void WindowController::StartingWindow(sptr info, sptr abilityToken) { + WLOGFI("begin CancelStartingWindow!"); auto node = windowRoot_->FindWindowNodeWithToken(abilityToken); if (node == nullptr) { WLOGFI("cannot find windowNode!"); return; } - WM_SCOPED_TRACE("wms:CancelStartingWindow(%u)", node->GetWindowId()); - DestroyWindow(node->GetWindowId(), true); + WLOGFI("CancelStartingWindow with id:%{public}u!", node->GetWindowId()); + WMError res = windowRoot_->DestroyWindow(node->GetWindowId(), false); + if (res != WMError::WM_OK) { + WLOGFE("DestroyWindow failed!"); + } } WMError WindowController::NotifyWindowTransition(sptr& srcInfo, sptr& dstInfo) { + WLOGFI("NotifyWindowTransition begin!"); if (!srcInfo || !dstInfo) { WLOGFE("srcInfo or dstInfo is nullptr!"); return WMError::WM_ERROR_NULLPTR; @@ -147,7 +152,7 @@ WMError WindowController::CreateWindow(sptr& window, sptr node = windowRoot_->FindWindowNodeWithToken(token); if (node != nullptr && WindowHelper::IsMainWindow(property->GetWindowType()) && node->startingWindowShown_) { - StartingWindow::HandleClientWindowCreate(node, window, windowId, surfaceNode); + StartingWindow::HandleClientWindowCreate(node, window, windowId, surfaceNode, property); windowRoot_->AddDeathRecipient(node); return WMError::WM_OK; } @@ -157,6 +162,8 @@ WMError WindowController::CreateWindow(sptr& window, sptrabilityToken_ = token; UpdateWindowAnimation(node); + WLOGFI("createWindow name:%{public}u, windowName:%{public}s", + windowId, node->GetWindowName().c_str()); return windowRoot_->SaveWindow(node); } @@ -172,23 +179,13 @@ WMError WindowController::AddWindowNode(sptr& property) return WMError::WM_ERROR_INVALID_OPERATION; } // using starting window rect if client rect is empty - if (WindowHelper::IsEmptyRect(property->GetRequestRect())) { // for tile and cascade + if (WindowHelper::IsEmptyRect(property->GetRequestRect()) && node->startingWindowShown_) { // for tile and cascade property->SetRequestRect(node->GetRequestRect()); property->SetWindowRect(node->GetWindowRect()); + property->SetDecoStatus(true); } node->GetWindowProperty()->CopyFrom(property); - if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && - WindowHelper::IsAppWindow(node->GetWindowType()) && !node->isPlayAnimationShow_) { - WM_SCOPED_TRACE_BEGIN("controller:MinimizeStructuredAppWindowsExceptSelf"); - WMError res = windowRoot_->MinimizeStructuredAppWindowsExceptSelf(node); - WM_SCOPED_TRACE_END(); - if (res != WMError::WM_OK) { - WLOGFE("Minimize other structured window failed"); - MinimizeApp::ClearNodesWithReason(MinimizeReason::OTHER_WINDOW); - return res; - } - } // Need 'check permission' // Need 'adjust property' WMError res = windowRoot_->AddWindowNode(property->GetParentId(), node); @@ -205,7 +202,6 @@ WMError WindowController::AddWindowNode(sptr& property) sysBarWinId_[node->GetWindowType()] = node->GetWindowId(); ReSizeSystemBarPropertySizeIfNeed(node); } - StopBootAnimationIfNeed(node->GetWindowType()); MinimizeApp::ExecuteMinimizeAll(); return WMError::WM_OK; @@ -305,7 +301,10 @@ WMError WindowController::ResizeRect(uint32_t windowId, const Rect& rect, Window if (reason == WindowSizeChangeReason::MOVE) { newRect = { rect.posX_, rect.posY_, lastRect.width_, lastRect.height_ }; if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { - if (windowRoot_->isVerticalDisplay(node)) { + if (windowRoot_->IsForbidDockSliceMove(node->GetDisplayId())) { + WLOGFI("dock slice is forbidden to move"); + newRect = lastRect; + } else if (windowRoot_->isVerticalDisplay(node)) { newRect.posX_ = lastRect.posX_; } else { newRect.posY_ = lastRect.posY_; @@ -512,7 +511,12 @@ WMError WindowController::SetWindowFlags(uint32_t windowId, uint32_t flags) return WMError::WM_ERROR_NULLPTR; } auto property = node->GetWindowProperty(); + uint32_t oldFlags = property->GetWindowFlags(); property->SetWindowFlags(flags); + // only forbid_split_move flag change, just set property + if ((oldFlags ^ flags) == static_cast(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE)) { + return WMError::WM_OK; + } WMError res = windowRoot_->UpdateWindowNode(windowId, WindowUpdateReason::UPDATE_FLAGS); if (res != WMError::WM_OK) { return res; @@ -567,6 +571,8 @@ WMError WindowController::ProcessPointDown(uint32_t windowId, bool isStartDrag) return WMError::WM_ERROR_INVALID_OPERATION; } + NotifyOutsidePressed(node); + if (isStartDrag) { WMError res = windowRoot_->UpdateSizeChangeReason(windowId, WindowSizeChangeReason::DRAG_START); return res; @@ -605,12 +611,13 @@ void WindowController::MinimizeAllAppWindows(DisplayId displayId) MinimizeApp::ExecuteMinimizeAll(); } -void WindowController::ToggleShownStateForAllAppWindows() +WMError WindowController::ToggleShownStateForAllAppWindows() { if (isScreenLocked_) { - return; + return WMError::WM_DO_NOTHING; } windowRoot_->ToggleShownStateForAllAppWindows(); + return WMError::WM_OK; } WMError WindowController::MaxmizeWindow(uint32_t windowId) @@ -704,16 +711,13 @@ WMError WindowController::UpdateProperty(sptr& property, Propert switch (action) { case PropertyChangeAction::ACTION_UPDATE_RECT: { node->SetDecoStatus(property->GetDecoStatus()); - ResizeRect(windowId, property->GetRequestRect(), property->GetWindowSizeChangeReason()); - break; + return ResizeRect(windowId, property->GetRequestRect(), property->GetWindowSizeChangeReason()); } case PropertyChangeAction::ACTION_UPDATE_MODE: { - SetWindowMode(windowId, property->GetWindowMode()); - break; + return SetWindowMode(windowId, property->GetWindowMode()); } case PropertyChangeAction::ACTION_UPDATE_FLAGS: { - SetWindowFlags(windowId, property->GetWindowFlags()); - break; + return SetWindowFlags(windowId, property->GetWindowFlags()); } case PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS: { auto& props = property->GetSystemBarProperty(); @@ -761,6 +765,10 @@ WMError WindowController::UpdateProperty(sptr& property, Propert windowRoot_->SetBrightness(node->GetWindowId(), node->GetBrightness()); break; } + case PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO: { + node->SetModeSupportInfo(property->GetModeSupportInfo()); + break; + } default: break; } @@ -772,5 +780,57 @@ WMError WindowController::GetModeChangeHotZones(DisplayId displayId, { return windowRoot_->GetModeChangeHotZones(displayId, hotZones, config); } + +void WindowController::NotifyOutsidePressed(const sptr& node) +{ + auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(node->GetDisplayId()); + if (windowNodeContainer == nullptr) { + WLOGFE("window node container is null"); + return; + } + + std::vector> windowNodes; + windowNodeContainer->TraverseContainer(windowNodes); + uint32_t skipNodeId = GetEmbedNodeId(windowNodes, node); + for (auto& windowNode : windowNodes) { + if (windowNode == nullptr || windowNode->GetWindowToken() == nullptr || + windowNode->GetWindowId() == skipNodeId || + windowNode->GetWindowId() == node->GetWindowId()) { + WLOGFD("continue %{public}s", windowNode == nullptr ? "nullptr" : windowNode->GetWindowName().c_str()); + continue; + } + WLOGFD("notify %{public}s id %{public}d", windowNode->GetWindowName().c_str(), windowNode->GetWindowId()); + windowNode->GetWindowToken()->NotifyOutsidePressed(); + } +} + +uint32_t WindowController::GetEmbedNodeId(const std::vector>& windowNodes, + const sptr& node) +{ + if (node->GetWindowType() != WindowType::WINDOW_TYPE_APP_COMPONENT) { + return 0; + } + + Rect nodeRect = node->GetWindowRect(); + bool isSkip = true; + for (auto& windowNode : windowNodes) { + if (windowNode == nullptr) { + continue; + } + if (windowNode->GetWindowId() == node->GetWindowId()) { + isSkip = false; + continue; + } + if (isSkip) { + continue; + } + if (nodeRect.IsInsideOf(windowNode->GetWindowRect())) { + WLOGI("OutsidePressed window type is component %{public}s windowNode %{public}d", + windowNode->GetWindowName().c_str(), windowNode->GetWindowId()); + return windowNode->GetWindowId(); + } + } + return 0; +} } // namespace OHOS } // namespace Rosen \ No newline at end of file diff --git a/wmserver/src/window_dumper.cpp b/wmserver/src/window_dumper.cpp index 9c032584..d582ce7f 100644 --- a/wmserver/src/window_dumper.cpp +++ b/wmserver/src/window_dumper.cpp @@ -25,16 +25,18 @@ #include "string_ex.h" #include "unique_fd.h" #include "window_manager_hilog.h" +#include "window_manager_service.h" #include "wm_common.h" namespace OHOS { namespace Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowDumper"}; + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowDumper"}; constexpr int WINDOW_NAME_MAX_LENGTH = 20; const std::string ARG_DUMP_HELP = "-h"; const std::string ARG_DUMP_ALL = "-a"; + const std::string ARG_DUMP_WINDOW = "-w"; } WMError WindowDumper::Dump(int fd, const std::vector& args) const @@ -53,13 +55,13 @@ WMError WindowDumper::Dump(int fd, const std::vector& args) cons std::string dumpInfo; if (params.empty()) { - ShowIllegalArgsInfo(dumpInfo); - } else if (params[0] == ARG_DUMP_HELP) { + ShowIllegalArgsInfo(dumpInfo, WMError::WM_ERROR_INVALID_PARAM); + } else if (params.size() == 1 && params[0] == ARG_DUMP_HELP) { // 1: params num ShowHelpInfo(dumpInfo); } else { WMError errCode = DumpWindowInfo(params, dumpInfo); - if (errCode == WMError::WM_ERROR_INVALID_PARAM) { - ShowIllegalArgsInfo(dumpInfo); + if (errCode != WMError::WM_OK) { + ShowIllegalArgsInfo(dumpInfo, errCode); } } int ret = dprintf(fd, "%s\n", dumpInfo.c_str()); @@ -71,18 +73,18 @@ WMError WindowDumper::Dump(int fd, const std::vector& args) cons return WMError::WM_OK; } -WMError WindowDumper::DumpDisplayWindowInfo(DisplayId displayId, std::string& dumpInfo) const +WMError WindowDumper::DumpScreenGroupWindowInfo(ScreenId screenGroupId, + const sptr& windowNodeContainer, std::string& dumpInfo) const { - auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(displayId); if (windowNodeContainer == nullptr) { WLOGFE("windowNodeContainer is null"); return WMError::WM_ERROR_NULLPTR; } std::ostringstream oss; - oss << "---------------------------------------Display " << displayId - << "---------------------------------------" + oss << "-------------------------------------ScreenGroup " << screenGroupId + << "-------------------------------------" << std::endl; - oss << "WindowName WinId Type Mode Flag ZOrd Orientation [ x y w h ]" + oss << "WindowName DisplayId WinId Type Mode Flag ZOrd Orientation [ x y w h ]" << std::endl; std::vector> windowNodes; windowNodeContainer->TraverseContainer(windowNodes); @@ -97,6 +99,7 @@ WMError WindowDumper::DumpDisplayWindowInfo(DisplayId displayId, std::string& du windowNode->GetWindowName() : windowNode->GetWindowName().substr(0, WINDOW_NAME_MAX_LENGTH); // std::setw is used to set the output width and different width values are set to keep the format aligned. oss << std::left << std::setw(21) << windowName + << std::left << std::setw(10) << windowNode->GetDisplayId() << std::left << std::setw(6) << windowNode->GetWindowId() << std::left << std::setw(5) << static_cast(windowNode->GetWindowType()) << std::left << std::setw(5) << static_cast(windowNode->GetWindowMode()) @@ -112,24 +115,24 @@ WMError WindowDumper::DumpDisplayWindowInfo(DisplayId displayId, std::string& du << std::endl; } oss << "Focus window: " << windowNodeContainer->GetFocusWindow() << std::endl; - oss << "total window num: " << windowRoot_->GetWindowNodeMap().size() << std::endl; + oss << "total window num: " << windowRoot_->GetTotalWindowNum()<< std::endl; dumpInfo.append(oss.str()); return WMError::WM_OK; } WMError WindowDumper::DumpAllWindowInfo(std::string& dumpInfo) const { - std::map windowNodeContainers; + std::map> windowNodeContainers; std::vector displayIds = DisplayManagerServiceInner::GetInstance().GetAllDisplayIds(); - std::lock_guard lock(mutex_); for (DisplayId displayId : displayIds) { + ScreenId screenGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); auto windowNodeContainer = windowRoot_->GetOrCreateWindowNodeContainer(displayId); - if (windowNodeContainer != nullptr) { - windowNodeContainers.emplace(windowNodeContainer.GetRefPtr(), displayId); + if (windowNodeContainers.count(screenGroupId) == 0 && windowNodeContainer != nullptr) { + windowNodeContainers.insert(std::make_pair(screenGroupId, windowNodeContainer)); } } for (auto it = windowNodeContainers.begin(); it != windowNodeContainers.end(); it++) { - WMError ret = DumpDisplayWindowInfo(it->second, dumpInfo); + WMError ret = DumpScreenGroupWindowInfo(it->first, it->second, dumpInfo); if (ret != WMError::WM_OK) { return ret; } @@ -137,20 +140,90 @@ WMError WindowDumper::DumpAllWindowInfo(std::string& dumpInfo) const return WMError::WM_OK; } +bool WindowDumper::IsValidDigitString(const std::string& windowIdStr) const +{ + if (windowIdStr.empty()) { + return false; + } + for (char ch : windowIdStr) { + if ((ch >= '0' && ch <= '9')) { + continue; + } + WLOGFE("invalid window id"); + return false; + } + return true; +} + +WMError WindowDumper::DumpSpecifiedWindowInfo(uint32_t windowId, const std::vector& params, + std::string& dumpInfo) const +{ + auto node = windowRoot_->GetWindowNode(windowId); + if (node == nullptr) { + WLOGFE("invalid window"); + return WMError::WM_ERROR_NULLPTR; + } + std::ostringstream oss; + oss << "WindowName DisplayId WinId Type Mode Flag Orientation [ x y w h ]" + << std::endl; + Rect rect = node->GetWindowRect(); + const std::string& windowName = node->GetWindowName().size() <= WINDOW_NAME_MAX_LENGTH ? + node->GetWindowName() : node->GetWindowName().substr(0, WINDOW_NAME_MAX_LENGTH); + // std::setw is used to set the output width and different width values are set to keep the format aligned. + oss << std::left << std::setw(21) << windowName + << std::left << std::setw(10) << node->GetDisplayId() + << std::left << std::setw(6) << node->GetWindowId() + << std::left << std::setw(5) << static_cast(node->GetWindowType()) + << std::left << std::setw(5) << static_cast(node->GetWindowMode()) + << std::left << std::setw(5) << node->GetWindowFlags() + << std::left << std::setw(12) << static_cast(node->GetRequestedOrientation()) + << "[ " + << std::left << std::setw(5) << rect.posX_ + << std::left << std::setw(5) << rect.posY_ + << std::left << std::setw(5) << rect.width_ + << std::left << std::setw(5) << rect.height_ + << "]" + << std::endl; + dumpInfo.append(oss.str()); + if (node->GetWindowToken() != nullptr) { + std::vector resetParams; + resetParams.assign(params.begin() + 2, params.end()); // 2: params num + if (resetParams.empty()) { + WLOGFI("do not dump ui info"); + return WMError::WM_OK; + } + std::vector infos; + node->GetWindowToken()->DumpInfo(resetParams, infos); + for (auto& info: infos) { + dumpInfo.append(info).append("\n"); + } + } + return WMError::WM_OK; +} + WMError WindowDumper::DumpWindowInfo(const std::vector& args, std::string& dumpInfo) const { if (args.empty()) { return WMError::WM_ERROR_INVALID_PARAM; } DumpType dumpType = DumpType::DUMP_NONE; - if (args[0] == ARG_DUMP_ALL) { + uint32_t windowId = INVALID_WINDOW_ID; + if (args.size() == 1 && args[0] == ARG_DUMP_ALL) { // 1: params num dumpType = DumpType::DUMP_ALL; + } else if (args.size() >= 2 && args[0] == ARG_DUMP_WINDOW && IsValidDigitString(args[1])) { // 2: params num + windowId = std::stoul(args[1]); + dumpType = DumpType::DUMP_WINDOW; + } else { + // do nothing } WMError ret = WMError::WM_OK; switch (dumpType) { case DumpType::DUMP_ALL: ret = DumpAllWindowInfo(dumpInfo); break; + case DumpType::DUMP_WINDOW: + ret = DumpSpecifiedWindowInfo(windowId, args, dumpInfo); + break; default: ret = WMError::WM_ERROR_INVALID_PARAM; break; @@ -158,18 +231,50 @@ WMError WindowDumper::DumpWindowInfo(const std::vector& args, std:: return ret; } -void WindowDumper::ShowIllegalArgsInfo(std::string& dumpInfo) const +void WindowDumper::ShowIllegalArgsInfo(std::string& dumpInfo, WMError errCode) const { - dumpInfo.append("The arguments are illegal and you can enter '-h' for help."); + switch (errCode) { + case WMError::WM_ERROR_INVALID_PARAM: + dumpInfo.append("The arguments are illegal and you can enter '-h' for help."); + break; + case WMError::WM_ERROR_NULLPTR: + dumpInfo.append("The window is invalid, you can enter '-a' to get valid window id."); + break; + default: + break; + } } void WindowDumper::ShowHelpInfo(std::string& dumpInfo) const { dumpInfo.append("Usage:\n") - .append(" -h ") + .append(" -h ") .append("|help text for the tool\n") - .append(" -a ") - .append("|dump all window infomation in the system\n"); + .append(" -a ") + .append("|dump all window infomation in the system\n") + .append(" -w {window id} [ArkUI Option] ") + .append("|dump specified window information\n") + .append(" ------------------------------------[ArkUI Option]------------------------------------ \n"); + ShowAceDumpHelp(dumpInfo); +} + +void WindowDumper::ShowAceDumpHelp(std::string& dumpInfo) const +{ + std::vector infos; + auto node = windowRoot_->GetWindowForDumpAceHelpInfo(); + if (node == nullptr) { + WLOGFE("invalid window"); + return; + } + if (node->GetWindowToken() != nullptr) { + std::vector params; + params.emplace_back(ARG_DUMP_HELP); + std::vector infos; + node->GetWindowToken()->DumpInfo(params, infos); + for (auto& info: infos) { + dumpInfo.append(info).append("\n"); + } + } } } } \ No newline at end of file diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 072fe475..0e252e57 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -26,9 +26,9 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowLayoutPolicy"}; } -WindowLayoutPolicy::WindowLayoutPolicy(const std::map& displayRectMap, - WindowNodeMaps& windowNodeMaps, std::map>& displayInfosMap) - : displayRectMap_(displayRectMap), windowNodeMaps_(windowNodeMaps), displayInfosMap_(displayInfosMap) +WindowLayoutPolicy::WindowLayoutPolicy(const sptr& displayGroupInfo, + DisplayGroupWindowTree& displayGroupWindowTree) + : displayGroupInfo_(displayGroupInfo), displayGroupWindowTree_(displayGroupWindowTree) { } @@ -50,7 +50,7 @@ void WindowLayoutPolicy::Reorder() void WindowLayoutPolicy::LimitWindowToBottomRightCorner(const sptr& node) { Rect windowRect = node->GetRequestRect(); - Rect displayRect = displayRectMap_[node->GetDisplayId()]; + Rect displayRect = displayGroupInfo_->GetDisplayRect(node->GetDisplayId()); windowRect.posX_ = std::max(windowRect.posX_, displayRect.posX_); windowRect.posY_ = std::max(windowRect.posY_, displayRect.posY_); windowRect.width_ = std::min(windowRect.width_, displayRect.width_); @@ -81,7 +81,7 @@ void WindowLayoutPolicy::UpdateDisplayGroupRect() { Rect newDisplayGroupRect = { 0, 0, 0, 0 }; // current mutiDisplay is only support left-right combination, maxNum is two - for (auto& elem : displayRectMap_) { + for (auto& elem : displayGroupInfo_->GetAllDisplayRects()) { newDisplayGroupRect.posX_ = std::min(displayGroupRect_.posX_, elem.second.posX_); newDisplayGroupRect.posY_ = std::min(displayGroupRect_.posY_, elem.second.posY_); newDisplayGroupRect.width_ += elem.second.width_; @@ -119,21 +119,21 @@ void WindowLayoutPolicy::UpdateDisplayGroupLimitRect_() } void WindowLayoutPolicy::UpdateRectInDisplayGroup(const sptr& node, - const Rect& srcDisplayRect, - const Rect& dstDisplayRect) + const Rect& oriDisplayRect, + const Rect& newDisplayRect) { Rect newRect = node->GetRequestRect(); WLOGFI("before update rect in display group, windowId: %{public}d, rect: [%{public}d, %{public}d, " "%{public}d, %{public}d]", node->GetWindowId(), newRect.posX_, newRect.posY_, newRect.width_, newRect.height_); - newRect.posX_ = newRect.posX_ - srcDisplayRect.posX_ + dstDisplayRect.posX_; - newRect.posY_ = newRect.posY_ - srcDisplayRect.posY_ + dstDisplayRect.posY_; + newRect.posX_ = newRect.posX_ - oriDisplayRect.posX_ + newDisplayRect.posX_; + newRect.posY_ = newRect.posY_ - oriDisplayRect.posY_ + newDisplayRect.posY_; node->SetRequestRect(newRect); WLOGFI("after update rect in display group, windowId: %{public}d, newRect: [%{public}d, %{public}d, " "%{public}d, %{public}d]", node->GetWindowId(), newRect.posX_, newRect.posY_, newRect.width_, newRect.height_); for (auto& childNode : node->children_) { - UpdateRectInDisplayGroup(childNode, srcDisplayRect, dstDisplayRect); + UpdateRectInDisplayGroup(childNode, oriDisplayRect, newDisplayRect); } } @@ -144,7 +144,7 @@ bool WindowLayoutPolicy::IsMultiDisplay() void WindowLayoutPolicy::UpdateMultiDisplayFlag() { - if (displayRectMap_.size() > 1) { + if (displayGroupInfo_->GetAllDisplayRects().size() > 1) { isMultiDisplay_ = true; WLOGFI("current mode is muti-display"); } else { @@ -154,20 +154,20 @@ void WindowLayoutPolicy::UpdateMultiDisplayFlag() } void WindowLayoutPolicy::UpdateRectInDisplayGroupForAllNodes(DisplayId displayId, - const Rect& srcDisplayRect, - const Rect& dstDisplayRect) + const Rect& oriDisplayRect, + const Rect& newDisplayRect) { - WLOGFI("displayId: %{public}" PRIu64", srcDisplayRect: [ %{public}d, %{public}d, %{public}d, %{public}d] " - "dstDisplayRect: [ %{public}d, %{public}d, %{public}d, %{public}d]", - displayId, srcDisplayRect.posX_, srcDisplayRect.posY_, srcDisplayRect.width_, srcDisplayRect.height_, - dstDisplayRect.posX_, dstDisplayRect.posY_, dstDisplayRect.width_, dstDisplayRect.height_); + WLOGFI("displayId: %{public}" PRIu64", oriDisplayRect: [ %{public}d, %{public}d, %{public}d, %{public}d] " + "newDisplayRect: [ %{public}d, %{public}d, %{public}d, %{public}d]", + displayId, oriDisplayRect.posX_, oriDisplayRect.posY_, oriDisplayRect.width_, oriDisplayRect.height_, + newDisplayRect.posX_, newDisplayRect.posY_, newDisplayRect.width_, newDisplayRect.height_); - auto& windowNodeMap = windowNodeMaps_[displayId]; - for (auto& iter : windowNodeMap) { + auto& displayWindowTree = displayGroupWindowTree_[displayId]; + for (auto& iter : displayWindowTree) { auto& nodeVector = *(iter.second); for (auto& node : nodeVector) { if (!node->isShowingOnMultiDisplays_) { - UpdateRectInDisplayGroup(node, srcDisplayRect, dstDisplayRect); + UpdateRectInDisplayGroup(node, oriDisplayRect, newDisplayRect); } if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { LimitWindowToBottomRightCorner(node); @@ -178,12 +178,22 @@ void WindowLayoutPolicy::UpdateRectInDisplayGroupForAllNodes(DisplayId displayId } } +void WindowLayoutPolicy::UpdateDisplayRectAndDisplayGroupInfo(const std::map& displayRectMap) +{ + for (auto& elem : displayRectMap) { + auto& displayId = elem.first; + auto& displayRect = elem.second; + displayGroupInfo_->SetDisplayRect(displayId, displayRect); + } +} + void WindowLayoutPolicy::PostProcessWhenDisplayChange() { + displayGroupInfo_->UpdateLeftAndRightDisplayId(); UpdateMultiDisplayFlag(); UpdateDisplayGroupRect(); Launch(); - for (auto& elem : displayRectMap_) { + for (auto& elem : displayGroupInfo_->GetAllDisplayRects()) { LayoutWindowTree(elem.first); WLOGFI("LayoutWindowTree, displayId: %{public}" PRIu64", displayRect: [ %{public}d, %{public}d, %{public}d, " "%{public}d]", elem.first, elem.second.posX_, elem.second.posY_, elem.second.width_, elem.second.height_); @@ -192,41 +202,57 @@ void WindowLayoutPolicy::PostProcessWhenDisplayChange() void WindowLayoutPolicy::ProcessDisplayCreate(DisplayId displayId, const std::map& displayRectMap) { + const auto& oriDisplayRectMap = displayGroupInfo_->GetAllDisplayRects(); + // check displayId and displayRectMap size + if (oriDisplayRectMap.find(displayId) == oriDisplayRectMap.end() || + displayRectMap.size() != oriDisplayRectMap.size()) { + WLOGFE("current display is exited or displayInfo map size is error, displayId: %{public}" PRIu64"", displayId); + return; + } for (auto& elem : displayRectMap) { - auto iter = displayRectMap_.find(elem.first); - if (iter != displayRectMap_.end()) { - UpdateRectInDisplayGroupForAllNodes(elem.first, iter->second, elem.second); - iter->second = elem.second; + auto iter = oriDisplayRectMap.find(elem.first); + if (iter != oriDisplayRectMap.end()) { + const auto& oriDisplayRect = iter->second; + const auto& newDisplayRect = elem.second; + UpdateRectInDisplayGroupForAllNodes(elem.first, oriDisplayRect, newDisplayRect); } else { if (elem.first != displayId) { WLOGFE("Wrong display, displayId: %{public}" PRIu64"", displayId); return; } - displayRectMap_.insert(std::make_pair(displayId, elem.second)); } } - + UpdateDisplayRectAndDisplayGroupInfo(displayRectMap); PostProcessWhenDisplayChange(); WLOGFI("Process display create, displayId: %{public}" PRIu64"", displayId); } void WindowLayoutPolicy::ProcessDisplayDestroy(DisplayId displayId, const std::map& displayRectMap) { - for (auto oriIter = displayRectMap_.begin(); oriIter != displayRectMap_.end();) { + const auto& oriDisplayRectMap = displayGroupInfo_->GetAllDisplayRects(); + // check displayId and displayRectMap size + if (oriDisplayRectMap.find(displayId) != oriDisplayRectMap.end() || + displayRectMap.size() != oriDisplayRectMap.size()) { + WLOGFE("can not find current display or displayInfo map size is error, displayId: %{public}" PRIu64"", + displayId); + return; + } + for (auto oriIter = oriDisplayRectMap.begin(); oriIter != oriDisplayRectMap.end();) { auto newIter = displayRectMap.find(oriIter->first); if (newIter != displayRectMap.end()) { - UpdateRectInDisplayGroupForAllNodes(oriIter->first, oriIter->second, newIter->second); - oriIter->second = newIter->second; - ++oriIter; + const auto& oriDisplayRect = oriIter->second; + const auto& newDisplayRect = newIter->second; + UpdateRectInDisplayGroupForAllNodes(oriIter->first, oriDisplayRect, newDisplayRect); } else { if (oriIter->first != displayId) { WLOGFE("Wrong display, displayId: %{public}" PRIu64"", displayId); return; } - displayRectMap_.erase(oriIter++); } + ++oriIter; } + UpdateDisplayRectAndDisplayGroupInfo(displayRectMap); PostProcessWhenDisplayChange(); WLOGFI("Process display destroy, displayId: %{public}" PRIu64"", displayId); } @@ -234,14 +260,23 @@ void WindowLayoutPolicy::ProcessDisplayDestroy(DisplayId displayId, const std::m void WindowLayoutPolicy::ProcessDisplaySizeChangeOrRotation(DisplayId displayId, const std::map& displayRectMap) { + const auto& oriDisplayRectMap = displayGroupInfo_->GetAllDisplayRects(); + // check displayId and displayRectMap size + if (oriDisplayRectMap.find(displayId) == oriDisplayRectMap.end() || + displayRectMap.size() != oriDisplayRectMap.size()) { + WLOGFE("can not find current display or displayInfo map size is error, displayId: %{public}" PRIu64"", + displayId); + return; + } + for (auto& elem : displayRectMap) { - auto iter = displayRectMap_.find(elem.first); - if (iter != displayRectMap_.end()) { + auto iter = oriDisplayRectMap.find(elem.first); + if (iter != oriDisplayRectMap.end()) { UpdateRectInDisplayGroupForAllNodes(elem.first, iter->second, elem.second); - iter->second = elem.second; } } + UpdateDisplayRectAndDisplayGroupInfo(displayRectMap); PostProcessWhenDisplayChange(); WLOGFI("Process display change, displayId: %{public}" PRIu64"", displayId); } @@ -259,16 +294,16 @@ void WindowLayoutPolicy::LayoutWindowNodesByRootType(const std::vectorGetDisplayRect(displayId); // ensure that the avoid area windows are traversed first - LayoutWindowNodesByRootType(*(windowNodeMap[WindowRootNodeType::ABOVE_WINDOW_NODE])); - if (IsFullScreenRecentWindowExist(*(windowNodeMap[WindowRootNodeType::ABOVE_WINDOW_NODE]))) { + LayoutWindowNodesByRootType(*(displayWindowTree[WindowRootNodeType::ABOVE_WINDOW_NODE])); + if (IsFullScreenRecentWindowExist(*(displayWindowTree[WindowRootNodeType::ABOVE_WINDOW_NODE]))) { WLOGFI("recent window on top, early exit layout tree"); return; } - LayoutWindowNodesByRootType(*(windowNodeMap[WindowRootNodeType::APP_WINDOW_NODE])); - LayoutWindowNodesByRootType(*(windowNodeMap[WindowRootNodeType::BELOW_WINDOW_NODE])); + LayoutWindowNodesByRootType(*(displayWindowTree[WindowRootNodeType::APP_WINDOW_NODE])); + LayoutWindowNodesByRootType(*(displayWindowTree[WindowRootNodeType::BELOW_WINDOW_NODE])); } void WindowLayoutPolicy::LayoutWindowNode(const sptr& node) @@ -295,7 +330,7 @@ void WindowLayoutPolicy::LayoutWindowNode(const sptr& node) bool WindowLayoutPolicy::IsVerticalDisplay(DisplayId displayId) const { - return displayRectMap_[displayId].width_ < displayRectMap_[displayId].height_; + return displayGroupInfo_->GetDisplayRect(displayId).width_ < displayGroupInfo_->GetDisplayRect(displayId).height_; } void WindowLayoutPolicy::UpdateClientRectAndResetReason(const sptr& node, @@ -395,7 +430,7 @@ void WindowLayoutPolicy::CalcAndSetNodeHotZone(Rect layoutOutRect, const sptrGetWindowType() == WindowType::WINDOW_TYPE_LAUNCHER_RECENT) { - rect = displayRectMap_[node->GetDisplayId()]; + rect = displayGroupInfo_->GetDisplayRect(node->GetDisplayId()); } else if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { rect.posX_ -= hotZone; rect.posY_ -= hotZone; @@ -434,6 +469,74 @@ void WindowLayoutPolicy::LimitFloatingWindowSize(const sptr& node, } } +DockWindowShowState WindowLayoutPolicy::GetDockWindowShowState(DisplayId displayId, Rect& dockWinRect) const +{ + auto& displayWindowTree = displayGroupWindowTree_[displayId]; + auto& nodeVec = *(displayWindowTree[WindowRootNodeType::ABOVE_WINDOW_NODE]); + for (auto& node : nodeVec) { + if (node->GetWindowType() != WindowType::WINDOW_TYPE_LAUNCHER_DOCK) { + continue; + } + + dockWinRect = node->GetWindowRect(); + auto displayRect = displayGroupInfo_->GetDisplayRect(displayId); + WLOGFI("begin dockWinRect :[%{public}d, %{public}d, %{public}u, %{public}u]", + dockWinRect.posX_, dockWinRect.posY_, dockWinRect.width_, dockWinRect.height_); + if (dockWinRect.height_ < dockWinRect.width_) { + if (static_cast(dockWinRect.posY_) + dockWinRect.height_ == displayRect.height_) { + return DockWindowShowState::SHOWN_IN_BOTTOM; + } else { + return DockWindowShowState::NOT_SHOWN; + } + } else { + if (dockWinRect.posX_ == 0) { + return DockWindowShowState::SHOWN_IN_LEFT; + } else if (static_cast(dockWinRect.posX_) + dockWinRect.width_ == displayRect.width_) { + return DockWindowShowState::SHOWN_IN_RIGHT; + } else { + return DockWindowShowState::NOT_SHOWN; + } + } + } + return DockWindowShowState::NOT_SHOWN; +} + +void WindowLayoutPolicy::LimitMainFloatingWindowPositionWithDrag(const sptr& node, Rect& winRect) const +{ + if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { + float virtualPixelRatio = GetVirtualPixelRatio(node->GetDisplayId()); + uint32_t windowTitleBarH = static_cast(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio); + const Rect lastRect = node->GetWindowRect(); + // fix rect in case of moving window when dragging + winRect = WindowHelper::GetFixedWindowRectByLimitSize(winRect, lastRect, + IsVerticalDisplay(node->GetDisplayId()), virtualPixelRatio); + + // if is mutiDisplay, the limit rect should be full limitRect when move or drag + Rect limitRect; + if (isMultiDisplay_) { + limitRect = displayGroupLimitRect_; + } else { + limitRect = limitRectMap_[node->GetDisplayId()]; + } + winRect = WindowHelper::GetFixedWindowRectByLimitPosition(winRect, lastRect, + virtualPixelRatio, limitRect); + Rect dockWinRect; + DockWindowShowState dockShownState = GetDockWindowShowState(node->GetDisplayId(), dockWinRect); + if (dockShownState == DockWindowShowState::SHOWN_IN_BOTTOM) { + WLOGFI("dock window show in bottom"); + winRect.posY_ = std::min(dockWinRect.posY_ - static_cast(windowTitleBarH), winRect.posY_); + } else if (dockShownState == DockWindowShowState::SHOWN_IN_LEFT) { + WLOGFI("dock window show in left"); + winRect.posX_ = std::max(static_cast(dockWinRect.width_ + windowTitleBarH - winRect.width_), + winRect.posX_); + } else if (dockShownState == DockWindowShowState::SHOWN_IN_RIGHT) { + WLOGFI("dock window show in right"); + winRect.posX_ = std::min(dockWinRect.posX_ - static_cast(windowTitleBarH), + winRect.posX_); + } + } +} + void WindowLayoutPolicy::LimitMainFloatingWindowPosition(const sptr& node, Rect& winRect) const { float virtualPixelRatio = GetVirtualPixelRatio(node->GetDisplayId()); @@ -449,25 +552,42 @@ void WindowLayoutPolicy::LimitMainFloatingWindowPosition(const sptr& // limit position of the main floating window(window which support dragging) if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { + Rect dockWinRect; + DockWindowShowState dockShownState = GetDockWindowShowState(node->GetDisplayId(), dockWinRect); winRect.posY_ = std::max(limitRect.posY_, winRect.posY_); winRect.posY_ = std::min(limitRect.posY_ + static_cast(limitRect.height_ - windowTitleBarH), winRect.posY_); - + if (dockShownState == DockWindowShowState::SHOWN_IN_BOTTOM) { + WLOGFI("dock window show in bottom"); + winRect.posY_ = std::min(dockWinRect.posY_ + static_cast(dockWinRect.height_ - windowTitleBarH), + winRect.posY_); + } winRect.posX_ = std::max(limitRect.posX_ + static_cast(windowTitleBarH - winRect.width_), winRect.posX_); + if (dockShownState == DockWindowShowState::SHOWN_IN_LEFT) { + WLOGFI("dock window show in left"); + winRect.posX_ = std::max(static_cast(dockWinRect.width_ + windowTitleBarH - winRect.width_), + winRect.posX_); + } winRect.posX_ = std::min(limitRect.posX_ + static_cast(limitRect.width_ - windowTitleBarH), winRect.posX_); + if (dockShownState == DockWindowShowState::SHOWN_IN_RIGHT) { + WLOGFI("dock window show in right"); + winRect.posX_ = std::min(dockWinRect.posX_ - static_cast(windowTitleBarH), + winRect.posX_); + } } } AvoidPosType WindowLayoutPolicy::GetAvoidPosType(const Rect& rect, DisplayId displayId) const { - if (displayInfosMap_.find(displayId) == std::end(displayInfosMap_)) { + const auto& displayRectMap = displayGroupInfo_->GetAllDisplayRects(); + if (displayRectMap.find(displayId) == std::end(displayRectMap)) { WLOGFE("GetAvoidPosType fail. Get display fail. displayId: %{public}" PRIu64"", displayId); return AvoidPosType::AVOID_POS_UNKNOWN; } - return WindowHelper::GetAvoidPosType(rect, displayInfosMap_[displayId]->GetWidth(), - displayInfosMap_[displayId]->GetHeight()); + const auto& displayRect = displayGroupInfo_->GetDisplayRect(displayId); + return WindowHelper::GetAvoidPosType(rect, displayRect.width_, displayRect.height_); } void WindowLayoutPolicy::UpdateLimitRect(const sptr& node, Rect& limitRect) @@ -517,14 +637,7 @@ void WindowLayoutPolicy::Reset() float WindowLayoutPolicy::GetVirtualPixelRatio(DisplayId displayId) const { - if (displayInfosMap_.find(displayId) == std::end(displayInfosMap_)) { - return 1.0; // 1.0 is default vpr - } - float virtualPixelRatio = displayInfosMap_[displayId]->GetVirtualPixelRatio(); - if (virtualPixelRatio == 0.0) { - WLOGFE("GetVirtualPixel fail. vpr is 0.0. displayId:%{public}" PRIu64", use Default vpr:1.0", displayId); - return 1.0; // Use DefaultVPR 1.0 - } + float virtualPixelRatio = displayGroupInfo_->GetDisplayVirtualPixelRatio(displayId); WLOGFI("GetVirtualPixel success. displayId:%{public}" PRIu64", vpr:%{public}f", displayId, virtualPixelRatio); return virtualPixelRatio; } diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index 9fcfd9c8..6f99e74b 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -26,9 +26,9 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowLayoutPolicyCascade"}; } -WindowLayoutPolicyCascade::WindowLayoutPolicyCascade(const std::map& displayRectMap, - WindowNodeMaps& windowNodeMaps, std::map>& displayInfosMap) - : WindowLayoutPolicy(displayRectMap, windowNodeMaps, displayInfosMap) +WindowLayoutPolicyCascade::WindowLayoutPolicyCascade(const sptr& displayGroupInfo, + DisplayGroupWindowTree& displayGroupWindowTree) + : WindowLayoutPolicy(displayGroupInfo, displayGroupWindowTree) { CascadeRects cascadeRects { .primaryRect_ = {0, 0, 0, 0}, @@ -38,7 +38,7 @@ WindowLayoutPolicyCascade::WindowLayoutPolicyCascade(const std::mapGetAllDisplayRects()) { cascadeRectsMap_.insert(std::make_pair(iter.first, cascadeRects)); } } @@ -56,8 +56,9 @@ void WindowLayoutPolicyCascade::Clean() void WindowLayoutPolicyCascade::Reset() { + const auto& displayRectMap = displayGroupInfo_->GetAllDisplayRects(); // reset split and limit rects - for (auto& iter : displayRectMap_) { + for (auto& iter : displayRectMap) { InitSplitRects(iter.first); InitLimitRects(iter.first); } @@ -66,15 +67,16 @@ void WindowLayoutPolicyCascade::Reset() void WindowLayoutPolicyCascade::InitAllRects() { - for (auto& iter : displayRectMap_) { + const auto& displayRectMap = displayGroupInfo_->GetAllDisplayRects(); + for (auto& iter : displayRectMap) { // init split and limit rects InitSplitRects(iter.first); InitLimitRects(iter.first); // init full displayRect displayGroupLimitRect_ = displayGroupRect_; // init cascade rect - auto& windowNodeMap = windowNodeMaps_[iter.first]; - LayoutWindowNodesByRootType(*(windowNodeMap[WindowRootNodeType::ABOVE_WINDOW_NODE])); + auto& displayWindowTree = displayGroupWindowTree_[iter.first]; + LayoutWindowNodesByRootType(*(displayWindowTree[WindowRootNodeType::ABOVE_WINDOW_NODE])); InitCascadeRect(iter.first); } } @@ -148,7 +150,7 @@ void WindowLayoutPolicyCascade::UpdateWindowNode(const sptr& node, b node->GetWindowId(), splitDockerRect.posX_, splitDockerRect.posY_, splitDockerRect.width_, splitDockerRect.height_); if (!isAddWindow) { - const auto& appWindowNodeVec = *(windowNodeMaps_[displayId][WindowRootNodeType::APP_WINDOW_NODE]); + const auto& appWindowNodeVec = *(displayGroupWindowTree_[displayId][WindowRootNodeType::APP_WINDOW_NODE]); for (auto& childNode : appWindowNodeVec) { // update split node size change reason if (childNode->IsSplitMode()) { childNode->SetWindowSizeChangeReason(WindowSizeChangeReason::DRAG); @@ -176,10 +178,20 @@ void WindowLayoutPolicyCascade::AddWindowNode(const sptr& node) } if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { node->SetRequestRect(cascadeRectsMap_[node->GetDisplayId()].dividerRect_); // init divider bar + DisplayId displayId = node->GetDisplayId(); + if (!WindowHelper::IsEmptyRect(restoringDividerWindowRects_[displayId])) { + node->SetRequestRect(restoringDividerWindowRects_[displayId]); + } + restoringDividerWindowRects_.erase(displayId); } UpdateWindowNode(node, true); // currently, update and add do the same process } +void WindowLayoutPolicyCascade::SetSplitDividerWindowRects(std::map dividerWindowRects) +{ + restoringDividerWindowRects_ = dividerWindowRects; +} + void WindowLayoutPolicyCascade::LimitMoveBounds(Rect& rect, DisplayId displayId) const { float virtualPixelRatio = GetVirtualPixelRatio(displayId); @@ -212,8 +224,9 @@ void WindowLayoutPolicyCascade::InitCascadeRect(DisplayId displayId) constexpr float ratio = DEFAULT_ASPECT_RATIO; // calculate default H and w - uint32_t defaultW = static_cast(displayRectMap_[displayId].width_ * ratio); - uint32_t defaultH = static_cast(displayRectMap_[displayId].height_ * ratio); + const auto& displayRect = displayGroupInfo_->GetDisplayRect(displayId); + uint32_t defaultW = static_cast(displayRect.width_ * ratio); + uint32_t defaultH = static_cast(displayRect.height_ * ratio); // calculate default x and y Rect resRect = {0, 0, defaultW, defaultH}; @@ -235,32 +248,17 @@ void WindowLayoutPolicyCascade::ApplyWindowRectConstraints(const sptrGetWindowSizeChangeReason(); - float virtualPixelRatio = GetVirtualPixelRatio(node->GetDisplayId()); + if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { // if divider, limit position LimitMoveBounds(winRect, node->GetDisplayId()); } // if drag or move window, limit size and position if (reason == WindowSizeChangeReason::DRAG || reason == WindowSizeChangeReason::MOVE) { - if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { - const Rect lastRect = node->GetWindowRect(); - // fix rect in case of moving window when dragging - winRect = WindowHelper::GetFixedWindowRectByLimitSize(winRect, lastRect, - IsVerticalDisplay(node->GetDisplayId()), virtualPixelRatio); - - // if is mutiDisplay, the limit rect should be full limitRect when move or drag - Rect limitRect; - if (isMultiDisplay_) { - limitRect = displayGroupLimitRect_; - } else { - limitRect = limitRectMap_[node->GetDisplayId()]; - } - winRect = WindowHelper::GetFixedWindowRectByLimitPosition(winRect, lastRect, - virtualPixelRatio, limitRect); - } + LimitMainFloatingWindowPositionWithDrag(node, winRect); } else { // Limit window to the maximum window size if size change is other reason, such as init window rect when show - LimitFloatingWindowSize(node, displayRectMap_[node->GetDisplayId()], winRect); + LimitFloatingWindowSize(node, displayGroupInfo_->GetDisplayRect(node->GetDisplayId()), winRect); LimitMainFloatingWindowPosition(node, winRect); } @@ -316,7 +314,7 @@ void WindowLayoutPolicyCascade::UpdateLayoutRect(const sptr& node) void WindowLayoutPolicyCascade::InitLimitRects(DisplayId displayId) { - limitRectMap_[displayId] = displayRectMap_[displayId]; + limitRectMap_[displayId] = displayGroupInfo_->GetDisplayRect(displayId); cascadeRectsMap_[displayId].primaryLimitRect_ = cascadeRectsMap_[displayId].primaryRect_; cascadeRectsMap_[displayId].secondaryLimitRect_ = cascadeRectsMap_[displayId].secondaryRect_; } @@ -339,7 +337,7 @@ Rect WindowLayoutPolicyCascade::GetDisplayRect(const WindowMode mode, DisplayId } else if (mode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { return cascadeRectsMap_[displayId].secondaryRect_; } else { - return displayRectMap_[displayId]; + return displayGroupInfo_->GetDisplayRect(displayId); } } @@ -361,7 +359,7 @@ void WindowLayoutPolicyCascade::InitSplitRects(DisplayId displayId) float virtualPixelRatio = GetVirtualPixelRatio(displayId); uint32_t dividerWidth = static_cast(DIVIDER_WIDTH * virtualPixelRatio); auto& dividerRect = cascadeRectsMap_[displayId].dividerRect_; - auto& displayRect = displayRectMap_[displayId]; + const auto& displayRect = displayGroupInfo_->GetDisplayRect(displayId); if (!IsVerticalDisplay(displayId)) { dividerRect = { static_cast((displayRect.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO), 0, dividerWidth, displayRect.height_ }; @@ -395,7 +393,7 @@ void WindowLayoutPolicyCascade::SetSplitRect(const Rect& divRect, DisplayId disp auto& dividerRect = cascadeRectsMap_[displayId].dividerRect_; auto& primaryRect = cascadeRectsMap_[displayId].primaryRect_; auto& secondaryRect = cascadeRectsMap_[displayId].secondaryRect_; - auto& displayRect = displayRectMap_[displayId]; + const auto& displayRect = displayGroupInfo_->GetDisplayRect(displayId); dividerRect.width_ = divRect.width_; dividerRect.height_ = divRect.height_; @@ -425,11 +423,11 @@ void WindowLayoutPolicyCascade::SetSplitRect(const Rect& divRect, DisplayId disp void WindowLayoutPolicyCascade::Reorder() { WLOGFI("Cascade reorder start"); - for (auto& iter : displayRectMap_) { + for (auto& iter : displayGroupInfo_->GetAllDisplayRects()) { DisplayId displayId = iter.first; Rect rect = cascadeRectsMap_[displayId].firstCascadeRect_; bool isFirstReorderedWindow = true; - const auto& appWindowNodeVec = *(windowNodeMaps_[displayId][WindowRootNodeType::APP_WINDOW_NODE]); + const auto& appWindowNodeVec = *(displayGroupWindowTree_[displayId][WindowRootNodeType::APP_WINDOW_NODE]); for (auto iter = appWindowNodeVec.begin(); iter != appWindowNodeVec.end(); iter++) { auto node = *iter; if (node == nullptr || node->GetWindowType() != WindowType::WINDOW_TYPE_APP_MAIN_WINDOW) { @@ -443,12 +441,13 @@ void WindowLayoutPolicyCascade::Reorder() } node->SetRequestRect(rect); node->SetDecoStatus(true); - if (node->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING) { - node->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - if (node->GetWindowToken()) { - node->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING); + if (node->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING && + WindowHelper::IsWindowModeSupported(node->GetModeSupportInfo(), WindowMode::WINDOW_MODE_FLOATING)) { + node->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + if (node->GetWindowToken()) { + node->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING); + } } - } WLOGFI("Cascade reorder Id: %{public}d, rect:[%{public}d, %{public}d, %{public}d, %{public}d]", node->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_); } @@ -462,9 +461,9 @@ Rect WindowLayoutPolicyCascade::GetCurCascadeRect(const sptr& node) Rect cascadeRect = {0, 0, 0, 0}; const DisplayId& displayId = node->GetDisplayId(); const auto& appWindowNodeVec = *(const_cast(this)-> - windowNodeMaps_[displayId][WindowRootNodeType::APP_WINDOW_NODE]); + displayGroupWindowTree_[displayId][WindowRootNodeType::APP_WINDOW_NODE]); const auto& aboveAppWindowNodeVec = *(const_cast(this)-> - windowNodeMaps_[displayId][WindowRootNodeType::ABOVE_WINDOW_NODE]); + displayGroupWindowTree_[displayId][WindowRootNodeType::ABOVE_WINDOW_NODE]); std::vector>> roots = { aboveAppWindowNodeVec, appWindowNodeVec }; for (auto& root : roots) { diff --git a/wmserver/src/window_layout_policy_tile.cpp b/wmserver/src/window_layout_policy_tile.cpp index f4a9c7bd..fbf39e2e 100644 --- a/wmserver/src/window_layout_policy_tile.cpp +++ b/wmserver/src/window_layout_policy_tile.cpp @@ -29,11 +29,11 @@ namespace { constexpr uint32_t MID_INTERVAL = 24; } -WindowLayoutPolicyTile::WindowLayoutPolicyTile(const std::map& displayRectMap, - WindowNodeMaps& windowNodeMaps, std::map>& displayInfosMap) - : WindowLayoutPolicy(displayRectMap, windowNodeMaps, displayInfosMap) +WindowLayoutPolicyTile::WindowLayoutPolicyTile(const sptr& displayGroupInfo, + DisplayGroupWindowTree& displayGroupWindowTree) + : WindowLayoutPolicy(displayGroupInfo, displayGroupWindowTree) { - for (auto& iter : displayRectMap) { + for (auto& iter : displayGroupInfo_->GetAllDisplayRects()) { maxTileWinNumMap_.insert(std::make_pair(iter.first, static_cast(1))); } } @@ -44,12 +44,12 @@ void WindowLayoutPolicyTile::Launch() InitAllRects(); // select app min win in queue, and minimize others InitForegroundNodeQueue(); - for (auto& iter : displayRectMap_) { + for (auto& iter : displayGroupInfo_->GetAllDisplayRects()) { DisplayId displayId = iter.first; AssignNodePropertyForTileWindows(displayId); LayoutForegroundNodeQueue(displayId); - auto& windowNodeMap = windowNodeMaps_[displayId]; - LayoutWindowNodesByRootType(*(windowNodeMap[WindowRootNodeType::BELOW_WINDOW_NODE])); + auto& displayWindowTree = displayGroupWindowTree_[displayId]; + LayoutWindowNodesByRootType(*(displayWindowTree[WindowRootNodeType::BELOW_WINDOW_NODE])); } WLOGFI("WindowLayoutPolicyTile::Launch"); } @@ -57,11 +57,11 @@ void WindowLayoutPolicyTile::Launch() void WindowLayoutPolicyTile::InitAllRects() { displayGroupLimitRect_ = displayGroupRect_; - for (auto& iter : displayRectMap_) { + for (auto& iter : displayGroupInfo_->GetAllDisplayRects()) { DisplayId displayId = iter.first; limitRectMap_[displayId] = iter.second; - auto& windowNodeMap = windowNodeMaps_[displayId]; - LayoutWindowNodesByRootType(*(windowNodeMap[WindowRootNodeType::ABOVE_WINDOW_NODE])); + auto& displayWindowTree = displayGroupWindowTree_[displayId]; + LayoutWindowNodesByRootType(*(displayWindowTree[WindowRootNodeType::ABOVE_WINDOW_NODE])); InitTileWindowRects(displayId); } } @@ -86,7 +86,7 @@ void WindowLayoutPolicyTile::InitTileWindowRects(DisplayId displayId) constexpr float ratio = DEFAULT_ASPECT_RATIO; const Rect& limitRect = limitRectMap_[displayId]; - const Rect& displayRect = displayRectMap_[displayId]; + const Rect& displayRect = displayGroupInfo_->GetDisplayRect(displayId); constexpr int half = 2; maxTileWinNumMap_[displayId] = GetMaxTileWinNum(displayId); WLOGFI("set max tile window num %{public}u", maxTileWinNumMap_[displayId]); @@ -180,10 +180,10 @@ void WindowLayoutPolicyTile::LayoutForegroundNodeQueue(DisplayId displayId) void WindowLayoutPolicyTile::InitForegroundNodeQueue() { - for (auto& iter : displayRectMap_) { + for (auto& iter : displayGroupInfo_->GetAllDisplayRects()) { DisplayId displayId = iter.first; foregroundNodesMap_[displayId].clear(); - const auto& appWindowNodes = *(windowNodeMaps_[displayId][WindowRootNodeType::APP_WINDOW_NODE]); + const auto& appWindowNodes = *(displayGroupWindowTree_[displayId][WindowRootNodeType::APP_WINDOW_NODE]); for (auto& node : appWindowNodes) { if (WindowHelper::IsMainWindow(node->GetWindowType())) { ForegroundNodeQueuePushBack(node, displayId); @@ -246,15 +246,17 @@ void WindowLayoutPolicyTile::AssignNodePropertyForTileWindows(DisplayId displayI auto rectIt = presetRect.begin(); for (auto node : foregroundNodesMap_[displayId]) { auto& rect = (*rectIt); - node->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - if (node->GetWindowToken()) { - node->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING); + if (WindowHelper::IsWindowModeSupported(node->GetModeSupportInfo(), WindowMode::WINDOW_MODE_FLOATING)) { + node->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + if (node->GetWindowToken()) { + node->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_FLOATING); + } + node->SetRequestRect(rect); + node->SetDecoStatus(true); + WLOGFI("set rect for qwin id: %{public}d [%{public}d %{public}d %{public}d %{public}d]", + node->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_); + rectIt++; } - node->SetRequestRect(rect); - node->SetDecoStatus(true); - WLOGFI("set rect for qwin id: %{public}d [%{public}d %{public}d %{public}d %{public}d]", - node->GetWindowId(), rect.posX_, rect.posY_, rect.width_, rect.height_); - rectIt++; } } @@ -274,7 +276,7 @@ void WindowLayoutPolicyTile::UpdateLayoutRect(const sptr& node) bool subWindow = WindowHelper::IsSubWindow(type); bool floatingWindow = (mode == WindowMode::WINDOW_MODE_FLOATING); const Rect lastRect = node->GetWindowRect(); - Rect limitRect = displayRectMap_[node->GetDisplayId()]; + Rect limitRect = displayGroupInfo_->GetDisplayRect(node->GetDisplayId()); ComputeDecoratedRequestRect(node); Rect winRect = node->GetRequestRect(); @@ -295,7 +297,7 @@ void WindowLayoutPolicyTile::UpdateLayoutRect(const sptr& node) } } - LimitFloatingWindowSize(node, displayRectMap_[node->GetDisplayId()], winRect); + LimitFloatingWindowSize(node, displayGroupInfo_->GetDisplayRect(node->GetDisplayId()), winRect); LimitMainFloatingWindowPosition(node, winRect); node->SetWindowRect(winRect); diff --git a/wmserver/src/window_manager_config.cpp b/wmserver/src/window_manager_config.cpp index 44a6d4a3..dbfdf44b 100644 --- a/wmserver/src/window_manager_config.cpp +++ b/wmserver/src/window_manager_config.cpp @@ -83,7 +83,11 @@ void WindowManagerConfig::ReadEnableConfigInfo(const xmlNodePtr& currNode) } std::string nodeName = reinterpret_cast(currNode->name); - enableConfig_[nodeName] = xmlStrcmp(enable, reinterpret_cast("true")) ? false : true; + if (!xmlStrcmp(enable, reinterpret_cast("true"))) { + enableConfig_[nodeName] = true; + } else if (!xmlStrcmp(enable, reinterpret_cast("false"))) { + enableConfig_[nodeName] = false; + } xmlFree(enable); } diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 44490565..0a3b0b27 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -47,13 +48,16 @@ const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonCon WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true) { - windowRoot_ = new WindowRoot(mutex_, + windowRoot_ = new WindowRoot( std::bind(&WindowManagerService::OnWindowEvent, this, std::placeholders::_1, std::placeholders::_2)); inputWindowMonitor_ = new InputWindowMonitor(windowRoot_); windowController_ = new WindowController(windowRoot_, inputWindowMonitor_); snapshotController_ = new SnapshotController(windowRoot_); dragController_ = new DragController(windowRoot_); + windowDumper_ = new WindowDumper(windowRoot_); freezeDisplayController_ = new FreezeController(); + wmsTaskLooper_ = std::make_unique(); + startingOpen_ = system::GetParameter("persist.window.sw.enabled", "1") == "1"; // startingWin default enabled } void WindowManagerService::OnStart() @@ -67,6 +71,7 @@ void WindowManagerService::OnStart() DisplayManagerServiceInner::GetInstance().RegisterDisplayChangeListener(listener); RegisterSnapshotHandler(); RegisterWindowManagerServiceHandler(); + wmsTaskLooper_->Start(); } void WindowManagerService::RegisterSnapshotHandler() @@ -179,9 +184,11 @@ bool WindowManagerService::Init() int WindowManagerService::Dump(int fd, const std::vector& args) { if (windowDumper_ == nullptr) { - windowDumper_ = new WindowDumper(windowRoot_, mutex_); + windowDumper_ = new WindowDumper(windowRoot_); } - return static_cast(windowDumper_->Dump(fd, args)); + return wmsTaskLooper_->ScheduleTask([this, fd, &args]() { + return static_cast(windowDumper_->Dump(fd, args)); + }).get(); } void WindowManagerService::ConfigureWindowManagerService() @@ -228,33 +235,44 @@ void WindowManagerService::OnStop() WMError WindowManagerService::NotifyWindowTransition( sptr& fromInfo, sptr& toInfo) { - std::lock_guard lock(mutex_); - return windowController_->NotifyWindowTransition(fromInfo, toInfo); + return wmsTaskLooper_->ScheduleTask([this, &fromInfo, &toInfo]() { + return windowController_->NotifyWindowTransition(fromInfo, toInfo); + }).get(); } WMError WindowManagerService::GetFocusWindowInfo(sptr& abilityToken) { - std::lock_guard lock(mutex_); - return windowController_->GetFocusWindowInfo(abilityToken); + return wmsTaskLooper_->ScheduleTask([this, &abilityToken]() { + return windowController_->GetFocusWindowInfo(abilityToken); + }).get(); } void WindowManagerService::StartingWindow(sptr info, sptr pixelMap, bool isColdStart, uint32_t bkgColor) { - std::lock_guard lock(mutex_); - return windowController_->StartingWindow(info, pixelMap, bkgColor, isColdStart); + if (!startingOpen_) { + WLOGFI("startingWindow not open!"); + return; + } + return wmsTaskLooper_->ScheduleTask([this, &info, &pixelMap, isColdStart, bkgColor]() { + return windowController_->StartingWindow(info, pixelMap, bkgColor, isColdStart); + }).wait(); } void WindowManagerService::CancelStartingWindow(sptr abilityToken) { - std::lock_guard lock(mutex_); - return windowController_->CancelStartingWindow(abilityToken); + if (!startingOpen_) { + WLOGFI("startingWindow not open!"); + return; + } + return wmsTaskLooper_->ScheduleTask([this, &abilityToken]() { + return windowController_->CancelStartingWindow(abilityToken); + }).wait(); } WMError WindowManagerService::CreateWindow(sptr& window, sptr& property, const std::shared_ptr& surfaceNode, uint32_t& windowId, sptr token) { - WM_SCOPED_TRACE("wms:CreateWindow(%u)", windowId); if (window == nullptr || property == nullptr || surfaceNode == nullptr) { WLOGFE("window is invalid"); return WMError::WM_ERROR_NULLPTR; @@ -263,73 +281,83 @@ WMError WindowManagerService::CreateWindow(sptr& window, sptr lock(mutex_); - return windowController_->CreateWindow(window, property, surfaceNode, windowId, token); + return wmsTaskLooper_->ScheduleTask([this, &window, &property, &surfaceNode, &windowId, &token]() { + WM_SCOPED_TRACE("wms:CreateWindow(%u)", windowId); + return windowController_->CreateWindow(window, property, surfaceNode, windowId, token); + }).get(); } WMError WindowManagerService::AddWindow(sptr& property) { - Rect rect = property->GetRequestRect(); - uint32_t windowId = property->GetWindowId(); - WLOGFI("[WMS] Add: %{public}5d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \ - "%{public}4d %{public}4d]", windowId, property->GetWindowType(), property->GetWindowMode(), - property->GetWindowFlags(), rect.posX_, rect.posY_, rect.width_, rect.height_); - WM_SCOPED_TRACE("wms:AddWindow(%u)", windowId); - std::lock_guard lock(mutex_); - WMError res = windowController_->AddWindowNode(property); - if (property->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { - dragController_->StartDrag(windowId); - } - return res; + return wmsTaskLooper_->ScheduleTask([this, &property]() { + Rect rect = property->GetRequestRect(); + uint32_t windowId = property->GetWindowId(); + WLOGFI("[WMS] Add: %{public}5d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \ + "%{public}4d %{public}4d]", windowId, property->GetWindowType(), property->GetWindowMode(), + property->GetWindowFlags(), rect.posX_, rect.posY_, rect.width_, rect.height_); + WM_SCOPED_TRACE("wms:AddWindow(%u)", windowId); + WMError res = windowController_->AddWindowNode(property); + if (property->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { + dragController_->StartDrag(windowId); + } + return res; + }).get(); } WMError WindowManagerService::RemoveWindow(uint32_t windowId) { - WLOGFI("[WMS] Remove: %{public}u", windowId); - WM_SCOPED_TRACE("wms:RemoveWindow(%u)", windowId); - std::lock_guard lock(mutex_); - return windowController_->RemoveWindowNode(windowId); + return wmsTaskLooper_->ScheduleTask([this, windowId]() { + WLOGFI("[WMS] Remove: %{public}u", windowId); + WM_SCOPED_TRACE("wms:RemoveWindow(%u)", windowId); + return windowController_->RemoveWindowNode(windowId); + }).get(); } WMError WindowManagerService::DestroyWindow(uint32_t windowId, bool onlySelf) { - WLOGFI("[WMS] Destroy: %{public}u", windowId); - WM_SCOPED_TRACE("wms:DestroyWindow(%u)", windowId); - std::lock_guard lock(mutex_); - auto node = windowRoot_->GetWindowNode(windowId); - if (node != nullptr && node->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { - dragController_->FinishDrag(windowId); - } - return windowController_->DestroyWindow(windowId, onlySelf); + return wmsTaskLooper_->ScheduleTask([this, windowId, onlySelf]() { + WLOGFI("[WMS] Destroy: %{public}u", windowId); + WM_SCOPED_TRACE("wms:DestroyWindow(%u)", windowId); + auto node = windowRoot_->GetWindowNode(windowId); + if (node != nullptr && node->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { + dragController_->FinishDrag(windowId); + } + return windowController_->DestroyWindow(windowId, onlySelf); + }).get(); } WMError WindowManagerService::RequestFocus(uint32_t windowId) { - WLOGFI("[WMS] RequestFocus: %{public}u", windowId); - WM_SCOPED_TRACE("wms:RequestFocus"); - std::lock_guard lock(mutex_); - return windowController_->RequestFocus(windowId); + return wmsTaskLooper_->ScheduleTask([this, windowId]() { + WLOGFI("[WMS] RequestFocus: %{public}u", windowId); + WM_SCOPED_TRACE("wms:RequestFocus"); + return windowController_->RequestFocus(windowId); + }).get(); } WMError WindowManagerService::SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level) { - WM_SCOPED_TRACE("wms:SetWindowBackgroundBlur"); - std::lock_guard lock(mutex_); - return windowController_->SetWindowBackgroundBlur(windowId, level); + return wmsTaskLooper_->ScheduleTask([this, windowId, level]() { + WM_SCOPED_TRACE("wms:SetWindowBackgroundBlur"); + return windowController_->SetWindowBackgroundBlur(windowId, level); + }).get(); } WMError WindowManagerService::SetAlpha(uint32_t windowId, float alpha) { - WM_SCOPED_TRACE("wms:SetAlpha"); - std::lock_guard lock(mutex_); - return windowController_->SetAlpha(windowId, alpha); + return wmsTaskLooper_->ScheduleTask([this, windowId, alpha]() { + WM_SCOPED_TRACE("wms:SetAlpha"); + return windowController_->SetAlpha(windowId, alpha); + }).get(); } std::vector WindowManagerService::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) { - WLOGFI("[WMS] GetAvoidAreaByType: %{public}u, Type: %{public}u", windowId, static_cast(avoidAreaType)); - std::lock_guard lock(mutex_); - return windowController_->GetAvoidAreaByType(windowId, avoidAreaType); + return wmsTaskLooper_->ScheduleTask([this, windowId, avoidAreaType]() { + WLOGFI("[WMS] GetAvoidAreaByType: %{public}u, Type: %{public}u", windowId, + static_cast(avoidAreaType)); + return windowController_->GetAvoidAreaByType(windowId, avoidAreaType); + }).get(); } void WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType type, @@ -339,11 +367,12 @@ void WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType typ WLOGFE("windowManagerAgent is null"); return; } - std::lock_guard lock(mutex_); - WindowManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type); - if (type == WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR) { // if system bar, notify once - windowController_->NotifySystemBarTints(); - } + return wmsTaskLooper_->ScheduleTask([this, &windowManagerAgent, type]() { + WindowManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type); + if (type == WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR) { // if system bar, notify once + windowController_->NotifySystemBarTints(); + } + }).wait(); } void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType type, @@ -353,8 +382,9 @@ void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType t WLOGFE("windowManagerAgent is null"); return; } - std::lock_guard lock(mutex_); - WindowManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type); + return wmsTaskLooper_->ScheduleTask([this, &windowManagerAgent, type]() { + WindowManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type); + }).wait(); } WMError WindowManagerService::SetWindowAnimationController(const sptr& controller) @@ -364,23 +394,30 @@ WMError WindowManagerService::SetWindowAnimationController(const sptr deathRecipient = new AgentDeathRecipient( - [&mutex](sptr& remoteObject) { - std::lock_guard lock(mutex); - RemoteAnimation::OnRemoteDie(remoteObject); + [this](sptr& remoteObject) { + wmsTaskLooper_->ScheduleTask([&remoteObject]() { + RemoteAnimation::OnRemoteDie(remoteObject); + }).wait(); } ); controller->AsObject()->AddDeathRecipient(deathRecipient); - - std::lock_guard lock(mutex_); - return windowController_->SetWindowAnimationController(controller); + return wmsTaskLooper_->ScheduleTask([this, &controller]() { + return windowController_->SetWindowAnimationController(controller); + }).get(); } -void WindowManagerService::OnWindowEvent(Event event, uint32_t windowId) +void WindowManagerService::OnWindowEvent(Event event, const sptr& remoteObject) { if (event == Event::REMOTE_DIED) { - DestroyWindow(windowId, true); + return wmsTaskLooper_->ScheduleTask([this, &remoteObject, event]() { + uint32_t windowId = windowRoot_->GetWindowIdByObject(remoteObject); + auto node = windowRoot_->GetWindowNode(windowId); + if (node != nullptr && node->GetWindowType() == WindowType::WINDOW_TYPE_DRAGGING_EFFECT) { + dragController_->FinishDrag(windowId); + } + windowController_->DestroyWindow(windowId, true); + }).wait(); } } @@ -392,7 +429,6 @@ void WindowManagerService::NotifyDisplayStateChange(DisplayId id, DisplayStateCh } else if (type == DisplayStateChangeType::UNFREEZE) { freezeDisplayController_->UnfreezeDisplay(id); } else { - std::lock_guard lock(mutex_); return windowController_->NotifyDisplayStateChange(id, type); } } @@ -404,50 +440,57 @@ void DisplayChangeListener::OnDisplayStateChange(DisplayId id, DisplayStateChang void WindowManagerService::ProcessPointDown(uint32_t windowId, bool isStartDrag) { - std::lock_guard lock(mutex_); - windowController_->ProcessPointDown(windowId, isStartDrag); + return wmsTaskLooper_->PostTask([this, windowId, isStartDrag]() { + windowController_->ProcessPointDown(windowId, isStartDrag); + }); } void WindowManagerService::ProcessPointUp(uint32_t windowId) { - std::lock_guard lock(mutex_); - windowController_->ProcessPointUp(windowId); + return wmsTaskLooper_->PostTask([this, windowId]() { + windowController_->ProcessPointUp(windowId); + }); } void WindowManagerService::MinimizeAllAppWindows(DisplayId displayId) { - WLOGFI("displayId %{public}" PRIu64"", displayId); - std::lock_guard lock(mutex_); - windowController_->MinimizeAllAppWindows(displayId); + return wmsTaskLooper_->PostTask([this, displayId]() { + WLOGFI("displayId %{public}" PRIu64"", displayId); + windowController_->MinimizeAllAppWindows(displayId); + }); } -void WindowManagerService::ToggleShownStateForAllAppWindows() +WMError WindowManagerService::ToggleShownStateForAllAppWindows() { - WM_SCOPED_TRACE("wms:ToggleShownStateForAllAppWindows"); - std::lock_guard lock(mutex_); - windowController_->ToggleShownStateForAllAppWindows(); + return wmsTaskLooper_->ScheduleTask([this]() { + WM_SCOPED_TRACE("wms:ToggleShownStateForAllAppWindows"); + return windowController_->ToggleShownStateForAllAppWindows(); + }).get(); } WMError WindowManagerService::MaxmizeWindow(uint32_t windowId) { - WM_SCOPED_TRACE("wms:MaxmizeWindow"); - std::lock_guard lock(mutex_); - return windowController_->MaxmizeWindow(windowId); + return wmsTaskLooper_->ScheduleTask([this, windowId]() { + WM_SCOPED_TRACE("wms:MaxmizeWindow"); + return windowController_->MaxmizeWindow(windowId); + }).get(); } WMError WindowManagerService::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) { - WM_SCOPED_TRACE("wms:GetTopWindowId(%u)", mainWinId); - std::lock_guard lock(mutex_); - return windowController_->GetTopWindowId(mainWinId, topWinId); + return wmsTaskLooper_->ScheduleTask([this, &topWinId, mainWinId]() { + WM_SCOPED_TRACE("wms:GetTopWindowId(%u)", mainWinId); + return windowController_->GetTopWindowId(mainWinId, topWinId); + }).get(); } WMError WindowManagerService::SetWindowLayoutMode(WindowLayoutMode mode) { - WLOGFI("layoutMode: %{public}u", mode); - WM_SCOPED_TRACE("wms:SetWindowLayoutMode"); - std::lock_guard lock(mutex_); - return windowController_->SetWindowLayoutMode(mode); + return wmsTaskLooper_->ScheduleTask([this, mode]() { + WLOGFI("layoutMode: %{public}u", mode); + WM_SCOPED_TRACE("wms:SetWindowLayoutMode"); + return windowController_->SetWindowLayoutMode(mode); + }).get(); } WMError WindowManagerService::UpdateProperty(sptr& windowProperty, PropertyChangeAction action) @@ -456,14 +499,15 @@ WMError WindowManagerService::UpdateProperty(sptr& windowPropert WLOGFE("property is invalid"); return WMError::WM_ERROR_NULLPTR; } - WM_SCOPED_TRACE("wms:UpdateProperty"); - std::lock_guard lock(mutex_); - WMError res = windowController_->UpdateProperty(windowProperty, action); - if (action == PropertyChangeAction::ACTION_UPDATE_RECT && res == WMError::WM_OK && - windowProperty->GetWindowSizeChangeReason() == WindowSizeChangeReason::MOVE) { - dragController_->UpdateDragInfo(windowProperty->GetWindowId()); - } - return res; + return wmsTaskLooper_->ScheduleTask([this, &windowProperty, action]() { + WM_SCOPED_TRACE("wms:UpdateProperty"); + WMError res = windowController_->UpdateProperty(windowProperty, action); + if (action == PropertyChangeAction::ACTION_UPDATE_RECT && res == WMError::WM_OK && + windowProperty->GetWindowSizeChangeReason() == WindowSizeChangeReason::MOVE) { + dragController_->UpdateDragInfo(windowProperty->GetWindowId()); + } + return res; + }).get(); } WMError WindowManagerService::GetAccessibilityWindowInfo(sptr& windowInfo) @@ -472,10 +516,10 @@ WMError WindowManagerService::GetAccessibilityWindowInfo(sptr lock(mutex_); - WMError res = windowRoot_->GetAccessibilityWindowInfo(windowInfo); - return res; + return wmsTaskLooper_->ScheduleTask([this, &windowInfo]() { + WM_SCOPED_TRACE("wms:GetAccessibilityWindowInfo"); + return windowRoot_->GetAccessibilityWindowInfo(windowInfo); + }).get(); } WMError WindowManagerService::GetSystemConfig(SystemConfig& systemConfig) diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index 2aaf4724..7f5c86a1 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -23,6 +23,11 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowNode"}; } +WindowNode::~WindowNode() +{ + WLOGFI("~WindowNode id:%{public}u", GetWindowId()); +} + void WindowNode::SetDisplayId(DisplayId displayId) { property_->SetDisplayId(displayId); @@ -153,6 +158,11 @@ void WindowNode::SetShowingDisplays(const std::vector& displayIdVec) showingDisplays_.assign(displayIdVec.begin(), displayIdVec.end()); } +void WindowNode::SetModeSupportInfo(uint32_t modeSupportInfo) +{ + property_->SetModeSupportInfo(modeSupportInfo); +} + void WindowNode::ResetWindowSizeChangeReason() { windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED; @@ -168,14 +178,14 @@ void WindowNode::SetWindowToken(sptr window) windowToken_ = window; } -void WindowNode::SetCallingPid() +void WindowNode::SetCallingPid(int32_t pid) { - callingPid_ = IPCSkeleton::GetCallingPid(); + property_->SetWindowPid(pid); } -void WindowNode::SetCallingUid() +void WindowNode::SetCallingUid(int32_t uid) { - callingUid_ = IPCSkeleton::GetCallingUid(); + property_->SetWindowPid(uid); } DisplayId WindowNode::GetDisplayId() const @@ -265,12 +275,12 @@ const sptr& WindowNode::GetWindowProperty() const int32_t WindowNode::GetCallingPid() const { - return callingPid_; + return property_->GetWindowPid(); } int32_t WindowNode::GetCallingUid() const { - return callingUid_; + return property_->GetWindowUid(); } const std::unordered_map& WindowNode::GetSystemBarProperty() const @@ -298,5 +308,10 @@ std::vector WindowNode::GetShowingDisplays() const { return showingDisplays_; } + +uint32_t WindowNode::GetModeSupportInfo() const +{ + return property_->GetModeSupportInfo(); +} } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 5279a70f..053c0495 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -41,25 +41,23 @@ namespace { constexpr int WINDOW_NAME_MAX_LENGTH = 10; const char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_animation"; constexpr uint32_t MAX_BRIGHTNESS = 255; + constexpr uint32_t SPLIT_WINDOWS_CNT = 2; } -WindowNodeContainer::WindowNodeContainer(const sptr& displayInfo) +WindowNodeContainer::WindowNodeContainer(const sptr& displayInfo, ScreenId displayGroupId) { DisplayId displayId = displayInfo->GetDisplayId(); - Rect displayRect = { displayInfo->GetOffsetX(), displayInfo->GetOffsetY(), - displayInfo->GetWidth(), displayInfo->GetHeight() }; - displayRectMap_.insert(std::make_pair(displayId, displayRect)); - displayInfosMap_.insert(std::make_pair(displayId, displayInfo)); - // create mutiDisplayController and init nodes and systemBar map for display - displayGroupController_ = new DisplayGroupController(this, displayRectMap_, displayInfosMap_); + // create and displayGroupInfo and displayGroupController + displayGroupInfo_ = new DisplayGroupInfo(displayGroupId, displayInfo); + displayGroupController_ = new DisplayGroupController(this, displayGroupInfo_); displayGroupController_->InitNewDisplay(displayId); // init layout policy - layoutPolicys_[WindowLayoutMode::CASCADE] = new WindowLayoutPolicyCascade(displayRectMap_, - displayGroupController_->windowNodeMaps_, displayInfosMap_); - layoutPolicys_[WindowLayoutMode::TILE] = new WindowLayoutPolicyTile(displayRectMap_, - displayGroupController_->windowNodeMaps_, displayInfosMap_); + layoutPolicys_[WindowLayoutMode::CASCADE] = new WindowLayoutPolicyCascade(displayGroupInfo_, + displayGroupController_->displayGroupWindowTree_); + layoutPolicys_[WindowLayoutMode::TILE] = new WindowLayoutPolicyTile(displayGroupInfo_, + displayGroupController_->displayGroupWindowTree_); layoutPolicy_ = layoutPolicys_[WindowLayoutMode::CASCADE]; layoutPolicy_->Launch(); @@ -131,8 +129,8 @@ WMError WindowNodeContainer::ShowStartingWindow(sptr& node) WLOGFE("Window pair is nullptr"); return WMError::WM_ERROR_NULLPTR; } - windowPair->UpdateIfSplitRelated(node); UpdateWindowTree(node); + windowPair->UpdateIfSplitRelated(node); if (node->IsSplitMode() || node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { RaiseSplitRelatedWindowToTop(node); } @@ -158,9 +156,9 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrUpdateIfSplitRelated(node); UpdateWindowTree(node); - if (node->IsSplitMode() || node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { + windowPair->UpdateIfSplitRelated(node); + if (node->IsSplitMode()) { RaiseSplitRelatedWindowToTop(node); } @@ -169,12 +167,13 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrGetShowingDisplays()) { UpdateRSTree(node, displayId, true, node->isPlayAnimationShow_); } - AssignZOrder(); } else { node->isPlayAnimationShow_ = false; node->startingWindowShown_ = false; + ReZOrderShowWhenLockedWindowIfNeeded(node); } + AssignZOrder(); layoutPolicy_->AddWindowNode(node); if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) { avoidController_->AvoidControl(node, AvoidControlType::AVOID_NODE_ADD); @@ -190,6 +189,10 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrGetWindowType())) { backupWindowIds_.clear(); } + + if (node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { + isScreenLocked_ = true; + } return WMError::WM_OK; } @@ -287,29 +290,49 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) auto emptyVec = std::vector(); node->showingDisplays_.swap(emptyVec); - displayGroupController_->UpdateWindowNodeMaps(); + displayGroupController_->UpdateDisplayGroupWindowTree(); layoutPolicy_->RemoveWindowNode(node); - auto windowPair = displayGroupController_->GetWindowPairByDisplayId(node->GetDisplayId()); - if (windowPair == nullptr) { - WLOGFE("Window pair is nullptr"); + if (HandleRemoveWindow(node) != WMError::WM_OK) { return WMError::WM_ERROR_NULLPTR; } - windowPair->HandleRemoveWindow(node); if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) { avoidController_->AvoidControl(node, AvoidControlType::AVOID_NODE_REMOVE); NotifyIfSystemBarRegionChanged(node->GetDisplayId()); } else { NotifyIfSystemBarTintChanged(node->GetDisplayId()); } + if (WindowHelper::IsMainFullScreenWindow(node->GetWindowType(), node->GetWindowMode())) { + NotifyDockWindowStateChanged(node, true); + } UpdateWindowVisibilityInfos(infos); DumpScreenWindowTree(); NotifyAccessibilityWindowInfo(node, WindowUpdateType::WINDOW_UPDATE_REMOVED); RcoveryScreenDefaultOrientationIfNeed(node->GetDisplayId()); + if (node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { + isScreenLocked_ = false; + } WLOGFI("RemoveWindowNode windowId: %{public}u end", node->GetWindowId()); return WMError::WM_OK; } +WMError WindowNodeContainer::HandleRemoveWindow(sptr& node) +{ + auto windowPair = displayGroupController_->GetWindowPairByDisplayId(node->GetDisplayId()); + if (windowPair == nullptr) { + WLOGFE("Window pair is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + windowPair->HandleRemoveWindow(node); + auto dividerWindow = windowPair->GetDividerWindow(); + auto type = node->GetWindowType(); + if ((type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) && + dividerWindow != nullptr) { + UpdateWindowNode(dividerWindow, WindowUpdateReason::UPDATE_RECT); + } + return WMError::WM_OK; +} + WMError WindowNodeContainer::DestroyWindowNode(sptr& node, std::vector& windowIds) { WMError ret = RemoveWindowNode(node); @@ -369,7 +392,15 @@ void WindowNodeContainer::UpdateWindowTree(sptr& node) RaiseShowWhenLockedWindowIfNeeded(node); auto parentNode = node->parent_; auto position = parentNode->children_.end(); + int splitWindowCnt = 0; for (auto iter = parentNode->children_.begin(); iter < parentNode->children_.end(); ++iter) { + if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE && splitWindowCnt == SPLIT_WINDOWS_CNT) { + position = iter; + break; + } + if (WindowHelper::IsSplitWindowMode((*iter)->GetWindowMode())) { + splitWindowCnt++; + } if ((*iter)->priority_ > node->priority_) { position = iter; break; @@ -425,7 +456,7 @@ bool WindowNodeContainer::UpdateRSTree(sptr& node, DisplayId display void WindowNodeContainer::RcoveryScreenDefaultOrientationIfNeed(DisplayId displayId) { - if (displayGroupController_->windowNodeMaps_[displayId][WindowRootNodeType::APP_WINDOW_NODE]->empty()) { + if (displayGroupController_->displayGroupWindowTree_[displayId][WindowRootNodeType::APP_WINDOW_NODE]->empty()) { WLOGFI("appWindowNode_ child is empty in display %{public}" PRIu64"", displayId); DisplayManagerServiceInner::GetInstance(). SetOrientationFromWindow(displayId, Orientation::UNSPECIFIED); @@ -568,7 +599,7 @@ void WindowNodeContainer::AssignZOrder() return false; }; TraverseWindowTree(func, false); - displayGroupController_->UpdateWindowNodeMaps(); + displayGroupController_->UpdateDisplayGroupWindowTree(); } WMError WindowNodeContainer::SetFocusWindow(uint32_t windowId) @@ -839,6 +870,30 @@ void WindowNodeContainer::NotifySystemBarTints(std::vector displayIdV } } +void WindowNodeContainer::NotifyDockWindowStateChanged(sptr& node, bool isEnable) +{ + WM_FUNCTION_TRACE(); + WLOGFI("begin isEnable: %{public}d", isEnable); + if (isEnable) { + for (auto& windowNode : appWindowNode_->children_) { + if (windowNode->GetWindowId() == node->GetWindowId()) { + continue; + } + if (!WindowHelper::IsFloatintWindow(windowNode->GetWindowMode())) { + return; + } + } + } + SystemBarProperty prop; + prop.enable_ = isEnable; + SystemBarRegionTint tint; + tint.type_ = WindowType::WINDOW_TYPE_LAUNCHER_DOCK; + tint.prop_ = prop; + SystemBarRegionTints tints; + tints.push_back(tint); + WindowManagerAgentController::GetInstance().UpdateSystemBarRegionTints(node->GetDisplayId(), tints); +} + bool WindowNodeContainer::IsTopWindow(uint32_t windowId, sptr& rootNode) const { if (rootNode->children_.empty()) { @@ -1029,13 +1084,12 @@ uint64_t WindowNodeContainer::GetScreenId(DisplayId displayId) const Rect WindowNodeContainer::GetDisplayRect(DisplayId displayId) const { - return const_cast(this)->displayRectMap_[displayId]; + return displayGroupInfo_->GetDisplayRect(displayId); } bool WindowNodeContainer::isVerticalDisplay(DisplayId displayId) const { - return const_cast(this)->displayRectMap_[displayId].width_ < - const_cast(this)->displayRectMap_[displayId].height_; + return displayGroupInfo_->GetDisplayRect(displayId).width_ < displayGroupInfo_->GetDisplayRect(displayId).height_; } void WindowNodeContainer::ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason) @@ -1219,6 +1273,19 @@ sptr WindowNodeContainer::GetNextActiveWindow(uint32_t windowId) con return nullptr; } +bool WindowNodeContainer::IsForbidDockSliceMove(DisplayId displayId) const +{ + auto windowPair = displayGroupController_->GetWindowPairByDisplayId(displayId); + if (windowPair == nullptr) { + WLOGFE("window pair is nullptr"); + return true; + } + if (windowPair->IsForbidDockSliceMove()) { + return true; + } + return false; +} + void WindowNodeContainer::MinimizeAllAppWindows(DisplayId displayId) { WMError ret = MinimizeAppNodeExceptOptions(MinimizeReason::MINIMIZE_ALL); @@ -1246,16 +1313,20 @@ void WindowNodeContainer::MinimizeOldestAppWindow() WLOGFI("no window needs to minimize"); } -void WindowNodeContainer::ToggleShownStateForAllAppWindows(std::function restoreFunc, bool restore) +void WindowNodeContainer::ToggleShownStateForAllAppWindows( + std::function restoreFunc, bool restore) { WLOGFI("ToggleShownStateForAllAppWindows"); // to do, backup reentry: 1.ToggleShownStateForAllAppWindows fast; 2.this display should reset backupWindowIds_. if (!restore && appWindowNode_->children_.empty() && !backupWindowIds_.empty()) { backupWindowIds_.clear(); + backupWindowMode_.clear(); + backupDividerWindowRect_.clear(); } if (!restore && !appWindowNode_->children_.empty() && backupWindowIds_.empty()) { - // backup WLOGFI("backup"); + std::set displayIdSet; + backupWindowMode_.clear(); for (auto& appNode : appWindowNode_->children_) { // exclude exceptional window if (!WindowHelper::IsMainWindow(appNode->GetWindowType())) { @@ -1265,27 +1336,56 @@ void WindowNodeContainer::ToggleShownStateForAllAppWindows(std::functionGetWindowId()); backupWindowIds_.emplace_back(appNode->GetWindowId()); + backupWindowMode_[appNode->GetWindowId()] = appNode->GetWindowMode(); + displayIdSet.insert(appNode->GetDisplayId()); if (appNode->GetWindowToken()) { appNode->GetWindowToken()->UpdateWindowState(WindowState::STATE_HIDDEN); } } - } else if (restore && !backupWindowIds_.empty()) { - // restore - WLOGFI("restore"); - std::vector backupWindowIds(backupWindowIds_); - for (auto windowId: backupWindowIds) { - if (!restoreFunc(windowId)) { - WLOGFE("restore %{public}u failed", windowId); + backupDividerWindowRect_.clear(); + for (auto displayId : displayIdSet) { + auto windowPair = displayGroupController_->GetWindowPairByDisplayId(displayId); + if (windowPair == nullptr || windowPair->GetDividerWindow() == nullptr) { continue; } - WLOGFD("restore %{public}u", windowId); + backupDividerWindowRect_[displayId] = windowPair->GetDividerWindow()->GetWindowRect(); } - backupWindowIds_.clear(); + } else if (restore && !backupWindowIds_.empty()) { + WLOGFI("restore"); + RestoreAllAppWindows(restoreFunc); } else { WLOGFI("do nothing because shown app windows is empty or backup windows is empty."); } } +void WindowNodeContainer::RestoreAllAppWindows(std::function restoreFunc) +{ + std::vector backupWindowIds(backupWindowIds_); + auto displayIds = DisplayManagerServiceInner::GetInstance().GetAllDisplayIds(); + std::vector> windowPairs; + for (auto displayId : displayIds) { + auto windowPair = displayGroupController_->GetWindowPairByDisplayId(displayId); + if (windowPair != nullptr) { + windowPair->SetAllAppWindowsRestoring(true); + windowPairs.emplace_back(windowPair); + } + } + for (auto windowId: backupWindowIds) { + if (!restoreFunc(windowId, backupWindowMode_[windowId])) { + WLOGFE("restore %{public}u failed", windowId); + continue; + } + WLOGFD("restore %{public}u", windowId); + } + for (auto windowPair : windowPairs) { + windowPair->SetAllAppWindowsRestoring(false); + } + layoutPolicy_->SetSplitDividerWindowRects(backupDividerWindowRect_); + backupWindowIds_.clear(); + backupWindowMode_.clear(); + backupDividerWindowRect_.clear(); +} + bool WindowNodeContainer::IsAppWindowsEmpty() const { return appWindowNode_->children_.empty(); @@ -1359,21 +1459,16 @@ WMError WindowNodeContainer::SwitchLayoutPolicy(WindowLayoutMode dstMode, Displa void WindowNodeContainer::RaiseInputMethodWindowPriorityIfNeeded(const sptr& node) const { - if (node->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { + if (node->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT || !isScreenLocked_) { return; } - auto iter = std::find_if(aboveAppWindowNode_->children_.begin(), aboveAppWindowNode_->children_.end(), - [](sptr node) { - return node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD; - }); - if (iter != aboveAppWindowNode_->children_.end()) { - WLOGFI("raise input method float window priority."); - node->priority_ = zorderPolicy_->GetWindowPriority( - WindowType::WINDOW_TYPE_KEYGUARD) + 2; // 2: higher than keyguard and show when locked window - } + + WLOGFI("raise input method float window priority."); + node->priority_ = zorderPolicy_->GetWindowPriority( + WindowType::WINDOW_TYPE_KEYGUARD) + 2; // 2: higher than keyguard and show when locked window } -void WindowNodeContainer::ReZOrderShowWhenLockedWindows(const sptr& node, bool up) +void WindowNodeContainer::ReZOrderShowWhenLockedWindows(bool up) { WLOGFI("Keyguard change %{public}u, re-zorder showWhenLocked window", up); std::vector> needReZOrderNodes; @@ -1405,32 +1500,56 @@ void WindowNodeContainer::ReZOrderShowWhenLockedWindows(const sptr& } parentNode->children_.insert(position, needReZOrderNode); + if (up && WindowHelper::IsSplitWindowMode(needReZOrderNode->GetWindowMode())) { + needReZOrderNode->GetWindowProperty()->ResumeLastWindowMode(); + if (needReZOrderNode->GetWindowToken() != nullptr) { + needReZOrderNode->GetWindowToken()->UpdateWindowMode(needReZOrderNode->GetWindowMode()); + } + auto windowPair = displayGroupController_->GetWindowPairByDisplayId(needReZOrderNode->GetDisplayId()); + if (windowPair == nullptr) { + WLOGFE("Window pair is nullptr"); + return; + } + windowPair->UpdateIfSplitRelated(needReZOrderNode); + } WLOGFI("ShowWhenLocked window %{public}u re-zorder when keyguard change %{public}u", needReZOrderNode->GetWindowId(), up); } } +void WindowNodeContainer::ReZOrderShowWhenLockedWindowIfNeeded(const sptr& node) +{ + if (!(node->GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED)) || + !isScreenLocked_) { + return; + } + + WLOGFI("ShowWhenLocked window %{public}u re-zorder to up", node->GetWindowId()); + ReZOrderShowWhenLockedWindows(true); +} + void WindowNodeContainer::RaiseShowWhenLockedWindowIfNeeded(const sptr& node) { // if keyguard window show, raise show when locked windows if (node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { - ReZOrderShowWhenLockedWindows(node, true); + ReZOrderShowWhenLockedWindows(true); return; } // if show when locked window show, raise itself when exist keyguard - if (!(node->GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED))) { + if (!(node->GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED)) || + !isScreenLocked_) { return; } - auto iter = std::find_if(aboveAppWindowNode_->children_.begin(), aboveAppWindowNode_->children_.end(), - [](sptr node) { - return node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD; - }); - if (iter != aboveAppWindowNode_->children_.end()) { - WLOGFI("ShowWhenLocked window %{public}u raise itself", node->GetWindowId()); - node->priority_ = zorderPolicy_->GetWindowPriority(WindowType::WINDOW_TYPE_KEYGUARD) + 1; - node->parent_ = aboveAppWindowNode_; + WLOGFI("ShowWhenLocked window %{public}u raise itself", node->GetWindowId()); + node->priority_ = zorderPolicy_->GetWindowPriority(WindowType::WINDOW_TYPE_KEYGUARD) + 1; + node->parent_ = aboveAppWindowNode_; + if (WindowHelper::IsSplitWindowMode(node->GetWindowMode())) { + node->GetWindowProperty()->ResumeLastWindowMode(); + if (node->GetWindowToken() != nullptr) { + node->GetWindowToken()->UpdateWindowMode(node->GetWindowMode()); + } } } @@ -1438,7 +1557,7 @@ void WindowNodeContainer::DropShowWhenLockedWindowIfNeeded(const sptrGetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { - ReZOrderShowWhenLockedWindows(node, false); + ReZOrderShowWhenLockedWindows(false); AssignZOrder(); } } @@ -1527,7 +1646,7 @@ void WindowNodeContainer::UpdateWindowVisibilityInfos(std::vectorGetWindowRect(); - const Rect& displayRect = displayRectMap_[node->GetDisplayId()]; + const Rect& displayRect = displayGroupInfo_->GetDisplayRect(node->GetDisplayId()); int32_t nodeX = std::max(0, layoutRect.posX_); int32_t nodeY = std::max(0, layoutRect.posY_); int32_t nodeXEnd = std::min(displayRect.posX_ + static_cast(displayRect.width_), @@ -1589,6 +1708,12 @@ WMError WindowNodeContainer::SetWindowMode(sptr& node, WindowMode ds if (srcMode == dstMode) { return WMError::WM_OK; } + + if (WindowHelper::IsSplitWindowMode(dstMode) && isScreenLocked_ && + (node->GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED))) { + return WMError::WM_ERROR_INVALID_PARAM; + } + WMError res = WMError::WM_OK; if ((srcMode == WindowMode::WINDOW_MODE_FULLSCREEN) && (dstMode == WindowMode::WINDOW_MODE_FLOATING)) { node->SetWindowSizeChangeReason(WindowSizeChangeReason::RECOVER); @@ -1604,6 +1729,14 @@ WMError WindowNodeContainer::SetWindowMode(sptr& node, WindowMode ds return WMError::WM_ERROR_NULLPTR; } windowPair->UpdateIfSplitRelated(node); + if (WindowHelper::IsMainWindow(node->GetWindowType())) { + if (WindowHelper::IsFloatintWindow(node->GetWindowMode())) { + NotifyDockWindowStateChanged(node, true); + } else { + NotifyDockWindowStateChanged(node, false); + } + } + if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && WindowHelper::IsAppWindow(node->GetWindowType())) { // minimize other app window @@ -1627,7 +1760,7 @@ WMError WindowNodeContainer::SetWindowMode(sptr& node, WindowMode ds void WindowNodeContainer::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config) { - auto displayRect = displayRectMap_[displayId]; + const auto& displayRect = displayGroupInfo_->GetDisplayRect(displayId); hotZones.fullscreen_.width_ = displayRect.width_; hotZones.fullscreen_.height_ = config.fullscreenRange_; @@ -1642,18 +1775,12 @@ void WindowNodeContainer::GetModeChangeHotZones(DisplayId displayId, ModeChangeH float WindowNodeContainer::GetDisplayVirtualPixelRatio(DisplayId displayId) const { - if (displayInfosMap_.find(displayId) == std::end(displayInfosMap_)) { - return 1.0; // 1.0 is default vpr - } - return displayInfosMap_.at(displayId)->GetVirtualPixelRatio(); + return displayGroupInfo_->GetDisplayVirtualPixelRatio(displayId); } sptr WindowNodeContainer::GetDisplayInfo(DisplayId displayId) { - if (displayInfosMap_.find(displayId) != std::end(displayInfosMap_)) { - return displayInfosMap_[displayId]; - } - return nullptr; + return displayGroupInfo_->GetDisplayInfo(displayId); } } // namespace Rosen } // namespace OHOS diff --git a/wmserver/src/window_pair.cpp b/wmserver/src/window_pair.cpp index f3475228..5631db88 100644 --- a/wmserver/src/window_pair.cpp +++ b/wmserver/src/window_pair.cpp @@ -29,8 +29,8 @@ namespace { const std::string SPLIT_SCREEN_EVENT_NAME = "common.event.SPLIT_SCREEN"; } -WindowPair::WindowPair(const DisplayId& displayId, WindowNodeMaps& windowNodeMaps) - : displayId_(displayId), windowNodeMaps_(windowNodeMaps) { +WindowPair::WindowPair(const DisplayId& displayId, DisplayGroupWindowTree& displayGroupWindowTree) + : displayId_(displayId), displayGroupWindowTree_(displayGroupWindowTree) { } WindowPair::~WindowPair() @@ -141,6 +141,19 @@ sptr WindowPair::GetSecondaryWindow() const return secondary_; } +bool WindowPair::IsForbidDockSliceMove() const +{ + if (status_ != WindowPairStatus::STATUS_PAIRED_DONE) { + return false; + } + uint32_t flag = static_cast(WindowFlag::WINDOW_FLAG_FORBID_SPLIT_MOVE); + if (primary_ != nullptr && !(primary_->GetWindowFlags() & flag) && secondary_ != nullptr && + !(secondary_->GetWindowFlags() & flag)) { + return false; + } + return true; +} + void WindowPair::Clear() { WLOGI("Clear window pair."); @@ -228,16 +241,16 @@ sptr WindowPair::FindPairableWindow(sptr& node) if (!node->IsSplitMode()) { return nullptr; } - - auto& appNodeVec = *(windowNodeMaps_[displayId_][WindowRootNodeType::APP_WINDOW_NODE]); + auto& appNodeVec = *(displayGroupWindowTree_[displayId_][WindowRootNodeType::APP_WINDOW_NODE]); + WindowMode dstMode = (node->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY ? + WindowMode::WINDOW_MODE_SPLIT_SECONDARY : WindowMode::WINDOW_MODE_SPLIT_PRIMARY); for (auto iter = appNodeVec.rbegin(); iter != appNodeVec.rend(); iter++) { auto pairNode = *iter; if (pairNode == nullptr) { continue; } - if (pairNode->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { - WindowMode dstMode = (node->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY ? - WindowMode::WINDOW_MODE_SPLIT_SECONDARY : WindowMode::WINDOW_MODE_SPLIT_PRIMARY); + if (pairNode->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && + WindowHelper::IsWindowModeSupported(pairNode->GetModeSupportInfo(), dstMode)) { pairNode->SetWindowMode(dstMode); if (pairNode->GetWindowToken() != nullptr) { pairNode->GetWindowToken()->UpdateWindowMode(pairNode->GetWindowMode()); @@ -280,10 +293,12 @@ void WindowPair::UpdateIfSplitRelated(sptr& node) status_, node->GetWindowId(), node->GetWindowMode()); if (status_ == WindowPairStatus::STATUS_EMPTY) { Insert(node); - // find pairable window from trees or send broadcast - sptr pairableNode = GetPairableWindow(node); - // insert pairable node - Insert(pairableNode); + if (!isAllAppWindowsRestoring_) { + // find pairable window from trees or send broadcast + sptr pairableNode = GetPairableWindow(node); + // insert pairable node + Insert(pairableNode); + } } else { if (Find(node) == nullptr) { // add new split related node to pair @@ -331,14 +346,16 @@ void WindowPair::SwitchPosition() WLOGFI("Switch the pair pos, pri: %{public}u pri-mode: %{public}u, sec: %{public}u sec-mode: %{public}u,", primary_->GetWindowId(), primary_->GetWindowMode(), secondary_->GetWindowId(), secondary_->GetWindowMode()); if (primary_->GetWindowMode() == secondary_->GetWindowMode() && - primary_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY) { + primary_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY && + WindowHelper::IsWindowModeSupported(primary_->GetModeSupportInfo(), WindowMode::WINDOW_MODE_SPLIT_SECONDARY)) { primary_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); if (primary_->GetWindowToken() != nullptr) { primary_->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); } std::swap(primary_, secondary_); } else if (primary_->GetWindowMode() == secondary_->GetWindowMode() && - primary_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { + primary_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_SECONDARY && + WindowHelper::IsWindowModeSupported(secondary_->GetModeSupportInfo(), WindowMode::WINDOW_MODE_SPLIT_PRIMARY)) { secondary_->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); if (secondary_->GetWindowToken() != nullptr) { secondary_->GetWindowToken()->UpdateWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); @@ -430,5 +447,10 @@ void WindowPair::HandleRemoveWindow(sptr& node) Clear(); } } + +void WindowPair::SetAllAppWindowsRestoring(bool isAllAppWindowsRestoring) +{ + isAllAppWindowsRestoring_ = isAllAppWindowsRestoring; +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index e7850efa..7d916d07 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -23,6 +23,7 @@ #include "window_helper.h" #include "window_manager_hilog.h" #include "window_manager_service.h" +#include "wm_trace.h" namespace OHOS { namespace Rosen { @@ -30,9 +31,22 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowRoot"}; } -std::map> WindowRoot::GetWindowNodeMap() +uint32_t WindowRoot::GetTotalWindowNum() const { - return windowNodeMap_; + return static_cast(windowNodeMap_.size()); +} + +sptr WindowRoot::GetWindowForDumpAceHelpInfo() const +{ + for (auto& iter : windowNodeMap_) { + if (iter.second->GetWindowType() == WindowType::WINDOW_TYPE_DESKTOP || + iter.second->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR || + iter.second->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR || + iter.second->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) { + return iter.second; + } + } + return nullptr; } ScreenId WindowRoot::GetScreenGroupId(DisplayId displayId, bool& isRecordedDisplay) @@ -52,12 +66,12 @@ ScreenId WindowRoot::GetScreenGroupId(DisplayId displayId, bool& isRecordedDispl sptr WindowRoot::GetOrCreateWindowNodeContainer(DisplayId displayId) { bool isRecordedDisplay; - ScreenId screenGroupId = GetScreenGroupId(displayId, isRecordedDisplay); - auto iter = windowNodeContainerMap_.find(screenGroupId); + ScreenId displayGroupId = GetScreenGroupId(displayId, isRecordedDisplay); + auto iter = windowNodeContainerMap_.find(displayGroupId); if (iter != windowNodeContainerMap_.end()) { // if container exist for screenGroup and display is not be recorded, process expand display if (!isRecordedDisplay) { - ProcessExpandDisplayCreate(displayId, screenGroupId); + ProcessExpandDisplayCreate(displayId, displayGroupId); } return iter->second; } @@ -75,14 +89,14 @@ sptr WindowRoot::CreateWindowNodeContainer(DisplayId displa return nullptr; } - ScreenId screenGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); + ScreenId displayGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); WLOGFI("create new container for display, width: %{public}d, height: %{public}d, " - "screenGroupId:%{public}" PRIu64", displayId:%{public}" PRIu64"", displayInfo->GetWidth(), - displayInfo->GetHeight(), screenGroupId, displayId); - sptr container = new WindowNodeContainer(displayInfo); - windowNodeContainerMap_.insert(std::make_pair(screenGroupId, container)); + "displayGroupId:%{public}" PRIu64", displayId:%{public}" PRIu64"", displayInfo->GetWidth(), + displayInfo->GetHeight(), displayGroupId, displayId); + sptr container = new WindowNodeContainer(displayInfo, displayGroupId); + windowNodeContainerMap_.insert(std::make_pair(displayGroupId, container)); std::vector displayVec = { displayId }; - displayIdMap_.insert(std::make_pair(screenGroupId, displayVec)); + displayIdMap_.insert(std::make_pair(displayGroupId, displayVec)); return container; } @@ -192,8 +206,14 @@ WMError WindowRoot::SaveWindow(const sptr& node) AddDeathRecipient(node); } // Register FirstFrame Callback to rs, inform ability to get snapshot - auto firstFrameCompleteCallback = [node]() { - AAFwk::AbilityManagerClient::GetInstance()->CompleteFirstFrameDrawing(node->abilityToken_); + wptr weak = node; + auto firstFrameCompleteCallback = [weak]() { + auto weakNode = weak.promote(); + if (weakNode == nullptr) { + WLOGFE("windowNode is nullptr"); + return; + } + AAFwk::AbilityManagerClient::GetInstance()->CompleteFirstFrameDrawing(weakNode->abilityToken_); }; if (node->surfaceNode_ && WindowHelper::IsMainWindow(node->GetWindowType())) { node->surfaceNode_->SetBufferAvailableCallback(firstFrameCompleteCallback); @@ -203,6 +223,7 @@ WMError WindowRoot::SaveWindow(const sptr& node) WMError WindowRoot::MinimizeStructuredAppWindowsExceptSelf(sptr& node) { + WM_SCOPED_TRACE("root:MinimizeStructuredAppWindowsExceptSelf"); auto container = GetOrCreateWindowNodeContainer(node->GetDisplayId()); if (container == nullptr) { WLOGFE("MinimizeAbility failed, window container could not be found"); @@ -211,6 +232,16 @@ WMError WindowRoot::MinimizeStructuredAppWindowsExceptSelf(sptr& nod return container->MinimizeStructuredAppWindowsExceptSelf(node); } +bool WindowRoot::IsForbidDockSliceMove(DisplayId displayId) const +{ + auto container = const_cast(this)->GetOrCreateWindowNodeContainer(displayId); + if (container == nullptr) { + WLOGFE("can't find container"); + return true; + } + return container->IsForbidDockSliceMove(displayId); +} + std::vector WindowRoot::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) { std::vector avoidArea; @@ -254,7 +285,7 @@ void WindowRoot::ToggleShownStateForAllAppWindows() } std::for_each(containers.begin(), containers.end(), [this, isAllAppWindowsEmpty] (sptr container) { - std::function restoreFunc = [this](uint32_t windowId) { + auto restoreFunc = [this](uint32_t windowId, WindowMode mode) { auto windowNode = GetWindowNode(windowId); if (windowNode == nullptr) { return false; @@ -267,6 +298,10 @@ void WindowRoot::ToggleShownStateForAllAppWindows() if (property == nullptr) { return false; } + if (mode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || + mode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY) { + property->SetWindowMode(mode); + } WindowManagerService::GetInstance().AddWindow(property); return true; }; @@ -297,6 +332,55 @@ WMError WindowRoot::MaxmizeWindow(uint32_t windowId) return WMError::WM_OK; } +void WindowRoot::DestroyLeakStartingWindow() +{ + std::vector destroyIds; + for (auto& iter : windowNodeMap_) { + if (iter.second->startingWindowShown_ && !iter.second->GetWindowToken()) { + destroyIds.push_back(iter.second->GetWindowId()); + } + } + for (auto& id : destroyIds) { + WLOGFI("Destroy Window id:%{public}u", id); + DestroyWindow(id, false); + } +} + +WMError WindowRoot::PostProcessAddWindowNode(sptr& node, sptr& parentNode, + sptr& container) +{ + if (WindowHelper::IsSubWindow(node->GetWindowType())) { + if (parentNode == nullptr) { + WLOGFE("window type is invalid"); + return WMError::WM_ERROR_INVALID_TYPE; + } + sptr parent = nullptr; + container->RaiseZOrderForAppWindow(parentNode, parent); + } + if (node->GetWindowProperty()->GetFocusable()) { + container->SetFocusWindow(node->GetWindowId()); + needCheckFocusWindow = true; + } + container->SetActiveWindow(node->GetWindowId(), false); + NotifyKeyboardSizeChangeInfo(node, container, node->GetWindowRect()); + for (auto& child : node->children_) { + if (child == nullptr || !child->currentVisibility_) { + break; + } + HandleKeepScreenOn(child->GetWindowId(), child->IsKeepScreenOn()); + } + HandleKeepScreenOn(node->GetWindowId(), node->IsKeepScreenOn()); + WLOGFI("windowId:%{public}u, name:%{public}s, orientation:%{public}u, type:%{public}u, isMainWindow:%{public}d", + node->GetWindowId(), node->GetWindowName().c_str(), static_cast(node->GetRequestedOrientation()), + node->GetWindowType(), WindowHelper::IsMainWindow(node->GetWindowType())); + if (WindowHelper::IsMainWindow(node->GetWindowType()) && + node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { + DisplayManagerServiceInner::GetInstance(). + SetOrientationFromWindow(node->GetDisplayId(), node->GetRequestedOrientation()); + } + return WMError::WM_OK; +} + WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr& node, bool fromStartingWin) { if (node == nullptr) { @@ -309,6 +393,16 @@ WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr& node, boo WLOGFE("add window failed, window container could not be found"); return WMError::WM_ERROR_NULLPTR; } + if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && + WindowHelper::IsAppWindow(node->GetWindowType()) && !node->isPlayAnimationShow_) { + container->NotifyDockWindowStateChanged(node, false); + WMError res = MinimizeStructuredAppWindowsExceptSelf(node); + if (res != WMError::WM_OK) { + WLOGFE("Minimize other structured window failed"); + MinimizeApp::ClearNodesWithReason(MinimizeReason::OTHER_WINDOW); + return res; + } + } if (fromStartingWin) { return container->ShowStartingWindow(node); } @@ -320,38 +414,15 @@ WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr& node, boo auto parentNode = GetWindowNode(parentId); WMError res = container->AddWindowNode(node, parentNode); - if (res == WMError::WM_OK && WindowHelper::IsSubWindow(node->GetWindowType())) { - if (parentNode == nullptr) { - WLOGFE("window type is invalid"); - return WMError::WM_ERROR_INVALID_TYPE; - } - sptr parent = nullptr; - container->RaiseZOrderForAppWindow(parentNode, parent); + if (!WindowHelper::IsSystemWindow(node->GetWindowType())) { + DestroyLeakStartingWindow(); } - if (res == WMError::WM_OK && node->GetWindowProperty()->GetFocusable()) { - container->SetFocusWindow(node->GetWindowId()); - needCheckFocusWindow = true; + if (res != WMError::WM_OK) { + WLOGFE("AddWindowNode failed with ret: %{public}u", static_cast(res)); + return res; } - if (res == WMError::WM_OK) { - container->SetActiveWindow(node->GetWindowId(), false); - NotifyKeyboardSizeChangeInfo(node, container, node->GetWindowRect()); - for (auto& child : node->children_) { - if (child == nullptr || !child->currentVisibility_) { - break; - } - HandleKeepScreenOn(child->GetWindowId(), child->IsKeepScreenOn()); - } - HandleKeepScreenOn(node->GetWindowId(), node->IsKeepScreenOn()); - } - WLOGFI("windowId:%{public}u, name:%{public}s, orientation:%{public}u, type:%{public}u, isMainWindow:%{public}d", - node->GetWindowId(), node->GetWindowName().c_str(), static_cast(node->GetRequestedOrientation()), - node->GetWindowType(), WindowHelper::IsMainWindow(node->GetWindowType())); - if (res == WMError::WM_OK && WindowHelper::IsMainWindow(node->GetWindowType()) && - node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) { - DisplayManagerServiceInner::GetInstance(). - SetOrientationFromWindow(node->GetDisplayId(), node->GetRequestedOrientation()); - } - return res; + + return PostProcessAddWindowNode(node, parentNode, container); } WMError WindowRoot::RemoveWindowNode(uint32_t windowId) @@ -555,6 +626,7 @@ WMError WindowRoot::DestroyWindowInner(sptr& node) windowIdMap_.erase(window->AsObject()); } windowNodeMap_.erase(node->GetWindowId()); + WLOGFI("destroy window node use_count:%{public}d", node->GetSptrRefCount()); return WMError::WM_OK; } @@ -768,16 +840,15 @@ WMError WindowRoot::RaiseZOrderForAppWindow(sptr& node) return container->RaiseZOrderForAppWindow(node, parentNode); } +uint32_t WindowRoot::GetWindowIdByObject(const sptr& remoteObject) +{ + auto iter = windowIdMap_.find(remoteObject); + return iter == std::end(windowIdMap_) ? INVALID_WINDOW_ID : iter->second; +} + void WindowRoot::OnRemoteDied(const sptr& remoteObject) { - std::lock_guard lock(mutex_); - auto iter = windowIdMap_.find(remoteObject); - if (iter == windowIdMap_.end()) { - WLOGFE("window id could not be found"); - return; - } - uint32_t windowId = iter->second; - callback_(Event::REMOTE_DIED, windowId); + callback_(Event::REMOTE_DIED, remoteObject); } WMError WindowRoot::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) @@ -895,24 +966,24 @@ void WindowRoot::FocusFaultDetection() const } } -void WindowRoot::ProcessExpandDisplayCreate(DisplayId displayId, ScreenId screenGroupId) +void WindowRoot::ProcessExpandDisplayCreate(DisplayId displayId, ScreenId displayGroupId) { const sptr displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); if (displayInfo == nullptr || !CheckDisplayInfo(displayInfo)) { WLOGFE("get display failed or get invailed display info, displayId :%{public}" PRIu64 "", displayId); return; } - auto container = windowNodeContainerMap_[screenGroupId]; + auto container = windowNodeContainerMap_[displayGroupId]; if (container == nullptr) { WLOGFE("window node container is nullptr, displayId :%{public}" PRIu64 "", displayId); } // add displayId in displayId vector - displayIdMap_[screenGroupId].push_back(displayId); + displayIdMap_[displayGroupId].push_back(displayId); WLOGFI("[Display Create] before add new display, displayId: %{public}" PRIu64"", displayId); - auto displayInfoMap = GetAllDisplayInfos(displayIdMap_[screenGroupId]); - container->GetMutiDisplayController()->ProcessDisplayCreate(displayId, displayInfoMap); + auto displayRectMap = GetAllDisplayRects(displayIdMap_[displayGroupId]); + container->GetMutiDisplayController()->ProcessDisplayCreate(displayId, displayRectMap); WLOGFI("[Display Create] Container exist, add new display, displayId: %{public}" PRIu64"", displayId); } @@ -928,20 +999,35 @@ std::map> WindowRoot::GetAllDisplayInfos(const std: return displayInfoMap; } +std::map WindowRoot::GetAllDisplayRects(const std::vector& displayIdVec) +{ + std::map displayRectMap; + for (auto& displayId : displayIdVec) { + auto displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); + Rect displayRect = { displayInfo->GetOffsetX(), displayInfo->GetOffsetY(), + displayInfo->GetWidth(), displayInfo->GetHeight() }; + displayRectMap.insert(std::make_pair(displayId, displayRect)); + + WLOGFI("displayId: %{public}" PRIu64", displayRect: [ %{public}d, %{public}d, %{public}d, %{public}d]", + displayId, displayRect.posX_, displayRect.posY_, displayRect.width_, displayRect.height_); + } + return displayRectMap; +} + void WindowRoot::ProcessDisplayCreate(DisplayId displayId) { - ScreenId screenGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); - auto iter = windowNodeContainerMap_.find(screenGroupId); + ScreenId displayGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); + auto iter = windowNodeContainerMap_.find(displayGroupId); if (iter == windowNodeContainerMap_.end()) { CreateWindowNodeContainer(displayId); WLOGFI("[Display Create] Create new container for display, displayId: %{public}" PRIu64"", displayId); } else { - auto& displayIdVec = displayIdMap_[screenGroupId]; + auto& displayIdVec = displayIdMap_[displayGroupId]; if (std::find(displayIdVec.begin(), displayIdVec.end(), displayId) != displayIdVec.end()) { WLOGFI("[Display Create] Current display is already exist, displayId: %{public}" PRIu64"", displayId); return; } - ProcessExpandDisplayCreate(displayId, screenGroupId); + ProcessExpandDisplayCreate(displayId, displayGroupId); } } @@ -964,9 +1050,9 @@ void WindowRoot::MoveNotShowingWindowToDefaultDisplay(DisplayId displayId) void WindowRoot::ProcessDisplayDestroy(DisplayId displayId) { - ScreenId screenGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); - auto& displayIdVec = displayIdMap_[screenGroupId]; - auto iter = windowNodeContainerMap_.find(screenGroupId); + ScreenId displayGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); + auto& displayIdVec = displayIdMap_[displayGroupId]; + auto iter = windowNodeContainerMap_.find(displayGroupId); if (iter == windowNodeContainerMap_.end() || std::find(displayIdVec.begin(), displayIdVec.end(), displayId) == displayIdVec.end()) { WLOGFE("[Display Destroy] could not find display, destroy failed, displayId: %{public}" PRIu64"", displayId); @@ -986,8 +1072,8 @@ void WindowRoot::ProcessDisplayDestroy(DisplayId displayId) WLOGFI("[Display Destroy] displayId: %{public}" PRIu64"", displayId); std::vector needDestoryWindows; - auto displayInfoMap = GetAllDisplayInfos(displayIdVec); - container->GetMutiDisplayController()->ProcessDisplayDestroy(displayId, displayInfoMap, needDestoryWindows); + auto displayRectMap = GetAllDisplayRects(displayIdVec); + container->GetMutiDisplayController()->ProcessDisplayDestroy(displayId, displayRectMap, needDestoryWindows); for (auto id : needDestoryWindows) { auto node = GetWindowNode(id); if (node != nullptr) { @@ -1001,9 +1087,9 @@ void WindowRoot::ProcessDisplayDestroy(DisplayId displayId) void WindowRoot::ProcessDisplayChange(DisplayId displayId, DisplayStateChangeType type) { - ScreenId screenGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); - auto& displayIdVec = displayIdMap_[screenGroupId]; - auto iter = windowNodeContainerMap_.find(screenGroupId); + ScreenId displayGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); + auto& displayIdVec = displayIdMap_[displayGroupId]; + auto iter = windowNodeContainerMap_.find(displayGroupId); if (iter == windowNodeContainerMap_.end() || std::find(displayIdVec.begin(), displayIdVec.end(), displayId) == displayIdVec.end()) { WLOGFE("[Display Change] could not find display, change failed, displayId: %{public}" PRIu64"", displayId); @@ -1016,8 +1102,8 @@ void WindowRoot::ProcessDisplayChange(DisplayId displayId, DisplayStateChangeTyp return; } - auto displayInfoMap = GetAllDisplayInfos(displayIdVec); - container->GetMutiDisplayController()->ProcessDisplayChange(displayId, displayInfoMap, type); + auto displayRectMap = GetAllDisplayRects(displayIdVec); + container->GetMutiDisplayController()->ProcessDisplayChange(displayId, displayRectMap, type); } float WindowRoot::GetVirtualPixelRatio(DisplayId displayId) const diff --git a/wmserver/src/window_task_looper.cpp b/wmserver/src/window_task_looper.cpp new file mode 100644 index 00000000..914185e1 --- /dev/null +++ b/wmserver/src/window_task_looper.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "window_task_looper.h" + +namespace OHOS { +namespace Rosen { +void WindowTaskLooper::PostTask(const Task& task) +{ + { + std::lock_guard lock(mtx_); + taskQ_.emplace_back(task); + } + WakeUp(); +} + +void WindowTaskLooper::WaitTask() +{ + std::unique_lock lock(mtx_); + if (!wakeUp_ && taskQ_.empty()) { + taskCond_.wait( + lock, + [this] () { + return !taskQ_.empty() || wakeUp_; + }); + } + wakeUp_ = false; +} + +void WindowTaskLooper::WakeUp() +{ + std::lock_guard lock(mtx_); + wakeUp_ = true; + taskCond_.notify_one(); +} + +void WindowTaskLooper::Start() noexcept +{ + taskProcessThread_ = std::make_unique([this]() { + TaskProcessThread(); + }); + taskProcessThread_->detach(); +} + +void WindowTaskLooper::TaskProcessThread() +{ + if (running_) { + return; + } + running_ = true; + while (running_) { + WaitTask(); + ExecuteAllTask(); + } +} + +void WindowTaskLooper::ExecuteAllTask() +{ + std::vector tasks; + { + std::lock_guard lock(mtx_); + tasks.swap(taskQ_); + } + for (const auto& task : tasks) { + if (task != nullptr) { + task(); + } + } +} + +bool WindowTaskLooper::IsRunning() +{ + return running_; +} + +WindowTaskLooper::~WindowTaskLooper() +{ + std::lock_guard lock(mtx_); + running_ = false; + taskQ_.clear(); +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wmserver/src/zidl/window_manager_proxy.cpp b/wmserver/src/zidl/window_manager_proxy.cpp index 068a2fb3..dff42403 100644 --- a/wmserver/src/zidl/window_manager_proxy.cpp +++ b/wmserver/src/zidl/window_manager_proxy.cpp @@ -410,20 +410,26 @@ void WindowManagerProxy::MinimizeAllAppWindows(DisplayId displayId) } } -void WindowManagerProxy::ToggleShownStateForAllAppWindows() +WMError WindowManagerProxy::ToggleShownStateForAllAppWindows() { MessageParcel data; MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); + MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("WriteInterfaceToken failed"); - return; + return WMError::WM_ERROR_IPC_FAILED; } if (Remote()->SendRequest( static_cast(WindowManagerMessage::TRANS_ID_TOGGLE_SHOWN_STATE_FOR_ALL_APP_WINDOWS), data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); + return WMError::WM_ERROR_IPC_FAILED; } + int32_t ret; + if (!reply.ReadInt32(ret)) { + return WMError::WM_ERROR_IPC_FAILED; + } + return static_cast(ret); } WMError WindowManagerProxy::MaxmizeWindow(uint32_t windowId) diff --git a/wmserver/src/zidl/window_manager_stub.cpp b/wmserver/src/zidl/window_manager_stub.cpp index 61056aa0..c7c32da8 100644 --- a/wmserver/src/zidl/window_manager_stub.cpp +++ b/wmserver/src/zidl/window_manager_stub.cpp @@ -31,6 +31,8 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M WLOGFE("InterfaceToken check failed"); return -1; } + int32_t pid = IPCSkeleton::GetCallingPid(); + int32_t uid = IPCSkeleton::GetCallingUid(); WindowManagerMessage msgId = static_cast(code); switch (msgId) { case WindowManagerMessage::TRANS_ID_CREATE_WINDOW: { @@ -45,6 +47,8 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M } else { WLOGFI("accept token is nullptr"); } + windowProperty->SetWindowPid(pid); + windowProperty->SetWindowUid(uid); WMError errCode = CreateWindow(windowProxy, windowProperty, surfaceNode, windowId, token); reply.WriteUint32(windowId); reply.WriteInt32(static_cast(errCode)); @@ -52,6 +56,8 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M } case WindowManagerMessage::TRANS_ID_ADD_WINDOW: { sptr windowProperty = data.ReadStrongParcelable(); + windowProperty->SetWindowPid(pid); + windowProperty->SetWindowUid(uid); WMError errCode = AddWindow(windowProperty); reply.WriteInt32(static_cast(errCode)); break; @@ -144,7 +150,8 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M break; } case WindowManagerMessage::TRANS_ID_TOGGLE_SHOWN_STATE_FOR_ALL_APP_WINDOWS: { - ToggleShownStateForAllAppWindows(); + WMError errCode = ToggleShownStateForAllAppWindows(); + reply.WriteInt32(static_cast(errCode)); break; } case WindowManagerMessage::TRANS_ID_MAXMIZE_WINDOW: {