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
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index 1aaaf41..6c00da2 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -1689,8 +1689,9 @@
          * Returns information about the specified logical display.
          *
          * @param displayId The logical display id.
-         * @return The logical display info, or null if the display does not exist.  The
-         * returned object must be treated as immutable.
+         * @return The logical display info, return {@code null} if the display does not exist or
+         * the calling UID isn't present on the display.  The returned object must be treated as
+         * immutable.
          */
         @Override // Binder call
         public DisplayInfo getDisplayInfo(int displayId) {
@@ -1717,6 +1718,16 @@
             }
         }
 
+        @Override // Binder call
+        public boolean isUidPresentOnDisplay(int uid, int displayId) {
+            final long token = Binder.clearCallingIdentity();
+            try {
+                return isUidPresentOnDisplayInternal(uid, displayId);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
         /**
          * Returns the stable device display size, in pixels.
          */
@@ -2385,11 +2396,6 @@
         }
 
         @Override
-        public boolean isUidPresentOnDisplay(int uid, int displayId) {
-            return isUidPresentOnDisplayInternal(uid, displayId);
-        }
-
-        @Override
         public void persistBrightnessTrackerState() {
             synchronized (mSyncRoot) {
                 mDisplayPowerController.persistBrightnessTrackerState();