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

Commit 58db75e8 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Fix getProcessMemoryInfo()'s calling UID check

Bug: 119109396
Bug: 119179466
Test: atest cts/tests/app/src/android/app/cts/ActivityManagerMemoryInfoTest.java\#testGetProcessMemoryInfo
Change-Id: Ieb3a27582fee072aecd7f7373a5601a03b1e7397
parent 67dd91e6
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -3852,7 +3852,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        final int callingPid = Binder.getCallingPid();
        final int callingUid = Binder.getCallingUid();
        final int userId = UserHandle.getUserId(callingUid);
        final int callingUserId = UserHandle.getUserId(callingUid);
        final boolean allUsers = ActivityManager.checkUidPermission(INTERACT_ACROSS_USERS_FULL,
                callingUid) == PackageManager.PERMISSION_GRANTED;
        // Check REAL_GET_TASKS to see if they are allowed to access other uids
@@ -3870,11 +3870,17 @@ public class ActivityManagerService extends IActivityManager.Stub
                    oomAdj = proc != null ? proc.setAdj : 0;
                }
            }
            if (!allUids || (!allUsers && (proc == null
                    || UserHandle.getUserId(proc.uid) != userId))) {
                // The caller is not allow to get information about this other process...
                // just leave it empty.
                continue;
            final int targetUid = (proc != null) ? proc.uid : -1;
            final int targetUserId = (proc != null) ? UserHandle.getUserId(targetUid) : -1;
            if (callingUid != targetUid) {
                if (!allUids) {
                    continue; // Not allowed to see other UIDs.
                }
                if (!allUsers && (targetUserId != callingUserId)) {
                    continue; // Not allowed to see other users.
                }
            }
            if (proc != null && proc.lastMemInfoTime >= lastNow && proc.lastMemInfo != null) {
                // It hasn't been long enough that we want to take another sample; return