From 4e67f5853a95803a06614ef95b3e34643a25f8c5 Mon Sep 17 00:00:00 2001 From: huandong Date: Wed, 23 Feb 2022 17:28:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0vpr=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=80=BC=E6=A0=A1=E9=AA=8C=EF=BC=8C=E5=A2=9E=E5=8A=A0avoid=5Fa?= =?UTF-8?q?rea=E5=BC=82=E5=B8=B8=E5=80=BC=E6=A0=A1=E9=AA=8C=E5=92=8C?= =?UTF-8?q?=E5=BC=82=E5=B8=B8ut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I033d56d12510e26ab35e6e646d38309e157568cb Signed-off-by: huandong --- utils/include/window_helper.h | 5 ++ wm/test/systemtest/window_layout_test.cpp | 2 + wm/test/systemtest/window_test_utils.cpp | 10 ++- .../unittest/avoid_area_controller_test.cpp | 70 ++++++++++++++++++- wmserver/include/avoid_area_controller.h | 4 -- wmserver/src/avoid_area_controller.cpp | 29 +++++++- wmserver/src/window_layout_policy.cpp | 6 ++ wmserver/src/window_layout_policy_tile.cpp | 4 +- wmserver/src/window_node_container.cpp | 9 ++- 9 files changed, 122 insertions(+), 17 deletions(-) diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index 8adfee83..a8091862 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -58,6 +58,11 @@ public: return ((IsMainWindow(type)) && (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 IsSplitWindowMode(WindowMode mode) { return mode == WindowMode::WINDOW_MODE_SPLIT_PRIMARY || mode == WindowMode::WINDOW_MODE_SPLIT_SECONDARY; diff --git a/wm/test/systemtest/window_layout_test.cpp b/wm/test/systemtest/window_layout_test.cpp index 6bb5c15a..9d874cdf 100644 --- a/wm/test/systemtest/window_layout_test.cpp +++ b/wm/test/systemtest/window_layout_test.cpp @@ -354,6 +354,7 @@ HWTEST_F(WindowLayoutTest, LayoutTile01, Function | MediumTest | Level3) if (utils::isVerticalDisplay_) { ASSERT_TRUE(utils::RectEqualTo(test1, utils::doubleTileRects_[0])); ASSERT_TRUE(utils::RectEqualTo(test2, utils::doubleTileRects_[1])); + WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE, displayId_); return; } else { ASSERT_TRUE(utils::RectEqualTo(window, utils::tripleTileRects_[0])); @@ -367,6 +368,7 @@ HWTEST_F(WindowLayoutTest, LayoutTile01, Function | MediumTest | Level3) ASSERT_TRUE(utils::RectEqualTo(test1, utils::tripleTileRects_[0])); ASSERT_TRUE(utils::RectEqualTo(test2, utils::tripleTileRects_[1])); ASSERT_TRUE(utils::RectEqualTo(test3, utils::tripleTileRects_[2])); // 2 is second rect idx + WindowManager::GetInstance().SetWindowLayoutMode(WindowLayoutMode::CASCADE, displayId_); } } } // namespace Rosen diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp index 3f7b91dd..ca6e271c 100644 --- a/wm/test/systemtest/window_test_utils.cpp +++ b/wm/test/systemtest/window_test_utils.cpp @@ -391,10 +391,16 @@ float WindowTestUtils::GetVirtualPixelRatio(DisplayId displayId) { auto display = DisplayManager::GetInstance().GetDisplayById(displayId); if (display == nullptr) { - WLOGFE("GetVirtualPixel fail. Get display fail. displayId:%{public}" PRIu64", vpr:%{public}f", displayId, 0.0); - return 0.0; + WLOGFE("GetVirtualPixel fail. Get display fail. displayId:%{public}" PRIu64", use Default vpr:1.0", displayId); + return 1.0; // Use DefaultVPR 1.0 } + float virtualPixelRatio = display->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 + } + WLOGFI("GetVirtualPixel success. displayId:%{public}" PRIu64", vpr:%{public}f", displayId, virtualPixelRatio); return virtualPixelRatio; } diff --git a/wm/test/unittest/avoid_area_controller_test.cpp b/wm/test/unittest/avoid_area_controller_test.cpp index 220d895d..2ab190ab 100644 --- a/wm/test/unittest/avoid_area_controller_test.cpp +++ b/wm/test/unittest/avoid_area_controller_test.cpp @@ -123,6 +123,37 @@ HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode02, Function | SmallTest | Leve ASSERT_TRUE(avoidAreaController->IsAvoidAreaNode(node)); } +/** + * @tc.name: IsAvoidAreaNode03 + * @tc.desc: Create a Dock_Slice Window. Test IsAvoidAreaNode + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode03, Function | SmallTest | Level2) +{ + auto avoidAreaController = new AvoidAreaController(nullptr); + + sptr node = new WindowNode(); + sptr property = new WindowProperty(); + property->SetWindowType(WindowType::WINDOW_TYPE_DOCK_SLICE); + node->SetWindowProperty(property); + + ASSERT_EQ(false, avoidAreaController->IsAvoidAreaNode(node)); +} + +/** + * @tc.name: IsAvoidAreaNode04 + * @tc.desc: Create a Dock_Slice Window. Test IsAvoidAreaNode + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, IsAvoidAreaNode04, Function | SmallTest | Level2) +{ + auto avoidAreaController = new AvoidAreaController(nullptr); + + ASSERT_EQ(false, avoidAreaController->IsAvoidAreaNode(nullptr)); +} + /** * @tc.name: AddAvoidAreaNode01 * @tc.desc: Add a new avoid area Node @@ -198,6 +229,18 @@ HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode03, Function | SmallTest | Lev ASSERT_EQ(WMError::WM_OK, avoidAreaController->AddAvoidAreaNode(node2)); } +/** + * @tc.name: AddAvoidAreaNode04 + * @tc.desc: Add nullptr + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, AddAvoidAreaNode04, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->AddAvoidAreaNode(nullptr)); +} + /** * @tc.name: RemoveAvoidAreaNode01 * @tc.desc: Add a new avoid area. And Remove this. @@ -238,6 +281,18 @@ HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode02, Function | SmallTest | ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->RemoveAvoidAreaNode(node)); } +/** + * @tc.name: RemoveAvoidAreaNode03 + * @tc.desc: Remove nullptr + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, RemoveAvoidAreaNode03, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->RemoveAvoidAreaNode(nullptr)); +} + /** * @tc.name: UpdateAvoidAreaNode01 * @tc.desc: Add a new avoid area node and update this @@ -280,6 +335,18 @@ HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode02, Function | SmallTest | ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->UpdateAvoidAreaNode(node)); } +/** + * @tc.name: UpdateAvoidAreaNode03 + * @tc.desc: Update nullptr + * @tc.type: FUNC + * @tc.require: AR000GGTVD + */ +HWTEST_F(AvoidAreaControllerTest, UpdateAvoidAreaNode03, Function | SmallTest | Level2) +{ + sptr avoidAreaController = new AvoidAreaController(nullptr); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, avoidAreaController->UpdateAvoidAreaNode(nullptr)); +} + /** * @tc.name: GetAvoidArea01 * @tc.desc: GetAvoidArea @@ -362,7 +429,6 @@ HWTEST_F(AvoidAreaControllerTest, GetAvoidArea03, Function | SmallTest | Level2) HWTEST_F(AvoidAreaControllerTest, GetAvoidAreaByType01, Function | SmallTest | Level2) { sptr avoidAreaController = new AvoidAreaController(nullptr); - std::vector avoidArea = avoidAreaController->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT); ASSERT_EQ(4u, static_cast(avoidArea.size())); @@ -374,7 +440,7 @@ HWTEST_F(AvoidAreaControllerTest, GetAvoidAreaByType01, Function | SmallTest | L /** * @tc.name: GetAvoidAreaByType02 - * @tc.desc: Search a unexist AvoidAreaType. And GetAvoidAreaByType + * @tc.desc: Add a new node. And GetAvoidAreaByType * @tc.type: FUNC * @tc.require: AR000GGTVD */ diff --git a/wmserver/include/avoid_area_controller.h b/wmserver/include/avoid_area_controller.h index 375570bb..a5c9d4e4 100644 --- a/wmserver/include/avoid_area_controller.h +++ b/wmserver/include/avoid_area_controller.h @@ -51,10 +51,6 @@ public: private: std::map> avoidNodes_; // key: windowId - const std::set avoidType_ { - WindowType::WINDOW_TYPE_STATUS_BAR, - WindowType::WINDOW_TYPE_NAVIGATION_BAR, - }; UpdateAvoidAreaFunc updateAvoidAreaCallBack_; void UseCallbackNotifyAvoidAreaChanged(std::vector& avoidArea) const; void DumpAvoidArea(const std::vector& avoidArea) const; diff --git a/wmserver/src/avoid_area_controller.cpp b/wmserver/src/avoid_area_controller.cpp index b56d28d1..eb3a4456 100644 --- a/wmserver/src/avoid_area_controller.cpp +++ b/wmserver/src/avoid_area_controller.cpp @@ -14,6 +14,7 @@ */ #include "avoid_area_controller.h" +#include "window_helper.h" #include "window_manager_hilog.h" #include "wm_trace.h" @@ -27,10 +28,17 @@ const int32_t AVOID_NUM = 4; bool AvoidAreaController::IsAvoidAreaNode(const sptr& node) const { - if (avoidType_.find(node->GetWindowType()) != avoidType_.end()) { - return true; + if (node == nullptr) { + WLOGFE("IsAvoidAreaNode Failed, node is nullprt"); + return false; } - return false; + + if (!WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) { + WLOGFE("IsAvoidAreaNode Failed, node type is not avoid type"); + return false; + } + + return true; } static AvoidPos GetAvoidPosType(const Rect& rect) @@ -54,6 +62,11 @@ static AvoidPos GetAvoidPosType(const Rect& rect) WMError AvoidAreaController::AddAvoidAreaNode(const sptr& node) { WM_FUNCTION_TRACE(); + if (!IsAvoidAreaNode(node)) { + WLOGFE("AddAvoidAreaNode check param Failed."); + return WMError::WM_ERROR_INVALID_PARAM; + } + uint32_t windowId = node->GetWindowId(); auto iter = avoidNodes_.find(windowId); if (iter != avoidNodes_.end()) { @@ -75,6 +88,11 @@ WMError AvoidAreaController::AddAvoidAreaNode(const sptr& node) WMError AvoidAreaController::RemoveAvoidAreaNode(const sptr& node) { WM_FUNCTION_TRACE(); + if (!IsAvoidAreaNode(node)) { + WLOGFE("RemoveAvoidAreaNode check param Failed."); + return WMError::WM_ERROR_INVALID_PARAM; + } + uint32_t windowId = node->GetWindowId(); auto iter = avoidNodes_.find(windowId); if (iter == avoidNodes_.end()) { @@ -96,6 +114,11 @@ WMError AvoidAreaController::RemoveAvoidAreaNode(const sptr& node) WMError AvoidAreaController::UpdateAvoidAreaNode(const sptr& node) { WM_FUNCTION_TRACE(); + if (!IsAvoidAreaNode(node)) { + WLOGFE("UpdateAvoidAreaNode check param Failed."); + return WMError::WM_ERROR_INVALID_PARAM; + } + uint32_t windowId = node->GetWindowId(); auto iter = avoidNodes_.find(windowId); if (iter == avoidNodes_.end()) { diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index ded4d478..6f3c98fb 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -360,7 +360,13 @@ float WindowLayoutPolicy::GetVirtualPixelRatio() const WLOGFE("GetVirtualPixel fail. Get display fail. displayId:%{public}" PRIu64", use Default vpr:1.0", screenId_); return 1.0; // Use DefaultVPR 1.0 } + float virtualPixelRatio = display->GetVirtualPixelRatio(); + if (virtualPixelRatio == 0.0) { + WLOGFE("GetVirtualPixel fail. vpr is 0.0. displayId:%{public}" PRIu64", use Default vpr:1.0", screenId_); + return 1.0; // Use DefaultVPR 1.0 + } + WLOGFI("GetVirtualPixel success. displayId:%{public}" PRIu64", vpr:%{public}f", screenId_, virtualPixelRatio); return virtualPixelRatio; } diff --git a/wmserver/src/window_layout_policy_tile.cpp b/wmserver/src/window_layout_policy_tile.cpp index 59ec65c1..500d34d9 100644 --- a/wmserver/src/window_layout_policy_tile.cpp +++ b/wmserver/src/window_layout_policy_tile.cpp @@ -23,7 +23,7 @@ namespace OHOS { namespace Rosen { namespace { - constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowLayoutPolicyTile"}; + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowLayoutPolicyTile"}; constexpr uint32_t MAX_WIN_NUM_VERTICAL = 2; constexpr uint32_t MAX_WIN_NUM_HORIZONTAL = 3; } @@ -96,6 +96,7 @@ void WindowLayoutPolicyTile::AddWindowNode(sptr& node) void WindowLayoutPolicyTile::RemoveWindowNode(sptr& node) { WM_FUNCTION_TRACE(); + WLOGFI("RemoveWindowNode %{public}d in tile", node->GetWindowId()); auto type = node->GetWindowType(); // affect other windows, trigger off global layout if (avoidTypes_.find(type) != avoidTypes_.end()) { @@ -146,6 +147,7 @@ void WindowLayoutPolicyTile::ForegroundNodeQueuePushBack(sptr& node) while (foregroundNodes_.size() >= maxTileWinNum) { auto removeNode = foregroundNodes_.front(); foregroundNodes_.pop_front(); + WLOGFI("pop win in queue head id: %{public}d, for add new win", removeNode->GetWindowId()); if (removeNode->abilityToken_ != nullptr) { WLOGFI("minimize win %{public}d in tile", removeNode->GetWindowId()); AAFwk::AbilityManagerClient::GetInstance()->MinimizeAbility(removeNode->abilityToken_); diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 287e95c3..ddaac156 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -108,8 +108,7 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrchildren_) { child->currentVisibility_ = child->requestedVisibility_; } - if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR || - node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) { sysBarNodeMap_[node->GetWindowType()] = node; } } @@ -129,7 +128,7 @@ WMError WindowNodeContainer::AddWindowNode(sptr& node, sptrAddWindowNode(node); - if (avoidController_->IsAvoidAreaNode(node)) { + if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) { avoidController_->AddAvoidAreaNode(node); NotifyIfSystemBarRegionChanged(); } else { @@ -153,7 +152,7 @@ WMError WindowNodeContainer::UpdateWindowNode(sptr& node, WindowUpda SwitchLayoutPolicy(WindowLayoutMode::CASCADE); } layoutPolicy_->UpdateWindowNode(node); - if (avoidController_->IsAvoidAreaNode(node)) { + if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) { avoidController_->UpdateAvoidAreaNode(node); NotifyIfSystemBarRegionChanged(); } else { @@ -283,7 +282,7 @@ WMError WindowNodeContainer::RemoveWindowNode(sptr& node) UpdateRSTree(node, false); layoutPolicy_->RemoveWindowNode(node); - if (avoidController_->IsAvoidAreaNode(node)) { + if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) { avoidController_->RemoveAvoidAreaNode(node); NotifyIfSystemBarRegionChanged(); } else {