Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9924c705 authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "Add error messages to send-trim-memory"

parents 343b006d d31f3467
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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");
        }
    }

+17 −13
Original line number Diff line number Diff line
@@ -4068,26 +4068,30 @@ 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.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 (app.trimMemoryLevel < level && app.thread != null &&
                    (level < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN ||
            if (!(level < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN ||
                    app.curProcState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND)) {
                try {
                throw new IllegalArgumentException("Unable to set a background trim level "
                    + "on a foreground process");
            }
            app.thread.scheduleTrimMemory(level);
            app.trimMemoryLevel = level;
            return true;
                } catch (RemoteException e) {
                    // Fallthrough to failure case.
        }
    }
        }
        return false;
    }
    private void dispatchProcessesChanged() {
        int N;