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 b2a06f18339c041c010ebbb162ad1d2e518a7666..302056adebd7edbb95ff0910e12e4ac291f664d8 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 @@ -48,6 +48,7 @@ const std::string GRANT_ABILITY_ABILITY_NAME = "com.ohos.permissionmanager.Secur 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"; +const std::string WINDOW_ID_KEY = "ohos.ability.params.windowId"; const std::string CALLER_UID_KEY = "ohos.caller.uid"; const std::string DISPLAY_WIDTH = "ohos.display.width"; const std::string DISPLAY_HEIGHT = "ohos.display.height"; @@ -334,7 +335,7 @@ bool FirstUseDialog::GetDialogInfo(AAFwk::Want& want, const uint64_t displayId, } void FirstUseDialog::StartDialogAbility(std::shared_ptr entity, sptr callerToken, - sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState) + sptr dialogCallback, const DisplayInfo& displayInfo) { int32_t typeNum; SecCompType type = entity->GetType(); @@ -359,9 +360,10 @@ void FirstUseDialog::StartDialogAbility(std::shared_ptr entity, s want.SetParam(TYPE_KEY, typeNum); want.SetParam(TOKEN_KEY, callerToken); want.SetParam(CALLBACK_KEY, srvCallback); + want.SetParam(WINDOW_ID_KEY, displayInfo.windowId); int32_t uid = IPCSkeleton::GetCallingUid(); want.SetParam(CALLER_UID_KEY, uid); - if (!GetDialogInfo(want, displayId, crossAxisState)) { + if (!GetDialogInfo(want, displayInfo.displayId, displayInfo.crossAxisState)) { SC_LOG_ERROR(LABEL, "Get display info failed."); return; } @@ -416,7 +418,7 @@ bool FirstUseDialog::SetFirstUseMap(std::shared_ptr entity) } int32_t FirstUseDialog::NotifyFirstUseDialog(std::shared_ptr entity, sptr callerToken, - sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState) + sptr dialogCallback, const DisplayInfo& displayInfo) { if (entity == nullptr) { SC_LOG_ERROR(LABEL, "Entity is invalid."); @@ -452,7 +454,7 @@ int32_t FirstUseDialog::NotifyFirstUseDialog(std::shared_ptr enti auto iter = firstUseMap_.find(tokenId); if (iter == firstUseMap_.end()) { SC_LOG_INFO(LABEL, "has not use record, start dialog"); - StartDialogAbility(entity, callerToken, dialogCallback, displayId, crossAxisState); + StartDialogAbility(entity, callerToken, dialogCallback, displayInfo); return SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE; } @@ -461,7 +463,7 @@ int32_t FirstUseDialog::NotifyFirstUseDialog(std::shared_ptr enti SC_LOG_INFO(LABEL, "no need notify again."); return SC_OK; } - StartDialogAbility(entity, callerToken, dialogCallback, displayId, crossAxisState); + StartDialogAbility(entity, callerToken, dialogCallback, displayInfo); return SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE; } 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 96e1bc4e425aef77815a4729908a1a2078080f05..ade64952711225df38d9b383a766bd2b1344b64e 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 @@ -15,6 +15,7 @@ #ifndef FIRST_USE_DIALOG_H #define FIRST_USE_DIALOG_H +#include #include #include #include @@ -51,11 +52,17 @@ private: class FirstUseDialog final { public: +struct DisplayInfo { + const uint64_t displayId; + const CrossAxisState crossAxisState; + const int32_t windowId; +}; + static FirstUseDialog& GetInstance(); ~FirstUseDialog() = default; int32_t NotifyFirstUseDialog(std::shared_ptr entity, sptr callerToken, - sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState); + sptr dialogCallback, const DisplayInfo& displayInfo); void Init(std::shared_ptr secHandler); int32_t GrantDialogWaitEntity(int32_t scId); void RemoveDialogWaitEntitys(int32_t pid); @@ -74,7 +81,7 @@ private: void LoadFirstUseRecord(void); void SaveFirstUseRecord(void); void StartDialogAbility(std::shared_ptr entity, sptr callerToken, - sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState); + sptr dialogCallback, const DisplayInfo& displayInfo); bool GetDialogInfo(AAFwk::Want& want, const uint64_t displayId, const CrossAxisState crossAxisState); void SendSaveEventHandler(void); 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 98e41dec86b5adeec63b65f4332e2c6de5db44fb..10eee0952da862c4e2490b21a09c33702d59fee2 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 @@ -19,6 +19,7 @@ #include "display.h" #include "display_info.h" #include "display_manager.h" +#include "first_use_dialog.h" #include "hisysevent.h" #include "i_sec_comp_service.h" #include "ipc_skeleton.h" @@ -563,8 +564,10 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(SecCompInfo& info, con return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } - if (FirstUseDialog::GetInstance().NotifyFirstUseDialog(sc, remote[0], remote[1], report->displayId_, - report->crossAxisState_) == SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE) { + const FirstUseDialog::DisplayInfo displayInfo = {report->displayId_, report->crossAxisState_, report->windowId_}; + + if (FirstUseDialog::GetInstance().NotifyFirstUseDialog(sc, remote[0], remote[1], displayInfo) == + 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; } 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 d0a5901147127a14b0ddc4c6e8c367b518866b77..e12e575e6a9800a48365ac34cab936e94e2d2b7b 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 @@ -406,13 +406,15 @@ HWTEST_F(FirstUseDialogTest, NotifyFirstUseDialog001, TestSize.Level1) FirstUseDialog diag; diag.secHandler_ = nullptr; + const FirstUseDialog::DisplayInfo displayInfo = {0, CrossAxisState::STATE_INVALID, 0}; + // no entity - EXPECT_EQ(diag.NotifyFirstUseDialog(nullptr, nullptr, nullptr, 0, CrossAxisState::STATE_INVALID), + EXPECT_EQ(diag.NotifyFirstUseDialog(nullptr, nullptr, nullptr, displayInfo), SC_SERVICE_ERROR_VALUE_INVALID); std::shared_ptr entity = std::make_shared(nullptr, 0, 0, 0, 0); // no handler - EXPECT_EQ(diag.NotifyFirstUseDialog(entity, nullptr, nullptr, 0, CrossAxisState::STATE_INVALID), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, nullptr, nullptr, displayInfo), SC_SERVICE_ERROR_VALUE_INVALID); // no calltoken @@ -420,38 +422,38 @@ HWTEST_F(FirstUseDialogTest, NotifyFirstUseDialog001, TestSize.Level1) ASSERT_NE(nullptr, runner); std::shared_ptr handler = std::make_shared(runner); diag.secHandler_ = handler; - EXPECT_EQ(diag.NotifyFirstUseDialog(entity, nullptr, nullptr, 0, CrossAxisState::STATE_INVALID), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, nullptr, nullptr, displayInfo), SC_SERVICE_ERROR_VALUE_INVALID); // no dialogCallback sptr testRemoteObject = new TestRemoteObject(std::u16string()); - EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, nullptr, 0, CrossAxisState::STATE_INVALID), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, nullptr, displayInfo), SC_SERVICE_ERROR_VALUE_INVALID); // type invalid - EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, 0, CrossAxisState::STATE_INVALID), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo), SC_OK); // first use location button entity->componentInfo_ = std::make_shared(); entity->componentInfo_->type_ = LOCATION_COMPONENT; entity->tokenId_ = 0; - EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, 0, CrossAxisState::STATE_INVALID), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo), SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); EXPECT_EQ(0, static_cast(diag.firstUseMap_[0])); // first use save button entity->componentInfo_->type_ = SAVE_COMPONENT; - EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, 0, CrossAxisState::STATE_INVALID), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo), SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); EXPECT_EQ(0, static_cast(diag.firstUseMap_[0])); // second use save button - EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, 0, CrossAxisState::STATE_INVALID), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo), SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); EXPECT_EQ(0, static_cast(diag.firstUseMap_[0])); - diag.StartDialogAbility(entity, testRemoteObject, testRemoteObject, 0, CrossAxisState::STATE_INVALID); + diag.StartDialogAbility(entity, testRemoteObject, testRemoteObject, displayInfo); // wait for event handler done sleep(3); diff --git a/test/fuzztest/security_component/mock/first_use_dialog.cpp b/test/fuzztest/security_component/mock/first_use_dialog.cpp index f00a8533a4df8e23bb632b4b5f9b555e4965e142..c92da8c3ab0762bd1628ae4d77216125ca5ba92f 100644 --- a/test/fuzztest/security_component/mock/first_use_dialog.cpp +++ b/test/fuzztest/security_component/mock/first_use_dialog.cpp @@ -86,7 +86,7 @@ int32_t FirstUseDialog::GrantDialogWaitEntity(int32_t scId) } void FirstUseDialog::StartDialogAbility(std::shared_ptr entity, sptr callerToken, - sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState) + sptr dialogCallback, const DisplayInfo& displayInfo) { return; } @@ -102,7 +102,7 @@ bool FirstUseDialog::SetFirstUseMap(std::shared_ptr entity) } int32_t FirstUseDialog::NotifyFirstUseDialog(std::shared_ptr entity, sptr callerToken, - sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState) + sptr dialogCallback, const DisplayInfo& displayInfo) { return SC_OK; }