OSDN Git Service

RESTRICT AUTOMERGE: Added an app id security check in isAppForeground.
authorVarun Shah <varunshah@google.com>
Sat, 27 Oct 2018 00:03:23 +0000 (17:03 -0700)
committerandroid-build-team Robot <android-build-team-robot@google.com>
Fri, 7 Dec 2018 21:42:31 +0000 (21:42 +0000)
ActivityManagerService#isAppForeground now checks if the caller has the
permission to view if an app is in the foreground.

Bug: 115384617
Test: cts-tradefed run cts -m CtsSecurityTestCases -t android.security.cts.ActivityManagerTest#testIsAppInForegroundNormal
Test: cts-tradefed run cts -m CtsSecurityTestCases -t android.security.cts.ActivityManagerTest#testIsAppInForegroundMalicious
Change-Id: I9602c89b2d40036e525c38960a08326dc74c6682
(cherry picked from commit ad02e59ac2cd3e6180e02fd60e6dedd8177c7b6e)

core/java/android/os/UserHandle.java
services/core/java/com/android/server/am/ActivityManagerService.java

index e8ebf63..f36cf1c 100644 (file)
@@ -132,6 +132,19 @@ public final class UserHandle implements Parcelable {
     }
 
     /**
+     * Whether a UID belongs to a system core component or not.
+     * @hide
+     */
+    public static boolean isCore(int uid) {
+        if (uid >= 0) {
+            final int appId = getAppId(uid);
+            return appId < Process.FIRST_APPLICATION_UID;
+        } else {
+            return false;
+        }
+    }
+
+    /**
      * Returns the user for a given uid.
      * @param uid A uid for an application running in a particular user.
      * @return A {@link UserHandle} for that user.
index 366e533..448d60a 100644 (file)
@@ -8021,6 +8021,14 @@ public class ActivityManagerService extends IActivityManager.Stub
 
     @Override
     public boolean isAppForeground(int uid) throws RemoteException {
+        int callerUid = Binder.getCallingUid();
+        if (UserHandle.isCore(callerUid) || callerUid == uid) {
+            return isAppForegroundInternal(uid);
+        }
+        return false;
+    }
+
+    private boolean isAppForegroundInternal(int uid) {
         synchronized (this) {
             UidRecord uidRec = mActiveUids.get(uid);
             if (uidRec == null || uidRec.idle) {