diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 90ca20d97205da51a9fd6cd9c0a4c2265ae10600..053311d9ca0c00b0e0b7dc3145e7d5bcd6b820cf 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") @@ -279,6 +280,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 5ff475e905019ec156feb03eee927897b9e6611c..3a7710f133d64d8b48c23d52e525a7c58a3bb22b 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"); @@ -1584,6 +1588,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/BUILD.gn b/frameworks/native/appkit/BUILD.gn index f3e6144bfbd09b509417698e5c2a40d4b83daa19..e510f2e32dd0162a872e758b02821599cccc6961 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -13,6 +13,7 @@ import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") import("//build/ohos.gni") +import("//commonlibrary/memory_utils/purgeable_mem_config.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") es2abc_gen_abc("gen_delegator_mgmt_abc") { @@ -178,6 +179,11 @@ ohos_shared_library("appkit_native") { defines += [ "NWEB" ] } + if (purgeable_ashmem_enable) { + external_deps += [ "memory_utils:libpurgeablemem" ] + defines += [ "IMAGE_PURGEABLE_PIXELMAP" ] + } + innerapi_tags = [ "platformsdk" ] version_script = "libappkit_native.map" subsystem_name = "ability" diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 1f2e22664b324c68ef4a28df70b2ebb90a9d530f..ea6d135ca98ed78946f7c7ba71b79ea496a81535 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -69,6 +69,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 @@ -1788,6 +1792,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;