From 16045c24fe10cc92329ede099923f1223f49b17d Mon Sep 17 00:00:00 2001 From: Stefan Kuhne Date: Fri, 5 Jun 2015 07:18:06 -0700 Subject: Adding am send-trim-memory command This patch adds a send-trim-memory command to the ActivityManager to allow for better debugging&testing. The command is adb shell am send-trim-memory [--user ] whereas LEVEL can be one of the following: [HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE| RUNNING_CRITICAL|COMPLETE] Bug: 21633189 Change-Id: I7a41ce02c3c9043ffd3e5aaa791f7b7306a9de49 --- cmds/am/src/com/android/commands/am/Am.java | 67 ++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 5 deletions(-) (limited to 'cmds') diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index 808e124..b0a7dc7 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -31,6 +31,7 @@ import android.app.UiAutomationConnection; import android.app.usage.ConfigurationStats; import android.app.usage.IUsageStatsManager; import android.app.usage.UsageStatsManager; +import android.content.ComponentCallbacks2; import android.content.ComponentName; import android.content.Context; import android.content.IIntentReceiver; @@ -144,6 +145,8 @@ public class Am extends BaseCommand { " am get-config\n" + " am set-inactive [--user ] true|false\n" + " am get-inactive [--user ] \n" + + " am send-trim-memory [--user ] \n" + + " [HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE|RUNNING_CRITICAL|COMPLETE]\n" + "\n" + "am start: start an Activity. Options are:\n" + " -D: enable debugging\n" + @@ -271,9 +274,9 @@ public class Am extends BaseCommand { "\n" + "am stack info: display the information about activity stack .\n" + "\n" + - "am task lock: bring to the front and don't allow other tasks to run\n" + + "am task lock: bring to the front and don't allow other tasks to run.\n" + "\n" + - "am task lock stop: end the current task lock\n" + + "am task lock stop: end the current task lock.\n" + "\n" + "am task resizeable: change if is resizeable (true) or not (false).\n" + "\n" + @@ -282,12 +285,13 @@ public class Am extends BaseCommand { " has the specified bounds.\n" + "\n" + "am get-config: retrieve the configuration and any recent configurations\n" + - " of the device\n" + + " of the device.\n" + "\n" + - "am set-inactive: sets the inactive state of an app\n" + + "am set-inactive: sets the inactive state of an app.\n" + "\n" + - "am get-inactive: returns the inactive state of an app\n" + + "am get-inactive: returns the inactive state of an app.\n" + "\n" + + " am send-trim-memory: Send a memory trim event to a .\n" + "\n" + " specifications include these flags and arguments:\n" + " [-a ] [-d ] [-t ]\n" + @@ -399,6 +403,8 @@ public class Am extends BaseCommand { runSetInactive(); } else if (op.equals("get-inactive")) { runGetInactive(); + } else if (op.equals("send-trim-memory")) { + runSendTrimMemory(); } else { showError("Error: unknown command '" + op + "'"); } @@ -2070,6 +2076,57 @@ public class Am extends BaseCommand { System.out.println("Idle=" + isIdle); } + private void runSendTrimMemory() throws Exception { + int userId = UserHandle.USER_CURRENT; + String opt; + while ((opt = nextOption()) != null) { + if (opt.equals("--user")) { + userId = parseUserArg(nextArgRequired()); + if (userId == UserHandle.USER_ALL) { + System.err.println("Error: Can't use user 'all'"); + return; + } + } else { + System.err.println("Error: Unknown option: " + opt); + return; + } + } + + String proc = nextArgRequired(); + String levelArg = nextArgRequired(); + int level; + switch (levelArg) { + case "HIDDEN": + level = ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN; + break; + case "RUNNING_MODERATE": + level = ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE; + break; + case "BACKGROUND": + level = ComponentCallbacks2.TRIM_MEMORY_BACKGROUND; + break; + case "RUNNING_LOW": + level = ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW; + break; + case "MODERATE": + level = ComponentCallbacks2.TRIM_MEMORY_MODERATE; + break; + case "RUNNING_CRITICAL": + level = ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL; + break; + case "COMPLETE": + level = ComponentCallbacks2.TRIM_MEMORY_COMPLETE; + break; + default: + System.err.println("Error: Unknown level option: " + levelArg); + return; + } + if (!mAm.setProcessMemoryTrimLevel(proc, userId, level)) { + System.err.println("Error: Failure to set the level - probably Unknown Process: " + + proc); + } + } + /** * Open the given file for sending into the system process. This verifies * with SELinux that the system will have access to the file. -- cgit v1.1