diff options
| author | Jeff Brown <jeffbrown@google.com> | 2013-06-04 00:02:38 -0700 |
|---|---|---|
| committer | Jeff Brown <jeffbrown@google.com> | 2013-06-18 15:32:41 -0700 |
| commit | a506a6ec94863a35acca9feb165db76ddac3892c (patch) | |
| tree | 703825e9e8d3d4928b4d36185244c22b425be04c /core/java/android/view/Display.java | |
| parent | 012416fdbb279f291b43e9d6bf565750752e6a41 (diff) | |
Add an API to allow for creating private virtual displays.
This change enables applications to create a private virtual
display that renders its content to a surface of its own creation.
The display is private in the sense that only the application
that owns the display is allowed to place windows upon it.
Mirroring and blanking is also disabled for these displays.
Bug: 9192512
Change-Id: I852ea07f0c7df1d244e354e3daca3a6960285ca0
Diffstat (limited to 'core/java/android/view/Display.java')
| -rw-r--r-- | core/java/android/view/Display.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java index e6a7950b1dbf..4d984fddd109 100644 --- a/core/java/android/view/Display.java +++ b/core/java/android/view/Display.java @@ -20,6 +20,7 @@ import android.graphics.PixelFormat; import android.graphics.Point; import android.graphics.Rect; import android.hardware.display.DisplayManagerGlobal; +import android.os.Process; import android.os.SystemClock; import android.util.DisplayMetrics; import android.util.Log; @@ -57,6 +58,8 @@ public final class Display { private final int mFlags; private final int mType; private final String mAddress; + private final int mOwnerUid; + private final String mOwnerPackageName; private final CompatibilityInfoHolder mCompatibilityInfo; private DisplayInfo mDisplayInfo; // never null @@ -143,6 +146,18 @@ public final class Display { public static final int FLAG_SECURE = 1 << 1; /** + * Display flag: Indicates that the display is private. Only the application that + * owns the display can create windows on it. + * <p> + * This flag is associated with displays that were created using + * {@link android.hardware.display.DisplayManager#createPrivateVirtualDisplay}. + * </p> + * + * @see #getFlags + */ + public static final int FLAG_PRIVATE = 1 << 2; + + /** * Display type: Unknown display type. * @hide */ @@ -173,6 +188,12 @@ public final class Display { public static final int TYPE_OVERLAY = 4; /** + * Display type: Virtual display. + * @hide + */ + public static final int TYPE_VIRTUAL = 5; + + /** * Internal method to create a display. * Applications should use {@link android.view.WindowManager#getDefaultDisplay()} * or {@link android.hardware.display.DisplayManager#getDisplay} @@ -194,6 +215,8 @@ public final class Display { mFlags = displayInfo.flags; mType = displayInfo.type; mAddress = displayInfo.address; + mOwnerUid = displayInfo.ownerUid; + mOwnerPackageName = displayInfo.ownerPackageName; } /** @@ -262,6 +285,7 @@ public final class Display { * * @see #FLAG_SUPPORTS_PROTECTED_BUFFERS * @see #FLAG_SECURE + * @see #FLAG_PRIVATE */ public int getFlags() { return mFlags; @@ -277,6 +301,7 @@ public final class Display { * @see #TYPE_HDMI * @see #TYPE_WIFI * @see #TYPE_OVERLAY + * @see #TYPE_VIRTUAL * @hide */ public int getType() { @@ -295,6 +320,32 @@ public final class Display { } /** + * Gets the UID of the application that owns this display, or zero if it is + * owned by the system. + * <p> + * If the display is private, then only the owner can use it. + * </p> + * + * @hide + */ + public int getOwnerUid() { + return mOwnerUid; + } + + /** + * Gets the package name of the application that owns this display, or null if it is + * owned by the system. + * <p> + * If the display is private, then only the owner can use it. + * </p> + * + * @hide + */ + public String getOwnerPackageName() { + return mOwnerPackageName; + } + + /** * Gets the compatibility info used by this display instance. * * @return The compatibility info holder, or null if none is required. @@ -564,6 +615,22 @@ public final class Display { } } + /** + * Returns true if the specified UID has access to this display. + * @hide + */ + public boolean hasAccess(int uid) { + return Display.hasAccess(uid, mFlags, mOwnerUid); + } + + /** @hide */ + public static boolean hasAccess(int uid, int flags, int ownerUid) { + return (flags & Display.FLAG_PRIVATE) == 0 + || uid == ownerUid + || uid == Process.SYSTEM_UID + || uid == 0; + } + private void updateDisplayInfoLocked() { // Note: The display manager caches display info objects on our behalf. DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId); @@ -624,6 +691,8 @@ public final class Display { return "WIFI"; case TYPE_OVERLAY: return "OVERLAY"; + case TYPE_VIRTUAL: + return "VIRTUAL"; default: return Integer.toString(type); } |
