From 3f97ab9daf260a6c1cc1684a0e38927bdba76166 Mon Sep 17 00:00:00 2001 From: baoyang Date: Mon, 31 Mar 2025 10:29:33 +0800 Subject: [PATCH] fix 5.1 difference Signed-off-by: baoyang Change-Id: I632e846acc31b3248fe214d12f29a9a92bcd6391 --- .../sa/sa_main/first_use_dialog.cpp | 12 +- .../sa/sa_main/first_use_dialog.h | 11 +- .../sa/sa_main/sec_comp_manager.cpp | 7 +- .../include/application_state_observer_stub.h | 2 +- .../unittest/src/first_use_dialog_test.cpp | 20 ++- .../src/sec_comp_info_helper_test.cpp | 3 - .../unittest/src/window_info_helper_test.cpp | 132 ------------------ .../mock/first_use_dialog.cpp | 4 +- 8 files changed, 21 insertions(+), 170 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 445c621..09e7dc6 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,7 +48,6 @@ 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"; @@ -335,7 +334,7 @@ bool FirstUseDialog::SetDialogInfo(AAFwk::Want& want, const uint64_t displayId, } void FirstUseDialog::StartDialogAbility(std::shared_ptr entity, sptr callerToken, - sptr dialogCallback, const DisplayInfo& displayInfo) + sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState) { int32_t typeNum; SecCompType type = entity->GetType(); @@ -360,10 +359,9 @@ 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 (!SetDialogInfo(want, displayInfo.displayId, displayInfo.crossAxisState)) { + if (!SetDialogInfo(want, displayId, crossAxisState)) { SC_LOG_ERROR(LABEL, "Set dialog info failed."); return; } @@ -418,7 +416,7 @@ bool FirstUseDialog::SetFirstUseMap(std::shared_ptr entity) } int32_t FirstUseDialog::NotifyFirstUseDialog(std::shared_ptr entity, sptr callerToken, - sptr dialogCallback, const DisplayInfo& displayInfo) + sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState) { if (entity == nullptr) { SC_LOG_ERROR(LABEL, "Entity is invalid."); @@ -454,7 +452,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, displayInfo); + StartDialogAbility(entity, callerToken, dialogCallback, displayId, crossAxisState); return SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE; } @@ -463,7 +461,7 @@ int32_t FirstUseDialog::NotifyFirstUseDialog(std::shared_ptr enti SC_LOG_INFO(LABEL, "no need notify again."); return SC_OK; } - StartDialogAbility(entity, callerToken, dialogCallback, displayInfo); + StartDialogAbility(entity, callerToken, dialogCallback, displayId, crossAxisState); 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 a705d60..255cd52 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,7 +15,6 @@ #ifndef FIRST_USE_DIALOG_H #define FIRST_USE_DIALOG_H -#include #include #include #include @@ -52,17 +51,11 @@ 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 DisplayInfo& displayInfo); + sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState); void Init(std::shared_ptr secHandler); int32_t GrantDialogWaitEntity(int32_t scId); void RemoveDialogWaitEntitys(int32_t pid); @@ -81,7 +74,7 @@ private: void LoadFirstUseRecord(void); void SaveFirstUseRecord(void); void StartDialogAbility(std::shared_ptr entity, sptr callerToken, - sptr dialogCallback, const DisplayInfo& displayInfo); + sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState); bool SetDialogInfo(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 1e5b618..15cbbbc 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,7 +19,6 @@ #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" @@ -578,10 +577,8 @@ int32_t SecCompManager::ReportSecurityComponentClickEvent(SecCompInfo& info, con return SC_SERVICE_ERROR_CLICK_EVENT_INVALID; } - 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) { + if (FirstUseDialog::GetInstance().NotifyFirstUseDialog(sc, remote[0], remote[1], report->displayId_, + report->crossAxisState_) == 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/mock/include/application_state_observer_stub.h b/services/security_component_service/sa/test/mock/include/application_state_observer_stub.h index 35c9890..aefcb3d 100644 --- a/services/security_component_service/sa/test/mock/include/application_state_observer_stub.h +++ b/services/security_component_service/sa/test/mock/include/application_state_observer_stub.h @@ -60,7 +60,7 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IApplicationStateObserver"); virtual void OnProcessStateChanged(const ProcessData &processData) {} virtual void OnProcessDied(const ProcessData &processData) = 0; - virtual void OnAppCacheStateChanged(const AppExecFwk::AppStateData &appStateData) = 0; + virtual void OnAppCacheStateChanged(const AppStateData &appStateData) = 0; }; class ApplicationStateObserverStub : public IRemoteStub { 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 e12e575..d0a5901 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,15 +406,13 @@ 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, displayInfo), + EXPECT_EQ(diag.NotifyFirstUseDialog(nullptr, nullptr, nullptr, 0, CrossAxisState::STATE_INVALID), 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, displayInfo), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, nullptr, nullptr, 0, CrossAxisState::STATE_INVALID), SC_SERVICE_ERROR_VALUE_INVALID); // no calltoken @@ -422,38 +420,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, displayInfo), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, nullptr, nullptr, 0, CrossAxisState::STATE_INVALID), SC_SERVICE_ERROR_VALUE_INVALID); // no dialogCallback sptr testRemoteObject = new TestRemoteObject(std::u16string()); - EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, nullptr, displayInfo), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, nullptr, 0, CrossAxisState::STATE_INVALID), SC_SERVICE_ERROR_VALUE_INVALID); // type invalid - EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, displayInfo), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, 0, CrossAxisState::STATE_INVALID), 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, displayInfo), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, 0, CrossAxisState::STATE_INVALID), 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, displayInfo), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, 0, CrossAxisState::STATE_INVALID), 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, displayInfo), + EXPECT_EQ(diag.NotifyFirstUseDialog(entity, testRemoteObject, testRemoteObject, 0, CrossAxisState::STATE_INVALID), SC_SERVICE_ERROR_WAIT_FOR_DIALOG_CLOSE); EXPECT_EQ(0, static_cast(diag.firstUseMap_[0])); - diag.StartDialogAbility(entity, testRemoteObject, testRemoteObject, displayInfo); + diag.StartDialogAbility(entity, testRemoteObject, testRemoteObject, 0, CrossAxisState::STATE_INVALID); // wait for event handler done sleep(3); diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp index 54d0452..fe68501 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_info_helper_test.cpp @@ -190,9 +190,6 @@ HWTEST_F(SecCompInfoHelperTest, ParseComponent004, TestSize.Level1) ASSERT_FALSE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); rect.y_ = g_testHeight; - - screenInfo.isWearable = true; - ASSERT_TRUE(SecCompInfoHelper::CheckRectValid(rect, windowRect, screenInfo, message)); } /** diff --git a/services/security_component_service/sa/test/unittest/src/window_info_helper_test.cpp b/services/security_component_service/sa/test/unittest/src/window_info_helper_test.cpp index 26dad8c..e28df80 100644 --- a/services/security_component_service/sa/test/unittest/src/window_info_helper_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/window_info_helper_test.cpp @@ -154,135 +154,3 @@ HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp003, TestSize.Level1) std::string message; ASSERT_TRUE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message)); } - -/** - * @tc.name: CheckOtherWindowCoverComp004 - * @tc.desc: Test component window is not covered - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp004, TestSize.Level1) -{ - WindowManager::GetInstance().result_ = WMError::WM_OK; - std::vector> list; - sptr compWin = new UnreliableWindowInfo(); - compWin->windowId_ = 1; - compWin->zOrder_ = 1; - compWin->floatingScale_ = 1.0; - compWin->windowRect_ = Rosen::Rect { - 0, 0, - ServiceTestCommon::TEST_COORDINATE + 2, ServiceTestCommon::TEST_COORDINATE + 2 - }; - list.emplace_back(compWin); - WindowManager::GetInstance().info_ = list; - - SecCompRect compRect = { - ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE, - ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE - }; - compRect.borderRadius_ = { - ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2, - ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2 - }; - std::string message; - ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message)); -} - -/** - * @tc.name: CheckOtherWindowCoverComp005 - * @tc.desc: Test component window is not covered - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp005, TestSize.Level1) -{ - WindowManager::GetInstance().result_ = WMError::WM_OK; - std::vector> list; - sptr compWin = new UnreliableWindowInfo(); - compWin->windowId_ = 1; - compWin->zOrder_ = 1; - compWin->floatingScale_ = 1.0; - compWin->windowRect_ = Rosen::Rect { - 0, (ServiceTestCommon::TEST_COORDINATE * 2) - 2, - ServiceTestCommon::TEST_COORDINATE + 2, ServiceTestCommon::TEST_COORDINATE + 2 - }; - list.emplace_back(compWin); - WindowManager::GetInstance().info_ = list; - - SecCompRect compRect = { - ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE, - ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE - }; - compRect.borderRadius_ = { - ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2, - ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2 - }; - std::string message; - ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message)); -} - -/** - * @tc.name: CheckOtherWindowCoverComp006 - * @tc.desc: Test component window is not covered - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp006, TestSize.Level1) -{ - WindowManager::GetInstance().result_ = WMError::WM_OK; - std::vector> list; - sptr compWin = new UnreliableWindowInfo(); - compWin->windowId_ = 1; - compWin->zOrder_ = 1; - compWin->floatingScale_ = 1.0; - compWin->windowRect_ = Rosen::Rect { - (ServiceTestCommon::TEST_COORDINATE * 2) - 2, 0, - ServiceTestCommon::TEST_COORDINATE + 2, ServiceTestCommon::TEST_COORDINATE + 2 - }; - list.emplace_back(compWin); - WindowManager::GetInstance().info_ = list; - - SecCompRect compRect = { - ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE, - ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE - }; - compRect.borderRadius_ = { - ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2, - ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2 - }; - std::string message; - ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message)); -} - -/** - * @tc.name: CheckOtherWindowCoverComp007 - * @tc.desc: Test component window is not covered - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(WindowInfoHelperTest, CheckOtherWindowCoverComp007, TestSize.Level1) -{ - WindowManager::GetInstance().result_ = WMError::WM_OK; - std::vector> list; - sptr compWin = new UnreliableWindowInfo(); - compWin->windowId_ = 1; - compWin->zOrder_ = 1; - compWin->floatingScale_ = 1.0; - compWin->windowRect_ = Rosen::Rect { - (ServiceTestCommon::TEST_COORDINATE * 2) - 2, (ServiceTestCommon::TEST_COORDINATE * 2) - 2, - ServiceTestCommon::TEST_COORDINATE + 2, ServiceTestCommon::TEST_COORDINATE + 2 - }; - list.emplace_back(compWin); - WindowManager::GetInstance().info_ = list; - - SecCompRect compRect = { - ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE, - ServiceTestCommon::TEST_COORDINATE, ServiceTestCommon::TEST_COORDINATE - }; - compRect.borderRadius_ = { - ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2, - ServiceTestCommon::TEST_COORDINATE / 2, ServiceTestCommon::TEST_COORDINATE / 2 - }; - std::string message; - ASSERT_FALSE(WindowInfoHelper::CheckOtherWindowCoverComp(0, compRect, message)); -} diff --git a/test/fuzztest/security_component/mock/first_use_dialog.cpp b/test/fuzztest/security_component/mock/first_use_dialog.cpp index c92da8c..f00a853 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 DisplayInfo& displayInfo) + sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState) { 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 DisplayInfo& displayInfo) + sptr dialogCallback, const uint64_t displayId, const CrossAxisState crossAxisState) { return SC_OK; } -- Gitee