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 502233992c739d26270096cf0c3cc2a43c5e2015..2e41c80ae232052f47bf5a2f46ee4bbf26e3bc3f 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 7ce03fcb382be0cefd174e280d900555bd7bb472..3974f8c2291bf2ea76008ee7eaff6ca3145c68ab 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 6cf600b3d0403f743867d716aeb008744312fa44..6712ed3d85f0758657d0b8a2ae5f86d9b2cd5961 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 a22fd70faba02ba0d3459881c762e1a32a167a19..3beda08ee250c58c841bf054da5209a294a6cfed 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 edb2056102c4b5070b7abc0d40bea462c851f4f9..f81aadc35277cc43a1d7ee55ba98280bdcea468b 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 836138963a2e85f76f640530fdf6a6b3fb5ba873..4acb1a3cc5e8239ba7f0343dcf4f1b265e236c46 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 9a77b3a2146474eb55342fd45c049b8072124bda..a053a129c5123feb33bd547b2fce9e7299a38b5f 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 ad2d13201feae81f939a00d950215bf698cd931a..69df3588b856e37dc0501fb3e72738d4599a9f79 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 600e4c73f6937997a6bcff2c89c536d6b8d22ed6..445c621956bec2dda92ca269d139a350ce9f4f26 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 5f369c47bd31ab31036efce0b34c4afd9d5e1824..50c158d2292cdd3df0838221e8cc0e2c1c055a50 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 * NUMBER_TWO) + + ", height = " + std::to_string(radius * NUMBER_TWO) + ")"; + 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 + 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_) + + "), 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,23 +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) + ")"; - 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) + ")"; + 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 2687ce1ae46ce55a108e7ac9e18453d7109c8363..c453ee8118a0999da4e5a0ebe5d0dde5d8d520ee 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 a464dd17cbb7044e66917d1d89552f41b2cc6732..fe68501897d2ac37c043d73b2acfd64156f0d29f 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 75db0fce98012b4220dc9e09c4ab0862def7688f..69ef4c6d8b9307810b3ddba730b126edf2ac268f 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 184b1fa6cc22c76295c941fa189e2c94d111d830..e3f8f3905e6f98b87c536643501850bc5bbe9748 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 9f08a80f675b20a2263ed87934d4e3e1231adfc8..ebf8c0b5f9d31cee5bb3b3bbf2ff2e0f69f61e13 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_;