From 3a5cd5bbe3418f79970f5c37f45583a0323b0d41 Mon Sep 17 00:00:00 2001 From: John Reck Date: Mon, 6 Jul 2020 16:10:49 -0700 Subject: [PATCH] Add missing isShellUser check Bug: 160390416 Test: verified command still works from shell Change-Id: I23bb06e00f1623e4f27c02d7eb2c0d273b40771b (cherry picked from commit 03542611973e4ce3ddca522ee12bcc85e59ce901) Merged-In: I23bb06e00f1623e4f27c02d7eb2c0d273b40771b --- .../com/android/server/am/ActivityManagerService.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index c917530ea42c1..49827ae6199a1 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -4260,9 +4260,18 @@ public class ActivityManagerService extends IActivityManager.Stub return procState; } + private boolean isCallerShell() { + final int callingUid = Binder.getCallingUid(); + return callingUid == SHELL_UID || callingUid == ROOT_UID; + } + @Override public boolean setProcessMemoryTrimLevel(String process, int userId, int level) throws RemoteException { + if (!isCallerShell()) { + EventLog.writeEvent(0x534e4554, 160390416, Binder.getCallingUid(), ""); + throw new SecurityException("Only shell can call it"); + } synchronized (this) { final ProcessRecord app = findProcessLocked(process, userId, "setProcessMemoryTrimLevel"); if (app == null) {