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 155604b89e73a414bdc75cc2909a4f293213078b..2a28352e722ec174703a5485d027e18b1d7f150a 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 @@ -16,6 +16,7 @@ #define I_SECURITY_COMPONENT_SERVICE_H #include + #include "access_token.h" #include "iremote_broker.h" #include "sec_comp_info.h" @@ -34,8 +35,8 @@ public: const std::string& componentInfo, int32_t& scId) = 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(int32_t scId, const std::string& componentInfo, - const SecCompClickEvent& clickInfo, sptr callerToken, sptr dialogCallback) = 0; + virtual int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, + sptr callerToken, sptr dialogCallback, std::string& message) = 0; virtual bool VerifySavePermission(AccessToken::AccessTokenID tokenId) = 0; virtual sptr GetEnhanceRemoteObject() = 0; virtual int32_t PreRegisterSecCompProcess() = 0; 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 563376e6675426c3cf38fac8c72f1686d5846d76..e4c91c4ac5d47255eeb8c4525a1970bbb0e88265 100644 --- a/frameworks/inner_api/security_component/include/sec_comp_client.h +++ b/frameworks/inner_api/security_component/include/sec_comp_client.h @@ -33,9 +33,8 @@ public: int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId); int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo); int32_t UnregisterSecurityComponent(int32_t scId); - int32_t ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, sptr dialogCallback); + int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, + sptr callerToken, sptr dialogCallback, std::string& message); bool VerifySavePermission(AccessToken::AccessTokenID tokenId); sptr GetEnhanceRemoteObject(bool doLoadSa); int32_t PreRegisterSecCompProcess(); 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 bb637ea3f660def6257ca48b1892a4aec9df9902..cc1b213706890031cfe75383ea02173a1c00629b 100644 --- a/frameworks/inner_api/security_component/include/sec_comp_proxy.h +++ b/frameworks/inner_api/security_component/include/sec_comp_proxy.h @@ -29,15 +29,14 @@ public: int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId) override; int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) override; int32_t UnregisterSecurityComponent(int32_t scId) override; - int32_t ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, sptr dialogCallback) override; + int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, sptr callerToken, + sptr dialogCallback, std::string& message) override; bool VerifySavePermission(AccessToken::AccessTokenID tokenId) override; sptr GetEnhanceRemoteObject() override; int32_t PreRegisterSecCompProcess() override; private: - int32_t SendReportClickEventRequest(MessageParcel& data); + int32_t SendReportClickEventRequest(MessageParcel& data, std::string& message); static inline BrokerDelegator delegator_; std::mutex useIPCMutex_; }; 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 26836a701ec0acdff079ea5283bbdd9d495d2218..b7815d69d653ee05e876ad12be77e61be8e4f140 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_client.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_client.cpp @@ -89,9 +89,8 @@ int32_t SecCompClient::UnregisterSecurityComponent(int32_t scId) return proxy->UnregisterSecurityComponent(scId); } -int32_t SecCompClient::ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, sptr dialogCallback) +int32_t SecCompClient::ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, + sptr callerToken, sptr dialogCallback, std::string& message) { auto proxy = GetProxy(true); if (proxy == nullptr) { @@ -99,7 +98,7 @@ int32_t SecCompClient::ReportSecurityComponentClickEvent(int32_t scId, return SC_SERVICE_ERROR_VALUE_INVALID; } - return proxy->ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, callerToken, dialogCallback); + return proxy->ReportSecurityComponentClickEvent(secCompInfo, callerToken, dialogCallback, message); } bool SecCompClient::VerifySavePermission(AccessToken::AccessTokenID tokenId) 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 6df28a158b61794794c47b5f8feb5698d3e67825..4bc666292e2d6737f97c7086786d3f83c52206e2 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_kit.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_kit.cpp @@ -101,9 +101,8 @@ int32_t SecCompKit::UnregisterSecurityComponent(int32_t scId) return res; } -int32_t SecCompKit::ReportSecurityComponentClickEvent(int32_t scId, - std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, OnFirstUseDialogCloseFunc&& callback) +int32_t SecCompKit::ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, + sptr callerToken, OnFirstUseDialogCloseFunc&& callback, std::string& message) { if (!SecCompCallerAuthorization::GetInstance().IsKitCaller( reinterpret_cast(__builtin_return_address(0)))) { @@ -129,14 +128,13 @@ int32_t SecCompKit::ReportSecurityComponentClickEvent(int32_t scId, return SC_SERVICE_ERROR_MEMORY_OPERATE_FAIL; } - if (!SecCompEnhanceAdapter::EnhanceDataPreprocess(scId, componentInfo)) { + if (!SecCompEnhanceAdapter::EnhanceDataPreprocess(secCompInfo.scId, secCompInfo.componentInfo)) { SC_LOG_ERROR(LABEL, "Preprocess security component fail"); return SC_ENHANCE_ERROR_VALUE_INVALID; } - int32_t res = - SecCompClient::GetInstance().ReportSecurityComponentClickEvent(scId, componentInfo, - clickInfo, callerToken, callbackRemote); + int32_t res = SecCompClient::GetInstance().ReportSecurityComponentClickEvent(secCompInfo, + callerToken, callbackRemote, message); if (res != SC_OK) { SC_LOG_ERROR(LABEL, "report click event fail, error: %{public}d", 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 f8eb8029cdb4b74d222bb51bbcf1229b30b7c98f..7cd7798fd80ca77e66ee4a6d3886614d41a6e008 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_proxy.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_proxy.cpp @@ -197,7 +197,7 @@ int32_t SecCompProxy::UnregisterSecurityComponent(int32_t scId) return res; } -int32_t SecCompProxy::SendReportClickEventRequest(MessageParcel& data) +int32_t SecCompProxy::SendReportClickEventRequest(MessageParcel& data, std::string& message) { MessageParcel reply; MessageParcel deserializedReply; @@ -226,12 +226,16 @@ int32_t SecCompProxy::SendReportClickEventRequest(MessageParcel& data) SC_LOG_ERROR(LABEL, "Report read res failed."); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } + + if (!deserializedReply.ReadString(message)) { + SC_LOG_ERROR(LABEL, "Report read error message failed."); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } return res; } -int32_t SecCompProxy::ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, sptr dialogCallback) +int32_t SecCompProxy::ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, + sptr callerToken, sptr dialogCallback, std::string& message) { std::lock_guard lock(useIPCMutex_); MessageParcel rawData; @@ -241,12 +245,12 @@ int32_t SecCompProxy::ReportSecurityComponentClickEvent(int32_t scId, return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - if (!rawData.WriteInt32(scId)) { + if (!rawData.WriteInt32(secCompInfo.scId)) { SC_LOG_ERROR(LABEL, "Report write scId failed."); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - if (!rawData.WriteString(componentInfo)) { + if (!rawData.WriteString(secCompInfo.componentInfo)) { SC_LOG_ERROR(LABEL, "Report write componentInfo failed."); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } @@ -256,7 +260,7 @@ int32_t SecCompProxy::ReportSecurityComponentClickEvent(int32_t scId, SC_LOG_ERROR(LABEL, "Report new click event parcel failed."); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - parcel->clickInfoParams_ = clickInfo; + parcel->clickInfoParams_ = secCompInfo.clickInfo; if (!rawData.WriteParcelable(parcel)) { SC_LOG_ERROR(LABEL, "Report write clickInfo failed."); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; @@ -277,7 +281,7 @@ int32_t SecCompProxy::ReportSecurityComponentClickEvent(int32_t scId, return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - return SendReportClickEventRequest(data); + return SendReportClickEventRequest(data, message); } bool SecCompProxy::VerifySavePermission(AccessToken::AccessTokenID tokenId) diff --git a/frameworks/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp index 11edd4a2abaf5550365ec2eac80d401b8513deed..85f469ebf7229d2fa7b333bae4a85e97ca8fc6c1 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp @@ -41,7 +41,9 @@ static void TestInCallerNotCheckList() int registerRes = SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, emptyStr, scId); int updateRes = SecCompKit::UpdateSecurityComponent(scId, emptyStr); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; - int reportRes = SecCompKit::ReportSecurityComponentClickEvent(scId, emptyStr, click, nullptr, std::move(func)); + SecCompInfo SecCompInfo{ scId, emptyStr, click }; + std::string message; + int reportRes = SecCompKit::ReportSecurityComponentClickEvent(SecCompInfo, nullptr, std::move(func), message); EXPECT_EQ(registerRes, SC_SERVICE_ERROR_CALLER_INVALID); EXPECT_EQ(updateRes, SC_SERVICE_ERROR_CALLER_INVALID); @@ -56,7 +58,9 @@ static void TestInCallerCheckList() int registerRes = SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, emptyStr, scId); int updateRes = SecCompKit::UpdateSecurityComponent(scId, emptyStr); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; - int reportRes = SecCompKit::ReportSecurityComponentClickEvent(scId, emptyStr, click, nullptr, std::move(func)); + SecCompInfo secCompInfo{ scId, emptyStr, click }; + std::string message; + int reportRes = SecCompKit::ReportSecurityComponentClickEvent(secCompInfo, nullptr, std::move(func), message); EXPECT_NE(registerRes, SC_SERVICE_ERROR_CALLER_INVALID); EXPECT_NE(updateRes, SC_SERVICE_ERROR_CALLER_INVALID); @@ -126,7 +130,9 @@ HWTEST_F(SecCompKitTest, ExceptCall001, TestSize.Level1) .point.timestamp = static_cast(std::chrono::high_resolution_clock::now().time_since_epoch().count()) }; OnFirstUseDialogCloseFunc func = nullptr; - EXPECT_NE(SC_OK, SecCompKit::ReportSecurityComponentClickEvent(scId, jsonStr, touch, nullptr, std::move(func))); + SecCompInfo secCompInfo{ scId, jsonStr, touch }; + std::string message; + EXPECT_NE(SC_OK, SecCompKit::ReportSecurityComponentClickEvent(secCompInfo, nullptr, std::move(func), message)); EXPECT_NE(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } diff --git a/frameworks/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp index 4d199611d9dd3f79d9406951eb29e17a0c93fe2e..6507bdc1d7f8d9e15e6eb9dec80694fe416e62c9 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp @@ -60,12 +60,12 @@ static __attribute__((noinline)) int32_t RegisterSecurityComponent( } static __attribute__((noinline)) int32_t ReportSecurityComponentClickEvent( - int32_t scId, std::string& componentInfo, - const SecCompClickEvent& clickInfo, sptr callerToken, OnFirstUseDialogCloseFunc dialogCall) + SecCompInfo& secCompInfo, sptr callerToken, OnFirstUseDialogCloseFunc dialogCall, + std::string& message) { SC_LOG_INFO(LABEL, "ReportSecurityComponentClickEvent enter"); - return SecCompKit::ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, callerToken, - std::move(dialogCall)); + return SecCompKit::ReportSecurityComponentClickEvent(secCompInfo, callerToken, + std::move(dialogCall), message); } static __attribute__((noinline)) int32_t UpdateSecurityComponent(int32_t scId, std::string& componentInfo) @@ -220,8 +220,10 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent004, TestSize.Lev ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; + std::string message; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -255,8 +257,10 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent005, TestSize.Lev ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; + std::string message; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -307,8 +311,10 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent001, Test ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; + std::string message; ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -346,8 +352,10 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent002, Test ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; + std::string message; ASSERT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); setuid(g_selfUid); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); @@ -381,12 +389,14 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent003, Test ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; + std::string message; #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); #else ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); #endif EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } @@ -419,8 +429,10 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent004, Test ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = nullptr; + SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; + std::string message; ASSERT_EQ(SC_ENHANCE_ERROR_VALUE_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } @@ -456,8 +468,10 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportClickWithoutHmac001, TestSize.Level1 ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + SecCompInfo secCompInfo{ scId, locationInfo, clickInfo }; + std::string message; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -493,8 +507,10 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission001, TestSize.Level1) ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; + std::string message; ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); setuid(100); ASSERT_FALSE(SecCompKit::VerifySavePermission(TestCommon::HAP_TOKEN_ID)); // mediaLibraryTokenId_ != 0 @@ -533,8 +549,10 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission002, TestSize.Level1) ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; + std::string message; ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -568,8 +586,10 @@ HWTEST_F(SecCompRegisterCallbackTest, UnregisterSecurityComponent001, TestSize.L ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; + std::string message; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } diff --git a/interfaces/inner_api/security_component/include/sec_comp_info.h b/interfaces/inner_api/security_component/include/sec_comp_info.h index a712f0e53cff7bdcc3d10c238a44f123b740d0e9..39afc04e58e754815bd642f0854044879382cbe9 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_info.h +++ b/interfaces/inner_api/security_component/include/sec_comp_info.h @@ -18,6 +18,7 @@ #include #include +#include namespace OHOS { namespace Security { @@ -144,6 +145,12 @@ struct SecCompClickEvent { }; ExtraInfo extraInfo; }; + +struct SecCompInfo { + int32_t scId; + std::string componentInfo; + SecCompClickEvent clickInfo; +}; } // namespace SecurityComponent } // namespace Security } // namespace OHOS 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 a2649937bf93145ff7caf86fdc0a9ae214bc9bb2..bfa8d08099235dca536dac0713436b6a8969006f 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_kit.h +++ b/interfaces/inner_api/security_component/include/sec_comp_kit.h @@ -29,10 +29,8 @@ public: static int32_t RegisterSecurityComponent(SecCompType type, std::string& componentInfo, int32_t& scId); static int32_t UpdateSecurityComponent(int32_t scId, std::string& componentInfo); static int32_t UnregisterSecurityComponent(int32_t scId); - static int32_t ReportSecurityComponentClickEvent(int32_t scId, - std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, - OnFirstUseDialogCloseFunc&& callback); + static int32_t ReportSecurityComponentClickEvent(SecCompInfo& SecCompInfo, sptr callerToken, + OnFirstUseDialogCloseFunc&& callback, std::string& message); static bool VerifySavePermission(AccessToken::AccessTokenID tokenId); static sptr GetEnhanceRemoteObject(bool isLoad); static int32_t PreRegisterSecCompProcess(); 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 f9b6a8c06baad4cdc6a99e73dc59981082ed0939..d6c8209e92ae2196930cd6bcc2276a9a76787c4e 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 @@ -36,9 +36,10 @@ T* ConstructComponent(const nlohmann::json& jsonComponent) class __attribute__((visibility("default"))) SecCompInfoHelper { public: - static SecCompBase* ParseComponent(SecCompType type, const nlohmann::json& jsonComponent); - static bool CheckComponentValid(SecCompBase* comp); - static bool CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, const uint64_t displayId); + static SecCompBase* ParseComponent(SecCompType type, const nlohmann::json& jsonComponent, std::string& message); + static bool CheckComponentValid(SecCompBase* comp, std::string& message); + static bool CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, const uint64_t displayId, + std::string& message); private: static float GetWindowScale(int32_t windowId); diff --git a/services/security_component_service/sa/sa_main/sec_comp_entity.cpp b/services/security_component_service/sa/sa_main/sec_comp_entity.cpp index 30a7caa938fef5feb2da78ada9ea707ed299e3f4..bf235f49bb8dce73078502d19387b80837340128 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_entity.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_entity.cpp @@ -97,10 +97,10 @@ int32_t SecCompEntity::CheckKeyEvent(const SecCompClickEvent& clickInfo) const return SC_OK; } -int32_t SecCompEntity::CheckClickInfo(const SecCompClickEvent& clickInfo) const +int32_t SecCompEntity::CheckClickInfo(const SecCompClickEvent& clickInfo, std::string& message) const { if (!WindowInfoHelper::CheckOtherWindowCoverComp(componentInfo_->windowId_, - componentInfo_->rect_)) { + componentInfo_->rect_, message)) { SC_LOG_ERROR(LABEL, "Component may be covered by other window"); return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } diff --git a/services/security_component_service/sa/sa_main/sec_comp_entity.h b/services/security_component_service/sa/sa_main/sec_comp_entity.h index 2bc4d64f16c118f3477fc51945c3e75afbc243b3..4998d42ac6953e06395ef6644e31c52ebf83fc33 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_entity.h +++ b/services/security_component_service/sa/sa_main/sec_comp_entity.h @@ -46,7 +46,7 @@ public: } bool CompareComponentBasicInfo(SecCompBase* other, bool isRectCheck) const; - int32_t CheckClickInfo(const SecCompClickEvent& clickInfo) const; + int32_t CheckClickInfo(const SecCompClickEvent& clickInfo, std::string& message) const; std::shared_ptr componentInfo_; AccessToken::AccessTokenID tokenId_; 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 a92c0d8a7a598ef2fc0a9e1a6637906d0dda369a..0bcc777cc0457a9de406485df0c30365ecba9875 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 @@ -14,6 +14,9 @@ */ #include "sec_comp_info_helper.h" +#include +#include + #include "accesstoken_kit.h" #include "display.h" #include "display_info.h" @@ -33,6 +36,12 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompInfoHelper"}; static constexpr double MAX_RECT_PERCENT = 0.1F; // 10% static constexpr double ZERO_OFFSET = 0.0F; +const std::string OUT_OF_SCREEN = ", security component is out of screen, security component(x = "; +const std::string OUT_OF_WINDOW = ", security component is out of window, security component(x = "; +const std::string SECURITY_COMPONENT_IS_TOO_LARGER = + ", security component is too larger, security component(width = "; +const int HEX_FIELD_WIDTH = 2; +const char HEX_FILL_CHAR = '0'; } void SecCompInfoHelper::AdjustSecCompRect(SecCompBase* comp, float scale) @@ -46,7 +55,8 @@ void SecCompInfoHelper::AdjustSecCompRect(SecCompBase* comp, float scale) comp->rect_.x_, comp->rect_.y_, comp->rect_.width_, comp->rect_.height_); } -SecCompBase* SecCompInfoHelper::ParseComponent(SecCompType type, const nlohmann::json& jsonComponent) +SecCompBase* SecCompInfoHelper::ParseComponent(SecCompType type, const nlohmann::json& jsonComponent, + std::string& message) { SecCompBase* comp = nullptr; switch (type) { @@ -68,7 +78,7 @@ SecCompBase* SecCompInfoHelper::ParseComponent(SecCompType type, const nlohmann: return comp; } - comp->SetValid(CheckComponentValid(comp)); + comp->SetValid(CheckComponentValid(comp, message)); return comp; } @@ -95,7 +105,7 @@ static bool GetScreenSize(double& width, double& height, const uint64_t displayI } bool SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, - const uint64_t displayId) + const uint64_t displayId, std::string& message) { double curScreenWidth = 0.0F; double curScreenHeight = 0.0F; @@ -112,12 +122,20 @@ bool SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRec if (GreatNotEqual(ZERO_OFFSET, rect.x_) || GreatNotEqual(ZERO_OFFSET, rect.y_) || GreatNotEqual(rect.x_, curScreenWidth) || GreatNotEqual(rect.y_, curScreenHeight)) { SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of screen"); + message = OUT_OF_SCREEN + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + + ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + + "), current screen(width = " + std::to_string(curScreenWidth) + + ", height = " + std::to_string(curScreenHeight) + ")"; return false; } if (GreatOrEqual((rect.x_ + rect.width_), curScreenWidth) || GreatOrEqual((rect.y_ + rect.height_), curScreenHeight)) { SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of screen"); + message = OUT_OF_SCREEN + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + + ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + + "), current screen(width = " + std::to_string(curScreenWidth) + + ", height = " + std::to_string(curScreenHeight) + ")"; return false; } @@ -125,19 +143,68 @@ bool SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRec GreatNotEqual(rect.x_ + rect.width_, windowRect.x_ + windowRect.width_) || GreatNotEqual(rect.y_ + rect.height_, windowRect.y_ + windowRect.height_)) { SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of window"); + message = OUT_OF_WINDOW + std::to_string(rect.x_) + ", y = " + std::to_string(rect.y_) + + ", width = " + std::to_string(rect.width_) + ", height = " + std::to_string(rect.height_) + + "), current window(x = " + std::to_string(windowRect.x_) + ", y = " + std::to_string(windowRect.y_) + + ", width = " + std::to_string(windowRect.width_) + ", height = " + + std::to_string(windowRect.height_) + ")"; return false; } // check rect > 10% if (GreatOrEqual((rect.width_ * rect.height_), (curScreenWidth * curScreenHeight * MAX_RECT_PERCENT))) { SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is larger than 10 percent of screen"); + message = SECURITY_COMPONENT_IS_TOO_LARGER + std::to_string(rect.width_) + + ", height = " + std::to_string(rect.height_) + "), current screen(width = " + + std::to_string(curScreenWidth) + ", height = " + std::to_string(curScreenHeight) + ")"; return false; } SC_LOG_DEBUG(LABEL, "check component rect success."); return true; } -static bool CheckSecCompBaseButton(const SecCompBase* comp) +std::string ColorToHexString(const SecCompColor& color) +{ + std::stringstream ss; + ss << std::hex; + ss << std::setw(HEX_FIELD_WIDTH) << std::setfill(HEX_FILL_CHAR) << static_cast(color.argb.alpha); + ss << std::setw(HEX_FIELD_WIDTH) << std::setfill(HEX_FILL_CHAR) << static_cast(color.argb.red); + ss << std::setw(HEX_FIELD_WIDTH) << std::setfill(HEX_FILL_CHAR) << static_cast(color.argb.green); + ss << std::setw(HEX_FIELD_WIDTH) << std::setfill(HEX_FILL_CHAR) << static_cast(color.argb.blue); + + return "#" + ss.str(); +} + +static bool CheckSecCompBaseButtonColorsimilar(const SecCompBase* comp, std::string& message) +{ + if ((comp->bg_ != SecCompBackground::NO_BG_TYPE) && !IsColorFullTransparent(comp->bgColor_) && + (comp->icon_ != NO_ICON) && IsColorSimilar(comp->iconColor_, comp->bgColor_)) { + SC_LOG_INFO(LABEL, "SecurityComponentCheckFail: iconColor is similar with backgroundColor."); + message = ", icon color is similar with background color, icon color = " + + ColorToHexString(comp->iconColor_) + ", background color = " + ColorToHexString(comp->bgColor_); + return false; + } + + if ((comp->bg_ != SecCompBackground::NO_BG_TYPE) && !IsColorFullTransparent(comp->bgColor_) && + (comp->text_ != NO_TEXT) && IsColorSimilar(comp->fontColor_, comp->bgColor_)) { + SC_LOG_INFO(LABEL, "SecurityComponentCheckFail: fontColor is similar with backgroundColor."); + message = ", font color is similar with background color, font color = " + + ColorToHexString(comp->fontColor_) + ", background color = " + ColorToHexString(comp->bgColor_); + return false; + } + + if (comp->bg_ == SecCompBackground::NO_BG_TYPE && + ((comp->padding_.top != MIN_PADDING_WITHOUT_BG) || (comp->padding_.right != MIN_PADDING_WITHOUT_BG) || + (comp->padding_.bottom != MIN_PADDING_WITHOUT_BG) || (comp->padding_.left != MIN_PADDING_WITHOUT_BG))) { + SC_LOG_INFO(LABEL, "padding can not change without background."); + message = ", padding can not change without background"; + return false; + } + + return true; +} + +static bool CheckSecCompBaseButton(const SecCompBase* comp, std::string& message) { if ((comp->text_ < 0) && (comp->icon_ < 0)) { SC_LOG_INFO(LABEL, "both text and icon do not exist."); @@ -153,58 +220,65 @@ static bool CheckSecCompBaseButton(const SecCompBase* comp) if (comp->fontSize_ < minFontSize) { SC_LOG_INFO(LABEL, "SecurityComponentCheckFail: fontSize is too small."); + message = ", font size is too small, font size = " + + std::to_string(comp->fontSize_); return false; } } if ((comp->icon_ >= 0) && comp->iconSize_ < MIN_ICON_SIZE) { SC_LOG_INFO(LABEL, "SecurityComponentCheckFail: iconSize is too small."); + message = ", icon size is too small, icon size = " + + std::to_string(comp->iconSize_); return false; } - if ((comp->bg_ != SecCompBackground::NO_BG_TYPE) && !IsColorFullTransparent(comp->bgColor_) && - (((comp->text_ != NO_TEXT) && (IsColorSimilar(comp->fontColor_, comp->bgColor_))) || - ((comp->icon_ != NO_ICON) && (IsColorSimilar(comp->iconColor_, comp->bgColor_))))) { - SC_LOG_INFO(LABEL, "SecurityComponentCheckFail: fontColor or iconColor is similar with backgroundColor."); - return false; - } - - if (comp->bg_ == SecCompBackground::NO_BG_TYPE && - ((comp->padding_.top != MIN_PADDING_WITHOUT_BG) || (comp->padding_.right != MIN_PADDING_WITHOUT_BG) || - (comp->padding_.bottom != MIN_PADDING_WITHOUT_BG) || (comp->padding_.left != MIN_PADDING_WITHOUT_BG))) { - SC_LOG_INFO(LABEL, "padding can not change without background."); - return false; - } - - return true; + return CheckSecCompBaseButtonColorsimilar(comp, message); } -static bool CheckSecCompBase(const SecCompBase* comp) +static bool CheckSecCompBase(const SecCompBase* comp, std::string& message) { if (comp->parentEffect_) { SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: the parents of security component have invalid effect."); + message = "PARENT_HAVE_INVALID_EFFECT"; return false; } if ((comp->padding_.top < MIN_PADDING_SIZE) || (comp->padding_.right < MIN_PADDING_SIZE) || - (comp->padding_.bottom < MIN_PADDING_SIZE) || (comp->padding_.left < MIN_PADDING_SIZE) || - (comp->textIconSpace_ < MIN_PADDING_SIZE)) { - SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: padding or textIconSpace is too small."); + (comp->padding_.bottom < MIN_PADDING_SIZE) || (comp->padding_.left < MIN_PADDING_SIZE)) { + SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: padding is too small."); + message = ", padding is too small, padding(top = " + std::to_string(comp->padding_.top) + + ", bottom = " + std::to_string(comp->padding_.bottom) + + ", left = " + std::to_string(comp->padding_.left) + + ", right = " + std::to_string(comp->padding_.right) + ")"; + return false; + } + + if ((comp->textIconSpace_ < MIN_PADDING_SIZE)) { + SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: textIconSpace is too small."); + message = ", textIconSpace is too small, textIconSpace = " + std::to_string(comp->textIconSpace_); return false; } - if (((comp->text_ != NO_TEXT) && (IsColorTransparent(comp->fontColor_))) || - ((comp->icon_ != NO_ICON) && (IsColorTransparent(comp->iconColor_)))) { - SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: fontColor or iconColor is too transparent."); + if ((comp->text_ != NO_TEXT) && (IsColorTransparent(comp->fontColor_))) { + SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: fontColor is too transparent."); + message = ", font color is too transparent, font color = " + ColorToHexString(comp->fontColor_); return false; } - if (!CheckSecCompBaseButton(comp)) { + + if ((comp->icon_ != NO_ICON) && (IsColorTransparent(comp->iconColor_))) { + SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: iconColor is too transparent."); + message = ", icon color is too transparent, icon color = " + ColorToHexString(comp->iconColor_); + return false; + } + + if (!CheckSecCompBaseButton(comp, message)) { return false; } return true; } -bool SecCompInfoHelper::CheckComponentValid(SecCompBase* comp) +bool SecCompInfoHelper::CheckComponentValid(SecCompBase* comp, std::string& message) { if ((comp == nullptr) || !IsComponentTypeValid(comp->type_)) { SC_LOG_INFO(LABEL, "comp is null or type is invalid."); @@ -217,7 +291,7 @@ bool SecCompInfoHelper::CheckComponentValid(SecCompBase* comp) AdjustSecCompRect(comp, scale); } - if (!CheckSecCompBase(comp)) { + if (!CheckSecCompBase(comp, message)) { SC_LOG_INFO(LABEL, "SecComp base is invalid."); return false; } 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 bda0d42bdf80926701096f00d2908a230b91cc07..570e498d4582c1a3177515030547dfe56fc0b8ee 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 @@ -36,6 +36,7 @@ static constexpr int32_t MAX_INT_NUM = 0x7fffffff; static constexpr int32_t MAX_SINGLE_PROC_COMP_SIZE = 500; static constexpr unsigned long REPORT_REMOTE_OBJECT_SIZE = 2UL; static std::mutex g_instanceMutex; +const std::string START_DIALOG = "start dialog, onclick will be trap after dialog closed."; } SecCompManager::SecCompManager() @@ -354,7 +355,8 @@ int32_t SecCompManager::RegisterSecurityComponent(SecCompType type, return SC_ENHANCE_ERROR_IN_MALICIOUS_LIST; } - SecCompBase* componentPtr = SecCompInfoHelper::ParseComponent(type, jsonComponent); + std::string message; + SecCompBase* componentPtr = SecCompInfoHelper::ParseComponent(type, jsonComponent, message); std::shared_ptr component(componentPtr); if (component == nullptr) { SC_LOG_ERROR(LABEL, "Parse component info invalid"); @@ -405,7 +407,8 @@ int32_t SecCompManager::UpdateSecurityComponent(int32_t scId, const nlohmann::js SC_LOG_ERROR(LABEL, "Can not find target component"); return SC_SERVICE_ERROR_COMPONENT_NOT_EXIST; } - SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), jsonComponent); + std::string message; + SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), jsonComponent, message); std::shared_ptr reportComponentInfo(report); if (reportComponentInfo == nullptr) { SC_LOG_ERROR(LABEL, "Update component info invalid"); @@ -444,10 +447,10 @@ int32_t SecCompManager::UnregisterSecurityComponent(int32_t scId, const SecCompC } int32_t SecCompManager::CheckClickSecurityComponentInfo(std::shared_ptr sc, int32_t scId, - const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller) + const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller, std::string& message) { SC_LOG_DEBUG(LABEL, "PID: %{public}d, Check security component", caller.pid); - SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), jsonComponent); + SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), jsonComponent, message); std::shared_ptr reportComponentInfo(report); int32_t uid = IPCSkeleton::GetCallingUid(); OHOS::AppExecFwk::BundleMgrClient bmsClient; @@ -468,7 +471,7 @@ int32_t SecCompManager::CheckClickSecurityComponentInfo(std::shared_ptrrect_, reportComponentInfo->windowRect_, - report->displayId_))) { + report->displayId_, message))) { SC_LOG_ERROR(LABEL, "compare component info failed."); HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "COMPONENT_INFO_CHECK_FAILED", HiviewDFX::HiSysEvent::EventType::SECURITY, "CALLER_UID", uid, "CALLER_BUNDLE_NAME", bundleName, @@ -501,11 +504,12 @@ static void ReportEvent(std::string eventName, HiviewDFX::HiSysEvent::EventType "CALLER_PID", IPCSkeleton::GetCallingPid(), "SC_ID", scId, "SC_TYPE", scType); } -int32_t SecCompManager::ReportSecurityComponentClickEvent(int32_t scId, +int32_t SecCompManager::ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller, - const SecCompClickEvent& clickInfo, const std::vector>& remote) + const std::vector>& remote, std::string& message) { if (remote.size() < REPORT_REMOTE_OBJECT_SIZE) { + SC_LOG_ERROR(LABEL, "remote object size is invalid"); return SC_SERVICE_ERROR_VALUE_INVALID; } auto callerToken = remote[0]; @@ -517,21 +521,21 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(int32_t scId, } OHOS::Utils::UniqueReadGuard lk(this->componentInfoLock_); - std::shared_ptr sc = GetSecurityComponentFromList(caller.pid, scId); + std::shared_ptr sc = GetSecurityComponentFromList(caller.pid, secCompInfo.scId); if (sc == nullptr) { SC_LOG_ERROR(LABEL, "Can not find target component"); return SC_SERVICE_ERROR_COMPONENT_NOT_EXIST; } - int32_t res = CheckClickSecurityComponentInfo(sc, scId, jsonComponent, caller); + int32_t res = CheckClickSecurityComponentInfo(sc, secCompInfo.scId, jsonComponent, caller, message); if (res != SC_OK) { return res; } - res = sc->CheckClickInfo(clickInfo); + res = sc->CheckClickInfo(secCompInfo.clickInfo, message); if (res != SC_OK) { ReportEvent("CLICK_INFO_CHECK_FAILED", HiviewDFX::HiSysEvent::EventType::SECURITY, - scId, sc->GetType()); + secCompInfo.scId, sc->GetType()); if (res == SC_ENHANCE_ERROR_CLICK_EXTRA_CHECK_FAIL) { malicious_.AddAppToMaliciousAppList(caller.pid); } @@ -539,7 +543,7 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(int32_t scId, return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } - SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), jsonComponent); + SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), jsonComponent, message); if (FirstUseDialog::GetInstance().NotifyFirstUseDialog(sc, callerToken, dialogCallback, report->displayId_) == SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE) { SC_LOG_INFO(LABEL, "start dialog, onclick will be trap after dialog closed."); @@ -548,13 +552,12 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(int32_t scId, res = sc->GrantTempPermission(); if (res != SC_OK) { - ReportEvent("TEMP_GRANT_FAILED", HiviewDFX::HiSysEvent::EventType::FAULT, - scId, sc->GetType()); + ReportEvent("TEMP_GRANT_FAILED", HiviewDFX::HiSysEvent::EventType::FAULT, secCompInfo.scId, sc->GetType()); return res; } HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "TEMP_GRANT_SUCCESS", HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "CALLER_UID", IPCSkeleton::GetCallingUid(), - "CALLER_PID", IPCSkeleton::GetCallingPid(), "SC_ID", scId, "SC_TYPE", sc->GetType()); + "CALLER_PID", IPCSkeleton::GetCallingPid(), "SC_ID", secCompInfo.scId, "SC_TYPE", sc->GetType()); return res; } 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 04d85e4e2634f0f56c9723214e4611800ac70df3..af40df827ad5c2ace05ca60ae0505c85d60aa981 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 @@ -57,9 +57,8 @@ public: int32_t UpdateSecurityComponent(int32_t scId, const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller); int32_t UnregisterSecurityComponent(int32_t scId, const SecCompCallerInfo& caller); - int32_t ReportSecurityComponentClickEvent(int32_t scId, const nlohmann::json& jsonComponent, - const SecCompCallerInfo& caller, const SecCompClickEvent& clickInfo, - const std::vector>& remote); + int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, const nlohmann::json& jsonComponent, + const SecCompCallerInfo& caller, const std::vector>& remote, std::string& message); void NotifyProcessForeground(int32_t pid); void NotifyProcessBackground(int32_t pid); void NotifyProcessDied(int32_t pid); @@ -78,7 +77,7 @@ private: int32_t DeleteSecurityComponentFromList(int32_t pid, int32_t scId); std::shared_ptr GetSecurityComponentFromList(int32_t pid, int32_t scId); int32_t CheckClickSecurityComponentInfo(std::shared_ptr sc, int32_t scId, - const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller); + const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller, std::string& message); void SendCheckInfoEnhanceSysEvent(int32_t scId, SecCompType type, const std::string& scene, int32_t res); int32_t CreateScId(); 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 5f35b29f01205685ef733cc7bc6f8e3dfcf729fc..35cce2879a982c7a6cc99518466790445c24f5ed 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 @@ -244,21 +244,20 @@ int32_t SecCompService::UnregisterSecurityComponent(int32_t scId) return SecCompManager::GetInstance().UnregisterSecurityComponent(scId, caller); } -int32_t SecCompService::ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, sptr dialogCallback) +int32_t SecCompService::ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, + sptr callerToken, sptr dialogCallback, std::string& message) { StartTrace(HITRACE_TAG_ACCESS_CONTROL, "SecurityComponentClick"); SecCompCallerInfo caller; nlohmann::json jsonRes; - if (ParseParams(componentInfo, caller, jsonRes) != SC_OK) { + if (ParseParams(secCompInfo.componentInfo, caller, jsonRes) != SC_OK) { FinishTrace(HITRACE_TAG_ACCESS_CONTROL); return SC_SERVICE_ERROR_VALUE_INVALID; } std::vector> remoteArr = { callerToken, dialogCallback }; int32_t res = - SecCompManager::GetInstance().ReportSecurityComponentClickEvent(scId, jsonRes, caller, clickInfo, - remoteArr); + SecCompManager::GetInstance().ReportSecurityComponentClickEvent(secCompInfo, jsonRes, caller, remoteArr, + message); FinishTrace(HITRACE_TAG_ACCESS_CONTROL); return res; } 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 ff955821541e8d24570bd8bbc9a334fe20ae1c65..9a4541076f6285ea4763f1d6c8faf7641f21984f 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 @@ -43,9 +43,8 @@ public: int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId) override; int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) override; int32_t UnregisterSecurityComponent(int32_t scId) override; - int32_t ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, sptr dialogCallback) override; + int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, sptr callerToken, + sptr dialogCallback, std::string& message) override; bool VerifySavePermission(AccessToken::AccessTokenID tokenId) override; sptr GetEnhanceRemoteObject() override; int32_t PreRegisterSecCompProcess() override; 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 b50d9322353aa9cf397563511941478fb1df058c..198b0876d395562fc118c2a9764d5f4760cef696 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 @@ -167,6 +167,28 @@ int32_t SecCompStub::UnregisterSecurityComponentInner(MessageParcel& data, Messa return SC_OK; } +int32_t SecCompStub::WriteSecurityComponentClickEventResult(int32_t res, MessageParcel& reply, + const std::string& message) +{ + MessageParcel rawReply; + if (!rawReply.WriteInt32(res)) { + SC_LOG_ERROR(LABEL, "Report security component result failed"); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + + if (!rawReply.WriteString(message)) { + SC_LOG_ERROR(LABEL, "Report security component error message failed"); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + + if (!SecCompEnhanceAdapter::EnhanceSrvSerialize(rawReply, reply)) { + SC_LOG_ERROR(LABEL, "Report serialize session info failed"); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + + return SC_OK; +} + int32_t SecCompStub::ReportSecurityComponentClickEventInner(MessageParcel& data, MessageParcel& reply) { sptr callerToken = data.ReadRemoteObject(); @@ -208,22 +230,10 @@ int32_t SecCompStub::ReportSecurityComponentClickEventInner(MessageParcel& data, return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - int32_t res = - this->ReportSecurityComponentClickEvent(scId, - componentInfo, clickInfoParcel->clickInfoParams_, - callerToken, dialogCallback); - MessageParcel rawReply; - if (!rawReply.WriteInt32(res)) { - SC_LOG_ERROR(LABEL, "Report security component result failed"); - return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; - } - - if (!SecCompEnhanceAdapter::EnhanceSrvSerialize(rawReply, reply)) { - SC_LOG_ERROR(LABEL, "Report serialize session info failed"); - return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; - } - - return SC_OK; + SecCompInfo secCompInfo{ scId, componentInfo, clickInfoParcel->clickInfoParams_ }; + std::string message; + int32_t res = this->ReportSecurityComponentClickEvent(secCompInfo, callerToken, dialogCallback, message); + return WriteSecurityComponentClickEventResult(res, reply, message); } int32_t SecCompStub::VerifySavePermissionInner(MessageParcel& data, MessageParcel& reply) diff --git a/services/security_component_service/sa/sa_main/sec_comp_stub.h b/services/security_component_service/sa/sa_main/sec_comp_stub.h index 57ce8b47fd3a86ac2de173b4645525dfd4796491..325ea413e3744843a31162fe03eb86fed9ef2e2d 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_stub.h +++ b/services/security_component_service/sa/sa_main/sec_comp_stub.h @@ -38,6 +38,8 @@ private: int32_t VerifySavePermissionInner(MessageParcel& data, MessageParcel& reply); int32_t GetEnhanceRemoteObjectInner(MessageParcel& data, MessageParcel& reply); int32_t PreRegisterSecCompProcessInner(MessageParcel& data, MessageParcel& reply); + int32_t WriteSecurityComponentClickEventResult(int32_t res, MessageParcel& reply, + const std::string& message); bool IsMediaLibraryCalling(); using RequestFuncType = int32_t (SecCompStub::*)(MessageParcel& data, MessageParcel& reply); diff --git a/services/security_component_service/sa/sa_main/window_info_helper.cpp b/services/security_component_service/sa/sa_main/window_info_helper.cpp index 4af328b0763e81dcd0c0b5dba5caa96d828777ca..ac99691895e8cfdfdb6273265caa7db036eeb893 100644 --- a/services/security_component_service/sa/sa_main/window_info_helper.cpp +++ b/services/security_component_service/sa/sa_main/window_info_helper.cpp @@ -47,6 +47,26 @@ float WindowInfoHelper::GetWindowScale(int32_t windowId) return scale; } +std::string GetSecCompWindowMsg(int32_t compWinId, const SecCompRect& secRect, + int32_t coverWindowId) +{ + std::string message = ", the id of the window where the security component is located is " + + std::to_string(compWinId) + ", security component is covered by the window(id = " + + std::to_string(coverWindowId) + "), the size of security component is (x = " + + std::to_string(secRect.x_) + ", y = " + std::to_string(secRect.y_) + + ", width = " + std::to_string(secRect.width_) + + ", height = " + std::to_string(secRect.height_) + ")"; + return message; +} + +std::string GetCoveredWindowMsg(const Rosen::Rect& windowRect) +{ + std::string coveredWindowMessage = ", the size of window covering security component is (x = " + + std::to_string(windowRect.posX_) + ", y = " + std::to_string(windowRect.posY_) + + ", width = " + std::to_string(windowRect.width_) + ", height = " + std::to_string(windowRect.height_) + ")"; + return coveredWindowMessage; +} + static bool IsRectInWindRect(const Rosen::Rect& windRect, const SecCompRect& secRect) { // left or right @@ -63,7 +83,30 @@ static bool IsRectInWindRect(const Rosen::Rect& windRect, const SecCompRect& sec return true; } -bool WindowInfoHelper::CheckOtherWindowCoverComp(int32_t compWinId, const SecCompRect& secRect) +static bool IsOtherWindowCoverComp(int32_t compWinId, const SecCompRect& secRect, int32_t compLayer, + std::string& message, const std::vector>& layerList) +{ + if (compLayer == INVALID_WINDOW_LAYER) { + SC_LOG_ERROR(LABEL, "windId %{public}d component layer is wrong", compWinId); + return false; + } + + if (layerList.size() == static_cast(0)) { + return true; + } + + auto iter = std::find_if(layerList.begin(), layerList.end(), [compLayer](const std::pair layer) { + return layer.second >= compLayer; + }); + if (iter != layerList.end()) { + SC_LOG_ERROR(LABEL, "component window %{public}d is covered by %{public}d, click check failed", + compWinId, iter->first); + message = GetSecCompWindowMsg(compWinId, secRect, iter->first); + return false; + } + return true; +} +bool WindowInfoHelper::CheckOtherWindowCoverComp(int32_t compWinId, const SecCompRect& secRect, std::string& message) { if ((static_cast(compWinId) & UI_EXTENSION_MASK) == UI_EXTENSION_MASK) { SC_LOG_INFO(LABEL, "UI extension can not check"); @@ -76,6 +119,7 @@ bool WindowInfoHelper::CheckOtherWindowCoverComp(int32_t compWinId, const SecCom } int32_t compLayer = INVALID_WINDOW_LAYER; + std::string coveredWindowMsg; // {windowId, zOrder} std::vector> layerList; for (auto& info : infos) { @@ -93,28 +137,18 @@ bool WindowInfoHelper::CheckOtherWindowCoverComp(int32_t compWinId, const SecCom } if (IsRectInWindRect(info->windowRect_, secRect)) { layerList.emplace_back(std::make_pair(info->windowId_, info->zOrder_)); + if (compLayer != INVALID_WINDOW_LAYER && static_cast(info->zOrder_) >= compLayer) { + coveredWindowMsg = GetCoveredWindowMsg(info->windowRect_); + break; + } } } - if (compLayer == INVALID_WINDOW_LAYER) { - SC_LOG_ERROR(LABEL, "windId %{public}d component layer is wrong", compWinId); - return false; - } - - if (layerList.size() == static_cast(0)) { - return true; - } - - auto iter = std::find_if(layerList.begin(), layerList.end(), - [compLayer](const std::pair layer) { - return layer.second >= compLayer; - }); - if (iter != layerList.end()) { - SC_LOG_ERROR(LABEL, "component window %{public}d is covered by %{public}d, click check failed", - compWinId, iter->first); - return false; + bool res = IsOtherWindowCoverComp(compWinId, secRect, compLayer, message, layerList); + if (!message.empty()) { + message += coveredWindowMsg; } - return true; + return res; } } // namespace SecurityComponent } // namespace Security diff --git a/services/security_component_service/sa/sa_main/window_info_helper.h b/services/security_component_service/sa/sa_main/window_info_helper.h index a831bc10d1f177fb4283e3e06d3ecafadb51729f..f1c088572f7eac23790351568253c5350c7423f7 100644 --- a/services/security_component_service/sa/sa_main/window_info_helper.h +++ b/services/security_component_service/sa/sa_main/window_info_helper.h @@ -24,7 +24,7 @@ namespace SecurityComponent { class __attribute__((visibility("default"))) WindowInfoHelper { public: static float GetWindowScale(int32_t windowId); - static bool CheckOtherWindowCoverComp(int32_t compWinId, const SecCompRect& secRect); + static bool CheckOtherWindowCoverComp(int32_t compWinId, const SecCompRect& secRect, std::string& message); public: static constexpr float FULL_SCREEN_SCALE = 1.0F; }; diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp index b73a85cbbe5627823973cc41c480c8ff7b60aa39..fbd951395ff25f901b9094d2dab49305d0754fc2 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp @@ -116,11 +116,12 @@ HWTEST_F(SecCompEntityTest, CheckClickInfo001, TestSize.Level1) .point.touchY = ServiceTestCommon::TEST_COORDINATE, .point.timestamp = 0, }; - ASSERT_NE(entity_->CheckClickInfo(touch), SC_OK); + std::string message; + ASSERT_NE(entity_->CheckClickInfo(touch, message), SC_OK); uint64_t current = static_cast(std::chrono::high_resolution_clock::now().time_since_epoch().count()); touch.point.timestamp = current + 10000L; // 10s - ASSERT_NE(entity_->CheckClickInfo(touch), SC_OK); + ASSERT_NE(entity_->CheckClickInfo(touch, message), SC_OK); entity_->componentInfo_->rect_.x_ = ServiceTestCommon::TEST_DIFF_COORDINATE; // click event will not hit this rect entity_->componentInfo_->rect_.y_ = ServiceTestCommon::TEST_DIFF_COORDINATE; @@ -128,7 +129,7 @@ HWTEST_F(SecCompEntityTest, CheckClickInfo001, TestSize.Level1) entity_->componentInfo_->rect_.height_ = ServiceTestCommon::TEST_DIFF_COORDINATE; touch.point.timestamp = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / ServiceTestCommon::TIME_CONVERSION_UNIT; - ASSERT_NE(entity_->CheckClickInfo(touch), SC_OK); + ASSERT_NE(entity_->CheckClickInfo(touch, message), SC_OK); entity_->componentInfo_->rect_.x_ = ServiceTestCommon::TEST_COORDINATE; entity_->componentInfo_->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; @@ -137,7 +138,7 @@ HWTEST_F(SecCompEntityTest, CheckClickInfo001, TestSize.Level1) touch.extraInfo.data = buffer; touch.point.timestamp = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / ServiceTestCommon::TIME_CONVERSION_UNIT; - ASSERT_EQ(entity_->CheckClickInfo(touch), SC_OK); + ASSERT_EQ(entity_->CheckClickInfo(touch, message), SC_OK); } /** @@ -154,7 +155,8 @@ HWTEST_F(SecCompEntityTest, CheckClickInfo002, TestSize.Level1) .point.touchY = ServiceTestCommon::TEST_COORDINATE, .point.timestamp = static_cast(std::chrono::high_resolution_clock::now().time_since_epoch().count()), }; - ASSERT_NE(entity_->CheckClickInfo(touch), SC_OK); + std::string message; + ASSERT_NE(entity_->CheckClickInfo(touch, message), SC_OK); entity_->componentInfo_->rect_.x_ = ServiceTestCommon::TEST_COORDINATE; entity_->componentInfo_->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; @@ -163,7 +165,7 @@ HWTEST_F(SecCompEntityTest, CheckClickInfo002, TestSize.Level1) // GetAccessibilityWindowInfo failed OHOS::Rosen::WindowManager::GetInstance().result_ = static_cast(-1); - ASSERT_EQ(entity_->CheckClickInfo(touch), SC_SERVICE_ERROR_CLICK_EVENT_INVALID); + ASSERT_EQ(entity_->CheckClickInfo(touch, message), SC_SERVICE_ERROR_CLICK_EVENT_INVALID); } /** @@ -176,7 +178,8 @@ HWTEST_F(SecCompEntityTest, CompareComponentBasicInfo001, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* other = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* other = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); bool isRectCheck = true; ASSERT_FALSE(entity_->CompareComponentBasicInfo(other, isRectCheck)); } @@ -194,14 +197,15 @@ HWTEST_F(SecCompEntityTest, CheckKeyEvent001, TestSize.Level1) auto current = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / 1000; clickInfo.key.timestamp = current - 1000000L - 1; - ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, entity_->CheckClickInfo(clickInfo)); + std::string message; + ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, entity_->CheckClickInfo(clickInfo, message)); clickInfo.key.timestamp = current + 1; - ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, entity_->CheckClickInfo(clickInfo)); + ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, entity_->CheckClickInfo(clickInfo, message)); clickInfo.key.timestamp = current - 1; clickInfo.key.keyCode = 1; - ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, entity_->CheckClickInfo(clickInfo)); + ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, entity_->CheckClickInfo(clickInfo, message)); clickInfo.key.keyCode = KEY_SPACE; ASSERT_EQ(SC_OK, entity_->CheckKeyEvent(clickInfo)); diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp index 25e66cf43ca5b935ce140f4b84b775197d69be7d..748b4501d56bc616e3c587f6796d78604ddf6656 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp @@ -88,7 +88,8 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent001, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_NE(nullptr, comp); ASSERT_TRUE(comp->GetValid()); } @@ -102,11 +103,12 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent001, TestSize.Level1) HWTEST_F(SecCompInfoHelperTest, ParseComponent002, TestSize.Level1) { nlohmann::json jsonComponent; - ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(UNKNOWN_SC_TYPE, jsonComponent)); + std::string message; + ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(UNKNOWN_SC_TYPE, jsonComponent, message)); - ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent)); - ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(PASTE_COMPONENT, jsonComponent)); - ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(SAVE_COMPONENT, jsonComponent)); + ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message)); + ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(PASTE_COMPONENT, jsonComponent, message)); + ASSERT_EQ(nullptr, SecCompInfoHelper::ParseComponent(SAVE_COMPONENT, jsonComponent, message)); } /** @@ -118,13 +120,14 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent002, TestSize.Level1) HWTEST_F(SecCompInfoHelperTest, ParseComponent003, TestSize.Level1) { nlohmann::json jsonComponent; + std::string message; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); jsonComponent[JsonTagConstants::JSON_SC_TYPE] = UNKNOWN_SC_TYPE; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_EQ(nullptr, comp); } @@ -149,36 +152,37 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent004, TestSize.Level1) { SecCompRect rect = GetDefaultRect(); SecCompRect windowRect = GetDefaultRect(); - ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + std::string message; + ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); rect.x_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); rect.x_ = g_testWidth; rect.y_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); rect.y_ = g_testHeight; rect.x_ = g_curScreenWidth + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); rect.x_ = g_testWidth; rect.y_ = g_curScreenHeight + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); rect.y_ = g_testHeight; rect.width_ = g_curScreenWidth; rect.height_ = g_curScreenHeight; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); rect.width_ = g_testWidth; rect.height_ = g_testHeight; rect.x_ = g_curScreenWidth - g_testWidth; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); rect.x_ = g_testWidth; rect.y_ = g_curScreenHeight - g_testHeight; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); rect.y_ = g_testHeight; } @@ -192,30 +196,31 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent005, TestSize.Level1) { SecCompRect rect = GetDefaultRect(); SecCompRect windowRect = GetDefaultRect(); - ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + std::string message; + ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); windowRect.x_ = g_testWidth + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); windowRect.x_ = g_testWidth; windowRect.y_ = g_testHeight + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); windowRect.y_ = g_testHeight; windowRect.width_ = g_testWidth - 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); windowRect.width_ = g_testWidth; windowRect.height_ = g_testHeight - 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); windowRect.height_ = g_testHeight; windowRect.width_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); windowRect.width_ = g_testWidth; windowRect.height_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message)); windowRect.height_ = g_testHeight; } @@ -229,8 +234,9 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent006, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); + std::string message; - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { @@ -242,7 +248,7 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent006, TestSize.Level1) { JsonTagConstants::JSON_RIGHT_CLIP_TAG, 0.0 }, { JsonTagConstants::JSON_PARENT_TAG_TAG, "" }, }; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -256,23 +262,24 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent007, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); + std::string message; - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = ServiceTestCommon::TEST_DIMENSION; sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = ServiceTestCommon::TEST_DIMENSION; sizeJson[JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -286,18 +293,19 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent008, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = ServiceTestCommon::TEST_DIMENSION; paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -311,18 +319,19 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent009, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); auto& sizesJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingsJson = sizesJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; paddingsJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); paddingsJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = ServiceTestCommon::TEST_DIMENSION; paddingsJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = ServiceTestCommon::TEST_INVALID_DIMENSION; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -336,17 +345,18 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent010, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); auto& colorJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG]; colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_INVALID; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_RED; colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_INVALID; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -360,7 +370,8 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent011, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { @@ -368,7 +379,7 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent011, TestSize.Level1) { JsonTagConstants::JSON_ICON_TAG, NO_ICON }, { JsonTagConstants::JSON_BG_TAG, SecCompBackground::CIRCLE }, }; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -382,22 +393,23 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent012, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); auto& colorsJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG]; colorsJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_YELLOW; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); colorsJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_RED; colorsJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = ServiceTestCommon::TEST_COLOR_YELLOW; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::NO_BG_TYPE; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -411,7 +423,8 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent013, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; @@ -421,14 +434,14 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent013, TestSize.Level1) paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG; paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = ServiceTestCommon::TEST_DIMENSION; paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -441,8 +454,9 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent013, TestSize.Level1) HWTEST_F(SecCompInfoHelperTest, ParseComponent014, TestSize.Level1) { nlohmann::json jsonComponent; + std::string message; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; @@ -453,14 +467,14 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent014, TestSize.Level1) paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG; paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = MIN_PADDING_WITHOUT_BG; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = MIN_PADDING_WITHOUT_BG; paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = MIN_PADDING_WITHOUT_BG; paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = MIN_PADDING_WITHOUT_BG; paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = ServiceTestCommon::TEST_DIMENSION; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -475,7 +489,8 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent015, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); jsonComponent[JsonTagConstants::JSON_STYLE_TAG] = nlohmann::json { @@ -488,7 +503,7 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent015, TestSize.Level1) { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLACK }, { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_YELLOW } }; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_FALSE(comp->GetValid()); } @@ -502,16 +517,17 @@ HWTEST_F(SecCompInfoHelperTest, CheckComponentValid001, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); ASSERT_TRUE(comp->GetValid()); - ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp)); + ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp, message)); jsonComponent[JsonTagConstants::JSON_COLORS_TAG] = nlohmann::json { { JsonTagConstants::JSON_FONT_COLOR_TAG, ServiceTestCommon::TEST_COLOR_RED }, { JsonTagConstants::JSON_ICON_COLOR_TAG, ServiceTestCommon::TEST_COLOR_BLACK }, { JsonTagConstants::JSON_BG_COLOR_TAG, ServiceTestCommon::TEST_COLOR_WHITE } }; - comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); - ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp)); + comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); + ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp, message)); } /** @@ -524,16 +540,17 @@ HWTEST_F(SecCompInfoHelperTest, CheckComponentValid002, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); comp->text_ = UNKNOWN_TEXT; - ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp)); + ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp, message)); comp->text_ = static_cast(LocationDesc::SELECT_LOCATION); comp->icon_ = UNKNOWN_ICON; - ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp)); + ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp, message)); comp->text_ = UNKNOWN_TEXT; - ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp)); + ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp, message)); } /** @@ -546,12 +563,13 @@ HWTEST_F(SecCompInfoHelperTest, CheckComponentValid003, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); comp->type_ = SecCompType::UNKNOWN_SC_TYPE; - ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp)); + ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp, message)); comp->type_ = SecCompType::MAX_SC_TYPE; - ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp)); + ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp, message)); } /** @@ -564,7 +582,8 @@ HWTEST_F(SecCompInfoHelperTest, CheckComponentValid004, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); Rosen::WindowManager::GetInstance().result_ = Rosen::WMError::WM_OK; std::vector> list; @@ -580,7 +599,7 @@ HWTEST_F(SecCompInfoHelperTest, CheckComponentValid004, TestSize.Level1) otherWin->scaleVal_ = 0.0; list.emplace_back(otherWin); Rosen::WindowManager::GetInstance().list_ = list; - ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp)); + ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp, message)); } /** @@ -593,10 +612,11 @@ HWTEST_F(SecCompInfoHelperTest, CheckComponentValid005, TestSize.Level1) { nlohmann::json jsonComponent; ServiceTestCommon::BuildLocationComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(LOCATION_COMPONENT, jsonComponent, message); Rosen::WindowManager::GetInstance().result_ = static_cast(-1); - ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp)); + ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp, message)); } /** diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp index ed7144a6ee4c68c733480dcd01513abdeb613378..5f961960179b75164dbc421cf432638eb74a48e0 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp @@ -432,9 +432,11 @@ HWTEST_F(SecCompManagerTest, ReportSecurityComponentClickEvent001, TestSize.Leve LocationButton buttonValid = BuildValidLocationComponent(); buttonValid.ToJson(jsonVaild); std::vector> remote = { nullptr, nullptr }; - ASSERT_NE(SC_OK, - SecCompManager::GetInstance().ReportSecurityComponentClickEvent(1, - jsonVaild, caller, clickInfo, remote)); + int32_t scId = 1; + SecCompInfo secCompInfo{ scId, "", clickInfo}; + std::string message; + ASSERT_NE(SC_OK, SecCompManager::GetInstance().ReportSecurityComponentClickEvent(secCompInfo, + jsonVaild, caller, remote, message)); } /** @@ -486,17 +488,19 @@ HWTEST_F(SecCompManagerTest, CheckClickSecurityComponentInfo001, TestSize.Level1 buttonValid.ToJson(jsonVaild); jsonVaild[JsonTagConstants::JSON_SC_TYPE] = UNKNOWN_SC_TYPE; std::vector> remote = { nullptr, nullptr }; + SecCompInfo secCompInfo{ ServiceTestCommon::TEST_SC_ID_1, "", clickInfo }; + std::string message; ASSERT_EQ(SC_SERVICE_ERROR_COMPONENT_INFO_INVALID, SecCompManager::GetInstance().ReportSecurityComponentClickEvent( - ServiceTestCommon::TEST_SC_ID_1, jsonVaild, caller, clickInfo, remote)); + secCompInfo, jsonVaild, caller, remote, message)); jsonVaild[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; jsonVaild[JsonTagConstants::JSON_RECT][JsonTagConstants::JSON_RECT_X] = ServiceTestCommon::TEST_INVALID_DIMENSION; ASSERT_EQ(SC_SERVICE_ERROR_COMPONENT_INFO_INVALID, SecCompManager::GetInstance().ReportSecurityComponentClickEvent( - ServiceTestCommon::TEST_SC_ID_1, jsonVaild, caller, clickInfo, remote)); + secCompInfo, jsonVaild, caller, remote, message)); jsonVaild[JsonTagConstants::JSON_RECT][JsonTagConstants::JSON_RECT_X] = ServiceTestCommon::TEST_COORDINATE - 1; ASSERT_EQ(SC_SERVICE_ERROR_COMPONENT_INFO_INVALID, SecCompManager::GetInstance().ReportSecurityComponentClickEvent( - ServiceTestCommon::TEST_SC_ID_1, jsonVaild, caller, clickInfo, remote)); + secCompInfo, jsonVaild, caller, remote, message)); } /** diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_perm_manager_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_perm_manager_test.cpp index 4111522016986aa5aed2309d4b83cfd522740711..bf2a052285787597865937b6d1fc231fb3dd82b0 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_perm_manager_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_perm_manager_test.cpp @@ -192,7 +192,8 @@ HWTEST_F(SecCompPermManagerTest, GrantTempPermission001, TestSize.Level1) SecCompPermManager permMgr; nlohmann::json jsonComponent; ServiceTestCommon::BuildSaveComponentJson(jsonComponent); - SecCompBase* comp = SecCompInfoHelper::ParseComponent(SAVE_COMPONENT, jsonComponent); + std::string message; + SecCompBase* comp = SecCompInfoHelper::ParseComponent(SAVE_COMPONENT, jsonComponent, message); ASSERT_NE(nullptr, comp); std::shared_ptr shared_comp(comp); diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_service_mock_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_service_mock_test.cpp index 4e5454f25f946ebc11e1fdea6b49e1338eb78f2c..d86203c79da94271e48fe0a4f3e56cde6d8781b9 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_service_mock_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_service_mock_test.cpp @@ -113,9 +113,9 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent001, TestSize.Level1) .dataSize = 1 }, }; - - EXPECT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, - saveInfo, touch, nullptr, nullptr)); + SecCompInfo secCompInfo{ scId, saveInfo, touch }; + std::string message; + EXPECT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); SecCompPermManager::GetInstance().applySaveCountMap_.clear(); } @@ -149,8 +149,10 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent002, TestSize.Level1) .point.timestamp = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) }; + SecCompInfo secCompInfo{ scId, saveInfo, touch }; + std::string message; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr, nullptr)); + secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); SecCompPermManager::GetInstance().applySaveCountMap_.clear(); } @@ -190,8 +192,10 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent003, TestSize.Level1) .dataSize = 1 }, }; + SecCompInfo secCompInfo{ scId, saveInfo, touch }; + std::string message; EXPECT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL, - secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr, nullptr)); + secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); SecCompPermManager::GetInstance().applySaveCountMap_.clear(); } @@ -231,8 +235,9 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent001, TestSize. .dataSize = 1 }, }; - - ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, nullptr, nullptr)); + SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; + std::string message; + ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); // test 10s valid ASSERT_TRUE(secCompService_->VerifySavePermission(ServiceTestCommon::HAP_TOKEN_ID)); @@ -241,13 +246,13 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent001, TestSize. ASSERT_FALSE(secCompService_->VerifySavePermission(ServiceTestCommon::HAP_TOKEN_ID)); // test 10s multiple clicks - clickInfo.point.timestamp = static_cast( + secCompInfo.clickInfo.point.timestamp = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / ServiceTestCommon::TIME_CONVERSION_UNIT; - ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, nullptr, nullptr)); + ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); sleep(3); - clickInfo.point.timestamp = static_cast( + secCompInfo.clickInfo.point.timestamp = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / ServiceTestCommon::TIME_CONVERSION_UNIT; - ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, nullptr, nullptr)); + ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); sleep(8); ASSERT_TRUE(secCompService_->VerifySavePermission(ServiceTestCommon::HAP_TOKEN_ID)); sleep(2); @@ -290,9 +295,10 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent002, TestSize. .dataSize = 1 }, }; - + SecCompInfo secCompInfo{ scId, locationInfo, clickInfo1 }; + std::string message; ASSERT_EQ(SC_OK, - secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo1, nullptr, nullptr)); + secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); // test 10s valid ASSERT_EQ(AccessTokenKit::VerifyAccessToken(ServiceTestCommon::HAP_TOKEN_ID, "ohos.permission.LOCATION"), 0); diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp index de46e83f8de25ba1f2ba9fd7998dc4ca6242a39c..f8936c8b01d519453deff115f8a541522b88a0f3 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp @@ -273,8 +273,10 @@ HWTEST_F(SecCompServiceTest, ReportSecurityComponentClickEvent001, TestSize.Leve .extraInfo.data = data, .extraInfo.dataSize = 16, }; + SecCompInfo secCompInfo{ scId, locationInfo, touch }; + std::string message; EXPECT_EQ(SC_OK, - secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, touch, nullptr, nullptr)); + secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); setuid(uid); } @@ -363,7 +365,9 @@ HWTEST_F(SecCompServiceTest, GetCallerInfo002, TestSize.Level1) EXPECT_NE(secCompService_->UnregisterSecurityComponent(scId), SC_SERVICE_ERROR_VALUE_INVALID); struct SecCompClickEvent touchInfo; - EXPECT_EQ(secCompService_->ReportSecurityComponentClickEvent(scId, componentInfo, touchInfo, nullptr, nullptr), + SecCompInfo secCompInfo{ scId, componentInfo, touchInfo }; + std::string message; + EXPECT_EQ(secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message), SC_SERVICE_ERROR_VALUE_INVALID); secCompService_->GetEnhanceRemoteObject(); } diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_stub_mock_test.h b/services/security_component_service/sa/test/unittest/src/sec_comp_stub_mock_test.h index 022d53334eebaf8e6172d09fdaf427479b88d31d..4a197be5e6caa1fb3dcab352217640695e8bffc7 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_stub_mock_test.h +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_stub_mock_test.h @@ -43,9 +43,8 @@ public: return 0; }; - int32_t ReportSecurityComponentClickEvent(int32_t scId, const std::string& componentInfo, - const SecCompClickEvent& clickInfo, sptr callerToken, - sptr dialogCall) override + int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, sptr callerToken, + sptr dialogCall, std::string& message) override { return 0; }; diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h b/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h index 2c2c1c32847ed47a077b5a6af36cfa7038063cce..a29772a782bbc3c63ee8073b915f975996bec6b7 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h @@ -43,8 +43,8 @@ public: return 0; }; - int32_t ReportSecurityComponentClickEvent(int32_t scId, const std::string& componentInfo, - const SecCompClickEvent& clickInfo, sptr callerToken, sptr dialogCall) override + int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, sptr callerToken, + sptr dialogCall, std::string& message) override { return 0; }; diff --git a/services/security_component_service/sa/test/unittest/src/window_info_helper_test.cpp b/services/security_component_service/sa/test/unittest/src/window_info_helper_test.cpp index 4f3ea0cb7565bb044cba0134c654221e6d1cb6c2..e28df800e553766a8a9c0af179623e078e93cc40 100644 --- a/services/security_component_service/sa/test/unittest/src/window_info_helper_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/window_info_helper_test.cpp @@ -101,7 +101,8 @@ HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp001, TestSize.Level1) ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE }; - ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect)); + std::string message; + ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message)); } /** @@ -125,7 +126,8 @@ HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp002, TestSize.Level1) ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE }; - ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect)); + std::string message; + ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message)); } /** @@ -149,5 +151,6 @@ HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp003, TestSize.Level1) ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE }; - ASSERT_TRUE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect)); + std::string message; + ASSERT_TRUE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message)); } diff --git a/test/fuzztest/security_component/innerkits/reportsecuritycomponentclickevent_fuzzer/reportsecuritycomponentclickevent_fuzzer.cpp b/test/fuzztest/security_component/innerkits/reportsecuritycomponentclickevent_fuzzer/reportsecuritycomponentclickevent_fuzzer.cpp index 3507bc529b92c83f15fe1f383316583d47e5b678..c4ddf6389981590071dd53228277be31ad184fbe 100644 --- a/test/fuzztest/security_component/innerkits/reportsecuritycomponentclickevent_fuzzer/reportsecuritycomponentclickevent_fuzzer.cpp +++ b/test/fuzztest/security_component/innerkits/reportsecuritycomponentclickevent_fuzzer/reportsecuritycomponentclickevent_fuzzer.cpp @@ -44,7 +44,9 @@ static void ReportSecurityComponentClickEventFuzzTest(const uint8_t *data, size_ clickInfo.extraInfo.data = data1; clickInfo.extraInfo.dataSize = size; OnFirstUseDialogCloseFunc func = [] (int32_t) {}; - SecCompKit::ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, nullptr, std::move(func)); + SecCompInfo SecCompInfo{ scId, componentInfo, clickInfo }; + std::string message = generator.GenerateRandomCompoStr(generator.GetScType()); + SecCompKit::ReportSecurityComponentClickEvent(SecCompInfo, nullptr, std::move(func), message); } } // namespace OHOS