From aa1b92de935e6f2476df845a9107175e64c0c0ec Mon Sep 17 00:00:00 2001 From: sunxuhui Date: Mon, 10 Feb 2025 14:10:20 +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: sunxuhui --- .../include/i_sec_comp_service.h | 2 +- .../include/sec_comp_client.h | 2 +- .../include/sec_comp_proxy.h | 2 +- .../src/sec_comp_client.cpp | 4 +- .../security_component/src/sec_comp_kit.cpp | 4 +- .../security_component/src/sec_comp_proxy.cpp | 7 +- .../unittest/src/location_button_test.cpp | 118 ++++++++++-------- .../test/unittest/src/paste_button_test.cpp | 26 ++-- .../test/unittest/src/save_button_test.cpp | 28 +++-- .../src/location_button.cpp | 10 +- .../security_component/src/paste_button.cpp | 10 +- .../security_component/src/save_button.cpp | 12 +- .../security_component/src/sec_comp_base.cpp | 9 +- .../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 +- .../security_component/include/sec_comp_kit.h | 2 +- .../sec_comp_info_helper.h | 4 +- .../sa/sa_main/sec_comp_info_helper.cpp | 6 +- .../sa/sa_main/sec_comp_manager.cpp | 3 +- .../sa/sa_main/sec_comp_manager.h | 2 +- .../sa/sa_main/sec_comp_service.cpp | 4 +- .../sa/sa_main/sec_comp_service.h | 2 +- .../sa/sa_main/sec_comp_stub.cpp | 8 +- 25 files changed, 163 insertions(+), 114 deletions(-) diff --git a/frameworks/inner_api/security_component/include/i_sec_comp_service.h b/frameworks/inner_api/security_component/include/i_sec_comp_service.h index 2a28352..3047943 100644 --- a/frameworks/inner_api/security_component/include/i_sec_comp_service.h +++ b/frameworks/inner_api/security_component/include/i_sec_comp_service.h @@ -32,7 +32,7 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.security.ISecCompService"); virtual int32_t RegisterSecurityComponent(SecCompType type, - const std::string& componentInfo, int32_t& scId) = 0; + const std::string& componentInfo, int32_t& scId, std::string& message) = 0; virtual int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) = 0; virtual int32_t UnregisterSecurityComponent(int32_t scId) = 0; virtual int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, diff --git a/frameworks/inner_api/security_component/include/sec_comp_client.h b/frameworks/inner_api/security_component/include/sec_comp_client.h index e4c91c4..dcc6189 100644 --- a/frameworks/inner_api/security_component/include/sec_comp_client.h +++ b/frameworks/inner_api/security_component/include/sec_comp_client.h @@ -30,7 +30,7 @@ class SecCompClient final { public: static SecCompClient& GetInstance(); - int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId); + int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId, std::string& message); int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo); int32_t UnregisterSecurityComponent(int32_t scId); int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, diff --git a/frameworks/inner_api/security_component/include/sec_comp_proxy.h b/frameworks/inner_api/security_component/include/sec_comp_proxy.h index cc1b213..5444f0e 100644 --- a/frameworks/inner_api/security_component/include/sec_comp_proxy.h +++ b/frameworks/inner_api/security_component/include/sec_comp_proxy.h @@ -26,7 +26,7 @@ class SecCompProxy : public IRemoteProxy { public: explicit SecCompProxy(const sptr& impl); ~SecCompProxy() override; - int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId) override; + int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId, std::string& message) override; int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) override; int32_t UnregisterSecurityComponent(int32_t scId) override; int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, sptr callerToken, diff --git a/frameworks/inner_api/security_component/src/sec_comp_client.cpp b/frameworks/inner_api/security_component/src/sec_comp_client.cpp index b7815d6..5f07a2e 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_client.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_client.cpp @@ -56,7 +56,7 @@ SecCompClient::~SecCompClient() } int32_t SecCompClient::RegisterSecurityComponent(SecCompType type, - const std::string& componentInfo, int32_t& scId) + const std::string& componentInfo, int32_t& scId, std::string& message) { auto proxy = GetProxy(true); if (proxy == nullptr) { @@ -64,7 +64,7 @@ int32_t SecCompClient::RegisterSecurityComponent(SecCompType type, return SC_SERVICE_ERROR_VALUE_INVALID; } - return proxy->RegisterSecurityComponent(type, componentInfo, scId); + return proxy->RegisterSecurityComponent(type, componentInfo, scId, message); } int32_t SecCompClient::UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) diff --git a/frameworks/inner_api/security_component/src/sec_comp_kit.cpp b/frameworks/inner_api/security_component/src/sec_comp_kit.cpp index 4bc6662..6c17364 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_kit.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_kit.cpp @@ -31,7 +31,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ } // namespace int32_t SecCompKit::RegisterSecurityComponent(SecCompType type, - std::string& componentInfo, int32_t& scId) + std::string& componentInfo, int32_t& scId, std::string& message) { if (!SecCompCallerAuthorization::GetInstance().IsKitCaller( reinterpret_cast(__builtin_return_address(0)))) { @@ -51,7 +51,7 @@ int32_t SecCompKit::RegisterSecurityComponent(SecCompType type, return SC_ENHANCE_ERROR_VALUE_INVALID; } - int32_t res = SecCompClient::GetInstance().RegisterSecurityComponent(type, componentInfo, scId); + int32_t res = SecCompClient::GetInstance().RegisterSecurityComponent(type, componentInfo, scId, message); if (res != SC_OK) { SC_LOG_ERROR(LABEL, "register security component fail, error: %{public}d", res); return res; diff --git a/frameworks/inner_api/security_component/src/sec_comp_proxy.cpp b/frameworks/inner_api/security_component/src/sec_comp_proxy.cpp index 7cd7798..f2bb1b8 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_proxy.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_proxy.cpp @@ -34,7 +34,7 @@ SecCompProxy::~SecCompProxy() {} int32_t SecCompProxy::RegisterSecurityComponent(SecCompType type, - const std::string& componentInfo, int32_t& scId) + const std::string& componentInfo, int32_t& scId, std::string& message) { std::lock_guard lock(useIPCMutex_); MessageParcel rawData; @@ -91,6 +91,11 @@ int32_t SecCompProxy::RegisterSecurityComponent(SecCompType type, SC_LOG_ERROR(LABEL, "Register read scId failed."); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } + + if (!deserializedReply.ReadString(message)) { + SC_LOG_ERROR(LABEL, "Register read error message failed."); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } return res; } 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..ceede45 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,9 @@ HWTEST_F(LocationButtonTest, FromJson001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton comp; - - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); } /** @@ -68,7 +69,8 @@ HWTEST_F(LocationButtonTest, FromJson002, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); } /** @@ -82,13 +84,14 @@ HWTEST_F(LocationButtonTest, FromJson003, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton comp; - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); jsonComponent[JsonTagConstants::JSON_SC_TYPE] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); jsonComponent[JsonTagConstants::JSON_SC_TYPE] = 0; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); } /** @@ -104,26 +107,27 @@ HWTEST_F(LocationButtonTest, FromJson004, TestSize.Level1) 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)); + std::string message; + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); auto& rectJson = jsonComponent[JsonTagConstants::JSON_RECT]; rectJson[JsonTagConstants::JSON_RECT_X] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); 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)); 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)); 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)); } /** @@ -139,26 +143,27 @@ HWTEST_F(LocationButtonTest, FromJson005, TestSize.Level1) 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)); + std::string message; + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); 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)); 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)); 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)); 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)); } /** @@ -172,19 +177,20 @@ HWTEST_F(LocationButtonTest, FromJson006, TestSize.Level1) nlohmann::json jsonComponent; LocationButton comp; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); 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)); 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)); 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)); } /** @@ -198,16 +204,17 @@ HWTEST_F(LocationButtonTest, FromJson007, TestSize.Level1) nlohmann::json jsonComponent; LocationButton comp; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); 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)); 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)); } /** @@ -221,16 +228,17 @@ HWTEST_F(LocationButtonTest, FromJson008, TestSize.Level1) nlohmann::json jsonComponent; LocationButton comp; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); 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)); 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)); } /** @@ -244,18 +252,19 @@ HWTEST_F(LocationButtonTest, FromJson009, TestSize.Level1) nlohmann::json jsonComponent; LocationButton comp; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); 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)); 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)); } /** @@ -269,19 +278,20 @@ HWTEST_F(LocationButtonTest, FromJson010, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; - ASSERT_TRUE(button.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(button.FromJson(jsonComponent, message)); 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)); 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)); 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)); } /** @@ -295,19 +305,20 @@ HWTEST_F(LocationButtonTest, FromJson011, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; - ASSERT_TRUE(button.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(button.FromJson(jsonComponent, message)); 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)); 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)); 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)); } /** @@ -321,32 +332,33 @@ HWTEST_F(LocationButtonTest, FromJson012, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; + std::string message; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message)); 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)); 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)); 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)); 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)); 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)); 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)); } /** @@ -360,8 +372,9 @@ HWTEST_F(LocationButtonTest, ToJsonStr001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; + std::string message; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message)); ASSERT_EQ(jsonComponent.dump(), button.ToJsonStr()); } @@ -393,9 +406,10 @@ HWTEST_F(LocationButtonTest, CompareLocationButton001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -424,7 +438,8 @@ HWTEST_F(LocationButtonTest, CompareLocationButton002, TestSize.Level1) nlohmann::json jsonComponent; LocationButton comp1; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp1.FromJson(jsonComponent, message)); LocationButton comp2 = comp1; comp1.type_ = SAVE_COMPONENT; @@ -490,7 +505,8 @@ HWTEST_F(LocationButtonTest, CompareLocationButton003, TestSize.Level1) SaveButton button2; nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); 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..1d1f194 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,33 @@ HWTEST_F(PasteButtonTest, IsParamValid001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildPasteComponentInfo(jsonComponent); PasteButton button; + std::string message; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message)); 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)); 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)); 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)); 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)); 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)); 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)); } /** @@ -94,9 +95,10 @@ HWTEST_F(PasteButtonTest, ComparePasteButton001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildPasteComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -125,7 +127,8 @@ HWTEST_F(PasteButtonTest, ComparePasteButton002, TestSize.Level1) nlohmann::json jsonComponent; PasteButton comp1; TestCommon::BuildPasteComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp1.FromJson(jsonComponent, message)); PasteButton comp2 = comp1; comp1.type_ = SAVE_COMPONENT; @@ -159,7 +162,8 @@ HWTEST_F(PasteButtonTest, ComparePasteButton003, TestSize.Level1) SaveButton button2; nlohmann::json jsonComponent; TestCommon::BuildPasteComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); 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..0afb25d 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,37 @@ HWTEST_F(SaveButtonTest, IsParamValid001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildSaveComponentInfo(jsonComponent); SaveButton button; + std::string message; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message)); 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)); 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)); 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)); 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)); 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)); 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)); 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)); } /** @@ -98,9 +99,10 @@ HWTEST_F(SaveButtonTest, CompareSaveButton001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildSaveComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -129,7 +131,8 @@ HWTEST_F(SaveButtonTest, CompareSaveButton002, TestSize.Level1) nlohmann::json jsonComponent; SaveButton comp1; TestCommon::BuildSaveComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp1.FromJson(jsonComponent, message)); SaveButton comp2 = comp1; comp1.type_ = PASTE_COMPONENT; @@ -163,7 +166,8 @@ HWTEST_F(SaveButtonTest, CompareSaveButton003, TestSize.Level1) PasteButton button2; nlohmann::json jsonComponent; TestCommon::BuildSaveComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); 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..a2ae918 100644 --- a/frameworks/security_component/src/location_button.cpp +++ b/frameworks/security_component/src/location_button.cpp @@ -24,10 +24,14 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "LocationButton"}; } -bool LocationButton::IsTextIconTypeValid() +bool LocationButton::IsTextIconTypeValid(std::string &message) { - if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= LocationDesc::MAX_LABEL_TYPE) || - (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= LocationIcon::MAX_ICON_TYPE)) { + if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= LocationDesc::MAX_LABEL_TYPE)) { + message = ", security component text is invalid."; + return false; + } + if ((icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= LocationIcon::MAX_ICON_TYPE)) { + message = ", security component icon is invalid."; return false; } return true; diff --git a/frameworks/security_component/src/paste_button.cpp b/frameworks/security_component/src/paste_button.cpp index 23d353b..4b38741 100644 --- a/frameworks/security_component/src/paste_button.cpp +++ b/frameworks/security_component/src/paste_button.cpp @@ -24,10 +24,14 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "PasteButton"}; } -bool PasteButton::IsTextIconTypeValid() +bool PasteButton::IsTextIconTypeValid(std::string& message) { - if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= PasteDesc::MAX_LABEL_TYPE) || - (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= PasteIcon::MAX_ICON_TYPE)) { + if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= PasteDesc::MAX_LABEL_TYPE)) { + message = ", security component text is invalid."; + return false; + } + if ((icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= PasteIcon::MAX_ICON_TYPE)) { + message = ", security component icon is invalid."; return false; } diff --git a/frameworks/security_component/src/save_button.cpp b/frameworks/security_component/src/save_button.cpp index 73a5a9d..c07508d 100644 --- a/frameworks/security_component/src/save_button.cpp +++ b/frameworks/security_component/src/save_button.cpp @@ -26,15 +26,21 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SaveButton"}; } -bool SaveButton::IsTextIconTypeValid() +bool SaveButton::IsTextIconTypeValid(std::string &message) { - if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= SaveDesc::MAX_LABEL_TYPE) || - (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= SaveIcon::MAX_ICON_TYPE)) { + if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= SaveDesc::MAX_LABEL_TYPE)) { + message = ", security component text is invalid."; + return false; + } + + if ((icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= SaveIcon::MAX_ICON_TYPE)) { + message = ", security component icon is invalid."; return false; } if ((static_cast(icon_) == SaveIcon::PICTURE_ICON) && !IsSystemAppCalling()) { SC_LOG_ERROR(LABEL, "Picture icon only for system application."); + message = ", 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 323d9e3..cff7225 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) { 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)) { 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) { 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)) { SC_LOG_ERROR(LABEL, "text or icon is invalid."); return false; } @@ -469,6 +469,7 @@ bool SecCompBase::ParseStyle(const nlohmann::json& json, const std::string& tag) (bg_ != SecCompBackground::CIRCLE) && (bg_ != SecCompBackground::NORMAL) && (bg_ != SecCompBackground::ROUNDED_RECTANGLE)) { SC_LOG_ERROR(LABEL, "bg is invalid."); + message = ", security component background is invalid."; return false; } return true; diff --git a/interfaces/inner_api/security_component/include/location_button.h b/interfaces/inner_api/security_component/include/location_button.h index 9788b0c..a482160 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) 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..1148ae4 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) 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..2e8e033 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) 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..f2c7204 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); 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) = 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 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/include/sec_comp_kit.h b/interfaces/inner_api/security_component/include/sec_comp_kit.h index bfa8d08..bab659f 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_kit.h +++ b/interfaces/inner_api/security_component/include/sec_comp_kit.h @@ -26,7 +26,7 @@ namespace Security { namespace SecurityComponent { class __attribute__((visibility("default"))) SecCompKit { public: - static int32_t RegisterSecurityComponent(SecCompType type, std::string& componentInfo, int32_t& scId); + static int32_t RegisterSecurityComponent(SecCompType type, std::string& componentInfo, int32_t& scId, std::string& message); static int32_t UpdateSecurityComponent(int32_t scId, std::string& componentInfo); static int32_t UnregisterSecurityComponent(int32_t scId); static int32_t ReportSecurityComponentClickEvent(SecCompInfo& SecCompInfo, sptr callerToken, 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..380255a 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) { T *componentPtr = new (std::nothrow)T(); - if ((componentPtr != nullptr) && !componentPtr->FromJson(jsonComponent)) { + if ((componentPtr != nullptr) && !componentPtr->FromJson(jsonComponent, message)) { delete componentPtr; return nullptr; } 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 6c2a3c9..025ee55 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 @@ -61,13 +61,13 @@ SecCompBase* SecCompInfoHelper::ParseComponent(SecCompType type, const nlohmann: SecCompBase* comp = nullptr; switch (type) { case LOCATION_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message); break; case PASTE_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message); break; case SAVE_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message); 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 98e41de..7de4a06 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 @@ -350,7 +350,7 @@ int32_t SecCompManager::AddSecurityComponentProcess(const SecCompCallerInfo& cal } int32_t SecCompManager::RegisterSecurityComponent(SecCompType type, - const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller, int32_t& scId) + const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller, int32_t& scId, std::string& message) { SC_LOG_DEBUG(LABEL, "PID: %{public}d, register security component", caller.pid); if (malicious_.IsInMaliciousAppList(caller.pid, caller.uid)) { @@ -358,7 +358,6 @@ int32_t SecCompManager::RegisterSecurityComponent(SecCompType type, return SC_ENHANCE_ERROR_IN_MALICIOUS_LIST; } - std::string message; SecCompBase* componentPtr = SecCompInfoHelper::ParseComponent(type, jsonComponent, message); std::shared_ptr component(componentPtr); if (component == nullptr) { diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.h b/services/security_component_service/sa/sa_main/sec_comp_manager.h index 30de2dd..316570b 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.h +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.h @@ -53,7 +53,7 @@ public: virtual ~SecCompManager() = default; int32_t RegisterSecurityComponent(SecCompType type, const nlohmann::json& jsonComponent, - const SecCompCallerInfo& caller, int32_t& scId); + const SecCompCallerInfo& caller, int32_t& scId, std::string& message); int32_t UpdateSecurityComponent(int32_t scId, const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller); int32_t UnregisterSecurityComponent(int32_t scId, const SecCompCallerInfo& caller); diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.cpp b/services/security_component_service/sa/sa_main/sec_comp_service.cpp index 35cce28..406f275 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_service.cpp @@ -185,7 +185,7 @@ int32_t SecCompService::ParseParams(const std::string& componentInfo, } int32_t SecCompService::RegisterSecurityComponent(SecCompType type, - const std::string& componentInfo, int32_t& scId) + const std::string& componentInfo, int32_t& scId, std::string& message) { StartTrace(HITRACE_TAG_ACCESS_CONTROL, "SecurityComponentRegister"); SecCompCallerInfo caller; @@ -205,7 +205,7 @@ int32_t SecCompService::RegisterSecurityComponent(SecCompType type, return SC_SERVICE_ERROR_VALUE_INVALID; } - int32_t res = SecCompManager::GetInstance().RegisterSecurityComponent(type, jsonRes, caller, scId); + int32_t res = SecCompManager::GetInstance().RegisterSecurityComponent(type, jsonRes, caller, scId, message); FinishTrace(HITRACE_TAG_ACCESS_CONTROL); int32_t uid = IPCSkeleton::GetCallingUid(); diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.h b/services/security_component_service/sa/sa_main/sec_comp_service.h index 9a45410..7ec3d14 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.h +++ b/services/security_component_service/sa/sa_main/sec_comp_service.h @@ -40,7 +40,7 @@ public: void OnStart() override; void OnStop() override; - int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId) override; + int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId, std::string& message) override; int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) override; int32_t UnregisterSecurityComponent(int32_t scId) override; int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, sptr callerToken, diff --git a/services/security_component_service/sa/sa_main/sec_comp_stub.cpp b/services/security_component_service/sa/sa_main/sec_comp_stub.cpp index 198b087..2886cff 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_stub.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_stub.cpp @@ -75,7 +75,8 @@ int32_t SecCompStub::RegisterSecurityComponentInner(MessageParcel& data, Message } int32_t scId = INVALID_SC_ID; - int32_t res = this->RegisterSecurityComponent(static_cast(type), componentInfo, scId); + std::string message; + int32_t res = this->RegisterSecurityComponent(static_cast(type), componentInfo, scId, message); MessageParcel rawReply; if (!rawReply.WriteInt32(res)) { SC_LOG_ERROR(LABEL, "Register security component result failed"); @@ -87,6 +88,11 @@ int32_t SecCompStub::RegisterSecurityComponentInner(MessageParcel& data, Message return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } + if (!rawReply.WriteString(message)) { + SC_LOG_ERROR(LABEL, "Register security component result failed"); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + if (!SecCompEnhanceAdapter::EnhanceSrvSerialize(rawReply, reply)) { SC_LOG_ERROR(LABEL, "Register serialize session info failed"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; -- Gitee