public final class Display extends Object
The display area is described in two different ways.
getSize(android.graphics.Point)
, getRectSize(android.graphics.Rect)
and getMetrics(android.util.DisplayMetrics)
.getRealSize(android.graphics.Point)
, getRealMetrics(android.util.DisplayMetrics)
.A logical display does not necessarily represent a particular physical display device such as the built-in screen or an external monitor. The contents of a logical display may be presented on one or more physical displays according to the devices that are currently attached and whether mirroring has been enabled.
Modifier and Type | Class and Description |
---|---|
static class |
Display.HdrCapabilities
Encapsulates the HDR capabilities of a given display.
|
static class |
Display.Mode
A mode supported by a given display.
|
Modifier and Type | Field and Description |
---|---|
static int |
COLOR_MODE_DEFAULT
Display color mode: The default or native gamut of the display.
|
static int |
COLOR_MODE_INVALID
Display color mode: The current color mode is unknown or invalid.
|
static int |
COLOR_MODE_SRGB
Display color mode: SRGB
|
static int |
DEFAULT_DISPLAY
The default Display id, which is the id of the built-in primary display
assuming there is one.
|
static int |
FLAG_PRESENTATION
Display flag: Indicates that the display is a presentation display.
|
static int |
FLAG_PRIVATE
Display flag: Indicates that the display is private.
|
static int |
FLAG_ROUND
Display flag: Indicates that the display has a round shape.
|
static int |
FLAG_SCALING_DISABLED
Display flag: Indicates that the contents of the display should not be scaled
to fit the physical screen dimensions.
|
static int |
FLAG_SECURE
Display flag: Indicates that the display has a secure video output and
supports compositing secure surfaces.
|
static int |
FLAG_SUPPORTS_PROTECTED_BUFFERS
Display flag: Indicates that the display supports compositing content
that is stored in protected graphics buffers.
|
static int |
INVALID_DISPLAY
Invalid display id.
|
static int |
STATE_DOZE
Display state: The display is dozing in a low power state; it is still
on but is optimized for showing system-provided content while the
device is non-interactive.
|
static int |
STATE_DOZE_SUSPEND
Display state: The display is dozing in a suspended low power state; it is still
on but is optimized for showing static system-provided content while the device
is non-interactive.
|
static int |
STATE_OFF
Display state: The display is off.
|
static int |
STATE_ON
Display state: The display is on.
|
static int |
STATE_UNKNOWN
Display state: The display state is unknown.
|
static int |
TYPE_BUILT_IN
Display type: Built-in display.
|
static int |
TYPE_HDMI
Display type: HDMI display.
|
static int |
TYPE_OVERLAY
Display type: Overlay display.
|
static int |
TYPE_UNKNOWN
Display type: Unknown display type.
|
static int |
TYPE_VIRTUAL
Display type: Virtual display.
|
static int |
TYPE_WIFI
Display type: WiFi display.
|
Constructor and Description |
---|
Display(DisplayManagerGlobal global,
int displayId,
DisplayInfo displayInfo,
DisplayAdjustments daj)
Internal method to create a display.
|
Modifier and Type | Method and Description |
---|---|
String |
getAddress()
Gets the display address, or null if none.
|
long |
getAppVsyncOffsetNanos()
Gets the app VSYNC offset, in nanoseconds.
|
int |
getColorMode()
Returns the active color mode of this display
|
void |
getCurrentSizeRange(Point outSmallestSize,
Point outLargestSize)
Return the range of display sizes an application can expect to encounter
under normal operation, as long as there is no physical change in screen
size.
|
DisplayAdjustments |
getDisplayAdjustments()
Gets the compatibility info used by this display instance.
|
int |
getDisplayId()
Gets the display id.
|
boolean |
getDisplayInfo(DisplayInfo outDisplayInfo)
Gets a full copy of the display information.
|
int |
getFlags()
Returns a combination of flags that describe the capabilities of the display.
|
Display.HdrCapabilities |
getHdrCapabilities()
Returns the display's HDR capabilities.
|
int |
getHeight()
Deprecated.
Use
getSize(Point) instead. |
int |
getLayerStack()
Gets the display's layer stack.
|
int |
getMaximumSizeDimension()
Return the maximum screen size dimension that will happen.
|
void |
getMetrics(DisplayMetrics outMetrics)
Gets display metrics that describe the size and density of this display.
|
Display.Mode |
getMode()
Returns the active mode of the display.
|
String |
getName()
Gets the name of the display.
|
int |
getOrientation()
Deprecated.
use
getRotation() |
void |
getOverscanInsets(Rect outRect) |
String |
getOwnerPackageName()
Gets the package name of the application that owns this display, or null if it is
owned by the system.
|
int |
getOwnerUid()
Gets the UID of the application that owns this display, or zero if it is
owned by the system.
|
int |
getPixelFormat()
Deprecated.
This method is no longer supported.
The result is always
PixelFormat.RGBA_8888 . |
long |
getPresentationDeadlineNanos()
This is how far in advance a buffer must be queued for presentation at
a given time.
|
void |
getRealMetrics(DisplayMetrics outMetrics)
Gets display metrics based on the real size of this display.
|
void |
getRealSize(Point outSize)
Gets the real size of the display without subtracting any window decor or
applying any compatibility scale factors.
|
void |
getRectSize(Rect outSize)
Gets the size of the display as a rectangle, in pixels.
|
float |
getRefreshRate()
Gets the refresh rate of this display in frames per second.
|
int |
getRotation()
Returns the rotation of the screen from its "natural" orientation.
|
void |
getSize(Point outSize)
Gets the size of the display, in pixels.
|
int |
getState()
Gets the state of the display, such as whether it is on or off.
|
int[] |
getSupportedColorModes()
Gets the supported color modes of this device.
|
Display.Mode[] |
getSupportedModes()
Gets the supported modes of this display.
|
float[] |
getSupportedRefreshRates()
Deprecated.
use
getSupportedModes() instead |
int |
getType()
Gets the display type.
|
int |
getWidth()
Deprecated.
Use
getSize(Point) instead. |
boolean |
hasAccess(int uid)
Returns true if the specified UID has access to this display.
|
static boolean |
hasAccess(int uid,
int flags,
int ownerUid) |
boolean |
isPublicPresentation()
Returns true if the display is a public presentation display.
|
static boolean |
isSuspendedState(int state)
Returns true if display updates may be suspended while in the specified
display power state.
|
boolean |
isValid()
Returns true if this display is still valid, false if the display has been removed.
|
void |
requestColorMode(int colorMode)
Request the display applies a color mode.
|
static String |
stateToString(int state) |
String |
toString()
Returns a string representation of the object.
|
static String |
typeToString(int type) |
public static final int DEFAULT_DISPLAY
public static final int INVALID_DISPLAY
public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS
If this flag is set then the display device supports compositing protected buffers.
If this flag is not set then the display device may not support compositing protected buffers; the user may see a blank region on the screen instead of the protected content.
Secure (DRM) video decoders may allocate protected graphics buffers to request that a hardware-protected path be provided between the video decoder and the external display sink. If a hardware-protected path is not available, then content stored in protected graphics buffers may not be composited.
An application can use the absence of this flag as a hint that it should not use protected buffers for this display because the content may not be visible. For example, if the flag is not set then the application may choose not to show content on this display, show an informative error message, select an alternate content stream or adopt a different strategy for decoding content that does not rely on protected buffers.
getFlags()
,
Constant Field Valuespublic static final int FLAG_SECURE
If this flag is set then the display device has a secure video output
and is capable of showing secure surfaces. It may also be capable of
showing protected buffers
.
If this flag is not set then the display device may not have a secure video output; the user may see a blank region on the screen instead of the contents of secure surfaces or protected buffers.
Secure surfaces are used to prevent content rendered into those surfaces by applications from appearing in screenshots or from being viewed on non-secure displays. Protected buffers are used by secure video decoders for a similar purpose.
An application creates a window with a secure surface by specifying the
WindowManager.LayoutParams.FLAG_SECURE
window flag.
Likewise, an application creates a SurfaceView
with a secure surface
by calling SurfaceView.setSecure(boolean)
before attaching the secure view to
its containing window.
An application can use the absence of this flag as a hint that it should not create secure surfaces or protected buffers on this display because the content may not be visible. For example, if the flag is not set then the application may choose not to show content on this display, show an informative error message, select an alternate content stream or adopt a different strategy for decoding content that does not rely on secure surfaces or protected buffers.
getFlags()
,
Constant Field Valuespublic static final int FLAG_PRIVATE
getFlags()
,
Constant Field Valuespublic static final int FLAG_PRESENTATION
This flag identifies secondary displays that are suitable for use as presentation displays such as HDMI or Wireless displays. Applications may automatically project their content to presentation displays to provide richer second screen experiences.
getFlags()
,
Constant Field Valuespublic static final int FLAG_ROUND
This flag identifies displays that are circular, elliptical or otherwise do not permit the user to see all the way to the logical corners of the display.
getFlags()
,
Constant Field Valuespublic static final int FLAG_SCALING_DISABLED
public static final int TYPE_UNKNOWN
public static final int TYPE_BUILT_IN
public static final int TYPE_HDMI
public static final int TYPE_WIFI
public static final int TYPE_OVERLAY
public static final int TYPE_VIRTUAL
public static final int STATE_UNKNOWN
getState()
,
Constant Field Valuespublic static final int STATE_OFF
getState()
,
Constant Field Valuespublic static final int STATE_ON
getState()
,
Constant Field Valuespublic static final int STATE_DOZE
public static final int STATE_DOZE_SUSPEND
public static final int COLOR_MODE_INVALID
public static final int COLOR_MODE_DEFAULT
public static final int COLOR_MODE_SRGB
public Display(DisplayManagerGlobal global, int displayId, DisplayInfo displayInfo, DisplayAdjustments daj)
WindowManager.getDefaultDisplay()
or DisplayManager.getDisplay(int)
to get a display object.public int getDisplayId()
Each logical display has a unique id.
The default display has id DEFAULT_DISPLAY
.
public boolean isValid()
Display
object after the display's demise.
It's possible for a display that was previously invalid to become
valid again if a display with the same id is reconnected.public boolean getDisplayInfo(DisplayInfo outDisplayInfo)
outDisplayInfo
- The object to receive the copy of the display information.public int getLayerStack()
public int getFlags()
FLAG_SUPPORTS_PROTECTED_BUFFERS
,
FLAG_SECURE
,
FLAG_PRIVATE
public int getType()
TYPE_UNKNOWN
,
TYPE_BUILT_IN
,
TYPE_HDMI
,
TYPE_WIFI
,
TYPE_OVERLAY
,
TYPE_VIRTUAL
public String getAddress()
public int getOwnerUid()
If the display is private, then only the owner can use it.
public String getOwnerPackageName()
If the display is private, then only the owner can use it.
public DisplayAdjustments getDisplayAdjustments()
public String getName()
Note that some displays may be renamed by the user.
public void getSize(Point outSize)
1. The returned size may be adjusted to exclude certain system decor elements that are always visible.
2. It may be scaled to provide compatibility with older applications that were originally designed for smaller displays.
3. It can be different depending on the WindowManager to which the display belongs.
- If requested from non-Activity context (e.g. Application context via
(WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)
)
it will report the size of the entire display based on current rotation and with subtracted
system decoration areas.
- If requested from activity (either using getWindowManager()
or
(WindowManager) getSystemService(Context.WINDOW_SERVICE)
) resulting size will
correspond to current app window size. In this case it can be smaller than physical size in
multi-window mode.
Typically for the purposes of layout apps should make a request from activity context to obtain size available for the app content.
outSize
- A Point
object to receive the size information.public void getRectSize(Rect outSize)
outSize
- A Rect
object to receive the size information.getSize(Point)
public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize)
outSmallestSize
- Filled in with the smallest width and height
that the application will encounter, in pixels (not dp units). The x
(width) dimension here directly corresponds to
Configuration.smallestScreenWidthDp
, except the value here is in raw
screen pixels rather than dp units. Your application may of course
still get smaller space yet if, for example, a soft keyboard is
being displayed.outLargestSize
- Filled in with the largest width and height
that the application will encounter, in pixels (not dp units). Your
application may of course still get larger space than this if,
for example, screen decorations like the status bar are being hidden.public int getMaximumSizeDimension()
@Deprecated public int getWidth()
getSize(Point)
instead.@Deprecated public int getHeight()
getSize(Point)
instead.public void getOverscanInsets(Rect outRect)
public int getRotation()
Surface.ROTATION_0
(no rotation), Surface.ROTATION_90
,
Surface.ROTATION_180
, or
Surface.ROTATION_270
. For
example, if a device has a naturally tall screen, and the user has
turned it on its side to go into a landscape orientation, the value
returned here may be either Surface.ROTATION_90
or Surface.ROTATION_270
depending on
the direction it was turned. The angle is the rotation of the drawn
graphics on the screen, which is the opposite direction of the physical
rotation of the device. For example, if the device is rotated 90
degrees counter-clockwise, to compensate rendering will be rotated by
90 degrees clockwise and thus the returned value here will be
Surface.ROTATION_90
.@Deprecated public int getOrientation()
getRotation()
@Deprecated public int getPixelFormat()
PixelFormat.RGBA_8888
.PixelFormat
.public float getRefreshRate()
@Deprecated public float[] getSupportedRefreshRates()
getSupportedModes()
instead
This method only returns refresh rates for the display's default modes. For more options, use
getSupportedModes()
.
public Display.Mode getMode()
public Display.Mode[] getSupportedModes()
public void requestColorMode(int colorMode)
public int getColorMode()
public Display.HdrCapabilities getHdrCapabilities()
public int[] getSupportedColorModes()
public long getAppVsyncOffsetNanos()
Apps generally do not need to be aware of this. It's only useful for fine-grained A/V synchronization.
public long getPresentationDeadlineNanos()
The desired presentation time for GLES rendering may be set with
EGLExt.eglPresentationTimeANDROID(android.opengl.EGLDisplay, android.opengl.EGLSurface, long)
. For video decoding, use
MediaCodec.releaseOutputBuffer(int, long)
. Times are
expressed in nanoseconds, using the system monotonic clock
(System.nanoTime()
).
public void getMetrics(DisplayMetrics outMetrics)
1. The returned size may be adjusted to exclude certain system decor elements that are always visible.
2. It may be scaled to provide compatibility with older applications that were originally designed for smaller displays.
3. It can be different depending on the WindowManager to which the display belongs.
- If requested from non-Activity context (e.g. Application context via
(WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)
)
metrics will report the size of the entire display based on current rotation and with
subtracted system decoration areas.
- If requested from activity (either using getWindowManager()
or
(WindowManager) getSystemService(Context.WINDOW_SERVICE)
) resulting metrics will
correspond to current app window metrics. In this case the size can be smaller than physical
size in multi-window mode.
outMetrics
- A DisplayMetrics
object to receive the metrics.public void getRealSize(Point outSize)
The size is adjusted based on the current rotation of the display.
The real size may be smaller than the physical size of the screen when the window manager is emulating a smaller display (using adb shell am display-size).
outSize
- Set to the real size of the display.public void getRealMetrics(DisplayMetrics outMetrics)
The size is adjusted based on the current rotation of the display.
The real size may be smaller than the physical size of the screen when the window manager is emulating a smaller display (using adb shell wm size).
outMetrics
- A DisplayMetrics
object to receive the metrics.public int getState()
STATE_OFF
, STATE_ON
,
STATE_DOZE
, STATE_DOZE_SUSPEND
, or STATE_UNKNOWN
.public boolean hasAccess(int uid)
public static boolean hasAccess(int uid, int flags, int ownerUid)
public boolean isPublicPresentation()
public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
public static String typeToString(int type)
public static String stateToString(int state)
public static boolean isSuspendedState(int state)