From 7ed7d70b72bebf5574c6bd20c65c7af4b012b4ac Mon Sep 17 00:00:00 2001 From: sunxuhui Date: Mon, 16 Dec 2024 10:22:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=8E=A7=E4=BB=B6=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=BF=A1=E6=81=AF=E5=A2=9E=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunxuhui --- .../include/i_sec_comp_service.h | 3 +- .../include/sec_comp_client.h | 3 +- .../include/sec_comp_proxy.h | 5 +- .../src/sec_comp_client.cpp | 7 +- .../security_component/src/sec_comp_kit.cpp | 9 +- .../security_component/src/sec_comp_proxy.cpp | 25 ++- .../test/unittest/src/sec_comp_kit_test.cpp | 12 +- .../src/sec_comp_register_callback_test.cpp | 53 +++--- .../security_component/include/sec_comp_err.h | 9 ++ .../security_component/include/sec_comp_kit.h | 3 +- .../sec_comp_info_helper.h | 8 +- .../sa/sa_main/first_use_dialog.cpp | 3 +- .../sa/sa_main/sec_comp_entity.cpp | 34 ++-- .../sa/sa_main/sec_comp_entity.h | 8 +- .../sa/sa_main/sec_comp_info_helper.cpp | 113 ++++++++----- .../sa/sa_main/sec_comp_manager.cpp | 47 ++++-- .../sa/sa_main/sec_comp_manager.h | 5 +- .../sa/sa_main/sec_comp_perm_manager.cpp | 9 +- .../sa/sa_main/sec_comp_perm_manager.h | 2 +- .../sa/sa_main/sec_comp_service.cpp | 6 +- .../sa/sa_main/sec_comp_service.h | 3 +- .../sa/sa_main/sec_comp_stub.cpp | 16 +- .../sa/sa_main/window_info_helper.cpp | 7 +- .../sa/sa_main/window_info_helper.h | 2 +- .../unittest/src/sec_comp_entity_test.cpp | 40 +++-- .../src/sec_comp_info_helper_test.cpp | 152 ++++++++++-------- .../unittest/src/sec_comp_manager_test.cpp | 11 +- .../src/sec_comp_perm_manager_test.cpp | 5 +- .../src/sec_comp_service_mock_test.cpp | 25 +-- .../unittest/src/sec_comp_service_test.cpp | 8 +- .../unittest/src/sec_comp_stub_mock_test.h | 2 +- .../sa/test/unittest/src/sec_comp_stub_test.h | 3 +- .../unittest/src/window_info_helper_test.cpp | 10 +- ...portsecuritycomponentclickevent_fuzzer.cpp | 3 +- 34 files changed, 428 insertions(+), 223 deletions(-) diff --git a/frameworks/inner_api/security_component/include/i_sec_comp_service.h b/frameworks/inner_api/security_component/include/i_sec_comp_service.h index 155604b..2af8955 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 @@ -35,7 +35,8 @@ public: 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; + const SecCompClickEvent& clickInfo, 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 563376e..0bcab6b 100644 --- a/frameworks/inner_api/security_component/include/sec_comp_client.h +++ b/frameworks/inner_api/security_component/include/sec_comp_client.h @@ -35,7 +35,8 @@ public: int32_t UnregisterSecurityComponent(int32_t scId); int32_t ReportSecurityComponentClickEvent(int32_t scId, const std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, sptr dialogCallback); + 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 bb637ea..df200d5 100644 --- a/frameworks/inner_api/security_component/include/sec_comp_proxy.h +++ b/frameworks/inner_api/security_component/include/sec_comp_proxy.h @@ -31,13 +31,14 @@ public: 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; + 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 26836a7..049c266 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_client.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_client.cpp @@ -91,15 +91,18 @@ int32_t SecCompClient::UnregisterSecurityComponent(int32_t scId) int32_t SecCompClient::ReportSecurityComponentClickEvent(int32_t scId, const std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, sptr dialogCallback) + sptr callerToken, sptr dialogCallback, + std::string& message) { auto proxy = GetProxy(true); if (proxy == nullptr) { SC_LOG_ERROR(LABEL, "Proxy is null"); + message = "Service is not available"; return SC_SERVICE_ERROR_VALUE_INVALID; } - return proxy->ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, callerToken, dialogCallback); + return proxy->ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, + 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 6df28a1..792bd0e 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_kit.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_kit.cpp @@ -103,7 +103,8 @@ int32_t SecCompKit::UnregisterSecurityComponent(int32_t scId) int32_t SecCompKit::ReportSecurityComponentClickEvent(int32_t scId, std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, OnFirstUseDialogCloseFunc&& callback) + sptr callerToken, OnFirstUseDialogCloseFunc&& callback, + std::string& message) { if (!SecCompCallerAuthorization::GetInstance().IsKitCaller( reinterpret_cast(__builtin_return_address(0)))) { @@ -115,28 +116,32 @@ int32_t SecCompKit::ReportSecurityComponentClickEvent(int32_t scId, HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "CALLER_CHECK_FAILED", HiviewDFX::HiSysEvent::EventType::SECURITY, "CALLER_UID", uid, "CALLER_BUNDLE_NAME", bundleName, "CALLER_PID", IPCSkeleton::GetCallingRealPid(), "CALL_SCENE", "CLICK"); + message = "report click event fail, caller invalid"; return SC_SERVICE_ERROR_CALLER_INVALID; } if (callback == nullptr) { SC_LOG_ERROR(LABEL, "DialogCloseCallback is null"); + message = "DialogCloseCallback is null"; return SC_ENHANCE_ERROR_VALUE_INVALID; } sptr callbackRemote = new (std::nothrow) SecCompDialogCallback(std::move(callback)); if (callbackRemote == nullptr) { SC_LOG_ERROR(LABEL, "New SecCompDialogCallback fail"); + message = "New SecCompDialogCallback fail"; return SC_SERVICE_ERROR_MEMORY_OPERATE_FAIL; } if (!SecCompEnhanceAdapter::EnhanceDataPreprocess(scId, componentInfo)) { SC_LOG_ERROR(LABEL, "Preprocess security component fail"); + message = "Preprocess security component fail"; return SC_ENHANCE_ERROR_VALUE_INVALID; } int32_t res = SecCompClient::GetInstance().ReportSecurityComponentClickEvent(scId, componentInfo, - clickInfo, callerToken, callbackRemote); + clickInfo, 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 f8eb802..76f5384 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; @@ -205,6 +205,7 @@ int32_t SecCompProxy::SendReportClickEventRequest(MessageParcel& data) sptr remote = Remote(); if (remote == nullptr) { SC_LOG_ERROR(LABEL, "Report remote service is null."); + message = "Report serialize session info failed."; return SC_SERVICE_ERROR_IPC_REQUEST_FAIL; } int32_t requestResult = remote->SendRequest( @@ -213,17 +214,26 @@ int32_t SecCompProxy::SendReportClickEventRequest(MessageParcel& data) if (!SecCompEnhanceAdapter::EnhanceClientDeserialize(reply, deserializedReply)) { SC_LOG_ERROR(LABEL, "Report deserialize session info failed."); + message = "Report serialize session info failed."; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (requestResult != SC_OK) { SC_LOG_ERROR(LABEL, "Report request failed, result: %{public}d.", requestResult); + message = "Report serialize session info failed."; return requestResult; } int32_t res; if (!deserializedReply.ReadInt32(res)) { SC_LOG_ERROR(LABEL, "Report read res failed."); + message = "Report read res failed."; + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + + if (!deserializedReply.ReadString(message)) { + SC_LOG_ERROR(LABEL, "Report read error message failed."); + message = "Report read error message failed."; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } return res; @@ -231,53 +241,62 @@ int32_t SecCompProxy::SendReportClickEventRequest(MessageParcel& data) int32_t SecCompProxy::ReportSecurityComponentClickEvent(int32_t scId, const std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, sptr dialogCallback) + sptr callerToken, sptr dialogCallback, + std::string& message) { std::lock_guard lock(useIPCMutex_); MessageParcel rawData; MessageParcel data; if (!data.WriteInterfaceToken(SecCompProxy::GetDescriptor())) { SC_LOG_ERROR(LABEL, "Report write descriptor failed."); + message = "Report serialize session info failed."; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!rawData.WriteInt32(scId)) { SC_LOG_ERROR(LABEL, "Report write scId failed."); + message = "Report serialize session info failed."; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!rawData.WriteString(componentInfo)) { SC_LOG_ERROR(LABEL, "Report write componentInfo failed."); + message = "Report serialize session info failed."; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } sptr parcel = new (std::nothrow) SecCompClickEventParcel(); if (parcel == nullptr) { SC_LOG_ERROR(LABEL, "Report new click event parcel failed."); + message = "Report serialize session info failed."; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } parcel->clickInfoParams_ = clickInfo; if (!rawData.WriteParcelable(parcel)) { SC_LOG_ERROR(LABEL, "Report write clickInfo failed."); + message = "Report serialize session info failed."; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if ((callerToken != nullptr) && !data.WriteRemoteObject(callerToken)) { SC_LOG_ERROR(LABEL, "Report write caller token failed."); + message = "Report serialize session info failed."; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if ((dialogCallback != nullptr) && !data.WriteRemoteObject(dialogCallback)) { SC_LOG_ERROR(LABEL, "Report write caller token failed."); + message = "Report serialize session info failed."; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (!SecCompEnhanceAdapter::EnhanceClientSerialize(rawData, data)) { SC_LOG_ERROR(LABEL, "Report serialize session info failed."); + message = "Report serialize session info failed."; 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 11edd4a..4895da8 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)); + std::string message = ""; + int reportRes = SecCompKit::ReportSecurityComponentClickEvent(scId, emptyStr, click, 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)); + std::string message = ""; + int reportRes = SecCompKit::ReportSecurityComponentClickEvent(scId, emptyStr, click, 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))); + std::string message = ""; + EXPECT_NE(SC_OK, SecCompKit::ReportSecurityComponentClickEvent(scId, jsonStr, touch, 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 4d19961..6b66c6d 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 @@ -61,11 +61,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) + const SecCompClickEvent& clickInfo, sptr callerToken, OnFirstUseDialogCloseFunc dialogCall, + std::string& message) { SC_LOG_INFO(LABEL, "ReportSecurityComponentClickEvent enter"); return SecCompKit::ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, callerToken, - std::move(dialogCall)); + std::move(dialogCall), message); } static __attribute__((noinline)) int32_t UpdateSecurityComponent(int32_t scId, std::string& componentInfo) @@ -220,8 +221,9 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent004, TestSize.Lev ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; - EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + std::string message = ""; + EXPECT_EQ(SC_SERVICE_ERROR_COMPONENT_IS_COVERED, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -255,8 +257,9 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent005, TestSize.Lev ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; - EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + std::string message = ""; + EXPECT_EQ(SC_SERVICE_ERROR_COMPONENT_IS_COVERED, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -307,8 +310,9 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent001, Test ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; - ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + std::string message = ""; + ASSERT_EQ(SC_SERVICE_ERROR_COMPONENT_IS_COVERED, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -346,8 +350,9 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent002, Test ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + std::string message = ""; ASSERT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func), message)); setuid(g_selfUid); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); @@ -381,12 +386,13 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent003, Test ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + 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(scId, saveInfo, clickInfo, token, std::move(func), message)); #else - ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ASSERT_EQ(SC_SERVICE_ERROR_COMPONENT_IS_COVERED, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func), message)); #endif EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } @@ -419,8 +425,9 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent004, Test ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = nullptr; + std::string message = ""; ASSERT_EQ(SC_ENHANCE_ERROR_VALUE_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } @@ -456,8 +463,9 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportClickWithoutHmac001, TestSize.Level1 ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; - EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo, token, std::move(func))); + std::string message = ""; + EXPECT_EQ(SC_SERVICE_ERROR_COMPONENT_IS_COVERED, + ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -493,8 +501,9 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission001, TestSize.Level1) ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; - ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + std::string message = ""; + ASSERT_EQ(SC_SERVICE_ERROR_COMPONENT_IS_COVERED, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func), message)); setuid(100); ASSERT_FALSE(SecCompKit::VerifySavePermission(TestCommon::HAP_TOKEN_ID)); // mediaLibraryTokenId_ != 0 @@ -533,8 +542,9 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission002, TestSize.Level1) ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; - ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + std::string message = ""; + ASSERT_EQ(SC_SERVICE_ERROR_COMPONENT_IS_COVERED, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -568,8 +578,9 @@ HWTEST_F(SecCompRegisterCallbackTest, UnregisterSecurityComponent001, TestSize.L ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; - EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + std::string message = ""; + EXPECT_EQ(SC_SERVICE_ERROR_COMPONENT_IS_COVERED, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, 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_err.h b/interfaces/inner_api/security_component/include/sec_comp_err.h index 160f430..dc5a369 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_err.h +++ b/interfaces/inner_api/security_component/include/sec_comp_err.h @@ -37,6 +37,15 @@ enum SCErrCode : int32_t { SC_SERVICE_ERROR_CALLER_INVALID = -62, SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE = -63, SC_SERVICE_ERROR_GRANT_CANCEL_FOR_DIALOG_CLOSE = -64, + SC_SERVICE_ERROR_COMPONENT_IS_COVERED = -65, + SC_SERVICE_ERROR_COMPONENT_DISPLAY_OUT = -66, + SC_SERVICE_ERROR_PARENT_COMPONENT_DISALLOWS_PROPERTY = -67, + SC_SERVICE_ERROR_SIZE_ANOMALY = -68, + SC_SERVICE_ERROR_TRANSPARENCE_ANOMALY = -69, + SC_SERVICE_ERROR_COLOR_SIMILARITY = -70, + SC_SERVICE_ERROR_COMPONENT_UNREGISTERED = -71, + SC_SERVICE_ERROR_COMPONENT_TEXT_OUT_OF_RANGE = -72, + SC_SERVICE_ERROR_PADDING_FAIL = -73, SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE = -100, SC_ENHANCE_ERROR_VALUE_INVALID = -101, 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 a264993..4f8e6ef 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_kit.h +++ b/interfaces/inner_api/security_component/include/sec_comp_kit.h @@ -32,7 +32,8 @@ public: static int32_t ReportSecurityComponentClickEvent(int32_t scId, std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken, - OnFirstUseDialogCloseFunc&& callback); + 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 f9b6a8c..c9be899 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,11 @@ 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 int32_t CheckComponentValid(SecCompBase* comp, std::string& message); + static int32_t 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/first_use_dialog.cpp b/services/security_component_service/sa/sa_main/first_use_dialog.cpp index 5d8ab5d..1a3b7d3 100644 --- a/services/security_component_service/sa/sa_main/first_use_dialog.cpp +++ b/services/security_component_service/sa/sa_main/first_use_dialog.cpp @@ -279,7 +279,8 @@ int32_t FirstUseDialog::GrantDialogWaitEntity(int32_t scId) SC_LOG_ERROR(LABEL, "Grant dialog wait security component %{public}d is nullptr", scId); return SC_SERVICE_ERROR_COMPONENT_NOT_EXIST; } - int32_t res = sc->GrantTempPermission(); + std::string message = ""; + int32_t res = sc->GrantTempPermission(message); if (res != SC_OK) { OHOS::AppExecFwk::BundleMgrClient bmsClient; std::string bundleName = ""; 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 30a7caa..933876a 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 @@ -46,10 +46,10 @@ constexpr const char *QUERY_KEYWORD = "accessibility_screenreader_enabled"; static bool IsScreenReadMode(); } -int32_t SecCompEntity::GrantTempPermission() +int32_t SecCompEntity::GrantTempPermission(std::string& message) { isGrant_ = true; - return SecCompPermManager::GetInstance().GrantTempPermission(tokenId_, componentInfo_); + return SecCompPermManager::GetInstance().GrantTempPermission(tokenId_, componentInfo_, message); } bool SecCompEntity::CompareComponentBasicInfo(SecCompBase* other, bool isRectCheck) const @@ -57,13 +57,16 @@ bool SecCompEntity::CompareComponentBasicInfo(SecCompBase* other, bool isRectChe return componentInfo_->CompareComponentBasicInfo(other, isRectCheck); } -int32_t SecCompEntity::CheckPointEvent(const SecCompClickEvent& clickInfo) const +int32_t SecCompEntity::CheckPointEvent(const SecCompClickEvent& clickInfo, std::string& message) const { auto current = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TIME_CONVERSION_UNIT; if (clickInfo.point.timestamp < current - MAX_TOUCH_INTERVAL || clickInfo.point.timestamp > current) { SC_LOG_ERROR(LABEL, "touch timestamp invalid clickInfo. timestamp: %{public}llu, current: %{public}llu", static_cast(clickInfo.point.timestamp), static_cast(current)); + message = ", touch timestamp invalid clickInfo. timestamp: " + + std::to_string(clickInfo.point.timestamp) + ", " + + "current: " + std::to_string(current); return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } @@ -74,46 +77,57 @@ int32_t SecCompEntity::CheckPointEvent(const SecCompClickEvent& clickInfo) const clickInfo.point.touchX, clickInfo.point.touchY, componentInfo_->rect_.x_, componentInfo_->rect_.y_, componentInfo_->rect_.x_ + componentInfo_->rect_.width_, componentInfo_->rect_.y_ + componentInfo_->rect_.height_); + message = ", touch point is not in component rect = ( " + + std::to_string(clickInfo.point.touchX) + ", " + + std::to_string(clickInfo.point.touchY) + ", " + + std::to_string(componentInfo_->rect_.x_) + ", " + + std::to_string(componentInfo_->rect_.y_) + ", " + + std::to_string(componentInfo_->rect_.x_ + componentInfo_->rect_.width_) + + ", " + std::to_string(componentInfo_->rect_.y_ + componentInfo_->rect_.height_) + ")"; return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } return SC_OK; } -int32_t SecCompEntity::CheckKeyEvent(const SecCompClickEvent& clickInfo) const +int32_t SecCompEntity::CheckKeyEvent(const SecCompClickEvent& clickInfo, std::string& message) const { auto current = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TIME_CONVERSION_UNIT; if (clickInfo.key.timestamp < current - MAX_TOUCH_INTERVAL || clickInfo.key.timestamp > current) { SC_LOG_ERROR(LABEL, "keyboard timestamp invalid clickInfo. timestamp: %{public}llu, current: %{public}llu", static_cast(clickInfo.key.timestamp), static_cast(current)); + message = ", keyboard timestamp invalid clickInfo. timestamp: " + + std::to_string(clickInfo.key.timestamp) + + "current: " + std::to_string(current); return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } if ((clickInfo.key.keyCode != KEY_SPACE) && (clickInfo.key.keyCode != KEY_ENTER) && (clickInfo.key.keyCode != KEY_NUMPAD_ENTER)) { SC_LOG_ERROR(LABEL, "keyboard keyCode invalid. keyCode: %{public}d", clickInfo.key.keyCode); + message = ", keyboard keyCode invalid. keyCode: " + std::to_string(clickInfo.key.keyCode); return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } 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; + return SC_SERVICE_ERROR_COMPONENT_IS_COVERED; } int32_t res = SC_SERVICE_ERROR_CLICK_EVENT_INVALID; bool isScreenReadMode = IsScreenReadMode(); if (clickInfo.type == ClickEventType::POINT_EVENT_TYPE && !isScreenReadMode) { - res = CheckPointEvent(clickInfo); + res = CheckPointEvent(clickInfo, message); } else if (clickInfo.type == ClickEventType::POINT_EVENT_TYPE && isScreenReadMode) { SC_LOG_WARN(LABEL, "Device is in screen read mode, skip event check."); return SC_OK; } else if (clickInfo.type == ClickEventType::KEY_EVENT_TYPE) { - res = CheckKeyEvent(clickInfo); + res = CheckKeyEvent(clickInfo, message); } if (res != SC_OK) { return res; @@ -122,6 +136,7 @@ int32_t SecCompEntity::CheckClickInfo(const SecCompClickEvent& clickInfo) const res = SecCompEnhanceAdapter::CheckExtraInfo(clickInfo); if (res == SC_SERVICE_ERROR_CLICK_EVENT_INVALID) { SC_LOG_ERROR(LABEL, "Click ExtraInfo is invalid"); + message = ", Click ExtraInfo is invalid"; return res; } @@ -134,6 +149,7 @@ int32_t SecCompEntity::CheckClickInfo(const SecCompClickEvent& clickInfo) const HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "CLICK_INFO_CHECK_FAILED", HiviewDFX::HiSysEvent::EventType::SECURITY, "CALLER_UID", uid, "CALLER_BUNDLE_NAME", bundleName, "CALLER_PID", IPCSkeleton::GetCallingPid(), "SC_ID", scId_, "SC_TYPE", componentInfo_->type_); + message = ", HMAC checkout failed"; return SC_ENHANCE_ERROR_CLICK_EXTRA_CHECK_FAIL; } return SC_OK; 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 2bc4d64..33d3150 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 @@ -31,7 +31,7 @@ public: : componentInfo_(component), tokenId_(token), scId_(scId), pid_(pid), uid_(uid) {}; ~SecCompEntity() = default; int32_t RevokeTempPermission(); - int32_t GrantTempPermission(); + int32_t GrantTempPermission(std::string& message); SecCompType GetType() const { if (componentInfo_ == nullptr) { @@ -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_; @@ -55,8 +55,8 @@ public: int32_t uid_; private: - int32_t CheckKeyEvent(const SecCompClickEvent& clickInfo) const; - int32_t CheckPointEvent(const SecCompClickEvent& clickInfo) const; + int32_t CheckKeyEvent(const SecCompClickEvent& clickInfo, std::string& message) const; + int32_t CheckPointEvent(const SecCompClickEvent& clickInfo, std::string& message) const; bool isGrant_ = false; }; } // namespace SecurityComponent 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 a92c0d8..ab09e66 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 @@ -46,7 +46,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 +69,7 @@ SecCompBase* SecCompInfoHelper::ParseComponent(SecCompType type, const nlohmann: return comp; } - comp->SetValid(CheckComponentValid(comp)); + comp->SetValid(CheckComponentValid(comp, message) == SC_OK); return comp; } @@ -94,54 +95,62 @@ static bool GetScreenSize(double& width, double& height, const uint64_t displayI return true; } -bool SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, - const uint64_t displayId) +int32_t SecCompInfoHelper::CheckRectValid(const SecCompRect& rect, const SecCompRect& windowRect, + const uint64_t displayId, std::string& message) { double curScreenWidth = 0.0F; double curScreenHeight = 0.0F; if (!GetScreenSize(curScreenWidth, curScreenHeight, displayId)) { SC_LOG_ERROR(LABEL, "Get screen size is invalid"); - return false; + message = ", Get screen size is invalid"; + return SC_SERVICE_ERROR_COMPONENT_INFO_INVALID; } if (GreatOrEqual(0.0, rect.width_) || GreatOrEqual(0.0, rect.height_)) { SC_LOG_ERROR(LABEL, "width or height is <= 0"); - return false; + message = ", width or height is <= 0"; + return SC_SERVICE_ERROR_COMPONENT_INFO_INVALID; } 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"); - return false; + message = ", security component is out of screen"; + return SC_SERVICE_ERROR_COMPONENT_DISPLAY_OUT; } if (GreatOrEqual((rect.x_ + rect.width_), curScreenWidth) || GreatOrEqual((rect.y_ + rect.height_), curScreenHeight)) { SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: security component is out of screen"); - return false; + message = ", security component is out of screen"; + return SC_SERVICE_ERROR_COMPONENT_DISPLAY_OUT; } if (GreatNotEqual(windowRect.x_, rect.x_) || GreatNotEqual(windowRect.y_, rect.y_) || 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"); - return false; + message = ", security component is out of window"; + return SC_SERVICE_ERROR_COMPONENT_DISPLAY_OUT; } // 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"); - return false; + message = ", security component is larger than 10 percent of screen"; + return SC_SERVICE_ERROR_COMPONENT_DISPLAY_OUT; } SC_LOG_DEBUG(LABEL, "check component rect success."); - return true; + return SC_OK; } -static bool CheckSecCompBaseButton(const SecCompBase* comp) +static int32_t 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."); - return false; + message = "scId = " + std::to_string(comp->nodeId_) + + ", scType = " + std::to_string(comp->type_) + ", both text and icon do not exist."; + return SC_SERVICE_ERROR_COMPONENT_INFO_INVALID; } if (comp->text_ >= 0) { DimensionT minFontSize; @@ -153,62 +162,92 @@ static bool CheckSecCompBaseButton(const SecCompBase* comp) if (comp->fontSize_ < minFontSize) { SC_LOG_INFO(LABEL, "SecurityComponentCheckFail: fontSize is too small."); - return false; + message = "scId = " + std::to_string(comp->nodeId_) + + ", scType = " + std::to_string(comp->type_) + ", fontSize is too small"; + return SC_SERVICE_ERROR_SIZE_ANOMALY; } } if ((comp->icon_ >= 0) && comp->iconSize_ < MIN_ICON_SIZE) { SC_LOG_INFO(LABEL, "SecurityComponentCheckFail: iconSize is too small."); - return false; + message = "scId = " + std::to_string(comp->nodeId_) + + ", scType = " + std::to_string(comp->type_) + ", iconSize is too small"; + return SC_SERVICE_ERROR_SIZE_ANOMALY; } 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; + (comp->icon_ != NO_TEXT) && IsColorSimilar(comp->iconColor_, comp->bgColor_)) { + SC_LOG_INFO(LABEL, "SecurityComponentCheckFail: iconColor is similar with backgroundColor."); + message = "scId = " + std::to_string(comp->nodeId_) + + ", scType = " + std::to_string(comp->type_) + ", iconColor is similar with backgroundColor"; + return SC_SERVICE_ERROR_COLOR_SIMILARITY; + } + + 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 = "scId = " + std::to_string(comp->nodeId_) + + ", scType = " + std::to_string(comp->type_) + ", fontColor is similar with backgroundColor"; + return SC_SERVICE_ERROR_COLOR_SIMILARITY; } 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; + message = "scId = " + std::to_string(comp->nodeId_) + + ", scType = " + std::to_string(comp->type_) + ", padding can not change without background"; + return SC_SERVICE_ERROR_PADDING_FAIL; } - return true; + return SC_OK; } -static bool CheckSecCompBase(const SecCompBase* comp) +static int32_t CheckSecCompBase(const SecCompBase* comp, std::string& message) { if (comp->parentEffect_) { SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: the parents of security component have invalid effect."); - return false; + return SC_SERVICE_ERROR_PARENT_COMPONENT_DISALLOWS_PROPERTY; } 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."); - return false; + message = "scId = " + std::to_string(comp->nodeId_) + + ", scType = " + std::to_string(comp->type_) + ", padding or textIconSpace is too small"; + return SC_SERVICE_ERROR_SIZE_ANOMALY; } - 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."); - return false; + if ((comp->text_ != NO_TEXT) && (IsColorTransparent(comp->fontColor_))) { + SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: fontColor is too transparent."); + message = "scId = " + std::to_string(comp->nodeId_) + + ", scType = " + std::to_string(comp->type_) + ", fontColor is too transparent"; + return SC_SERVICE_ERROR_TRANSPARENCE_ANOMALY; } - if (!CheckSecCompBaseButton(comp)) { - return false; + + if ((comp->icon_ != NO_ICON) && (IsColorTransparent(comp->iconColor_))) { + SC_LOG_ERROR(LABEL, "SecurityComponentCheckFail: iconColor is too transparent."); + message = "scId = " + std::to_string(comp->nodeId_) + + ", scType = " + std::to_string(comp->type_) + ", iconColor is too transparent"; + return SC_SERVICE_ERROR_TRANSPARENCE_ANOMALY; } - return true; + + int32_t res = CheckSecCompBaseButton(comp, message); + if (res != SC_OK) { + SC_LOG_INFO(LABEL, "SecComp base is invalid."); + return res; + } + return SC_OK; } -bool SecCompInfoHelper::CheckComponentValid(SecCompBase* comp) +int32_t SecCompInfoHelper::CheckComponentValid(SecCompBase* comp, std::string& message) { if ((comp == nullptr) || !IsComponentTypeValid(comp->type_)) { SC_LOG_INFO(LABEL, "comp is null or type is invalid."); - return false; + message = "scId = " + std::to_string(comp->nodeId_) + + ", scType = " + std::to_string(comp->type_) + ", comp is null or type is invalid"; + return SC_SERVICE_ERROR_COMPONENT_INFO_INVALID; } float scale = WindowInfoHelper::GetWindowScale(comp->windowId_); @@ -217,12 +256,12 @@ bool SecCompInfoHelper::CheckComponentValid(SecCompBase* comp) AdjustSecCompRect(comp, scale); } - if (!CheckSecCompBase(comp)) { + int32_t res = CheckSecCompBase(comp, message); + if (res != SC_OK) { SC_LOG_INFO(LABEL, "SecComp base is invalid."); - return false; + return res; } - - return true; + return SC_OK; } } // namespace SecurityComponent } // namespace Security 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 bda0d42..b7ee59f 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 @@ -354,7 +354,8 @@ int32_t SecCompManager::RegisterSecurityComponent(SecCompType type, return SC_ENHANCE_ERROR_IN_MALICIOUS_LIST; } - SecCompBase* componentPtr = SecCompInfoHelper::ParseComponent(type, jsonComponent); + std::string messagee = ""; + SecCompBase* componentPtr = SecCompInfoHelper::ParseComponent(type, jsonComponent, messagee); std::shared_ptr component(componentPtr); if (component == nullptr) { SC_LOG_ERROR(LABEL, "Parse component info invalid"); @@ -405,7 +406,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 messagee = ""; + SecCompBase* report = SecCompInfoHelper::ParseComponent(sc->GetType(), jsonComponent, messagee); std::shared_ptr reportComponentInfo(report); if (reportComponentInfo == nullptr) { SC_LOG_ERROR(LABEL, "Update component info invalid"); @@ -444,10 +446,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; @@ -459,6 +461,13 @@ int32_t SecCompManager::CheckClickSecurityComponentInfo(std::shared_ptrGetType()); + if (!reportComponentInfo->GetValid()) { + int32_t res = SecCompInfoHelper::CheckComponentValid(report, message); + if (res != SC_OK) { + return res; + } + } + message = "ComponentInfo is null"; return SC_SERVICE_ERROR_COMPONENT_INFO_INVALID; } if (report && (report->isClipped_)) { @@ -467,14 +476,18 @@ int32_t SecCompManager::CheckClickSecurityComponentInfo(std::shared_ptrrect_, reportComponentInfo->windowRect_, - report->displayId_))) { + int32_t res = SecCompInfoHelper::CheckRectValid(reportComponentInfo->rect_, reportComponentInfo->windowRect_, + report->displayId_, message); + if (res != SC_OK) { 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, "CALLER_PID", IPCSkeleton::GetCallingPid(), "SC_ID", scId, "CALL_SCENE", "CLICK", "SC_TYPE", sc->GetType()); - return SC_SERVICE_ERROR_COMPONENT_INFO_INVALID; + message = "security component id = " + + std::to_string(sc->componentInfo_->nodeId_) + + ", scType = " + std::to_string(sc->GetType()) + message; + return res; } int32_t enhanceRes = SecCompEnhanceAdapter::CheckComponentInfoEnhance(caller.pid, reportComponentInfo, jsonComponent); @@ -503,9 +516,11 @@ static void ReportEvent(std::string eventName, HiviewDFX::HiSysEvent::EventType int32_t SecCompManager::ReportSecurityComponentClickEvent(int32_t scId, const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller, - const SecCompClickEvent& clickInfo, const std::vector>& remote) + const SecCompClickEvent& clickInfo, const std::vector>& remote, + std::string& message) { if (remote.size() < REPORT_REMOTE_OBJECT_SIZE) { + message = "remote object size is invalid"; return SC_SERVICE_ERROR_VALUE_INVALID; } auto callerToken = remote[0]; @@ -513,6 +528,7 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(int32_t scId, if (malicious_.IsInMaliciousAppList(caller.pid, caller.uid)) { SC_LOG_ERROR(LABEL, "app is in MaliciousAppList, never allow it"); + message = "app is in MaliciousAppList, never allow it"; return SC_ENHANCE_ERROR_IN_MALICIOUS_LIST; } @@ -520,33 +536,36 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(int32_t scId, std::shared_ptr sc = GetSecurityComponentFromList(caller.pid, scId); if (sc == nullptr) { SC_LOG_ERROR(LABEL, "Can not find target component"); + message = "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, scId, jsonComponent, caller, message); if (res != SC_OK) { return res; } - res = sc->CheckClickInfo(clickInfo); + res = sc->CheckClickInfo(clickInfo, message); if (res != SC_OK) { ReportEvent("CLICK_INFO_CHECK_FAILED", HiviewDFX::HiSysEvent::EventType::SECURITY, scId, sc->GetType()); if (res == SC_ENHANCE_ERROR_CLICK_EXTRA_CHECK_FAIL) { malicious_.AddAppToMaliciousAppList(caller.pid); } - - return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; + message = "scId = " + std::to_string(scId) + + ", scType = " + std::to_string(sc->GetType()) + message; + return res; } - 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."); + message = "start dialog, onclick will be trap after dialog closed."; return SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE; } - res = sc->GrantTempPermission(); + res = sc->GrantTempPermission(message); if (res != SC_OK) { ReportEvent("TEMP_GRANT_FAILED", HiviewDFX::HiSysEvent::EventType::FAULT, scId, sc->GetType()); 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 04d85e4..faccc72 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 @@ -59,7 +59,8 @@ public: 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); + const std::vector>& remote, + std::string& message); void NotifyProcessForeground(int32_t pid); void NotifyProcessBackground(int32_t pid); void NotifyProcessDied(int32_t pid); @@ -78,7 +79,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_perm_manager.cpp b/services/security_component_service/sa/sa_main/sec_comp_perm_manager.cpp index 9fd40aa..48783d7 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_perm_manager.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_perm_manager.cpp @@ -276,10 +276,11 @@ inline bool IsDlpSandboxCalling(AccessToken::AccessTokenID tokenId) } int32_t SecCompPermManager::GrantTempPermission(AccessToken::AccessTokenID tokenId, - const std::shared_ptr& componentInfo) + const std::shared_ptr& componentInfo, std::string& message) { if ((tokenId <= 0) || (componentInfo == nullptr)) { SC_LOG_ERROR(LABEL, "Grant component is null"); + message = "Grant component is null"; return SC_SERVICE_ERROR_PERMISSION_OPER_FAIL; } @@ -290,11 +291,13 @@ int32_t SecCompPermManager::GrantTempPermission(AccessToken::AccessTokenID token { res = GrantAppPermission(tokenId, "ohos.permission.APPROXIMATELY_LOCATION"); if (res != SC_OK) { + message = "Grant location permission fail, scId = " + std::to_string(componentInfo->nodeId_); return SC_SERVICE_ERROR_PERMISSION_OPER_FAIL; } res = GrantAppPermission(tokenId, "ohos.permission.LOCATION"); if (res != SC_OK) { RevokeAppPermission(tokenId, "ohos.permission.APPROXIMATELY_LOCATION"); + message = "Grant location permission fail, scId = " + std::to_string(componentInfo->nodeId_); return SC_SERVICE_ERROR_PERMISSION_OPER_FAIL; } SC_LOG_INFO(LABEL, "Grant location permission, scid = %{public}d.", componentInfo->nodeId_); @@ -303,6 +306,7 @@ int32_t SecCompPermManager::GrantTempPermission(AccessToken::AccessTokenID token case PASTE_COMPONENT: res = GrantAppPermission(tokenId, "ohos.permission.SECURE_PASTE"); if (res != SC_OK) { + message = "Grant paste permission fail, scId = " + std::to_string(componentInfo->nodeId_); return SC_SERVICE_ERROR_PERMISSION_OPER_FAIL; } SC_LOG_INFO(LABEL, "Grant paste permission, scid = %{public}d.", componentInfo->nodeId_); @@ -310,12 +314,15 @@ int32_t SecCompPermManager::GrantTempPermission(AccessToken::AccessTokenID token case SAVE_COMPONENT: if (IsDlpSandboxCalling(tokenId)) { SC_LOG_INFO(LABEL, "Dlp sandbox app are not allowed to use save component."); + message = "Dlp sandbox app are not allowed to use save component, scId = " + + std::to_string(componentInfo->nodeId_); return SC_SERVICE_ERROR_PERMISSION_OPER_FAIL; } SC_LOG_INFO(LABEL, "Grant save permission, scid = %{public}d.", componentInfo->nodeId_); return GrantTempSavePermission(tokenId); default: SC_LOG_ERROR(LABEL, "Parse component type unknown"); + message = "Parse component type unknown"; break; } return SC_SERVICE_ERROR_PERMISSION_OPER_FAIL; diff --git a/services/security_component_service/sa/sa_main/sec_comp_perm_manager.h b/services/security_component_service/sa/sa_main/sec_comp_perm_manager.h index aaa2817..37088a9 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_perm_manager.h +++ b/services/security_component_service/sa/sa_main/sec_comp_perm_manager.h @@ -33,7 +33,7 @@ public: static SecCompPermManager& GetInstance(); int32_t GrantTempPermission(AccessToken::AccessTokenID tokenId, - const std::shared_ptr& componentInfo); + const std::shared_ptr& componentInfo, std::string& message); int32_t GrantTempSavePermission(AccessToken::AccessTokenID tokenId); void RevokeTempSavePermission(AccessToken::AccessTokenID tokenId); bool VerifySavePermission(AccessToken::AccessTokenID tokenId); 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 5f35b29..2bd83a8 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 @@ -246,19 +246,21 @@ int32_t SecCompService::UnregisterSecurityComponent(int32_t scId) int32_t SecCompService::ReportSecurityComponentClickEvent(int32_t scId, const std::string& componentInfo, const SecCompClickEvent& clickInfo, - sptr callerToken, sptr dialogCallback) + 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) { FinishTrace(HITRACE_TAG_ACCESS_CONTROL); + message = "component info invalid"; return SC_SERVICE_ERROR_VALUE_INVALID; } std::vector> remoteArr = { callerToken, dialogCallback }; int32_t res = SecCompManager::GetInstance().ReportSecurityComponentClickEvent(scId, jsonRes, caller, clickInfo, - remoteArr); + 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 ff95582..5c01422 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 @@ -45,7 +45,8 @@ public: 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; + 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 b50d932..f62be57 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 @@ -169,52 +169,66 @@ int32_t SecCompStub::UnregisterSecurityComponentInner(MessageParcel& data, Messa int32_t SecCompStub::ReportSecurityComponentClickEventInner(MessageParcel& data, MessageParcel& reply) { + std::string message = ""; sptr callerToken = data.ReadRemoteObject(); if (callerToken == nullptr) { SC_LOG_ERROR(LABEL, "callerToken is nullptr"); + message = "callerToken is nullptr"; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } sptr dialogCallback = data.ReadRemoteObject(); if (dialogCallback == nullptr) { SC_LOG_ERROR(LABEL, "dialogCallback is nullptr"); + message = "dialogCallback is nullptr"; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } MessageParcel deserializedData; if (!SecCompEnhanceAdapter::EnhanceSrvDeserialize(data, deserializedData, reply)) { SC_LOG_ERROR(LABEL, "Report deserialize session info failed"); + message = "Report deserialize session info failed"; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } int32_t scId; if (!deserializedData.ReadInt32(scId)) { SC_LOG_ERROR(LABEL, "Report read component id failed"); + message = "Report read component id failed"; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } if (scId < 0) { SC_LOG_ERROR(LABEL, "Report security component id invalid"); + message = "Report security component id invalid"; return SC_SERVICE_ERROR_VALUE_INVALID; } std::string componentInfo; if (!deserializedData.ReadString(componentInfo)) { SC_LOG_ERROR(LABEL, "Report read component info failed"); + message = "Report read component info failed"; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } sptr clickInfoParcel = deserializedData.ReadParcelable(); if (clickInfoParcel == nullptr) { SC_LOG_ERROR(LABEL, "Report read clickInfo info failed"); + message = "Report read clickInfo info failed"; return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } int32_t res = this->ReportSecurityComponentClickEvent(scId, componentInfo, clickInfoParcel->clickInfoParams_, - callerToken, dialogCallback); + callerToken, dialogCallback, message); MessageParcel rawReply; if (!rawReply.WriteInt32(res)) { SC_LOG_ERROR(LABEL, "Report security component result failed"); + message = "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; } 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 4af328b..2cb02da 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 @@ -63,7 +63,7 @@ static bool IsRectInWindRect(const Rosen::Rect& windRect, const SecCompRect& sec return true; } -bool WindowInfoHelper::CheckOtherWindowCoverComp(int32_t compWinId, const SecCompRect& secRect) +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"); @@ -72,6 +72,7 @@ bool WindowInfoHelper::CheckOtherWindowCoverComp(int32_t compWinId, const SecCom std::vector> infos; if (Rosen::WindowManager::GetInstance().GetUnreliableWindowInfo(compWinId, infos) != Rosen::WMError::WM_OK) { SC_LOG_ERROR(LABEL, "Get AccessibilityWindowInfo failed"); + message = ", Get AccessibilityWindowInfo failed"; return false; } @@ -98,6 +99,7 @@ bool WindowInfoHelper::CheckOtherWindowCoverComp(int32_t compWinId, const SecCom if (compLayer == INVALID_WINDOW_LAYER) { SC_LOG_ERROR(LABEL, "windId %{public}d component layer is wrong", compWinId); + message = ", windId " + std::to_string(compWinId) + "component layer is wrong"; return false; } @@ -112,6 +114,9 @@ bool WindowInfoHelper::CheckOtherWindowCoverComp(int32_t compWinId, const SecCom if (iter != layerList.end()) { SC_LOG_ERROR(LABEL, "component window %{public}d is covered by %{public}d, click check failed", compWinId, iter->first); + message = ", component window " + std::to_string(compWinId) + + " is covered by " + std::to_string(iter->first) + + ", click check failed"; return false; } return true; 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 a831bc1..f1c0885 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 b73a85c..fcd0df7 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 @@ -71,17 +71,18 @@ HWTEST_F(SecCompEntityTest, GrantTempPermission001, TestSize.Level1) { entity_->isGrant_ = false; entity_->componentInfo_->type_ = UNKNOWN_SC_TYPE; - ASSERT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL, entity_->GrantTempPermission()); + std::string message = ""; + ASSERT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL, entity_->GrantTempPermission(message)); ASSERT_TRUE(entity_->isGrant_); entity_->isGrant_ = false; entity_->componentInfo_->type_ = LOCATION_COMPONENT; - ASSERT_EQ(SC_OK, entity_->GrantTempPermission()); + ASSERT_EQ(SC_OK, entity_->GrantTempPermission(message)); ASSERT_TRUE(entity_->isGrant_); entity_->isGrant_ = false; entity_->componentInfo_->type_ = PASTE_COMPONENT; - ASSERT_EQ(SC_OK, entity_->GrantTempPermission()); + ASSERT_EQ(SC_OK, entity_->GrantTempPermission(message)); ASSERT_TRUE(entity_->isGrant_); } @@ -94,12 +95,13 @@ HWTEST_F(SecCompEntityTest, GrantTempPermission001, TestSize.Level1) HWTEST_F(SecCompEntityTest, GrantTempPermission002, TestSize.Level1) { std::shared_ptr pasteComponent = std::make_shared(); + std::string message = ""; ASSERT_NE(nullptr, pasteComponent); entity_ = std::make_shared(pasteComponent, 0, 1, 1, 1); ASSERT_NE(nullptr, entity_); - ASSERT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL, entity_->GrantTempPermission()); + ASSERT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL, entity_->GrantTempPermission(message)); } /** @@ -116,11 +118,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 +131,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 +140,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 +157,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 +167,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_COMPONENT_IS_COVERED); } /** @@ -176,7 +180,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,19 +199,20 @@ 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)); + ASSERT_EQ(SC_OK, entity_->CheckKeyEvent(clickInfo, message)); clickInfo.key.keyCode = KEY_ENTER; - ASSERT_EQ(SC_OK, entity_->CheckKeyEvent(clickInfo)); + ASSERT_EQ(SC_OK, entity_->CheckKeyEvent(clickInfo, message)); clickInfo.key.keyCode = KEY_NUMPAD_ENTER; - ASSERT_EQ(SC_OK, entity_->CheckKeyEvent(clickInfo)); + ASSERT_EQ(SC_OK, entity_->CheckKeyEvent(clickInfo, message)); } 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 25e66cf..e4739d5 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)); } /** @@ -119,12 +121,13 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent003, 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_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) == SC_OK); rect.x_ = ServiceTestCommon::TEST_INVALID_DIMENSION; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message) == SC_OK); 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) == SC_OK); rect.y_ = g_testHeight; rect.x_ = g_curScreenWidth + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message) == SC_OK); rect.x_ = g_testWidth; rect.y_ = g_curScreenHeight + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message) == SC_OK); 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) == SC_OK); 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) == SC_OK); 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) == SC_OK); 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) == SC_OK); windowRect.x_ = g_testWidth + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message) == SC_OK); windowRect.x_ = g_testWidth; windowRect.y_ = g_testHeight + 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message) == SC_OK); windowRect.y_ = g_testHeight; windowRect.width_ = g_testWidth - 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message) == SC_OK); windowRect.width_ = g_testWidth; windowRect.height_ = g_testHeight - 1; - ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0)); + ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, 0, message) == SC_OK); 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) == SC_OK); 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) == SC_OK); 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()); } @@ -442,7 +455,8 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent014, 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]; @@ -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) == SC_OK); 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) == SC_OK); } /** @@ -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) == SC_OK); comp->text_ = static_cast(LocationDesc::SELECT_LOCATION); comp->icon_ = UNKNOWN_ICON; - ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp)); + ASSERT_TRUE(SecCompInfoHelper::CheckComponentValid(comp, message) == SC_OK); comp->text_ = UNKNOWN_TEXT; - ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp)); + ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp, message) == SC_OK); } /** @@ -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) == SC_OK); comp->type_ = SecCompType::MAX_SC_TYPE; - ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp)); + ASSERT_FALSE(SecCompInfoHelper::CheckComponentValid(comp, message) == SC_OK); } /** @@ -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) == SC_OK); } /** @@ -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) == SC_OK); } /** 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 ed7144a..88c3eef 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,10 @@ HWTEST_F(SecCompManagerTest, ReportSecurityComponentClickEvent001, TestSize.Leve LocationButton buttonValid = BuildValidLocationComponent(); buttonValid.ToJson(jsonVaild); std::vector> remote = { nullptr, nullptr }; + std::string message = ""; ASSERT_NE(SC_OK, SecCompManager::GetInstance().ReportSecurityComponentClickEvent(1, - jsonVaild, caller, clickInfo, remote)); + jsonVaild, caller, clickInfo, remote, message)); } /** @@ -486,17 +487,19 @@ HWTEST_F(SecCompManagerTest, CheckClickSecurityComponentInfo001, TestSize.Level1 buttonValid.ToJson(jsonVaild); jsonVaild[JsonTagConstants::JSON_SC_TYPE] = UNKNOWN_SC_TYPE; std::vector> remote = { nullptr, nullptr }; + SC_LOG_INFO(LABEL, "setup"); + std::string message = "test"; ASSERT_EQ(SC_SERVICE_ERROR_COMPONENT_INFO_INVALID, SecCompManager::GetInstance().ReportSecurityComponentClickEvent( - ServiceTestCommon::TEST_SC_ID_1, jsonVaild, caller, clickInfo, remote)); + ServiceTestCommon::TEST_SC_ID_1, jsonVaild, caller, clickInfo, 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)); + ServiceTestCommon::TEST_SC_ID_1, jsonVaild, caller, clickInfo, 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)); + ServiceTestCommon::TEST_SC_ID_1, jsonVaild, caller, clickInfo, 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 4111522..627fa87 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,10 +192,11 @@ 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); EXPECT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL, - permMgr.GrantTempPermission(*tokenid, shared_comp)); + permMgr.GrantTempPermission(*tokenid, shared_comp, message)); } \ No newline at end of file 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 4e5454f..0cc4887 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 }, }; - + std::string message = ""; EXPECT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, - saveInfo, touch, nullptr, nullptr)); + saveInfo, touch, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); SecCompPermManager::GetInstance().applySaveCountMap_.clear(); } @@ -149,8 +149,9 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent002, TestSize.Level1) .point.timestamp = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) }; + std::string message = ""; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr, nullptr)); + secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); SecCompPermManager::GetInstance().applySaveCountMap_.clear(); } @@ -190,8 +191,9 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent003, TestSize.Level1) .dataSize = 1 }, }; + std::string message = ""; EXPECT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL, - secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr, nullptr)); + secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); SecCompPermManager::GetInstance().applySaveCountMap_.clear(); } @@ -231,8 +233,9 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent001, TestSize. .dataSize = 1 }, }; - - ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, nullptr, nullptr)); + std::string message = ""; + ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, + nullptr, nullptr, message)); // test 10s valid ASSERT_TRUE(secCompService_->VerifySavePermission(ServiceTestCommon::HAP_TOKEN_ID)); @@ -243,11 +246,13 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent001, TestSize. // test 10s multiple clicks 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(scId, saveInfo, clickInfo, + nullptr, nullptr, message)); sleep(3); 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(scId, saveInfo, clickInfo, + nullptr, nullptr, message)); sleep(8); ASSERT_TRUE(secCompService_->VerifySavePermission(ServiceTestCommon::HAP_TOKEN_ID)); sleep(2); @@ -290,9 +295,9 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent002, TestSize. .dataSize = 1 }, }; - + std::string message = ""; ASSERT_EQ(SC_OK, - secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo1, nullptr, nullptr)); + secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo1, 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 de46e83..43cca78 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,9 @@ HWTEST_F(SecCompServiceTest, ReportSecurityComponentClickEvent001, TestSize.Leve .extraInfo.data = data, .extraInfo.dataSize = 16, }; + std::string message = ""; EXPECT_EQ(SC_OK, - secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, touch, nullptr, nullptr)); + secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, touch, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); setuid(uid); } @@ -363,7 +364,8 @@ 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), - SC_SERVICE_ERROR_VALUE_INVALID); + std::string message = ""; + EXPECT_EQ(secCompService_->ReportSecurityComponentClickEvent(scId, componentInfo, touchInfo, + 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 022d533..6e0dbd0 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 @@ -45,7 +45,7 @@ public: int32_t ReportSecurityComponentClickEvent(int32_t scId, const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken, - sptr dialogCall) override + 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 2c2c1c3..ab4677c 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 @@ -44,7 +44,8 @@ public: }; int32_t ReportSecurityComponentClickEvent(int32_t scId, const std::string& componentInfo, - const SecCompClickEvent& clickInfo, sptr callerToken, sptr dialogCall) override + const SecCompClickEvent& clickInfo, 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 4f3ea0c..685545e 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 @@ -100,8 +100,8 @@ HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp001, 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)); } /** @@ -125,7 +125,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 +150,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 3507bc5..14f5076 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,8 @@ 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)); + std::string message = ""; + SecCompKit::ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, nullptr, std::move(func), message); } } // namespace OHOS -- Gitee