From 298d31b02fb90d0d774eaa9cb80bf43daad78db8 Mon Sep 17 00:00:00 2001 From: baoyang Date: Sun, 7 Sep 2025 16:50:04 +0800 Subject: [PATCH] fix out of window Signed-off-by: baoyang Change-Id: I3987a4168956bde9fcb1f6c050c305b35516c396 --- .../include/sec_comp_base.h | 1 + .../sec_comp_info_helper.h | 2 +- .../sa/sa_main/sec_comp_info_helper.cpp | 14 +++++-- .../sa/sa_main/sec_comp_manager.cpp | 2 +- .../src/sec_comp_info_helper_test.cpp | 42 ++++++++++--------- 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/interfaces/inner_api/security_component/include/sec_comp_base.h b/interfaces/inner_api/security_component/include/sec_comp_base.h index e95c5ff..08adf21 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_base.h +++ b/interfaces/inner_api/security_component/include/sec_comp_base.h @@ -163,6 +163,7 @@ public: bool isWearableDevice_ = false; TipPosition tipPosition_ = TipPosition::ABOVE_BOTTOM; bool isCustomizable_ = false; + float scale_ = 1.0f; protected: virtual bool IsTextIconTypeValid(std::string& message, bool isClicked) = 0; virtual bool IsCorrespondenceType() = 0; diff --git a/interfaces/inner_api/security_component_common/sec_comp_info_helper.h b/interfaces/inner_api/security_component_common/sec_comp_info_helper.h index 773bf56..8d60d42 100644 --- a/interfaces/inner_api/security_component_common/sec_comp_info_helper.h +++ b/interfaces/inner_api/security_component_common/sec_comp_info_helper.h @@ -46,7 +46,7 @@ struct ScreenInfo { std::string& message, bool isClicked = false); static bool CheckComponentValid(SecCompBase* comp, std::string& message); static bool CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, const ScreenInfo& screenInfo, - std::string& message); + std::string& message, const float scale); static double GetDistance(DimensionT x1, DimensionT y1, DimensionT x2, DimensionT y2); private: diff --git a/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp b/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp index 5eea866..2db323c 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp @@ -57,6 +57,7 @@ void SecCompInfoHelper::AdjustSecCompRect(SecCompBase* comp, const Scales scales comp->rect_.y_ = comp->windowRect_.y_ + (comp->rect_.y_ - comp->windowRect_.y_) * scales.floatingScale; comp->windowRect_.width_ *= scales.floatingScale; comp->windowRect_.height_ *= scales.floatingScale; + comp->scale_ = scales.floatingScale; } else { // window scales towards the center comp->rect_.width_ *= scales.scaleX; @@ -70,6 +71,11 @@ void SecCompInfoHelper::AdjustSecCompRect(SecCompBase* comp, const Scales scales comp->windowRect_.y_ = windowRect.y_; comp->windowRect_.width_ = windowRect.width_; comp->windowRect_.height_ = windowRect.height_; + if (scales.scaleX > scales.scaleY) { + comp->scale_ = scales.scaleX; + } else { + comp->scale_ = scales.scaleY; + } } SC_LOG_DEBUG(LABEL, "After adjust x %{public}f, y %{public}f, width %{public}f, height %{public}f", comp->rect_.x_, comp->rect_.y_, comp->rect_.width_, comp->rect_.height_); @@ -191,7 +197,7 @@ bool SecCompInfoHelper::IsOutOfScreen(const SecCompRect& rect, double curScreenW } bool SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, - const ScreenInfo& screenInfo, std::string& message) + const ScreenInfo& screenInfo, std::string& message, const float scale) { double curScreenWidth = 0.0F; double curScreenHeight = 0.0F; @@ -210,9 +216,9 @@ bool SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRec return false; } - if (GreatNotEqual(windowRect.x_, rect.x_ + 1.0) || GreatNotEqual(windowRect.y_, rect.y_ + 1.0) || - GreatNotEqual(rect.x_ + rect.width_, windowRect.x_ + windowRect.width_ + 1.0) || - GreatNotEqual(rect.y_ + rect.height_, windowRect.y_ + windowRect.height_ + 1.0)) { + if (GreatNotEqual(windowRect.x_, rect.x_ + 1.0 + scale) || GreatNotEqual(windowRect.y_, rect.y_ + 1.0 + scale) || + GreatNotEqual(rect.x_ + rect.width_, windowRect.x_ + windowRect.width_ + 1.0 + scale) || + GreatNotEqual(rect.y_ + rect.height_, windowRect.y_ + windowRect.height_ + 1.0 + scale)) { SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of window"); message = OUT_OF_WINDOW + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp index cd92d96..f40ef3f 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp @@ -502,7 +502,7 @@ int32_t SecCompManager::CheckClickSecurityComponentInfo(std::shared_ptrdisplayId_, report->crossAxisState_, report->isWearableDevice_}; if ((!SecCompInfoHelper::CheckRectValid(reportComponentInfo->rect_, reportComponentInfo->windowRect_, - screenInfo, message))) { + screenInfo, message, reportComponentInfo->scale_))) { SC_LOG_ERROR(LABEL, "compare component info failed."); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "COMPONENT_INFO_CHECK_FAILED", HiviewDFX::HiSysEvent::EventType::SECURITY, "CALLER_UID", uid, "CALLER_BUNDLE_NAME", bundleName, diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp index 8620191..8870841 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp @@ -160,40 +160,41 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent004, TestSize.Level0) .crossAxisState = CrossAxisState::STATE_INVALID, .isWearable = false }; - ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + float scale = 1.0; + ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); rect.x_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); rect.x_ = g_testWidth; rect.y_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); rect.y_ = g_testHeight; rect.x_ = g_curScreenWidth + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); rect.x_ = g_testWidth; rect.y_ = g_curScreenHeight + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); rect.y_ = g_testHeight; rect.width_ = g_curScreenWidth; rect.height_ = g_curScreenHeight; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); rect.width_ = g_testWidth; rect.height_ = g_testHeight; rect.x_ = g_curScreenWidth - g_testWidth; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); rect.x_ = g_testWidth; rect.y_ = g_curScreenHeight - g_testHeight; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); rect.y_ = g_testHeight; screenInfo.isWearable = true; - ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); } /** @@ -212,30 +213,31 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent005, TestSize.Level0) .crossAxisState = CrossAxisState::STATE_INVALID, .isWearable = false }; - ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + float scale = 1.0; + ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); - windowRect.x_ = g_testWidth + 2.0; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + windowRect.x_ = g_testWidth + 3.0; + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); windowRect.x_ = g_testWidth; - windowRect.y_ = g_testHeight + 2.0; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + windowRect.y_ = g_testHeight + 3.0; + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); windowRect.y_ = g_testHeight; - windowRect.width_ = g_testWidth - 2.0; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + windowRect.width_ = g_testWidth - 3.0; + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); windowRect.width_ = g_testWidth; - windowRect.height_ = g_testHeight - 2.0; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + windowRect.height_ = g_testHeight - 3.0; + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); windowRect.height_ = g_testHeight; windowRect.width_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); windowRect.width_ = g_testWidth; windowRect.height_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message, scale)); windowRect.height_ = g_testHeight; } -- Gitee