diff options
-rw-r--r-- | cmds/am/src/com/android/commands/am/Am.java | 3 | ||||
-rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 30 |
2 files changed, 18 insertions, 15 deletions
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index d6c00589e7c2..91334bd87296 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -2523,8 +2523,7 @@ public class Am extends BaseCommand { return; } if (!mAm.setProcessMemoryTrimLevel(proc, userId, level)) { - System.err.println("Error: Failure to set the level - probably Unknown Process: " + - proc); + System.err.println("Unknown error: failed to set trim level"); } } diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 324d60241146..0e957b9f30a7 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -4068,25 +4068,29 @@ public final class ActivityManagerService extends ActivityManagerNative } @Override - public boolean setProcessMemoryTrimLevel(String process, int userId, int level) { + public boolean setProcessMemoryTrimLevel(String process, int userId, int level) + throws RemoteException { synchronized (this) { final ProcessRecord app = findProcessLocked(process, userId, "setProcessMemoryTrimLevel"); if (app == null) { - return false; + throw new IllegalArgumentException("Unknown process: " + process); } - if (app.trimMemoryLevel < level && app.thread != null && - (level < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN || - app.curProcState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND)) { - try { - app.thread.scheduleTrimMemory(level); - app.trimMemoryLevel = level; - return true; - } catch (RemoteException e) { - // Fallthrough to failure case. - } + if (app.thread == null) { + throw new IllegalArgumentException("Process has no app thread"); } + if (app.trimMemoryLevel >= level) { + throw new IllegalArgumentException( + "Unable to set a higher trim level than current level"); + } + if (!(level < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN || + app.curProcState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND)) { + throw new IllegalArgumentException("Unable to set a background trim level " + + "on a foreground process"); + } + app.thread.scheduleTrimMemory(level); + app.trimMemoryLevel = level; + return true; } - return false; } private void dispatchProcessesChanged() { |