From c9a0c0b90773fded6c251646300231f67c891b78 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Mon, 6 Apr 2015 16:08:52 -0700 Subject: [PATCH] Lockdown AM.getRunningAppProcesses API with permission.REAL_GET_TASKS * Applications must now have ...permission.REAL_GET_TASKS to be able to get process information for all applications. * Only the process information for the calling application will be returned if the app doesn't have the permission. * Privilages apps will temporarily be able to get process information for all applications if they don't have the new permission, but have deprecated ...permission.GET_TASKS. Bug: 20034603 Change-Id: I67ae9491f65d2280adb6a81593693d499714a216 (cherry picked from commit 9dbaa54f6834e013a63f18bd51ace554de811d80) --- .../server/am/ActivityManagerService.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 3215144ac59a5..0983066534573 100755 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -8249,7 +8249,7 @@ public final class ActivityManagerService extends ActivityManagerNative } if (!allowed) { Slog.w(TAG, caller + ": caller " + callingUid - + " does not hold GET_TASKS; limiting output"); + + " does not hold REAL_GET_TASKS; limiting output"); } return allowed; } @@ -12247,16 +12247,23 @@ public final class ActivityManagerService extends ActivityManagerNative public List getRunningAppProcesses() { enforceNotIsolatedCaller("getRunningAppProcesses"); + + final int callingUid = Binder.getCallingUid(); + // Lazy instantiation of list List runList = null; final boolean allUsers = ActivityManager.checkUidPermission(INTERACT_ACROSS_USERS_FULL, - Binder.getCallingUid()) == PackageManager.PERMISSION_GRANTED; - int userId = UserHandle.getUserId(Binder.getCallingUid()); + callingUid) == PackageManager.PERMISSION_GRANTED; + final int userId = UserHandle.getUserId(callingUid); + final boolean allUids = isGetTasksAllowed( + "getRunningAppProcesses", Binder.getCallingPid(), callingUid); + synchronized (this) { // Iterate across all processes - for (int i=mLruProcesses.size()-1; i>=0; i--) { + for (int i = mLruProcesses.size() - 1; i >= 0; i--) { ProcessRecord app = mLruProcesses.get(i); - if (!allUsers && app.userId != userId) { + if ((!allUsers && app.userId != userId) + || (!allUids && app.uid != callingUid)) { continue; } if ((app.thread != null) && (!app.crashing && !app.notResponding)) { @@ -12280,7 +12287,7 @@ public final class ActivityManagerService extends ActivityManagerNative //Slog.v(TAG, "Proc " + app.processName + ": imp=" + currApp.importance // + " lru=" + currApp.lru); if (runList == null) { - runList = new ArrayList(); + runList = new ArrayList<>(); } runList.add(currApp); }