mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-19 17:08:11 -04:00
增加vpr异常值校验,增加avoid_area异常值校验和异常ut
Change-Id: I033d56d12510e26ab35e6e646d38309e157568cb Signed-off-by: huandong <huandong1@huawei.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<WindowNode> node = new WindowNode();
|
||||
sptr<WindowProperty> 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> 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> 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> 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> avoidAreaController = new AvoidAreaController(nullptr);
|
||||
|
||||
std::vector<Rect> avoidArea = avoidAreaController->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT);
|
||||
|
||||
ASSERT_EQ(4u, static_cast<uint32_t>(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
|
||||
*/
|
||||
|
||||
@@ -51,10 +51,6 @@ public:
|
||||
|
||||
private:
|
||||
std::map<uint32_t, sptr<WindowNode>> avoidNodes_; // key: windowId
|
||||
const std::set<WindowType> avoidType_ {
|
||||
WindowType::WINDOW_TYPE_STATUS_BAR,
|
||||
WindowType::WINDOW_TYPE_NAVIGATION_BAR,
|
||||
};
|
||||
UpdateAvoidAreaFunc updateAvoidAreaCallBack_;
|
||||
void UseCallbackNotifyAvoidAreaChanged(std::vector<Rect>& avoidArea) const;
|
||||
void DumpAvoidArea(const std::vector<Rect>& avoidArea) const;
|
||||
|
||||
@@ -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<WindowNode>& 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<WindowNode>& 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<WindowNode>& node)
|
||||
WMError AvoidAreaController::RemoveAvoidAreaNode(const sptr<WindowNode>& 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<WindowNode>& node)
|
||||
WMError AvoidAreaController::UpdateAvoidAreaNode(const sptr<WindowNode>& 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()) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<WindowNode>& node)
|
||||
void WindowLayoutPolicyTile::RemoveWindowNode(sptr<WindowNode>& 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<WindowNode>& 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_);
|
||||
|
||||
@@ -108,8 +108,7 @@ WMError WindowNodeContainer::AddWindowNode(sptr<WindowNode>& node, sptr<WindowNo
|
||||
for (auto& child : node->children_) {
|
||||
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<WindowNode>& node, sptr<WindowNo
|
||||
UpdateRSTree(node, true);
|
||||
AssignZOrder();
|
||||
layoutPolicy_->AddWindowNode(node);
|
||||
if (avoidController_->IsAvoidAreaNode(node)) {
|
||||
if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) {
|
||||
avoidController_->AddAvoidAreaNode(node);
|
||||
NotifyIfSystemBarRegionChanged();
|
||||
} else {
|
||||
@@ -153,7 +152,7 @@ WMError WindowNodeContainer::UpdateWindowNode(sptr<WindowNode>& 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<WindowNode>& node)
|
||||
|
||||
UpdateRSTree(node, false);
|
||||
layoutPolicy_->RemoveWindowNode(node);
|
||||
if (avoidController_->IsAvoidAreaNode(node)) {
|
||||
if (WindowHelper::IsAvoidAreaWindow(node->GetWindowType())) {
|
||||
avoidController_->RemoveAvoidAreaNode(node);
|
||||
NotifyIfSystemBarRegionChanged();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user