diff --git a/frameworks/BUILD.gn b/frameworks/BUILD.gn index 39b3a151054b924a29f2de3af2f17ffc2b6c1c46..14fcd7b057e84731c468d4be1280d49b122bb2e0 100644 --- a/frameworks/BUILD.gn +++ b/frameworks/BUILD.gn @@ -44,6 +44,7 @@ ohos_source_set("security_component_framework_src_set") { "security_component/src/save_button.cpp", "security_component/src/sec_comp_base.cpp", "security_component/src/sec_comp_click_event_parcel.cpp", + "security_component/src/sec_comp_dialog_callback_stub.cpp", ] configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] @@ -52,6 +53,7 @@ ohos_source_set("security_component_framework_src_set") { external_deps = [ "c_utils:utils", "hilog:libhilog", + "ipc:ipc_core", "json:nlohmann_json_static", ] diff --git a/frameworks/common/include/sec_comp_err.h b/frameworks/common/include/sec_comp_err.h index ff2cb6b11dcc93983b00ef865ce659511077b3a4..5c182026a57abc216c211e94dde5cb0fcb5a0659 100644 --- a/frameworks/common/include/sec_comp_err.h +++ b/frameworks/common/include/sec_comp_err.h @@ -35,6 +35,7 @@ enum SCErrCode : int32_t { SC_SERVICE_ERROR_CLICK_EVENT_INVALID = -60, SC_SERVICE_ERROR_COMPONENT_INFO_NOT_EQUAL = -61, SC_SERVICE_ERROR_CALLER_INVALID = -62, + SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE = -63, SC_ENHANCE_ERROR_NOT_EXIST_ENHANCE = -100, SC_ENHANCE_ERROR_VALUE_INVALID = -101, diff --git a/frameworks/security_component/src/sec_comp_dialog_callback_stub.cpp b/frameworks/security_component/src/sec_comp_dialog_callback_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e0ab5ee3037ef51e3f7d8e02f4f84a05da57231 --- /dev/null +++ b/frameworks/security_component/src/sec_comp_dialog_callback_stub.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sec_comp_dialog_callback_stub.h" + +#include "sec_comp_err.h" +#include "sec_comp_log.h" + +namespace OHOS { +namespace Security { +namespace SecurityComponent { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompDialogCallbackStub" +}; +} + +int32_t SecCompDialogCallbackStub::OnRemoteRequest( + uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) +{ + SC_LOG_DEBUG(LABEL, "Entry, code: 0x%{public}x", code); + std::u16string descriptor = data.ReadInterfaceToken(); + if (descriptor != ISecCompDialogCallback::GetDescriptor()) { + SC_LOG_ERROR(LABEL, "Get unexpect descriptor"); + return SC_SERVICE_ERROR_IPC_REQUEST_FAIL; + } + int32_t msgCode = static_cast(code); + if (msgCode == ISecCompDialogCallback::ON_DIALOG_CLOSED) { + int32_t res; + if (!data.ReadInt32(res)) { + SC_LOG_ERROR(LABEL, "Read result failed."); + return SC_SERVICE_ERROR_IPC_REQUEST_FAIL; + } + + OnDialogClosed(res); + } else { + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return 0; +} +} // namespace SecurityComponent +} // namespace Security +} // namespace OHOS diff --git a/interfaces/inner_api/enhance_kits/test/unittest/src/sec_comp_enhance_test.cpp b/interfaces/inner_api/enhance_kits/test/unittest/src/sec_comp_enhance_test.cpp index 9f7b3cb7c5e8b3dd01b06d7ab547038a4b2bc76c..b2987cebc63a2349cc7eb43c8ed416eae847e8a2 100644 --- a/interfaces/inner_api/enhance_kits/test/unittest/src/sec_comp_enhance_test.cpp +++ b/interfaces/inner_api/enhance_kits/test/unittest/src/sec_comp_enhance_test.cpp @@ -48,7 +48,7 @@ void SecCompEnhanceTest::SetUpTestCase() if (access(ENHANCE_SRV_INTERFACE_LIB.c_str(), F_OK) == 0) { g_srvEnhanceExist = true; } - system("kill -9 `pidof security_compon`"); + system("kill -9 `pidof security_component_service`"); SC_LOG_INFO(LABEL, "SetUpTestCase."); } diff --git a/interfaces/inner_api/security_component/BUILD.gn b/interfaces/inner_api/security_component/BUILD.gn index 2469ff92d1c945d99700e954d7735942650661f7..92c036427cfcf90c907bf21829a5798e8c3ba759 100644 --- a/interfaces/inner_api/security_component/BUILD.gn +++ b/interfaces/inner_api/security_component/BUILD.gn @@ -44,6 +44,7 @@ ohos_shared_library("libsecurity_component_sdk") { "src/sec_comp_caller_authorization.cpp", "src/sec_comp_client.cpp", "src/sec_comp_death_recipient.cpp", + "src/sec_comp_dialog_callback.cpp", "src/sec_comp_kit.cpp", "src/sec_comp_load_callback.cpp", "src/sec_comp_proxy.cpp", diff --git a/interfaces/inner_api/security_component/include/i_sec_comp_dialog_callback.h b/interfaces/inner_api/security_component/include/i_sec_comp_dialog_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..805c3cab3cf7fd4b47fef779dfe16fb995e73629 --- /dev/null +++ b/interfaces/inner_api/security_component/include/i_sec_comp_dialog_callback.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef I_SECURITY_COMPONENT_DIALOG_CALLBACK_H +#define I_SECURITY_COMPONENT_DIALOG_CALLBACK_H + +#include "iremote_broker.h" + +namespace OHOS { +namespace Security { +namespace SecurityComponent { +class ISecCompDialogCallback : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.security.ISecCompDialogCallback"); + virtual void OnDialogClosed(int32_t result) = 0; + enum InterfaceCode { + ON_DIALOG_CLOSED = 0, + }; +}; +} // namespace SecurityComponent +} // namespace Security +} // namespace OHOS +#endif // I_SECURITY_COMPONENT_DIALOG_CALLBACK_H diff --git a/interfaces/inner_api/security_component/include/i_sec_comp_service.h b/interfaces/inner_api/security_component/include/i_sec_comp_service.h index cd76c2e7aade5c3fe45c89d48888180d50d631f9..155604b89e73a414bdc75cc2909a4f293213078b 100644 --- a/interfaces/inner_api/security_component/include/i_sec_comp_service.h +++ b/interfaces/inner_api/security_component/include/i_sec_comp_service.h @@ -35,7 +35,7 @@ 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) = 0; + const SecCompClickEvent& clickInfo, sptr callerToken, sptr dialogCallback) = 0; virtual bool VerifySavePermission(AccessToken::AccessTokenID tokenId) = 0; virtual sptr GetEnhanceRemoteObject() = 0; virtual int32_t PreRegisterSecCompProcess() = 0; diff --git a/interfaces/inner_api/security_component/include/sec_comp_client.h b/interfaces/inner_api/security_component/include/sec_comp_client.h index d1d0af76b3497729362a7844fc89502062465f10..a1913abf9f406315bcff43939cb399b3a727412c 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_client.h +++ b/interfaces/inner_api/security_component/include/sec_comp_client.h @@ -34,7 +34,8 @@ public: int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo); int32_t UnregisterSecurityComponent(int32_t scId); int32_t ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken); + const std::string& componentInfo, const SecCompClickEvent& clickInfo, + sptr callerToken, sptr dialogCallback); bool VerifySavePermission(AccessToken::AccessTokenID tokenId); sptr GetEnhanceRemoteObject(bool doLoadSa); int32_t PreRegisterSecCompProcess(); diff --git a/interfaces/inner_api/security_component/include/sec_comp_dialog_callback.h b/interfaces/inner_api/security_component/include/sec_comp_dialog_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..56af2581a2d5e03f0e24e811de6744aaa8fc235d --- /dev/null +++ b/interfaces/inner_api/security_component/include/sec_comp_dialog_callback.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SECURITY_COMPONENT_DIALOG_CALLBACK_H +#define SECURITY_COMPONENT_DIALOG_CALLBACK_H + +#include "sec_comp_dialog_callback_stub.h" +#include "iremote_stub.h" +#include "nocopyable.h" +#include "sec_comp_info.h" + +namespace OHOS { +namespace Security { +namespace SecurityComponent { +class SecCompDialogCallback : public SecCompDialogCallbackStub { +public: + explicit SecCompDialogCallback(OnFirstUseDialogCloseFunc&& callback) + { + callback_ = std::move(callback); + }; + + ~SecCompDialogCallback() override {}; + + void OnDialogClosed(int32_t result) override; +private: + OnFirstUseDialogCloseFunc callback_; +}; +} // namespace SecurityComponent +} // namespace Security +} // namespace OHOS +#endif // I_SECURITY_COMPONENT_DIALOG_CALLBACK_STUB_H diff --git a/interfaces/inner_api/security_component/include/sec_comp_dialog_callback_stub.h b/interfaces/inner_api/security_component/include/sec_comp_dialog_callback_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..f1db394decc59ebc548facc0da1dc0781e31d855 --- /dev/null +++ b/interfaces/inner_api/security_component/include/sec_comp_dialog_callback_stub.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SECURITY_COMPONENT_DIALOG_CALLBACK_STUB_H +#define SECURITY_COMPONENT_DIALOG_CALLBACK_STUB_H + +#include "i_sec_comp_dialog_callback.h" + +#include "iremote_stub.h" +#include "nocopyable.h" + +namespace OHOS { +namespace Security { +namespace SecurityComponent { +class SecCompDialogCallbackStub : public IRemoteStub { +public: + SecCompDialogCallbackStub() = default; + virtual ~SecCompDialogCallbackStub() = default; + + int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; +}; +} // namespace SecurityComponent +} // namespace Security +} // namespace OHOS +#endif // SECURITY_COMPONENT_DIALOG_CALLBACK_STUB_H diff --git a/interfaces/inner_api/security_component/include/sec_comp_info.h b/interfaces/inner_api/security_component/include/sec_comp_info.h index cae755a94cb7ef163c0d29b9fcb4727f9b966da1..0f9d0053c007212251edaecfaa4337a41d6b5923 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_info.h +++ b/interfaces/inner_api/security_component/include/sec_comp_info.h @@ -17,6 +17,7 @@ #define SECURITY_COMPONENT_INFO_H #include +#include namespace OHOS { namespace Security { @@ -33,6 +34,7 @@ static constexpr uint32_t MAX_EXTRA_SIZE = 0x1000; static constexpr int32_t KEY_SPACE = 2050; static constexpr int32_t KEY_ENTER = 2054; +using OnFirstUseDialogCloseFunc = std::function; struct PaddingSize { DimensionT top = DEFAULT_DIMENSION; 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 2e49a783495c3fdac2e5b1ae4ea4d7513d44eeed..7cabd4e50257346b83e77c72902203ff835233b8 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_kit.h +++ b/interfaces/inner_api/security_component/include/sec_comp_kit.h @@ -30,7 +30,9 @@ public: static int32_t UpdateSecurityComponent(int32_t scId, std::string& componentInfo); static int32_t UnregisterSecurityComponent(int32_t scId); static int32_t ReportSecurityComponentClickEvent(int32_t scId, - std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken = nullptr); + std::string& componentInfo, const SecCompClickEvent& clickInfo, + sptr callerToken, + OnFirstUseDialogCloseFunc&& callback); static bool VerifySavePermission(AccessToken::AccessTokenID tokenId); static sptr GetEnhanceRemoteObject(bool isLoad); static int32_t PreRegisterSecCompProcess(); diff --git a/interfaces/inner_api/security_component/include/sec_comp_proxy.h b/interfaces/inner_api/security_component/include/sec_comp_proxy.h index 5df62d5e99cd2a86db8375352d02da9e3d5cd64f..1b140ccccaa97c24b828706b7755af6cc2fea70c 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_proxy.h +++ b/interfaces/inner_api/security_component/include/sec_comp_proxy.h @@ -30,7 +30,8 @@ public: int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) override; int32_t UnregisterSecurityComponent(int32_t scId) override; int32_t ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken) override; + const std::string& componentInfo, const SecCompClickEvent& clickInfo, + sptr callerToken, sptr dialogCallback) override; bool VerifySavePermission(AccessToken::AccessTokenID tokenId) override; sptr GetEnhanceRemoteObject() override; int32_t PreRegisterSecCompProcess() override; diff --git a/interfaces/inner_api/security_component/src/sec_comp_client.cpp b/interfaces/inner_api/security_component/src/sec_comp_client.cpp index ca2847c62995af378b9f8c0b79ea5ed2918c6dc5..210e7247646d03ac198002ec735cf583fc5a183e 100644 --- a/interfaces/inner_api/security_component/src/sec_comp_client.cpp +++ b/interfaces/inner_api/security_component/src/sec_comp_client.cpp @@ -81,7 +81,8 @@ int32_t SecCompClient::UnregisterSecurityComponent(int32_t scId) } int32_t SecCompClient::ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken) + const std::string& componentInfo, const SecCompClickEvent& clickInfo, + sptr callerToken, sptr dialogCallback) { auto proxy = GetProxy(true); if (proxy == nullptr) { @@ -89,7 +90,7 @@ int32_t SecCompClient::ReportSecurityComponentClickEvent(int32_t scId, return SC_SERVICE_ERROR_VALUE_INVALID; } - return proxy->ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, callerToken); + return proxy->ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, callerToken, dialogCallback); } bool SecCompClient::VerifySavePermission(AccessToken::AccessTokenID tokenId) diff --git a/interfaces/inner_api/security_component/src/sec_comp_dialog_callback.cpp b/interfaces/inner_api/security_component/src/sec_comp_dialog_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..94ed2a94e7374123b6f52ebd8c540628880039c1 --- /dev/null +++ b/interfaces/inner_api/security_component/src/sec_comp_dialog_callback.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sec_comp_log.h" +#include "sec_comp_dialog_callback.h" + +namespace OHOS { +namespace Security { +namespace SecurityComponent { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompDialogCallback" +}; + +void SecCompDialogCallback::OnDialogClosed(int32_t result) +{ + if (callback_ == nullptr) { + SC_LOG_ERROR(LABEL, "callback_ is nullptr"); + return; + } + + SC_LOG_DEBUG(LABEL, "OnDialogClosed call"); + callback_(result); +} +} // namespace SecurityComponent +} // namespace Security +} // namespace OHOS diff --git a/interfaces/inner_api/security_component/src/sec_comp_kit.cpp b/interfaces/inner_api/security_component/src/sec_comp_kit.cpp index bd414b64a104ac0e6e67a6cf16277e7976bb2573..6c466771c95404c0e139830cef8ef1dffca70fa1 100644 --- a/interfaces/inner_api/security_component/src/sec_comp_kit.cpp +++ b/interfaces/inner_api/security_component/src/sec_comp_kit.cpp @@ -18,6 +18,7 @@ #include "ipc_skeleton.h" #include "sec_comp_caller_authorization.h" #include "sec_comp_client.h" +#include "sec_comp_dialog_callback.h" #include "sec_comp_enhance_adapter.h" #include "sec_comp_log.h" @@ -95,7 +96,8 @@ int32_t SecCompKit::UnregisterSecurityComponent(int32_t scId) } int32_t SecCompKit::ReportSecurityComponentClickEvent(int32_t scId, - std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken) + std::string& componentInfo, const SecCompClickEvent& clickInfo, + sptr callerToken, OnFirstUseDialogCloseFunc&& callback) { if (!SecCompCallerAuthorization::GetInstance().IsKitCaller( reinterpret_cast(__builtin_return_address(0)))) { @@ -106,13 +108,25 @@ int32_t SecCompKit::ReportSecurityComponentClickEvent(int32_t scId, return SC_SERVICE_ERROR_CALLER_INVALID; } + if (callback == nullptr) { + SC_LOG_ERROR(LABEL, "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"); + return SC_SERVICE_ERROR_MEMORY_OPERATE_FAIL; + } + if (!SecCompEnhanceAdapter::EnhanceDataPreprocess(scId, componentInfo)) { SC_LOG_ERROR(LABEL, "Preprocess security component fail"); return SC_ENHANCE_ERROR_VALUE_INVALID; } int32_t res = - SecCompClient::GetInstance().ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, callerToken); + SecCompClient::GetInstance().ReportSecurityComponentClickEvent(scId, componentInfo, + clickInfo, callerToken, callbackRemote); if (res != SC_OK) { SC_LOG_ERROR(LABEL, "report click event fail, error: %{public}d", res); } diff --git a/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp b/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp index 50f7f51447a33fc2312b7fa84ecf93fd0f1c4886..0c99ed5557ef80e12417a2d54edb19331465c98c 100644 --- a/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp +++ b/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp @@ -68,7 +68,7 @@ int32_t SecCompProxy::RegisterSecurityComponent(SecCompType type, int32_t requestResult = remote->SendRequest( static_cast(SecurityComponentServiceInterfaceCode::REGISTER_SECURITY_COMPONENT), data, reply, option); - + if (!SecCompEnhanceAdapter::EnhanceDeserializeSessionInfo(reply, newReply)) { SC_LOG_ERROR(LABEL, "Register deserialize session info failed."); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; @@ -226,7 +226,8 @@ int32_t SecCompProxy::SendReportClickEventRequest(MessageParcel& data) } int32_t SecCompProxy::ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken) + const std::string& componentInfo, const SecCompClickEvent& clickInfo, + sptr callerToken, sptr dialogCallback) { MessageParcel tmpData; MessageParcel data; @@ -261,6 +262,11 @@ int32_t SecCompProxy::ReportSecurityComponentClickEvent(int32_t scId, return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } + if ((dialogCallback != nullptr) && !data.WriteRemoteObject(dialogCallback)) { + SC_LOG_ERROR(LABEL, "Report write caller token failed."); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + if (!SecCompEnhanceAdapter::EnhanceSerializeSessionInfo(tmpData, data)) { SC_LOG_ERROR(LABEL, "Report serialize session info failed."); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; @@ -353,11 +359,11 @@ sptr SecCompProxy::GetEnhanceRemoteObject() } else { SC_LOG_ERROR(LABEL, "Get enhance request failed, result: %{public}d.", requestResult); } - + if (!SecCompEnhanceAdapter::EnhanceDeserializeSessionInfo(reply, newReply)) { SC_LOG_ERROR(LABEL, "Get enhance deserialize session info failed."); } - + return callback; } @@ -391,7 +397,7 @@ int32_t SecCompProxy::PreRegisterSecCompProcess() SC_LOG_ERROR(LABEL, "PreRegister deserialize session info failed."); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - + if (requestResult != SC_OK) { SC_LOG_ERROR(LABEL, "PreRegister request failed, result: %{public}d.", requestResult); return requestResult; diff --git a/interfaces/inner_api/security_component/test/BUILD.gn b/interfaces/inner_api/security_component/test/BUILD.gn index 45479996fa73ae3d2f71ac247d9761a08fe13a58..509084fe44131e8ef999aa52063ea2d89664c2ed 100644 --- a/interfaces/inner_api/security_component/test/BUILD.gn +++ b/interfaces/inner_api/security_component/test/BUILD.gn @@ -31,6 +31,7 @@ ohos_unittest("sec_comp_sdk_test") { "${sec_comp_root_dir}/interfaces/inner_api/security_component/src/sec_comp_caller_authorization.cpp", "${sec_comp_root_dir}/interfaces/inner_api/security_component/src/sec_comp_client.cpp", "${sec_comp_root_dir}/interfaces/inner_api/security_component/src/sec_comp_death_recipient.cpp", + "${sec_comp_root_dir}/interfaces/inner_api/security_component/src/sec_comp_dialog_callback.cpp", "${sec_comp_root_dir}/interfaces/inner_api/security_component/src/sec_comp_kit.cpp", "${sec_comp_root_dir}/interfaces/inner_api/security_component/src/sec_comp_load_callback.cpp", "${sec_comp_root_dir}/interfaces/inner_api/security_component/src/sec_comp_proxy.cpp", diff --git a/interfaces/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp b/interfaces/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp index c2cb804603f2f9325be47fa235ba776e108f99a5..11edd4a2abaf5550365ec2eac80d401b8513deed 100644 --- a/interfaces/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp +++ b/interfaces/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp @@ -40,7 +40,8 @@ static void TestInCallerNotCheckList() std::string emptyStr = ""; int registerRes = SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, emptyStr, scId); int updateRes = SecCompKit::UpdateSecurityComponent(scId, emptyStr); - int reportRes = SecCompKit::ReportSecurityComponentClickEvent(scId, emptyStr, click, nullptr); + OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + int reportRes = SecCompKit::ReportSecurityComponentClickEvent(scId, emptyStr, click, nullptr, std::move(func)); EXPECT_EQ(registerRes, SC_SERVICE_ERROR_CALLER_INVALID); EXPECT_EQ(updateRes, SC_SERVICE_ERROR_CALLER_INVALID); @@ -54,7 +55,8 @@ static void TestInCallerCheckList() std::string emptyStr = ""; int registerRes = SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, emptyStr, scId); int updateRes = SecCompKit::UpdateSecurityComponent(scId, emptyStr); - int reportRes = SecCompKit::ReportSecurityComponentClickEvent(scId, emptyStr, click, nullptr); + OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + int reportRes = SecCompKit::ReportSecurityComponentClickEvent(scId, emptyStr, click, nullptr, std::move(func)); EXPECT_NE(registerRes, SC_SERVICE_ERROR_CALLER_INVALID); EXPECT_NE(updateRes, SC_SERVICE_ERROR_CALLER_INVALID); @@ -123,7 +125,8 @@ HWTEST_F(SecCompKitTest, ExceptCall001, TestSize.Level1) .point.touchY = TestCommon::TEST_COORDINATE, .point.timestamp = static_cast(std::chrono::high_resolution_clock::now().time_since_epoch().count()) }; - EXPECT_NE(SC_OK, SecCompKit::ReportSecurityComponentClickEvent(scId, jsonStr, touch, nullptr)); + OnFirstUseDialogCloseFunc func = nullptr; + EXPECT_NE(SC_OK, SecCompKit::ReportSecurityComponentClickEvent(scId, jsonStr, touch, nullptr, std::move(func))); EXPECT_NE(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } diff --git a/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp b/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp index 2efa18e84d8c2206d0ff7cd23e64425903c65dc0..0644030c669ba7d5d4208407091ee279d1363e95 100644 --- a/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp +++ b/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp @@ -37,6 +37,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompRegisterCallbackTest"}; static AccessTokenID g_selfTokenId = 0; static int32_t g_selfUid = 0; +static uint32_t g_token_sum = 0; class MockUiSecCompProbe : public ISecCompProbe { public: @@ -60,10 +61,11 @@ static __attribute__((noinline)) int32_t RegisterSecurityComponent( static __attribute__((noinline)) int32_t ReportSecurityComponentClickEvent( int32_t scId, std::string& componentInfo, - const SecCompClickEvent& clickInfo, sptr callerToken) + const SecCompClickEvent& clickInfo, sptr callerToken, OnFirstUseDialogCloseFunc dialogCall) { SC_LOG_INFO(LABEL, "ReportSecurityComponentClickEvent enter"); - return SecCompKit::ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, callerToken); + return SecCompKit::ReportSecurityComponentClickEvent(scId, componentInfo, clickInfo, callerToken, + std::move(dialogCall)); } static __attribute__((noinline)) int32_t UpdateSecurityComponent(int32_t scId, std::string& componentInfo) @@ -96,6 +98,7 @@ public: void SecCompRegisterCallbackTest::SetUpTestCase() { + system("kill -9 `pidof security_component_service`"); InitUiRegister(); SC_LOG_INFO(LABEL, "SecCompRegisterCallbackTest."); } @@ -215,8 +218,9 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent004, TestSize.Lev sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); 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)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -249,8 +253,9 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent005, TestSize.Lev sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); - EXPECT_EQ(SC_OK, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + EXPECT_EQ(SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -300,8 +305,9 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent001, Test sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); + OnFirstUseDialogCloseFunc func = [] (int32_t) {}; ASSERT_EQ(SC_OK, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); uint32_t selfTokenId = GetSelfTokenID(); ASSERT_TRUE(SecCompKit::VerifySavePermission(selfTokenId)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -321,7 +327,8 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent002, Test TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; - ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID)); + ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID + g_token_sum)); + g_token_sum ++; EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; @@ -339,8 +346,9 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent002, Test sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); + OnFirstUseDialogCloseFunc func = [] (int32_t) {}; ASSERT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); setuid(g_selfUid); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); @@ -348,7 +356,7 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent002, Test /** * @tc.name: ReportSecurityComponentClickEvent003 - * @tc.desc: Test report security component data is empty + * @tc.desc: Test report security component enhance data is empty * @tc.type: FUNC * @tc.require: AR000HO9J7 */ @@ -358,7 +366,8 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent003, Test TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; - ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID)); + ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID + g_token_sum)); + g_token_sum ++; EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); @@ -372,16 +381,50 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent003, Test sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); + OnFirstUseDialogCloseFunc func = [] (int32_t) {}; #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE - ASSERT_NE(SC_OK, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); #else - ASSERT_EQ(SC_OK, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ASSERT_EQ(SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); #endif EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } +/** + * @tc.name: ReportSecurityComponentClickEvent004 + * @tc.desc: Test report security component dialog callback is nullptr + * @tc.type: FUNC + * @tc.require: AR000HO9J7 + */ +HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent004, TestSize.Level1) +{ + nlohmann::json jsonRes; + TestCommon::BuildSaveComponentInfo(jsonRes); + std::string saveInfo = jsonRes.dump(); + int32_t scId; + ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID + g_token_sum)); + g_token_sum ++; + + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + + struct SecCompClickEvent clickInfo = { + .type = ClickEventType::POINT_EVENT_TYPE, + .point.touchX = TestCommon::TEST_COORDINATE, + .point.touchY = TestCommon::TEST_COORDINATE, + .point.timestamp = static_cast( + std::chrono::high_resolution_clock::now().time_since_epoch().count()) / TestCommon::TIME_CONVERSION_UNIT + }; + sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); + ASSERT_NE(callback, nullptr); + auto token = callback->AsObject(); + OnFirstUseDialogCloseFunc func = nullptr; + ASSERT_EQ(SC_ENHANCE_ERROR_VALUE_INVALID, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); + EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); +} + /** * @tc.name: ReportClickWithoutHmac001 * @tc.desc: Test report click event permission denied @@ -413,8 +456,9 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportClickWithoutHmac001, TestSize.Level1 sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); - EXPECT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL, - ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo, token)); + OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + EXPECT_EQ(SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE, + ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo, token, std::move(func))); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -432,7 +476,8 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission001, TestSize.Level1) TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; - ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID)); + ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID + g_token_sum)); + g_token_sum ++; EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; @@ -448,8 +493,9 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission001, TestSize.Level1) sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); - ASSERT_EQ(SC_OK, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + ASSERT_EQ(SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE, + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); setuid(100); ASSERT_FALSE(SecCompKit::VerifySavePermission(TestCommon::HAP_TOKEN_ID)); // mediaLibraryTokenId_ != 0 @@ -487,8 +533,9 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission002, TestSize.Level1) sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); + OnFirstUseDialogCloseFunc func = [] (int32_t) {}; ASSERT_EQ(SC_OK, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); ASSERT_FALSE(SecCompKit::VerifySavePermission(0)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); @@ -522,8 +569,9 @@ HWTEST_F(SecCompRegisterCallbackTest, UnregisterSecurityComponent001, TestSize.L sptr callback = new (std::nothrow) SystemAbilityLoadCallbackStub(); ASSERT_NE(callback, nullptr); auto token = callback->AsObject(); + OnFirstUseDialogCloseFunc func = [] (int32_t) {}; EXPECT_EQ(SC_OK, - ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token)); + ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, token, std::move(func))); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); system("param set sec.comp.enhance 0"); } @@ -559,7 +607,8 @@ HWTEST_F(SecCompRegisterCallbackTest, UpdateSecurityComponent002, TestSize.Level std::string saveInfo = jsonRes.dump(); int32_t scId; - ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID)); + ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID + g_token_sum)); + g_token_sum ++; ASSERT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); ASSERT_NE(-1, scId); setuid(100); diff --git a/services/security_component_service/sa/BUILD.gn b/services/security_component_service/sa/BUILD.gn index 12a900a8e71d02b2d39f1c16582ce86ae52e8a2b..fe0d40a792df8ef1335ffc8018c14944e4b79246 100644 --- a/services/security_component_service/sa/BUILD.gn +++ b/services/security_component_service/sa/BUILD.gn @@ -54,6 +54,7 @@ ohos_source_set("security_component_service_src_set") { "sa_main/app_state_observer.cpp", "sa_main/delay_exit_task.cpp", "sa_main/first_use_dialog.cpp", + "sa_main/sec_comp_dialog_callback_proxy.cpp", "sa_main/sec_comp_entity.cpp", "sa_main/sec_comp_info_helper.cpp", "sa_main/sec_comp_malicious_apps.cpp", 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 6840b51f976d4db7980ac562070074d294e36aaf..924abfe626d6a0165b901c679cd154c921726441 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 @@ -21,6 +21,8 @@ #include #include "ability_manager_client.h" #include "accesstoken_kit.h" +#include "hisysevent.h" +#include "sec_comp_dialog_callback_proxy.h" #include "sec_comp_err.h" #include "sec_comp_log.h" #include "want_params_wrapper.h" @@ -41,12 +43,33 @@ const std::string GRANT_ABILITY_BUNDLE_NAME = "com.ohos.permissionmanager"; const std::string GRANT_ABILITY_ABILITY_NAME = "com.ohos.permissionmanager.SecurityExtAbility"; const std::string TYPE_KEY = "ohos.user.security.type"; const std::string TOKEN_KEY = "ohos.ability.params.token"; +const std::string CALLBACK_KEY = "ohos.ability.params.callback"; constexpr uint32_t MAX_CFG_FILE_SIZE = 100 * 1024; // 100k constexpr uint64_t LOCATION_BUTTON_FIRST_USE = 1 << 0; constexpr uint64_t SAVE_BUTTON_FIRST_USE = 1 << 1; } +void SecCompDialogSrvCallback::OnDialogClosed(int32_t result) +{ + SC_LOG_INFO(LABEL, "Call dialog close callback scId_ %{public}d", scId_); + int32_t grantRes = FirstUseDialog::GetInstance().GrantDialogWaitEntity(scId_); + if (grantRes == SC_SERVICE_ERROR_COMPONENT_NOT_EXIST) { + SC_LOG_ERROR(LABEL, "Call dialog close callback scId_ %{public}d is not exist", scId_); + return; + } + auto callback = iface_cast(dialogCallback_); + if (callback != nullptr) { + callback->OnDialogClosed(grantRes); + } +} + +FirstUseDialog& FirstUseDialog::GetInstance() +{ + static FirstUseDialog instance; + return instance; +} + bool FirstUseDialog::IsCfgDirExist(void) { struct stat fstat = {}; @@ -215,9 +238,52 @@ void FirstUseDialog::SaveFirstUseRecord(void) WriteCfgContent(jsonRes.dump()); } -void FirstUseDialog::StartDialogAbility(SecCompType type, sptr callerToken) +void FirstUseDialog::RemoveDialogWaitEntitys(int32_t pid) +{ + std::unique_lock lock(useMapMutex_); + for (auto iter = dialogWaitMap_.begin(); iter != dialogWaitMap_.end();) { + std::shared_ptr entity = iter->second; + if ((entity != nullptr) && (entity->pid_ == pid)) { + iter = dialogWaitMap_.erase(iter); + } else { + ++iter; + } + } +} + +int32_t FirstUseDialog::GrantDialogWaitEntity(int32_t scId) +{ + std::unique_lock lock(useMapMutex_); + auto it = dialogWaitMap_.find(scId); + if (it == dialogWaitMap_.end()) { + SC_LOG_ERROR(LABEL, "Grant dialog wait security component %{public}d is not exist", scId); + return SC_SERVICE_ERROR_COMPONENT_NOT_EXIST; + } + + std::shared_ptr sc = it->second; + if (sc == nullptr) { + 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(); + if (res != SC_OK) { + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "TEMP_GRANT_FAILED", + HiviewDFX::HiSysEvent::EventType::FAULT, "CALLER_UID", sc->uid_, + "CALLER_PID", sc->pid_, "SC_ID", scId, "SC_TYPE", sc->GetType()); + } else { + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "TEMP_GRANT_SUCCESS", + HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "CALLER_UID", sc->uid_, + "CALLER_PID", sc->pid_, "SC_ID", scId, "SC_TYPE", sc->GetType()); + } + dialogWaitMap_.erase(scId); + return res; +} + +void FirstUseDialog::StartDialogAbility(std::shared_ptr entity, + sptr callerToken, sptr dialogCallback) { int32_t typeNum; + SecCompType type = entity->GetType(); if (type == LOCATION_COMPONENT) { typeNum = 0; } else if (type == SAVE_COMPONENT) { @@ -226,13 +292,24 @@ void FirstUseDialog::StartDialogAbility(SecCompType type, sptr ca SC_LOG_ERROR(LABEL, "unknown type."); return; } - + int32_t scId = entity->scId_; + SecCompDialogSrvCallback *call = new (std::nothrow)SecCompDialogSrvCallback(scId, dialogCallback); + sptr srvCallback = call; + if (srvCallback == nullptr) { + SC_LOG_ERROR(LABEL, "New SecCompDialogCallback fail"); + return; + } + dialogWaitMap_[scId] = entity; AAFwk::Want want; want.SetElementName(GRANT_ABILITY_BUNDLE_NAME, GRANT_ABILITY_ABILITY_NAME); want.SetParam(TYPE_KEY, typeNum); want.SetParam(TOKEN_KEY, callerToken); + want.SetParam(CALLBACK_KEY, srvCallback); int startRes = AAFwk::AbilityManagerClient::GetInstance()->StartExtensionAbility(want, callerToken); SC_LOG_INFO(LABEL, "start ability res %{public}d", startRes); + if (startRes != 0) { + dialogWaitMap_.erase(scId); + } } void FirstUseDialog::SendSaveEventHandler(void) @@ -245,47 +322,58 @@ void FirstUseDialog::SendSaveEventHandler(void) secHandler_->ProxyPostTask(delayed); } -bool FirstUseDialog::NotifyFirstUseDialog(AccessToken::AccessTokenID tokenId, SecCompType type, - sptr callerToken) +int32_t FirstUseDialog::NotifyFirstUseDialog(std::shared_ptr entity, + sptr callerToken, sptr dialogCallback) { + if (entity == nullptr) { + SC_LOG_ERROR(LABEL, "Entity is invalid."); + return SC_SERVICE_ERROR_VALUE_INVALID; + } if (secHandler_ == nullptr) { SC_LOG_ERROR(LABEL, "event handler invalid."); - return false; + return SC_SERVICE_ERROR_VALUE_INVALID; } if (callerToken == nullptr) { SC_LOG_INFO(LABEL, "callerToken is null, no need to notify dialog"); - return false; + return SC_SERVICE_ERROR_VALUE_INVALID; + } + + if (dialogCallback == nullptr) { + SC_LOG_INFO(LABEL, "DialogCallback is null, no need to notify dialog"); + return SC_SERVICE_ERROR_VALUE_INVALID; } uint64_t typeMask; + SecCompType type = entity->GetType(); if (type == LOCATION_COMPONENT) { typeMask = LOCATION_BUTTON_FIRST_USE; } else if (type == SAVE_COMPONENT) { typeMask = SAVE_BUTTON_FIRST_USE; } else { SC_LOG_INFO(LABEL, "this type need not notify dialog to user"); - return false; + return SC_OK; } std::unique_lock lock(useMapMutex_); + AccessToken::AccessTokenID tokenId = entity->tokenId_; auto iter = firstUseMap_.find(tokenId); if (iter == firstUseMap_.end()) { SC_LOG_INFO(LABEL, "has not use record, start dialog"); - StartDialogAbility(type, callerToken); + StartDialogAbility(entity, callerToken, dialogCallback); firstUseMap_[tokenId] = typeMask; SendSaveEventHandler(); - return true; + return SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE; } uint64_t compTypes = firstUseMap_[tokenId]; if ((compTypes & typeMask) == typeMask) { SC_LOG_INFO(LABEL, "no need notify again."); - return true; + return SC_OK; } - StartDialogAbility(type, callerToken); + StartDialogAbility(entity, callerToken, dialogCallback); firstUseMap_[tokenId] |= typeMask; SendSaveEventHandler(); - return true; + return SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE; } void FirstUseDialog::Init(std::shared_ptr secHandler) diff --git a/services/security_component_service/sa/sa_main/first_use_dialog.h b/services/security_component_service/sa/sa_main/first_use_dialog.h index 753500d9b971b24d46fdfdc6b832221050e8db40..39bbe8fe7091e2676fb99428f021d9fcf8ba2e57 100644 --- a/services/security_component_service/sa/sa_main/first_use_dialog.h +++ b/services/security_component_service/sa/sa_main/first_use_dialog.h @@ -22,6 +22,8 @@ #include "access_token.h" #include "iremote_object.h" #include "nlohmann/json.hpp" +#include "sec_comp_dialog_callback_stub.h" +#include "sec_comp_entity.h" #include "sec_comp_err.h" #include "sec_comp_info.h" #include "sec_event_handler.h" @@ -29,14 +31,38 @@ namespace OHOS { namespace Security { namespace SecurityComponent { +class SecCompDialogSrvCallback : public SecCompDialogCallbackStub { +public: + explicit SecCompDialogSrvCallback(int32_t scId, sptr dialogCallback) + { + scId_ = scId; + dialogCallback_ = dialogCallback; + }; + + ~SecCompDialogSrvCallback() override + { + dialogCallback_ = nullptr; + }; + + void OnDialogClosed(int32_t result) override; +private: + int32_t scId_; + sptr dialogCallback_; +}; + class FirstUseDialog final { public: - FirstUseDialog() = default; + static FirstUseDialog& GetInstance(); + ~FirstUseDialog() = default; - bool NotifyFirstUseDialog(AccessToken::AccessTokenID tokenId, SecCompType type, sptr callerToken); + int32_t NotifyFirstUseDialog(std::shared_ptr entity, + sptr callerToken, sptr dialogCallback); void Init(std::shared_ptr secHandler); + int32_t GrantDialogWaitEntity(int32_t scId); + void RemoveDialogWaitEntitys(int32_t pid); private: + FirstUseDialog() {}; bool IsCfgDirExist(void); bool IsCfgFileExist(void); bool IsCfgFileValid(void); @@ -47,11 +73,13 @@ private: void ParseRecords(nlohmann::json& jsonRes); void LoadFirstUseRecord(void); void SaveFirstUseRecord(void); - void StartDialogAbility(SecCompType type, sptr callerToken); + void StartDialogAbility(std::shared_ptr entity, + sptr callerToken, sptr dialogCallback); void SendSaveEventHandler(void); std::mutex useMapMutex_; std::unordered_map firstUseMap_; + std::unordered_map> dialogWaitMap_; std::shared_ptr secHandler_; }; } // namespace SecurityComponentEnhance diff --git a/services/security_component_service/sa/sa_main/sec_comp_dialog_callback_proxy.cpp b/services/security_component_service/sa/sa_main/sec_comp_dialog_callback_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e7e37be986e661c16a96b0a2b6157a25390f1045 --- /dev/null +++ b/services/security_component_service/sa/sa_main/sec_comp_dialog_callback_proxy.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sec_comp_dialog_callback_proxy.h" + +#include "sec_comp_log.h" + +namespace OHOS { +namespace Security { +namespace SecurityComponent { +namespace { +static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { + LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompDialogCallbackProxy" +}; +} + +SecCompDialogCallbackProxy::SecCompDialogCallbackProxy(const sptr& impl) + : IRemoteProxy(impl) { +} + +SecCompDialogCallbackProxy::~SecCompDialogCallbackProxy() +{} + +void SecCompDialogCallbackProxy::OnDialogClosed(int32_t result) +{ + MessageParcel data; + data.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor()); + data.WriteInt32(result); + + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + sptr remote = Remote(); + if (remote == nullptr) { + SC_LOG_ERROR(LABEL, "remote service null."); + return; + } + int32_t requestResult = remote->SendRequest( + static_cast(ISecCompDialogCallback::ON_DIALOG_CLOSED), data, reply, option); + if (requestResult != NO_ERROR) { + SC_LOG_ERROR(LABEL, "send request fail, result: %{public}d", requestResult); + return; + } + + SC_LOG_INFO(LABEL, "SendRequest success"); +} +} // namespace SecurityComponent +} // namespace Security +} // namespace OHOS diff --git a/services/security_component_service/sa/sa_main/sec_comp_dialog_callback_proxy.h b/services/security_component_service/sa/sa_main/sec_comp_dialog_callback_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..e6c6ee48a68f5f4abd33c2c309cadf49c064440a --- /dev/null +++ b/services/security_component_service/sa/sa_main/sec_comp_dialog_callback_proxy.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SEC_COMP_DIALOG_CALLBACK_PROXY_H +#define SEC_COMP_DIALOG_CALLBACK_PROXY_H + +#include "i_sec_comp_dialog_callback.h" + +#include "iremote_proxy.h" +#include "nocopyable.h" + +namespace OHOS { +namespace Security { +namespace SecurityComponent { +class SecCompDialogCallbackProxy : public IRemoteProxy { +public: + explicit SecCompDialogCallbackProxy(const sptr& impl); + ~SecCompDialogCallbackProxy() override; + + void OnDialogClosed(int32_t result) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace SecurityComponent +} // namespace Security +} // namespace OHOS +#endif // SEC_COMP_DIALOG_CALLBACK_PROXY_H 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 be7276058aee77eb7aa0cc2c762f8611dbed8b48..2bc4d64f16c118f3477fc51945c3e75afbc243b3 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 @@ -27,16 +27,11 @@ namespace SecurityComponent { class SecCompEntity { public: SecCompEntity(std::shared_ptr component, - AccessToken::AccessTokenID token, int32_t scId) : componentInfo_(component), - tokenId_(token), scId_(scId) {}; + AccessToken::AccessTokenID token, int32_t scId, int32_t pid, int32_t uid) + : componentInfo_(component), tokenId_(token), scId_(scId), pid_(pid), uid_(uid) {}; ~SecCompEntity() = default; int32_t RevokeTempPermission(); int32_t GrantTempPermission(); - int32_t GetScId() const - { - return scId_; - }; - SecCompType GetType() const { if (componentInfo_ == nullptr) { @@ -50,31 +45,19 @@ public: return isGrant_; } - std::shared_ptr GetComponentInfo() const - { - return componentInfo_; - }; - - void SetComponentInfo(const std::shared_ptr& com) - { - componentInfo_ = com; - }; - - std::shared_ptr GetComponentInfo() - { - return componentInfo_; - }; - bool CompareComponentBasicInfo(SecCompBase* other, bool isRectCheck) const; int32_t CheckClickInfo(const SecCompClickEvent& clickInfo) const; + std::shared_ptr componentInfo_; + AccessToken::AccessTokenID tokenId_; + int32_t scId_; + int32_t pid_; + int32_t uid_; + private: int32_t CheckKeyEvent(const SecCompClickEvent& clickInfo) const; int32_t CheckPointEvent(const SecCompClickEvent& clickInfo) const; - std::shared_ptr componentInfo_; bool isGrant_ = false; - AccessToken::AccessTokenID tokenId_; - int32_t scId_; }; } // namespace SecurityComponent } // namespace Security 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 aee774cd3721f201711bc306d87e24fc57607912..d82a012165d8d73980f5c8697c1f3fdc2911eb79 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 @@ -228,7 +228,7 @@ int32_t SecCompInfoHelper::GrantTempPermission(AccessToken::AccessTokenID tokenI const std::shared_ptr& componentInfo) { if ((tokenId <= 0) || (componentInfo == nullptr)) { - SC_LOG_ERROR(LABEL, "revoke component is null"); + SC_LOG_ERROR(LABEL, "grant component is null"); return SC_SERVICE_ERROR_PERMISSION_OPER_FAIL; } 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 7e4d348554384a61b407a540cd7900283baa721f..cfc914139f8448678b66debe127a055569212133 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 @@ -32,6 +32,7 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURIT static constexpr int32_t SC_ID_START = 1000; static constexpr int32_t MAX_INT_NUM = 0x7fffffff; static constexpr int32_t MAX_SINGLE_PROC_COMP_SIZE = 500; +static constexpr unsigned long REPORT_REMOTE_OBJECT_SIZE = 2UL; } SecCompManager::SecCompManager() @@ -57,7 +58,7 @@ int32_t SecCompManager::CreateScId() } int32_t SecCompManager::AddSecurityComponentToList(int32_t pid, - AccessToken::AccessTokenID tokenId, const SecCompEntity& newEntity) + AccessToken::AccessTokenID tokenId, std::shared_ptr newEntity) { OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); if (isSaExit_) { @@ -96,9 +97,14 @@ int32_t SecCompManager::DeleteSecurityComponentFromList(int32_t pid, int32_t scI SC_LOG_ERROR(LABEL, "Can not find registered process"); return SC_SERVICE_ERROR_COMPONENT_NOT_EXIST; } - std::vector& list = iter->second.compList; + auto& list = iter->second.compList; for (auto it = list.begin(); it != list.end(); ++it) { - if (it->GetScId() == scId) { + std::shared_ptr sc = *it; + if (sc == nullptr) { + SC_LOG_ERROR(LABEL, "Secomp entity is nullptr"); + continue; + } + if (sc->scId_ == scId) { list.erase(it); if (!IsForegroundCompExist()) { SecCompEnhanceAdapter::DisableInputEnhance(); @@ -140,16 +146,21 @@ static std::string TransformCallBackResult(enum SCErrCode error) return errMsg; } -SecCompEntity* SecCompManager::GetSecurityComponentFromList(int32_t pid, int32_t scId) +std::shared_ptr SecCompManager::GetSecurityComponentFromList(int32_t pid, int32_t scId) { auto iter = componentMap_.find(pid); if (iter == componentMap_.end()) { return nullptr; } - std::vector& list = iter->second.compList; + auto& list = iter->second.compList; for (auto it = list.begin(); it != list.end(); ++it) { - if (it->GetScId() == scId) { - return std::addressof(*it); + std::shared_ptr sc = *it; + if (sc == nullptr) { + SC_LOG_ERROR(LABEL, "Secomp entity is nullptr"); + continue; + } + if (sc->scId_ == scId) { + return *it; } } return nullptr; @@ -193,6 +204,8 @@ void SecCompManager::NotifyProcessBackground(int32_t pid) return; } + FirstUseDialog::GetInstance().RemoveDialogWaitEntitys(pid); + SecCompPermManager::GetInstance().RevokeAppPermisionsDelayed(iter->second.tokenId); iter->second.isForeground = false; if (!IsForegroundCompExist()) { @@ -212,6 +225,9 @@ void SecCompManager::NotifyProcessDied(int32_t pid) if (iter == componentMap_.end()) { return; } + + FirstUseDialog::GetInstance().RemoveDialogWaitEntitys(pid); + SC_LOG_INFO(LABEL, "App pid %{public}d died", pid); iter->second.compList.clear(); SecCompPermManager::GetInstance().RevokeAppPermissions(iter->second.tokenId); @@ -347,7 +363,8 @@ int32_t SecCompManager::RegisterSecurityComponent(SecCompType type, } int32_t registerId = CreateScId(); - SecCompEntity entity(component, caller.tokenId, registerId); + std::shared_ptr entity = + std::make_shared(component, caller.tokenId, registerId, caller.pid, caller.uid); int32_t ret = AddSecurityComponentToList(caller.pid, caller.tokenId, entity); if (ret == SC_OK) { scId = registerId; @@ -368,7 +385,7 @@ int32_t SecCompManager::UpdateSecurityComponent(int32_t scId, const nlohmann::js } OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); - SecCompEntity* sc = GetSecurityComponentFromList(caller.pid, scId); + std::shared_ptr sc = GetSecurityComponentFromList(caller.pid, scId); if (sc == nullptr) { SC_LOG_ERROR(LABEL, "Can not find target component"); return SC_SERVICE_ERROR_COMPONENT_NOT_EXIST; @@ -393,7 +410,7 @@ int32_t SecCompManager::UpdateSecurityComponent(int32_t scId, const nlohmann::js return enhanceRes; } - sc->SetComponentInfo(reportComponentInfo); + sc->componentInfo_ = reportComponentInfo; return SC_OK; } @@ -407,7 +424,7 @@ int32_t SecCompManager::UnregisterSecurityComponent(int32_t scId, const SecCompC return DeleteSecurityComponentFromList(caller.pid, scId); } -int32_t SecCompManager::CheckClickSecurityComponentInfo(SecCompEntity* sc, int32_t scId, +int32_t SecCompManager::CheckClickSecurityComponentInfo(std::shared_ptr sc, int32_t scId, const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller) { SC_LOG_DEBUG(LABEL, "PID: %{public}d, Check security component", caller.pid); @@ -438,21 +455,27 @@ int32_t SecCompManager::CheckClickSecurityComponentInfo(SecCompEntity* sc, int32 return enhanceRes; } - sc->SetComponentInfo(reportComponentInfo); + sc->componentInfo_ = reportComponentInfo; return SC_OK; } int32_t SecCompManager::ReportSecurityComponentClickEvent(int32_t scId, const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller, - const SecCompClickEvent& clickInfo, sptr callerToken) + const SecCompClickEvent& clickInfo, const std::vector>& remote) { + if (remote.size() < REPORT_REMOTE_OBJECT_SIZE) { + return SC_SERVICE_ERROR_VALUE_INVALID; + } + auto callerToken = remote[0]; + auto dialogCallback = remote[1]; + if (malicious_.IsInMaliciousAppList(caller.pid, caller.uid)) { SC_LOG_ERROR(LABEL, "app is in MaliciousAppList, never allow it"); return SC_ENHANCE_ERROR_IN_MALICIOUS_LIST; } OHOS::Utils::UniqueReadGuard lk(this->componentInfoLock_); - SecCompEntity* sc = GetSecurityComponentFromList(caller.pid, scId); + std::shared_ptr sc = GetSecurityComponentFromList(caller.pid, scId); if (sc == nullptr) { SC_LOG_ERROR(LABEL, "Can not find target component"); return SC_SERVICE_ERROR_COMPONENT_NOT_EXIST; @@ -474,6 +497,13 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(int32_t scId, return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } + + if (FirstUseDialog::GetInstance().NotifyFirstUseDialog(sc, callerToken, dialogCallback) == + SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE) { + SC_LOG_INFO(LABEL, "start dialog, onclick will be trap after dialog closed."); + return SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE; + } + res = sc->GrantTempPermission(); if (res != SC_OK) { HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "TEMP_GRANT_FAILED", @@ -484,7 +514,6 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(int32_t scId, HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SEC_COMPONENT, "TEMP_GRANT_SUCCESS", HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "CALLER_UID", IPCSkeleton::GetCallingUid(), "CALLER_PID", IPCSkeleton::GetCallingPid(), "SC_ID", scId, "SC_TYPE", sc->GetType()); - firstUseDialog_.NotifyFirstUseDialog(caller.tokenId, sc->GetType(), callerToken); return res; } @@ -492,12 +521,23 @@ void SecCompManager::DumpSecComp(std::string& dumpStr) { OHOS::Utils::UniqueReadGuard lk(this->componentInfoLock_); for (auto iter = componentMap_.begin(); iter != componentMap_.end(); ++iter) { - dumpStr.append("pid:" + std::to_string(iter->first) + "\n"); - for (auto compIter = iter->second.compList.begin(); compIter != iter->second.compList.end(); compIter ++) { + AccessToken::AccessTokenID tokenId = iter->second.tokenId; + bool locationPerm = SecCompPermManager::GetInstance().VerifyPermission(tokenId, LOCATION_COMPONENT); + bool pastePerm = SecCompPermManager::GetInstance().VerifyPermission(tokenId, PASTE_COMPONENT); + bool savePerm = SecCompPermManager::GetInstance().VerifyPermission(tokenId, SAVE_COMPONENT); + dumpStr.append("pid:" + std::to_string(iter->first) + ", tokenId:" + std::to_string(pastePerm) + + ", locationPerm:" + std::to_string(locationPerm) + ", pastePerm:" + std::to_string(pastePerm) + + ", savePerm:" + std::to_string(savePerm) + " \n"); + for (auto compIter = iter->second.compList.begin(); compIter != iter->second.compList.end(); ++compIter) { nlohmann::json json; - compIter->GetComponentInfo()->ToJson(json); - dumpStr.append(" scId:" + std::to_string(compIter->GetScId()) + - ", isGrant:" + std::to_string(compIter->IsGrant()) + ", " + json.dump() + "\n"); + std::shared_ptr sc = *compIter; + if (sc == nullptr || sc->componentInfo_ == nullptr) { + continue; + } + + sc->componentInfo_->ToJson(json); + dumpStr.append(" scId:" + std::to_string(sc->scId_) + + ", isGrant:" + std::to_string(sc->IsGrant()) + ", " + json.dump() + "\n"); } } } @@ -515,7 +555,7 @@ bool SecCompManager::Initialize() secHandler_ = std::make_shared(secRunner_); DelayExitTask::GetInstance().Init(secHandler_); - firstUseDialog_.Init(secHandler_); + FirstUseDialog::GetInstance().Init(secHandler_); SecCompEnhanceAdapter::EnableInputEnhance(); return SecCompPermManager::GetInstance().InitEventHandler(secHandler_); 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 fdf83d0542c71b3c9fb434dfbe814de2b6d2f0c5..323f5d5a8e60cce17e98ab50b8eaf049cd6e523a 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 @@ -41,7 +41,7 @@ struct SecCompCallerInfo { }; struct ProcessCompInfos { - std::vector compList; + std::vector> compList; bool isForeground = false; AccessToken::AccessTokenID tokenId; }; @@ -57,7 +57,8 @@ public: const SecCompCallerInfo& caller); int32_t UnregisterSecurityComponent(int32_t scId, const SecCompCallerInfo& caller); int32_t ReportSecurityComponentClickEvent(int32_t scId, const nlohmann::json& jsonComponent, - const SecCompCallerInfo& caller, const SecCompClickEvent& clickInfo, sptr callerToken); + const SecCompCallerInfo& caller, const SecCompClickEvent& clickInfo, + const std::vector>& remote); void NotifyProcessForeground(int32_t pid); void NotifyProcessBackground(int32_t pid); void NotifyProcessDied(int32_t pid); @@ -72,10 +73,10 @@ private: bool IsForegroundCompExist(); bool IsCompExist(); int32_t AddSecurityComponentToList(int32_t pid, - AccessToken::AccessTokenID tokenId, const SecCompEntity& newEntity); + AccessToken::AccessTokenID tokenId, std::shared_ptr newEntity); int32_t DeleteSecurityComponentFromList(int32_t pid, int32_t scId); - SecCompEntity* GetSecurityComponentFromList(int32_t pid, int32_t scId); - int32_t CheckClickSecurityComponentInfo(SecCompEntity* sc, 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); void SendCheckInfoEnhanceSysEvent(int32_t scId, SecCompType type, const std::string& scene, int32_t res); @@ -89,7 +90,6 @@ private: std::shared_ptr secRunner_; std::shared_ptr secHandler_; - FirstUseDialog firstUseDialog_; SecCompMaliciousApps malicious_; DISALLOW_COPY_AND_MOVE(SecCompManager); 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 1d6ae8b2ee62ceeb3f98ddae990c2d650cb87f19..02b15949edcee8e3e6f460e72b8eca147dd21fbd 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 @@ -129,6 +129,29 @@ bool SecCompPermManager::VerifySavePermission(AccessToken::AccessTokenID tokenId return true; } +bool SecCompPermManager::VerifyPermission(AccessToken::AccessTokenID tokenId, SecCompType type) +{ + int32_t res; + switch (type) { + case LOCATION_COMPONENT: + res = AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, "ohos.permission.LOCATION"); + if (res != AccessToken::TypePermissionState::PERMISSION_GRANTED) { + return false; + } + res = AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, "ohos.permission.APPROXIMATELY_LOCATION"); + return (res == AccessToken::TypePermissionState::PERMISSION_GRANTED); + case PASTE_COMPONENT: + res = AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, + "ohos.permission.SECURE_PASTE"); + return (res == AccessToken::TypePermissionState::PERMISSION_GRANTED); + case SAVE_COMPONENT: + return VerifySavePermission(tokenId); + default: + SC_LOG_ERROR(LABEL, "Unknown component type."); + } + return false; +} + void SecCompPermManager::AddAppGrantPermissionRecord(AccessToken::AccessTokenID tokenId, const std::string& permissionName) { 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 92385393cc8ed40f96314778511897b044afca0a..a5b8ab5a77b780f5c3b96043d64a17febda07014 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 @@ -35,6 +35,7 @@ public: int32_t GrantTempSavePermission(AccessToken::AccessTokenID tokenId); void RevokeTempSavePermission(AccessToken::AccessTokenID tokenId); bool VerifySavePermission(AccessToken::AccessTokenID tokenId); + bool VerifyPermission(AccessToken::AccessTokenID tokenId, SecCompType type); int32_t GrantAppPermission(AccessToken::AccessTokenID tokenId, const std::string& permissionName); int32_t RevokeAppPermission(AccessToken::AccessTokenID tokenId, const std::string& permissionName); 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 ad22a292269c92d91afa36132b0b1c394ea08efa..388f573468e94444cedf190debf2047ca2168e66 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 @@ -228,7 +228,8 @@ int32_t SecCompService::UnregisterSecurityComponent(int32_t scId) } int32_t SecCompService::ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken) + const std::string& componentInfo, const SecCompClickEvent& clickInfo, + sptr callerToken, sptr dialogCallback) { StartTrace(HITRACE_TAG_ACCESS_CONTROL, "SecurityComponentClick"); SecCompCallerInfo caller; @@ -237,8 +238,10 @@ int32_t SecCompService::ReportSecurityComponentClickEvent(int32_t scId, FinishTrace(HITRACE_TAG_ACCESS_CONTROL); return SC_SERVICE_ERROR_VALUE_INVALID; } + std::vector> remoteArr = { callerToken, dialogCallback }; int32_t res = - SecCompManager::GetInstance().ReportSecurityComponentClickEvent(scId, jsonRes, caller, clickInfo, callerToken); + SecCompManager::GetInstance().ReportSecurityComponentClickEvent(scId, jsonRes, caller, clickInfo, + remoteArr); 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 c7c548e685847bfa5646c7a9cdbc702f97384729..ff955821541e8d24570bd8bbc9a334fe20ae1c65 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 @@ -44,7 +44,8 @@ public: int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) override; int32_t UnregisterSecurityComponent(int32_t scId) override; int32_t ReportSecurityComponentClickEvent(int32_t scId, - const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr callerToken) override; + const std::string& componentInfo, const SecCompClickEvent& clickInfo, + sptr callerToken, sptr dialogCallback) 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 fdbd3f8efd53011c8d43e7cb07d5b2b89bb16035..955a73537504ad127d1d9f1e7f3f24f281d7d978 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 @@ -174,7 +174,13 @@ int32_t SecCompStub::ReportSecurityComponentClickEventInner(MessageParcel& data, SC_LOG_ERROR(LABEL, "callerToken is nullptr"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } - + + sptr dialogCallback = data.ReadRemoteObject(); + if (dialogCallback == nullptr) { + SC_LOG_ERROR(LABEL, "dialogCallback is nullptr"); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + MessageParcel newData; if (!SecCompEnhanceAdapter::DeserializeSessionInfoEnhance(data, newData, reply)) { SC_LOG_ERROR(LABEL, "Report deserialize session info failed"); @@ -203,7 +209,9 @@ int32_t SecCompStub::ReportSecurityComponentClickEventInner(MessageParcel& data, } int32_t res = - this->ReportSecurityComponentClickEvent(scId, componentInfo, clickInfoParcel->clickInfoParams_, callerToken); + this->ReportSecurityComponentClickEvent(scId, + componentInfo, clickInfoParcel->clickInfoParams_, + callerToken, dialogCallback); MessageParcel tmpReply; if (!tmpReply.WriteInt32(res)) { SC_LOG_ERROR(LABEL, "Report security component result failed"); diff --git a/services/security_component_service/sa/test/BUILD.gn b/services/security_component_service/sa/test/BUILD.gn index e599b588ad9c1e8216cc43d58344138a74b0abea..269c1754d47ea41e80b4ae6906b1ac6f8e49853f 100644 --- a/services/security_component_service/sa/test/BUILD.gn +++ b/services/security_component_service/sa/test/BUILD.gn @@ -34,6 +34,7 @@ ohos_unittest("sec_comp_service_test") { "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/app_state_observer.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/delay_exit_task.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/first_use_dialog.cpp", + "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_dialog_callback_proxy.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_entity.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_malicious_apps.cpp", @@ -108,10 +109,12 @@ ohos_unittest("sec_comp_service_mock_test") { ] sources = [ + #"${sec_comp_root_dir}/interfaces/inner_api/security_component/src/sec_comp_dialog_callback_stub.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/app_mgr_death_recipient.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/app_state_observer.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/delay_exit_task.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/first_use_dialog.cpp", + "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_dialog_callback_proxy.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_entity.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp", "${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_malicious_apps.cpp", diff --git a/services/security_component_service/sa/test/mock/include/accesstoken_kit.h b/services/security_component_service/sa/test/mock/include/accesstoken_kit.h index 52f7fb767184f53aa11309c2063081110e0e3c94..d0f249999bab99ce6d3b161f196636f2721ec953 100644 --- a/services/security_component_service/sa/test/mock/include/accesstoken_kit.h +++ b/services/security_component_service/sa/test/mock/include/accesstoken_kit.h @@ -27,6 +27,11 @@ namespace AccessToken { struct HapTokenInfo { }; +typedef enum TypePermissionState { + PERMISSION_DENIED = -1, + PERMISSION_GRANTED = 0, +} PermissionState; + class AccessTokenKit { public: static int RevokePermission(AccessTokenID tokenID, const std::string& permissionName, int flag); diff --git a/services/security_component_service/sa/test/unittest/src/first_use_dialog_test.cpp b/services/security_component_service/sa/test/unittest/src/first_use_dialog_test.cpp index f262416ed1e935fc4b4537843bb1be72c198750f..dc9f1cb8ceca824573d25b78c1bca907cbca5956 100644 --- a/services/security_component_service/sa/test/unittest/src/first_use_dialog_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/first_use_dialog_test.cpp @@ -15,8 +15,11 @@ #include "first_use_dialog_test.h" #include "accesstoken_kit.h" +#include "location_button.h" +#include "save_button.h" #include "sec_comp_log.h" #include "sec_comp_err.h" +#include "sec_event_handler.h" using namespace testing::ext; using namespace OHOS; @@ -342,34 +345,126 @@ HWTEST_F(FirstUseDialogTest, NotifyFirstUseDialog001, TestSize.Level1) { FirstUseDialog diag; diag.secHandler_ = nullptr; + + // no entity + EXPECT_EQ(diag.NotifyFirstUseDialog(nullptr, nullptr, nullptr), SC_SERVICE_ERROR_VALUE_INVALID); + + std::shared_ptr entity = std::make_shared(nullptr, 0, 0, 0, 0); // no handler - ASSERT_FALSE(diag.NotifyFirstUseDialog(0, LOCATION_COMPONENT, nullptr)); + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, nullptr, nullptr), SC_SERVICE_ERROR_VALUE_INVALID); // no calltoken std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); ASSERT_NE(nullptr, runner); std::shared_ptr handler = std::make_shared(runner); diag.secHandler_ = handler; - ASSERT_FALSE(diag.NotifyFirstUseDialog(0, LOCATION_COMPONENT, nullptr)); + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, nullptr, nullptr), SC_SERVICE_ERROR_VALUE_INVALID); - // type invalid + // no dialogCallback sptr testRemoteObject = new TestRemoteObject(std::u16string()); - ASSERT_FALSE(diag.NotifyFirstUseDialog(0, PASTE_COMPONENT, testRemoteObject)); + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, nullptr), SC_SERVICE_ERROR_VALUE_INVALID); + + // type invalid + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject), SC_OK); // first use location button - ASSERT_TRUE(diag.NotifyFirstUseDialog(0, LOCATION_COMPONENT, testRemoteObject)); - ASSERT_EQ(LOCATION_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); + entity->componentInfo_ = std::make_shared(); + entity->componentInfo_->type_ = LOCATION_COMPONENT; + entity->tokenId_ = 0; + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject), + SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); + EXPECT_EQ(LOCATION_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); // first use save button - ASSERT_TRUE(diag.NotifyFirstUseDialog(0, SAVE_COMPONENT, testRemoteObject)); - ASSERT_EQ(LOCATION_BUTTON_FIRST_USE | SAVE_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); + entity->componentInfo_->type_ = SAVE_COMPONENT; + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject), + SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); + EXPECT_EQ(LOCATION_BUTTON_FIRST_USE | SAVE_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); // second use save button - ASSERT_TRUE(diag.NotifyFirstUseDialog(0, SAVE_COMPONENT, testRemoteObject)); - ASSERT_EQ(LOCATION_BUTTON_FIRST_USE | SAVE_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject), SC_OK); + EXPECT_EQ(LOCATION_BUTTON_FIRST_USE | SAVE_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); - diag.StartDialogAbility(PASTE_COMPONENT, nullptr); + diag.StartDialogAbility(entity, testRemoteObject, testRemoteObject); // wait for event handler done sleep(3); } + +/* + * @tc.name: GrantDialogWaitEntity001 + * @tc.desc: Test GrantDialogWaitEntity + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FirstUseDialogTest, GrantDialogWaitEntity001, TestSize.Level1) +{ + FirstUseDialog diag; + EXPECT_EQ(diag.GrantDialogWaitEntity(0), SC_SERVICE_ERROR_COMPONENT_NOT_EXIST); + + diag.dialogWaitMap_[0] = nullptr; + EXPECT_EQ(diag.GrantDialogWaitEntity(0), SC_SERVICE_ERROR_COMPONENT_NOT_EXIST); + + std::shared_ptr entity = std::make_shared(nullptr, 1, 0, 0, 0); + diag.dialogWaitMap_[0] = entity; + EXPECT_EQ(diag.GrantDialogWaitEntity(0), SC_SERVICE_ERROR_PERMISSION_OPER_FAIL); + + std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); + ASSERT_NE(runner, nullptr); + + std::shared_ptr handler = std::make_shared(runner); + SecCompPermManager::GetInstance().InitEventHandler(handler); + entity->componentInfo_ = std::make_shared(); + entity->componentInfo_->type_ = SAVE_COMPONENT; + diag.dialogWaitMap_[1] = entity; + EXPECT_EQ(diag.GrantDialogWaitEntity(1), SC_OK); +} + +/* + * @tc.name: RemoveDialogWaitEntitys001 + * @tc.desc: Test RemoveDialogWaitEntitys + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FirstUseDialogTest, RemoveDialogWaitEntitys001, TestSize.Level1) +{ + FirstUseDialog diag; + std::shared_ptr entity = std::make_shared(nullptr, 0, 0, 0, 0); + std::shared_ptr entity1 = std::make_shared(nullptr, 0, 0, 1, 0); + diag.dialogWaitMap_[0] = entity; + diag.dialogWaitMap_[1] = entity1; + diag.RemoveDialogWaitEntitys(1); + EXPECT_EQ(diag.dialogWaitMap_.count(1), 0); +} + +/* + * @tc.name: SecCompDialogSrvCallback001 + * @tc.desc: Test SecCompDialogSrvCallback + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FirstUseDialogTest, SecCompDialogSrvCallback001, TestSize.Level1) +{ + SecCompDialogSrvCallback *call = new (std::nothrow)SecCompDialogSrvCallback(0, nullptr); + sptr srvCallback = call; + + MessageParcel data; + MessageParcel reply; + MessageOption option; + EXPECT_EQ(srvCallback->OnRemoteRequest(ISecCompDialogCallback::ON_DIALOG_CLOSED, data, reply, option), + SC_SERVICE_ERROR_IPC_REQUEST_FAIL); + + data.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor()); + EXPECT_EQ(srvCallback->OnRemoteRequest(ISecCompDialogCallback::ON_DIALOG_CLOSED, data, reply, option), + SC_SERVICE_ERROR_IPC_REQUEST_FAIL); + + MessageParcel data1; + data1.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor()); + data1.WriteInt32(0); + EXPECT_EQ(srvCallback->OnRemoteRequest(ISecCompDialogCallback::ON_DIALOG_CLOSED, data1, reply, option), + 0); + + MessageParcel data2; + data2.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor()); + EXPECT_NE(srvCallback->OnRemoteRequest(-1, data2, reply, option), 0); +} 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 3ae3e0a0aa7fa3b5d656a599c86c565f9570fc80..2243578f9a3d2bd9d568c3f04355d3399bbff106 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 @@ -50,7 +50,7 @@ void SecCompEntityTest::SetUp() std::shared_ptr component = std::make_shared(); ASSERT_NE(nullptr, component); - entity_ = std::make_shared(component, 1, 1); + entity_ = std::make_shared(component, 1, 1, 1, 1); ASSERT_NE(nullptr, entity_); Rosen::WindowManager::GetInstance().SetDefaultSecCompScene(); @@ -96,7 +96,7 @@ HWTEST_F(SecCompEntityTest, GrantTempPermission002, TestSize.Level1) std::shared_ptr pasteComponent = std::make_shared(); ASSERT_NE(nullptr, pasteComponent); - entity_ = std::make_shared(pasteComponent, 0, 1); + entity_ = std::make_shared(pasteComponent, 0, 1, 1, 1); ASSERT_NE(nullptr, entity_); ASSERT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL, entity_->GrantTempPermission()); 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 25f5d7f3392aba6897e780b5a2e14c6ead8308b5..e659faf11eb080c648b04bfe2589dabbc1b4d738 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 @@ -142,7 +142,9 @@ HWTEST_F(SecCompManagerTest, AddSecurityComponentToList001, TestSize.Level1) compPtr->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.width_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.height_ = ServiceTestCommon::TEST_COORDINATE; - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); ASSERT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(1, 0, entity)); @@ -152,7 +154,9 @@ HWTEST_F(SecCompManagerTest, AddSecurityComponentToList001, TestSize.Level1) compPtrNew->rect_.y_ = ServiceTestCommon::TEST_COORDINATE * 2; // not overlap compPtrNew->rect_.width_ = ServiceTestCommon::TEST_COORDINATE; compPtrNew->rect_.height_ = ServiceTestCommon::TEST_COORDINATE; - SecCompEntity entityNew(compPtrNew, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_2); + std::shared_ptr entityNew = + std::make_shared( + compPtrNew, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_2, 1, 1); ASSERT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(1, 0, entityNew)); } @@ -167,7 +171,9 @@ HWTEST_F(SecCompManagerTest, AddSecurityComponentToList002, TestSize.Level1) bool isSaExit = SecCompManager::GetInstance().isSaExit_; std::shared_ptr compPtr = std::make_shared(); ASSERT_NE(nullptr, compPtr); - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); ASSERT_NE(SC_SERVICE_ERROR_SERVICE_NOT_EXIST, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_1, 0, entity)); @@ -191,7 +197,9 @@ HWTEST_F(SecCompManagerTest, DeleteSecurityComponentFromList001, TestSize.Level1 compPtr->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.width_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.height_ = ServiceTestCommon::TEST_COORDINATE; - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); ASSERT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_1, 0, entity)); @@ -219,7 +227,9 @@ HWTEST_F(SecCompManagerTest, GetSecurityComponentFromList001, TestSize.Level1) compPtr->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.width_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.height_ = ServiceTestCommon::TEST_COORDINATE; - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); ASSERT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_1, 0, entity)); ASSERT_EQ(nullptr, SecCompManager::GetInstance().GetSecurityComponentFromList( @@ -244,7 +254,9 @@ HWTEST_F(SecCompManagerTest, NotifyProcessBackground001, TestSize.Level1) compPtr->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.width_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.height_ = ServiceTestCommon::TEST_COORDINATE; - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); ASSERT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_1, 0, entity)); auto component = SecCompManager::GetInstance().GetSecurityComponentFromList( @@ -272,7 +284,9 @@ HWTEST_F(SecCompManagerTest, NotifyProcessDied001, TestSize.Level1) compPtr->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.width_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.height_ = ServiceTestCommon::TEST_COORDINATE; - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); ASSERT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_1, 0, entity)); @@ -282,7 +296,9 @@ HWTEST_F(SecCompManagerTest, NotifyProcessDied001, TestSize.Level1) compPtr2->rect_.y_ = ServiceTestCommon::TEST_COORDINATE * 2; // not overlap compPtr2->rect_.width_ = ServiceTestCommon::TEST_COORDINATE; compPtr2->rect_.height_ = ServiceTestCommon::TEST_COORDINATE; - SecCompEntity entity2(compPtr2, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_2); + std::shared_ptr entity2 = + std::make_shared( + compPtr2, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_2, 1, 1); ASSERT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_2, 0, entity2)); @@ -352,7 +368,9 @@ HWTEST_F(SecCompManagerTest, UpdateSecurityComponent001, TestSize.Level1) std::shared_ptr compPtr = std::make_shared(); compPtr->type_ = LOCATION_COMPONENT; - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); EXPECT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_1, 0, entity)); @@ -402,8 +420,10 @@ HWTEST_F(SecCompManagerTest, ReportSecurityComponentClickEvent001, TestSize.Leve nlohmann::json jsonVaild; LocationButton buttonValid = BuildValidLocationComponent(); buttonValid.ToJson(jsonVaild); + std::vector> remote = { nullptr, nullptr }; ASSERT_NE(SC_OK, - SecCompManager::GetInstance().ReportSecurityComponentClickEvent(1, jsonVaild, caller, clickInfo, nullptr)); + SecCompManager::GetInstance().ReportSecurityComponentClickEvent(1, + jsonVaild, caller, clickInfo, remote)); } /** @@ -417,7 +437,9 @@ HWTEST_F(SecCompManagerTest, AddSecurityComponentToList004, TestSize.Level1) std::shared_ptr managerInstance = std::make_shared(); managerInstance->isSaExit_ = false; int pid = 1; - SecCompEntity entity(nullptr, 0, 0); + std::shared_ptr entity = + std::make_shared( + nullptr, 0, 0, 1, 1); const int MAX_COMPONENT_SIZE = 500; for (int i = 0; i < MAX_COMPONENT_SIZE; i++) { managerInstance->componentMap_[pid].compList.emplace_back(entity); @@ -441,7 +463,9 @@ HWTEST_F(SecCompManagerTest, CheckClickSecurityComponentInfo001, TestSize.Level1 std::shared_ptr compPtr = std::make_shared(); ASSERT_NE(nullptr, compPtr); - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); ASSERT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_1, 0, entity)); @@ -450,17 +474,18 @@ HWTEST_F(SecCompManagerTest, CheckClickSecurityComponentInfo001, TestSize.Level1 LocationButton buttonValid = BuildValidLocationComponent(); buttonValid.ToJson(jsonVaild); jsonVaild[JsonTagConstants::JSON_SC_TYPE] = UNKNOWN_SC_TYPE; + std::vector> remote = { nullptr, nullptr }; ASSERT_EQ(SC_SERVICE_ERROR_COMPONENT_INFO_INVALID, SecCompManager::GetInstance().ReportSecurityComponentClickEvent( - ServiceTestCommon::TEST_SC_ID_1, jsonVaild, caller, clickInfo, nullptr)); + ServiceTestCommon::TEST_SC_ID_1, jsonVaild, caller, clickInfo, remote)); 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, nullptr)); + ServiceTestCommon::TEST_SC_ID_1, jsonVaild, caller, clickInfo, remote)); 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, nullptr)); + ServiceTestCommon::TEST_SC_ID_1, jsonVaild, caller, clickInfo, remote)); } /** @@ -473,7 +498,9 @@ HWTEST_F(SecCompManagerTest, AddSecurityComponentToList003, TestSize.Level1) { SecCompManager::GetInstance().isSaExit_ = true; std::shared_ptr compPtr = std::make_shared(); - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); ASSERT_EQ(SC_SERVICE_ERROR_SERVICE_NOT_EXIST, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_1, 0, entity)); SecCompManager::GetInstance().isSaExit_ = false; @@ -493,7 +520,9 @@ HWTEST_F(SecCompManagerTest, DeleteSecurityComponentFromList002, TestSize.Level1 compPtr->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.width_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.height_ = ServiceTestCommon::TEST_COORDINATE; - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); ASSERT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_1, 0, entity)); @@ -539,7 +568,9 @@ HWTEST_F(SecCompManagerTest, ExitSaProcess001, TestSize.Level1) compPtr->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.width_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.height_ = ServiceTestCommon::TEST_COORDINATE; - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); std::shared_ptr instance = std::make_shared(); ASSERT_EQ(SC_OK, instance->AddSecurityComponentToList(ServiceTestCommon::TEST_PID_1, 0, entity)); @@ -580,7 +611,9 @@ HWTEST_F(SecCompManagerTest, ExitWhenAppMgrDied001, TestSize.Level1) compPtr->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.width_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.height_ = ServiceTestCommon::TEST_COORDINATE; - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); std::shared_ptr saClient = std::make_shared(); ASSERT_NE(nullptr, saClient); @@ -637,7 +670,9 @@ HWTEST_F(SecCompManagerTest, DumpSecComp001, TestSize.Level1) compPtr->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.width_ = ServiceTestCommon::TEST_COORDINATE; compPtr->rect_.height_ = ServiceTestCommon::TEST_COORDINATE; - SecCompEntity entity(compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1); + std::shared_ptr entity = + std::make_shared( + compPtr, ServiceTestCommon::TEST_TOKEN_ID, ServiceTestCommon::TEST_SC_ID_1, 1, 1); SecCompManager::GetInstance().isSaExit_ = false; ASSERT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_1, 0, entity)); 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 f6f2c37127de7817c64f4e867b2dba817cb55df4..a7ddbb785f8594d8658425b7cf9fafd5559de21c 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 @@ -152,3 +152,19 @@ HWTEST_F(SecCompPermManagerTest, RevokeAppPermission001, TestSize.Level1) AccessTokenID id = 0; ASSERT_EQ(permMgr.RevokeAppPermission(id, "test"), 0); } + +/** + * @tc.name: VerifyPermission001 + * @tc.desc: Test VerifyPermission + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(SecCompPermManagerTest, VerifyPermission001, TestSize.Level1) +{ + SecCompPermManager permMgr; + AccessTokenID id = 1000; + ASSERT_FALSE(permMgr.VerifyPermission(id, LOCATION_COMPONENT)); + ASSERT_FALSE(permMgr.VerifyPermission(id, PASTE_COMPONENT)); + ASSERT_FALSE(permMgr.VerifyPermission(id, SAVE_COMPONENT)); + ASSERT_FALSE(permMgr.VerifyPermission(id, static_cast(-1))); +} 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 92f07925330d67c1bde6b3466edfa58caa25c939..70f1a23e9339bb58d1ffa477354be8e0de35e6c8 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 @@ -114,7 +114,7 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent001, TestSize.Level1) }, }; - EXPECT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr)); + EXPECT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr, nullptr)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); SecCompPermManager::GetInstance().applySaveCountMap_.clear(); } @@ -149,7 +149,7 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent002, TestSize.Level1) std::chrono::high_resolution_clock::now().time_since_epoch().count()) }; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, - secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr)); + secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr, nullptr)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); SecCompPermManager::GetInstance().applySaveCountMap_.clear(); } @@ -190,7 +190,7 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent003, TestSize.Level1) }, }; EXPECT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL, - secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr)); + secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, touch, nullptr, nullptr)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); SecCompPermManager::GetInstance().applySaveCountMap_.clear(); } @@ -231,7 +231,7 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent001, TestSize. }, }; - ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, nullptr)); + ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, nullptr, nullptr)); // test 10s valid ASSERT_TRUE(secCompService_->VerifySavePermission(ServiceTestCommon::HAP_TOKEN_ID)); @@ -242,11 +242,11 @@ 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)); + ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, nullptr, nullptr)); 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)); + ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, saveInfo, clickInfo, nullptr, nullptr)); sleep(8); ASSERT_TRUE(secCompService_->VerifySavePermission(ServiceTestCommon::HAP_TOKEN_ID)); sleep(2); @@ -290,7 +290,8 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent002, TestSize. }, }; - ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo1, nullptr)); + ASSERT_EQ(SC_OK, + secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, clickInfo1, nullptr, nullptr)); // 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 08978d1bffde7ef3d0cd29aaff4f6d91eb0a514e..de46e83f8de25ba1f2ba9fd7998dc4ca6242a39c 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 @@ -274,7 +274,7 @@ HWTEST_F(SecCompServiceTest, ReportSecurityComponentClickEvent001, TestSize.Leve .extraInfo.dataSize = 16, }; EXPECT_EQ(SC_OK, - secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, touch, nullptr)); + secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, touch, nullptr, nullptr)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); setuid(uid); } @@ -363,7 +363,7 @@ 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), + EXPECT_EQ(secCompService_->ReportSecurityComponentClickEvent(scId, componentInfo, touchInfo, nullptr, nullptr), 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 03a6862c5cc783b64ed846f78c9ccd4122f0547f..022d53334eebaf8e6172d09fdaf427479b88d31d 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 @@ -44,7 +44,8 @@ public: }; int32_t ReportSecurityComponentClickEvent(int32_t scId, const std::string& componentInfo, - const SecCompClickEvent& clickInfo, sptr callerToken) override + const SecCompClickEvent& clickInfo, sptr callerToken, + sptr dialogCall) 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 438c1f56d72b1fdbe6e811641eddc92d58733c19..2c2c1c32847ed47a077b5a6af36cfa7038063cce 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,7 @@ public: }; int32_t ReportSecurityComponentClickEvent(int32_t scId, const std::string& componentInfo, - const SecCompClickEvent& clickInfo, sptr callerToken) override + const SecCompClickEvent& clickInfo, sptr callerToken, sptr dialogCall) override { return 0; }; diff --git a/test/fuzztest/security_component/reportsecuritycomponentclickevent_fuzzer/reportsecuritycomponentclickevent_fuzzer.cpp b/test/fuzztest/security_component/reportsecuritycomponentclickevent_fuzzer/reportsecuritycomponentclickevent_fuzzer.cpp index fb8770a762bbf3b0236c1216b6fa4b5052e2865b..04e2f018b8cedf8d20673a754e8c4fa20940566d 100644 --- a/test/fuzztest/security_component/reportsecuritycomponentclickevent_fuzzer/reportsecuritycomponentclickevent_fuzzer.cpp +++ b/test/fuzztest/security_component/reportsecuritycomponentclickevent_fuzzer/reportsecuritycomponentclickevent_fuzzer.cpp @@ -39,7 +39,8 @@ static void ReportSecurityComponentClickEventFuzzTest(const uint8_t *data, size_ clickInfo.point.timestamp = timesStamp; clickInfo.extraInfo.data = data1; clickInfo.extraInfo.dataSize = size; - SecCompKit::ReportSecurityComponentClickEvent(size, componentInfo, clickInfo); + OnFirstUseDialogCloseFunc func = [] (int32_t) {}; + SecCompKit::ReportSecurityComponentClickEvent(size, componentInfo, clickInfo, nullptr, std::move(func)); } } // namespace OHOS