From f30d17494958e29354ba589230552fb449042435 Mon Sep 17 00:00:00 2001 From: baoyang Date: Fri, 28 Feb 2025 18:01:02 +0800 Subject: [PATCH] add hisysevent Signed-off-by: baoyang Change-Id: I15051a8346db340e375944f2fe272df6f7f53a63 --- .../test/unittest/src/test_common.cpp | 9 +++++++ .../security_component/src/sec_comp_base.cpp | 26 +++++++++++++++++++ .../include/sec_comp_base.h | 7 +++++ .../sa/sa_main/sec_comp_manager.cpp | 2 +- .../test/unittest/src/service_test_common.cpp | 9 +++++++ .../security_component/common/fuzz_common.cpp | 9 +++++++ 6 files changed, 61 insertions(+), 1 deletion(-) 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..3536676 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 @@ -73,6 +73,9 @@ void TestCommon::BuildLocationComponentInfo(nlohmann::json& jsonComponent) jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0; jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0; jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0; + jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false; + jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false; + jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0; } void TestCommon::BuildSaveComponentInfo(nlohmann::json& jsonComponent) @@ -131,6 +134,9 @@ void TestCommon::BuildSaveComponentInfo(nlohmann::json& jsonComponent) jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0; jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0; jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0; + jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false; + jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false; + jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0; } void TestCommon::BuildPasteComponentInfo(nlohmann::json& jsonComponent) @@ -189,6 +195,9 @@ void TestCommon::BuildPasteComponentInfo(nlohmann::json& jsonComponent) jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0; jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0; jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0; + jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false; + jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false; + jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0; } } // namespace SecurityComponent } // namespace Security diff --git a/frameworks/security_component/src/sec_comp_base.cpp b/frameworks/security_component/src/sec_comp_base.cpp index 3d121ec..468b96e 100644 --- a/frameworks/security_component/src/sec_comp_base.cpp +++ b/frameworks/security_component/src/sec_comp_base.cpp @@ -64,6 +64,28 @@ const std::string JsonTagConstants::JSON_BG_TAG = "bg"; const std::string JsonTagConstants::JSON_WINDOW_ID = "windowId"; const std::string JsonTagConstants::JSON_DISPLAY_ID = "displayId"; const std::string JsonTagConstants::JSON_CROSS_AXIS_STATE = "crossAxisState"; +const std::string JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG = "hasNonCompatileChange"; +const std::string JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG = "blurRadius"; +const std::string JsonTagConstants::JSON_IS_BORDER_COVERED_TAG = "isBorderCovered"; + +bool SecCompBase::ParseNonCompatibleChange(const nlohmann::json& json) +{ + std::string tag = JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_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; + } + hasNonCompatileChange_ = json.at(tag).get(); + + if (!ParseDimension(json, JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG, blurRadius_)) { + return false; + } + if (!ParseBool(json, JsonTagConstants::JSON_IS_BORDER_COVERED_TAG, isBorderCovered_)) { + return false; + } + + return true; +} bool SecCompBase::ParseDimension(const nlohmann::json& json, const std::string& tag, DimensionT& res) { @@ -341,6 +363,7 @@ bool SecCompBase::FromJson(const nlohmann::json& jsonSrc) if (!ParseCrossAxisState(jsonSrc, JsonTagConstants::JSON_CROSS_AXIS_STATE)) { return false; } + ParseNonCompatibleChange(jsonSrc); return true; } @@ -402,6 +425,9 @@ void SecCompBase::ToJson(nlohmann::json& jsonRes) const jsonRes[JsonTagConstants::JSON_WINDOW_ID] = windowId_; jsonRes[JsonTagConstants::JSON_DISPLAY_ID] = displayId_; jsonRes[JsonTagConstants::JSON_CROSS_AXIS_STATE] = crossAxisState_; + jsonRes[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = hasNonCompatileChange_; + jsonRes[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = blurRadius_; + jsonRes[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = isBorderCovered_; } std::string SecCompBase::ToJsonStr() const 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 44b493a..3f2949c 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_base.h +++ b/interfaces/inner_api/security_component/include/sec_comp_base.h @@ -80,6 +80,9 @@ public: static const std::string JSON_WINDOW_ID; static const std::string JSON_DISPLAY_ID; static const std::string JSON_CROSS_AXIS_STATE; + static const std::string JSON_NON_COMPATIBLE_CHANGE_TAG; + static const std::string JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG; + static const std::string JSON_IS_BORDER_COVERED_TAG; }; class __attribute__((visibility("default"))) SecCompBase { @@ -132,6 +135,9 @@ public: int32_t icon_ = UNKNOWN_ICON; SecCompBackground bg_ = SecCompBackground::UNKNOWN_BG; + bool hasNonCompatileChange_ = false; + double blurRadius_ = 0.0; + bool isBorderCovered_ = false; int32_t windowId_ = 0; uint64_t displayId_ = 0; int32_t nodeId_ = 0; @@ -140,6 +146,7 @@ protected: virtual bool IsTextIconTypeValid() = 0; virtual bool IsCorrespondenceType() = 0; private: + bool ParseNonCompatibleChange(const nlohmann::json& json); bool ParseDimension(const nlohmann::json& json, const std::string& tag, DimensionT& res); bool ParseColor(const nlohmann::json& json, const std::string& tag, SecCompColor& res); bool ParseBool(const nlohmann::json& json, const std::string& tag, bool& res); 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 944f141..88ae01b 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 @@ -457,7 +457,7 @@ int32_t SecCompManager::CheckClickSecurityComponentInfo(std::shared_ptrGetType()); return SC_SERVICE_ERROR_COMPONENT_INFO_INVALID; } - if (report && (report->isClipped_)) { + if (report && (report->isClipped_ || report->hasNonCompatileChange_)) { HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "CLIP_CHECK_FAILED", HiviewDFX::HiSysEvent::EventType::SECURITY, "CALLER_BUNDLE_NAME", bundleName, "COMPONENT_INFO", jsonComponent.dump().c_str()); 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..65e39c5 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 @@ -73,6 +73,9 @@ void ServiceTestCommon::BuildLocationComponentJson(nlohmann::json& jsonComponent jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0; jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0; jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0; + jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false; + jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false; + jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0; } void ServiceTestCommon::BuildSaveComponentJson(nlohmann::json& jsonComponent) @@ -131,6 +134,9 @@ void ServiceTestCommon::BuildSaveComponentJson(nlohmann::json& jsonComponent) jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0; jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0; jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0; + jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false; + jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false; + jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0; } void ServiceTestCommon::BuildPasteComponentJson(nlohmann::json& jsonComponent) @@ -189,6 +195,9 @@ void ServiceTestCommon::BuildPasteComponentJson(nlohmann::json& jsonComponent) jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0; jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0; jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0; + jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false; + jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false; + jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0; } } // namespace SecurityComponent } // namespace Security diff --git a/test/fuzztest/security_component/common/fuzz_common.cpp b/test/fuzztest/security_component/common/fuzz_common.cpp index 741833f..c4118e8 100644 --- a/test/fuzztest/security_component/common/fuzz_common.cpp +++ b/test/fuzztest/security_component/common/fuzz_common.cpp @@ -111,6 +111,9 @@ std::string CompoRandomGenerator::ConstructLocationJson() jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0; jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0; jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0; + jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false; + jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false; + jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0; return jsonComponent.dump(); } @@ -155,6 +158,9 @@ std::string CompoRandomGenerator::ConstructSaveJson() jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0; jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0; jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0; + jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false; + jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false; + jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0; return jsonComponent.dump(); } @@ -198,6 +204,9 @@ std::string CompoRandomGenerator::ConstructPasteJson() jsonComponent[JsonTagConstants::JSON_WINDOW_ID] = 0; jsonComponent[JsonTagConstants::JSON_DISPLAY_ID] = 0; jsonComponent[JsonTagConstants::JSON_CROSS_AXIS_STATE] = 0; + jsonComponent[JsonTagConstants::JSON_IS_BORDER_COVERED_TAG] = false; + jsonComponent[JsonTagConstants::JSON_NON_COMPATIBLE_CHANGE_TAG] = false; + jsonComponent[JsonTagConstants::JSON_LINEAR_GRADIENT_BLUR_RADIUS_TAG] = 0.0; return jsonComponent.dump(); } -- Gitee