Remove handling of deprecated TRIM_MEMORY levels in VirtualMachine
This CL removes handling of several deprecated `TRIM_MEMORY` levels in
the `VirtualMachine` class. The removed levels include
`TRIM_MEMORY_RUNNING_CRITICAL`, `TRIM_MEMORY_RUNNING_LOW`,
`TRIM_MEMORY_RUNNING_MODERATE`, and `TRIM_MEMORY_COMPLETE`.
The level < TRIM_MEMORY_UI_HIDDEN is now target on 10% memory release.
The level that TRIM_UI_HIDDEN <= level < TRIM_MEMORY_BACKGROUND targets
on 30% memory release. The level >= TRIM_MEMORY_BACKGROUND targets on
50% memory release.
Bug: b:395028417
Test: atest
com.android.microdroid.benchmark.MicrodroidBenchmarks#testMemoryReclaim
Change-Id: I7c623b2fed66ddfe8c29e28bce541727155385fc
diff --git a/libs/framework-virtualization/src/android/system/virtualmachine/VirtualMachine.java b/libs/framework-virtualization/src/android/system/virtualmachine/VirtualMachine.java
index 5f634ef..af313a1 100644
--- a/libs/framework-virtualization/src/android/system/virtualmachine/VirtualMachine.java
+++ b/libs/framework-virtualization/src/android/system/virtualmachine/VirtualMachine.java
@@ -276,28 +276,16 @@
@Override
public void onTrimMemory(int level) {
- int percent;
+ /* Treat level < TRIM_MEMORY_UI_HIDDEN as generic low-memory warnings */
+ int percent = 10;
- switch (level) {
- case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
- percent = 50;
- break;
- case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
- percent = 30;
- break;
- case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
- percent = 10;
- break;
- case ComponentCallbacks2.TRIM_MEMORY_BACKGROUND:
- case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
- case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
- /* Release as much memory as we can. The app is on the LMKD LRU kill list. */
- percent = 50;
- break;
- default:
- /* Treat unrecognised messages as generic low-memory warnings. */
- percent = 30;
- break;
+ if (level >= ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
+ percent = 30;
+ }
+
+ if (level >= ComponentCallbacks2.TRIM_MEMORY_BACKGROUND) {
+ /* Release as much memory as we can. The app is on the LMKD LRU kill list. */
+ percent = 50;
}
synchronized (mLock) {