19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2006 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.view;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1967e2ae86396c6d0f989285275cbf908dee5e71f7Aurimas Liutikasimport static android.Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE;
2067e2ae86396c6d0f989285275cbf908dee5e71f7Aurimas Liutikas
21f173c323449840771312afe5cbec03a71281e6ffRonghua Wuimport android.annotation.IntDef;
2258e829f71d2c525309e5bb5a1c02dc64397df221Michael Wrightimport android.annotation.RequiresPermission;
2348d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautnerimport android.content.res.CompatibilityInfo;
24609bf65668181d93502a57575f6f20281f2494b8Bryce Leeimport android.content.res.Resources;
25fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brownimport android.graphics.PixelFormat;
26ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackbornimport android.graphics.Point;
27ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackbornimport android.graphics.Rect;
28bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brownimport android.hardware.display.DisplayManagerGlobal;
29b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligandimport android.os.Parcel;
30b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligandimport android.os.Parcelable;
31a506a6ec94863a35acca9feb165db76ddac3892cJeff Brownimport android.os.Process;
32ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackbornimport android.os.SystemClock;
339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.DisplayMetrics;
34fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brownimport android.util.Log;
359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
36f173c323449840771312afe5cbec03a71281e6ffRonghua Wuimport java.lang.annotation.Retention;
37f173c323449840771312afe5cbec03a71281e6ffRonghua Wuimport java.lang.annotation.RetentionPolicy;
383f145a2f958320766ae9240c7a57debc20d578aaMichael Wrightimport java.util.Arrays;
393f145a2f958320766ae9240c7a57debc20d578aaMichael Wright
40bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown/**
41fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * Provides information about the size and density of a logical display.
42fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <p>
43fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * The display area is described in two different ways.
44fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <ul>
45fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <li>The application display area specifies the part of the display that may contain
46fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * an application window, excluding the system decorations.  The application display area may
47fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * be smaller than the real display area because the system subtracts the space needed
48fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * for decor elements such as the status bar.  Use the following methods to query the
49fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * application display area: {@link #getSize}, {@link #getRectSize} and {@link #getMetrics}.</li>
50fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <li>The real display area specifies the part of the display that contains content
51fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * including the system decorations.  Even so, the real display area may be smaller than the
52fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * physical size of the display if the window manager is emulating a smaller display
53cd097993399f94aa663c5fad50e444b75e6ee5ddAndrii Kulian * using (adb shell wm size).  Use the following methods to query the
54fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * real display area: {@link #getRealSize}, {@link #getRealMetrics}.</li>
55fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </ul>
56fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </p><p>
57fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * A logical display does not necessarily represent a particular physical display device
58fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * such as the built-in screen or an external monitor.  The contents of a logical
59fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * display may be presented on one or more physical displays according to the devices
60fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * that are currently attached and whether mirroring has been enabled.
61fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </p>
62bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown */
63fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brownpublic final class Display {
64fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private static final String TAG = "Display";
65bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    private static final boolean DEBUG = false;
66fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
67bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    private final DisplayManagerGlobal mGlobal;
68fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private final int mDisplayId;
694ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown    private final int mLayerStack;
7092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    private final int mFlags;
7192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    private final int mType;
7292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    private final String mAddress;
73a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    private final int mOwnerUid;
74a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    private final String mOwnerPackageName;
75609bf65668181d93502a57575f6f20281f2494b8Bryce Lee    private final Resources mResources;
76609bf65668181d93502a57575f6f20281f2494b8Bryce Lee    private DisplayAdjustments mDisplayAdjustments;
77bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown
78bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    private DisplayInfo mDisplayInfo; // never null
79bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    private boolean mIsValid;
80fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
81fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // Temporary display metrics structure used for compatibility mode.
82fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private final DisplayMetrics mTempMetrics = new DisplayMetrics();
83fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
84fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // We cache the app width and height properties briefly between calls
85fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // to getHeight() and getWidth() to ensure that applications perceive
86fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // consistent results when the size changes (most of the time).
87fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // Applications should now be using getSize() instead.
88fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private static final int CACHED_APP_SIZE_DURATION_MILLIS = 20;
89fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private long mLastCachedAppSizeUpdate;
90fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private int mCachedAppWidthCompat;
91fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private int mCachedAppHeightCompat;
925fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn
939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
9498365d7663cbd82979a5700faf0050220b01084dJeff Brown     * The default Display id, which is the id of the built-in primary display
9598365d7663cbd82979a5700faf0050220b01084dJeff Brown     * assuming there is one.
969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int DEFAULT_DISPLAY = 0;
989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
10026698514fbac587675221149aca98f3ea6414d55Wale Ogunwale     * Invalid display id.
10126698514fbac587675221149aca98f3ea6414d55Wale Ogunwale     */
10226698514fbac587675221149aca98f3ea6414d55Wale Ogunwale    public static final int INVALID_DISPLAY = -1;
10326698514fbac587675221149aca98f3ea6414d55Wale Ogunwale
10426698514fbac587675221149aca98f3ea6414d55Wale Ogunwale    /**
10577aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown     * Display flag: Indicates that the display supports compositing content
10677aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown     * that is stored in protected graphics buffers.
107c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * <p>
108f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * If this flag is set then the display device supports compositing protected buffers.
109f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * </p><p>
110f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * If this flag is not set then the display device may not support compositing
111f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * protected buffers; the user may see a blank region on the screen instead of
112f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * the protected content.
113f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * </p><p>
11477aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown     * Secure (DRM) video decoders may allocate protected graphics buffers to request that
11577aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown     * a hardware-protected path be provided between the video decoder and the external
11677aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown     * display sink.  If a hardware-protected path is not available, then content stored
11777aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown     * in protected graphics buffers may not be composited.
118c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * </p><p>
119f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * An application can use the absence of this flag as a hint that it should not use protected
120f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * buffers for this display because the content may not be visible.  For example,
121f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * if the flag is not set then the application may choose not to show content on this
122f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * display, show an informative error message, select an alternate content stream
123f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * or adopt a different strategy for decoding content that does not rely on
124f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * protected buffers.
125c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * </p>
126f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     *
127f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * @see #getFlags
128c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     */
12977aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown    public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 0;
130c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown
131c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown    /**
132f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * Display flag: Indicates that the display has a secure video output and
133f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * supports compositing secure surfaces.
134f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * <p>
135f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * If this flag is set then the display device has a secure video output
136f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * and is capable of showing secure surfaces.  It may also be capable of
137f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * showing {@link #FLAG_SUPPORTS_PROTECTED_BUFFERS protected buffers}.
138f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * </p><p>
139f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * If this flag is not set then the display device may not have a secure video
140f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * output; the user may see a blank region on the screen instead of
141f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * the contents of secure surfaces or protected buffers.
142f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * </p><p>
143f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * Secure surfaces are used to prevent content rendered into those surfaces
144f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * by applications from appearing in screenshots or from being viewed
145f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * on non-secure displays.  Protected buffers are used by secure video decoders
146f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * for a similar purpose.
147f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * </p><p>
148f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * An application creates a window with a secure surface by specifying the
149f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * {@link WindowManager.LayoutParams#FLAG_SECURE} window flag.
150f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * Likewise, an application creates a {@link SurfaceView} with a secure surface
151f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * by calling {@link SurfaceView#setSecure} before attaching the secure view to
152f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * its containing window.
153f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * </p><p>
154f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * An application can use the absence of this flag as a hint that it should not create
155f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * secure surfaces or protected buffers on this display because the content may
156f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * not be visible.  For example, if the flag is not set then the application may
157f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * choose not to show content on this display, show an informative error message,
158f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * select an alternate content stream or adopt a different strategy for decoding
159f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * content that does not rely on secure surfaces or protected buffers.
160f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * </p>
161f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     *
162f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * @see #getFlags
163f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     */
164f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown    public static final int FLAG_SECURE = 1 << 1;
165f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown
166f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown    /**
167a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * Display flag: Indicates that the display is private.  Only the application that
168fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian     * owns the display and apps that are already on the display can create windows on it.
1697d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown     *
1707d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown     * @see #getFlags
1717d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown     */
1727d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown    public static final int FLAG_PRIVATE = 1 << 2;
1737d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown
1747d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown    /**
1757d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown     * Display flag: Indicates that the display is a presentation display.
176a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * <p>
1777d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown     * This flag identifies secondary displays that are suitable for
1787d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown     * use as presentation displays such as HDMI or Wireless displays.  Applications
1797d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown     * may automatically project their content to presentation displays to provide
1807d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown     * richer second screen experiences.
181a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * </p>
182a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     *
183a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * @see #getFlags
184a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     */
1857d00affce6e25b22fd8fc135933b3bf6b547a0dcJeff Brown    public static final int FLAG_PRESENTATION = 1 << 3;
186a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown
187a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    /**
18849e7ff9647e6547c2b852944a5435a05794b9951Adam Powell     * Display flag: Indicates that the display has a round shape.
18949e7ff9647e6547c2b852944a5435a05794b9951Adam Powell     * <p>
19049e7ff9647e6547c2b852944a5435a05794b9951Adam Powell     * This flag identifies displays that are circular, elliptical or otherwise
19149e7ff9647e6547c2b852944a5435a05794b9951Adam Powell     * do not permit the user to see all the way to the logical corners of the display.
19249e7ff9647e6547c2b852944a5435a05794b9951Adam Powell     * </p>
19349e7ff9647e6547c2b852944a5435a05794b9951Adam Powell     *
19449e7ff9647e6547c2b852944a5435a05794b9951Adam Powell     * @see #getFlags
19549e7ff9647e6547c2b852944a5435a05794b9951Adam Powell     */
19649e7ff9647e6547c2b852944a5435a05794b9951Adam Powell    public static final int FLAG_ROUND = 1 << 4;
19749e7ff9647e6547c2b852944a5435a05794b9951Adam Powell
19849e7ff9647e6547c2b852944a5435a05794b9951Adam Powell    /**
199fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian     * Display flag: Indicates that the display can show its content when non-secure keyguard is
200fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian     * shown.
201fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian     * <p>
202fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian     * This flag identifies secondary displays that won't show keyguard if it can be dismissed
203fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian     * without entering credentials. Display content will be shown even if other displays are
204fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian     * locked.
205fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian     * </p>
206fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian     *
207fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian     * @see #getFlags
20822512e8a225cee9b53f9028734d1e9d79d27f67dAndrii Kulian     * @hide
209fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian     */
2107211d2eba8e02b5e7462313798fc25c0bd36ab2dAndrii Kulian    public static final int FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 5;
211fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian
212fc8f82bc6b587bddd2aeaddc54c1ea3f598bb9c3Andrii Kulian    /**
213d46747a1c64b6ca3282e8841833980ab91829436Jeff Brown     * Display flag: Indicates that the contents of the display should not be scaled
214d46747a1c64b6ca3282e8841833980ab91829436Jeff Brown     * to fit the physical screen dimensions.  Used for development only to emulate
215d46747a1c64b6ca3282e8841833980ab91829436Jeff Brown     * devices with smaller physicals screens while preserving density.
216d46747a1c64b6ca3282e8841833980ab91829436Jeff Brown     *
217d46747a1c64b6ca3282e8841833980ab91829436Jeff Brown     * @hide
218d46747a1c64b6ca3282e8841833980ab91829436Jeff Brown     */
219d46747a1c64b6ca3282e8841833980ab91829436Jeff Brown    public static final int FLAG_SCALING_DISABLED = 1 << 30;
220d46747a1c64b6ca3282e8841833980ab91829436Jeff Brown
221d46747a1c64b6ca3282e8841833980ab91829436Jeff Brown    /**
22292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * Display type: Unknown display type.
22392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @hide
22492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     */
22592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    public static final int TYPE_UNKNOWN = 0;
22692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown
22792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    /**
22892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * Display type: Built-in display.
22992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @hide
23092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     */
23192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    public static final int TYPE_BUILT_IN = 1;
23292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown
23392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    /**
23492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * Display type: HDMI display.
23592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @hide
23692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     */
23792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    public static final int TYPE_HDMI = 2;
23892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown
23992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    /**
24092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * Display type: WiFi display.
24192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @hide
24292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     */
24392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    public static final int TYPE_WIFI = 3;
24492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown
24592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    /**
24692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * Display type: Overlay display.
24792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @hide
24892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     */
24992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    public static final int TYPE_OVERLAY = 4;
25092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown
25192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    /**
252a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * Display type: Virtual display.
253a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * @hide
254a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     */
255a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    public static final int TYPE_VIRTUAL = 5;
256a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown
257a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    /**
258037c33eae74bee2774897d969d48947f9abe254fJeff Brown     * Display state: The display state is unknown.
259037c33eae74bee2774897d969d48947f9abe254fJeff Brown     *
260037c33eae74bee2774897d969d48947f9abe254fJeff Brown     * @see #getState
261037c33eae74bee2774897d969d48947f9abe254fJeff Brown     */
262037c33eae74bee2774897d969d48947f9abe254fJeff Brown    public static final int STATE_UNKNOWN = 0;
263037c33eae74bee2774897d969d48947f9abe254fJeff Brown
264037c33eae74bee2774897d969d48947f9abe254fJeff Brown    /**
265037c33eae74bee2774897d969d48947f9abe254fJeff Brown     * Display state: The display is off.
266037c33eae74bee2774897d969d48947f9abe254fJeff Brown     *
267037c33eae74bee2774897d969d48947f9abe254fJeff Brown     * @see #getState
268037c33eae74bee2774897d969d48947f9abe254fJeff Brown     */
269037c33eae74bee2774897d969d48947f9abe254fJeff Brown    public static final int STATE_OFF = 1;
270037c33eae74bee2774897d969d48947f9abe254fJeff Brown
271037c33eae74bee2774897d969d48947f9abe254fJeff Brown    /**
272037c33eae74bee2774897d969d48947f9abe254fJeff Brown     * Display state: The display is on.
273037c33eae74bee2774897d969d48947f9abe254fJeff Brown     *
274037c33eae74bee2774897d969d48947f9abe254fJeff Brown     * @see #getState
275037c33eae74bee2774897d969d48947f9abe254fJeff Brown     */
276037c33eae74bee2774897d969d48947f9abe254fJeff Brown    public static final int STATE_ON = 2;
277037c33eae74bee2774897d969d48947f9abe254fJeff Brown
278037c33eae74bee2774897d969d48947f9abe254fJeff Brown    /**
2795dc219142a756d57355b511c8f8ab913c01710daJeff Brown     * Display state: The display is dozing in a low power state; it is still
2805dc219142a756d57355b511c8f8ab913c01710daJeff Brown     * on but is optimized for showing system-provided content while the
2815dc219142a756d57355b511c8f8ab913c01710daJeff Brown     * device is non-interactive.
282037c33eae74bee2774897d969d48947f9abe254fJeff Brown     *
283037c33eae74bee2774897d969d48947f9abe254fJeff Brown     * @see #getState
284037c33eae74bee2774897d969d48947f9abe254fJeff Brown     * @see android.os.PowerManager#isInteractive
285037c33eae74bee2774897d969d48947f9abe254fJeff Brown     */
2865dc219142a756d57355b511c8f8ab913c01710daJeff Brown    public static final int STATE_DOZE = 3;
2875dc219142a756d57355b511c8f8ab913c01710daJeff Brown
2885dc219142a756d57355b511c8f8ab913c01710daJeff Brown    /**
2895dc219142a756d57355b511c8f8ab913c01710daJeff Brown     * Display state: The display is dozing in a suspended low power state; it is still
2905dc219142a756d57355b511c8f8ab913c01710daJeff Brown     * on but is optimized for showing static system-provided content while the device
2915dc219142a756d57355b511c8f8ab913c01710daJeff Brown     * is non-interactive.  This mode may be used to conserve even more power by allowing
2925dc219142a756d57355b511c8f8ab913c01710daJeff Brown     * the hardware to stop applying frame buffer updates from the graphics subsystem or
2935dc219142a756d57355b511c8f8ab913c01710daJeff Brown     * to take over the display and manage it autonomously to implement low power always-on
2945dc219142a756d57355b511c8f8ab913c01710daJeff Brown     * display functionality.
2955dc219142a756d57355b511c8f8ab913c01710daJeff Brown     *
2965dc219142a756d57355b511c8f8ab913c01710daJeff Brown     * @see #getState
2975dc219142a756d57355b511c8f8ab913c01710daJeff Brown     * @see android.os.PowerManager#isInteractive
2985dc219142a756d57355b511c8f8ab913c01710daJeff Brown     */
2995dc219142a756d57355b511c8f8ab913c01710daJeff Brown    public static final int STATE_DOZE_SUSPEND = 4;
300037c33eae74bee2774897d969d48947f9abe254fJeff Brown
3013107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon    /**
3023107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon     * Display state: The display is on and optimized for VR mode.
3033107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon     *
3043107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon     * @see #getState
3053107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon     * @see android.os.PowerManager#isInteractive
3063107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon     */
3073107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon    public static final int STATE_VR = 5;
3083107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon
3091c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright    /* The color mode constants defined below must be kept in sync with the ones in
3106d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy     * system/core/include/system/graphics-base.h */
3111c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright
3121c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright    /**
3131c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright     * Display color mode: The current color mode is unknown or invalid.
3141c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright     * @hide
3151c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright     */
3161c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright    public static final int COLOR_MODE_INVALID = -1;
3171c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright
3181c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright    /**
3191c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright     * Display color mode: The default or native gamut of the display.
3201c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright     * @hide
3211c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright     */
3221c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright    public static final int COLOR_MODE_DEFAULT = 0;
3231c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright
3246d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    /** @hide */
3256d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    public static final int COLOR_MODE_BT601_625 = 1;
3266d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    /** @hide */
3276d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    public static final int COLOR_MODE_BT601_625_UNADJUSTED = 2;
3286d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    /** @hide */
3296d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    public static final int COLOR_MODE_BT601_525 = 3;
3306d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    /** @hide */
3316d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    public static final int COLOR_MODE_BT601_525_UNADJUSTED = 4;
3326d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    /** @hide */
3336d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    public static final int COLOR_MODE_BT709 = 5;
3346d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    /** @hide */
3356d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    public static final int COLOR_MODE_DCI_P3 = 6;
3366d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    /** @hide */
3371c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright    public static final int COLOR_MODE_SRGB = 7;
3386d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    /** @hide */
3396d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    public static final int COLOR_MODE_ADOBE_RGB = 8;
3406d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    /** @hide */
3416d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    public static final int COLOR_MODE_DISPLAY_P3 = 9;
3421c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright
343037c33eae74bee2774897d969d48947f9abe254fJeff Brown    /**
344250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * Indicates that when display is removed, all its activities will be moved to the primary
345250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * display and the topmost activity should become focused.
346250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     *
347250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * @hide
348250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     */
349250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian    public static final int REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY = 0;
350250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian    /**
351250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * Indicates that when display is removed, all its stacks and tasks will be removed, all
352250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * activities will be destroyed according to the usual lifecycle.
353250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     *
354250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * @hide
355250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     */
356250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian    public static final int REMOVE_MODE_DESTROY_CONTENT = 1;
357250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian
358250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian    /**
359fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Internal method to create a display.
360609bf65668181d93502a57575f6f20281f2494b8Bryce Lee     * The display created with this method will have a static {@link DisplayAdjustments} applied.
361fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Applications should use {@link android.view.WindowManager#getDefaultDisplay()}
36298365d7663cbd82979a5700faf0050220b01084dJeff Brown     * or {@link android.hardware.display.DisplayManager#getDisplay}
36398365d7663cbd82979a5700faf0050220b01084dJeff Brown     * to get a display object.
364fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
365fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @hide
3669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
367609bf65668181d93502a57575f6f20281f2494b8Bryce Lee    public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
36848d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner            DisplayAdjustments daj) {
369609bf65668181d93502a57575f6f20281f2494b8Bryce Lee        this(global, displayId, displayInfo, daj, null /*res*/);
370609bf65668181d93502a57575f6f20281f2494b8Bryce Lee    }
371609bf65668181d93502a57575f6f20281f2494b8Bryce Lee
372609bf65668181d93502a57575f6f20281f2494b8Bryce Lee    /**
373609bf65668181d93502a57575f6f20281f2494b8Bryce Lee     * Internal method to create a display.
374609bf65668181d93502a57575f6f20281f2494b8Bryce Lee     * The display created with this method will be adjusted based on the adjustments in the
375609bf65668181d93502a57575f6f20281f2494b8Bryce Lee     * supplied {@link Resources}.
376609bf65668181d93502a57575f6f20281f2494b8Bryce Lee     *
377609bf65668181d93502a57575f6f20281f2494b8Bryce Lee     * @hide
378609bf65668181d93502a57575f6f20281f2494b8Bryce Lee     */
379609bf65668181d93502a57575f6f20281f2494b8Bryce Lee    public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
380609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            Resources res) {
381609bf65668181d93502a57575f6f20281f2494b8Bryce Lee        this(global, displayId, displayInfo, null /*daj*/, res);
382609bf65668181d93502a57575f6f20281f2494b8Bryce Lee    }
383609bf65668181d93502a57575f6f20281f2494b8Bryce Lee
384609bf65668181d93502a57575f6f20281f2494b8Bryce Lee    private Display(DisplayManagerGlobal global, int displayId,
385609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            /*@NotNull*/ DisplayInfo displayInfo, DisplayAdjustments daj, Resources res) {
386bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        mGlobal = global;
387fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        mDisplayId = displayId;
388bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        mDisplayInfo = displayInfo;
389609bf65668181d93502a57575f6f20281f2494b8Bryce Lee        mResources = res;
390609bf65668181d93502a57575f6f20281f2494b8Bryce Lee        mDisplayAdjustments = mResources != null
391609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            ? new DisplayAdjustments(mResources.getConfiguration())
392609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            : daj != null ? new DisplayAdjustments(daj) : null;
393bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        mIsValid = true;
39492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown
39592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        // Cache properties that cannot change as long as the display is valid.
39692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        mLayerStack = displayInfo.layerStack;
39792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        mFlags = displayInfo.flags;
39892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        mType = displayInfo.type;
39992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        mAddress = displayInfo.address;
400a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown        mOwnerUid = displayInfo.ownerUid;
401a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown        mOwnerPackageName = displayInfo.ownerPackageName;
4025fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn    }
4035fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn
4049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
405fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the display id.
406fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * <p>
407fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Each logical display has a unique id.
408fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The default display has id {@link #DEFAULT_DISPLAY}.
409fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p>
4109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int getDisplayId() {
412fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        return mDisplayId;
4139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
416bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * Returns true if this display is still valid, false if the display has been removed.
417bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     *
418bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * If the display is invalid, then the methods of this class will
419bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * continue to report the most recently observed display information.
420bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * However, it is unwise (and rather fruitless) to continue using a
421bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * {@link Display} object after the display's demise.
422bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     *
423bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * It's possible for a display that was previously invalid to become
424bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * valid again if a display with the same id is reconnected.
425bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     *
426bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * @return True if the display is still valid.
427bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     */
428bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    public boolean isValid() {
429bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        synchronized (this) {
430bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            updateDisplayInfoLocked();
431bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            return mIsValid;
432bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        }
433bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    }
434bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown
435bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    /**
4362ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     * Gets a full copy of the display information.
4372ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     *
4382ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     * @param outDisplayInfo The object to receive the copy of the display information.
439bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * @return True if the display is still valid.
4402ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     * @hide
4412ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     */
442bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    public boolean getDisplayInfo(DisplayInfo outDisplayInfo) {
4432ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown        synchronized (this) {
4442ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown            updateDisplayInfoLocked();
4452ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown            outDisplayInfo.copyFrom(mDisplayInfo);
446bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            return mIsValid;
4472ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown        }
4482ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown    }
4492ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown
4502ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown    /**
45198365d7663cbd82979a5700faf0050220b01084dJeff Brown     * Gets the display's layer stack.
45298365d7663cbd82979a5700faf0050220b01084dJeff Brown     *
45398365d7663cbd82979a5700faf0050220b01084dJeff Brown     * Each display has its own independent layer stack upon which surfaces
45498365d7663cbd82979a5700faf0050220b01084dJeff Brown     * are placed to be managed by surface flinger.
45598365d7663cbd82979a5700faf0050220b01084dJeff Brown     *
4564ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown     * @return The display's layer stack number.
45798365d7663cbd82979a5700faf0050220b01084dJeff Brown     * @hide
45898365d7663cbd82979a5700faf0050220b01084dJeff Brown     */
45998365d7663cbd82979a5700faf0050220b01084dJeff Brown    public int getLayerStack() {
4604ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown        return mLayerStack;
46198365d7663cbd82979a5700faf0050220b01084dJeff Brown    }
46298365d7663cbd82979a5700faf0050220b01084dJeff Brown
46398365d7663cbd82979a5700faf0050220b01084dJeff Brown    /**
464c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * Returns a combination of flags that describe the capabilities of the display.
465c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     *
466c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * @return The display flags.
467c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     *
46877aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown     * @see #FLAG_SUPPORTS_PROTECTED_BUFFERS
469f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown     * @see #FLAG_SECURE
470a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * @see #FLAG_PRIVATE
471c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     */
472c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown    public int getFlags() {
47392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        return mFlags;
47492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    }
47592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown
47692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    /**
47792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * Gets the display type.
47892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     *
47992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @return The display type.
48092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     *
48192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @see #TYPE_UNKNOWN
48292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @see #TYPE_BUILT_IN
48392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @see #TYPE_HDMI
48492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @see #TYPE_WIFI
48592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @see #TYPE_OVERLAY
486a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * @see #TYPE_VIRTUAL
48792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @hide
48892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     */
48992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    public int getType() {
49092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        return mType;
49192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    }
49292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown
49392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    /**
49492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * Gets the display address, or null if none.
49592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * Interpretation varies by display type.
49692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     *
49792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @return The display address.
49892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @hide
49992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     */
50092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    public String getAddress() {
50192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        return mAddress;
502c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown    }
503c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown
504c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown    /**
505a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * Gets the UID of the application that owns this display, or zero if it is
506a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * owned by the system.
507a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * <p>
508a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * If the display is private, then only the owner can use it.
509a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * </p>
510a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     *
511a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * @hide
512a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     */
513a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    public int getOwnerUid() {
514a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown        return mOwnerUid;
515a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    }
516a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown
517a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    /**
518a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * Gets the package name of the application that owns this display, or null if it is
519a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * owned by the system.
520a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * <p>
521a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * If the display is private, then only the owner can use it.
522a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * </p>
523a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     *
524a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * @hide
525a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     */
526a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    public String getOwnerPackageName() {
527a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown        return mOwnerPackageName;
528a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    }
529a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown
530a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    /**
53198365d7663cbd82979a5700faf0050220b01084dJeff Brown     * Gets the compatibility info used by this display instance.
53298365d7663cbd82979a5700faf0050220b01084dJeff Brown     *
53348d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner     * @return The display adjustments holder, or null if none is required.
53498365d7663cbd82979a5700faf0050220b01084dJeff Brown     * @hide
53598365d7663cbd82979a5700faf0050220b01084dJeff Brown     */
53648d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner    public DisplayAdjustments getDisplayAdjustments() {
537609bf65668181d93502a57575f6f20281f2494b8Bryce Lee        if (mResources != null) {
538609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            final DisplayAdjustments currentAdjustements = mResources.getDisplayAdjustments();
539609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            if (!mDisplayAdjustments.equals(currentAdjustements)) {
540609bf65668181d93502a57575f6f20281f2494b8Bryce Lee                mDisplayAdjustments = new DisplayAdjustments(currentAdjustements);
541609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            }
542609bf65668181d93502a57575f6f20281f2494b8Bryce Lee        }
543609bf65668181d93502a57575f6f20281f2494b8Bryce Lee
54448d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner        return mDisplayAdjustments;
54598365d7663cbd82979a5700faf0050220b01084dJeff Brown    }
54698365d7663cbd82979a5700faf0050220b01084dJeff Brown
54798365d7663cbd82979a5700faf0050220b01084dJeff Brown    /**
5484ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown     * Gets the name of the display.
54992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * <p>
55092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * Note that some displays may be renamed by the user.
55192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * </p>
55292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     *
5534ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown     * @return The display's name.
5544ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown     */
5554ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown    public String getName() {
55692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        synchronized (this) {
55792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown            updateDisplayInfoLocked();
55892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown            return mDisplayInfo.name;
55992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        }
5604ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown    }
5614ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown
5624ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown    /**
563bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * Gets the size of the display, in pixels.
5645f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * Value returned by this method does not necessarily represent the actual raw size
5655f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * (native resolution) of the display.
566bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * <p>
5675f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * 1. The returned size may be adjusted to exclude certain system decor elements
5685f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * that are always visible.
569bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p><p>
5705f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * 2. It may be scaled to provide compatibility with older applications that
571bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * were originally designed for smaller displays.
5725f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * </p><p>
5735f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * 3. It can be different depending on the WindowManager to which the display belongs.
5745f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * </p><p>
5755f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * - If requested from non-Activity context (e.g. Application context via
5765f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * {@code (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)})
5775f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * it will report the size of the entire display based on current rotation and with subtracted
5785f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * system decoration areas.
5795f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * </p><p>
5805f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * - If requested from activity (either using {@code getWindowManager()} or
5815f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * {@code (WindowManager) getSystemService(Context.WINDOW_SERVICE)}) resulting size will
5825f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * correspond to current app window size. In this case it can be smaller than physical size in
5835f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * multi-window mode.
5845f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * </p><p>
5855f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * Typically for the purposes of layout apps should make a request from activity context
5865f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * to obtain size available for the app content.
587bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p>
588bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     *
589bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @param outSize A {@link Point} object to receive the size information.
5909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
591ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public void getSize(Point outSize) {
592fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
593fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
594609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
595fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.x = mTempMetrics.widthPixels;
596fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.y = mTempMetrics.heightPixels;
597ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
598ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
599fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
6009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
601bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * Gets the size of the display as a rectangle, in pixels.
602bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     *
603bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @param outSize A {@link Rect} object to receive the size information.
604bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @see #getSize(Point)
6059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
606ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public void getRectSize(Rect outSize) {
607fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
608fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
609609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
610fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels);
611ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
612ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
6139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
614ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    /**
61568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * Return the range of display sizes an application can expect to encounter
61668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * under normal operation, as long as there is no physical change in screen
61768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * size.  This is basically the sizes you will see as the orientation
61868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * changes, taking into account whatever screen decoration there is in
61968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * each rotation.  For example, the status bar is always at the top of the
62068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * screen, so it will reduce the height both in landscape and portrait, and
62168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * the smallest height returned here will be the smaller of the two.
62268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     *
62368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * This is intended for applications to get an idea of the range of sizes
62468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * they will encounter while going through device rotations, to provide a
62568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * stable UI through rotation.  The sizes here take into account all standard
62668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * system decorations that reduce the size actually available to the
62768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * application: the status bar, navigation bar, system bar, etc.  It does
62868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * <em>not</em> take into account more transient elements like an IME
62968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * soft keyboard.
63068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     *
63168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * @param outSmallestSize Filled in with the smallest width and height
63268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * that the application will encounter, in pixels (not dp units).  The x
63368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * (width) dimension here directly corresponds to
63468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * {@link android.content.res.Configuration#smallestScreenWidthDp
63568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * Configuration.smallestScreenWidthDp}, except the value here is in raw
63668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * screen pixels rather than dp units.  Your application may of course
63768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * still get smaller space yet if, for example, a soft keyboard is
63868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * being displayed.
63968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * @param outLargestSize Filled in with the largest width and height
64068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * that the application will encounter, in pixels (not dp units).  Your
64168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * application may of course still get larger space than this if,
64268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * for example, screen decorations like the status bar are being hidden.
64368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     */
64468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn    public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) {
645fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
646fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
647fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth;
648fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight;
649fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outLargestSize.x = mDisplayInfo.largestNominalAppWidth;
650fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outLargestSize.y = mDisplayInfo.largestNominalAppHeight;
65168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn        }
65268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn    }
65368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn
65468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn    /**
655ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * Return the maximum screen size dimension that will happen.  This is
656ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * mostly for wallpapers.
657ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * @hide
658ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     */
659ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public int getMaximumSizeDimension() {
660fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
661fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
662fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
663ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
664ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
665ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn
666ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    /**
667ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * @deprecated Use {@link #getSize(Point)} instead.
668ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     */
669ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    @Deprecated
670ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public int getWidth() {
671fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
672fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateCachedAppSizeIfNeededLocked();
673fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return mCachedAppWidthCompat;
674ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
675ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
676ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn
677ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    /**
678ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * @deprecated Use {@link #getSize(Point)} instead.
679ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     */
680ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    @Deprecated
681ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public int getHeight() {
682fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
683fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateCachedAppSizeIfNeededLocked();
684fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return mCachedAppHeightCompat;
685bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown        }
686bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    }
687ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn
688bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    /**
689c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn     * @hide
690c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn     * Return a rectangle defining the insets of the overscan region of the display.
691c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn     * Each field of the rectangle is the number of pixels the overscan area extends
692c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn     * into the display on that side.
693c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn     */
694c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn    public void getOverscanInsets(Rect outRect) {
695c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn        synchronized (this) {
696c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn            updateDisplayInfoLocked();
697c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn            outRect.set(mDisplayInfo.overscanLeft, mDisplayInfo.overscanTop,
698c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn                    mDisplayInfo.overscanRight, mDisplayInfo.overscanBottom);
699c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn        }
700c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn    }
701c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn
702c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn    /**
7035cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * Returns the rotation of the screen from its "natural" orientation.
7045cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * The returned value may be {@link Surface#ROTATION_0 Surface.ROTATION_0}
7055cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * (no rotation), {@link Surface#ROTATION_90 Surface.ROTATION_90},
7065cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * {@link Surface#ROTATION_180 Surface.ROTATION_180}, or
7075cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * {@link Surface#ROTATION_270 Surface.ROTATION_270}.  For
7085cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * example, if a device has a naturally tall screen, and the user has
7095cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * turned it on its side to go into a landscape orientation, the value
7105cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * returned here may be either {@link Surface#ROTATION_90 Surface.ROTATION_90}
7115cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * or {@link Surface#ROTATION_270 Surface.ROTATION_270} depending on
7125cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * the direction it was turned.  The angle is the rotation of the drawn
7135cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * graphics on the screen, which is the opposite direction of the physical
7145cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * rotation of the device.  For example, if the device is rotated 90
7155cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * degrees counter-clockwise, to compensate rendering will be rotated by
7165cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * 90 degrees clockwise and thus the returned value here will be
7175cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * {@link Surface#ROTATION_90 Surface.ROTATION_90}.
7185cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     */
719d9273d6f289d9b55da3fd0db2f659fdfb48106a8Tor Norbye    @Surface.Rotation
7205cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn    public int getRotation() {
721fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
722fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
723fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return mDisplayInfo.rotation;
724fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
7255cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn    }
726fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
7275cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn    /**
7284c904a3bf3dbe98607b5e3f706ee8ef8887ee104Joe Onorato     * @deprecated use {@link #getRotation}
7299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return orientation of this display.
7309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
731fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    @Deprecated
732d9273d6f289d9b55da3fd0db2f659fdfb48106a8Tor Norbye    @Surface.Rotation
733fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    public int getOrientation() {
734fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        return getRotation();
735fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    }
7369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
738fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the pixel format of the display.
739fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @return One of the constants defined in {@link android.graphics.PixelFormat}.
740fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
741fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @deprecated This method is no longer supported.
742fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The result is always {@link PixelFormat#RGBA_8888}.
7439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
744fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    @Deprecated
7459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int getPixelFormat() {
746fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        return PixelFormat.RGBA_8888;
7479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
748fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
7499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
750fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the refresh rate of this display in frames per second.
7519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public float getRefreshRate() {
753fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
754fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
755b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return mDisplayInfo.getMode().getRefreshRate();
756fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
7579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
758fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
7599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7603f145a2f958320766ae9240c7a57debc20d578aaMichael Wright     * Get the supported refresh rates of this display in frames per second.
761b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     * <p>
762b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     * This method only returns refresh rates for the display's default modes. For more options, use
763b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     * {@link #getSupportedModes()}.
764b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     *
765b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     * @deprecated use {@link #getSupportedModes()} instead
7663f145a2f958320766ae9240c7a57debc20d578aaMichael Wright     */
767b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand    @Deprecated
7683f145a2f958320766ae9240c7a57debc20d578aaMichael Wright    public float[] getSupportedRefreshRates() {
7693f145a2f958320766ae9240c7a57debc20d578aaMichael Wright        synchronized (this) {
7703f145a2f958320766ae9240c7a57debc20d578aaMichael Wright            updateDisplayInfoLocked();
771b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return mDisplayInfo.getDefaultRefreshRates();
772b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
773b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand    }
774b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
775b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand    /**
776b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     * Returns the active mode of the display.
777b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     */
778b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand    public Mode getMode() {
779b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        synchronized (this) {
780b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            updateDisplayInfoLocked();
781b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return mDisplayInfo.getMode();
782b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
783b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand    }
784b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
785b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand    /**
786b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     * Gets the supported modes of this display.
787b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     */
788b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand    public Mode[] getSupportedModes() {
789b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        synchronized (this) {
790b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            updateDisplayInfoLocked();
791b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            final Display.Mode[] modes = mDisplayInfo.supportedModes;
792b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return Arrays.copyOf(modes, modes.length);
7933f145a2f958320766ae9240c7a57debc20d578aaMichael Wright        }
7943f145a2f958320766ae9240c7a57debc20d578aaMichael Wright    }
7953f145a2f958320766ae9240c7a57debc20d578aaMichael Wright
7963f145a2f958320766ae9240c7a57debc20d578aaMichael Wright    /**
7971c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright     * Request the display applies a color mode.
79858e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright     * @hide
79958e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright     */
8001c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright    @RequiresPermission(CONFIGURE_DISPLAY_COLOR_MODE)
8011c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright    public void requestColorMode(int colorMode) {
8021c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright        mGlobal.requestColorMode(mDisplayId, colorMode);
80358e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright    }
80458e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright
80558e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright    /**
8061c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright     * Returns the active color mode of this display
80758e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright     * @hide
80858e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright     */
8091c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright    public int getColorMode() {
81058e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright        synchronized (this) {
81158e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright            updateDisplayInfoLocked();
8121c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright            return mDisplayInfo.colorMode;
81358e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright        }
81458e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright    }
81558e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright
81658e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright    /**
817250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * @hide
818250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * Get current remove mode of the display - what actions should be performed with the display's
819250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * content when it is removed. Default behavior for public displays in this case is to move all
820250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * activities to the primary display and make it focused. For private display - destroy all
821250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * activities.
822250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     *
823250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * @see #REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY
824250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     * @see #REMOVE_MODE_DESTROY_CONTENT
825250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian     */
826250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian    public int getRemoveMode() {
827250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian        return mDisplayInfo.removeMode;
828250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian    }
829250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian
830250d653325ffeeb8ef75e51e3a3d08d6abb8cf9cAndrii Kulian    /**
831f173c323449840771312afe5cbec03a71281e6ffRonghua Wu     * Returns the display's HDR capabilities.
8326d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy     *
8336d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy     * @see #isHdr()
834f173c323449840771312afe5cbec03a71281e6ffRonghua Wu     */
835f173c323449840771312afe5cbec03a71281e6ffRonghua Wu    public HdrCapabilities getHdrCapabilities() {
8369ff94c0251722c44eece7c3561b4ed36b286d4a8Michael Wright        synchronized (this) {
8379ff94c0251722c44eece7c3561b4ed36b286d4a8Michael Wright            updateDisplayInfoLocked();
8389ff94c0251722c44eece7c3561b4ed36b286d4a8Michael Wright            return mDisplayInfo.hdrCapabilities;
8399ff94c0251722c44eece7c3561b4ed36b286d4a8Michael Wright        }
840f173c323449840771312afe5cbec03a71281e6ffRonghua Wu    }
841f173c323449840771312afe5cbec03a71281e6ffRonghua Wu
842f173c323449840771312afe5cbec03a71281e6ffRonghua Wu    /**
8436d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy     * Returns whether this display supports any HDR type.
8446d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy     *
8456d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy     * @see #getHdrCapabilities()
8466d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy     * @see HdrCapabilities#getSupportedHdrTypes()
8476d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy     */
8486d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    public boolean isHdr() {
8496d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy        synchronized (this) {
8506d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy            updateDisplayInfoLocked();
851408afbf06040ea29d1a9d60e9dc50d1923068de4Romain Guy            return mDisplayInfo.isHdr();
8526d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy        }
8536d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    }
8546d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy
8556d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    /**
8566d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy     * Returns whether this display can be used to display wide color gamut content.
8576d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy     */
8586d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    public boolean isWideColorGamut() {
8596d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy        synchronized (this) {
8606d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy            updateDisplayInfoLocked();
861408afbf06040ea29d1a9d60e9dc50d1923068de4Romain Guy            return mDisplayInfo.isWideColorGamut();
8626d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy        }
8636d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    }
8646d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy
8656d228c2589db75ef8ae6cd820d58a1c66f6ebe19Romain Guy    /**
8661c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright     * Gets the supported color modes of this device.
86758e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright     * @hide
86858e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright     */
8691c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright    public int[] getSupportedColorModes() {
87058e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright        synchronized (this) {
87158e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright            updateDisplayInfoLocked();
8721c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright            int[] colorModes = mDisplayInfo.supportedColorModes;
8731c9977b762b4bac46b4470f04c898bfd17da5d90Michael Wright            return Arrays.copyOf(colorModes, colorModes.length);
87458e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright        }
87558e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright    }
87658e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright
87758e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright    /**
878e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * Gets the app VSYNC offset, in nanoseconds.  This is a positive value indicating
879e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * the phase offset of the VSYNC events provided by Choreographer relative to the
880e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * display refresh.  For example, if Choreographer reports that the refresh occurred
881e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * at time N, it actually occurred at (N - appVsyncOffset).
882e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * <p>
883e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * Apps generally do not need to be aware of this.  It's only useful for fine-grained
884e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * A/V synchronization.
885e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     */
886e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden    public long getAppVsyncOffsetNanos() {
887e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden        synchronized (this) {
888e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden            updateDisplayInfoLocked();
889e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden            return mDisplayInfo.appVsyncOffsetNanos;
890e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden        }
891e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden    }
892e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden
893e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden    /**
894e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * This is how far in advance a buffer must be queued for presentation at
895e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * a given time.  If you want a buffer to appear on the screen at
896e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * time N, you must submit the buffer before (N - presentationDeadline).
897e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * <p>
898e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * The desired presentation time for GLES rendering may be set with
899e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * {@link android.opengl.EGLExt#eglPresentationTimeANDROID}.  For video decoding, use
900e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * {@link android.media.MediaCodec#releaseOutputBuffer(int, long)}.  Times are
901e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * expressed in nanoseconds, using the system monotonic clock
902e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     * ({@link System#nanoTime}).
903e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden     */
904e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden    public long getPresentationDeadlineNanos() {
905e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden        synchronized (this) {
906e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden            updateDisplayInfoLocked();
907e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden            return mDisplayInfo.presentationDeadlineNanos;
908e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden        }
909e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden    }
910e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden
911e8b1aeb51e1e5da64f1d4fd40f2ee1e815886fe5Andy McFadden    /**
912bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * Gets display metrics that describe the size and density of this display.
913a4bb9d3f527663862bcc2abc1cd81489bfc6754eAndrii Kulian     * The size returned by this method does not necessarily represent the
914a4bb9d3f527663862bcc2abc1cd81489bfc6754eAndrii Kulian     * actual raw size (native resolution) of the display.
915bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * <p>
916a4bb9d3f527663862bcc2abc1cd81489bfc6754eAndrii Kulian     * 1. The returned size may be adjusted to exclude certain system decor elements
917a4bb9d3f527663862bcc2abc1cd81489bfc6754eAndrii Kulian     * that are always visible.
918bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p><p>
919a4bb9d3f527663862bcc2abc1cd81489bfc6754eAndrii Kulian     * 2. It may be scaled to provide compatibility with older applications that
920bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * were originally designed for smaller displays.
921a4bb9d3f527663862bcc2abc1cd81489bfc6754eAndrii Kulian     * </p><p>
922a4bb9d3f527663862bcc2abc1cd81489bfc6754eAndrii Kulian     * 3. It can be different depending on the WindowManager to which the display belongs.
9235f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * </p><p>
924a4bb9d3f527663862bcc2abc1cd81489bfc6754eAndrii Kulian     * - If requested from non-Activity context (e.g. Application context via
925a4bb9d3f527663862bcc2abc1cd81489bfc6754eAndrii Kulian     * {@code (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)})
9265f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * metrics will report the size of the entire display based on current rotation and with
9275f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * subtracted system decoration areas.
9285f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * </p><p>
9295f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * - If requested from activity (either using {@code getWindowManager()} or
9305f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * {@code (WindowManager) getSystemService(Context.WINDOW_SERVICE)}) resulting metrics will
9315f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * correspond to current app window metrics. In this case the size can be smaller than physical
9325f57a3d6d8a8ae97aa431386b76e35a70dbb9314Andrii Kulian     * size in multi-window mode.
933bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p>
934bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     *
935bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
9369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
9379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void getMetrics(DisplayMetrics outMetrics) {
938fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
939fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
940609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            mDisplayInfo.getAppMetrics(outMetrics, getDisplayAdjustments());
94168066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn        }
94268066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn    }
94368066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn
94468066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn    /**
945fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the real size of the display without subtracting any window decor or
946fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * applying any compatibility scale factors.
947fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * <p>
948fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The size is adjusted based on the current rotation of the display.
949fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p><p>
950fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The real size may be smaller than the physical size of the screen when the
951cd097993399f94aa663c5fad50e444b75e6ee5ddAndrii Kulian     * window manager is emulating a smaller display (using adb shell wm size).
952fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p>
953fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
954fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @param outSize Set to the real size of the display.
95568066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn     */
956fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    public void getRealSize(Point outSize) {
957fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
958fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
959fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.x = mDisplayInfo.logicalWidth;
960fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.y = mDisplayInfo.logicalHeight;
961bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown        }
962bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    }
963bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown
964bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    /**
965fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets display metrics based on the real size of this display.
966fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * <p>
967fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The size is adjusted based on the current rotation of the display.
968fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p><p>
969fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The real size may be smaller than the physical size of the screen when the
970a4bb9d3f527663862bcc2abc1cd81489bfc6754eAndrii Kulian     * window manager is emulating a smaller display (using adb shell wm size).
971fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p>
972fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
973fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
97493de746e5554bc9397ca8109f57875d92e64eabcJeff Brown     */
975fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    public void getRealMetrics(DisplayMetrics outMetrics) {
976fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
977fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
97848d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner            mDisplayInfo.getLogicalMetrics(outMetrics,
979a4bb9d3f527663862bcc2abc1cd81489bfc6754eAndrii Kulian                    CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
980fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
98193de746e5554bc9397ca8109f57875d92e64eabcJeff Brown    }
98293de746e5554bc9397ca8109f57875d92e64eabcJeff Brown
983a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    /**
984037c33eae74bee2774897d969d48947f9abe254fJeff Brown     * Gets the state of the display, such as whether it is on or off.
985037c33eae74bee2774897d969d48947f9abe254fJeff Brown     *
986037c33eae74bee2774897d969d48947f9abe254fJeff Brown     * @return The state of the display: one of {@link #STATE_OFF}, {@link #STATE_ON},
9873107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon     * {@link #STATE_DOZE}, {@link #STATE_DOZE_SUSPEND}, or
9883107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon     * {@link #STATE_UNKNOWN}.
989037c33eae74bee2774897d969d48947f9abe254fJeff Brown     */
990037c33eae74bee2774897d969d48947f9abe254fJeff Brown    public int getState() {
991037c33eae74bee2774897d969d48947f9abe254fJeff Brown        synchronized (this) {
992037c33eae74bee2774897d969d48947f9abe254fJeff Brown            updateDisplayInfoLocked();
993037c33eae74bee2774897d969d48947f9abe254fJeff Brown            return mIsValid ? mDisplayInfo.state : STATE_UNKNOWN;
994037c33eae74bee2774897d969d48947f9abe254fJeff Brown        }
995037c33eae74bee2774897d969d48947f9abe254fJeff Brown    }
996037c33eae74bee2774897d969d48947f9abe254fJeff Brown
997037c33eae74bee2774897d969d48947f9abe254fJeff Brown    /**
998a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * Returns true if the specified UID has access to this display.
999a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     * @hide
1000a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown     */
1001a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    public boolean hasAccess(int uid) {
1002a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown        return Display.hasAccess(uid, mFlags, mOwnerUid);
1003a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    }
1004a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown
1005a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    /** @hide */
1006a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    public static boolean hasAccess(int uid, int flags, int ownerUid) {
1007a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown        return (flags & Display.FLAG_PRIVATE) == 0
1008a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown                || uid == ownerUid
1009a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown                || uid == Process.SYSTEM_UID
1010a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown                || uid == 0;
1011a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown    }
1012a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown
101369b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    /**
101469b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown     * Returns true if the display is a public presentation display.
101569b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown     * @hide
101669b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown     */
101769b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    public boolean isPublicPresentation() {
101869b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown        return (mFlags & (Display.FLAG_PRIVATE | Display.FLAG_PRESENTATION)) ==
101969b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown                Display.FLAG_PRESENTATION;
102069b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown    }
102169b07161bebdb2c726e3a826c2268866f1a94517Jeff Brown
1022fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private void updateDisplayInfoLocked() {
1023bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        // Note: The display manager caches display info objects on our behalf.
1024bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId);
1025bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        if (newInfo == null) {
1026bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            // Preserve the old mDisplayInfo after the display is removed.
1027bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            if (mIsValid) {
1028bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                mIsValid = false;
1029bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                if (DEBUG) {
1030bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                    Log.d(TAG, "Logical display " + mDisplayId + " was removed.");
1031bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                }
1032bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            }
1033bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        } else {
1034bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            // Use the new display info.  (It might be the same object if nothing changed.)
1035bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            mDisplayInfo = newInfo;
1036bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            if (!mIsValid) {
1037bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                mIsValid = true;
1038bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                if (DEBUG) {
1039bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                    Log.d(TAG, "Logical display " + mDisplayId + " was recreated.");
1040bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                }
1041bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            }
1042fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
10439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
10449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1045fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private void updateCachedAppSizeIfNeededLocked() {
1046fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        long now = SystemClock.uptimeMillis();
1047fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) {
1048fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
1049609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
1050fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mCachedAppWidthCompat = mTempMetrics.widthPixels;
1051fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mCachedAppHeightCompat = mTempMetrics.heightPixels;
1052fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mLastCachedAppSizeUpdate = now;
1053fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
1054ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
1055bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown
1056bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    // For debugging purposes
1057bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    @Override
1058bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    public String toString() {
1059bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown        synchronized (this) {
1060bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown            updateDisplayInfoLocked();
1061609bf65668181d93502a57575f6f20281f2494b8Bryce Lee            mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
1062bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown            return "Display id " + mDisplayId + ": " + mDisplayInfo
1063bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                    + ", " + mTempMetrics + ", isValid=" + mIsValid;
1064bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown        }
1065bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    }
106692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown
106792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    /**
106892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     * @hide
106992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown     */
107092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    public static String typeToString(int type) {
107192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        switch (type) {
107292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown            case TYPE_UNKNOWN:
107392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown                return "UNKNOWN";
107492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown            case TYPE_BUILT_IN:
107592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown                return "BUILT_IN";
107692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown            case TYPE_HDMI:
107792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown                return "HDMI";
107892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown            case TYPE_WIFI:
107992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown                return "WIFI";
108092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown            case TYPE_OVERLAY:
108192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown                return "OVERLAY";
1082a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown            case TYPE_VIRTUAL:
1083a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown                return "VIRTUAL";
108492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown            default:
108592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown                return Integer.toString(type);
108692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown        }
108792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown    }
10889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1089037c33eae74bee2774897d969d48947f9abe254fJeff Brown    /**
1090037c33eae74bee2774897d969d48947f9abe254fJeff Brown     * @hide
1091037c33eae74bee2774897d969d48947f9abe254fJeff Brown     */
1092037c33eae74bee2774897d969d48947f9abe254fJeff Brown    public static String stateToString(int state) {
1093037c33eae74bee2774897d969d48947f9abe254fJeff Brown        switch (state) {
1094037c33eae74bee2774897d969d48947f9abe254fJeff Brown            case STATE_UNKNOWN:
1095037c33eae74bee2774897d969d48947f9abe254fJeff Brown                return "UNKNOWN";
1096037c33eae74bee2774897d969d48947f9abe254fJeff Brown            case STATE_OFF:
1097037c33eae74bee2774897d969d48947f9abe254fJeff Brown                return "OFF";
1098037c33eae74bee2774897d969d48947f9abe254fJeff Brown            case STATE_ON:
1099037c33eae74bee2774897d969d48947f9abe254fJeff Brown                return "ON";
11005dc219142a756d57355b511c8f8ab913c01710daJeff Brown            case STATE_DOZE:
11015dc219142a756d57355b511c8f8ab913c01710daJeff Brown                return "DOZE";
11025dc219142a756d57355b511c8f8ab913c01710daJeff Brown            case STATE_DOZE_SUSPEND:
11035dc219142a756d57355b511c8f8ab913c01710daJeff Brown                return "DOZE_SUSPEND";
11043107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon            case STATE_VR:
11053107d29c8f6f40b98533978a7e19e5c328f73d24Santos Cordon                return "VR";
1106037c33eae74bee2774897d969d48947f9abe254fJeff Brown            default:
1107037c33eae74bee2774897d969d48947f9abe254fJeff Brown                return Integer.toString(state);
1108037c33eae74bee2774897d969d48947f9abe254fJeff Brown        }
1109037c33eae74bee2774897d969d48947f9abe254fJeff Brown    }
1110970d4132ea28e748c1010be39450a98bbf7466f3Jeff Brown
1111970d4132ea28e748c1010be39450a98bbf7466f3Jeff Brown    /**
1112970d4132ea28e748c1010be39450a98bbf7466f3Jeff Brown     * Returns true if display updates may be suspended while in the specified
1113970d4132ea28e748c1010be39450a98bbf7466f3Jeff Brown     * display power state.
1114970d4132ea28e748c1010be39450a98bbf7466f3Jeff Brown     * @hide
1115970d4132ea28e748c1010be39450a98bbf7466f3Jeff Brown     */
1116970d4132ea28e748c1010be39450a98bbf7466f3Jeff Brown    public static boolean isSuspendedState(int state) {
1117970d4132ea28e748c1010be39450a98bbf7466f3Jeff Brown        return state == STATE_OFF || state == STATE_DOZE_SUSPEND;
1118970d4132ea28e748c1010be39450a98bbf7466f3Jeff Brown    }
1119b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1120b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand    /**
1121b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     * A mode supported by a given display.
1122b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     *
1123b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     * @see Display#getSupportedModes()
1124b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand     */
1125b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand    public static final class Mode implements Parcelable {
1126b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        /**
1127b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * @hide
1128b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         */
1129b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public static final Mode[] EMPTY_ARRAY = new Mode[0];
1130b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1131b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        private final int mModeId;
1132b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        private final int mWidth;
1133b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        private final int mHeight;
1134b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        private final float mRefreshRate;
1135b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1136b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        /**
1137b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * @hide
1138b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         */
1139b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public Mode(int modeId, int width, int height, float refreshRate) {
1140b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            mModeId = modeId;
1141b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            mWidth = width;
1142b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            mHeight = height;
1143b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            mRefreshRate = refreshRate;
1144b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1145b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1146b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        /**
1147b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * Returns this mode's id.
1148b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         */
1149b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public int getModeId() {
1150b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return mModeId;
1151b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1152b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1153b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        /**
1154b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * Returns the physical width of the display in pixels when configured in this mode's
1155b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * resolution.
1156b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * <p>
1157b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * Note that due to application UI scaling, the number of pixels made available to
1158b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * applications when the mode is active (as reported by {@link Display#getWidth()} may
1159b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * differ from the mode's actual resolution (as reported by this function).
1160b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * <p>
1161b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * For example, applications running on a 4K display may have their UI laid out and rendered
1162b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * in 1080p and then scaled up. Applications can take advantage of the extra resolution by
1163b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * rendering content through a {@link android.view.SurfaceView} using full size buffers.
1164b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         */
1165b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public int getPhysicalWidth() {
1166b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return mWidth;
1167b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1168b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1169b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        /**
1170b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * Returns the physical height of the display in pixels when configured in this mode's
1171b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * resolution.
1172b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * <p>
1173b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * Note that due to application UI scaling, the number of pixels made available to
1174b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * applications when the mode is active (as reported by {@link Display#getHeight()} may
1175b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * differ from the mode's actual resolution (as reported by this function).
1176b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * <p>
1177b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * For example, applications running on a 4K display may have their UI laid out and rendered
1178b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * in 1080p and then scaled up. Applications can take advantage of the extra resolution by
1179b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * rendering content through a {@link android.view.SurfaceView} using full size buffers.
1180b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         */
1181b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public int getPhysicalHeight() {
1182b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return mHeight;
1183b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1184b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1185b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        /**
1186b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * Returns the refresh rate in frames per second.
1187b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         */
1188b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public float getRefreshRate() {
1189b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return mRefreshRate;
1190b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1191b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1192b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        /**
1193b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * Returns {@code true} if this mode matches the given parameters.
1194b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         *
1195b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         * @hide
1196b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand         */
1197b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public boolean matches(int width, int height, float refreshRate) {
1198b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return mWidth == width &&
1199b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                    mHeight == height &&
1200b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                    Float.floatToIntBits(mRefreshRate) == Float.floatToIntBits(refreshRate);
1201b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1202b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1203b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        @Override
1204b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public boolean equals(Object other) {
1205b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            if (this == other) {
1206b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                return true;
1207b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            }
1208b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            if (!(other instanceof Mode)) {
1209b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                return false;
1210b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            }
1211b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            Mode that = (Mode) other;
1212b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return mModeId == that.mModeId && matches(that.mWidth, that.mHeight, that.mRefreshRate);
1213b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1214b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1215b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        @Override
1216b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public int hashCode() {
1217b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            int hash = 1;
1218b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            hash = hash * 17 + mModeId;
1219b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            hash = hash * 17 + mWidth;
1220b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            hash = hash * 17 + mHeight;
1221b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            hash = hash * 17 + Float.floatToIntBits(mRefreshRate);
1222b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return hash;
1223b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1224b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1225b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        @Override
1226b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public String toString() {
1227b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return new StringBuilder("{")
1228b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                    .append("id=").append(mModeId)
1229b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                    .append(", width=").append(mWidth)
1230b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                    .append(", height=").append(mHeight)
1231b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                    .append(", fps=").append(mRefreshRate)
1232b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                    .append("}")
1233b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                    .toString();
1234b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1235b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1236b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        @Override
1237b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public int describeContents() {
1238b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            return 0;
1239b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1240b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1241b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        private Mode(Parcel in) {
1242b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            this(in.readInt(), in.readInt(), in.readInt(), in.readFloat());
1243b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1244b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1245b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        @Override
1246b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public void writeToParcel(Parcel out, int parcelableFlags) {
1247b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            out.writeInt(mModeId);
1248b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            out.writeInt(mWidth);
1249b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            out.writeInt(mHeight);
1250b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            out.writeFloat(mRefreshRate);
1251b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        }
1252b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1253b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        @SuppressWarnings("hiding")
1254b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        public static final Parcelable.Creator<Mode> CREATOR
1255b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                = new Parcelable.Creator<Mode>() {
1256b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            @Override
1257b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            public Mode createFromParcel(Parcel in) {
1258b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                return new Mode(in);
1259b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            }
1260b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand
1261b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            @Override
1262b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            public Mode[] newArray(int size) {
1263b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand                return new Mode[size];
1264b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand            }
1265b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand        };
1266b3b9eb3cfc5b3b3609a5d01258315798b38a5cf9P.Y. Laligand    }
126758e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright
126858e829f71d2c525309e5bb5a1c02dc64397df221Michael Wright    /**
1269f173c323449840771312afe5cbec03a71281e6ffRonghua Wu     * Encapsulates the HDR capabilities of a given display.
1270f173c323449840771312afe5cbec03a71281e6ffRonghua Wu     * For example, what HDR types it supports and details about the desired luminance data.
1271f173c323449840771312afe5cbec03a71281e6ffRonghua Wu     * <p>You can get an instance for a given {@link Display} object with
1272f173c323449840771312afe5cbec03a71281e6ffRonghua Wu     * {@link Display#getHdrCapabilities getHdrCapabilities()}.
1273f173c323449840771312afe5cbec03a71281e6ffRonghua Wu     */
1274f173c323449840771312afe5cbec03a71281e6ffRonghua Wu    public static final class HdrCapabilities implements Parcelable {
1275f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        /**
1276f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         * Invalid luminance value.
1277f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         */
1278f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public static final float INVALID_LUMINANCE = -1;
1279f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        /**
1280f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         * Dolby Vision high dynamic range (HDR) display.
1281f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         */
1282f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public static final int HDR_TYPE_DOLBY_VISION = 1;
1283f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        /**
1284f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         * HDR10 display.
1285f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         */
1286f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public static final int HDR_TYPE_HDR10 = 2;
1287f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        /**
1288f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         * Hybrid Log-Gamma HDR display.
1289f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         */
1290f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public static final int HDR_TYPE_HLG = 3;
1291f173c323449840771312afe5cbec03a71281e6ffRonghua Wu
1292da802f5100fe2b19b5cb898efc2c66bdd7e19fd1Hangyu Kuang        /** @hide */
1293f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        @IntDef({
1294f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            HDR_TYPE_DOLBY_VISION,
1295f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            HDR_TYPE_HDR10,
1296f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            HDR_TYPE_HLG,
1297f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        })
1298f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        @Retention(RetentionPolicy.SOURCE)
1299f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public @interface HdrType {}
1300f173c323449840771312afe5cbec03a71281e6ffRonghua Wu
1301f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        private @HdrType int[] mSupportedHdrTypes = new int[0];
1302f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        private float mMaxLuminance = INVALID_LUMINANCE;
1303f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        private float mMaxAverageLuminance = INVALID_LUMINANCE;
1304f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        private float mMinLuminance = INVALID_LUMINANCE;
1305f173c323449840771312afe5cbec03a71281e6ffRonghua Wu
1306da802f5100fe2b19b5cb898efc2c66bdd7e19fd1Hangyu Kuang        /**
1307da802f5100fe2b19b5cb898efc2c66bdd7e19fd1Hangyu Kuang         * @hide
1308da802f5100fe2b19b5cb898efc2c66bdd7e19fd1Hangyu Kuang         */
1309f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public HdrCapabilities() {
1310f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        }
1311f173c323449840771312afe5cbec03a71281e6ffRonghua Wu
13121e7d1aa6a6bdee2c92245b5bef5aaa7167b8a311Hangyu Kuang        /**
13131e7d1aa6a6bdee2c92245b5bef5aaa7167b8a311Hangyu Kuang         * @hide
13141e7d1aa6a6bdee2c92245b5bef5aaa7167b8a311Hangyu Kuang         */
131554ac21918481fe6f7aac1c0effde51f9e9860ae3Hangyu Kuang        public HdrCapabilities(int[] supportedHdrTypes, float maxLuminance,
131654ac21918481fe6f7aac1c0effde51f9e9860ae3Hangyu Kuang                float maxAverageLuminance, float minLuminance) {
131754ac21918481fe6f7aac1c0effde51f9e9860ae3Hangyu Kuang            mSupportedHdrTypes = supportedHdrTypes;
131854ac21918481fe6f7aac1c0effde51f9e9860ae3Hangyu Kuang            mMaxLuminance = maxLuminance;
131954ac21918481fe6f7aac1c0effde51f9e9860ae3Hangyu Kuang            mMaxAverageLuminance = maxAverageLuminance;
132054ac21918481fe6f7aac1c0effde51f9e9860ae3Hangyu Kuang            mMinLuminance = minLuminance;
132154ac21918481fe6f7aac1c0effde51f9e9860ae3Hangyu Kuang        }
132254ac21918481fe6f7aac1c0effde51f9e9860ae3Hangyu Kuang
1323f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        /**
1324f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         * Gets the supported HDR types of this display.
1325f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         * Returns empty array if HDR is not supported by the display.
1326f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         */
1327f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public @HdrType int[] getSupportedHdrTypes() {
1328f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            return mSupportedHdrTypes;
1329f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        }
1330f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        /**
1331f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         * Returns the desired content max luminance data in cd/m2 for this display.
1332f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         */
1333f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public float getDesiredMaxLuminance() {
1334f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            return mMaxLuminance;
1335f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        }
1336f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        /**
1337f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         * Returns the desired content max frame-average luminance data in cd/m2 for this display.
1338f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         */
1339f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public float getDesiredMaxAverageLuminance() {
1340f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            return mMaxAverageLuminance;
1341f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        }
1342f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        /**
1343f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         * Returns the desired content min luminance data in cd/m2 for this display.
1344f173c323449840771312afe5cbec03a71281e6ffRonghua Wu         */
1345f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public float getDesiredMinLuminance() {
1346f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            return mMinLuminance;
1347f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        }
1348f173c323449840771312afe5cbec03a71281e6ffRonghua Wu
134916ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright        @Override
135016ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright        public boolean equals(Object other) {
135116ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            if (this == other) {
135216ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright                return true;
135316ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            }
135416ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright
135516ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            if (!(other instanceof HdrCapabilities)) {
135616ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright                return false;
135716ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            }
135816ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            HdrCapabilities that = (HdrCapabilities) other;
135916ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright
136016ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            return Arrays.equals(mSupportedHdrTypes, that.mSupportedHdrTypes)
136116ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright                && mMaxLuminance == that.mMaxLuminance
136216ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright                && mMaxAverageLuminance == that.mMaxAverageLuminance
136316ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright                && mMinLuminance == that.mMinLuminance;
136416ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright        }
136516ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright
136616ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright        @Override
136716ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright        public int hashCode() {
136816ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            int hash = 23;
136916ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            hash = hash * 17 + Arrays.hashCode(mSupportedHdrTypes);
137016ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            hash = hash * 17 + Float.floatToIntBits(mMaxLuminance);
137116ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            hash = hash * 17 + Float.floatToIntBits(mMaxAverageLuminance);
137216ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            hash = hash * 17 + Float.floatToIntBits(mMinLuminance);
137316ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright            return hash;
137416ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright        }
137516ae0423516ec1146ff191b4e856e1a6f88ea495Michael Wright
1376f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public static final Creator<HdrCapabilities> CREATOR = new Creator<HdrCapabilities>() {
1377f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            @Override
1378f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            public HdrCapabilities createFromParcel(Parcel source) {
1379f173c323449840771312afe5cbec03a71281e6ffRonghua Wu                return new HdrCapabilities(source);
1380f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            }
1381f173c323449840771312afe5cbec03a71281e6ffRonghua Wu
1382f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            @Override
1383f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            public HdrCapabilities[] newArray(int size) {
1384f173c323449840771312afe5cbec03a71281e6ffRonghua Wu                return new HdrCapabilities[size];
1385f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            }
1386f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        };
1387f173c323449840771312afe5cbec03a71281e6ffRonghua Wu
1388f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        private HdrCapabilities(Parcel source) {
1389f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            readFromParcel(source);
1390f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        }
1391f173c323449840771312afe5cbec03a71281e6ffRonghua Wu
1392da802f5100fe2b19b5cb898efc2c66bdd7e19fd1Hangyu Kuang        /**
1393da802f5100fe2b19b5cb898efc2c66bdd7e19fd1Hangyu Kuang         * @hide
1394da802f5100fe2b19b5cb898efc2c66bdd7e19fd1Hangyu Kuang         */
1395f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public void readFromParcel(Parcel source) {
1396f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            int types = source.readInt();
1397f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            mSupportedHdrTypes = new int[types];
1398f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            for (int i = 0; i < types; ++i) {
1399f173c323449840771312afe5cbec03a71281e6ffRonghua Wu                mSupportedHdrTypes[i] = source.readInt();
1400f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            }
1401f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            mMaxLuminance = source.readFloat();
1402f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            mMaxAverageLuminance = source.readFloat();
1403f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            mMinLuminance = source.readFloat();
1404f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        }
1405f173c323449840771312afe5cbec03a71281e6ffRonghua Wu
1406f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        @Override
1407f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public void writeToParcel(Parcel dest, int flags) {
1408f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            dest.writeInt(mSupportedHdrTypes.length);
1409f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            for (int i = 0; i < mSupportedHdrTypes.length; ++i) {
1410f173c323449840771312afe5cbec03a71281e6ffRonghua Wu                dest.writeInt(mSupportedHdrTypes[i]);
1411f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            }
1412f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            dest.writeFloat(mMaxLuminance);
1413f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            dest.writeFloat(mMaxAverageLuminance);
1414f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            dest.writeFloat(mMinLuminance);
1415f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        }
1416f173c323449840771312afe5cbec03a71281e6ffRonghua Wu
1417f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        @Override
1418f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        public int describeContents() {
1419f173c323449840771312afe5cbec03a71281e6ffRonghua Wu            return 0;
1420f173c323449840771312afe5cbec03a71281e6ffRonghua Wu        }
1421f173c323449840771312afe5cbec03a71281e6ffRonghua Wu    }
1422037c33eae74bee2774897d969d48947f9abe254fJeff Brown}
1423