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

Commit ec75b421 authored by lumark's avatar lumark
Browse files

Add the check for UID presence to Display#hasAccess()

It would be nice if there is a common & reliable method for both outer
& internal modules to check the UID presense of the display.

Add more check in Display#hasAccess() to ask system if calling UID can
precense on the specific display, to consolidate only few special UIDs
& display flag checking.

Bug: 117347985
Test: atest ActivityManagerMultiDisplayTests
Change-Id: I2f8989598c99c0962e925c5aa65500972b4fc62b
parent 5af401bd
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2732,6 +2732,10 @@ package android.view {
    field public static final int CALLBACK_ANIMATION = 1; // 0x1
  }

  public final class Display {
    method public boolean hasAccess(int);
  }

  public class FocusFinder {
    method public static void sort(android.view.View[], int, int, android.view.ViewGroup, boolean);
  }
+15 −0
Original line number Diff line number Diff line
@@ -184,6 +184,21 @@ public final class DisplayManagerGlobal {
        }
    }

    /**
     * Check if specified UID's content is present on display and should be granted access to it.
     *
     * @param uid UID to be checked.
     * @param displayId id of the display where presence of the content is checked.
     * @return {@code true} if UID is present on display, {@code false} otherwise.
     */
    public boolean isUidPresentOnDisplay(int uid, int displayId) {
        try {
            return mDm.isUidPresentOnDisplay(uid, displayId);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
    }

    /**
     * Gets information about a logical display.
     *
+0 −8
Original line number Diff line number Diff line
@@ -186,14 +186,6 @@ public abstract class DisplayManagerInternal {
     */
    public abstract void setDisplayAccessUIDs(SparseArray<IntArray> displayAccessUIDs);

    /**
     * Check if specified UID's content is present on display and should be granted access to it.
     *
     * @param uid UID to be checked.
     * @param displayId id of the display where presence of the content is checked.
     * */
    public abstract boolean isUidPresentOnDisplay(int uid, int displayId);

    /**
     * Persist brightness slider events and ambient brightness stats.
     */
+2 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ interface IDisplayManager {
    DisplayInfo getDisplayInfo(int displayId);
    int[] getDisplayIds();

    boolean isUidPresentOnDisplay(int uid, int displayId);

    void registerCallback(in IDisplayManagerCallback callback);

    // Requires CONFIGURE_WIFI_DISPLAY permission.
+7 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE;
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
import android.app.KeyguardManager;
import android.content.res.CompatibilityInfo;
@@ -1096,16 +1097,19 @@ public final class Display {
     * Returns true if the specified UID has access to this display.
     * @hide
     */
    @TestApi
    public boolean hasAccess(int uid) {
        return Display.hasAccess(uid, mFlags, mOwnerUid);
        return hasAccess(uid, mFlags, mOwnerUid, mDisplayId);
    }

    /** @hide */
    public static boolean hasAccess(int uid, int flags, int ownerUid) {
    public static boolean hasAccess(int uid, int flags, int ownerUid, int displayId) {
        return (flags & Display.FLAG_PRIVATE) == 0
                || uid == ownerUid
                || uid == Process.SYSTEM_UID
                || uid == 0;
                || uid == 0
                // Check if the UID is present on given display.
                || DisplayManagerGlobal.getInstance().isUidPresentOnDisplay(uid, displayId);
    }

    /**
Loading