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 7ee7671bfa1c82677a1f1790527bb024197d1f74..2680e099eb8ef2c2988eb757096d37a7ad7e4194 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 c63f294396a1a2f25234a36243f8f639d913fa0f..260b40e53d594e463bfb8b3557cc1c25e39115e1 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