From fab717c03265802a0234e6e07ef5a31816997a98 Mon Sep 17 00:00:00 2001 From: baoyang Date: Sat, 19 Jul 2025 16:05:36 +0800 Subject: [PATCH] phone application adjust Signed-off-by: baoyang Change-Id: I62f275bd54d02473055997f7b117c853a4b65057 --- .../sec_comp_info_helper.h | 2 +- .../sa/sa_main/sec_comp_info_helper.cpp | 24 +++++++--- .../sa/sa_main/window_info_helper.cpp | 5 +- .../sa/sa_main/window_info_helper.h | 2 +- .../sa/test/mock/include/window_manager.h | 1 + .../src/sec_comp_info_helper_test.cpp | 46 +++++++++++++++++++ .../unittest/src/sec_comp_info_helper_test.h | 2 + 7 files changed, 71 insertions(+), 11 deletions(-) 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 7d5a44e..5902c6f 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 @@ -51,7 +51,7 @@ struct ScreenInfo { private: static float GetWindowScale(int32_t windowId); - static void AdjustSecCompRect(SecCompBase* comp, float scale); + static void AdjustSecCompRect(SecCompBase* comp, float scale, bool isCompatScaleMode); static bool IsOutOfWatchScreen(const SecCompRect& rect, double radius, std::string& message); static bool IsOutOfScreen(const SecCompRect& rect, double curScreenWidth, double curScreenHeight, std::string& message, bool isWearable); 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 ae6624c..6c113a2 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 @@ -46,16 +46,25 @@ const int NUMBER_TWO = 2; const char HEX_FILL_CHAR = '0'; } -void SecCompInfoHelper::AdjustSecCompRect(SecCompBase* comp, float scale) +void SecCompInfoHelper::AdjustSecCompRect(SecCompBase* comp, float scale, bool isCompatScaleMode) { comp->rect_.width_ *= scale; comp->rect_.height_ *= scale; - comp->rect_.x_ = comp->windowRect_.x_ + (comp->rect_.x_ - comp->windowRect_.x_) * scale; - comp->rect_.y_ = comp->windowRect_.y_ + (comp->rect_.y_ - comp->windowRect_.y_) * scale; - + if (!isCompatScaleMode) { + // window scales towards the top-left corner + comp->rect_.x_ = comp->windowRect_.x_ + (comp->rect_.x_ - comp->windowRect_.x_) * scale; + comp->rect_.y_ = comp->windowRect_.y_ + (comp->rect_.y_ - comp->windowRect_.y_) * scale; + } else { + // window scales towards the center + auto disX = comp->rect_.x_ - comp->windowRect_.x_; + auto disY = comp->rect_.y_ - comp->windowRect_.y_; + comp->windowRect_.x_ = comp->windowRect_.x_ + (1 - scale) * comp->windowRect_.width_ / NUMBER_TWO; + comp->windowRect_.y_ = comp->windowRect_.y_ + (1 - scale) * comp->windowRect_.height_ / NUMBER_TWO; + comp->rect_.x_ = comp->windowRect_.x_ + scale * disX; + comp->rect_.y_ = comp->windowRect_.y_ + scale * disY; + } 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_); - comp->windowRect_.width_ *= scale; comp->windowRect_.height_ *= scale; } @@ -337,10 +346,11 @@ bool SecCompInfoHelper::CheckComponentValid(SecCompBase* comp, std::string& mess return false; } - float scale = WindowInfoHelper::GetWindowScale(comp->windowId_); + bool isCompatScaleMode = false; + float scale = WindowInfoHelper::GetWindowScale(comp->windowId_, isCompatScaleMode); SC_LOG_DEBUG(LABEL, "WindowScale = %{public}f", scale); if (!IsEqual(scale, WindowInfoHelper::FULL_SCREEN_SCALE) && !IsEqual(scale, 0.0)) { - AdjustSecCompRect(comp, scale); + AdjustSecCompRect(comp, scale, isCompatScaleMode); } if (!CheckSecCompBase(comp, message)) { diff --git a/services/security_component_service/sa/sa_main/window_info_helper.cpp b/services/security_component_service/sa/sa_main/window_info_helper.cpp index c119cce..6c791ab 100644 --- a/services/security_component_service/sa/sa_main/window_info_helper.cpp +++ b/services/security_component_service/sa/sa_main/window_info_helper.cpp @@ -28,7 +28,7 @@ constexpr int32_t INVALID_WINDOW_LAYER = -1; constexpr uint32_t UI_EXTENSION_MASK = 0x40000000; } -float WindowInfoHelper::GetWindowScale(int32_t windowId) +float WindowInfoHelper::GetWindowScale(int32_t windowId, bool& isCompatScaleMode) { float scale = FULL_SCREEN_SCALE; std::vector> infos; @@ -43,8 +43,9 @@ float WindowInfoHelper::GetWindowScale(int32_t windowId) SC_LOG_WARN(LABEL, "Cannot find AccessibilityWindowInfo, return default scale"); return scale; } + isCompatScaleMode = (*iter)->isCompatScaleMode_; scale = (*iter)->scaleVal_; - SC_LOG_INFO(LABEL, "Get scale %{public}f", scale); + SC_LOG_INFO(LABEL, "Get scale = %{public}f, isCompatScaleMode = %{public}d", scale, isCompatScaleMode); return scale; } diff --git a/services/security_component_service/sa/sa_main/window_info_helper.h b/services/security_component_service/sa/sa_main/window_info_helper.h index f1c0885..aec5035 100644 --- a/services/security_component_service/sa/sa_main/window_info_helper.h +++ b/services/security_component_service/sa/sa_main/window_info_helper.h @@ -23,7 +23,7 @@ namespace Security { namespace SecurityComponent { class __attribute__((visibility("default"))) WindowInfoHelper { public: - static float GetWindowScale(int32_t windowId); + static float GetWindowScale(int32_t windowId, bool& isCompatScaleMode); static bool CheckOtherWindowCoverComp(int32_t compWinId, const SecCompRect& secRect, std::string& message); public: static constexpr float FULL_SCREEN_SCALE = 1.0F; diff --git a/services/security_component_service/sa/test/mock/include/window_manager.h b/services/security_component_service/sa/test/mock/include/window_manager.h index f7479c2..c24499e 100644 --- a/services/security_component_service/sa/test/mock/include/window_manager.h +++ b/services/security_component_service/sa/test/mock/include/window_manager.h @@ -55,6 +55,7 @@ public: WindowMode mode_; WindowType type_; float scaleVal_; + bool isCompatScaleMode_ { false }; }; class UnreliableWindowInfo : public Parcelable { 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 679268f..60e2b31 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 @@ -22,6 +22,7 @@ #include "location_button.h" #include "paste_button.h" #include "save_button.h" +#include "sec_comp_info.h" #include "sec_comp_info_helper.h" #include "sec_comp_log.h" #include "sec_comp_err.h" @@ -660,3 +661,48 @@ HWTEST_F(SecCompInfoHelperTest, IsColorSimilar001, TestSize.Level0) }; EXPECT_TRUE(IsColorSimilar(color1, color2)); } + +/** + * @tc.name: AdjustSecCompRect001 + * @tc.desc: Test AdjustSecCompRect + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SecCompInfoHelperTest, AdjustSecCompRect001, TestSize.Level0) +{ + nlohmann::json jsonComponent; + ServiceTestCommon::BuildLocationComponentJson(jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); + float scale = 0.8f; + + comp->rect_.x_ = 10.0f; + comp->rect_.y_ = 5.0f; + comp->rect_.width_ = 20.0f; + comp->rect_.height_ = 10.0f; + comp->windowRect_.x_ = 0.0f; + comp->windowRect_.y_ = 0.0f; + comp->windowRect_.width_ = 200.0f; + comp->windowRect_.height_ = 100.0f; + + SecCompInfoHelper::AdjustSecCompRect(comp, scale, false); + EXPECT_TRUE(IsEqual(comp->rect_.width_, 16)); + EXPECT_TRUE(IsEqual(comp->rect_.height_, 8)); + EXPECT_TRUE(IsEqual(comp->rect_.x_, 8)); + EXPECT_TRUE(IsEqual(comp->rect_.y_, 4)); + + comp->rect_.x_ = 10.0f; + comp->rect_.y_ = 5.0f; + comp->rect_.width_ = 20.0f; + comp->rect_.height_ = 10.0f; + comp->windowRect_.x_ = 0.0f; + comp->windowRect_.y_ = 0.0f; + comp->windowRect_.width_ = 200.0f; + comp->windowRect_.height_ = 100.0f; + + SecCompInfoHelper::AdjustSecCompRect(comp, scale, true); + EXPECT_TRUE(IsEqual(comp->rect_.width_, 16)); + EXPECT_TRUE(IsEqual(comp->rect_.height_, 8)); + EXPECT_TRUE(IsEqual(comp->rect_.x_, 28)); + EXPECT_TRUE(IsEqual(comp->rect_.y_, 14)); +} diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.h b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.h index a9d8459..7bd06cd 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.h +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.h @@ -16,7 +16,9 @@ #define SEC_COMP_INFO_HELPER_TEST_H #include +#define private public #include "sec_comp_info_helper.h" +#undef private namespace OHOS { namespace Security { -- Gitee