diff --git a/frameworks/inner_api/security_component/include/i_sec_comp_dialog_callback.h b/frameworks/inner_api/security_component/include/i_sec_comp_dialog_callback.h index 805c3cab3cf7fd4b47fef779dfe16fb995e73629..c981ac3321cc7266756278cbd942e06a0e8f8910 100644 --- a/frameworks/inner_api/security_component/include/i_sec_comp_dialog_callback.h +++ b/frameworks/inner_api/security_component/include/i_sec_comp_dialog_callback.h @@ -26,6 +26,8 @@ public: virtual void OnDialogClosed(int32_t result) = 0; enum InterfaceCode { ON_DIALOG_CLOSED = 0, + ON_DIALOG_FAILED = 1, + ON_DIALOG_CANCELED = 2, }; }; } // namespace SecurityComponent 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 597a96abea8b82e7acc7883c5c4628e7d575891c..f905317ec94574dd39b37737d1803f8fe68d3df3 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 @@ -28,6 +28,7 @@ #include "display_info.h" #include "display_manager.h" #include "hisysevent.h" +#include "i_sec_comp_dialog_callback.h" #include "ipc_skeleton.h" #include "sec_comp_dialog_callback_proxy.h" #include "sec_comp_err.h" @@ -99,13 +100,16 @@ bool ReportUserData(const std::string& filePath, const std::string& folderPath) 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; - } - if (!grantRes && !FirstUseDialog::GetInstance().SetFirstUseMap(sc_)) { - return; + int32_t grantRes = result; + if (result == ISecCompDialogCallback::ON_DIALOG_CLOSED) { + 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; + } + if (!grantRes && !FirstUseDialog::GetInstance().SetFirstUseMap(sc_)) { + return; + } } auto callback = iface_cast(dialogCallback_); if (callback != nullptr) { 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 9c1d12ed99d2e35d86abcf18e77f65841091a5e0..3f80bf33bff26d4eb3f2c09035297a3053ea35a6 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 @@ -16,6 +16,7 @@ #include #include "accesstoken_kit.h" +#include "i_sec_comp_dialog_callback.h" #include "location_button.h" #include "save_button.h" #include "sec_comp_log.h" @@ -567,6 +568,51 @@ HWTEST_F(FirstUseDialogTest, GrantDialogWaitEntity001, TestSize.Level0) EXPECT_EQ(diag.GrantDialogWaitEntity(1), SC_OK); } +/* + * @tc.name: OnDialogClosed001 + * @tc.desc: Test OnDialogClosed + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FirstUseDialogTest, OnDialogClosed001, TestSize.Level0) +{ + SecCompDialogSrvCallback *call = new (std::nothrow)SecCompDialogSrvCallback(0, nullptr, nullptr); + sptr srvCallback = call; + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + data.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor()); + data.WriteInt32(ISecCompDialogCallback::ON_DIALOG_FAILED); + EXPECT_EQ(srvCallback->OnRemoteRequest(ISecCompDialogCallback::ON_DIALOG_CLOSED, data, reply, option), 0); + + MessageParcel data1; + data1.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor()); + data1.WriteInt32(ISecCompDialogCallback::ON_DIALOG_CLOSED); + srvCallback->scId_ = 0; + FirstUseDialog::GetInstance().dialogWaitMap_[0] = nullptr; + EXPECT_EQ(srvCallback->OnRemoteRequest(ISecCompDialogCallback::ON_DIALOG_CLOSED, data1, reply, option), 0); + + std::shared_ptr entity = std::make_shared(nullptr, 1, 0, 0, 0); + FirstUseDialog::GetInstance().dialogWaitMap_[0] = entity; + data1.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor()); + data1.WriteInt32(ISecCompDialogCallback::ON_DIALOG_CLOSED); + EXPECT_EQ(srvCallback->OnRemoteRequest(ISecCompDialogCallback::ON_DIALOG_CLOSED, data1, reply, option), 0); + + 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; + FirstUseDialog::GetInstance().dialogWaitMap_[1] = entity; + srvCallback->scId_ = 1; + data1.WriteInterfaceToken(ISecCompDialogCallback::GetDescriptor()); + data1.WriteInt32(ISecCompDialogCallback::ON_DIALOG_CLOSED); + EXPECT_EQ(srvCallback->OnRemoteRequest(ISecCompDialogCallback::ON_DIALOG_CLOSED, data1, reply, option), 0); +} + /* * @tc.name: RemoveDialogWaitEntitys001 * @tc.desc: Test RemoveDialogWaitEntitys