From 4d7fe151ffc671bf895e4658e15825f08d0dbfb6 Mon Sep 17 00:00:00 2001 From: zhirong <215782872@qq.com> Date: Wed, 15 Jun 2022 14:29:48 +0800 Subject: [PATCH] add st for window mode support Signed-off-by: zhirong <215782872@qq.com> Change-Id: I57724f0b6dadd4e5469643db74812380634338b5 Signed-off-by: zhirong <215782872@qq.com> --- interfaces/innerkits/wm/window.h | 1 + utils/src/window_property.cpp | 1 + wm/include/window_impl.h | 2 +- wm/src/window_impl.cpp | 7 +- wm/test/systemtest/BUILD.gn | 12 + .../window_mode_support_info_test.cpp | 237 ++++++++++++++++++ wmserver/include/window_node_container.h | 2 +- wmserver/include/window_root.h | 2 +- wmserver/src/window_manager_service.cpp | 4 +- wmserver/src/window_node_container.cpp | 4 +- wmserver/src/window_root.cpp | 2 +- 11 files changed, 263 insertions(+), 11 deletions(-) create mode 100644 wm/test/systemtest/window_mode_support_info_test.cpp diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 1e46df3a..24cbf7d1 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -217,6 +217,7 @@ public: virtual void SetRequestedOrientation(Orientation) = 0; virtual Orientation GetRequestedOrientation() = 0; virtual void SetModeSupportInfo(uint32_t modeSupportInfo) = 0; + virtual uint32_t GetModeSupportInfo() const = 0; virtual bool IsDecorEnable() const = 0; virtual WMError Maximize() = 0; diff --git a/utils/src/window_property.cpp b/utils/src/window_property.cpp index a77f987c..67d20dce 100644 --- a/utils/src/window_property.cpp +++ b/utils/src/window_property.cpp @@ -546,6 +546,7 @@ bool WindowProperty::WriteMemberVariable(Parcel& parcel, const MemberVariable& m } return true; } + void WindowProperty::ReadMemberVariable(Parcel& parcel, const MemberVariable& mv) { void* mvData = reinterpret_cast(this) + mv.offset_; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index da385b63..68628e15 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -94,7 +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; + uint32_t GetModeSupportInfo() const override; inline NotifyNativeWinDestroyFunc GetNativeDestroyCallback() { return notifyNativefunc_; diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index fee33011..16b6e1a2 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1479,10 +1479,9 @@ void WindowImpl::UpdateRect(const struct Rect& rect, bool decoStatus, WindowSize Rect rectToAce = rect; // update rectToAce for stretchable window if (windowSystemConfig_.isStretchable_ && WindowHelper::IsMainFloatingWindow(GetType(), GetMode())) { - if (reason == WindowSizeChangeReason::DRAG || - reason == WindowSizeChangeReason::DRAG_END || - reason == WindowSizeChangeReason::DRAG_START || - reason == WindowSizeChangeReason::RECOVER) { + if (reason == WindowSizeChangeReason::DRAG || reason == WindowSizeChangeReason::DRAG_END || + reason == WindowSizeChangeReason::DRAG_START || reason == WindowSizeChangeReason::RECOVER || + reason == WindowSizeChangeReason::MOVE) { rectToAce = originRect; } else { property_->SetOriginRect(rect); diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn index 870028ce..a016803d 100644 --- a/wm/test/systemtest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -27,6 +27,7 @@ group("systemtest") { ":wm_window_immersive_test", ":wm_window_input_method_test", ":wm_window_layout_test", + ":wm_window_mode_support_info_test", ":wm_window_move_drag_test", ":wm_window_multi_ability_test", ":wm_window_occupied_area_change_test", @@ -219,6 +220,17 @@ ohos_systemtest("wm_window_outside_pressed_test") { ## SystemTest wm_window_outside_pressed_test }}} +## SystemTest wm_window_mode_support_info_test {{{ +ohos_systemtest("wm_window_mode_support_info_test") { + module_out_path = module_out_path + + sources = [ "window_mode_support_info_test.cpp" ] + + deps = [ ":wm_systemtest_common" ] +} + +## SystemTest wm_window_mode_support_info_test }}} + ## Build wm_systemtest_common.a {{{ config("wm_systemtest_common_public_config") { include_dirs = [ diff --git a/wm/test/systemtest/window_mode_support_info_test.cpp b/wm/test/systemtest/window_mode_support_info_test.cpp new file mode 100644 index 00000000..bd93d8e9 --- /dev/null +++ b/wm/test/systemtest/window_mode_support_info_test.cpp @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2021-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. + */ + +// gtest +#include +#include "window_manager.h" +#include "window_test_utils.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using utils = WindowTestUtils; +class WindowModeSupportInfoTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + utils::TestWindowInfo fullScreenAppInfo_; + utils::TestWindowInfo floatingScreenAppInfo_; +private: + static constexpr uint32_t WAIT_SYANC_US = 100000; +}; + +void WindowModeSupportInfoTest::SetUpTestCase() +{ + auto display = DisplayManager::GetInstance().GetDisplayById(0); + ASSERT_TRUE((display != nullptr)); + Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; + utils::InitByDisplayRect(displayRect); +} + +void WindowModeSupportInfoTest::TearDownTestCase() +{ +} + +void WindowModeSupportInfoTest::SetUp() +{ + fullScreenAppInfo_ = { + .name = "FullWindow", + .rect = utils::customAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }; + floatingScreenAppInfo_ = { + .name = "FloatingWindow", + .rect = utils::customAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }; +} + +void WindowModeSupportInfoTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: WindowModeSupportInfo01 + * @tc.desc: SetModeSupportInfo | GetModeSupportInfo + * @tc.type: FUNC + */ +HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo01, Function | MediumTest | Level3) +{ + const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + + window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); + ASSERT_EQ(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN, window->GetModeSupportInfo()); + window->Destroy(); +} + +/** + * @tc.name: WindowModeSupportInfo02 + * @tc.desc: modeSupportInfo test for single window + * @tc.type: FUNC + */ +HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo02, Function | MediumTest | Level3) +{ + const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + + window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN | + WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + window->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + window->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + window->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_SECONDARY); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + window->Destroy(); +} + +/** + * @tc.name: WindowModeSupportInfo03 + * @tc.desc: modeSupportInfo test for single window in case current window mode is not supported. + * @tc.type: FUNC + */ +HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo03, Function | MediumTest | Level3) +{ + const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING | + WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | + WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY | + WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY); + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, window->GetMode()); + ASSERT_EQ(WMError::WM_OK, window->Hide()); + + window->Destroy(); +} + +/** + * @tc.name: WindowModeSupportInfo04 + * @tc.desc: modeSupportInfo test for layout cascade + * @tc.type: FUNC + */ +HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo04, Function | MediumTest | Level3) +{ + const sptr& window1 = utils::CreateTestWindow(fullScreenAppInfo_); + window1->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); + const sptr& window2 = utils::CreateTestWindow(utils::TestWindowInfo { + .name = "FullWindow2", + .rect = utils::customAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }); + window2->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL); + ASSERT_EQ(WMError::WM_OK, window1->Show()); + ASSERT_EQ(WMError::WM_OK, window2->Show()); + WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE); + usleep(WAIT_SYANC_US); + + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window1->GetMode()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, window2->GetMode()); + + window1->Destroy(); + window2->Destroy(); +} + +/** + * @tc.name: WindowModeSupportInfo05 + * @tc.desc: modeSupportInfo test for layout tile + * @tc.type: FUNC + */ +HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo05, Function | MediumTest | Level3) +{ + const sptr& window = utils::CreateTestWindow(fullScreenAppInfo_); + window->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); + ASSERT_EQ(WMError::WM_OK, window->Show()); + WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::TILE); + usleep(WAIT_SYANC_US); + + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + + window->Destroy(); + WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE); + usleep(WAIT_SYANC_US); +} + +/** + * @tc.name: WindowModeSupportInfo06 + * @tc.desc: modeSupportInfo test for split + * @tc.type: FUNC + */ +HWTEST_F(WindowModeSupportInfoTest, WindowModeSupportInfo06, Function | MediumTest | Level3) +{ + const sptr& window1 = utils::CreateTestWindow(fullScreenAppInfo_); + window1->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL); + const sptr& window2 = utils::CreateTestWindow(utils::TestWindowInfo { + .name = "FullWindow2", + .rect = utils::customAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }); + window2->SetModeSupportInfo(WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN); + ASSERT_EQ(WMError::WM_OK, window1->Show()); + ASSERT_EQ(WMError::WM_OK, window2->Show()); + usleep(WAIT_SYANC_US); + + window1->SetWindowMode(WindowMode::WINDOW_MODE_SPLIT_PRIMARY); + + ASSERT_EQ(WindowMode::WINDOW_MODE_SPLIT_PRIMARY, window1->GetMode()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window2->GetMode()); + + window1->Destroy(); + window2->Destroy(); +} +} // namespace +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 69a67d46..b41a614a 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -63,7 +63,7 @@ public: Rect GetDisplayRect(DisplayId displayId) const; std::unordered_map GetExpectImmersiveProperty() const; void NotifyAccessibilityWindowInfo(const sptr& windowId, WindowUpdateType type) const; - int GetWindowCountByType(WindowType windowType); + uint32_t GetWindowCountByType(WindowType windowType); bool IsForbidDockSliceMove(DisplayId displayId) const; bool IsDockSliceInExitSplitModeArea(DisplayId displayId) const; void ExitSplitMode(DisplayId displayId); diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 23fa6844..7181676b 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -126,7 +126,7 @@ private: sptr windowDeath_ = new AgentDeathRecipient(std::bind(&WindowRoot::OnRemoteDied, this, std::placeholders::_1)); Callback callback_; - int maxAppWindowNumber_ = 100; + uint32_t maxAppWindowNumber_ = 100; FloatingWindowLimitsConfig floatingWindowLimitsConfig_; SplitRatioConfig splitRatioConfig_ = {0.1, 0.9, {}}; }; diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 1c795f4b..a197e075 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -240,7 +240,9 @@ void WindowManagerService::ConfigureWindowManagerService() if (intNumbersConfig.count("maxAppWindowNumber") != 0) { auto numbers = intNumbersConfig.at("maxAppWindowNumber"); if (numbers.size() == 1) { - windowRoot_->SetMaxAppWindowNumber(numbers[0]); + if (numbers[0] > 0) { + windowRoot_->SetMaxAppWindowNumber(static_cast(numbers[0])); + } } } diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index c3e8c91a..0e7b321f 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -75,9 +75,9 @@ WindowNodeContainer::~WindowNodeContainer() Destroy(); } -int WindowNodeContainer::GetWindowCountByType(WindowType windowType) +uint32_t WindowNodeContainer::GetWindowCountByType(WindowType windowType) { - int windowNumber = 0; + uint32_t windowNumber = 0; auto counter = [&windowNumber, &windowType](sptr& windowNode) { if (windowNode->GetWindowType() == windowType && !windowNode->startingWindowShown_) ++windowNumber; }; diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 3c0ae77a..8694e504 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -431,7 +431,7 @@ WMError WindowRoot::AddWindowNode(uint32_t parentId, sptr& node, boo } // limit number of main window int mainWindowNumber = container->GetWindowCountByType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); - if (mainWindowNumber >= maxAppWindowNumber_) { + if (mainWindowNumber >= maxAppWindowNumber_ && node->GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW) { container->MinimizeOldestAppWindow(); }