From a8ff10d8bd2c330c77cee01874a3c948fbe7df4c Mon Sep 17 00:00:00 2001 From: baoyang Date: Wed, 19 Feb 2025 11:22:07 +0800 Subject: [PATCH] fit multiton Signed-off-by: baoyang Change-Id: I0cd5a74223d440851583c13f9f594d24c9bcc9b8 --- .../sa/sa_main/first_use_dialog.cpp | 12 ++++++----- .../sa/sa_main/first_use_dialog.h | 11 ++++++++-- .../sa/sa_main/sec_comp_manager.cpp | 7 +++++-- .../unittest/src/first_use_dialog_test.cpp | 20 ++++++++++--------- .../mock/first_use_dialog.cpp | 4 ++-- 5 files changed, 34 insertions(+), 20 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 b2a06f1..302056a 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 96e1bc4..ade6495 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 98e41de..10eee09 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 d0a5901..e12e575 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 f00a853..c92da8c 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; } -- Gitee