From 312004efb54f5d2b4d2afc6ba97742fa951ac2ae Mon Sep 17 00:00:00 2001 From: baoyang Date: Wed, 25 Sep 2024 12:41:37 +0000 Subject: [PATCH] add hisysevent Signed-off-by: baoyang Change-Id: Iba83f7619a4a66ea8b20e4d338f787ac30934887 --- .../security_component/src/sec_comp_base.cpp | 46 ++++++++++++++++++- hisysevent.yaml | 5 ++ .../include/sec_comp_base.h | 13 ++++++ .../test/unittest/src/test_common.cpp | 18 ++++++++ .../sa/sa_main/sec_comp_info_helper.cpp | 14 ++++++ .../src/sec_comp_info_helper_test.cpp | 6 +++ .../test/unittest/src/service_test_common.cpp | 18 ++++++++ 7 files changed, 119 insertions(+), 1 deletion(-) diff --git a/frameworks/security_component/src/sec_comp_base.cpp b/frameworks/security_component/src/sec_comp_base.cpp index 84b3a78..22d10f3 100644 --- a/frameworks/security_component/src/sec_comp_base.cpp +++ b/frameworks/security_component/src/sec_comp_base.cpp @@ -51,6 +51,12 @@ const std::string JsonTagConstants::JSON_BORDER_TAG = "border"; const std::string JsonTagConstants::JSON_BORDER_WIDTH_TAG = "borderWidth"; const std::string JsonTagConstants::JSON_PARENT_TAG = "parent"; const std::string JsonTagConstants::JSON_PARENT_EFFECT_TAG = "parentEffect"; +const std::string JsonTagConstants::JSON_IS_CLIPPED_TAG = "isClipped"; +const std::string JsonTagConstants::JSON_TOP_CLIP_TAG = "topClip"; +const std::string JsonTagConstants::JSON_BOTTOM_CLIP_TAG = "bottomClip"; +const std::string JsonTagConstants::JSON_LEFT_CLIP_TAG = "leftClip"; +const std::string JsonTagConstants::JSON_RIGHT_CLIP_TAG = "rightClip"; +const std::string JsonTagConstants::JSON_PARENT_TAG_TAG = "parentTag"; const std::string JsonTagConstants::JSON_STYLE_TAG = "style"; const std::string JsonTagConstants::JSON_TEXT_TAG = "text"; const std::string JsonTagConstants::JSON_ICON_TAG = "icon"; @@ -90,6 +96,17 @@ bool SecCompBase::ParseBool(const nlohmann::json& json, const std::string& tag, return true; } +bool SecCompBase::ParseString(const nlohmann::json& json, const std::string& tag, std::string& res) +{ + if ((json.find(tag) == json.end()) || !json.at(tag).is_string()) { + SC_LOG_ERROR(LABEL, "json: %{public}s tag invalid.", tag.c_str()); + return false; + } + + res = json.at(tag).get(); + return true; +} + bool SecCompBase::ParsePadding(const nlohmann::json& json, const std::string& tag, PaddingSize& res) { if ((json.find(tag) == json.end()) || !json.at(tag).is_object()) { @@ -176,7 +193,28 @@ bool SecCompBase::ParseParent(const nlohmann::json& json, const std::string& tag return false; } auto jsonParent = json.at(tag); - return ParseBool(jsonParent, JsonTagConstants::JSON_PARENT_EFFECT_TAG, parentEffect_); + if (!ParseBool(jsonParent, JsonTagConstants::JSON_PARENT_EFFECT_TAG, parentEffect_)) { + return false; + } + if (!ParseBool(jsonParent, JsonTagConstants::JSON_IS_CLIPPED_TAG, isClipped_)) { + return false; + } + if (!ParseDimension(jsonParent, JsonTagConstants::JSON_TOP_CLIP_TAG, topClip_)) { + return false; + } + if (!ParseDimension(jsonParent, JsonTagConstants::JSON_BOTTOM_CLIP_TAG, bottomClip_)) { + return false; + } + if (!ParseDimension(jsonParent, JsonTagConstants::JSON_LEFT_CLIP_TAG, leftClip_)) { + return false; + } + if (!ParseDimension(jsonParent, JsonTagConstants::JSON_RIGHT_CLIP_TAG, rightClip_)) { + return false; + } + if (!ParseString(jsonParent, JsonTagConstants::JSON_PARENT_TAG_TAG, parentTag_)) { + return false; + } + return true; } bool SecCompBase::ParseRect(const nlohmann::json& json, const std::string& tag, SecCompRect& rect) @@ -301,6 +339,12 @@ void SecCompBase::ToJson(nlohmann::json& jsonRes) const }; jsonRes[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { { JsonTagConstants::JSON_PARENT_EFFECT_TAG, parentEffect_ }, + { JsonTagConstants::JSON_IS_CLIPPED_TAG, isClipped_ }, + { JsonTagConstants::JSON_TOP_CLIP_TAG, topClip_ }, + { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, bottomClip_ }, + { JsonTagConstants::JSON_LEFT_CLIP_TAG, leftClip_ }, + { JsonTagConstants::JSON_RIGHT_CLIP_TAG, rightClip_ }, + { JsonTagConstants::JSON_PARENT_TAG_TAG, parentTag_ }, }; jsonRes[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { diff --git a/hisysevent.yaml b/hisysevent.yaml index 2766531..44c4d55 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -127,3 +127,8 @@ PREPROCESS_MESSAGE_FAILED: CALLER_BUNDLE_NAME: {type: STRING, desc: caller bundle name} CLIENT_SESSION_ID: {type: INT32, desc: session id stored in client} CLIENT_SEQ_NUM: {type: INT32, desc: sequence number stored in client} + +CLIP_CHECK_FAILED: + __BASE: {type: SECURITY, level: CRITICAL, desc: The security component is clipped by parent component} + CALLER_BUNDLE_NAME: {type: STRING, desc: caller bundle name} + COMPONENT_INFO: {type: STRING, desc: component information} \ No newline at end of file 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 30d15fe..f7c0130 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_base.h +++ b/interfaces/inner_api/security_component/include/sec_comp_base.h @@ -66,6 +66,12 @@ public: static const std::string JSON_BORDER_WIDTH_TAG; static const std::string JSON_PARENT_TAG; static const std::string JSON_PARENT_EFFECT_TAG; + static const std::string JSON_IS_CLIPPED_TAG; + static const std::string JSON_TOP_CLIP_TAG; + static const std::string JSON_BOTTOM_CLIP_TAG; + static const std::string JSON_LEFT_CLIP_TAG; + static const std::string JSON_RIGHT_CLIP_TAG; + static const std::string JSON_PARENT_TAG_TAG; static const std::string JSON_STYLE_TAG; static const std::string JSON_TEXT_TAG; @@ -108,6 +114,12 @@ public: // parent effect bool parentEffect_ = false; + bool isClipped_ = false; + DimensionT topClip_; + DimensionT bottomClip_; + DimensionT leftClip_; + DimensionT rightClip_; + std::string parentTag_; SecCompType type_ = UNKNOWN_SC_TYPE; SecCompRect rect_; @@ -127,6 +139,7 @@ private: 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); + 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 ParseColors(const nlohmann::json& json, const std::string& tag); bool ParseBorders(const nlohmann::json& json, const std::string& tag); diff --git a/interfaces/inner_api/security_component/test/unittest/src/test_common.cpp b/interfaces/inner_api/security_component/test/unittest/src/test_common.cpp index e4342c4..2c602e3 100644 --- a/interfaces/inner_api/security_component/test/unittest/src/test_common.cpp +++ b/interfaces/inner_api/security_component/test/unittest/src/test_common.cpp @@ -58,6 +58,12 @@ void TestCommon::BuildLocationComponentInfo(nlohmann::json& jsonComponent) }; jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false }, + { JsonTagConstants::JSON_IS_CLIPPED_TAG, false }, + { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_PARENT_TAG_TAG, "" }, }; jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, @@ -108,6 +114,12 @@ void TestCommon::BuildSaveComponentInfo(nlohmann::json& jsonComponent) }; jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false }, + { JsonTagConstants::JSON_IS_CLIPPED_TAG, false }, + { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_PARENT_TAG_TAG, "" }, }; jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { { JsonTagConstants::JSON_TEXT_TAG, SaveDesc::DOWNLOAD }, @@ -158,6 +170,12 @@ void TestCommon::BuildPasteComponentInfo(nlohmann::json& jsonComponent) }; jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false }, + { JsonTagConstants::JSON_IS_CLIPPED_TAG, false }, + { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_PARENT_TAG_TAG, "" }, }; jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { { JsonTagConstants::JSON_TEXT_TAG, PasteDesc::PASTE }, 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 bdd3a3b..51c7df2 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 @@ -15,9 +15,12 @@ #include "sec_comp_info_helper.h" #include "accesstoken_kit.h" +#include "bundle_mgr_client.h" #include "display.h" #include "display_info.h" #include "display_manager.h" +#include "hisysevent.h" +#include "ipc_skeleton.h" #include "location_button.h" #include "paste_button.h" #include "save_button.h" @@ -69,6 +72,17 @@ SecCompBase* SecCompInfoHelper::ParseComponent(SecCompType type, const nlohmann: return comp; } + if (comp->isClipped_) { + int32_t uid = IPCSkeleton::GetCallingUid(); + OHOS::AppExecFwk::BundleMgrClient bmsClient; + std::string bundleName = ""; + bmsClient.GetNameForUid(uid, bundleName); + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "CLIP_CHECK_FAILED", + HiviewDFX::HiSysEvent::EventType::SECURITY, + "CALLER_BUNDLE_NAME", bundleName, + "COMPONENT_INFO", jsonComponent.dump().c_str()); + } + comp->SetValid(CheckComponentValid(comp)); return comp; } 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 37aa150..0e463d0 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 @@ -235,6 +235,12 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent006, TestSize.Level1) jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { { JsonTagConstants::JSON_PARENT_EFFECT_TAG, true }, + { JsonTagConstants::JSON_IS_CLIPPED_TAG, false }, + { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_PARENT_TAG_TAG, "" }, }; comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); 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 d2358ac..d3433d1 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 @@ -58,6 +58,12 @@ void ServiceTestCommon::BuildLocationComponentJson(nlohmann::json& jsonComponent }; jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false }, + { JsonTagConstants::JSON_IS_CLIPPED_TAG, false }, + { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_PARENT_TAG_TAG, "" }, }; jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { { JsonTagConstants::JSON_TEXT_TAG, LocationDesc::SELECT_LOCATION }, @@ -108,6 +114,12 @@ void ServiceTestCommon::BuildSaveComponentJson(nlohmann::json& jsonComponent) }; jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false }, + { JsonTagConstants::JSON_IS_CLIPPED_TAG, false }, + { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_PARENT_TAG_TAG, "" }, }; jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { { JsonTagConstants::JSON_TEXT_TAG, SaveDesc::DOWNLOAD }, @@ -158,6 +170,12 @@ void ServiceTestCommon::BuildPasteComponentJson(nlohmann::json& jsonComponent) }; jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { { JsonTagConstants::JSON_PARENT_EFFECT_TAG, false }, + { JsonTagConstants::JSON_IS_CLIPPED_TAG, false }, + { JsonTagConstants::JSON_TOP_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_BOTTOM_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_LEFT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 }, + { JsonTagConstants::JSON_PARENT_TAG_TAG, "" }, }; jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { { JsonTagConstants::JSON_TEXT_TAG, PasteDesc::PASTE },