2 * Copyright (C) 2006 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 import android.annotation.RequiresPermission;
20 import android.content.Context;
21 import android.content.res.CompatibilityInfo;
22 import android.content.res.Resources;
23 import android.graphics.PixelFormat;
24 import android.graphics.Point;
25 import android.graphics.Rect;
26 import android.hardware.display.DisplayManagerGlobal;
27 import android.os.Parcel;
28 import android.os.Parcelable;
29 import android.os.Process;
30 import android.os.SystemClock;
31 import android.util.DisplayMetrics;
32 import android.util.Log;
34 import java.util.Arrays;
36 import static android.Manifest.permission.CONFIGURE_DISPLAY_COLOR_TRANSFORM;
39 * Provides information about the size and density of a logical display.
41 * The display area is described in two different ways.
43 * <li>The application display area specifies the part of the display that may contain
44 * an application window, excluding the system decorations. The application display area may
45 * be smaller than the real display area because the system subtracts the space needed
46 * for decor elements such as the status bar. Use the following methods to query the
47 * application display area: {@link #getSize}, {@link #getRectSize} and {@link #getMetrics}.</li>
48 * <li>The real display area specifies the part of the display that contains content
49 * including the system decorations. Even so, the real display area may be smaller than the
50 * physical size of the display if the window manager is emulating a smaller display
51 * using (adb shell am display-size). Use the following methods to query the
52 * real display area: {@link #getRealSize}, {@link #getRealMetrics}.</li>
55 * A logical display does not necessarily represent a particular physical display device
56 * such as the built-in screen or an external monitor. The contents of a logical
57 * display may be presented on one or more physical displays according to the devices
58 * that are currently attached and whether mirroring has been enabled.
61 public final class Display {
62 private static final String TAG = "Display";
63 private static final boolean DEBUG = false;
65 private final DisplayManagerGlobal mGlobal;
66 private final int mDisplayId;
67 private final int mLayerStack;
68 private final int mFlags;
69 private final int mType;
70 private final String mAddress;
71 private final int mOwnerUid;
72 private final String mOwnerPackageName;
73 private final DisplayAdjustments mDisplayAdjustments;
75 private DisplayInfo mDisplayInfo; // never null
76 private boolean mIsValid;
78 // Temporary display metrics structure used for compatibility mode.
79 private final DisplayMetrics mTempMetrics = new DisplayMetrics();
81 // We cache the app width and height properties briefly between calls
82 // to getHeight() and getWidth() to ensure that applications perceive
83 // consistent results when the size changes (most of the time).
84 // Applications should now be using getSize() instead.
85 private static final int CACHED_APP_SIZE_DURATION_MILLIS = 20;
86 private long mLastCachedAppSizeUpdate;
87 private int mCachedAppWidthCompat;
88 private int mCachedAppHeightCompat;
91 * The default Display id, which is the id of the built-in primary display
92 * assuming there is one.
94 public static final int DEFAULT_DISPLAY = 0;
99 public static final int INVALID_DISPLAY = -1;
102 * Display flag: Indicates that the display supports compositing content
103 * that is stored in protected graphics buffers.
105 * If this flag is set then the display device supports compositing protected buffers.
107 * If this flag is not set then the display device may not support compositing
108 * protected buffers; the user may see a blank region on the screen instead of
109 * the protected content.
111 * Secure (DRM) video decoders may allocate protected graphics buffers to request that
112 * a hardware-protected path be provided between the video decoder and the external
113 * display sink. If a hardware-protected path is not available, then content stored
114 * in protected graphics buffers may not be composited.
116 * An application can use the absence of this flag as a hint that it should not use protected
117 * buffers for this display because the content may not be visible. For example,
118 * if the flag is not set then the application may choose not to show content on this
119 * display, show an informative error message, select an alternate content stream
120 * or adopt a different strategy for decoding content that does not rely on
126 public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 0;
129 * Display flag: Indicates that the display has a secure video output and
130 * supports compositing secure surfaces.
132 * If this flag is set then the display device has a secure video output
133 * and is capable of showing secure surfaces. It may also be capable of
134 * showing {@link #FLAG_SUPPORTS_PROTECTED_BUFFERS protected buffers}.
136 * If this flag is not set then the display device may not have a secure video
137 * output; the user may see a blank region on the screen instead of
138 * the contents of secure surfaces or protected buffers.
140 * Secure surfaces are used to prevent content rendered into those surfaces
141 * by applications from appearing in screenshots or from being viewed
142 * on non-secure displays. Protected buffers are used by secure video decoders
143 * for a similar purpose.
145 * An application creates a window with a secure surface by specifying the
146 * {@link WindowManager.LayoutParams#FLAG_SECURE} window flag.
147 * Likewise, an application creates a {@link SurfaceView} with a secure surface
148 * by calling {@link SurfaceView#setSecure} before attaching the secure view to
149 * its containing window.
151 * An application can use the absence of this flag as a hint that it should not create
152 * secure surfaces or protected buffers on this display because the content may
153 * not be visible. For example, if the flag is not set then the application may
154 * choose not to show content on this display, show an informative error message,
155 * select an alternate content stream or adopt a different strategy for decoding
156 * content that does not rely on secure surfaces or protected buffers.
161 public static final int FLAG_SECURE = 1 << 1;
164 * Display flag: Indicates that the display is private. Only the application that
165 * owns the display can create windows on it.
169 public static final int FLAG_PRIVATE = 1 << 2;
172 * Display flag: Indicates that the display is a presentation display.
174 * This flag identifies secondary displays that are suitable for
175 * use as presentation displays such as HDMI or Wireless displays. Applications
176 * may automatically project their content to presentation displays to provide
177 * richer second screen experiences.
182 public static final int FLAG_PRESENTATION = 1 << 3;
185 * Display flag: Indicates that the display has a round shape.
187 * This flag identifies displays that are circular, elliptical or otherwise
188 * do not permit the user to see all the way to the logical corners of the display.
193 public static final int FLAG_ROUND = 1 << 4;
196 * Display flag: Indicates that the contents of the display should not be scaled
197 * to fit the physical screen dimensions. Used for development only to emulate
198 * devices with smaller physicals screens while preserving density.
202 public static final int FLAG_SCALING_DISABLED = 1 << 30;
205 * Display type: Unknown display type.
208 public static final int TYPE_UNKNOWN = 0;
211 * Display type: Built-in display.
214 public static final int TYPE_BUILT_IN = 1;
217 * Display type: HDMI display.
220 public static final int TYPE_HDMI = 2;
223 * Display type: WiFi display.
226 public static final int TYPE_WIFI = 3;
229 * Display type: Overlay display.
232 public static final int TYPE_OVERLAY = 4;
235 * Display type: Virtual display.
238 public static final int TYPE_VIRTUAL = 5;
241 * Display state: The display state is unknown.
245 public static final int STATE_UNKNOWN = 0;
248 * Display state: The display is off.
252 public static final int STATE_OFF = 1;
255 * Display state: The display is on.
259 public static final int STATE_ON = 2;
262 * Display state: The display is dozing in a low power state; it is still
263 * on but is optimized for showing system-provided content while the
264 * device is non-interactive.
267 * @see android.os.PowerManager#isInteractive
269 public static final int STATE_DOZE = 3;
272 * Display state: The display is dozing in a suspended low power state; it is still
273 * on but is optimized for showing static system-provided content while the device
274 * is non-interactive. This mode may be used to conserve even more power by allowing
275 * the hardware to stop applying frame buffer updates from the graphics subsystem or
276 * to take over the display and manage it autonomously to implement low power always-on
277 * display functionality.
280 * @see android.os.PowerManager#isInteractive
282 public static final int STATE_DOZE_SUSPEND = 4;
285 * Internal method to create a display.
286 * Applications should use {@link android.view.WindowManager#getDefaultDisplay()}
287 * or {@link android.hardware.display.DisplayManager#getDisplay}
288 * to get a display object.
292 public Display(DisplayManagerGlobal global,
293 int displayId, DisplayInfo displayInfo /*not null*/,
294 DisplayAdjustments daj) {
296 mDisplayId = displayId;
297 mDisplayInfo = displayInfo;
298 mDisplayAdjustments = new DisplayAdjustments(daj);
301 // Cache properties that cannot change as long as the display is valid.
302 mLayerStack = displayInfo.layerStack;
303 mFlags = displayInfo.flags;
304 mType = displayInfo.type;
305 mAddress = displayInfo.address;
306 mOwnerUid = displayInfo.ownerUid;
307 mOwnerPackageName = displayInfo.ownerPackageName;
311 * Gets the display id.
313 * Each logical display has a unique id.
314 * The default display has id {@link #DEFAULT_DISPLAY}.
317 public int getDisplayId() {
322 * Returns true if this display is still valid, false if the display has been removed.
324 * If the display is invalid, then the methods of this class will
325 * continue to report the most recently observed display information.
326 * However, it is unwise (and rather fruitless) to continue using a
327 * {@link Display} object after the display's demise.
329 * It's possible for a display that was previously invalid to become
330 * valid again if a display with the same id is reconnected.
332 * @return True if the display is still valid.
334 public boolean isValid() {
335 synchronized (this) {
336 updateDisplayInfoLocked();
342 * Gets a full copy of the display information.
344 * @param outDisplayInfo The object to receive the copy of the display information.
345 * @return True if the display is still valid.
348 public boolean getDisplayInfo(DisplayInfo outDisplayInfo) {
349 synchronized (this) {
350 updateDisplayInfoLocked();
351 outDisplayInfo.copyFrom(mDisplayInfo);
357 * Gets the display's layer stack.
359 * Each display has its own independent layer stack upon which surfaces
360 * are placed to be managed by surface flinger.
362 * @return The display's layer stack number.
365 public int getLayerStack() {
370 * Returns a combination of flags that describe the capabilities of the display.
372 * @return The display flags.
374 * @see #FLAG_SUPPORTS_PROTECTED_BUFFERS
378 public int getFlags() {
383 * Gets the display type.
385 * @return The display type.
388 * @see #TYPE_BUILT_IN
395 public int getType() {
400 * Gets the display address, or null if none.
401 * Interpretation varies by display type.
403 * @return The display address.
406 public String getAddress() {
411 * Gets the UID of the application that owns this display, or zero if it is
412 * owned by the system.
414 * If the display is private, then only the owner can use it.
419 public int getOwnerUid() {
424 * Gets the package name of the application that owns this display, or null if it is
425 * owned by the system.
427 * If the display is private, then only the owner can use it.
432 public String getOwnerPackageName() {
433 return mOwnerPackageName;
437 * Gets the compatibility info used by this display instance.
439 * @return The display adjustments holder, or null if none is required.
442 public DisplayAdjustments getDisplayAdjustments() {
443 return mDisplayAdjustments;
447 * Gets the name of the display.
449 * Note that some displays may be renamed by the user.
452 * @return The display's name.
454 public String getName() {
455 synchronized (this) {
456 updateDisplayInfoLocked();
457 return mDisplayInfo.name;
462 * Gets the size of the display, in pixels.
464 * Note that this value should <em>not</em> be used for computing layouts,
465 * since a device will typically have screen decoration (such as a status bar)
466 * along the edges of the display that reduce the amount of application
467 * space available from the size returned here. Layouts should instead use
470 * The size is adjusted based on the current rotation of the display.
472 * The size returned by this method does not necessarily represent the
473 * actual raw size (native resolution) of the display. The returned size may
474 * be adjusted to exclude certain system decoration elements that are always visible.
475 * It may also be scaled to provide compatibility with older applications that
476 * were originally designed for smaller displays.
479 * @param outSize A {@link Point} object to receive the size information.
481 public void getSize(Point outSize) {
482 synchronized (this) {
483 updateDisplayInfoLocked();
484 mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments);
485 outSize.x = mTempMetrics.widthPixels;
486 outSize.y = mTempMetrics.heightPixels;
491 * Gets the size of the display as a rectangle, in pixels.
493 * @param outSize A {@link Rect} object to receive the size information.
494 * @see #getSize(Point)
496 public void getRectSize(Rect outSize) {
497 synchronized (this) {
498 updateDisplayInfoLocked();
499 mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments);
500 outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels);
505 * Return the range of display sizes an application can expect to encounter
506 * under normal operation, as long as there is no physical change in screen
507 * size. This is basically the sizes you will see as the orientation
508 * changes, taking into account whatever screen decoration there is in
509 * each rotation. For example, the status bar is always at the top of the
510 * screen, so it will reduce the height both in landscape and portrait, and
511 * the smallest height returned here will be the smaller of the two.
513 * This is intended for applications to get an idea of the range of sizes
514 * they will encounter while going through device rotations, to provide a
515 * stable UI through rotation. The sizes here take into account all standard
516 * system decorations that reduce the size actually available to the
517 * application: the status bar, navigation bar, system bar, etc. It does
518 * <em>not</em> take into account more transient elements like an IME
521 * @param outSmallestSize Filled in with the smallest width and height
522 * that the application will encounter, in pixels (not dp units). The x
523 * (width) dimension here directly corresponds to
524 * {@link android.content.res.Configuration#smallestScreenWidthDp
525 * Configuration.smallestScreenWidthDp}, except the value here is in raw
526 * screen pixels rather than dp units. Your application may of course
527 * still get smaller space yet if, for example, a soft keyboard is
529 * @param outLargestSize Filled in with the largest width and height
530 * that the application will encounter, in pixels (not dp units). Your
531 * application may of course still get larger space than this if,
532 * for example, screen decorations like the status bar are being hidden.
534 public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) {
535 synchronized (this) {
536 updateDisplayInfoLocked();
537 outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth;
538 outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight;
539 outLargestSize.x = mDisplayInfo.largestNominalAppWidth;
540 outLargestSize.y = mDisplayInfo.largestNominalAppHeight;
545 * Return the maximum screen size dimension that will happen. This is
546 * mostly for wallpapers.
549 public int getMaximumSizeDimension() {
550 synchronized (this) {
551 updateDisplayInfoLocked();
552 return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
557 * @deprecated Use {@link #getSize(Point)} instead.
560 public int getWidth() {
561 synchronized (this) {
562 updateCachedAppSizeIfNeededLocked();
563 return mCachedAppWidthCompat;
568 * @deprecated Use {@link #getSize(Point)} instead.
571 public int getHeight() {
572 synchronized (this) {
573 updateCachedAppSizeIfNeededLocked();
574 return mCachedAppHeightCompat;
580 * Return a rectangle defining the insets of the overscan region of the display.
581 * Each field of the rectangle is the number of pixels the overscan area extends
582 * into the display on that side.
584 public void getOverscanInsets(Rect outRect) {
585 synchronized (this) {
586 updateDisplayInfoLocked();
587 outRect.set(mDisplayInfo.overscanLeft, mDisplayInfo.overscanTop,
588 mDisplayInfo.overscanRight, mDisplayInfo.overscanBottom);
593 * Returns the rotation of the screen from its "natural" orientation.
594 * The returned value may be {@link Surface#ROTATION_0 Surface.ROTATION_0}
595 * (no rotation), {@link Surface#ROTATION_90 Surface.ROTATION_90},
596 * {@link Surface#ROTATION_180 Surface.ROTATION_180}, or
597 * {@link Surface#ROTATION_270 Surface.ROTATION_270}. For
598 * example, if a device has a naturally tall screen, and the user has
599 * turned it on its side to go into a landscape orientation, the value
600 * returned here may be either {@link Surface#ROTATION_90 Surface.ROTATION_90}
601 * or {@link Surface#ROTATION_270 Surface.ROTATION_270} depending on
602 * the direction it was turned. The angle is the rotation of the drawn
603 * graphics on the screen, which is the opposite direction of the physical
604 * rotation of the device. For example, if the device is rotated 90
605 * degrees counter-clockwise, to compensate rendering will be rotated by
606 * 90 degrees clockwise and thus the returned value here will be
607 * {@link Surface#ROTATION_90 Surface.ROTATION_90}.
610 public int getRotation() {
611 synchronized (this) {
612 updateDisplayInfoLocked();
613 return mDisplayInfo.rotation;
618 * @deprecated use {@link #getRotation}
619 * @return orientation of this display.
623 public int getOrientation() {
624 return getRotation();
628 * Gets the pixel format of the display.
629 * @return One of the constants defined in {@link android.graphics.PixelFormat}.
631 * @deprecated This method is no longer supported.
632 * The result is always {@link PixelFormat#RGBA_8888}.
635 public int getPixelFormat() {
636 return PixelFormat.RGBA_8888;
640 * Gets the refresh rate of this display in frames per second.
642 public float getRefreshRate() {
643 synchronized (this) {
644 updateDisplayInfoLocked();
645 return mDisplayInfo.getMode().getRefreshRate();
650 * Get the supported refresh rates of this display in frames per second.
652 * This method only returns refresh rates for the display's default modes. For more options, use
653 * {@link #getSupportedModes()}.
655 * @deprecated use {@link #getSupportedModes()} instead
658 public float[] getSupportedRefreshRates() {
659 synchronized (this) {
660 updateDisplayInfoLocked();
661 return mDisplayInfo.getDefaultRefreshRates();
666 * Returns the active mode of the display.
668 public Mode getMode() {
669 synchronized (this) {
670 updateDisplayInfoLocked();
671 return mDisplayInfo.getMode();
676 * Gets the supported modes of this display.
678 public Mode[] getSupportedModes() {
679 synchronized (this) {
680 updateDisplayInfoLocked();
681 final Display.Mode[] modes = mDisplayInfo.supportedModes;
682 return Arrays.copyOf(modes, modes.length);
687 * Request the display applies a color transform.
690 @RequiresPermission(CONFIGURE_DISPLAY_COLOR_TRANSFORM)
691 public void requestColorTransform(ColorTransform colorTransform) {
692 mGlobal.requestColorTransform(mDisplayId, colorTransform.getId());
696 * Returns the active color transform of this display
699 public ColorTransform getColorTransform() {
700 synchronized (this) {
701 updateDisplayInfoLocked();
702 return mDisplayInfo.getColorTransform();
707 * Returns the default color transform of this display
710 public ColorTransform getDefaultColorTransform() {
711 synchronized (this) {
712 updateDisplayInfoLocked();
713 return mDisplayInfo.getDefaultColorTransform();
718 * Gets the supported color transforms of this device.
721 public ColorTransform[] getSupportedColorTransforms() {
722 synchronized (this) {
723 updateDisplayInfoLocked();
724 ColorTransform[] transforms = mDisplayInfo.supportedColorTransforms;
725 return Arrays.copyOf(transforms, transforms.length);
730 * Gets the app VSYNC offset, in nanoseconds. This is a positive value indicating
731 * the phase offset of the VSYNC events provided by Choreographer relative to the
732 * display refresh. For example, if Choreographer reports that the refresh occurred
733 * at time N, it actually occurred at (N - appVsyncOffset).
735 * Apps generally do not need to be aware of this. It's only useful for fine-grained
736 * A/V synchronization.
738 public long getAppVsyncOffsetNanos() {
739 synchronized (this) {
740 updateDisplayInfoLocked();
741 return mDisplayInfo.appVsyncOffsetNanos;
746 * This is how far in advance a buffer must be queued for presentation at
747 * a given time. If you want a buffer to appear on the screen at
748 * time N, you must submit the buffer before (N - presentationDeadline).
750 * The desired presentation time for GLES rendering may be set with
751 * {@link android.opengl.EGLExt#eglPresentationTimeANDROID}. For video decoding, use
752 * {@link android.media.MediaCodec#releaseOutputBuffer(int, long)}. Times are
753 * expressed in nanoseconds, using the system monotonic clock
754 * ({@link System#nanoTime}).
756 public long getPresentationDeadlineNanos() {
757 synchronized (this) {
758 updateDisplayInfoLocked();
759 return mDisplayInfo.presentationDeadlineNanos;
764 * Gets display metrics that describe the size and density of this display.
766 * The size is adjusted based on the current rotation of the display.
768 * The size returned by this method does not necessarily represent the
769 * actual raw size (native resolution) of the display. The returned size may
770 * be adjusted to exclude certain system decor elements that are always visible.
771 * It may also be scaled to provide compatibility with older applications that
772 * were originally designed for smaller displays.
775 * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
777 public void getMetrics(DisplayMetrics outMetrics) {
778 synchronized (this) {
779 updateDisplayInfoLocked();
780 mDisplayInfo.getAppMetrics(outMetrics, mDisplayAdjustments);
785 * Gets the real size of the display without subtracting any window decor or
786 * applying any compatibility scale factors.
788 * The size is adjusted based on the current rotation of the display.
790 * The real size may be smaller than the physical size of the screen when the
791 * window manager is emulating a smaller display (using adb shell am display-size).
794 * @param outSize Set to the real size of the display.
796 public void getRealSize(Point outSize) {
797 synchronized (this) {
798 updateDisplayInfoLocked();
799 outSize.x = mDisplayInfo.logicalWidth;
800 outSize.y = mDisplayInfo.logicalHeight;
805 * Gets display metrics based on the real size of this display.
807 * The size is adjusted based on the current rotation of the display.
809 * The real size may be smaller than the physical size of the screen when the
810 * window manager is emulating a smaller display (using adb shell am display-size).
813 * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
815 public void getRealMetrics(DisplayMetrics outMetrics) {
816 synchronized (this) {
817 updateDisplayInfoLocked();
818 mDisplayInfo.getLogicalMetrics(outMetrics,
819 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO,
820 mDisplayAdjustments.getConfiguration());
825 * Gets the state of the display, such as whether it is on or off.
827 * @return The state of the display: one of {@link #STATE_OFF}, {@link #STATE_ON},
828 * {@link #STATE_DOZE}, {@link #STATE_DOZE_SUSPEND}, or {@link #STATE_UNKNOWN}.
830 public int getState() {
831 synchronized (this) {
832 updateDisplayInfoLocked();
833 return mIsValid ? mDisplayInfo.state : STATE_UNKNOWN;
838 * Returns true if the specified UID has access to this display.
841 public boolean hasAccess(int uid) {
842 return Display.hasAccess(uid, mFlags, mOwnerUid);
846 public static boolean hasAccess(int uid, int flags, int ownerUid) {
847 return (flags & Display.FLAG_PRIVATE) == 0
849 || uid == Process.SYSTEM_UID
854 * Returns true if the display is a public presentation display.
857 public boolean isPublicPresentation() {
858 return (mFlags & (Display.FLAG_PRIVATE | Display.FLAG_PRESENTATION)) ==
859 Display.FLAG_PRESENTATION;
862 private void updateDisplayInfoLocked() {
863 // Note: The display manager caches display info objects on our behalf.
864 DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId);
865 if (newInfo == null) {
866 // Preserve the old mDisplayInfo after the display is removed.
870 Log.d(TAG, "Logical display " + mDisplayId + " was removed.");
874 // Use the new display info. (It might be the same object if nothing changed.)
875 mDisplayInfo = newInfo;
879 Log.d(TAG, "Logical display " + mDisplayId + " was recreated.");
885 private void updateCachedAppSizeIfNeededLocked() {
886 long now = SystemClock.uptimeMillis();
887 if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) {
888 updateDisplayInfoLocked();
889 mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments);
890 mCachedAppWidthCompat = mTempMetrics.widthPixels;
891 mCachedAppHeightCompat = mTempMetrics.heightPixels;
892 mLastCachedAppSizeUpdate = now;
896 // For debugging purposes
898 public String toString() {
899 synchronized (this) {
900 updateDisplayInfoLocked();
901 mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments);
902 return "Display id " + mDisplayId + ": " + mDisplayInfo
903 + ", " + mTempMetrics + ", isValid=" + mIsValid;
910 public static String typeToString(int type) {
925 return Integer.toString(type);
932 public static String stateToString(int state) {
942 case STATE_DOZE_SUSPEND:
943 return "DOZE_SUSPEND";
945 return Integer.toString(state);
950 * Returns true if display updates may be suspended while in the specified
951 * display power state.
954 public static boolean isSuspendedState(int state) {
955 return state == STATE_OFF || state == STATE_DOZE_SUSPEND;
959 * A mode supported by a given display.
961 * @see Display#getSupportedModes()
963 public static final class Mode implements Parcelable {
967 public static final Mode[] EMPTY_ARRAY = new Mode[0];
969 private final int mModeId;
970 private final int mWidth;
971 private final int mHeight;
972 private final float mRefreshRate;
977 public Mode(int modeId, int width, int height, float refreshRate) {
981 mRefreshRate = refreshRate;
985 * Returns this mode's id.
987 public int getModeId() {
992 * Returns the physical width of the display in pixels when configured in this mode's
995 * Note that due to application UI scaling, the number of pixels made available to
996 * applications when the mode is active (as reported by {@link Display#getWidth()} may
997 * differ from the mode's actual resolution (as reported by this function).
999 * For example, applications running on a 4K display may have their UI laid out and rendered
1000 * in 1080p and then scaled up. Applications can take advantage of the extra resolution by
1001 * rendering content through a {@link android.view.SurfaceView} using full size buffers.
1003 public int getPhysicalWidth() {
1008 * Returns the physical height of the display in pixels when configured in this mode's
1011 * Note that due to application UI scaling, the number of pixels made available to
1012 * applications when the mode is active (as reported by {@link Display#getHeight()} may
1013 * differ from the mode's actual resolution (as reported by this function).
1015 * For example, applications running on a 4K display may have their UI laid out and rendered
1016 * in 1080p and then scaled up. Applications can take advantage of the extra resolution by
1017 * rendering content through a {@link android.view.SurfaceView} using full size buffers.
1019 public int getPhysicalHeight() {
1024 * Returns the refresh rate in frames per second.
1026 public float getRefreshRate() {
1027 return mRefreshRate;
1031 * Returns {@code true} if this mode matches the given parameters.
1035 public boolean matches(int width, int height, float refreshRate) {
1036 return mWidth == width &&
1037 mHeight == height &&
1038 Float.floatToIntBits(mRefreshRate) == Float.floatToIntBits(refreshRate);
1042 public boolean equals(Object other) {
1043 if (this == other) {
1046 if (!(other instanceof Mode)) {
1049 Mode that = (Mode) other;
1050 return mModeId == that.mModeId && matches(that.mWidth, that.mHeight, that.mRefreshRate);
1054 public int hashCode() {
1056 hash = hash * 17 + mModeId;
1057 hash = hash * 17 + mWidth;
1058 hash = hash * 17 + mHeight;
1059 hash = hash * 17 + Float.floatToIntBits(mRefreshRate);
1064 public String toString() {
1065 return new StringBuilder("{")
1066 .append("id=").append(mModeId)
1067 .append(", width=").append(mWidth)
1068 .append(", height=").append(mHeight)
1069 .append(", fps=").append(mRefreshRate)
1075 public int describeContents() {
1079 private Mode(Parcel in) {
1080 this(in.readInt(), in.readInt(), in.readInt(), in.readFloat());
1084 public void writeToParcel(Parcel out, int parcelableFlags) {
1085 out.writeInt(mModeId);
1086 out.writeInt(mWidth);
1087 out.writeInt(mHeight);
1088 out.writeFloat(mRefreshRate);
1091 @SuppressWarnings("hiding")
1092 public static final Parcelable.Creator<Mode> CREATOR
1093 = new Parcelable.Creator<Mode>() {
1095 public Mode createFromParcel(Parcel in) {
1096 return new Mode(in);
1100 public Mode[] newArray(int size) {
1101 return new Mode[size];
1107 * A color transform supported by a given display.
1109 * @see Display#getSupportedColorTransforms()
1112 public static final class ColorTransform implements Parcelable {
1113 public static final ColorTransform[] EMPTY_ARRAY = new ColorTransform[0];
1115 private final int mId;
1116 private final int mColorTransform;
1118 public ColorTransform(int id, int colorTransform) {
1120 mColorTransform = colorTransform;
1123 public int getId() {
1127 public int getColorTransform() {
1128 return mColorTransform;
1132 public boolean equals(Object other) {
1133 if (this == other) {
1136 if (!(other instanceof ColorTransform)) {
1139 ColorTransform that = (ColorTransform) other;
1140 return mId == that.mId
1141 && mColorTransform == that.mColorTransform;
1145 public int hashCode() {
1147 hash = hash * 17 + mId;
1148 hash = hash * 17 + mColorTransform;
1153 public String toString() {
1154 return new StringBuilder("{")
1155 .append("id=").append(mId)
1156 .append(", colorTransform=").append(mColorTransform)
1162 public int describeContents() {
1166 private ColorTransform(Parcel in) {
1167 this(in.readInt(), in.readInt());
1171 public void writeToParcel(Parcel out, int parcelableFlags) {
1173 out.writeInt(mColorTransform);
1176 @SuppressWarnings("hiding")
1177 public static final Parcelable.Creator<ColorTransform> CREATOR
1178 = new Parcelable.Creator<ColorTransform>() {
1180 public ColorTransform createFromParcel(Parcel in) {
1181 return new ColorTransform(in);
1185 public ColorTransform[] newArray(int size) {
1186 return new ColorTransform[size];