diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index d789c07e45bb6882ed3a9ee266475a36331f8f31..5876e7003ac16ce44902c44d2ef10badbf1334df 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos.gni") +import("//commonlibrary/memory_utils/purgeable_mem_config.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") import("//foundation/distributeddatamgr/relational_store/relational_store.gni") @@ -296,6 +297,11 @@ ohos_shared_library("abilitykit_native") { defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ] } + if (purgeable_ashmem_enable) { + external_deps += [ "memory_utils:libpurgeablemem" ] + defines += [ "IMAGE_PURGEABLE_PIXELMAP" ] + } + if (efficiency_manager) { external_deps += [ "efficiency_manager:suspend_manager_client" ] defines += [ "EFFICIENCY_MANAGER_ENABLE" ] diff --git a/frameworks/native/ability/native/ability.cpp b/frameworks/native/ability/native/ability.cpp index 0e2eddb36cb5888287e06ae9edc60d0426b5660f..8ba87945a9c4c4d978a134bf8282fb354922f59d 100644 --- a/frameworks/native/ability/native/ability.cpp +++ b/frameworks/native/ability/native/ability.cpp @@ -56,6 +56,10 @@ #include "key_event.h" #endif +#ifdef IMAGE_PURGEABLE_PIXELMAP +#include "purgeable_resource_manager.h" +#endif + namespace OHOS { namespace AppExecFwk { const std::string Ability::SYSTEM_UI("com.ohos.systemui"); @@ -1585,6 +1589,10 @@ void Ability::OnBackground() HILOG_ERROR("Ability::OnBackground error. lifecycle_ == nullptr."); return; } +#ifdef IMAGE_PURGEABLE_PIXELMAP + HILOG_DEBUG("[PurgeableResourceManager] Ability OnBackground ExecEndVisitPurgeableMem."); + PurgeableMem::PurgeableResourceManager::GetInstance().ExecEndVisitPurgeableMem(); +#endif lifecycle_->DispatchLifecycle(LifeCycle::Event::ON_BACKGROUND); HILOG_DEBUG("%{public}s end", __func__); AAFwk::EventInfo eventInfo; diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 88cf3bcd023b1ec69172de5b5a7f00243743eec6..44f30cd5debe527f673a2534a0f4db5da2ced6ea 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -68,6 +68,10 @@ #include "nweb_helper.h" #endif +#ifdef IMAGE_PURGEABLE_PIXELMAP +#include "purgeable_resource_manager.h" +#endif + #if defined(ABILITY_LIBRARY_LOADER) || defined(APPLICATION_LIBRARY_LOADER) #include #include @@ -1786,6 +1790,11 @@ void MainThread::HandleForegroundApplication() return; } +#ifdef IMAGE_PURGEABLE_PIXELMAP + HILOG_DEBUG("[PurgeableResourceManager] Ability OnForeground ExecBeginVisitPurgeableMem."); + PurgeableMem::PurgeableResourceManager::GetInstance().ExecBeginVisitPurgeableMem(); +#endif + if (!applicationImpl_->PerformForeground()) { HILOG_ERROR("MainThread::handleForegroundApplication error!, applicationImpl_->PerformForeground() failed"); return;