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 2a28352e722ec174703a5485d027e18b1d7f150a..3047943d76590eb2cf82c9d3a79e7b3016f930c4 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 e4c91c4ac5d47255eeb8c4525a1970bbb0e88265..dcc618993438d1f572a826d05586f27138c65da5 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 cc1b213706890031cfe75383ea02173a1c00629b..5444f0e1aa5ce4094d61ad5fbd436b0a73e0ffaa 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 b7815d69d653ee05e876ad12be77e61be8e4f140..5f07a2e9c5b8742fe54027556fcf3ffbe9138a7a 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 4bc666292e2d6737f97c7086786d3f83c52206e2..6c1736413f14b21e0eb2d262e5a09404a095268a 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 7cd7798fd80ca77e66ee4a6d3886614d41a6e008..f2bb1b8d0cc93c48daccba71abef9af666db8dcb 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 335bb9845ef5f030b4e13cab179f744f335fe963..ceede45c74ae1c78df29844a231232e9fd05c95f 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 d79349ddb51e352852008fe32485db266f0a9f43..1d1f194167c60b7f13a8559aa4e370de8061fed9 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 ffe975ece56f5c4c3b171750a78d8a912d0eaede..0afb25d0288e247319e7aa35c87eda776ce4796a 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 b8c4c388ae6de4c1fe470683d0b184fcacd5a8da..a2ae91880917e07416e63b6460cf0e9b51b3f5bd 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 23d353b752ff7a06df2663293e9a0f801edfd8a3..4b38741d127e68206f1fa63ddac0daaa526fb373 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 73a5a9dca912c0882b003b5bb6ac94e29ddc14cd..c07508d6c4020a87427466e2b15f1604e31ccdfa 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 323d9e3ba54765130e45dfe6c76c65bfb94c826b..cff72251531e038a586fcb18f769dac2abd5b519 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 9788b0ca81b4215306ee74772c1abb2bbd5cfb52..a482160e51fca8bcd8fa55306a73742fa11b318e 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 0e43c8f8fd20dfd4f8068102be74e30a4fbcd519..1148ae43c440bd5d11f585db5cd5db0dc3c553f4 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 b547399c382008d0ae9da0909e78f25b13488abf..2e8e033437b4ac36fada0613b814fb99cf4afe24 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 02f77402da8dc9bff59b4d75b12ce79ece8328eb..f2c720442d3e0f29c93ca41479e3761e90425ad1 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 bfa8d08099235dca536dac0713436b6a8969006f..bab659f4f7de0d3ce4b9725630afe86a07a93fe1 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 42005c932bf5c3120e733d45488469c0561ab94a..380255afc7197ffba8c0696bf82f5eeb546354fd 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 6c2a3c9fee91997c350c10a8e772911072524feb..025ee554e213f3d10064e0740899a6bcbb019646 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 98e41dec86b5adeec63b65f4332e2c6de5db44fb..7de4a06b30c1b4dbb3af97ece3691cd24d44cc13 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 30de2ddecb21dcae455a860f01e3b3097d13276a..316570b04d38b76dcdb9500f9be1611e9f8f0686 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 35cce2879a982c7a6cc99518466790445c24f5ed..406f275bdfb2a4358044fecc079de51e925a78b2 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 9a4541076f6285ea4763f1d6c8faf7641f21984f..7ec3d14c7a45a51c36d78fe555629e785a8fe226 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 198b0876d395562fc118c2a9764d5f4760cef696..2886cff7275b862050cdeb1258d9cb0c31700209 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;