From 2ccdb44e5528908defc1f65d058384fb82ed049c Mon Sep 17 00:00:00 2001 From: baoyang Date: Thu, 6 Feb 2025 22:55:06 +0800 Subject: [PATCH 1/3] add out-of-screen algorithm Signed-off-by: baoyang Change-Id: I1b9a9268bb2afc87778b8131333d929307da4c7a --- .../unittest/src/location_button_test.cpp | 12 +-- .../test/unittest/src/test_common.cpp | 51 +++++++++--- .../security_component/src/sec_comp_base.cpp | 81 ++++++++++++++++--- .../include/sec_comp_base.h | 18 ++++- .../include/sec_comp_info.h | 8 ++ .../sec_comp_info_helper.h | 14 +++- .../sa/sa_main/app_state_observer.cpp | 2 +- .../sa/sa_main/app_state_observer.h | 2 +- .../sa/sa_main/first_use_dialog.cpp | 1 - .../sa/sa_main/sec_comp_info_helper.cpp | 75 ++++++++++++++--- .../sa/sa_main/sec_comp_manager.cpp | 10 ++- .../src/sec_comp_info_helper_test.cpp | 81 +++++++++++-------- .../test/unittest/src/service_test_common.cpp | 52 +++++++++--- .../security_component/common/fuzz_common.cpp | 32 +++++--- .../security_component/common/fuzz_common.h | 2 +- 15 files changed, 334 insertions(+), 107 deletions(-) diff --git a/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp index 5022339..2e41c80 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp @@ -216,11 +216,11 @@ HWTEST_F(LocationButtonTest, FromJson007, TestSize.Level1) auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; - paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = WRONG_TYPE; + paddingJson[JsonTagConstants::JSON_TOP_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); - paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = TestCommon::TEST_DIMENSION; - paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = WRONG_TYPE; + paddingJson[JsonTagConstants::JSON_TOP_TAG] = TestCommon::TEST_DIMENSION; + paddingJson[JsonTagConstants::JSON_RIGHT_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } @@ -241,11 +241,11 @@ HWTEST_F(LocationButtonTest, FromJson008, TestSize.Level1) auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; - paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = WRONG_TYPE; + paddingJson[JsonTagConstants::JSON_BOTTOM_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); - paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = TestCommon::TEST_DIMENSION; - paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = WRONG_TYPE; + paddingJson[JsonTagConstants::JSON_BOTTOM_TAG] = TestCommon::TEST_DIMENSION; + paddingJson[JsonTagConstants::JSON_LEFT_TAG] = WRONG_TYPE; ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } diff --git a/frameworks/inner_api/security_component/test/unittest/src/test_common.cpp b/frameworks/inner_api/security_component/test/unittest/src/test_common.cpp index 7ce03fc..3974f8c 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/test_common.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/test_common.cpp @@ -27,6 +27,7 @@ void TestCommon::BuildLocationComponentInfo(nlohmann::json& jsonComponent) {JsonTagConstants::JSON_RECT_HEIGHT, TestCommon::TEST_COORDINATE } }; jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0; + jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false; jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = nlohmann::json { {JsonTagConstants::JSON_RECT_X, TestCommon::TEST_COORDINATE }, {JsonTagConstants::JSON_RECT_Y, TestCommon::TEST_COORDINATE }, @@ -34,10 +35,17 @@ void TestCommon::BuildLocationComponentInfo(nlohmann::json& jsonComponent) {JsonTagConstants::JSON_RECT_HEIGHT, TestCommon::TEST_COORDINATE } }; nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_TOP_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_TAG, TestCommon::TEST_DIMENSION }, + }; + + nlohmann::json jsonBorderRadius = nlohmann::json { + { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, TEST_DIMENSION }, }; jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { @@ -45,6 +53,7 @@ void TestCommon::BuildLocationComponentInfo(nlohmann::json& jsonComponent) { JsonTagConstants::JSON_ICON_SIZE_TAG, TestCommon::TEST_SIZE }, { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, TestCommon::TEST_SIZE }, { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, + { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius} }; jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { @@ -79,6 +88,7 @@ void TestCommon::BuildSaveComponentInfo(nlohmann::json& jsonComponent) { jsonComponent[JsonTagConstants::JSON_SC_TYPE] = SAVE_COMPONENT; jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0; + jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false; jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json { {JsonTagConstants::JSON_RECT_X, TestCommon::TEST_COORDINATE }, {JsonTagConstants::JSON_RECT_Y, TestCommon::TEST_COORDINATE }, @@ -92,10 +102,17 @@ void TestCommon::BuildSaveComponentInfo(nlohmann::json& jsonComponent) {JsonTagConstants::JSON_RECT_HEIGHT, TestCommon::TEST_COORDINATE } }; nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_TOP_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_TAG, TestCommon::TEST_DIMENSION }, + }; + + nlohmann::json jsonBorderRadius = nlohmann::json { + { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, TEST_DIMENSION }, }; jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { @@ -103,6 +120,7 @@ void TestCommon::BuildSaveComponentInfo(nlohmann::json& jsonComponent) { JsonTagConstants::JSON_ICON_SIZE_TAG, TestCommon::TEST_SIZE }, { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, TestCommon::TEST_SIZE }, { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, + { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius} }; jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { @@ -137,6 +155,7 @@ void TestCommon::BuildPasteComponentInfo(nlohmann::json& jsonComponent) { jsonComponent[JsonTagConstants::JSON_SC_TYPE] = PASTE_COMPONENT; jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0; + jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false; jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json { {JsonTagConstants::JSON_RECT_X, TestCommon::TEST_COORDINATE }, {JsonTagConstants::JSON_RECT_Y, TestCommon::TEST_COORDINATE }, @@ -150,10 +169,17 @@ void TestCommon::BuildPasteComponentInfo(nlohmann::json& jsonComponent) {JsonTagConstants::JSON_RECT_HEIGHT, TestCommon::TEST_COORDINATE } }; nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_TOP_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_BOTTOM_TAG, TestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_TAG, TestCommon::TEST_DIMENSION }, + }; + + nlohmann::json jsonBorderRadius = nlohmann::json { + { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, TEST_DIMENSION }, }; jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { @@ -161,6 +187,7 @@ void TestCommon::BuildPasteComponentInfo(nlohmann::json& jsonComponent) { JsonTagConstants::JSON_ICON_SIZE_TAG, TestCommon::TEST_SIZE }, { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, TestCommon::TEST_SIZE }, { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, + { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius}, }; jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { diff --git a/frameworks/security_component/src/sec_comp_base.cpp b/frameworks/security_component/src/sec_comp_base.cpp index 6cf600b..6712ed3 100644 --- a/frameworks/security_component/src/sec_comp_base.cpp +++ b/frameworks/security_component/src/sec_comp_base.cpp @@ -27,6 +27,7 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURIT const std::string JsonTagConstants::JSON_RECT = "rect"; const std::string JsonTagConstants::JSON_SC_TYPE = "type"; const std::string JsonTagConstants::JSON_NODE_ID = "nodeId"; +const std::string JsonTagConstants::JSON_IS_WEARABLE = "isWearable"; const std::string JsonTagConstants::JSON_RECT_X = "x"; const std::string JsonTagConstants::JSON_RECT_Y = "y"; const std::string JsonTagConstants::JSON_RECT_WIDTH = "width"; @@ -36,10 +37,15 @@ const std::string JsonTagConstants::JSON_SIZE_TAG = "size"; const std::string JsonTagConstants::JSON_FONT_SIZE_TAG = "fontSize"; const std::string JsonTagConstants::JSON_ICON_SIZE_TAG = "iconSize"; const std::string JsonTagConstants::JSON_PADDING_SIZE_TAG = "paddingSize"; -const std::string JsonTagConstants::JSON_PADDING_LEFT_TAG = "left"; -const std::string JsonTagConstants::JSON_PADDING_TOP_TAG = "top"; -const std::string JsonTagConstants::JSON_PADDING_RIGHT_TAG = "right"; -const std::string JsonTagConstants::JSON_PADDING_BOTTOM_TAG = "bottom"; +const std::string JsonTagConstants::JSON_LEFT_TAG = "left"; +const std::string JsonTagConstants::JSON_TOP_TAG = "top"; +const std::string JsonTagConstants::JSON_RIGHT_TAG = "right"; +const std::string JsonTagConstants::JSON_BOTTOM_TAG = "bottom"; +const std::string JsonTagConstants::JSON_BORDER_RADIUS_TAG = "borderRadius"; +const std::string JsonTagConstants::JSON_LEFT_TOP_TAG = "leftTop"; +const std::string JsonTagConstants::JSON_LEFT_BOTTOM_TAG = "leftBottom"; +const std::string JsonTagConstants::JSON_RIGHT_TOP_TAG = "rightTop"; +const std::string JsonTagConstants::JSON_RIGHT_BOTTOM_TAG = "rightBottom"; const std::string JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG = "textIconSpace"; const std::string JsonTagConstants::JSON_RECT_WIDTH_TAG = "width"; const std::string JsonTagConstants::JSON_RECT_HEIGHT_TAG = "height"; @@ -117,16 +123,39 @@ bool SecCompBase::ParsePadding(const nlohmann::json& json, const std::string& ta } auto jsonPadding = json.at(tag); - if (!ParseDimension(jsonPadding, JsonTagConstants::JSON_PADDING_TOP_TAG, res.top)) { + if (!ParseDimension(jsonPadding, JsonTagConstants::JSON_TOP_TAG, res.top)) { return false; } - if (!ParseDimension(jsonPadding, JsonTagConstants::JSON_PADDING_RIGHT_TAG, res.right)) { + if (!ParseDimension(jsonPadding, JsonTagConstants::JSON_RIGHT_TAG, res.right)) { return false; } - if (!ParseDimension(jsonPadding, JsonTagConstants::JSON_PADDING_BOTTOM_TAG, res.bottom)) { + if (!ParseDimension(jsonPadding, JsonTagConstants::JSON_BOTTOM_TAG, res.bottom)) { return false; } - if (!ParseDimension(jsonPadding, JsonTagConstants::JSON_PADDING_LEFT_TAG, res.left)) { + if (!ParseDimension(jsonPadding, JsonTagConstants::JSON_LEFT_TAG, res.left)) { + return false; + } + return true; +} + +bool SecCompBase::ParseBorderRadius(const nlohmann::json& json, const std::string& tag, BorderRadius& res) +{ + if ((json.find(tag) == json.end()) || !json.at(tag).is_object()) { + SC_LOG_ERROR(LABEL, "json: %{public}s tag invalid.", tag.c_str()); + return false; + } + + auto jsonBorderRadius = json.at(tag); + if (!ParseDimension(jsonBorderRadius, JsonTagConstants::JSON_LEFT_TOP_TAG, res.leftTop)) { + return false; + } + if (!ParseDimension(jsonBorderRadius, JsonTagConstants::JSON_RIGHT_TOP_TAG, res.rightTop)) { + return false; + } + if (!ParseDimension(jsonBorderRadius, JsonTagConstants::JSON_LEFT_BOTTOM_TAG, res.leftBottom)) { + return false; + } + if (!ParseDimension(jsonBorderRadius, JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, res.rightBottom)) { return false; } return true; @@ -185,6 +214,11 @@ bool SecCompBase::ParseSize(const nlohmann::json& json, const std::string& tag) return false; } + if (!ParseBorderRadius(jsonSize, JsonTagConstants::JSON_BORDER_RADIUS_TAG, borderRadius_)) { + return false; + } + rect_.borderRadius_ = borderRadius_; + return true; } @@ -302,6 +336,17 @@ bool SecCompBase::ParseCrossAxisState(const nlohmann::json& json, const std::str return true; } +bool SecCompBase::ParseWearable(const nlohmann::json& json, const std::string& tag) +{ + if ((json.find(tag) == json.end()) || + !json.at(tag).is_boolean()) { + SC_LOG_ERROR(LABEL, "json: %{public}s tag invalid.", tag.c_str()); + return false; + } + isWearableDevice_ = json.at(tag).get(); + return true; +} + bool SecCompBase::FromJson(const nlohmann::json& jsonSrc, std::string& message, bool isClicked) { SC_LOG_DEBUG(LABEL, "Button info %{public}s.", jsonSrc.dump().c_str()); @@ -311,6 +356,9 @@ bool SecCompBase::FromJson(const nlohmann::json& jsonSrc, std::string& message, if (!ParseValue(jsonSrc, JsonTagConstants::JSON_NODE_ID, nodeId_)) { return false; } + if (!ParseWearable(jsonSrc, JsonTagConstants::JSON_IS_WEARABLE)) { + return false; + } if (!ParseRect(jsonSrc, JsonTagConstants::JSON_RECT, rect_)) { return false; } @@ -349,6 +397,7 @@ void SecCompBase::ToJson(nlohmann::json& jsonRes) const { jsonRes[JsonTagConstants::JSON_SC_TYPE] = type_; jsonRes[JsonTagConstants::JSON_NODE_ID] = nodeId_; + jsonRes[JsonTagConstants::JSON_IS_WEARABLE] = isWearableDevice_; jsonRes[JsonTagConstants::JSON_RECT] = nlohmann::json { {JsonTagConstants::JSON_RECT_X, rect_.x_}, {JsonTagConstants::JSON_RECT_Y, rect_.y_}, @@ -362,10 +411,17 @@ void SecCompBase::ToJson(nlohmann::json& jsonRes) const {JsonTagConstants::JSON_RECT_HEIGHT, windowRect_.height_} }; nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, padding_.top }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, padding_.right }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, padding_.bottom }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, padding_.left }, + { JsonTagConstants::JSON_TOP_TAG, padding_.top }, + { JsonTagConstants::JSON_RIGHT_TAG, padding_.right }, + { JsonTagConstants::JSON_BOTTOM_TAG, padding_.bottom }, + { JsonTagConstants::JSON_LEFT_TAG, padding_.left }, + }; + + nlohmann::json jsonBorderRadius = nlohmann::json { + { JsonTagConstants::JSON_LEFT_TOP_TAG, borderRadius_.leftTop }, + { JsonTagConstants::JSON_RIGHT_TOP_TAG, borderRadius_.rightTop }, + { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, borderRadius_.leftBottom }, + { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, borderRadius_.rightBottom }, }; jsonRes[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { @@ -373,6 +429,7 @@ void SecCompBase::ToJson(nlohmann::json& jsonRes) const { JsonTagConstants::JSON_ICON_SIZE_TAG, iconSize_ }, { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, textIconSpace_ }, { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, + { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius }, }; jsonRes[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { 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 a22fd70..3beda08 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_base.h +++ b/interfaces/inner_api/security_component/include/sec_comp_base.h @@ -41,6 +41,7 @@ public: static const std::string JSON_RECT; static const std::string JSON_SC_TYPE; static const std::string JSON_NODE_ID; + static const std::string JSON_IS_WEARABLE; static const std::string JSON_RECT_X; static const std::string JSON_RECT_Y; static const std::string JSON_RECT_WIDTH; @@ -51,10 +52,15 @@ public: static const std::string JSON_FONT_SIZE_TAG; static const std::string JSON_ICON_SIZE_TAG; static const std::string JSON_PADDING_SIZE_TAG; - static const std::string JSON_PADDING_LEFT_TAG; - static const std::string JSON_PADDING_TOP_TAG; - static const std::string JSON_PADDING_RIGHT_TAG; - static const std::string JSON_PADDING_BOTTOM_TAG; + static const std::string JSON_LEFT_TAG; + static const std::string JSON_TOP_TAG; + static const std::string JSON_RIGHT_TAG; + static const std::string JSON_BOTTOM_TAG; + static const std::string JSON_BORDER_RADIUS_TAG; + static const std::string JSON_LEFT_TOP_TAG; + static const std::string JSON_LEFT_BOTTOM_TAG; + static const std::string JSON_RIGHT_TOP_TAG; + static const std::string JSON_RIGHT_BOTTOM_TAG; static const std::string JSON_TEXT_ICON_PADDING_TAG; static const std::string JSON_RECT_WIDTH_TAG; static const std::string JSON_RECT_HEIGHT_TAG; @@ -105,6 +111,7 @@ public: DimensionT fontSize_ = DEFAULT_DIMENSION; DimensionT iconSize_ = DEFAULT_DIMENSION; PaddingSize padding_; + BorderRadius borderRadius_; DimensionT textIconSpace_ = DEFAULT_DIMENSION; // color @@ -137,6 +144,7 @@ public: uint64_t displayId_ = 0; int32_t nodeId_ = 0; CrossAxisState crossAxisState_ = CrossAxisState::STATE_INVALID; + bool isWearableDevice_ = false; protected: virtual bool IsTextIconTypeValid(std::string& message, bool isClicked) = 0; virtual bool IsCorrespondenceType() = 0; @@ -146,6 +154,7 @@ private: bool ParseBool(const nlohmann::json& json, const std::string& tag, bool& res); bool ParseString(const nlohmann::json& json, const std::string& tag, std::string& res); bool ParsePadding(const nlohmann::json& json, const std::string& tag, PaddingSize& res); + bool ParseBorderRadius(const nlohmann::json& json, const std::string& tag, BorderRadius& res); bool ParseColors(const nlohmann::json& json, const std::string& tag); bool ParseBorders(const nlohmann::json& json, const std::string& tag); bool ParseSize(const nlohmann::json& json, const std::string& tag); @@ -156,6 +165,7 @@ private: bool ParseValue(const nlohmann::json& json, const std::string& tag, int32_t& value); bool ParseDisplayId(const nlohmann::json& json, const std::string& tag); bool ParseCrossAxisState(const nlohmann::json& json, const std::string& tag); + bool ParseWearable(const nlohmann::json& json, const std::string& tag); }; } // namespace SecurityComponent } // namespace Security diff --git a/interfaces/inner_api/security_component/include/sec_comp_info.h b/interfaces/inner_api/security_component/include/sec_comp_info.h index edb2056..f81aadc 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_info.h +++ b/interfaces/inner_api/security_component/include/sec_comp_info.h @@ -45,6 +45,13 @@ struct PaddingSize { DimensionT left = DEFAULT_DIMENSION; }; +struct BorderRadius { + DimensionT leftTop = DEFAULT_DIMENSION; + DimensionT rightTop = DEFAULT_DIMENSION; + DimensionT leftBottom = DEFAULT_DIMENSION; + DimensionT rightBottom = DEFAULT_DIMENSION; +}; + enum SecCompType { UNKNOWN_SC_TYPE = 0, LOCATION_COMPONENT, @@ -119,6 +126,7 @@ public: DimensionT y_ = 0.0; DimensionT width_ = 0.0; DimensionT height_ = 0.0; + BorderRadius borderRadius_; }; struct ExtraInfo { 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 8361389..4acb1a3 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 @@ -36,15 +36,25 @@ T* ConstructComponent(const nlohmann::json& jsonComponent, std::string& message, class __attribute__((visibility("default"))) SecCompInfoHelper { public: +struct ScreenInfo { + uint64_t displayId; + CrossAxisState crossAxisState; + bool isWearable; +}; + static SecCompBase* ParseComponent(SecCompType type, const nlohmann::json& jsonComponent, std::string& message, bool isClicked = false); static bool CheckComponentValid(SecCompBase* comp, std::string& message); - static bool CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, const uint64_t displayId, - const CrossAxisState crossAxisState, std::string& message); + static bool CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, const ScreenInfo& screenInfo, + std::string& message); private: static float GetWindowScale(int32_t windowId); static void AdjustSecCompRect(SecCompBase* comp, float scale); + static double GetDistance(DimensionT x1, DimensionT y1, DimensionT x2, DimensionT y2); + 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); }; } // namespace SecurityComponent } // namespace Security diff --git a/services/security_component_service/sa/sa_main/app_state_observer.cpp b/services/security_component_service/sa/sa_main/app_state_observer.cpp index 9a77b3a..a053a12 100644 --- a/services/security_component_service/sa/sa_main/app_state_observer.cpp +++ b/services/security_component_service/sa/sa_main/app_state_observer.cpp @@ -86,7 +86,7 @@ void AppStateObserver::AddProcessToForegroundSet(const AppExecFwk::ProcessData & AddProcessToForegroundSet(processData.pid, proc); } -void AppStateObserver::RemoveProcessFromForegroundSet(const int32_t pid) +void AppStateObserver::RemoveProcessFromForegroundSet(int32_t pid) { Utils::UniqueWriteGuard infoGuard(this->fgProcLock_); for (auto iter = foregrandProcList_.begin(); iter != foregrandProcList_.end(); ++iter) { diff --git a/services/security_component_service/sa/sa_main/app_state_observer.h b/services/security_component_service/sa/sa_main/app_state_observer.h index ad2d132..69df358 100644 --- a/services/security_component_service/sa/sa_main/app_state_observer.h +++ b/services/security_component_service/sa/sa_main/app_state_observer.h @@ -46,7 +46,7 @@ public: void OnAppCacheStateChanged(const AppExecFwk::AppStateData &appStateData) override; private: - void RemoveProcessFromForegroundSet(const int32_t pid); + void RemoveProcessFromForegroundSet(int32_t pid); std::vector foregrandProcList_; OHOS::Utils::RWLock fgProcLock_; }; diff --git a/services/security_component_service/sa/sa_main/first_use_dialog.cpp b/services/security_component_service/sa/sa_main/first_use_dialog.cpp index 600e4c7..445c621 100644 --- a/services/security_component_service/sa/sa_main/first_use_dialog.cpp +++ b/services/security_component_service/sa/sa_main/first_use_dialog.cpp @@ -265,7 +265,6 @@ void FirstUseDialog::RemoveDialogWaitEntitys(int32_t pid) std::shared_ptr entity = iter->second; if ((entity != nullptr) && (entity->pid_ == pid)) { iter = dialogWaitMap_.erase(iter); - SC_LOG_ERROR(LABEL, "dialog %{public}d is removed", pid); } else { ++iter; } 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 5f369c4..90d2c5d 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 @@ -25,6 +25,7 @@ #include "paste_button.h" #include "save_button.h" #include "sec_comp_err.h" +#include "sec_comp_info.h" #include "sec_comp_log.h" #include "sec_comp_tool.h" #include "window_info_helper.h" @@ -41,6 +42,7 @@ const std::string OUT_OF_WINDOW = ", security component is out of window, securi const std::string SECURITY_COMPONENT_IS_TOO_LARGER = ", security component is too larger, security component(width = "; const int HEX_FIELD_WIDTH = 2; +const int NUMBER_TWO = 2; const char HEX_FILL_CHAR = '0'; } @@ -111,12 +113,73 @@ static bool GetScreenSize(double& width, double& height, const uint64_t displayI return true; } +double SecCompInfoHelper::GetDistance(DimensionT x1, DimensionT y1, DimensionT x2, DimensionT y2) +{ + return sqrt(pow(x1 - x2, NUMBER_TWO) + pow(y1 -y2, NUMBER_TWO)); +} + +bool SecCompInfoHelper::IsOutOfWatchScreen(const SecCompRect& rect, double radius, std::string& message) +{ + double leftTop = GetDistance(rect.x_ + rect.borderRadius_.leftTop, + rect.y_ + rect.borderRadius_.leftTop, radius, radius); + double leftBottom = GetDistance(rect.x_ + rect.borderRadius_.leftBottom, + rect.y_ + rect.height_ - rect.borderRadius_.leftBottom, radius, radius); + double rightTop = GetDistance(rect.x_ + rect.width_ - rect.borderRadius_.rightTop, + rect.y_ + rect.borderRadius_.rightTop, radius, radius); + double rightBottom = GetDistance(rect.x_ + rect.width_ - rect.borderRadius_.rightBottom, + rect.y_ + rect.height_ - rect.borderRadius_.rightBottom, radius, radius); + if (GreatNotEqual(leftTop, radius - rect.borderRadius_.leftTop + 1.0) || + GreatNotEqual(leftBottom, radius - rect.borderRadius_.leftBottom + 1.0) || + GreatNotEqual(rightTop, radius - rect.borderRadius_.rightTop + 1.0) || + GreatNotEqual(rightBottom, radius - rect.borderRadius_.rightBottom + 1.0)) { + SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of screen"); + message = OUT_OF_SCREEN + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + + ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + + "), current screen(width = " + std::to_string(radius) + + ", height = " + std::to_string(radius) + ")"; + return true; + } + return false; +} + +bool SecCompInfoHelper::IsOutOfScreen(const SecCompRect& rect, double curScreenWidth, double curScreenHeight, + std::string& message, bool isWearable) +{ + if (isWearable) { + if (IsOutOfWatchScreen(rect, curScreenHeight / NUMBER_TWO, message)) { + return true; + } + } else { + if (GreatNotEqual(ZERO_OFFSET, rect.x_) || GreatNotEqual(ZERO_OFFSET, rect.y_) || + GreatNotEqual(rect.x_, curScreenWidth) || GreatNotEqual(rect.y_, curScreenHeight)) { + SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of screen"); + message = OUT_OF_SCREEN + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + + ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + + "), current screen(width = " + std::to_string(curScreenWidth) + + ", height = " + std::to_string(curScreenHeight) + ")"; + return true; + } + + if (GreatOrEqual((rect.x_ + rect.width_), curScreenWidth) || + GreatOrEqual((rect.y_ + rect.height_), curScreenHeight)) { + SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of screen"); + message = OUT_OF_SCREEN + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + + ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + + "), current screen(width = " + std::to_string(curScreenWidth) + + ", height = " + std::to_string(curScreenHeight) + ")"; + return true; + } + } + + return false; +} + bool SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, - const uint64_t displayId, const CrossAxisState crossAxisState, std::string& message) + const ScreenInfo& screenInfo, std::string& message) { double curScreenWidth = 0.0F; double curScreenHeight = 0.0F; - if (!GetScreenSize(curScreenWidth, curScreenHeight, displayId, crossAxisState)) { + if (!GetScreenSize(curScreenWidth, curScreenHeight, screenInfo.displayId, screenInfo.crossAxisState)) { SC_LOG_ERROR(LABEL, "Get screen size is invalid"); return false; } @@ -126,13 +189,7 @@ bool SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRec return false; } - if (GreatNotEqual(ZERO_OFFSET, rect.x_) || GreatNotEqual(ZERO_OFFSET, rect.y_) || - GreatNotEqual(rect.x_, curScreenWidth) || GreatNotEqual(rect.y_, curScreenHeight)) { - SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of screen"); - message = OUT_OF_SCREEN + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + - ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + - "), current screen(width = " + std::to_string(curScreenWidth) + - ", height = " + std::to_string(curScreenHeight) + ")"; + if (IsOutOfScreen(rect, curScreenWidth, curScreenHeight, message, screenInfo.isWearable)) { return false; } 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 2687ce1..c453ee8 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 @@ -229,7 +229,7 @@ void SecCompManager::NotifyProcessBackground(int32_t pid) void SecCompManager::NotifyProcessDied(int32_t pid, bool isProcessCached) { if (!isProcessCached) { - // notify enhance process died. + // notify enhance process died. SecCompEnhanceAdapter::NotifyProcessDied(pid); malicious_.RemoveAppFromMaliciousAppList(pid); } @@ -475,8 +475,14 @@ int32_t SecCompManager::CheckClickSecurityComponentInfo(std::shared_ptrdisplayId_, + .crossAxisState = report->crossAxisState_, + .isWearable = report->isWearableDevice_ + }; + if ((!SecCompInfoHelper::CheckRectValid(reportComponentInfo->rect_, reportComponentInfo->windowRect_, - report->displayId_, report->crossAxisState_, message))) { + screenInfo, message))) { 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 a464dd1..fe68501 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_helper.h" #include "sec_comp_log.h" #include "sec_comp_err.h" #include "sec_comp_tool.h" @@ -153,36 +154,41 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent004, TestSize.Level1) SecCompRect rect = GetDefaultRect(); SecCompRect windowRect = GetDefaultRect(); std::string message; - ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + SecCompInfoHelper::ScreenInfo screenInfo = { + .displayId = 0, + .crossAxisState = CrossAxisState::STATE_INVALID, + .isWearable = false + }; + ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); rect.x_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); rect.x_ = g_testWidth; rect.y_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); rect.y_ = g_testHeight; rect.x_ = g_curScreenWidth + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); rect.x_ = g_testWidth; rect.y_ = g_curScreenHeight + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); rect.y_ = g_testHeight; rect.width_ = g_curScreenWidth; rect.height_ = g_curScreenHeight; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); rect.width_ = g_testWidth; rect.height_ = g_testHeight; rect.x_ = g_curScreenWidth - g_testWidth; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); rect.x_ = g_testWidth; rect.y_ = g_curScreenHeight - g_testHeight; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); rect.y_ = g_testHeight; } @@ -197,30 +203,35 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent005, TestSize.Level1) SecCompRect rect = GetDefaultRect(); SecCompRect windowRect = GetDefaultRect(); std::string message; - ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + SecCompInfoHelper::ScreenInfo screenInfo = { + .displayId = 0, + .crossAxisState = CrossAxisState::STATE_INVALID, + .isWearable = false + }; + ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); windowRect.x_ = g_testWidth + 2.0; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); windowRect.x_ = g_testWidth; windowRect.y_ = g_testHeight + 2.0; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); windowRect.y_ = g_testHeight; windowRect.width_ = g_testWidth - 2.0; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); windowRect.width_ = g_testWidth; windowRect.height_ = g_testHeight - 2.0; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); windowRect.height_ = g_testHeight; windowRect.width_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); windowRect.width_ = g_testWidth; windowRect.height_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, CrossAxisState::STATE_INVALID, message)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); windowRect.height_ = g_testHeight; } @@ -299,12 +310,12 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent008, TestSize.Level1) auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; - paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; + paddingJson[JsonTagConstants::JSON_TOP_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); - paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = ServiceTestCommon::TEST_DIMENSION; - paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; + paddingJson[JsonTagConstants::JSON_TOP_TAG] = ServiceTestCommon::TEST_DIMENSION; + paddingJson[JsonTagConstants::JSON_RIGHT_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -325,12 +336,12 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent009, TestSize.Level1) auto& sizesJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingsJson = sizesJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; - paddingsJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; + paddingsJson[JsonTagConstants::JSON_BOTTOM_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); - paddingsJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = ServiceTestCommon::TEST_DIMENSION; - paddingsJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; + paddingsJson[JsonTagConstants::JSON_BOTTOM_TAG] = ServiceTestCommon::TEST_DIMENSION; + paddingsJson[JsonTagConstants::JSON_LEFT_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -431,16 +442,16 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent013, TestSize.Level1) styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::NO_BG_TYPE; auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; - paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; - paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; - paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); - paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG; - paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = ServiceTestCommon::TEST_DIMENSION; - paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; - paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_TOP_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_RIGHT_TAG] = ServiceTestCommon::TEST_DIMENSION; + paddingJson[JsonTagConstants::JSON_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -464,16 +475,16 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent014, TestSize.Level1) auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; - paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG; - paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; - paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_TOP_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); - paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG; - paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; - paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; - paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = ServiceTestCommon::TEST_DIMENSION; + paddingJson[JsonTagConstants::JSON_TOP_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; + paddingJson[JsonTagConstants::JSON_LEFT_TAG] = ServiceTestCommon::TEST_DIMENSION; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } diff --git a/services/security_component_service/sa/test/unittest/src/service_test_common.cpp b/services/security_component_service/sa/test/unittest/src/service_test_common.cpp index 75db0fc..69ef4c6 100644 --- a/services/security_component_service/sa/test/unittest/src/service_test_common.cpp +++ b/services/security_component_service/sa/test/unittest/src/service_test_common.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ #include "service_test_common.h" +#include "sec_comp_base.h" namespace OHOS { namespace Security { @@ -21,6 +22,7 @@ void ServiceTestCommon::BuildLocationComponentJson(nlohmann::json& jsonComponent { jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0; + jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false; jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json { {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE }, {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE }, @@ -34,10 +36,17 @@ void ServiceTestCommon::BuildLocationComponentJson(nlohmann::json& jsonComponent { JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE } }; nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, + }; + + nlohmann::json jsonBorderRadius = nlohmann::json { + { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, TEST_DIMENSION }, }; jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { @@ -45,6 +54,7 @@ void ServiceTestCommon::BuildLocationComponentJson(nlohmann::json& jsonComponent { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, + { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius}, }; jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { @@ -79,6 +89,7 @@ void ServiceTestCommon::BuildSaveComponentJson(nlohmann::json& jsonComponent) { jsonComponent[JsonTagConstants::JSON_SC_TYPE] = SAVE_COMPONENT; jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0; + jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false; jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json { {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE }, {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE }, @@ -92,10 +103,17 @@ void ServiceTestCommon::BuildSaveComponentJson(nlohmann::json& jsonComponent) {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE } }; nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, + }; + + nlohmann::json jsonBorderRadius = nlohmann::json { + { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, TEST_DIMENSION }, }; jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { @@ -103,6 +121,7 @@ void ServiceTestCommon::BuildSaveComponentJson(nlohmann::json& jsonComponent) { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, + { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius}, }; jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { @@ -137,6 +156,7 @@ void ServiceTestCommon::BuildPasteComponentJson(nlohmann::json& jsonComponent) { jsonComponent[JsonTagConstants::JSON_SC_TYPE] = PASTE_COMPONENT; jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0; + jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false; jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json { {JsonTagConstants::JSON_RECT_X, ServiceTestCommon::TEST_COORDINATE }, {JsonTagConstants::JSON_RECT_Y, ServiceTestCommon::TEST_COORDINATE }, @@ -150,10 +170,17 @@ void ServiceTestCommon::BuildPasteComponentJson(nlohmann::json& jsonComponent) {JsonTagConstants::JSON_RECT_HEIGHT, ServiceTestCommon::TEST_COORDINATE } }; nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_TOP_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_BOTTOM_TAG, ServiceTestCommon::TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_TAG, ServiceTestCommon::TEST_DIMENSION }, + }; + + nlohmann::json jsonBorderRadius = nlohmann::json { + { JsonTagConstants::JSON_LEFT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_TOP_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, TEST_DIMENSION }, + { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, TEST_DIMENSION }, }; jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { @@ -161,6 +188,7 @@ void ServiceTestCommon::BuildPasteComponentJson(nlohmann::json& jsonComponent) { JsonTagConstants::JSON_ICON_SIZE_TAG, ServiceTestCommon::TEST_SIZE }, { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, ServiceTestCommon::TEST_SIZE }, { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, + { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius}, }; jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { diff --git a/test/fuzztest/security_component/common/fuzz_common.cpp b/test/fuzztest/security_component/common/fuzz_common.cpp index 184b1fa..e3f8f39 100644 --- a/test/fuzztest/security_component/common/fuzz_common.cpp +++ b/test/fuzztest/security_component/common/fuzz_common.cpp @@ -63,10 +63,12 @@ std::string CompoRandomGenerator::ConstructLocationJson() nlohmann::json jsonComponent; jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0; + jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false; SecCompRect window; PaddingSize padding; SecCompRect buttonRect; - ConstructWindowJson(jsonComponent, window, padding, buttonRect); + BorderRadius borderRadius; + ConstructWindowJson(jsonComponent, window, padding, borderRadius, buttonRect); jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { { JsonTagConstants::JSON_FONT_COLOR_TAG, GetData() }, @@ -107,10 +109,12 @@ std::string CompoRandomGenerator::ConstructSaveJson() nlohmann::json jsonComponent; jsonComponent[JsonTagConstants::JSON_SC_TYPE] = SAVE_COMPONENT; jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0; + jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false; SecCompRect window; PaddingSize padding; SecCompRect buttonRect; - ConstructWindowJson(jsonComponent, window, padding, buttonRect); + BorderRadius borderRadius; + ConstructWindowJson(jsonComponent, window, padding, borderRadius, buttonRect); jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { { JsonTagConstants::JSON_FONT_COLOR_TAG, GetData() }, @@ -151,10 +155,12 @@ std::string CompoRandomGenerator::ConstructPasteJson() nlohmann::json jsonComponent; jsonComponent[JsonTagConstants::JSON_SC_TYPE] = PASTE_COMPONENT; jsonComponent[JsonTagConstants::JSON_NODE_ID] = 0; + jsonComponent[JsonTagConstants::JSON_IS_WEARABLE] = false; SecCompRect window; PaddingSize padding; SecCompRect buttonRect; - ConstructWindowJson(jsonComponent, window, padding, buttonRect); + BorderRadius borderRadius; + ConstructWindowJson(jsonComponent, window, padding, borderRadius, buttonRect); jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { { JsonTagConstants::JSON_FONT_COLOR_TAG, GetData() }, @@ -209,8 +215,8 @@ void CompoRandomGenerator::ConstructButtonRect( padding.right = window.x_ + window.width_ - buttonRect.x_ - buttonRect.width_; } -void CompoRandomGenerator::ConstructWindowJson( - nlohmann::json &jsonComponent, SecCompRect &window, PaddingSize &padding, SecCompRect &buttonRect) +void CompoRandomGenerator::ConstructWindowJson(nlohmann::json &jsonComponent, SecCompRect &window, + PaddingSize &padding, BorderRadius &borderRadius, SecCompRect &buttonRect) { ConstructButtonRect(window, padding, buttonRect); jsonComponent[JsonTagConstants::JSON_RECT] = nlohmann::json { @@ -226,10 +232,17 @@ void CompoRandomGenerator::ConstructWindowJson( { JsonTagConstants::JSON_RECT_HEIGHT, window.height_ } }; nlohmann::json jsonPadding = nlohmann::json { - { JsonTagConstants::JSON_PADDING_TOP_TAG, padding.top }, - { JsonTagConstants::JSON_PADDING_RIGHT_TAG, padding.right }, - { JsonTagConstants::JSON_PADDING_BOTTOM_TAG, padding.bottom }, - { JsonTagConstants::JSON_PADDING_LEFT_TAG, padding.left }, + { JsonTagConstants::JSON_TOP_TAG, padding.top }, + { JsonTagConstants::JSON_RIGHT_TAG, padding.right }, + { JsonTagConstants::JSON_BOTTOM_TAG, padding.bottom }, + { JsonTagConstants::JSON_LEFT_TAG, padding.left }, + }; + + nlohmann::json jsonBorderRadius = nlohmann::json { + { JsonTagConstants::JSON_LEFT_TOP_TAG, borderRadius.leftTop }, + { JsonTagConstants::JSON_RIGHT_TOP_TAG, borderRadius.rightTop }, + { JsonTagConstants::JSON_LEFT_BOTTOM_TAG, borderRadius.leftBottom }, + { JsonTagConstants::JSON_RIGHT_BOTTOM_TAG, borderRadius.rightBottom }, }; jsonComponent[JsonTagConstants::JSON_SIZE_TAG] = nlohmann::json { @@ -237,6 +250,7 @@ void CompoRandomGenerator::ConstructWindowJson( { JsonTagConstants::JSON_ICON_SIZE_TAG, std::fabs(GetData()) }, { JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG, std::fabs(GetData()) }, { JsonTagConstants::JSON_PADDING_SIZE_TAG, jsonPadding }, + { JsonTagConstants::JSON_BORDER_RADIUS_TAG, jsonBorderRadius}, }; } } diff --git a/test/fuzztest/security_component/common/fuzz_common.h b/test/fuzztest/security_component/common/fuzz_common.h index 9f08a80..ebf8c0b 100644 --- a/test/fuzztest/security_component/common/fuzz_common.h +++ b/test/fuzztest/security_component/common/fuzz_common.h @@ -63,7 +63,7 @@ private: void ConstructButtonRect( SecCompRect &window, PaddingSize &padding, SecCompRect &buttonRect); void ConstructWindowJson(nlohmann::json &jsonComponent, - SecCompRect &window, PaddingSize &padding, SecCompRect &buttonRect); + SecCompRect &window, PaddingSize &padding, BorderRadius &borderRadius, SecCompRect &buttonRect); const uint8_t *data_; const size_t dataLenth_; -- Gitee From 69ce38c18a19c732d843098913c78d401696398a Mon Sep 17 00:00:00 2001 From: baoyang Date: Fri, 28 Feb 2025 04:32:37 +0000 Subject: [PATCH 2/3] update services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp. Signed-off-by: baoyang --- .../sa/sa_main/sec_comp_info_helper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 90d2c5d..5d5c8a3 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 @@ -135,8 +135,8 @@ bool SecCompInfoHelper::IsOutOfWatchScreen(const SecCompRect& rect, double radiu SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of screen"); message = OUT_OF_SCREEN + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + - "), current screen(width = " + std::to_string(radius) + - ", height = " + std::to_string(radius) + ")"; + "), current screen(width = " + std::to_string(radius * NUMBER_TWO) + + ", height = " + std::to_string(radius * NUMBER_TWO) + ")"; return true; } return false; -- Gitee From 210bd3b54613d755174bd9ba8439b57b820e3759 Mon Sep 17 00:00:00 2001 From: baoyang Date: Fri, 28 Feb 2025 06:43:43 +0000 Subject: [PATCH 3/3] update services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp. Signed-off-by: baoyang --- .../sa/sa_main/sec_comp_info_helper.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) 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 5d5c8a3..50c158d 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 @@ -160,8 +160,8 @@ bool SecCompInfoHelper::IsOutOfScreen(const SecCompRect& rect, double curScreenW return true; } - if (GreatOrEqual((rect.x_ + rect.width_), curScreenWidth) || - GreatOrEqual((rect.y_ + rect.height_), curScreenHeight)) { + if (GreatOrEqual((rect.x_ + rect.width_), curScreenWidth + 1.0) || + GreatOrEqual((rect.y_ + rect.height_), curScreenHeight + 1.0)) { SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of screen"); message = OUT_OF_SCREEN + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + @@ -193,16 +193,6 @@ bool SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRec return false; } - if (GreatNotEqual((rect.x_ + rect.width_), curScreenWidth + 1.0) || - GreatNotEqual((rect.y_ + rect.height_), curScreenHeight + 1.0)) { - SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of screen"); - message = OUT_OF_SCREEN + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + - ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + - "), current screen(width = " + std::to_string(curScreenWidth) + - ", height = " + std::to_string(curScreenHeight) + ")"; - 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)) { -- Gitee