From 907a198074a478b438c46429a3d4a641a9276ac0 Mon Sep 17 00:00:00 2001 From: baoyang Date: Tue, 25 Feb 2025 22:31:13 +0800 Subject: [PATCH] fit warmStart Signed-off-by: baoyang Change-Id: Ibc5f25c5c5c973cebb314cc9ebf01d5ac0bb3cac --- .../sa/sa_main/app_state_observer.cpp | 22 ++++++++++++++----- .../sa/sa_main/app_state_observer.h | 3 ++- .../sa/sa_main/first_use_dialog.cpp | 1 + .../sa/sa_main/sec_comp_manager.cpp | 9 ++++---- .../sa/sa_main/sec_comp_manager.h | 2 +- .../include/application_state_observer_stub.h | 1 + .../unittest/src/app_state_observer_test.cpp | 6 ++--- .../unittest/src/sec_comp_manager_test.cpp | 6 ++--- 8 files changed, 33 insertions(+), 17 deletions(-) diff --git a/services/security_component_service/sa/sa_main/app_state_observer.cpp b/services/security_component_service/sa/sa_main/app_state_observer.cpp index be4fa4e..9a77b3a 100644 --- a/services/security_component_service/sa/sa_main/app_state_observer.cpp +++ b/services/security_component_service/sa/sa_main/app_state_observer.cpp @@ -22,6 +22,7 @@ namespace Security { namespace SecurityComponent { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "AppStateObserver"}; +constexpr int32_t APP_STATE_CACHED = 100; } AppStateObserver::AppStateObserver() @@ -85,11 +86,11 @@ void AppStateObserver::AddProcessToForegroundSet(const AppExecFwk::ProcessData & AddProcessToForegroundSet(processData.pid, proc); } -void AppStateObserver::RemoveProcessFromForegroundSet(const AppExecFwk::ProcessData &processData) +void AppStateObserver::RemoveProcessFromForegroundSet(const int32_t pid) { Utils::UniqueWriteGuard infoGuard(this->fgProcLock_); for (auto iter = foregrandProcList_.begin(); iter != foregrandProcList_.end(); ++iter) { - if (processData.pid == iter->pid) { + if (pid == iter->pid) { foregrandProcList_.erase(iter); return; } @@ -102,7 +103,7 @@ void AppStateObserver::OnProcessStateChanged(const AppExecFwk::ProcessData &proc AddProcessToForegroundSet(processData); SecCompManager::GetInstance().NotifyProcessForeground(processData.pid); } else if (processData.state == AppExecFwk::AppProcessState::APP_STATE_BACKGROUND) { - RemoveProcessFromForegroundSet(processData); + RemoveProcessFromForegroundSet(processData.pid); SecCompManager::GetInstance().NotifyProcessBackground(processData.pid); } } @@ -111,8 +112,19 @@ void AppStateObserver::OnProcessDied(const AppExecFwk::ProcessData& processData) { SC_LOG_INFO(LABEL, "OnProcessDied die %{public}s pid %{public}d", processData.bundleName.c_str(), processData.pid); - RemoveProcessFromForegroundSet(processData); - SecCompManager::GetInstance().NotifyProcessDied(processData.pid); + RemoveProcessFromForegroundSet(processData.pid); + SecCompManager::GetInstance().NotifyProcessDied(processData.pid, false); +} + +void AppStateObserver::OnAppCacheStateChanged(const AppExecFwk::AppStateData &appStateData) +{ + SC_LOG_INFO(LABEL, "OnAppCacheStateChanged pid %{public}d", + appStateData.pid); + if (appStateData.state != APP_STATE_CACHED) { + return; + } + RemoveProcessFromForegroundSet(appStateData.pid); + SecCompManager::GetInstance().NotifyProcessDied(appStateData.pid, true); } void AppStateObserver::DumpProcess(std::string& dumpStr) diff --git a/services/security_component_service/sa/sa_main/app_state_observer.h b/services/security_component_service/sa/sa_main/app_state_observer.h index 56998a0..ad2d132 100644 --- a/services/security_component_service/sa/sa_main/app_state_observer.h +++ b/services/security_component_service/sa/sa_main/app_state_observer.h @@ -43,9 +43,10 @@ public: void AddProcessToForegroundSet(const AppExecFwk::ProcessData& processData); void AddProcessToForegroundSet(const AppExecFwk::AppStateData& stateData); void DumpProcess(std::string& dumpStr); + void OnAppCacheStateChanged(const AppExecFwk::AppStateData &appStateData) override; private: - void RemoveProcessFromForegroundSet(const AppExecFwk::ProcessData& processData); + void RemoveProcessFromForegroundSet(const int32_t pid); std::vector foregrandProcList_; OHOS::Utils::RWLock fgProcLock_; }; 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..600e4c7 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 @@ -265,6 +265,7 @@ void FirstUseDialog::RemoveDialogWaitEntitys(int32_t pid) std::shared_ptr entity = iter->second; if ((entity != nullptr) && (entity->pid_ == pid)) { iter = dialogWaitMap_.erase(iter); + SC_LOG_ERROR(LABEL, "dialog %{public}d is removed", pid); } else { ++iter; } 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 7ec4a4e..2687ce1 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 @@ -226,12 +226,13 @@ void SecCompManager::NotifyProcessBackground(int32_t pid) SC_LOG_INFO(LABEL, "App pid %{public}d to background", pid); } -void SecCompManager::NotifyProcessDied(int32_t pid) +void SecCompManager::NotifyProcessDied(int32_t pid, bool isProcessCached) { + if (!isProcessCached) { // notify enhance process died. - SecCompEnhanceAdapter::NotifyProcessDied(pid); - - malicious_.RemoveAppFromMaliciousAppList(pid); + SecCompEnhanceAdapter::NotifyProcessDied(pid); + malicious_.RemoveAppFromMaliciousAppList(pid); + } OHOS::Utils::UniqueWriteGuard lk(this->componentInfoLock_); auto iter = componentMap_.find(pid); if (iter == componentMap_.end()) { diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.h b/services/security_component_service/sa/sa_main/sec_comp_manager.h index b57b363..4d6ce05 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.h +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.h @@ -61,7 +61,7 @@ public: const SecCompCallerInfo& caller, const std::vector>& remote, std::string& message); void NotifyProcessForeground(int32_t pid); void NotifyProcessBackground(int32_t pid); - void NotifyProcessDied(int32_t pid); + void NotifyProcessDied(int32_t pid, bool isProcessCached); void DumpSecComp(std::string& dumpStr); bool Initialize(); void ExitSaProcess(); 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 9271160..35c9890 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,6 +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; }; class ApplicationStateObserverStub : public IRemoteStub { diff --git a/services/security_component_service/sa/test/unittest/src/app_state_observer_test.cpp b/services/security_component_service/sa/test/unittest/src/app_state_observer_test.cpp index ab47da8..deb2b19 100644 --- a/services/security_component_service/sa/test/unittest/src/app_state_observer_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/app_state_observer_test.cpp @@ -105,8 +105,8 @@ HWTEST_F(AppStateObserverTest, RemoveProcessFromForegroundSet001, TestSize.Level }; observer_->AddProcessToForegroundSet(procData); ASSERT_TRUE(observer_->IsProcessForeground(ServiceTestCommon::TEST_PID_1, ServiceTestCommon::TEST_UID_1)); - observer_->RemoveProcessFromForegroundSet(procData); - observer_->RemoveProcessFromForegroundSet(procData); + observer_->RemoveProcessFromForegroundSet(procData.pid); + observer_->RemoveProcessFromForegroundSet(procData.pid); ASSERT_FALSE(observer_->IsProcessForeground(ServiceTestCommon::TEST_PID_1, ServiceTestCommon::TEST_UID_1)); } @@ -125,7 +125,7 @@ HWTEST_F(AppStateObserverTest, RemoveProcessFromForegroundSet002, TestSize.Level observer_->AddProcessToForegroundSet(procData); ASSERT_TRUE(observer_->IsProcessForeground(ServiceTestCommon::TEST_PID_1, ServiceTestCommon::TEST_UID_1)); procData.pid = ServiceTestCommon::TEST_PID_2; - observer_->RemoveProcessFromForegroundSet(procData); + observer_->RemoveProcessFromForegroundSet(procData.pid); ASSERT_TRUE(observer_->IsProcessForeground(ServiceTestCommon::TEST_PID_1, ServiceTestCommon::TEST_UID_1)); } diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp index 5f96196..e061d8c 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp @@ -277,7 +277,7 @@ HWTEST_F(SecCompManagerTest, NotifyProcessBackground001, TestSize.Level1) ASSERT_TRUE(SecCompManager::GetInstance().IsForegroundCompExist()); SecCompManager::GetInstance().NotifyProcessBackground(ServiceTestCommon::TEST_PID_1); ASSERT_FALSE(SecCompManager::GetInstance().IsForegroundCompExist()); - SecCompManager::GetInstance().NotifyProcessDied(ServiceTestCommon::TEST_PID_1); + SecCompManager::GetInstance().NotifyProcessDied(ServiceTestCommon::TEST_PID_1, false); ASSERT_FALSE(SecCompManager::GetInstance().IsForegroundCompExist()); } @@ -313,11 +313,11 @@ HWTEST_F(SecCompManagerTest, NotifyProcessDied001, TestSize.Level1) ASSERT_EQ(SC_OK, SecCompManager::GetInstance().AddSecurityComponentToList(ServiceTestCommon::TEST_PID_2, 0, entity2)); - SecCompManager::GetInstance().NotifyProcessDied(ServiceTestCommon::TEST_PID_3); + SecCompManager::GetInstance().NotifyProcessDied(ServiceTestCommon::TEST_PID_3, false); ASSERT_NE(nullptr, SecCompManager::GetInstance().GetSecurityComponentFromList( ServiceTestCommon::TEST_PID_1, ServiceTestCommon::TEST_SC_ID_1)); - SecCompManager::GetInstance().NotifyProcessDied(ServiceTestCommon::TEST_PID_1); + SecCompManager::GetInstance().NotifyProcessDied(ServiceTestCommon::TEST_PID_1, false); ASSERT_EQ(nullptr, SecCompManager::GetInstance().GetSecurityComponentFromList( ServiceTestCommon::TEST_PID_1, ServiceTestCommon::TEST_SC_ID_1)); } -- Gitee