From 85ad401aea2db266049962e194709b76c14873cc Mon Sep 17 00:00:00 2001 From: Haryslee Date: Fri, 13 Jun 2025 10:03:55 +0800 Subject: [PATCH] fix: change the behavior of dialog of location button Signed-off-by: Haryslee --- .../sa/sa_main/first_use_dialog.cpp | 8 ++++--- .../unittest/src/first_use_dialog_test.cpp | 23 ++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) 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 7ee7671..2680e09 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 @@ -467,8 +467,10 @@ bool FirstUseDialog::SetFirstUseMap(std::shared_ptr entity) SecCompType type = entity->GetType(); if (type == LOCATION_COMPONENT) { - typeMask = LOCATION_BUTTON_FIRST_USE; - } else if (type == SAVE_COMPONENT) { + SC_LOG_INFO(LABEL, "LocationButton need not notify dialog to user."); + return true; + } + if (type == SAVE_COMPONENT) { typeMask = SAVE_BUTTON_FIRST_USE; } else { SC_LOG_INFO(LABEL, "This type need not notify dialog to user."); @@ -531,7 +533,7 @@ int32_t FirstUseDialog::NotifyFirstUseDialog(std::shared_ptr enti } uint64_t compTypes = firstUseMap_[tokenId]; - if ((compTypes & typeMask) == typeMask) { + if ((typeMask == SAVE_BUTTON_FIRST_USE) && ((compTypes & typeMask) == typeMask)) { SC_LOG_INFO(LABEL, "no need notify dialog again."); StartToastAbility(entity, callerToken, displayInfo); return SC_OK; 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 c63f294..260b40e 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 @@ -398,16 +398,16 @@ HWTEST_F(FirstUseDialogTest, SetFirstUseMap001, TestSize.Level0) entity->componentInfo_->type_ = LOCATION_COMPONENT; entity->tokenId_ = 0; EXPECT_EQ(diag.SetFirstUseMap(entity), true); - EXPECT_EQ(LOCATION_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); + EXPECT_NE(LOCATION_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); // first use save button entity->componentInfo_->type_ = SAVE_COMPONENT; EXPECT_EQ(diag.SetFirstUseMap(entity), true); - EXPECT_EQ(LOCATION_BUTTON_FIRST_USE | SAVE_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); + EXPECT_EQ(SAVE_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); // second use save button EXPECT_EQ(diag.SetFirstUseMap(entity), true); - EXPECT_EQ(LOCATION_BUTTON_FIRST_USE | SAVE_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); + EXPECT_EQ(SAVE_BUTTON_FIRST_USE, static_cast(diag.firstUseMap_[0])); // wait for event handler done sleep(3); @@ -460,7 +460,17 @@ HWTEST_F(FirstUseDialogTest, NotifyFirstUseDialog001, TestSize.Level0) SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); EXPECT_EQ(0, static_cast(diag.firstUseMap_[0])); + diag.firstUseMap_[0] = LOCATION_BUTTON_FIRST_USE; + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo), + SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); + + diag.firstUseMap_[0] = SAVE_BUTTON_FIRST_USE; + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo), + SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); + // first use save button + diag.firstUseMap_[0] = 0; + entity->componentInfo_ = std::make_shared(); entity->componentInfo_->type_ = SAVE_COMPONENT; EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo), SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); @@ -471,6 +481,13 @@ HWTEST_F(FirstUseDialogTest, NotifyFirstUseDialog001, TestSize.Level0) SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); EXPECT_EQ(0, static_cast(diag.firstUseMap_[0])); + diag.firstUseMap_[0] = SAVE_BUTTON_FIRST_USE; + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo), SC_OK); + + diag.firstUseMap_[0] = LOCATION_BUTTON_FIRST_USE; + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo), + SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); + diag.StartDialogAbility(entity, testRemoteObject, testRemoteObject, displayInfo); // wait for event handler done -- Gitee