blob: b3d98b8de0a37ead7a6c1c7f331a3178cae0fc17 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view;
18
Aurimas Liutikas67e2ae82016-10-11 18:17:42 -070019import static android.Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE;
20
Ronghua Wuf173c322016-02-29 13:57:18 -080021import android.annotation.IntDef;
Adrian Roosa4904792018-05-31 19:48:39 +020022import android.annotation.Nullable;
Michael Wright58e829f2015-09-15 00:13:26 +010023import android.annotation.RequiresPermission;
lumarkec75b422019-01-07 15:58:38 +080024import android.annotation.TestApi;
Mathew Inwooda570dee2018-08-17 14:56:00 +010025import android.annotation.UnsupportedAppUsage;
Adrian Roose99bc052017-11-20 17:55:31 +010026import android.app.KeyguardManager;
Craig Mautner48d0d182013-06-11 07:53:06 -070027import android.content.res.CompatibilityInfo;
Romain Guye89d0bb2017-06-20 12:23:42 -070028import android.content.res.Configuration;
Bryce Lee609bf652017-02-09 16:50:13 -080029import android.content.res.Resources;
Peiyong Lin277eaff2019-01-16 16:18:22 -080030import android.graphics.ColorSpace;
Jeff Brownfa25bf52012-07-23 19:26:30 -070031import android.graphics.PixelFormat;
Dianne Hackbornac8dea12011-04-20 18:18:51 -070032import android.graphics.Point;
33import android.graphics.Rect;
Andrii Kulian732a90a2017-08-17 17:21:20 -070034import android.hardware.display.DisplayManager;
Jeff Brownbd6e1502012-08-28 03:27:37 -070035import android.hardware.display.DisplayManagerGlobal;
Sergey Vasilinets669ad672019-02-07 13:42:33 +000036import android.os.Build;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -070037import android.os.Parcel;
38import android.os.Parcelable;
Jeff Browna506a6e2013-06-04 00:02:38 -070039import android.os.Process;
Dianne Hackbornac8dea12011-04-20 18:18:51 -070040import android.os.SystemClock;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.util.DisplayMetrics;
Jeff Brownfa25bf52012-07-23 19:26:30 -070042import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
Ronghua Wuf173c322016-02-29 13:57:18 -080044import java.lang.annotation.Retention;
45import java.lang.annotation.RetentionPolicy;
Michael Wright3f145a22014-07-22 19:46:03 -070046import java.util.Arrays;
47
Jeff Brownbc68a592011-07-25 12:58:12 -070048/**
Jeff Brownfa25bf52012-07-23 19:26:30 -070049 * Provides information about the size and density of a logical display.
50 * <p>
51 * The display area is described in two different ways.
52 * <ul>
53 * <li>The application display area specifies the part of the display that may contain
54 * an application window, excluding the system decorations. The application display area may
55 * be smaller than the real display area because the system subtracts the space needed
56 * for decor elements such as the status bar. Use the following methods to query the
57 * application display area: {@link #getSize}, {@link #getRectSize} and {@link #getMetrics}.</li>
58 * <li>The real display area specifies the part of the display that contains content
59 * including the system decorations. Even so, the real display area may be smaller than the
60 * physical size of the display if the window manager is emulating a smaller display
Andrii Kuliancd097992017-03-23 18:31:59 -070061 * using (adb shell wm size). Use the following methods to query the
Jeff Brownfa25bf52012-07-23 19:26:30 -070062 * real display area: {@link #getRealSize}, {@link #getRealMetrics}.</li>
63 * </ul>
64 * </p><p>
65 * A logical display does not necessarily represent a particular physical display device
66 * such as the built-in screen or an external monitor. The contents of a logical
67 * display may be presented on one or more physical displays according to the devices
68 * that are currently attached and whether mirroring has been enabled.
69 * </p>
Jeff Brownbc68a592011-07-25 12:58:12 -070070 */
Jeff Brownfa25bf52012-07-23 19:26:30 -070071public final class Display {
72 private static final String TAG = "Display";
Jeff Brownbd6e1502012-08-28 03:27:37 -070073 private static final boolean DEBUG = false;
Jeff Brownfa25bf52012-07-23 19:26:30 -070074
Jeff Brownbd6e1502012-08-28 03:27:37 -070075 private final DisplayManagerGlobal mGlobal;
Jeff Brownfa25bf52012-07-23 19:26:30 -070076 private final int mDisplayId;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070077 private final int mLayerStack;
Jeff Brown92130f62012-10-24 21:28:33 -070078 private final int mFlags;
79 private final int mType;
Dominik Laskowskidb845962019-01-27 21:20:00 -080080 private final DisplayAddress mAddress;
Jeff Browna506a6e2013-06-04 00:02:38 -070081 private final int mOwnerUid;
82 private final String mOwnerPackageName;
Bryce Lee609bf652017-02-09 16:50:13 -080083 private final Resources mResources;
84 private DisplayAdjustments mDisplayAdjustments;
Jeff Brownbd6e1502012-08-28 03:27:37 -070085
Mathew Inwooda570dee2018-08-17 14:56:00 +010086 @UnsupportedAppUsage
Jeff Brownbd6e1502012-08-28 03:27:37 -070087 private DisplayInfo mDisplayInfo; // never null
88 private boolean mIsValid;
Jeff Brownfa25bf52012-07-23 19:26:30 -070089
90 // Temporary display metrics structure used for compatibility mode.
91 private final DisplayMetrics mTempMetrics = new DisplayMetrics();
92
93 // We cache the app width and height properties briefly between calls
94 // to getHeight() and getWidth() to ensure that applications perceive
95 // consistent results when the size changes (most of the time).
96 // Applications should now be using getSize() instead.
97 private static final int CACHED_APP_SIZE_DURATION_MILLIS = 20;
98 private long mLastCachedAppSizeUpdate;
99 private int mCachedAppWidthCompat;
100 private int mCachedAppHeightCompat;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 /**
Jeff Brown98365d72012-08-19 20:30:52 -0700103 * The default Display id, which is the id of the built-in primary display
104 * assuming there is one.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 */
106 public static final int DEFAULT_DISPLAY = 0;
107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 /**
Wale Ogunwale26698512015-06-05 16:55:33 -0700109 * Invalid display id.
110 */
111 public static final int INVALID_DISPLAY = -1;
112
113 /**
Jeff Brown77aebfd2012-10-01 21:07:03 -0700114 * Display flag: Indicates that the display supports compositing content
115 * that is stored in protected graphics buffers.
Jeff Brownc5df37c2012-09-13 11:45:07 -0700116 * <p>
Jeff Brownf0681b32012-10-23 17:35:57 -0700117 * If this flag is set then the display device supports compositing protected buffers.
118 * </p><p>
119 * If this flag is not set then the display device may not support compositing
120 * protected buffers; the user may see a blank region on the screen instead of
121 * the protected content.
122 * </p><p>
Jeff Brown77aebfd2012-10-01 21:07:03 -0700123 * Secure (DRM) video decoders may allocate protected graphics buffers to request that
124 * a hardware-protected path be provided between the video decoder and the external
125 * display sink. If a hardware-protected path is not available, then content stored
126 * in protected graphics buffers may not be composited.
Jeff Brownc5df37c2012-09-13 11:45:07 -0700127 * </p><p>
Jeff Brownf0681b32012-10-23 17:35:57 -0700128 * An application can use the absence of this flag as a hint that it should not use protected
129 * buffers for this display because the content may not be visible. For example,
130 * if the flag is not set then the application may choose not to show content on this
131 * display, show an informative error message, select an alternate content stream
132 * or adopt a different strategy for decoding content that does not rely on
133 * protected buffers.
Jeff Brownc5df37c2012-09-13 11:45:07 -0700134 * </p>
Jeff Brownf0681b32012-10-23 17:35:57 -0700135 *
136 * @see #getFlags
Jeff Brownc5df37c2012-09-13 11:45:07 -0700137 */
Jeff Brown77aebfd2012-10-01 21:07:03 -0700138 public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 0;
Jeff Brownc5df37c2012-09-13 11:45:07 -0700139
140 /**
Jeff Brownf0681b32012-10-23 17:35:57 -0700141 * Display flag: Indicates that the display has a secure video output and
142 * supports compositing secure surfaces.
143 * <p>
144 * If this flag is set then the display device has a secure video output
145 * and is capable of showing secure surfaces. It may also be capable of
146 * showing {@link #FLAG_SUPPORTS_PROTECTED_BUFFERS protected buffers}.
147 * </p><p>
148 * If this flag is not set then the display device may not have a secure video
149 * output; the user may see a blank region on the screen instead of
150 * the contents of secure surfaces or protected buffers.
151 * </p><p>
152 * Secure surfaces are used to prevent content rendered into those surfaces
153 * by applications from appearing in screenshots or from being viewed
154 * on non-secure displays. Protected buffers are used by secure video decoders
155 * for a similar purpose.
156 * </p><p>
157 * An application creates a window with a secure surface by specifying the
158 * {@link WindowManager.LayoutParams#FLAG_SECURE} window flag.
159 * Likewise, an application creates a {@link SurfaceView} with a secure surface
160 * by calling {@link SurfaceView#setSecure} before attaching the secure view to
161 * its containing window.
162 * </p><p>
163 * An application can use the absence of this flag as a hint that it should not create
164 * secure surfaces or protected buffers on this display because the content may
165 * not be visible. For example, if the flag is not set then the application may
166 * choose not to show content on this display, show an informative error message,
167 * select an alternate content stream or adopt a different strategy for decoding
168 * content that does not rely on secure surfaces or protected buffers.
169 * </p>
170 *
171 * @see #getFlags
172 */
173 public static final int FLAG_SECURE = 1 << 1;
174
175 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700176 * Display flag: Indicates that the display is private. Only the application that
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800177 * owns the display and apps that are already on the display can create windows on it.
Jeff Browna506a6e2013-06-04 00:02:38 -0700178 *
179 * @see #getFlags
180 */
181 public static final int FLAG_PRIVATE = 1 << 2;
182
183 /**
Jeff Brown7d00aff2013-08-02 19:03:49 -0700184 * Display flag: Indicates that the display is a presentation display.
185 * <p>
186 * This flag identifies secondary displays that are suitable for
187 * use as presentation displays such as HDMI or Wireless displays. Applications
188 * may automatically project their content to presentation displays to provide
189 * richer second screen experiences.
190 * </p>
191 *
192 * @see #getFlags
193 */
194 public static final int FLAG_PRESENTATION = 1 << 3;
195
196 /**
Adam Powell49e7ff92015-05-14 16:18:53 -0700197 * Display flag: Indicates that the display has a round shape.
198 * <p>
199 * This flag identifies displays that are circular, elliptical or otherwise
200 * do not permit the user to see all the way to the logical corners of the display.
201 * </p>
202 *
203 * @see #getFlags
204 */
205 public static final int FLAG_ROUND = 1 << 4;
206
207 /**
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800208 * Display flag: Indicates that the display can show its content when non-secure keyguard is
209 * shown.
210 * <p>
Andrii Kulian732a90a2017-08-17 17:21:20 -0700211 * This flag identifies secondary displays that will continue showing content if keyguard can be
212 * dismissed without entering credentials.
213 * </p><p>
214 * An example of usage is a virtual display which content is displayed on external hardware
215 * display that is not visible to the system directly.
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800216 * </p>
217 *
Andrii Kulian732a90a2017-08-17 17:21:20 -0700218 * @see DisplayManager#VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD
Adrian Roose99bc052017-11-20 17:55:31 +0100219 * @see KeyguardManager#isDeviceSecure()
220 * @see KeyguardManager#isDeviceLocked()
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800221 * @see #getFlags
Andrii Kulian22512e82017-04-13 11:34:43 -0700222 * @hide
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800223 */
Chilun8753ad32018-10-09 15:56:45 +0800224 // TODO (b/114338689): Remove the flag and use IWindowManager#shouldShowWithInsecureKeyguard
Andrii Kulian7211d2e2017-01-27 15:58:05 -0800225 public static final int FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 5;
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800226
227 /**
Louis Changbd48dca2018-08-29 17:44:34 +0800228 * Display flag: Indicates that the display should show system decorations.
229 * <p>
230 * This flag identifies secondary displays that should show system decorations, such as status
231 * bar, navigation bar, home activity or IME.
232 * </p>
233 *
Louis Changbd48dca2018-08-29 17:44:34 +0800234 * @hide
235 */
Chilun8753ad32018-10-09 15:56:45 +0800236 // TODO (b/114338689): Remove the flag and use IWindowManager#setShouldShowSystemDecors
Louis Changbd48dca2018-08-29 17:44:34 +0800237 public static final int FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS = 1 << 6;
238
239 /**
Jeff Brownd46747a2015-04-15 19:02:36 -0700240 * Display flag: Indicates that the contents of the display should not be scaled
241 * to fit the physical screen dimensions. Used for development only to emulate
242 * devices with smaller physicals screens while preserving density.
243 *
244 * @hide
245 */
246 public static final int FLAG_SCALING_DISABLED = 1 << 30;
247
248 /**
Jeff Brown92130f62012-10-24 21:28:33 -0700249 * Display type: Unknown display type.
250 * @hide
251 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100252 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700253 public static final int TYPE_UNKNOWN = 0;
254
255 /**
256 * Display type: Built-in display.
257 * @hide
258 */
259 public static final int TYPE_BUILT_IN = 1;
260
261 /**
262 * Display type: HDMI display.
263 * @hide
264 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100265 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700266 public static final int TYPE_HDMI = 2;
267
268 /**
269 * Display type: WiFi display.
270 * @hide
271 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100272 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700273 public static final int TYPE_WIFI = 3;
274
275 /**
276 * Display type: Overlay display.
277 * @hide
278 */
279 public static final int TYPE_OVERLAY = 4;
280
281 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700282 * Display type: Virtual display.
283 * @hide
284 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100285 @UnsupportedAppUsage
Jeff Browna506a6e2013-06-04 00:02:38 -0700286 public static final int TYPE_VIRTUAL = 5;
287
288 /**
Jeff Brown037c33e2014-04-09 00:31:55 -0700289 * Display state: The display state is unknown.
290 *
291 * @see #getState
292 */
Bookatz1a1b0462018-01-12 11:47:03 -0800293 public static final int STATE_UNKNOWN = ViewProtoEnums.DISPLAY_STATE_UNKNOWN; // 0
Jeff Brown037c33e2014-04-09 00:31:55 -0700294
295 /**
296 * Display state: The display is off.
297 *
298 * @see #getState
299 */
Bookatz1a1b0462018-01-12 11:47:03 -0800300 public static final int STATE_OFF = ViewProtoEnums.DISPLAY_STATE_OFF; // 1
Jeff Brown037c33e2014-04-09 00:31:55 -0700301
302 /**
303 * Display state: The display is on.
304 *
305 * @see #getState
306 */
Bookatz1a1b0462018-01-12 11:47:03 -0800307 public static final int STATE_ON = ViewProtoEnums.DISPLAY_STATE_ON; // 2
Jeff Brown037c33e2014-04-09 00:31:55 -0700308
309 /**
Jeff Brown5dc21912014-07-17 18:50:18 -0700310 * Display state: The display is dozing in a low power state; it is still
311 * on but is optimized for showing system-provided content while the
312 * device is non-interactive.
Jeff Brown037c33e2014-04-09 00:31:55 -0700313 *
314 * @see #getState
315 * @see android.os.PowerManager#isInteractive
316 */
Bookatz1a1b0462018-01-12 11:47:03 -0800317 public static final int STATE_DOZE = ViewProtoEnums.DISPLAY_STATE_DOZE; // 3
Jeff Brown5dc21912014-07-17 18:50:18 -0700318
319 /**
320 * Display state: The display is dozing in a suspended low power state; it is still
Chris Phoenix10a4a642017-09-25 13:21:00 -0700321 * on but the CPU is not updating it. This may be used in one of two ways: to show
322 * static system-provided content while the device is non-interactive, or to allow
323 * a "Sidekick" compute resource to update the display. For this reason, the
324 * CPU must not control the display in this mode.
Jeff Brown5dc21912014-07-17 18:50:18 -0700325 *
326 * @see #getState
327 * @see android.os.PowerManager#isInteractive
328 */
Bookatz1a1b0462018-01-12 11:47:03 -0800329 public static final int STATE_DOZE_SUSPEND = ViewProtoEnums.DISPLAY_STATE_DOZE_SUSPEND; // 4
Jeff Brown037c33e2014-04-09 00:31:55 -0700330
Santos Cordon3107d292016-09-20 15:50:35 -0700331 /**
332 * Display state: The display is on and optimized for VR mode.
333 *
334 * @see #getState
335 * @see android.os.PowerManager#isInteractive
Santos Cordon3107d292016-09-20 15:50:35 -0700336 */
Bookatz1a1b0462018-01-12 11:47:03 -0800337 public static final int STATE_VR = ViewProtoEnums.DISPLAY_STATE_VR; // 5
Santos Cordon3107d292016-09-20 15:50:35 -0700338
Chris Phoenix10a4a642017-09-25 13:21:00 -0700339 /**
340 * Display state: The display is in a suspended full power state; it is still
341 * on but the CPU is not updating it. This may be used in one of two ways: to show
342 * static system-provided content while the device is non-interactive, or to allow
343 * a "Sidekick" compute resource to update the display. For this reason, the
344 * CPU must not control the display in this mode.
345 *
346 * @see #getState
347 * @see android.os.PowerManager#isInteractive
348 */
Bookatz1a1b0462018-01-12 11:47:03 -0800349 public static final int STATE_ON_SUSPEND = ViewProtoEnums.DISPLAY_STATE_ON_SUSPEND; // 6
Chris Phoenix10a4a642017-09-25 13:21:00 -0700350
Michael Wright1c9977b2016-07-12 13:30:10 -0700351 /* The color mode constants defined below must be kept in sync with the ones in
Romain Guy6d228c22017-01-20 18:41:06 -0800352 * system/core/include/system/graphics-base.h */
Michael Wright1c9977b2016-07-12 13:30:10 -0700353
354 /**
355 * Display color mode: The current color mode is unknown or invalid.
356 * @hide
357 */
358 public static final int COLOR_MODE_INVALID = -1;
359
360 /**
361 * Display color mode: The default or native gamut of the display.
362 * @hide
363 */
364 public static final int COLOR_MODE_DEFAULT = 0;
365
Romain Guy6d228c22017-01-20 18:41:06 -0800366 /** @hide */
367 public static final int COLOR_MODE_BT601_625 = 1;
368 /** @hide */
369 public static final int COLOR_MODE_BT601_625_UNADJUSTED = 2;
370 /** @hide */
371 public static final int COLOR_MODE_BT601_525 = 3;
372 /** @hide */
373 public static final int COLOR_MODE_BT601_525_UNADJUSTED = 4;
374 /** @hide */
375 public static final int COLOR_MODE_BT709 = 5;
376 /** @hide */
377 public static final int COLOR_MODE_DCI_P3 = 6;
378 /** @hide */
Michael Wright1c9977b2016-07-12 13:30:10 -0700379 public static final int COLOR_MODE_SRGB = 7;
Romain Guy6d228c22017-01-20 18:41:06 -0800380 /** @hide */
381 public static final int COLOR_MODE_ADOBE_RGB = 8;
382 /** @hide */
383 public static final int COLOR_MODE_DISPLAY_P3 = 9;
Michael Wright1c9977b2016-07-12 13:30:10 -0700384
Jeff Brown037c33e2014-04-09 00:31:55 -0700385 /**
Andrii Kulian250d6532017-02-08 23:30:45 -0800386 * Indicates that when display is removed, all its activities will be moved to the primary
387 * display and the topmost activity should become focused.
388 *
389 * @hide
390 */
Chilun8753ad32018-10-09 15:56:45 +0800391 // TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_MOVE_TO_PRIMARY
Andrii Kulian250d6532017-02-08 23:30:45 -0800392 public static final int REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY = 0;
393 /**
394 * Indicates that when display is removed, all its stacks and tasks will be removed, all
395 * activities will be destroyed according to the usual lifecycle.
396 *
397 * @hide
398 */
Chilun8753ad32018-10-09 15:56:45 +0800399 // TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_DESTROY
Andrii Kulian250d6532017-02-08 23:30:45 -0800400 public static final int REMOVE_MODE_DESTROY_CONTENT = 1;
401
402 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700403 * Internal method to create a display.
Bryce Lee609bf652017-02-09 16:50:13 -0800404 * The display created with this method will have a static {@link DisplayAdjustments} applied.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700405 * Applications should use {@link android.view.WindowManager#getDefaultDisplay()}
Jeff Brown98365d72012-08-19 20:30:52 -0700406 * or {@link android.hardware.display.DisplayManager#getDisplay}
407 * to get a display object.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700408 *
409 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 */
Bryce Lee609bf652017-02-09 16:50:13 -0800411 public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
Craig Mautner48d0d182013-06-11 07:53:06 -0700412 DisplayAdjustments daj) {
Bryce Lee609bf652017-02-09 16:50:13 -0800413 this(global, displayId, displayInfo, daj, null /*res*/);
414 }
415
416 /**
417 * Internal method to create a display.
418 * The display created with this method will be adjusted based on the adjustments in the
419 * supplied {@link Resources}.
420 *
421 * @hide
422 */
423 public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
424 Resources res) {
425 this(global, displayId, displayInfo, null /*daj*/, res);
426 }
427
428 private Display(DisplayManagerGlobal global, int displayId,
429 /*@NotNull*/ DisplayInfo displayInfo, DisplayAdjustments daj, Resources res) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700430 mGlobal = global;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700431 mDisplayId = displayId;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700432 mDisplayInfo = displayInfo;
Bryce Lee609bf652017-02-09 16:50:13 -0800433 mResources = res;
434 mDisplayAdjustments = mResources != null
435 ? new DisplayAdjustments(mResources.getConfiguration())
436 : daj != null ? new DisplayAdjustments(daj) : null;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700437 mIsValid = true;
Jeff Brown92130f62012-10-24 21:28:33 -0700438
439 // Cache properties that cannot change as long as the display is valid.
440 mLayerStack = displayInfo.layerStack;
441 mFlags = displayInfo.flags;
442 mType = displayInfo.type;
443 mAddress = displayInfo.address;
Jeff Browna506a6e2013-06-04 00:02:38 -0700444 mOwnerUid = displayInfo.ownerUid;
445 mOwnerPackageName = displayInfo.ownerPackageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 }
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700449 * Gets the display id.
450 * <p>
451 * Each logical display has a unique id.
452 * The default display has id {@link #DEFAULT_DISPLAY}.
453 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 */
455 public int getDisplayId() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700456 return mDisplayId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 }
458
459 /**
Garfield Tan891146c2018-10-09 12:14:00 -0700460 * Gets the display unique id.
461 * <p>
462 * Unique id is different from display id because physical displays have stable unique id across
463 * reboots.
464 *
465 * @see com.android.service.display.DisplayDevice#hasStableUniqueId().
466 * @hide
467 */
468 public String getUniqueId() {
469 return mDisplayInfo.uniqueId;
470 }
471
472 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700473 * Returns true if this display is still valid, false if the display has been removed.
474 *
475 * If the display is invalid, then the methods of this class will
476 * continue to report the most recently observed display information.
477 * However, it is unwise (and rather fruitless) to continue using a
478 * {@link Display} object after the display's demise.
479 *
480 * It's possible for a display that was previously invalid to become
481 * valid again if a display with the same id is reconnected.
482 *
483 * @return True if the display is still valid.
484 */
485 public boolean isValid() {
486 synchronized (this) {
487 updateDisplayInfoLocked();
488 return mIsValid;
489 }
490 }
491
492 /**
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700493 * Gets a full copy of the display information.
494 *
495 * @param outDisplayInfo The object to receive the copy of the display information.
Jeff Brownbd6e1502012-08-28 03:27:37 -0700496 * @return True if the display is still valid.
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700497 * @hide
498 */
Sergey Vasilinets669ad672019-02-07 13:42:33 +0000499 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Jeff Brownbd6e1502012-08-28 03:27:37 -0700500 public boolean getDisplayInfo(DisplayInfo outDisplayInfo) {
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700501 synchronized (this) {
502 updateDisplayInfoLocked();
503 outDisplayInfo.copyFrom(mDisplayInfo);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700504 return mIsValid;
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700505 }
506 }
507
508 /**
Jeff Brown98365d72012-08-19 20:30:52 -0700509 * Gets the display's layer stack.
510 *
511 * Each display has its own independent layer stack upon which surfaces
512 * are placed to be managed by surface flinger.
513 *
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700514 * @return The display's layer stack number.
Jeff Brown98365d72012-08-19 20:30:52 -0700515 * @hide
516 */
517 public int getLayerStack() {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700518 return mLayerStack;
Jeff Brown98365d72012-08-19 20:30:52 -0700519 }
520
521 /**
Jeff Brownc5df37c2012-09-13 11:45:07 -0700522 * Returns a combination of flags that describe the capabilities of the display.
523 *
524 * @return The display flags.
525 *
Jeff Brown77aebfd2012-10-01 21:07:03 -0700526 * @see #FLAG_SUPPORTS_PROTECTED_BUFFERS
Jeff Brownf0681b32012-10-23 17:35:57 -0700527 * @see #FLAG_SECURE
Jeff Browna506a6e2013-06-04 00:02:38 -0700528 * @see #FLAG_PRIVATE
Jeff Brownc5df37c2012-09-13 11:45:07 -0700529 */
530 public int getFlags() {
Jeff Brown92130f62012-10-24 21:28:33 -0700531 return mFlags;
532 }
533
534 /**
535 * Gets the display type.
536 *
537 * @return The display type.
538 *
539 * @see #TYPE_UNKNOWN
540 * @see #TYPE_BUILT_IN
541 * @see #TYPE_HDMI
542 * @see #TYPE_WIFI
543 * @see #TYPE_OVERLAY
Jeff Browna506a6e2013-06-04 00:02:38 -0700544 * @see #TYPE_VIRTUAL
Jeff Brown92130f62012-10-24 21:28:33 -0700545 * @hide
546 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100547 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700548 public int getType() {
549 return mType;
550 }
551
552 /**
553 * Gets the display address, or null if none.
554 * Interpretation varies by display type.
555 *
556 * @return The display address.
557 * @hide
558 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100559 @UnsupportedAppUsage
Dominik Laskowskidb845962019-01-27 21:20:00 -0800560 public DisplayAddress getAddress() {
Jeff Brown92130f62012-10-24 21:28:33 -0700561 return mAddress;
Jeff Brownc5df37c2012-09-13 11:45:07 -0700562 }
563
564 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700565 * Gets the UID of the application that owns this display, or zero if it is
566 * owned by the system.
567 * <p>
568 * If the display is private, then only the owner can use it.
569 * </p>
570 *
571 * @hide
572 */
573 public int getOwnerUid() {
574 return mOwnerUid;
575 }
576
577 /**
578 * Gets the package name of the application that owns this display, or null if it is
579 * owned by the system.
580 * <p>
581 * If the display is private, then only the owner can use it.
582 * </p>
583 *
584 * @hide
585 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100586 @UnsupportedAppUsage
Jeff Browna506a6e2013-06-04 00:02:38 -0700587 public String getOwnerPackageName() {
588 return mOwnerPackageName;
589 }
590
591 /**
Jeff Brown98365d72012-08-19 20:30:52 -0700592 * Gets the compatibility info used by this display instance.
593 *
Craig Mautner48d0d182013-06-11 07:53:06 -0700594 * @return The display adjustments holder, or null if none is required.
Jeff Brown98365d72012-08-19 20:30:52 -0700595 * @hide
596 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100597 @UnsupportedAppUsage
Craig Mautner48d0d182013-06-11 07:53:06 -0700598 public DisplayAdjustments getDisplayAdjustments() {
Bryce Lee609bf652017-02-09 16:50:13 -0800599 if (mResources != null) {
600 final DisplayAdjustments currentAdjustements = mResources.getDisplayAdjustments();
601 if (!mDisplayAdjustments.equals(currentAdjustements)) {
602 mDisplayAdjustments = new DisplayAdjustments(currentAdjustements);
603 }
604 }
605
Craig Mautner48d0d182013-06-11 07:53:06 -0700606 return mDisplayAdjustments;
Jeff Brown98365d72012-08-19 20:30:52 -0700607 }
608
609 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700610 * Gets the name of the display.
Jeff Brown92130f62012-10-24 21:28:33 -0700611 * <p>
612 * Note that some displays may be renamed by the user.
613 * </p>
614 *
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700615 * @return The display's name.
616 */
617 public String getName() {
Jeff Brown92130f62012-10-24 21:28:33 -0700618 synchronized (this) {
619 updateDisplayInfoLocked();
620 return mDisplayInfo.name;
621 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700622 }
623
624 /**
Jeff Brownbc68a592011-07-25 12:58:12 -0700625 * Gets the size of the display, in pixels.
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700626 * Value returned by this method does not necessarily represent the actual raw size
627 * (native resolution) of the display.
Jeff Brownbc68a592011-07-25 12:58:12 -0700628 * <p>
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700629 * 1. The returned size may be adjusted to exclude certain system decor elements
630 * that are always visible.
Jeff Brownbc68a592011-07-25 12:58:12 -0700631 * </p><p>
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700632 * 2. It may be scaled to provide compatibility with older applications that
Jeff Brownbc68a592011-07-25 12:58:12 -0700633 * were originally designed for smaller displays.
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700634 * </p><p>
635 * 3. It can be different depending on the WindowManager to which the display belongs.
636 * </p><p>
637 * - If requested from non-Activity context (e.g. Application context via
638 * {@code (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)})
639 * it will report the size of the entire display based on current rotation and with subtracted
640 * system decoration areas.
641 * </p><p>
642 * - If requested from activity (either using {@code getWindowManager()} or
643 * {@code (WindowManager) getSystemService(Context.WINDOW_SERVICE)}) resulting size will
644 * correspond to current app window size. In this case it can be smaller than physical size in
645 * multi-window mode.
646 * </p><p>
647 * Typically for the purposes of layout apps should make a request from activity context
648 * to obtain size available for the app content.
Jeff Brownbc68a592011-07-25 12:58:12 -0700649 * </p>
650 *
651 * @param outSize A {@link Point} object to receive the size information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 */
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700653 public void getSize(Point outSize) {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700654 synchronized (this) {
655 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -0800656 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownfa25bf52012-07-23 19:26:30 -0700657 outSize.x = mTempMetrics.widthPixels;
658 outSize.y = mTempMetrics.heightPixels;
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700659 }
660 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 /**
Jeff Brownbc68a592011-07-25 12:58:12 -0700663 * Gets the size of the display as a rectangle, in pixels.
664 *
665 * @param outSize A {@link Rect} object to receive the size information.
666 * @see #getSize(Point)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 */
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700668 public void getRectSize(Rect outSize) {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700669 synchronized (this) {
670 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -0800671 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownfa25bf52012-07-23 19:26:30 -0700672 outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels);
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700673 }
674 }
675
676 /**
Dianne Hackborn68c33ca2012-04-19 14:51:25 -0700677 * Return the range of display sizes an application can expect to encounter
678 * under normal operation, as long as there is no physical change in screen
679 * size. This is basically the sizes you will see as the orientation
680 * changes, taking into account whatever screen decoration there is in
681 * each rotation. For example, the status bar is always at the top of the
682 * screen, so it will reduce the height both in landscape and portrait, and
683 * the smallest height returned here will be the smaller of the two.
684 *
685 * This is intended for applications to get an idea of the range of sizes
686 * they will encounter while going through device rotations, to provide a
687 * stable UI through rotation. The sizes here take into account all standard
688 * system decorations that reduce the size actually available to the
689 * application: the status bar, navigation bar, system bar, etc. It does
690 * <em>not</em> take into account more transient elements like an IME
691 * soft keyboard.
692 *
693 * @param outSmallestSize Filled in with the smallest width and height
694 * that the application will encounter, in pixels (not dp units). The x
695 * (width) dimension here directly corresponds to
696 * {@link android.content.res.Configuration#smallestScreenWidthDp
697 * Configuration.smallestScreenWidthDp}, except the value here is in raw
698 * screen pixels rather than dp units. Your application may of course
699 * still get smaller space yet if, for example, a soft keyboard is
700 * being displayed.
701 * @param outLargestSize Filled in with the largest width and height
702 * that the application will encounter, in pixels (not dp units). Your
703 * application may of course still get larger space than this if,
704 * for example, screen decorations like the status bar are being hidden.
705 */
706 public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700707 synchronized (this) {
708 updateDisplayInfoLocked();
709 outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth;
710 outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight;
711 outLargestSize.x = mDisplayInfo.largestNominalAppWidth;
712 outLargestSize.y = mDisplayInfo.largestNominalAppHeight;
Dianne Hackborn68c33ca2012-04-19 14:51:25 -0700713 }
714 }
715
716 /**
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700717 * Return the maximum screen size dimension that will happen. This is
718 * mostly for wallpapers.
719 * @hide
720 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100721 @UnsupportedAppUsage
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700722 public int getMaximumSizeDimension() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700723 synchronized (this) {
724 updateDisplayInfoLocked();
725 return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700726 }
727 }
728
729 /**
730 * @deprecated Use {@link #getSize(Point)} instead.
731 */
732 @Deprecated
733 public int getWidth() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700734 synchronized (this) {
735 updateCachedAppSizeIfNeededLocked();
736 return mCachedAppWidthCompat;
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700737 }
738 }
739
740 /**
741 * @deprecated Use {@link #getSize(Point)} instead.
742 */
743 @Deprecated
744 public int getHeight() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700745 synchronized (this) {
746 updateCachedAppSizeIfNeededLocked();
747 return mCachedAppHeightCompat;
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700748 }
749 }
750
Jeff Brownbc68a592011-07-25 12:58:12 -0700751 /**
Dianne Hackbornc652de82013-02-15 16:32:56 -0800752 * @hide
753 * Return a rectangle defining the insets of the overscan region of the display.
754 * Each field of the rectangle is the number of pixels the overscan area extends
755 * into the display on that side.
756 */
757 public void getOverscanInsets(Rect outRect) {
758 synchronized (this) {
759 updateDisplayInfoLocked();
760 outRect.set(mDisplayInfo.overscanLeft, mDisplayInfo.overscanTop,
761 mDisplayInfo.overscanRight, mDisplayInfo.overscanBottom);
762 }
763 }
764
765 /**
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800766 * Returns the rotation of the screen from its "natural" orientation.
767 * The returned value may be {@link Surface#ROTATION_0 Surface.ROTATION_0}
768 * (no rotation), {@link Surface#ROTATION_90 Surface.ROTATION_90},
769 * {@link Surface#ROTATION_180 Surface.ROTATION_180}, or
770 * {@link Surface#ROTATION_270 Surface.ROTATION_270}. For
771 * example, if a device has a naturally tall screen, and the user has
772 * turned it on its side to go into a landscape orientation, the value
773 * returned here may be either {@link Surface#ROTATION_90 Surface.ROTATION_90}
774 * or {@link Surface#ROTATION_270 Surface.ROTATION_270} depending on
775 * the direction it was turned. The angle is the rotation of the drawn
776 * graphics on the screen, which is the opposite direction of the physical
777 * rotation of the device. For example, if the device is rotated 90
778 * degrees counter-clockwise, to compensate rendering will be rotated by
779 * 90 degrees clockwise and thus the returned value here will be
780 * {@link Surface#ROTATION_90 Surface.ROTATION_90}.
781 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700782 @Surface.Rotation
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800783 public int getRotation() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700784 synchronized (this) {
785 updateDisplayInfoLocked();
786 return mDisplayInfo.rotation;
787 }
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800788 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700789
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800790 /**
Joe Onorato4c904a32010-02-26 12:35:55 -0800791 * @deprecated use {@link #getRotation}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 * @return orientation of this display.
793 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700794 @Deprecated
Tor Norbyed9273d62013-05-30 15:59:53 -0700795 @Surface.Rotation
Jeff Brownfa25bf52012-07-23 19:26:30 -0700796 public int getOrientation() {
797 return getRotation();
798 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799
Adrian Roosa4904792018-05-31 19:48:39 +0200800
801 /**
802 * Returns the {@link DisplayCutout}, or {@code null} if there is none.
803 *
804 * @see DisplayCutout
805 */
806 @Nullable
807 public DisplayCutout getCutout() {
808 synchronized (this) {
809 updateDisplayInfoLocked();
810 return mDisplayInfo.displayCutout;
811 }
812 }
813
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700815 * Gets the pixel format of the display.
816 * @return One of the constants defined in {@link android.graphics.PixelFormat}.
817 *
818 * @deprecated This method is no longer supported.
819 * The result is always {@link PixelFormat#RGBA_8888}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700821 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 public int getPixelFormat() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700823 return PixelFormat.RGBA_8888;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700827 * Gets the refresh rate of this display in frames per second.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 */
829 public float getRefreshRate() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700830 synchronized (this) {
831 updateDisplayInfoLocked();
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700832 return mDisplayInfo.getMode().getRefreshRate();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700833 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 /**
Michael Wright3f145a22014-07-22 19:46:03 -0700837 * Get the supported refresh rates of this display in frames per second.
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700838 * <p>
839 * This method only returns refresh rates for the display's default modes. For more options, use
840 * {@link #getSupportedModes()}.
841 *
842 * @deprecated use {@link #getSupportedModes()} instead
Michael Wright3f145a22014-07-22 19:46:03 -0700843 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700844 @Deprecated
Michael Wright3f145a22014-07-22 19:46:03 -0700845 public float[] getSupportedRefreshRates() {
846 synchronized (this) {
847 updateDisplayInfoLocked();
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700848 return mDisplayInfo.getDefaultRefreshRates();
849 }
850 }
851
852 /**
853 * Returns the active mode of the display.
854 */
855 public Mode getMode() {
856 synchronized (this) {
857 updateDisplayInfoLocked();
858 return mDisplayInfo.getMode();
859 }
860 }
861
862 /**
863 * Gets the supported modes of this display.
864 */
865 public Mode[] getSupportedModes() {
866 synchronized (this) {
867 updateDisplayInfoLocked();
868 final Display.Mode[] modes = mDisplayInfo.supportedModes;
869 return Arrays.copyOf(modes, modes.length);
Michael Wright3f145a22014-07-22 19:46:03 -0700870 }
871 }
872
873 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700874 * Request the display applies a color mode.
Michael Wright58e829f2015-09-15 00:13:26 +0100875 * @hide
876 */
Michael Wright1c9977b2016-07-12 13:30:10 -0700877 @RequiresPermission(CONFIGURE_DISPLAY_COLOR_MODE)
878 public void requestColorMode(int colorMode) {
879 mGlobal.requestColorMode(mDisplayId, colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +0100880 }
881
882 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700883 * Returns the active color mode of this display
Michael Wright58e829f2015-09-15 00:13:26 +0100884 * @hide
885 */
Michael Wright1c9977b2016-07-12 13:30:10 -0700886 public int getColorMode() {
Michael Wright58e829f2015-09-15 00:13:26 +0100887 synchronized (this) {
888 updateDisplayInfoLocked();
Michael Wright1c9977b2016-07-12 13:30:10 -0700889 return mDisplayInfo.colorMode;
Michael Wright58e829f2015-09-15 00:13:26 +0100890 }
891 }
892
893 /**
Andrii Kulian250d6532017-02-08 23:30:45 -0800894 * @hide
895 * Get current remove mode of the display - what actions should be performed with the display's
896 * content when it is removed. Default behavior for public displays in this case is to move all
897 * activities to the primary display and make it focused. For private display - destroy all
898 * activities.
899 *
900 * @see #REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY
901 * @see #REMOVE_MODE_DESTROY_CONTENT
902 */
Chilun8753ad32018-10-09 15:56:45 +0800903 // TODO (b/114338689): Remove the method and use IWindowManager#getRemoveContentMode
Andrii Kulian250d6532017-02-08 23:30:45 -0800904 public int getRemoveMode() {
905 return mDisplayInfo.removeMode;
906 }
907
908 /**
Ronghua Wuf173c322016-02-29 13:57:18 -0800909 * Returns the display's HDR capabilities.
Romain Guy6d228c22017-01-20 18:41:06 -0800910 *
911 * @see #isHdr()
Ronghua Wuf173c322016-02-29 13:57:18 -0800912 */
913 public HdrCapabilities getHdrCapabilities() {
Michael Wright9ff94c02016-03-30 18:05:40 -0700914 synchronized (this) {
915 updateDisplayInfoLocked();
916 return mDisplayInfo.hdrCapabilities;
917 }
Ronghua Wuf173c322016-02-29 13:57:18 -0800918 }
919
920 /**
Romain Guy6d228c22017-01-20 18:41:06 -0800921 * Returns whether this display supports any HDR type.
922 *
923 * @see #getHdrCapabilities()
924 * @see HdrCapabilities#getSupportedHdrTypes()
925 */
926 public boolean isHdr() {
927 synchronized (this) {
928 updateDisplayInfoLocked();
Romain Guy408afbf2017-01-25 10:23:03 -0800929 return mDisplayInfo.isHdr();
Romain Guy6d228c22017-01-20 18:41:06 -0800930 }
931 }
932
933 /**
934 * Returns whether this display can be used to display wide color gamut content.
Romain Guye89d0bb2017-06-20 12:23:42 -0700935 * This does not necessarily mean the device itself can render wide color gamut
936 * content. To ensure wide color gamut content can be produced, refer to
937 * {@link Configuration#isScreenWideColorGamut()}.
Romain Guy6d228c22017-01-20 18:41:06 -0800938 */
939 public boolean isWideColorGamut() {
940 synchronized (this) {
941 updateDisplayInfoLocked();
Romain Guy408afbf2017-01-25 10:23:03 -0800942 return mDisplayInfo.isWideColorGamut();
Romain Guy6d228c22017-01-20 18:41:06 -0800943 }
944 }
945
946 /**
Peiyong Lin277eaff2019-01-16 16:18:22 -0800947 * Returns the preferred wide color space of the Display.
948 * The returned wide gamut color space is based on hardware capability and
949 * is preferred by the composition pipeline.
950 * Returns null if the display doesn't support wide color gamut.
951 * {@link Display#isWideColorGamut()}.
952 */
953 @Nullable
954 public ColorSpace getPreferredWideGamutColorSpace() {
955 synchronized (this) {
956 updateDisplayInfoLocked();
957 if (mDisplayInfo.isWideColorGamut()) {
958 return mGlobal.getPreferredWideGamutColorSpace();
959 }
960 return null;
961 }
962 }
963
964 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700965 * Gets the supported color modes of this device.
Michael Wright58e829f2015-09-15 00:13:26 +0100966 * @hide
967 */
Michael Wright1c9977b2016-07-12 13:30:10 -0700968 public int[] getSupportedColorModes() {
Michael Wright58e829f2015-09-15 00:13:26 +0100969 synchronized (this) {
970 updateDisplayInfoLocked();
Michael Wright1c9977b2016-07-12 13:30:10 -0700971 int[] colorModes = mDisplayInfo.supportedColorModes;
972 return Arrays.copyOf(colorModes, colorModes.length);
Michael Wright58e829f2015-09-15 00:13:26 +0100973 }
974 }
975
976 /**
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700977 * Gets the app VSYNC offset, in nanoseconds. This is a positive value indicating
978 * the phase offset of the VSYNC events provided by Choreographer relative to the
979 * display refresh. For example, if Choreographer reports that the refresh occurred
980 * at time N, it actually occurred at (N - appVsyncOffset).
981 * <p>
982 * Apps generally do not need to be aware of this. It's only useful for fine-grained
983 * A/V synchronization.
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700984 */
985 public long getAppVsyncOffsetNanos() {
986 synchronized (this) {
987 updateDisplayInfoLocked();
988 return mDisplayInfo.appVsyncOffsetNanos;
989 }
990 }
991
992 /**
993 * This is how far in advance a buffer must be queued for presentation at
994 * a given time. If you want a buffer to appear on the screen at
995 * time N, you must submit the buffer before (N - presentationDeadline).
996 * <p>
997 * The desired presentation time for GLES rendering may be set with
998 * {@link android.opengl.EGLExt#eglPresentationTimeANDROID}. For video decoding, use
999 * {@link android.media.MediaCodec#releaseOutputBuffer(int, long)}. Times are
1000 * expressed in nanoseconds, using the system monotonic clock
1001 * ({@link System#nanoTime}).
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001002 */
1003 public long getPresentationDeadlineNanos() {
1004 synchronized (this) {
1005 updateDisplayInfoLocked();
1006 return mDisplayInfo.presentationDeadlineNanos;
1007 }
1008 }
1009
1010 /**
Jeff Brownbc68a592011-07-25 12:58:12 -07001011 * Gets display metrics that describe the size and density of this display.
Jeff Brownbc68a592011-07-25 12:58:12 -07001012 * The size returned by this method does not necessarily represent the
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001013 * actual raw size (native resolution) of the display.
1014 * <p>
1015 * 1. The returned size may be adjusted to exclude certain system decor elements
1016 * that are always visible.
1017 * </p><p>
1018 * 2. It may be scaled to provide compatibility with older applications that
Jeff Brownbc68a592011-07-25 12:58:12 -07001019 * were originally designed for smaller displays.
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001020 * </p><p>
1021 * 3. It can be different depending on the WindowManager to which the display belongs.
Andrii Kulian5f57a3d2016-06-28 18:41:42 -07001022 * </p><p>
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001023 * - If requested from non-Activity context (e.g. Application context via
1024 * {@code (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)})
Andrii Kulian5f57a3d2016-06-28 18:41:42 -07001025 * metrics will report the size of the entire display based on current rotation and with
1026 * subtracted system decoration areas.
1027 * </p><p>
1028 * - If requested from activity (either using {@code getWindowManager()} or
1029 * {@code (WindowManager) getSystemService(Context.WINDOW_SERVICE)}) resulting metrics will
1030 * correspond to current app window metrics. In this case the size can be smaller than physical
1031 * size in multi-window mode.
Jeff Brownbc68a592011-07-25 12:58:12 -07001032 * </p>
1033 *
1034 * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 */
1036 public void getMetrics(DisplayMetrics outMetrics) {
Jeff Brownfa25bf52012-07-23 19:26:30 -07001037 synchronized (this) {
1038 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -08001039 mDisplayInfo.getAppMetrics(outMetrics, getDisplayAdjustments());
Dianne Hackborn68066c22011-04-21 17:26:39 -07001040 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001041 }
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001042
Jeff Brownfa25bf52012-07-23 19:26:30 -07001043 /**
1044 * Gets the real size of the display without subtracting any window decor or
1045 * applying any compatibility scale factors.
1046 * <p>
1047 * The size is adjusted based on the current rotation of the display.
1048 * </p><p>
1049 * The real size may be smaller than the physical size of the screen when the
Andrii Kuliancd097992017-03-23 18:31:59 -07001050 * window manager is emulating a smaller display (using adb shell wm size).
Jeff Brownfa25bf52012-07-23 19:26:30 -07001051 * </p>
1052 *
1053 * @param outSize Set to the real size of the display.
1054 */
1055 public void getRealSize(Point outSize) {
1056 synchronized (this) {
1057 updateDisplayInfoLocked();
1058 outSize.x = mDisplayInfo.logicalWidth;
1059 outSize.y = mDisplayInfo.logicalHeight;
1060 }
Dianne Hackborn68066c22011-04-21 17:26:39 -07001061 }
1062
1063 /**
Jeff Brownbc68a592011-07-25 12:58:12 -07001064 * Gets display metrics based on the real size of this display.
Jeff Brownfa25bf52012-07-23 19:26:30 -07001065 * <p>
1066 * The size is adjusted based on the current rotation of the display.
1067 * </p><p>
1068 * The real size may be smaller than the physical size of the screen when the
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001069 * window manager is emulating a smaller display (using adb shell wm size).
Jeff Brownfa25bf52012-07-23 19:26:30 -07001070 * </p>
1071 *
1072 * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
Dianne Hackborn68066c22011-04-21 17:26:39 -07001073 */
1074 public void getRealMetrics(DisplayMetrics outMetrics) {
Jeff Brownfa25bf52012-07-23 19:26:30 -07001075 synchronized (this) {
1076 updateDisplayInfoLocked();
Craig Mautner48d0d182013-06-11 07:53:06 -07001077 mDisplayInfo.getLogicalMetrics(outMetrics,
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001078 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
Jeff Brownbc68a592011-07-25 12:58:12 -07001079 }
Dianne Hackborn68066c22011-04-21 17:26:39 -07001080 }
1081
Jeff Browna506a6e2013-06-04 00:02:38 -07001082 /**
Jeff Brown037c33e2014-04-09 00:31:55 -07001083 * Gets the state of the display, such as whether it is on or off.
1084 *
1085 * @return The state of the display: one of {@link #STATE_OFF}, {@link #STATE_ON},
Chris Phoenix10a4a642017-09-25 13:21:00 -07001086 * {@link #STATE_DOZE}, {@link #STATE_DOZE_SUSPEND}, {@link #STATE_ON_SUSPEND}, or
Santos Cordon3107d292016-09-20 15:50:35 -07001087 * {@link #STATE_UNKNOWN}.
Jeff Brown037c33e2014-04-09 00:31:55 -07001088 */
1089 public int getState() {
1090 synchronized (this) {
1091 updateDisplayInfoLocked();
1092 return mIsValid ? mDisplayInfo.state : STATE_UNKNOWN;
1093 }
1094 }
1095
1096 /**
Jeff Browna506a6e2013-06-04 00:02:38 -07001097 * Returns true if the specified UID has access to this display.
1098 * @hide
1099 */
lumarkec75b422019-01-07 15:58:38 +08001100 @TestApi
Jeff Browna506a6e2013-06-04 00:02:38 -07001101 public boolean hasAccess(int uid) {
lumarkec75b422019-01-07 15:58:38 +08001102 return hasAccess(uid, mFlags, mOwnerUid, mDisplayId);
Jeff Browna506a6e2013-06-04 00:02:38 -07001103 }
1104
1105 /** @hide */
lumarkec75b422019-01-07 15:58:38 +08001106 public static boolean hasAccess(int uid, int flags, int ownerUid, int displayId) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001107 return (flags & Display.FLAG_PRIVATE) == 0
1108 || uid == ownerUid
1109 || uid == Process.SYSTEM_UID
lumarkec75b422019-01-07 15:58:38 +08001110 || uid == 0
1111 // Check if the UID is present on given display.
1112 || DisplayManagerGlobal.getInstance().isUidPresentOnDisplay(uid, displayId);
Jeff Browna506a6e2013-06-04 00:02:38 -07001113 }
1114
Jeff Brown69b07162013-11-07 00:30:16 -08001115 /**
1116 * Returns true if the display is a public presentation display.
1117 * @hide
1118 */
1119 public boolean isPublicPresentation() {
1120 return (mFlags & (Display.FLAG_PRIVATE | Display.FLAG_PRESENTATION)) ==
1121 Display.FLAG_PRESENTATION;
1122 }
1123
Jeff Brownfa25bf52012-07-23 19:26:30 -07001124 private void updateDisplayInfoLocked() {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001125 // Note: The display manager caches display info objects on our behalf.
1126 DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId);
1127 if (newInfo == null) {
1128 // Preserve the old mDisplayInfo after the display is removed.
1129 if (mIsValid) {
1130 mIsValid = false;
1131 if (DEBUG) {
1132 Log.d(TAG, "Logical display " + mDisplayId + " was removed.");
1133 }
1134 }
1135 } else {
1136 // Use the new display info. (It might be the same object if nothing changed.)
1137 mDisplayInfo = newInfo;
1138 if (!mIsValid) {
1139 mIsValid = true;
1140 if (DEBUG) {
1141 Log.d(TAG, "Logical display " + mDisplayId + " was recreated.");
1142 }
1143 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001144 }
Jeff Brownbc68a592011-07-25 12:58:12 -07001145 }
1146
Jeff Brownfa25bf52012-07-23 19:26:30 -07001147 private void updateCachedAppSizeIfNeededLocked() {
1148 long now = SystemClock.uptimeMillis();
1149 if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) {
1150 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -08001151 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownfa25bf52012-07-23 19:26:30 -07001152 mCachedAppWidthCompat = mTempMetrics.widthPixels;
1153 mCachedAppHeightCompat = mTempMetrics.heightPixels;
1154 mLastCachedAppSizeUpdate = now;
1155 }
Jeff Brownbc68a592011-07-25 12:58:12 -07001156 }
Jeff Brownbf5740e2012-08-19 23:20:02 -07001157
1158 // For debugging purposes
1159 @Override
1160 public String toString() {
1161 synchronized (this) {
1162 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -08001163 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownbf5740e2012-08-19 23:20:02 -07001164 return "Display id " + mDisplayId + ": " + mDisplayInfo
Jeff Brownbd6e1502012-08-28 03:27:37 -07001165 + ", " + mTempMetrics + ", isValid=" + mIsValid;
Jeff Brownbf5740e2012-08-19 23:20:02 -07001166 }
1167 }
Jeff Brown92130f62012-10-24 21:28:33 -07001168
1169 /**
1170 * @hide
1171 */
1172 public static String typeToString(int type) {
1173 switch (type) {
1174 case TYPE_UNKNOWN:
1175 return "UNKNOWN";
1176 case TYPE_BUILT_IN:
1177 return "BUILT_IN";
1178 case TYPE_HDMI:
1179 return "HDMI";
1180 case TYPE_WIFI:
1181 return "WIFI";
1182 case TYPE_OVERLAY:
1183 return "OVERLAY";
Jeff Browna506a6e2013-06-04 00:02:38 -07001184 case TYPE_VIRTUAL:
1185 return "VIRTUAL";
Jeff Brown92130f62012-10-24 21:28:33 -07001186 default:
1187 return Integer.toString(type);
1188 }
1189 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190
Jeff Brown037c33e2014-04-09 00:31:55 -07001191 /**
1192 * @hide
1193 */
1194 public static String stateToString(int state) {
1195 switch (state) {
1196 case STATE_UNKNOWN:
1197 return "UNKNOWN";
1198 case STATE_OFF:
1199 return "OFF";
1200 case STATE_ON:
1201 return "ON";
Jeff Brown5dc21912014-07-17 18:50:18 -07001202 case STATE_DOZE:
1203 return "DOZE";
1204 case STATE_DOZE_SUSPEND:
1205 return "DOZE_SUSPEND";
Santos Cordon3107d292016-09-20 15:50:35 -07001206 case STATE_VR:
1207 return "VR";
Chris Phoenix10a4a642017-09-25 13:21:00 -07001208 case STATE_ON_SUSPEND:
1209 return "ON_SUSPEND";
Jeff Brown037c33e2014-04-09 00:31:55 -07001210 default:
1211 return Integer.toString(state);
1212 }
1213 }
Jeff Brown970d4132014-07-19 11:33:47 -07001214
1215 /**
1216 * Returns true if display updates may be suspended while in the specified
Chris Phoenix10a4a642017-09-25 13:21:00 -07001217 * display power state. In SUSPEND states, updates are absolutely forbidden.
Jeff Brown970d4132014-07-19 11:33:47 -07001218 * @hide
1219 */
1220 public static boolean isSuspendedState(int state) {
Chris Phoenix10a4a642017-09-25 13:21:00 -07001221 return state == STATE_OFF || state == STATE_DOZE_SUSPEND || state == STATE_ON_SUSPEND;
Jeff Brown970d4132014-07-19 11:33:47 -07001222 }
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001223
1224 /**
Michael Wright05e76fe2017-07-20 18:18:33 +01001225 * Returns true if the display may be in a reduced operating mode while in the
1226 * specified display power state.
1227 * @hide
1228 */
1229 public static boolean isDozeState(int state) {
1230 return state == STATE_DOZE || state == STATE_DOZE_SUSPEND;
1231 }
1232
1233 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001234 * A mode supported by a given display.
1235 *
1236 * @see Display#getSupportedModes()
1237 */
1238 public static final class Mode implements Parcelable {
1239 /**
1240 * @hide
1241 */
1242 public static final Mode[] EMPTY_ARRAY = new Mode[0];
1243
1244 private final int mModeId;
1245 private final int mWidth;
1246 private final int mHeight;
1247 private final float mRefreshRate;
1248
1249 /**
1250 * @hide
1251 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001252 @UnsupportedAppUsage
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001253 public Mode(int modeId, int width, int height, float refreshRate) {
1254 mModeId = modeId;
1255 mWidth = width;
1256 mHeight = height;
1257 mRefreshRate = refreshRate;
1258 }
1259
1260 /**
1261 * Returns this mode's id.
1262 */
1263 public int getModeId() {
1264 return mModeId;
1265 }
1266
1267 /**
1268 * Returns the physical width of the display in pixels when configured in this mode's
1269 * resolution.
1270 * <p>
1271 * Note that due to application UI scaling, the number of pixels made available to
1272 * applications when the mode is active (as reported by {@link Display#getWidth()} may
1273 * differ from the mode's actual resolution (as reported by this function).
1274 * <p>
1275 * For example, applications running on a 4K display may have their UI laid out and rendered
1276 * in 1080p and then scaled up. Applications can take advantage of the extra resolution by
1277 * rendering content through a {@link android.view.SurfaceView} using full size buffers.
1278 */
1279 public int getPhysicalWidth() {
1280 return mWidth;
1281 }
1282
1283 /**
1284 * Returns the physical height of the display in pixels when configured in this mode's
1285 * resolution.
1286 * <p>
1287 * Note that due to application UI scaling, the number of pixels made available to
1288 * applications when the mode is active (as reported by {@link Display#getHeight()} may
1289 * differ from the mode's actual resolution (as reported by this function).
1290 * <p>
1291 * For example, applications running on a 4K display may have their UI laid out and rendered
1292 * in 1080p and then scaled up. Applications can take advantage of the extra resolution by
1293 * rendering content through a {@link android.view.SurfaceView} using full size buffers.
1294 */
1295 public int getPhysicalHeight() {
1296 return mHeight;
1297 }
1298
1299 /**
1300 * Returns the refresh rate in frames per second.
1301 */
1302 public float getRefreshRate() {
1303 return mRefreshRate;
1304 }
1305
1306 /**
1307 * Returns {@code true} if this mode matches the given parameters.
1308 *
1309 * @hide
1310 */
1311 public boolean matches(int width, int height, float refreshRate) {
1312 return mWidth == width &&
1313 mHeight == height &&
1314 Float.floatToIntBits(mRefreshRate) == Float.floatToIntBits(refreshRate);
1315 }
1316
1317 @Override
1318 public boolean equals(Object other) {
1319 if (this == other) {
1320 return true;
1321 }
1322 if (!(other instanceof Mode)) {
1323 return false;
1324 }
1325 Mode that = (Mode) other;
1326 return mModeId == that.mModeId && matches(that.mWidth, that.mHeight, that.mRefreshRate);
1327 }
1328
1329 @Override
1330 public int hashCode() {
1331 int hash = 1;
1332 hash = hash * 17 + mModeId;
1333 hash = hash * 17 + mWidth;
1334 hash = hash * 17 + mHeight;
1335 hash = hash * 17 + Float.floatToIntBits(mRefreshRate);
1336 return hash;
1337 }
1338
1339 @Override
1340 public String toString() {
1341 return new StringBuilder("{")
1342 .append("id=").append(mModeId)
1343 .append(", width=").append(mWidth)
1344 .append(", height=").append(mHeight)
1345 .append(", fps=").append(mRefreshRate)
1346 .append("}")
1347 .toString();
1348 }
1349
1350 @Override
1351 public int describeContents() {
1352 return 0;
1353 }
1354
1355 private Mode(Parcel in) {
1356 this(in.readInt(), in.readInt(), in.readInt(), in.readFloat());
1357 }
1358
1359 @Override
1360 public void writeToParcel(Parcel out, int parcelableFlags) {
1361 out.writeInt(mModeId);
1362 out.writeInt(mWidth);
1363 out.writeInt(mHeight);
1364 out.writeFloat(mRefreshRate);
1365 }
1366
1367 @SuppressWarnings("hiding")
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001368 public static final @android.annotation.NonNull Parcelable.Creator<Mode> CREATOR
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001369 = new Parcelable.Creator<Mode>() {
1370 @Override
1371 public Mode createFromParcel(Parcel in) {
1372 return new Mode(in);
1373 }
1374
1375 @Override
1376 public Mode[] newArray(int size) {
1377 return new Mode[size];
1378 }
1379 };
1380 }
Michael Wright58e829f2015-09-15 00:13:26 +01001381
1382 /**
Ronghua Wuf173c322016-02-29 13:57:18 -08001383 * Encapsulates the HDR capabilities of a given display.
1384 * For example, what HDR types it supports and details about the desired luminance data.
1385 * <p>You can get an instance for a given {@link Display} object with
1386 * {@link Display#getHdrCapabilities getHdrCapabilities()}.
Ronghua Wuf173c322016-02-29 13:57:18 -08001387 */
1388 public static final class HdrCapabilities implements Parcelable {
1389 /**
1390 * Invalid luminance value.
1391 */
1392 public static final float INVALID_LUMINANCE = -1;
1393 /**
1394 * Dolby Vision high dynamic range (HDR) display.
1395 */
1396 public static final int HDR_TYPE_DOLBY_VISION = 1;
1397 /**
1398 * HDR10 display.
1399 */
1400 public static final int HDR_TYPE_HDR10 = 2;
1401 /**
1402 * Hybrid Log-Gamma HDR display.
1403 */
1404 public static final int HDR_TYPE_HLG = 3;
1405
Peiyong Lin173ae082019-01-17 12:34:21 -08001406 /**
1407 * HDR10+ display.
1408 */
1409 public static final int HDR_TYPE_HDR10_PLUS = 4;
1410
Hangyu Kuangda802f52016-04-06 18:02:17 -07001411 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001412 @IntDef(prefix = { "HDR_TYPE_" }, value = {
1413 HDR_TYPE_DOLBY_VISION,
1414 HDR_TYPE_HDR10,
1415 HDR_TYPE_HLG,
Peiyong Lin173ae082019-01-17 12:34:21 -08001416 HDR_TYPE_HDR10_PLUS,
Ronghua Wuf173c322016-02-29 13:57:18 -08001417 })
1418 @Retention(RetentionPolicy.SOURCE)
1419 public @interface HdrType {}
1420
1421 private @HdrType int[] mSupportedHdrTypes = new int[0];
1422 private float mMaxLuminance = INVALID_LUMINANCE;
1423 private float mMaxAverageLuminance = INVALID_LUMINANCE;
1424 private float mMinLuminance = INVALID_LUMINANCE;
1425
Hangyu Kuangda802f52016-04-06 18:02:17 -07001426 /**
1427 * @hide
1428 */
Ronghua Wuf173c322016-02-29 13:57:18 -08001429 public HdrCapabilities() {
1430 }
1431
Hangyu Kuang1e7d1aa2016-05-17 14:21:01 -07001432 /**
1433 * @hide
1434 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001435 @UnsupportedAppUsage
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001436 public HdrCapabilities(int[] supportedHdrTypes, float maxLuminance,
1437 float maxAverageLuminance, float minLuminance) {
1438 mSupportedHdrTypes = supportedHdrTypes;
1439 mMaxLuminance = maxLuminance;
1440 mMaxAverageLuminance = maxAverageLuminance;
1441 mMinLuminance = minLuminance;
1442 }
1443
Ronghua Wuf173c322016-02-29 13:57:18 -08001444 /**
1445 * Gets the supported HDR types of this display.
1446 * Returns empty array if HDR is not supported by the display.
1447 */
1448 public @HdrType int[] getSupportedHdrTypes() {
1449 return mSupportedHdrTypes;
1450 }
1451 /**
1452 * Returns the desired content max luminance data in cd/m2 for this display.
1453 */
1454 public float getDesiredMaxLuminance() {
1455 return mMaxLuminance;
1456 }
1457 /**
1458 * Returns the desired content max frame-average luminance data in cd/m2 for this display.
1459 */
1460 public float getDesiredMaxAverageLuminance() {
1461 return mMaxAverageLuminance;
1462 }
1463 /**
1464 * Returns the desired content min luminance data in cd/m2 for this display.
1465 */
1466 public float getDesiredMinLuminance() {
1467 return mMinLuminance;
1468 }
1469
Michael Wright16ae0422016-07-26 18:18:53 +01001470 @Override
1471 public boolean equals(Object other) {
1472 if (this == other) {
1473 return true;
1474 }
1475
1476 if (!(other instanceof HdrCapabilities)) {
1477 return false;
1478 }
1479 HdrCapabilities that = (HdrCapabilities) other;
1480
1481 return Arrays.equals(mSupportedHdrTypes, that.mSupportedHdrTypes)
1482 && mMaxLuminance == that.mMaxLuminance
1483 && mMaxAverageLuminance == that.mMaxAverageLuminance
1484 && mMinLuminance == that.mMinLuminance;
1485 }
1486
1487 @Override
1488 public int hashCode() {
1489 int hash = 23;
1490 hash = hash * 17 + Arrays.hashCode(mSupportedHdrTypes);
1491 hash = hash * 17 + Float.floatToIntBits(mMaxLuminance);
1492 hash = hash * 17 + Float.floatToIntBits(mMaxAverageLuminance);
1493 hash = hash * 17 + Float.floatToIntBits(mMinLuminance);
1494 return hash;
1495 }
1496
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001497 public static final @android.annotation.NonNull Creator<HdrCapabilities> CREATOR = new Creator<HdrCapabilities>() {
Ronghua Wuf173c322016-02-29 13:57:18 -08001498 @Override
1499 public HdrCapabilities createFromParcel(Parcel source) {
1500 return new HdrCapabilities(source);
1501 }
1502
1503 @Override
1504 public HdrCapabilities[] newArray(int size) {
1505 return new HdrCapabilities[size];
1506 }
1507 };
1508
1509 private HdrCapabilities(Parcel source) {
1510 readFromParcel(source);
1511 }
1512
Hangyu Kuangda802f52016-04-06 18:02:17 -07001513 /**
1514 * @hide
1515 */
Ronghua Wuf173c322016-02-29 13:57:18 -08001516 public void readFromParcel(Parcel source) {
1517 int types = source.readInt();
1518 mSupportedHdrTypes = new int[types];
1519 for (int i = 0; i < types; ++i) {
1520 mSupportedHdrTypes[i] = source.readInt();
1521 }
1522 mMaxLuminance = source.readFloat();
1523 mMaxAverageLuminance = source.readFloat();
1524 mMinLuminance = source.readFloat();
1525 }
1526
1527 @Override
1528 public void writeToParcel(Parcel dest, int flags) {
1529 dest.writeInt(mSupportedHdrTypes.length);
1530 for (int i = 0; i < mSupportedHdrTypes.length; ++i) {
1531 dest.writeInt(mSupportedHdrTypes[i]);
1532 }
1533 dest.writeFloat(mMaxLuminance);
1534 dest.writeFloat(mMaxAverageLuminance);
1535 dest.writeFloat(mMinLuminance);
1536 }
1537
1538 @Override
1539 public int describeContents() {
1540 return 0;
1541 }
1542 }
Jeff Brown037c33e2014-04-09 00:31:55 -07001543}