From 6c0d378bc733cdbd0cec75eb2162e6a176db7c0e Mon Sep 17 00:00:00 2001 From: chenliming Date: Mon, 24 Feb 2025 19:21:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=8E=A7=E4=BB=B6=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E8=AE=BE=E7=BD=AE=E9=94=99=E8=AF=AF=E5=BC=95=E8=B5=B7?= =?UTF-8?q?=E7=9A=84=E5=8F=82=E6=95=B0=E8=A7=A3=E6=9E=90=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0message=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenliming --- .../unittest/src/location_button_test.cpp | 134 +++++++++++------- .../test/unittest/src/paste_button_test.cpp | 30 ++-- .../test/unittest/src/save_button_test.cpp | 32 +++-- .../src/location_button.cpp | 2 +- .../security_component/src/paste_button.cpp | 2 +- .../security_component/src/save_button.cpp | 6 +- .../security_component/src/sec_comp_base.cpp | 8 +- .../include/location_button.h | 2 +- .../security_component/include/paste_button.h | 2 +- .../security_component/include/save_button.h | 2 +- .../include/sec_comp_base.h | 6 +- .../sec_comp_info_helper.h | 7 +- .../sa/sa_main/sec_comp_info_helper.cpp | 8 +- .../sa/sa_main/sec_comp_manager.cpp | 5 +- 14 files changed, 148 insertions(+), 98 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 335bb98..5022339 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 @@ -54,8 +54,10 @@ HWTEST_F(LocationButtonTest, FromJson001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton comp; - - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -68,7 +70,9 @@ HWTEST_F(LocationButtonTest, FromJson002, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -82,13 +86,15 @@ HWTEST_F(LocationButtonTest, FromJson003, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton comp; - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); jsonComponent[JsonTagConstants::JSON_SC_TYPE] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); jsonComponent[JsonTagConstants::JSON_SC_TYPE] = 0; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -101,29 +107,31 @@ HWTEST_F(LocationButtonTest, FromJson004, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; nlohmann::json wrongJson = nlohmann::json::parse("{", nullptr, false); jsonComponent[JsonTagConstants::JSON_RECT] = wrongJson; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& rectJson = jsonComponent[JsonTagConstants::JSON_RECT]; rectJson[JsonTagConstants::JSON_RECT_X] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_X] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_Y] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_Y] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_WIDTH] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_WIDTH] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_HEIGHT] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -136,29 +144,31 @@ HWTEST_F(LocationButtonTest, FromJson005, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; nlohmann::json wrongJson = nlohmann::json::parse("{", nullptr, false); jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = wrongJson; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& rectJson = jsonComponent[JsonTagConstants::JSON_WINDOW_RECT]; rectJson[JsonTagConstants::JSON_RECT_X] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_X] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_Y] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_Y] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_WIDTH] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); rectJson[JsonTagConstants::JSON_RECT_WIDTH] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_HEIGHT] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -171,20 +181,22 @@ HWTEST_F(LocationButtonTest, FromJson006, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = TestCommon::TEST_SIZE; sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = TestCommon::TEST_SIZE; sizeJson[JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -197,17 +209,19 @@ HWTEST_F(LocationButtonTest, FromJson007, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = TestCommon::TEST_DIMENSION; paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -220,17 +234,19 @@ HWTEST_F(LocationButtonTest, FromJson008, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = TestCommon::TEST_DIMENSION; paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -243,19 +259,21 @@ HWTEST_F(LocationButtonTest, FromJson009, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message, isClicked)); jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json { { JsonTagConstants::JSON_BORDER_WIDTH_TAG, WRONG_TYPE }, }; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); TestCommon::BuildLocationComponentInfo(jsonComponent); jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { { JsonTagConstants::JSON_PARENT_EFFECT_TAG, WRONG_TYPE }, }; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message, isClicked)); } /** @@ -269,19 +287,21 @@ HWTEST_F(LocationButtonTest, FromJson010, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; - ASSERT_TRUE(button.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; styleJson[JsonTagConstants::JSON_TEXT_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; styleJson[JsonTagConstants::JSON_ICON_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); } /** @@ -295,19 +315,21 @@ HWTEST_F(LocationButtonTest, FromJson011, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; - ASSERT_TRUE(button.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); auto& colorJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG]; colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = TestCommon::TEST_COLOR_RED; colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = TestCommon::TEST_COLOR_BLUE; colorJson[JsonTagConstants::JSON_BG_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); } /** @@ -321,32 +343,34 @@ HWTEST_F(LocationButtonTest, FromJson012, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; + std::string message; + bool isClicked = true; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; styleJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; styleJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::MAX_LABEL_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::MAX_ICON_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); } /** @@ -360,8 +384,10 @@ HWTEST_F(LocationButtonTest, ToJsonStr001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; + std::string message; + bool isClicked = true; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); ASSERT_EQ(jsonComponent.dump(), button.ToJsonStr()); } @@ -392,10 +418,12 @@ HWTEST_F(LocationButtonTest, CompareLocationButton001, TestSize.Level1) LocationButton button2; nlohmann::json jsonComponent; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message, isClicked)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -423,8 +451,10 @@ HWTEST_F(LocationButtonTest, CompareLocationButton002, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp1; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + ASSERT_TRUE(comp1.FromJson(jsonComponent, message, isClicked)); LocationButton comp2 = comp1; comp1.type_ = SAVE_COMPONENT; @@ -489,8 +519,10 @@ HWTEST_F(LocationButtonTest, CompareLocationButton003, TestSize.Level1) LocationButton button1; SaveButton button2; nlohmann::json jsonComponent; + std::string message; + bool isClicked = true; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, false)); } diff --git a/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp index d79349d..e369012 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp @@ -53,32 +53,34 @@ HWTEST_F(PasteButtonTest, IsParamValid001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildPasteComponentInfo(jsonComponent); PasteButton button; + std::string message; + bool isClicked = true; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; styleJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::PASTE; styleJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::MAX_LABEL_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::PASTE; styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::MAX_ICON_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); } /** @@ -94,9 +96,11 @@ HWTEST_F(PasteButtonTest, ComparePasteButton001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildPasteComponentInfo(jsonComponent); + std::string message; + bool isClicked = true; - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message, isClicked)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -124,8 +128,10 @@ HWTEST_F(PasteButtonTest, ComparePasteButton002, TestSize.Level1) { nlohmann::json jsonComponent; PasteButton comp1; + std::string message; + bool isClicked = true; TestCommon::BuildPasteComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + ASSERT_TRUE(comp1.FromJson(jsonComponent, message, isClicked)); PasteButton comp2 = comp1; comp1.type_ = SAVE_COMPONENT; @@ -158,8 +164,10 @@ HWTEST_F(PasteButtonTest, ComparePasteButton003, TestSize.Level1) PasteButton button1; SaveButton button2; nlohmann::json jsonComponent; + std::string message; + bool isClicked = true; TestCommon::BuildPasteComponentInfo(jsonComponent); - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true)); } diff --git a/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp index ffe975e..6133497 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp @@ -53,36 +53,38 @@ HWTEST_F(SaveButtonTest, IsParamValid001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildSaveComponentInfo(jsonComponent); SaveButton button; + std::string message; + bool isClicked = true; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message, isClicked)); auto& stylesJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; stylesJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::DOWNLOAD; stylesJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::LINE_ICON; stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::MAX_LABEL_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::DOWNLOAD; stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::MAX_ICON_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::LINE_ICON; stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::PICTURE_ICON; stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message, isClicked)); } /** @@ -97,10 +99,12 @@ HWTEST_F(SaveButtonTest, CompareSaveButton001, TestSize.Level1) SaveButton button2; nlohmann::json jsonComponent; + std::string message; + bool isClicked = true; TestCommon::BuildSaveComponentInfo(jsonComponent); - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message, isClicked)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -129,7 +133,9 @@ HWTEST_F(SaveButtonTest, CompareSaveButton002, TestSize.Level1) nlohmann::json jsonComponent; SaveButton comp1; TestCommon::BuildSaveComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + std::string message; + bool isClicked = true; + ASSERT_TRUE(comp1.FromJson(jsonComponent, message, isClicked)); SaveButton comp2 = comp1; comp1.type_ = PASTE_COMPONENT; @@ -162,8 +168,10 @@ HWTEST_F(SaveButtonTest, CompareSaveButton003, TestSize.Level1) SaveButton button1; PasteButton button2; nlohmann::json jsonComponent; + std::string message; + bool isClicked = true; TestCommon::BuildSaveComponentInfo(jsonComponent); - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message, isClicked)); ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true)); } diff --git a/frameworks/security_component/src/location_button.cpp b/frameworks/security_component/src/location_button.cpp index b8c4c38..d1ca914 100644 --- a/frameworks/security_component/src/location_button.cpp +++ b/frameworks/security_component/src/location_button.cpp @@ -24,7 +24,7 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "LocationButton"}; } -bool LocationButton::IsTextIconTypeValid() +bool LocationButton::IsTextIconTypeValid(std::string &message, bool isClicked) { if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= LocationDesc::MAX_LABEL_TYPE) || (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= LocationIcon::MAX_ICON_TYPE)) { diff --git a/frameworks/security_component/src/paste_button.cpp b/frameworks/security_component/src/paste_button.cpp index 23d353b..ce0c7dd 100644 --- a/frameworks/security_component/src/paste_button.cpp +++ b/frameworks/security_component/src/paste_button.cpp @@ -24,7 +24,7 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "PasteButton"}; } -bool PasteButton::IsTextIconTypeValid() +bool PasteButton::IsTextIconTypeValid(std::string& message, bool isClicked) { if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= PasteDesc::MAX_LABEL_TYPE) || (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= PasteIcon::MAX_ICON_TYPE)) { diff --git a/frameworks/security_component/src/save_button.cpp b/frameworks/security_component/src/save_button.cpp index 73a5a9d..7407336 100644 --- a/frameworks/security_component/src/save_button.cpp +++ b/frameworks/security_component/src/save_button.cpp @@ -26,15 +26,17 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SaveButton"}; } -bool SaveButton::IsTextIconTypeValid() +bool SaveButton::IsTextIconTypeValid(std::string &message, bool isClicked) { if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= SaveDesc::MAX_LABEL_TYPE) || (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= SaveIcon::MAX_ICON_TYPE)) { return false; } - if ((static_cast(icon_) == SaveIcon::PICTURE_ICON) && !IsSystemAppCalling()) { + if (isClicked && (static_cast(icon_) == SaveIcon::PICTURE_ICON) && !IsSystemAppCalling()) { SC_LOG_ERROR(LABEL, "Picture icon only for system application."); + message = ", security component icon type = " + std::to_string(icon_) + + ", picture icon only for system application."; return false; } diff --git a/frameworks/security_component/src/sec_comp_base.cpp b/frameworks/security_component/src/sec_comp_base.cpp index 6d00cd2..6cf600b 100644 --- a/frameworks/security_component/src/sec_comp_base.cpp +++ b/frameworks/security_component/src/sec_comp_base.cpp @@ -302,7 +302,7 @@ bool SecCompBase::ParseCrossAxisState(const nlohmann::json& json, const std::str return true; } -bool SecCompBase::FromJson(const nlohmann::json& jsonSrc) +bool SecCompBase::FromJson(const nlohmann::json& jsonSrc, std::string& message, bool isClicked) { SC_LOG_DEBUG(LABEL, "Button info %{public}s.", jsonSrc.dump().c_str()); if (!ParseType(jsonSrc, JsonTagConstants::JSON_SC_TYPE)) { @@ -329,7 +329,7 @@ bool SecCompBase::FromJson(const nlohmann::json& jsonSrc) if (!ParseParent(jsonSrc, JsonTagConstants::JSON_PARENT_TAG)) { return false; } - if (!ParseStyle(jsonSrc, JsonTagConstants::JSON_STYLE_TAG)) { + if (!ParseStyle(jsonSrc, JsonTagConstants::JSON_STYLE_TAG, message, isClicked)) { return false; } if (!ParseValue(jsonSrc, JsonTagConstants::JSON_WINDOW_ID, windowId_)) { @@ -436,7 +436,7 @@ bool SecCompBase::CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck return (leftValue == rightValue); } -bool SecCompBase::ParseStyle(const nlohmann::json& json, const std::string& tag) +bool SecCompBase::ParseStyle(const nlohmann::json& json, const std::string& tag, std::string& message, bool isClicked) { if ((json.find(tag) == json.end()) || !json.at(tag).is_object()) { SC_LOG_ERROR(LABEL, "json: %{public}s tag invalid.", tag.c_str()); @@ -460,7 +460,7 @@ bool SecCompBase::ParseStyle(const nlohmann::json& json, const std::string& tag) } text_ = jsonStyle.at(JsonTagConstants::JSON_TEXT_TAG).get(); icon_ = jsonStyle.at(JsonTagConstants::JSON_ICON_TAG).get(); - if (!IsTextIconTypeValid()) { + if (!IsTextIconTypeValid(message, isClicked)) { SC_LOG_ERROR(LABEL, "text or icon is invalid."); return false; } diff --git a/interfaces/inner_api/security_component/include/location_button.h b/interfaces/inner_api/security_component/include/location_button.h index 9788b0c..a6b700e 100644 --- a/interfaces/inner_api/security_component/include/location_button.h +++ b/interfaces/inner_api/security_component/include/location_button.h @@ -46,7 +46,7 @@ enum class LocationIcon : int32_t { class __attribute__((visibility("default"))) LocationButton : public SecCompBase { public: - virtual bool IsTextIconTypeValid() override; + virtual bool IsTextIconTypeValid(std::string& message, bool isClicked) override; virtual bool IsCorrespondenceType() override; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const override; private: diff --git a/interfaces/inner_api/security_component/include/paste_button.h b/interfaces/inner_api/security_component/include/paste_button.h index 0e43c8f..cc3f4ef 100644 --- a/interfaces/inner_api/security_component/include/paste_button.h +++ b/interfaces/inner_api/security_component/include/paste_button.h @@ -35,7 +35,7 @@ enum class PasteIcon : int32_t { class __attribute__((visibility("default"))) PasteButton : public SecCompBase { public: - virtual bool IsTextIconTypeValid() override; + virtual bool IsTextIconTypeValid(std::string& message, bool isClicked) override; virtual bool IsCorrespondenceType() override; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const override; diff --git a/interfaces/inner_api/security_component/include/save_button.h b/interfaces/inner_api/security_component/include/save_button.h index b547399..ef9d039 100644 --- a/interfaces/inner_api/security_component/include/save_button.h +++ b/interfaces/inner_api/security_component/include/save_button.h @@ -49,7 +49,7 @@ enum class SaveIcon : int32_t { class __attribute__((visibility("default"))) SaveButton : public SecCompBase { public: - virtual bool IsTextIconTypeValid() override; + virtual bool IsTextIconTypeValid(std::string& message, bool isClicked) override; virtual bool IsCorrespondenceType() override; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const override; private: 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 02f7740..a22fd70 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_base.h +++ b/interfaces/inner_api/security_component/include/sec_comp_base.h @@ -87,7 +87,7 @@ class __attribute__((visibility("default"))) SecCompBase { public: SecCompBase() = default; virtual ~SecCompBase() = default; - bool FromJson(const nlohmann::json& jsonSrc); + bool FromJson(const nlohmann::json& jsonSrc, std::string& message, bool isClicked); void ToJson(nlohmann::json& jsonRes) const; std::string ToJsonStr(void) const; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const; @@ -138,7 +138,7 @@ public: int32_t nodeId_ = 0; CrossAxisState crossAxisState_ = CrossAxisState::STATE_INVALID; protected: - virtual bool IsTextIconTypeValid() = 0; + virtual bool IsTextIconTypeValid(std::string& message, bool isClicked) = 0; virtual bool IsCorrespondenceType() = 0; private: bool ParseDimension(const nlohmann::json& json, const std::string& tag, DimensionT& res); @@ -151,7 +151,7 @@ private: bool ParseSize(const nlohmann::json& json, const std::string& tag); bool ParseParent(const nlohmann::json& json, const std::string& tag); bool ParseRect(const nlohmann::json& json, const std::string& tag, SecCompRect& rect); - bool ParseStyle(const nlohmann::json& json, const std::string& tag); + bool ParseStyle(const nlohmann::json& json, const std::string& tag, std::string& message, bool isClicked); bool ParseType(const nlohmann::json& json, const std::string& tag); bool ParseValue(const nlohmann::json& json, const std::string& tag, int32_t& value); bool ParseDisplayId(const nlohmann::json& json, const std::string& tag); 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 42005c9..8361389 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 @@ -24,10 +24,10 @@ namespace OHOS { namespace Security { namespace SecurityComponent { template -T* ConstructComponent(const nlohmann::json& jsonComponent) +T* ConstructComponent(const nlohmann::json& jsonComponent, std::string& message, bool isClicked) { T *componentPtr = new (std::nothrow)T(); - if ((componentPtr != nullptr) && !componentPtr->FromJson(jsonComponent)) { + if ((componentPtr != nullptr) && !componentPtr->FromJson(jsonComponent, message, isClicked)) { delete componentPtr; return nullptr; } @@ -36,7 +36,8 @@ T* ConstructComponent(const nlohmann::json& jsonComponent) class __attribute__((visibility("default"))) SecCompInfoHelper { public: - static SecCompBase* ParseComponent(SecCompType type, const nlohmann::json& jsonComponent, std::string& message); + 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); 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 3f7e0c9..5f369c4 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 @@ -59,18 +59,18 @@ void SecCompInfoHelper::AdjustSecCompRect(SecCompBase* comp, float scale) } SecCompBase* SecCompInfoHelper::ParseComponent(SecCompType type, const nlohmann::json& jsonComponent, - std::string& message) + std::string& message, bool isClicked) { SecCompBase* comp = nullptr; switch (type) { case LOCATION_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message, isClicked); break; case PASTE_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message, isClicked); break; case SAVE_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message, isClicked); break; default: SC_LOG_ERROR(LABEL, "Parse component type unknown"); 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 c1fd80e..7ec4a4e 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 @@ -454,7 +454,7 @@ int32_t SecCompManager::CheckClickSecurityComponentInfo(std::shared_ptrGetType(), jsonComponent, message); + SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), jsonComponent, message, true); std::shared_ptr reportComponentInfo(report); int32_t uid = IPCSkeleton::GetCallingUid(); OHOS::AppExecFwk::BundleMgrClient bmsClient; @@ -549,12 +549,11 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(SecCompInfo& info, con SC_LOG_ERROR(LABEL, "Can not find target component"); return SC_SERVICE_ERROR_COMPONENT_NOT_EXIST; } - int32_t res = CheckClickSecurityComponentInfo(sc, info.scId, compJson, caller, message); if (res != SC_OK) { return res; } - SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), compJson, message); + SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), compJson, message, true); if (report == nullptr) { return SC_SERVICE_ERROR_COMPONENT_INFO_INVALID; } -- Gitee