blob: e3a6bd7a694913f5e082992bbf95dba9270bb843 [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;
Mathew Inwooda570dee2018-08-17 14:56:00 +010024import android.annotation.UnsupportedAppUsage;
Adrian Roose99bc052017-11-20 17:55:31 +010025import android.app.KeyguardManager;
Craig Mautner48d0d182013-06-11 07:53:06 -070026import android.content.res.CompatibilityInfo;
Romain Guye89d0bb2017-06-20 12:23:42 -070027import android.content.res.Configuration;
Bryce Lee609bf652017-02-09 16:50:13 -080028import android.content.res.Resources;
Peiyong Lin277eaff2019-01-16 16:18:22 -080029import android.graphics.ColorSpace;
Jeff Brownfa25bf52012-07-23 19:26:30 -070030import android.graphics.PixelFormat;
Dianne Hackbornac8dea12011-04-20 18:18:51 -070031import android.graphics.Point;
32import android.graphics.Rect;
Andrii Kulian732a90a2017-08-17 17:21:20 -070033import android.hardware.display.DisplayManager;
Jeff Brownbd6e1502012-08-28 03:27:37 -070034import android.hardware.display.DisplayManagerGlobal;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -070035import android.os.Parcel;
36import android.os.Parcelable;
Jeff Browna506a6e2013-06-04 00:02:38 -070037import android.os.Process;
Dianne Hackbornac8dea12011-04-20 18:18:51 -070038import android.os.SystemClock;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.util.DisplayMetrics;
Jeff Brownfa25bf52012-07-23 19:26:30 -070040import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
Ronghua Wuf173c322016-02-29 13:57:18 -080042import java.lang.annotation.Retention;
43import java.lang.annotation.RetentionPolicy;
Michael Wright3f145a22014-07-22 19:46:03 -070044import java.util.Arrays;
45
Jeff Brownbc68a592011-07-25 12:58:12 -070046/**
Jeff Brownfa25bf52012-07-23 19:26:30 -070047 * Provides information about the size and density of a logical display.
48 * <p>
49 * The display area is described in two different ways.
50 * <ul>
51 * <li>The application display area specifies the part of the display that may contain
52 * an application window, excluding the system decorations. The application display area may
53 * be smaller than the real display area because the system subtracts the space needed
54 * for decor elements such as the status bar. Use the following methods to query the
55 * application display area: {@link #getSize}, {@link #getRectSize} and {@link #getMetrics}.</li>
56 * <li>The real display area specifies the part of the display that contains content
57 * including the system decorations. Even so, the real display area may be smaller than the
58 * physical size of the display if the window manager is emulating a smaller display
Andrii Kuliancd097992017-03-23 18:31:59 -070059 * using (adb shell wm size). Use the following methods to query the
Jeff Brownfa25bf52012-07-23 19:26:30 -070060 * real display area: {@link #getRealSize}, {@link #getRealMetrics}.</li>
61 * </ul>
62 * </p><p>
63 * A logical display does not necessarily represent a particular physical display device
64 * such as the built-in screen or an external monitor. The contents of a logical
65 * display may be presented on one or more physical displays according to the devices
66 * that are currently attached and whether mirroring has been enabled.
67 * </p>
Jeff Brownbc68a592011-07-25 12:58:12 -070068 */
Jeff Brownfa25bf52012-07-23 19:26:30 -070069public final class Display {
70 private static final String TAG = "Display";
Jeff Brownbd6e1502012-08-28 03:27:37 -070071 private static final boolean DEBUG = false;
Jeff Brownfa25bf52012-07-23 19:26:30 -070072
Jeff Brownbd6e1502012-08-28 03:27:37 -070073 private final DisplayManagerGlobal mGlobal;
Jeff Brownfa25bf52012-07-23 19:26:30 -070074 private final int mDisplayId;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070075 private final int mLayerStack;
Jeff Brown92130f62012-10-24 21:28:33 -070076 private final int mFlags;
77 private final int mType;
78 private final String mAddress;
Jeff Browna506a6e2013-06-04 00:02:38 -070079 private final int mOwnerUid;
80 private final String mOwnerPackageName;
Bryce Lee609bf652017-02-09 16:50:13 -080081 private final Resources mResources;
82 private DisplayAdjustments mDisplayAdjustments;
Jeff Brownbd6e1502012-08-28 03:27:37 -070083
Mathew Inwooda570dee2018-08-17 14:56:00 +010084 @UnsupportedAppUsage
Jeff Brownbd6e1502012-08-28 03:27:37 -070085 private DisplayInfo mDisplayInfo; // never null
86 private boolean mIsValid;
Jeff Brownfa25bf52012-07-23 19:26:30 -070087
88 // Temporary display metrics structure used for compatibility mode.
89 private final DisplayMetrics mTempMetrics = new DisplayMetrics();
90
91 // We cache the app width and height properties briefly between calls
92 // to getHeight() and getWidth() to ensure that applications perceive
93 // consistent results when the size changes (most of the time).
94 // Applications should now be using getSize() instead.
95 private static final int CACHED_APP_SIZE_DURATION_MILLIS = 20;
96 private long mLastCachedAppSizeUpdate;
97 private int mCachedAppWidthCompat;
98 private int mCachedAppHeightCompat;
Dianne Hackborn5fd21692011-06-07 14:09:47 -070099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 /**
Jeff Brown98365d72012-08-19 20:30:52 -0700101 * The default Display id, which is the id of the built-in primary display
102 * assuming there is one.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 */
104 public static final int DEFAULT_DISPLAY = 0;
105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 /**
Wale Ogunwale26698512015-06-05 16:55:33 -0700107 * Invalid display id.
108 */
109 public static final int INVALID_DISPLAY = -1;
110
111 /**
Jeff Brown77aebfd2012-10-01 21:07:03 -0700112 * Display flag: Indicates that the display supports compositing content
113 * that is stored in protected graphics buffers.
Jeff Brownc5df37c2012-09-13 11:45:07 -0700114 * <p>
Jeff Brownf0681b32012-10-23 17:35:57 -0700115 * If this flag is set then the display device supports compositing protected buffers.
116 * </p><p>
117 * If this flag is not set then the display device may not support compositing
118 * protected buffers; the user may see a blank region on the screen instead of
119 * the protected content.
120 * </p><p>
Jeff Brown77aebfd2012-10-01 21:07:03 -0700121 * Secure (DRM) video decoders may allocate protected graphics buffers to request that
122 * a hardware-protected path be provided between the video decoder and the external
123 * display sink. If a hardware-protected path is not available, then content stored
124 * in protected graphics buffers may not be composited.
Jeff Brownc5df37c2012-09-13 11:45:07 -0700125 * </p><p>
Jeff Brownf0681b32012-10-23 17:35:57 -0700126 * An application can use the absence of this flag as a hint that it should not use protected
127 * buffers for this display because the content may not be visible. For example,
128 * if the flag is not set then the application may choose not to show content on this
129 * display, show an informative error message, select an alternate content stream
130 * or adopt a different strategy for decoding content that does not rely on
131 * protected buffers.
Jeff Brownc5df37c2012-09-13 11:45:07 -0700132 * </p>
Jeff Brownf0681b32012-10-23 17:35:57 -0700133 *
134 * @see #getFlags
Jeff Brownc5df37c2012-09-13 11:45:07 -0700135 */
Jeff Brown77aebfd2012-10-01 21:07:03 -0700136 public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 0;
Jeff Brownc5df37c2012-09-13 11:45:07 -0700137
138 /**
Jeff Brownf0681b32012-10-23 17:35:57 -0700139 * Display flag: Indicates that the display has a secure video output and
140 * supports compositing secure surfaces.
141 * <p>
142 * If this flag is set then the display device has a secure video output
143 * and is capable of showing secure surfaces. It may also be capable of
144 * showing {@link #FLAG_SUPPORTS_PROTECTED_BUFFERS protected buffers}.
145 * </p><p>
146 * If this flag is not set then the display device may not have a secure video
147 * output; the user may see a blank region on the screen instead of
148 * the contents of secure surfaces or protected buffers.
149 * </p><p>
150 * Secure surfaces are used to prevent content rendered into those surfaces
151 * by applications from appearing in screenshots or from being viewed
152 * on non-secure displays. Protected buffers are used by secure video decoders
153 * for a similar purpose.
154 * </p><p>
155 * An application creates a window with a secure surface by specifying the
156 * {@link WindowManager.LayoutParams#FLAG_SECURE} window flag.
157 * Likewise, an application creates a {@link SurfaceView} with a secure surface
158 * by calling {@link SurfaceView#setSecure} before attaching the secure view to
159 * its containing window.
160 * </p><p>
161 * An application can use the absence of this flag as a hint that it should not create
162 * secure surfaces or protected buffers on this display because the content may
163 * not be visible. For example, if the flag is not set then the application may
164 * choose not to show content on this display, show an informative error message,
165 * select an alternate content stream or adopt a different strategy for decoding
166 * content that does not rely on secure surfaces or protected buffers.
167 * </p>
168 *
169 * @see #getFlags
170 */
171 public static final int FLAG_SECURE = 1 << 1;
172
173 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700174 * Display flag: Indicates that the display is private. Only the application that
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800175 * owns the display and apps that are already on the display can create windows on it.
Jeff Browna506a6e2013-06-04 00:02:38 -0700176 *
177 * @see #getFlags
178 */
179 public static final int FLAG_PRIVATE = 1 << 2;
180
181 /**
Jeff Brown7d00aff2013-08-02 19:03:49 -0700182 * Display flag: Indicates that the display is a presentation display.
183 * <p>
184 * This flag identifies secondary displays that are suitable for
185 * use as presentation displays such as HDMI or Wireless displays. Applications
186 * may automatically project their content to presentation displays to provide
187 * richer second screen experiences.
188 * </p>
189 *
190 * @see #getFlags
191 */
192 public static final int FLAG_PRESENTATION = 1 << 3;
193
194 /**
Adam Powell49e7ff92015-05-14 16:18:53 -0700195 * Display flag: Indicates that the display has a round shape.
196 * <p>
197 * This flag identifies displays that are circular, elliptical or otherwise
198 * do not permit the user to see all the way to the logical corners of the display.
199 * </p>
200 *
201 * @see #getFlags
202 */
203 public static final int FLAG_ROUND = 1 << 4;
204
205 /**
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800206 * Display flag: Indicates that the display can show its content when non-secure keyguard is
207 * shown.
208 * <p>
Andrii Kulian732a90a2017-08-17 17:21:20 -0700209 * This flag identifies secondary displays that will continue showing content if keyguard can be
210 * dismissed without entering credentials.
211 * </p><p>
212 * An example of usage is a virtual display which content is displayed on external hardware
213 * display that is not visible to the system directly.
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800214 * </p>
215 *
Andrii Kulian732a90a2017-08-17 17:21:20 -0700216 * @see DisplayManager#VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD
Adrian Roose99bc052017-11-20 17:55:31 +0100217 * @see KeyguardManager#isDeviceSecure()
218 * @see KeyguardManager#isDeviceLocked()
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800219 * @see #getFlags
Andrii Kulian22512e82017-04-13 11:34:43 -0700220 * @hide
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800221 */
Chilun8753ad32018-10-09 15:56:45 +0800222 // TODO (b/114338689): Remove the flag and use IWindowManager#shouldShowWithInsecureKeyguard
Andrii Kulian7211d2e2017-01-27 15:58:05 -0800223 public static final int FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 5;
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800224
225 /**
Louis Changbd48dca2018-08-29 17:44:34 +0800226 * Display flag: Indicates that the display should show system decorations.
227 * <p>
228 * This flag identifies secondary displays that should show system decorations, such as status
229 * bar, navigation bar, home activity or IME.
230 * </p>
231 *
232 * @see #supportsSystemDecorations
233 * @hide
234 */
Chilun8753ad32018-10-09 15:56:45 +0800235 // TODO (b/114338689): Remove the flag and use IWindowManager#setShouldShowSystemDecors
Louis Changbd48dca2018-08-29 17:44:34 +0800236 public static final int FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS = 1 << 6;
237
238 /**
Jeff Brownd46747a2015-04-15 19:02:36 -0700239 * Display flag: Indicates that the contents of the display should not be scaled
240 * to fit the physical screen dimensions. Used for development only to emulate
241 * devices with smaller physicals screens while preserving density.
242 *
243 * @hide
244 */
245 public static final int FLAG_SCALING_DISABLED = 1 << 30;
246
247 /**
Jeff Brown92130f62012-10-24 21:28:33 -0700248 * Display type: Unknown display type.
249 * @hide
250 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100251 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700252 public static final int TYPE_UNKNOWN = 0;
253
254 /**
255 * Display type: Built-in display.
256 * @hide
257 */
258 public static final int TYPE_BUILT_IN = 1;
259
260 /**
261 * Display type: HDMI display.
262 * @hide
263 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100264 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700265 public static final int TYPE_HDMI = 2;
266
267 /**
268 * Display type: WiFi display.
269 * @hide
270 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100271 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700272 public static final int TYPE_WIFI = 3;
273
274 /**
275 * Display type: Overlay display.
276 * @hide
277 */
278 public static final int TYPE_OVERLAY = 4;
279
280 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700281 * Display type: Virtual display.
282 * @hide
283 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100284 @UnsupportedAppUsage
Jeff Browna506a6e2013-06-04 00:02:38 -0700285 public static final int TYPE_VIRTUAL = 5;
286
287 /**
Jeff Brown037c33e2014-04-09 00:31:55 -0700288 * Display state: The display state is unknown.
289 *
290 * @see #getState
291 */
Bookatz1a1b0462018-01-12 11:47:03 -0800292 public static final int STATE_UNKNOWN = ViewProtoEnums.DISPLAY_STATE_UNKNOWN; // 0
Jeff Brown037c33e2014-04-09 00:31:55 -0700293
294 /**
295 * Display state: The display is off.
296 *
297 * @see #getState
298 */
Bookatz1a1b0462018-01-12 11:47:03 -0800299 public static final int STATE_OFF = ViewProtoEnums.DISPLAY_STATE_OFF; // 1
Jeff Brown037c33e2014-04-09 00:31:55 -0700300
301 /**
302 * Display state: The display is on.
303 *
304 * @see #getState
305 */
Bookatz1a1b0462018-01-12 11:47:03 -0800306 public static final int STATE_ON = ViewProtoEnums.DISPLAY_STATE_ON; // 2
Jeff Brown037c33e2014-04-09 00:31:55 -0700307
308 /**
Jeff Brown5dc21912014-07-17 18:50:18 -0700309 * Display state: The display is dozing in a low power state; it is still
310 * on but is optimized for showing system-provided content while the
311 * device is non-interactive.
Jeff Brown037c33e2014-04-09 00:31:55 -0700312 *
313 * @see #getState
314 * @see android.os.PowerManager#isInteractive
315 */
Bookatz1a1b0462018-01-12 11:47:03 -0800316 public static final int STATE_DOZE = ViewProtoEnums.DISPLAY_STATE_DOZE; // 3
Jeff Brown5dc21912014-07-17 18:50:18 -0700317
318 /**
319 * Display state: The display is dozing in a suspended low power state; it is still
Chris Phoenix10a4a642017-09-25 13:21:00 -0700320 * on but the CPU is not updating it. This may be used in one of two ways: to show
321 * static system-provided content while the device is non-interactive, or to allow
322 * a "Sidekick" compute resource to update the display. For this reason, the
323 * CPU must not control the display in this mode.
Jeff Brown5dc21912014-07-17 18:50:18 -0700324 *
325 * @see #getState
326 * @see android.os.PowerManager#isInteractive
327 */
Bookatz1a1b0462018-01-12 11:47:03 -0800328 public static final int STATE_DOZE_SUSPEND = ViewProtoEnums.DISPLAY_STATE_DOZE_SUSPEND; // 4
Jeff Brown037c33e2014-04-09 00:31:55 -0700329
Santos Cordon3107d292016-09-20 15:50:35 -0700330 /**
331 * Display state: The display is on and optimized for VR mode.
332 *
333 * @see #getState
334 * @see android.os.PowerManager#isInteractive
Santos Cordon3107d292016-09-20 15:50:35 -0700335 */
Bookatz1a1b0462018-01-12 11:47:03 -0800336 public static final int STATE_VR = ViewProtoEnums.DISPLAY_STATE_VR; // 5
Santos Cordon3107d292016-09-20 15:50:35 -0700337
Chris Phoenix10a4a642017-09-25 13:21:00 -0700338 /**
339 * Display state: The display is in a suspended full power state; it is still
340 * on but the CPU is not updating it. This may be used in one of two ways: to show
341 * static system-provided content while the device is non-interactive, or to allow
342 * a "Sidekick" compute resource to update the display. For this reason, the
343 * CPU must not control the display in this mode.
344 *
345 * @see #getState
346 * @see android.os.PowerManager#isInteractive
347 */
Bookatz1a1b0462018-01-12 11:47:03 -0800348 public static final int STATE_ON_SUSPEND = ViewProtoEnums.DISPLAY_STATE_ON_SUSPEND; // 6
Chris Phoenix10a4a642017-09-25 13:21:00 -0700349
Michael Wright1c9977b2016-07-12 13:30:10 -0700350 /* The color mode constants defined below must be kept in sync with the ones in
Romain Guy6d228c22017-01-20 18:41:06 -0800351 * system/core/include/system/graphics-base.h */
Michael Wright1c9977b2016-07-12 13:30:10 -0700352
353 /**
354 * Display color mode: The current color mode is unknown or invalid.
355 * @hide
356 */
357 public static final int COLOR_MODE_INVALID = -1;
358
359 /**
360 * Display color mode: The default or native gamut of the display.
361 * @hide
362 */
363 public static final int COLOR_MODE_DEFAULT = 0;
364
Romain Guy6d228c22017-01-20 18:41:06 -0800365 /** @hide */
366 public static final int COLOR_MODE_BT601_625 = 1;
367 /** @hide */
368 public static final int COLOR_MODE_BT601_625_UNADJUSTED = 2;
369 /** @hide */
370 public static final int COLOR_MODE_BT601_525 = 3;
371 /** @hide */
372 public static final int COLOR_MODE_BT601_525_UNADJUSTED = 4;
373 /** @hide */
374 public static final int COLOR_MODE_BT709 = 5;
375 /** @hide */
376 public static final int COLOR_MODE_DCI_P3 = 6;
377 /** @hide */
Michael Wright1c9977b2016-07-12 13:30:10 -0700378 public static final int COLOR_MODE_SRGB = 7;
Romain Guy6d228c22017-01-20 18:41:06 -0800379 /** @hide */
380 public static final int COLOR_MODE_ADOBE_RGB = 8;
381 /** @hide */
382 public static final int COLOR_MODE_DISPLAY_P3 = 9;
Michael Wright1c9977b2016-07-12 13:30:10 -0700383
Jeff Brown037c33e2014-04-09 00:31:55 -0700384 /**
Andrii Kulian250d6532017-02-08 23:30:45 -0800385 * Indicates that when display is removed, all its activities will be moved to the primary
386 * display and the topmost activity should become focused.
387 *
388 * @hide
389 */
Chilun8753ad32018-10-09 15:56:45 +0800390 // TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_MOVE_TO_PRIMARY
Andrii Kulian250d6532017-02-08 23:30:45 -0800391 public static final int REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY = 0;
392 /**
393 * Indicates that when display is removed, all its stacks and tasks will be removed, all
394 * activities will be destroyed according to the usual lifecycle.
395 *
396 * @hide
397 */
Chilun8753ad32018-10-09 15:56:45 +0800398 // TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_DESTROY
Andrii Kulian250d6532017-02-08 23:30:45 -0800399 public static final int REMOVE_MODE_DESTROY_CONTENT = 1;
400
401 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700402 * Internal method to create a display.
Bryce Lee609bf652017-02-09 16:50:13 -0800403 * The display created with this method will have a static {@link DisplayAdjustments} applied.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700404 * Applications should use {@link android.view.WindowManager#getDefaultDisplay()}
Jeff Brown98365d72012-08-19 20:30:52 -0700405 * or {@link android.hardware.display.DisplayManager#getDisplay}
406 * to get a display object.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700407 *
408 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 */
Bryce Lee609bf652017-02-09 16:50:13 -0800410 public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
Craig Mautner48d0d182013-06-11 07:53:06 -0700411 DisplayAdjustments daj) {
Bryce Lee609bf652017-02-09 16:50:13 -0800412 this(global, displayId, displayInfo, daj, null /*res*/);
413 }
414
415 /**
416 * Internal method to create a display.
417 * The display created with this method will be adjusted based on the adjustments in the
418 * supplied {@link Resources}.
419 *
420 * @hide
421 */
422 public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
423 Resources res) {
424 this(global, displayId, displayInfo, null /*daj*/, res);
425 }
426
427 private Display(DisplayManagerGlobal global, int displayId,
428 /*@NotNull*/ DisplayInfo displayInfo, DisplayAdjustments daj, Resources res) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700429 mGlobal = global;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700430 mDisplayId = displayId;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700431 mDisplayInfo = displayInfo;
Bryce Lee609bf652017-02-09 16:50:13 -0800432 mResources = res;
433 mDisplayAdjustments = mResources != null
434 ? new DisplayAdjustments(mResources.getConfiguration())
435 : daj != null ? new DisplayAdjustments(daj) : null;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700436 mIsValid = true;
Jeff Brown92130f62012-10-24 21:28:33 -0700437
438 // Cache properties that cannot change as long as the display is valid.
439 mLayerStack = displayInfo.layerStack;
440 mFlags = displayInfo.flags;
441 mType = displayInfo.type;
442 mAddress = displayInfo.address;
Jeff Browna506a6e2013-06-04 00:02:38 -0700443 mOwnerUid = displayInfo.ownerUid;
444 mOwnerPackageName = displayInfo.ownerPackageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 }
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700448 * Gets the display id.
449 * <p>
450 * Each logical display has a unique id.
451 * The default display has id {@link #DEFAULT_DISPLAY}.
452 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 */
454 public int getDisplayId() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700455 return mDisplayId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 }
457
458 /**
Garfield Tan891146c2018-10-09 12:14:00 -0700459 * Gets the display unique id.
460 * <p>
461 * Unique id is different from display id because physical displays have stable unique id across
462 * reboots.
463 *
464 * @see com.android.service.display.DisplayDevice#hasStableUniqueId().
465 * @hide
466 */
467 public String getUniqueId() {
468 return mDisplayInfo.uniqueId;
469 }
470
471 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700472 * Returns true if this display is still valid, false if the display has been removed.
473 *
474 * If the display is invalid, then the methods of this class will
475 * continue to report the most recently observed display information.
476 * However, it is unwise (and rather fruitless) to continue using a
477 * {@link Display} object after the display's demise.
478 *
479 * It's possible for a display that was previously invalid to become
480 * valid again if a display with the same id is reconnected.
481 *
482 * @return True if the display is still valid.
483 */
484 public boolean isValid() {
485 synchronized (this) {
486 updateDisplayInfoLocked();
487 return mIsValid;
488 }
489 }
490
491 /**
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700492 * Gets a full copy of the display information.
493 *
494 * @param outDisplayInfo The object to receive the copy of the display information.
Jeff Brownbd6e1502012-08-28 03:27:37 -0700495 * @return True if the display is still valid.
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700496 * @hide
497 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100498 @UnsupportedAppUsage
Jeff Brownbd6e1502012-08-28 03:27:37 -0700499 public boolean getDisplayInfo(DisplayInfo outDisplayInfo) {
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700500 synchronized (this) {
501 updateDisplayInfoLocked();
502 outDisplayInfo.copyFrom(mDisplayInfo);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700503 return mIsValid;
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700504 }
505 }
506
507 /**
Jeff Brown98365d72012-08-19 20:30:52 -0700508 * Gets the display's layer stack.
509 *
510 * Each display has its own independent layer stack upon which surfaces
511 * are placed to be managed by surface flinger.
512 *
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700513 * @return The display's layer stack number.
Jeff Brown98365d72012-08-19 20:30:52 -0700514 * @hide
515 */
516 public int getLayerStack() {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700517 return mLayerStack;
Jeff Brown98365d72012-08-19 20:30:52 -0700518 }
519
520 /**
Jeff Brownc5df37c2012-09-13 11:45:07 -0700521 * Returns a combination of flags that describe the capabilities of the display.
522 *
523 * @return The display flags.
524 *
Jeff Brown77aebfd2012-10-01 21:07:03 -0700525 * @see #FLAG_SUPPORTS_PROTECTED_BUFFERS
Jeff Brownf0681b32012-10-23 17:35:57 -0700526 * @see #FLAG_SECURE
Jeff Browna506a6e2013-06-04 00:02:38 -0700527 * @see #FLAG_PRIVATE
Jeff Brownc5df37c2012-09-13 11:45:07 -0700528 */
529 public int getFlags() {
Jeff Brown92130f62012-10-24 21:28:33 -0700530 return mFlags;
531 }
532
533 /**
534 * Gets the display type.
535 *
536 * @return The display type.
537 *
538 * @see #TYPE_UNKNOWN
539 * @see #TYPE_BUILT_IN
540 * @see #TYPE_HDMI
541 * @see #TYPE_WIFI
542 * @see #TYPE_OVERLAY
Jeff Browna506a6e2013-06-04 00:02:38 -0700543 * @see #TYPE_VIRTUAL
Jeff Brown92130f62012-10-24 21:28:33 -0700544 * @hide
545 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100546 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700547 public int getType() {
548 return mType;
549 }
550
551 /**
552 * Gets the display address, or null if none.
553 * Interpretation varies by display type.
554 *
555 * @return The display address.
556 * @hide
557 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100558 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700559 public String getAddress() {
560 return mAddress;
Jeff Brownc5df37c2012-09-13 11:45:07 -0700561 }
562
563 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700564 * Gets the UID of the application that owns this display, or zero if it is
565 * owned by the system.
566 * <p>
567 * If the display is private, then only the owner can use it.
568 * </p>
569 *
570 * @hide
571 */
572 public int getOwnerUid() {
573 return mOwnerUid;
574 }
575
576 /**
577 * Gets the package name of the application that owns this display, or null if it is
578 * owned by the system.
579 * <p>
580 * If the display is private, then only the owner can use it.
581 * </p>
582 *
583 * @hide
584 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100585 @UnsupportedAppUsage
Jeff Browna506a6e2013-06-04 00:02:38 -0700586 public String getOwnerPackageName() {
587 return mOwnerPackageName;
588 }
589
590 /**
Jeff Brown98365d72012-08-19 20:30:52 -0700591 * Gets the compatibility info used by this display instance.
592 *
Craig Mautner48d0d182013-06-11 07:53:06 -0700593 * @return The display adjustments holder, or null if none is required.
Jeff Brown98365d72012-08-19 20:30:52 -0700594 * @hide
595 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100596 @UnsupportedAppUsage
Craig Mautner48d0d182013-06-11 07:53:06 -0700597 public DisplayAdjustments getDisplayAdjustments() {
Bryce Lee609bf652017-02-09 16:50:13 -0800598 if (mResources != null) {
599 final DisplayAdjustments currentAdjustements = mResources.getDisplayAdjustments();
600 if (!mDisplayAdjustments.equals(currentAdjustements)) {
601 mDisplayAdjustments = new DisplayAdjustments(currentAdjustements);
602 }
603 }
604
Craig Mautner48d0d182013-06-11 07:53:06 -0700605 return mDisplayAdjustments;
Jeff Brown98365d72012-08-19 20:30:52 -0700606 }
607
608 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700609 * Gets the name of the display.
Jeff Brown92130f62012-10-24 21:28:33 -0700610 * <p>
611 * Note that some displays may be renamed by the user.
612 * </p>
613 *
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700614 * @return The display's name.
615 */
616 public String getName() {
Jeff Brown92130f62012-10-24 21:28:33 -0700617 synchronized (this) {
618 updateDisplayInfoLocked();
619 return mDisplayInfo.name;
620 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700621 }
622
623 /**
Jeff Brownbc68a592011-07-25 12:58:12 -0700624 * Gets the size of the display, in pixels.
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700625 * Value returned by this method does not necessarily represent the actual raw size
626 * (native resolution) of the display.
Jeff Brownbc68a592011-07-25 12:58:12 -0700627 * <p>
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700628 * 1. The returned size may be adjusted to exclude certain system decor elements
629 * that are always visible.
Jeff Brownbc68a592011-07-25 12:58:12 -0700630 * </p><p>
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700631 * 2. It may be scaled to provide compatibility with older applications that
Jeff Brownbc68a592011-07-25 12:58:12 -0700632 * were originally designed for smaller displays.
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700633 * </p><p>
634 * 3. It can be different depending on the WindowManager to which the display belongs.
635 * </p><p>
636 * - If requested from non-Activity context (e.g. Application context via
637 * {@code (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)})
638 * it will report the size of the entire display based on current rotation and with subtracted
639 * system decoration areas.
640 * </p><p>
641 * - If requested from activity (either using {@code getWindowManager()} or
642 * {@code (WindowManager) getSystemService(Context.WINDOW_SERVICE)}) resulting size will
643 * correspond to current app window size. In this case it can be smaller than physical size in
644 * multi-window mode.
645 * </p><p>
646 * Typically for the purposes of layout apps should make a request from activity context
647 * to obtain size available for the app content.
Jeff Brownbc68a592011-07-25 12:58:12 -0700648 * </p>
649 *
650 * @param outSize A {@link Point} object to receive the size information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 */
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700652 public void getSize(Point outSize) {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700653 synchronized (this) {
654 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -0800655 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownfa25bf52012-07-23 19:26:30 -0700656 outSize.x = mTempMetrics.widthPixels;
657 outSize.y = mTempMetrics.heightPixels;
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700658 }
659 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 /**
Jeff Brownbc68a592011-07-25 12:58:12 -0700662 * Gets the size of the display as a rectangle, in pixels.
663 *
664 * @param outSize A {@link Rect} object to receive the size information.
665 * @see #getSize(Point)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 */
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700667 public void getRectSize(Rect outSize) {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700668 synchronized (this) {
669 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -0800670 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownfa25bf52012-07-23 19:26:30 -0700671 outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels);
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700672 }
673 }
674
675 /**
Dianne Hackborn68c33ca2012-04-19 14:51:25 -0700676 * Return the range of display sizes an application can expect to encounter
677 * under normal operation, as long as there is no physical change in screen
678 * size. This is basically the sizes you will see as the orientation
679 * changes, taking into account whatever screen decoration there is in
680 * each rotation. For example, the status bar is always at the top of the
681 * screen, so it will reduce the height both in landscape and portrait, and
682 * the smallest height returned here will be the smaller of the two.
683 *
684 * This is intended for applications to get an idea of the range of sizes
685 * they will encounter while going through device rotations, to provide a
686 * stable UI through rotation. The sizes here take into account all standard
687 * system decorations that reduce the size actually available to the
688 * application: the status bar, navigation bar, system bar, etc. It does
689 * <em>not</em> take into account more transient elements like an IME
690 * soft keyboard.
691 *
692 * @param outSmallestSize Filled in with the smallest width and height
693 * that the application will encounter, in pixels (not dp units). The x
694 * (width) dimension here directly corresponds to
695 * {@link android.content.res.Configuration#smallestScreenWidthDp
696 * Configuration.smallestScreenWidthDp}, except the value here is in raw
697 * screen pixels rather than dp units. Your application may of course
698 * still get smaller space yet if, for example, a soft keyboard is
699 * being displayed.
700 * @param outLargestSize Filled in with the largest width and height
701 * that the application will encounter, in pixels (not dp units). Your
702 * application may of course still get larger space than this if,
703 * for example, screen decorations like the status bar are being hidden.
704 */
705 public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700706 synchronized (this) {
707 updateDisplayInfoLocked();
708 outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth;
709 outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight;
710 outLargestSize.x = mDisplayInfo.largestNominalAppWidth;
711 outLargestSize.y = mDisplayInfo.largestNominalAppHeight;
Dianne Hackborn68c33ca2012-04-19 14:51:25 -0700712 }
713 }
714
715 /**
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700716 * Return the maximum screen size dimension that will happen. This is
717 * mostly for wallpapers.
718 * @hide
719 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100720 @UnsupportedAppUsage
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700721 public int getMaximumSizeDimension() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700722 synchronized (this) {
723 updateDisplayInfoLocked();
724 return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700725 }
726 }
727
728 /**
729 * @deprecated Use {@link #getSize(Point)} instead.
730 */
731 @Deprecated
732 public int getWidth() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700733 synchronized (this) {
734 updateCachedAppSizeIfNeededLocked();
735 return mCachedAppWidthCompat;
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700736 }
737 }
738
739 /**
740 * @deprecated Use {@link #getSize(Point)} instead.
741 */
742 @Deprecated
743 public int getHeight() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700744 synchronized (this) {
745 updateCachedAppSizeIfNeededLocked();
746 return mCachedAppHeightCompat;
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700747 }
748 }
749
Jeff Brownbc68a592011-07-25 12:58:12 -0700750 /**
Dianne Hackbornc652de82013-02-15 16:32:56 -0800751 * @hide
752 * Return a rectangle defining the insets of the overscan region of the display.
753 * Each field of the rectangle is the number of pixels the overscan area extends
754 * into the display on that side.
755 */
756 public void getOverscanInsets(Rect outRect) {
757 synchronized (this) {
758 updateDisplayInfoLocked();
759 outRect.set(mDisplayInfo.overscanLeft, mDisplayInfo.overscanTop,
760 mDisplayInfo.overscanRight, mDisplayInfo.overscanBottom);
761 }
762 }
763
764 /**
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800765 * Returns the rotation of the screen from its "natural" orientation.
766 * The returned value may be {@link Surface#ROTATION_0 Surface.ROTATION_0}
767 * (no rotation), {@link Surface#ROTATION_90 Surface.ROTATION_90},
768 * {@link Surface#ROTATION_180 Surface.ROTATION_180}, or
769 * {@link Surface#ROTATION_270 Surface.ROTATION_270}. For
770 * example, if a device has a naturally tall screen, and the user has
771 * turned it on its side to go into a landscape orientation, the value
772 * returned here may be either {@link Surface#ROTATION_90 Surface.ROTATION_90}
773 * or {@link Surface#ROTATION_270 Surface.ROTATION_270} depending on
774 * the direction it was turned. The angle is the rotation of the drawn
775 * graphics on the screen, which is the opposite direction of the physical
776 * rotation of the device. For example, if the device is rotated 90
777 * degrees counter-clockwise, to compensate rendering will be rotated by
778 * 90 degrees clockwise and thus the returned value here will be
779 * {@link Surface#ROTATION_90 Surface.ROTATION_90}.
780 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700781 @Surface.Rotation
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800782 public int getRotation() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700783 synchronized (this) {
784 updateDisplayInfoLocked();
785 return mDisplayInfo.rotation;
786 }
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800787 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700788
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800789 /**
Joe Onorato4c904a32010-02-26 12:35:55 -0800790 * @deprecated use {@link #getRotation}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 * @return orientation of this display.
792 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700793 @Deprecated
Tor Norbyed9273d62013-05-30 15:59:53 -0700794 @Surface.Rotation
Jeff Brownfa25bf52012-07-23 19:26:30 -0700795 public int getOrientation() {
796 return getRotation();
797 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798
Adrian Roosa4904792018-05-31 19:48:39 +0200799
800 /**
801 * Returns the {@link DisplayCutout}, or {@code null} if there is none.
802 *
803 * @see DisplayCutout
804 */
805 @Nullable
806 public DisplayCutout getCutout() {
807 synchronized (this) {
808 updateDisplayInfoLocked();
809 return mDisplayInfo.displayCutout;
810 }
811 }
812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700814 * Gets the pixel format of the display.
815 * @return One of the constants defined in {@link android.graphics.PixelFormat}.
816 *
817 * @deprecated This method is no longer supported.
818 * The result is always {@link PixelFormat#RGBA_8888}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700820 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 public int getPixelFormat() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700822 return PixelFormat.RGBA_8888;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700826 * Gets the refresh rate of this display in frames per second.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 */
828 public float getRefreshRate() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700829 synchronized (this) {
830 updateDisplayInfoLocked();
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700831 return mDisplayInfo.getMode().getRefreshRate();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700832 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835 /**
Michael Wright3f145a22014-07-22 19:46:03 -0700836 * Get the supported refresh rates of this display in frames per second.
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700837 * <p>
838 * This method only returns refresh rates for the display's default modes. For more options, use
839 * {@link #getSupportedModes()}.
840 *
841 * @deprecated use {@link #getSupportedModes()} instead
Michael Wright3f145a22014-07-22 19:46:03 -0700842 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700843 @Deprecated
Michael Wright3f145a22014-07-22 19:46:03 -0700844 public float[] getSupportedRefreshRates() {
845 synchronized (this) {
846 updateDisplayInfoLocked();
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700847 return mDisplayInfo.getDefaultRefreshRates();
848 }
849 }
850
851 /**
852 * Returns the active mode of the display.
853 */
854 public Mode getMode() {
855 synchronized (this) {
856 updateDisplayInfoLocked();
857 return mDisplayInfo.getMode();
858 }
859 }
860
861 /**
862 * Gets the supported modes of this display.
863 */
864 public Mode[] getSupportedModes() {
865 synchronized (this) {
866 updateDisplayInfoLocked();
867 final Display.Mode[] modes = mDisplayInfo.supportedModes;
868 return Arrays.copyOf(modes, modes.length);
Michael Wright3f145a22014-07-22 19:46:03 -0700869 }
870 }
871
872 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700873 * Request the display applies a color mode.
Michael Wright58e829f2015-09-15 00:13:26 +0100874 * @hide
875 */
Michael Wright1c9977b2016-07-12 13:30:10 -0700876 @RequiresPermission(CONFIGURE_DISPLAY_COLOR_MODE)
877 public void requestColorMode(int colorMode) {
878 mGlobal.requestColorMode(mDisplayId, colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +0100879 }
880
881 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700882 * Returns the active color mode of this display
Michael Wright58e829f2015-09-15 00:13:26 +0100883 * @hide
884 */
Michael Wright1c9977b2016-07-12 13:30:10 -0700885 public int getColorMode() {
Michael Wright58e829f2015-09-15 00:13:26 +0100886 synchronized (this) {
887 updateDisplayInfoLocked();
Michael Wright1c9977b2016-07-12 13:30:10 -0700888 return mDisplayInfo.colorMode;
Michael Wright58e829f2015-09-15 00:13:26 +0100889 }
890 }
891
892 /**
Andrii Kulian250d6532017-02-08 23:30:45 -0800893 * @hide
894 * Get current remove mode of the display - what actions should be performed with the display's
895 * content when it is removed. Default behavior for public displays in this case is to move all
896 * activities to the primary display and make it focused. For private display - destroy all
897 * activities.
898 *
899 * @see #REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY
900 * @see #REMOVE_MODE_DESTROY_CONTENT
901 */
Chilun8753ad32018-10-09 15:56:45 +0800902 // TODO (b/114338689): Remove the method and use IWindowManager#getRemoveContentMode
Andrii Kulian250d6532017-02-08 23:30:45 -0800903 public int getRemoveMode() {
904 return mDisplayInfo.removeMode;
905 }
906
907 /**
Louis Changbd48dca2018-08-29 17:44:34 +0800908 * Returns whether this display should support showing system decorations.
909 *
910 * @see #FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS
911 * @hide
912 */
Chilun8753ad32018-10-09 15:56:45 +0800913 // TODO (b/114338689): Remove the method and use IWindowManager#shouldShowSystemDecors
Louis Changbd48dca2018-08-29 17:44:34 +0800914 public boolean supportsSystemDecorations() {
915 return (mDisplayInfo.flags & FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0;
916 }
917
918 /**
Ronghua Wuf173c322016-02-29 13:57:18 -0800919 * Returns the display's HDR capabilities.
Romain Guy6d228c22017-01-20 18:41:06 -0800920 *
921 * @see #isHdr()
Ronghua Wuf173c322016-02-29 13:57:18 -0800922 */
923 public HdrCapabilities getHdrCapabilities() {
Michael Wright9ff94c02016-03-30 18:05:40 -0700924 synchronized (this) {
925 updateDisplayInfoLocked();
926 return mDisplayInfo.hdrCapabilities;
927 }
Ronghua Wuf173c322016-02-29 13:57:18 -0800928 }
929
930 /**
Romain Guy6d228c22017-01-20 18:41:06 -0800931 * Returns whether this display supports any HDR type.
932 *
933 * @see #getHdrCapabilities()
934 * @see HdrCapabilities#getSupportedHdrTypes()
935 */
936 public boolean isHdr() {
937 synchronized (this) {
938 updateDisplayInfoLocked();
Romain Guy408afbf2017-01-25 10:23:03 -0800939 return mDisplayInfo.isHdr();
Romain Guy6d228c22017-01-20 18:41:06 -0800940 }
941 }
942
943 /**
944 * Returns whether this display can be used to display wide color gamut content.
Romain Guye89d0bb2017-06-20 12:23:42 -0700945 * This does not necessarily mean the device itself can render wide color gamut
946 * content. To ensure wide color gamut content can be produced, refer to
947 * {@link Configuration#isScreenWideColorGamut()}.
Romain Guy6d228c22017-01-20 18:41:06 -0800948 */
949 public boolean isWideColorGamut() {
950 synchronized (this) {
951 updateDisplayInfoLocked();
Romain Guy408afbf2017-01-25 10:23:03 -0800952 return mDisplayInfo.isWideColorGamut();
Romain Guy6d228c22017-01-20 18:41:06 -0800953 }
954 }
955
956 /**
Peiyong Lin277eaff2019-01-16 16:18:22 -0800957 * Returns the preferred wide color space of the Display.
958 * The returned wide gamut color space is based on hardware capability and
959 * is preferred by the composition pipeline.
960 * Returns null if the display doesn't support wide color gamut.
961 * {@link Display#isWideColorGamut()}.
962 */
963 @Nullable
964 public ColorSpace getPreferredWideGamutColorSpace() {
965 synchronized (this) {
966 updateDisplayInfoLocked();
967 if (mDisplayInfo.isWideColorGamut()) {
968 return mGlobal.getPreferredWideGamutColorSpace();
969 }
970 return null;
971 }
972 }
973
974 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700975 * Gets the supported color modes of this device.
Michael Wright58e829f2015-09-15 00:13:26 +0100976 * @hide
977 */
Michael Wright1c9977b2016-07-12 13:30:10 -0700978 public int[] getSupportedColorModes() {
Michael Wright58e829f2015-09-15 00:13:26 +0100979 synchronized (this) {
980 updateDisplayInfoLocked();
Michael Wright1c9977b2016-07-12 13:30:10 -0700981 int[] colorModes = mDisplayInfo.supportedColorModes;
982 return Arrays.copyOf(colorModes, colorModes.length);
Michael Wright58e829f2015-09-15 00:13:26 +0100983 }
984 }
985
986 /**
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700987 * Gets the app VSYNC offset, in nanoseconds. This is a positive value indicating
988 * the phase offset of the VSYNC events provided by Choreographer relative to the
989 * display refresh. For example, if Choreographer reports that the refresh occurred
990 * at time N, it actually occurred at (N - appVsyncOffset).
991 * <p>
992 * Apps generally do not need to be aware of this. It's only useful for fine-grained
993 * A/V synchronization.
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700994 */
995 public long getAppVsyncOffsetNanos() {
996 synchronized (this) {
997 updateDisplayInfoLocked();
998 return mDisplayInfo.appVsyncOffsetNanos;
999 }
1000 }
1001
1002 /**
1003 * This is how far in advance a buffer must be queued for presentation at
1004 * a given time. If you want a buffer to appear on the screen at
1005 * time N, you must submit the buffer before (N - presentationDeadline).
1006 * <p>
1007 * The desired presentation time for GLES rendering may be set with
1008 * {@link android.opengl.EGLExt#eglPresentationTimeANDROID}. For video decoding, use
1009 * {@link android.media.MediaCodec#releaseOutputBuffer(int, long)}. Times are
1010 * expressed in nanoseconds, using the system monotonic clock
1011 * ({@link System#nanoTime}).
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001012 */
1013 public long getPresentationDeadlineNanos() {
1014 synchronized (this) {
1015 updateDisplayInfoLocked();
1016 return mDisplayInfo.presentationDeadlineNanos;
1017 }
1018 }
1019
1020 /**
Jeff Brownbc68a592011-07-25 12:58:12 -07001021 * Gets display metrics that describe the size and density of this display.
Jeff Brownbc68a592011-07-25 12:58:12 -07001022 * The size returned by this method does not necessarily represent the
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001023 * actual raw size (native resolution) of the display.
1024 * <p>
1025 * 1. The returned size may be adjusted to exclude certain system decor elements
1026 * that are always visible.
1027 * </p><p>
1028 * 2. It may be scaled to provide compatibility with older applications that
Jeff Brownbc68a592011-07-25 12:58:12 -07001029 * were originally designed for smaller displays.
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001030 * </p><p>
1031 * 3. It can be different depending on the WindowManager to which the display belongs.
Andrii Kulian5f57a3d2016-06-28 18:41:42 -07001032 * </p><p>
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001033 * - If requested from non-Activity context (e.g. Application context via
1034 * {@code (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)})
Andrii Kulian5f57a3d2016-06-28 18:41:42 -07001035 * metrics will report the size of the entire display based on current rotation and with
1036 * subtracted system decoration areas.
1037 * </p><p>
1038 * - If requested from activity (either using {@code getWindowManager()} or
1039 * {@code (WindowManager) getSystemService(Context.WINDOW_SERVICE)}) resulting metrics will
1040 * correspond to current app window metrics. In this case the size can be smaller than physical
1041 * size in multi-window mode.
Jeff Brownbc68a592011-07-25 12:58:12 -07001042 * </p>
1043 *
1044 * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 */
1046 public void getMetrics(DisplayMetrics outMetrics) {
Jeff Brownfa25bf52012-07-23 19:26:30 -07001047 synchronized (this) {
1048 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -08001049 mDisplayInfo.getAppMetrics(outMetrics, getDisplayAdjustments());
Dianne Hackborn68066c22011-04-21 17:26:39 -07001050 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001051 }
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001052
Jeff Brownfa25bf52012-07-23 19:26:30 -07001053 /**
1054 * Gets the real size of the display without subtracting any window decor or
1055 * applying any compatibility scale factors.
1056 * <p>
1057 * The size is adjusted based on the current rotation of the display.
1058 * </p><p>
1059 * The real size may be smaller than the physical size of the screen when the
Andrii Kuliancd097992017-03-23 18:31:59 -07001060 * window manager is emulating a smaller display (using adb shell wm size).
Jeff Brownfa25bf52012-07-23 19:26:30 -07001061 * </p>
1062 *
1063 * @param outSize Set to the real size of the display.
1064 */
1065 public void getRealSize(Point outSize) {
1066 synchronized (this) {
1067 updateDisplayInfoLocked();
1068 outSize.x = mDisplayInfo.logicalWidth;
1069 outSize.y = mDisplayInfo.logicalHeight;
1070 }
Dianne Hackborn68066c22011-04-21 17:26:39 -07001071 }
1072
1073 /**
Jeff Brownbc68a592011-07-25 12:58:12 -07001074 * Gets display metrics based on the real size of this display.
Jeff Brownfa25bf52012-07-23 19:26:30 -07001075 * <p>
1076 * The size is adjusted based on the current rotation of the display.
1077 * </p><p>
1078 * The real size may be smaller than the physical size of the screen when the
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001079 * window manager is emulating a smaller display (using adb shell wm size).
Jeff Brownfa25bf52012-07-23 19:26:30 -07001080 * </p>
1081 *
1082 * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
Dianne Hackborn68066c22011-04-21 17:26:39 -07001083 */
1084 public void getRealMetrics(DisplayMetrics outMetrics) {
Jeff Brownfa25bf52012-07-23 19:26:30 -07001085 synchronized (this) {
1086 updateDisplayInfoLocked();
Craig Mautner48d0d182013-06-11 07:53:06 -07001087 mDisplayInfo.getLogicalMetrics(outMetrics,
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001088 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
Jeff Brownbc68a592011-07-25 12:58:12 -07001089 }
Dianne Hackborn68066c22011-04-21 17:26:39 -07001090 }
1091
Jeff Browna506a6e2013-06-04 00:02:38 -07001092 /**
Jeff Brown037c33e2014-04-09 00:31:55 -07001093 * Gets the state of the display, such as whether it is on or off.
1094 *
1095 * @return The state of the display: one of {@link #STATE_OFF}, {@link #STATE_ON},
Chris Phoenix10a4a642017-09-25 13:21:00 -07001096 * {@link #STATE_DOZE}, {@link #STATE_DOZE_SUSPEND}, {@link #STATE_ON_SUSPEND}, or
Santos Cordon3107d292016-09-20 15:50:35 -07001097 * {@link #STATE_UNKNOWN}.
Jeff Brown037c33e2014-04-09 00:31:55 -07001098 */
1099 public int getState() {
1100 synchronized (this) {
1101 updateDisplayInfoLocked();
1102 return mIsValid ? mDisplayInfo.state : STATE_UNKNOWN;
1103 }
1104 }
1105
1106 /**
Jeff Browna506a6e2013-06-04 00:02:38 -07001107 * Returns true if the specified UID has access to this display.
1108 * @hide
1109 */
1110 public boolean hasAccess(int uid) {
1111 return Display.hasAccess(uid, mFlags, mOwnerUid);
1112 }
1113
1114 /** @hide */
1115 public static boolean hasAccess(int uid, int flags, int ownerUid) {
1116 return (flags & Display.FLAG_PRIVATE) == 0
1117 || uid == ownerUid
1118 || uid == Process.SYSTEM_UID
1119 || uid == 0;
1120 }
1121
Jeff Brown69b07162013-11-07 00:30:16 -08001122 /**
1123 * Returns true if the display is a public presentation display.
1124 * @hide
1125 */
1126 public boolean isPublicPresentation() {
1127 return (mFlags & (Display.FLAG_PRIVATE | Display.FLAG_PRESENTATION)) ==
1128 Display.FLAG_PRESENTATION;
1129 }
1130
Jeff Brownfa25bf52012-07-23 19:26:30 -07001131 private void updateDisplayInfoLocked() {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001132 // Note: The display manager caches display info objects on our behalf.
1133 DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId);
1134 if (newInfo == null) {
1135 // Preserve the old mDisplayInfo after the display is removed.
1136 if (mIsValid) {
1137 mIsValid = false;
1138 if (DEBUG) {
1139 Log.d(TAG, "Logical display " + mDisplayId + " was removed.");
1140 }
1141 }
1142 } else {
1143 // Use the new display info. (It might be the same object if nothing changed.)
1144 mDisplayInfo = newInfo;
1145 if (!mIsValid) {
1146 mIsValid = true;
1147 if (DEBUG) {
1148 Log.d(TAG, "Logical display " + mDisplayId + " was recreated.");
1149 }
1150 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001151 }
Jeff Brownbc68a592011-07-25 12:58:12 -07001152 }
1153
Jeff Brownfa25bf52012-07-23 19:26:30 -07001154 private void updateCachedAppSizeIfNeededLocked() {
1155 long now = SystemClock.uptimeMillis();
1156 if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) {
1157 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -08001158 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownfa25bf52012-07-23 19:26:30 -07001159 mCachedAppWidthCompat = mTempMetrics.widthPixels;
1160 mCachedAppHeightCompat = mTempMetrics.heightPixels;
1161 mLastCachedAppSizeUpdate = now;
1162 }
Jeff Brownbc68a592011-07-25 12:58:12 -07001163 }
Jeff Brownbf5740e2012-08-19 23:20:02 -07001164
1165 // For debugging purposes
1166 @Override
1167 public String toString() {
1168 synchronized (this) {
1169 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -08001170 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownbf5740e2012-08-19 23:20:02 -07001171 return "Display id " + mDisplayId + ": " + mDisplayInfo
Jeff Brownbd6e1502012-08-28 03:27:37 -07001172 + ", " + mTempMetrics + ", isValid=" + mIsValid;
Jeff Brownbf5740e2012-08-19 23:20:02 -07001173 }
1174 }
Jeff Brown92130f62012-10-24 21:28:33 -07001175
1176 /**
1177 * @hide
1178 */
1179 public static String typeToString(int type) {
1180 switch (type) {
1181 case TYPE_UNKNOWN:
1182 return "UNKNOWN";
1183 case TYPE_BUILT_IN:
1184 return "BUILT_IN";
1185 case TYPE_HDMI:
1186 return "HDMI";
1187 case TYPE_WIFI:
1188 return "WIFI";
1189 case TYPE_OVERLAY:
1190 return "OVERLAY";
Jeff Browna506a6e2013-06-04 00:02:38 -07001191 case TYPE_VIRTUAL:
1192 return "VIRTUAL";
Jeff Brown92130f62012-10-24 21:28:33 -07001193 default:
1194 return Integer.toString(type);
1195 }
1196 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197
Jeff Brown037c33e2014-04-09 00:31:55 -07001198 /**
1199 * @hide
1200 */
1201 public static String stateToString(int state) {
1202 switch (state) {
1203 case STATE_UNKNOWN:
1204 return "UNKNOWN";
1205 case STATE_OFF:
1206 return "OFF";
1207 case STATE_ON:
1208 return "ON";
Jeff Brown5dc21912014-07-17 18:50:18 -07001209 case STATE_DOZE:
1210 return "DOZE";
1211 case STATE_DOZE_SUSPEND:
1212 return "DOZE_SUSPEND";
Santos Cordon3107d292016-09-20 15:50:35 -07001213 case STATE_VR:
1214 return "VR";
Chris Phoenix10a4a642017-09-25 13:21:00 -07001215 case STATE_ON_SUSPEND:
1216 return "ON_SUSPEND";
Jeff Brown037c33e2014-04-09 00:31:55 -07001217 default:
1218 return Integer.toString(state);
1219 }
1220 }
Jeff Brown970d4132014-07-19 11:33:47 -07001221
1222 /**
1223 * Returns true if display updates may be suspended while in the specified
Chris Phoenix10a4a642017-09-25 13:21:00 -07001224 * display power state. In SUSPEND states, updates are absolutely forbidden.
Jeff Brown970d4132014-07-19 11:33:47 -07001225 * @hide
1226 */
1227 public static boolean isSuspendedState(int state) {
Chris Phoenix10a4a642017-09-25 13:21:00 -07001228 return state == STATE_OFF || state == STATE_DOZE_SUSPEND || state == STATE_ON_SUSPEND;
Jeff Brown970d4132014-07-19 11:33:47 -07001229 }
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001230
1231 /**
Michael Wright05e76fe2017-07-20 18:18:33 +01001232 * Returns true if the display may be in a reduced operating mode while in the
1233 * specified display power state.
1234 * @hide
1235 */
1236 public static boolean isDozeState(int state) {
1237 return state == STATE_DOZE || state == STATE_DOZE_SUSPEND;
1238 }
1239
1240 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001241 * A mode supported by a given display.
1242 *
1243 * @see Display#getSupportedModes()
1244 */
1245 public static final class Mode implements Parcelable {
1246 /**
1247 * @hide
1248 */
1249 public static final Mode[] EMPTY_ARRAY = new Mode[0];
1250
1251 private final int mModeId;
1252 private final int mWidth;
1253 private final int mHeight;
1254 private final float mRefreshRate;
1255
1256 /**
1257 * @hide
1258 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001259 @UnsupportedAppUsage
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001260 public Mode(int modeId, int width, int height, float refreshRate) {
1261 mModeId = modeId;
1262 mWidth = width;
1263 mHeight = height;
1264 mRefreshRate = refreshRate;
1265 }
1266
1267 /**
1268 * Returns this mode's id.
1269 */
1270 public int getModeId() {
1271 return mModeId;
1272 }
1273
1274 /**
1275 * Returns the physical width of the display in pixels when configured in this mode's
1276 * resolution.
1277 * <p>
1278 * Note that due to application UI scaling, the number of pixels made available to
1279 * applications when the mode is active (as reported by {@link Display#getWidth()} may
1280 * differ from the mode's actual resolution (as reported by this function).
1281 * <p>
1282 * For example, applications running on a 4K display may have their UI laid out and rendered
1283 * in 1080p and then scaled up. Applications can take advantage of the extra resolution by
1284 * rendering content through a {@link android.view.SurfaceView} using full size buffers.
1285 */
1286 public int getPhysicalWidth() {
1287 return mWidth;
1288 }
1289
1290 /**
1291 * Returns the physical height of the display in pixels when configured in this mode's
1292 * resolution.
1293 * <p>
1294 * Note that due to application UI scaling, the number of pixels made available to
1295 * applications when the mode is active (as reported by {@link Display#getHeight()} may
1296 * differ from the mode's actual resolution (as reported by this function).
1297 * <p>
1298 * For example, applications running on a 4K display may have their UI laid out and rendered
1299 * in 1080p and then scaled up. Applications can take advantage of the extra resolution by
1300 * rendering content through a {@link android.view.SurfaceView} using full size buffers.
1301 */
1302 public int getPhysicalHeight() {
1303 return mHeight;
1304 }
1305
1306 /**
1307 * Returns the refresh rate in frames per second.
1308 */
1309 public float getRefreshRate() {
1310 return mRefreshRate;
1311 }
1312
1313 /**
1314 * Returns {@code true} if this mode matches the given parameters.
1315 *
1316 * @hide
1317 */
1318 public boolean matches(int width, int height, float refreshRate) {
1319 return mWidth == width &&
1320 mHeight == height &&
1321 Float.floatToIntBits(mRefreshRate) == Float.floatToIntBits(refreshRate);
1322 }
1323
1324 @Override
1325 public boolean equals(Object other) {
1326 if (this == other) {
1327 return true;
1328 }
1329 if (!(other instanceof Mode)) {
1330 return false;
1331 }
1332 Mode that = (Mode) other;
1333 return mModeId == that.mModeId && matches(that.mWidth, that.mHeight, that.mRefreshRate);
1334 }
1335
1336 @Override
1337 public int hashCode() {
1338 int hash = 1;
1339 hash = hash * 17 + mModeId;
1340 hash = hash * 17 + mWidth;
1341 hash = hash * 17 + mHeight;
1342 hash = hash * 17 + Float.floatToIntBits(mRefreshRate);
1343 return hash;
1344 }
1345
1346 @Override
1347 public String toString() {
1348 return new StringBuilder("{")
1349 .append("id=").append(mModeId)
1350 .append(", width=").append(mWidth)
1351 .append(", height=").append(mHeight)
1352 .append(", fps=").append(mRefreshRate)
1353 .append("}")
1354 .toString();
1355 }
1356
1357 @Override
1358 public int describeContents() {
1359 return 0;
1360 }
1361
1362 private Mode(Parcel in) {
1363 this(in.readInt(), in.readInt(), in.readInt(), in.readFloat());
1364 }
1365
1366 @Override
1367 public void writeToParcel(Parcel out, int parcelableFlags) {
1368 out.writeInt(mModeId);
1369 out.writeInt(mWidth);
1370 out.writeInt(mHeight);
1371 out.writeFloat(mRefreshRate);
1372 }
1373
1374 @SuppressWarnings("hiding")
1375 public static final Parcelable.Creator<Mode> CREATOR
1376 = new Parcelable.Creator<Mode>() {
1377 @Override
1378 public Mode createFromParcel(Parcel in) {
1379 return new Mode(in);
1380 }
1381
1382 @Override
1383 public Mode[] newArray(int size) {
1384 return new Mode[size];
1385 }
1386 };
1387 }
Michael Wright58e829f2015-09-15 00:13:26 +01001388
1389 /**
Ronghua Wuf173c322016-02-29 13:57:18 -08001390 * Encapsulates the HDR capabilities of a given display.
1391 * For example, what HDR types it supports and details about the desired luminance data.
1392 * <p>You can get an instance for a given {@link Display} object with
1393 * {@link Display#getHdrCapabilities getHdrCapabilities()}.
Ronghua Wuf173c322016-02-29 13:57:18 -08001394 */
1395 public static final class HdrCapabilities implements Parcelable {
1396 /**
1397 * Invalid luminance value.
1398 */
1399 public static final float INVALID_LUMINANCE = -1;
1400 /**
1401 * Dolby Vision high dynamic range (HDR) display.
1402 */
1403 public static final int HDR_TYPE_DOLBY_VISION = 1;
1404 /**
1405 * HDR10 display.
1406 */
1407 public static final int HDR_TYPE_HDR10 = 2;
1408 /**
1409 * Hybrid Log-Gamma HDR display.
1410 */
1411 public static final int HDR_TYPE_HLG = 3;
1412
Peiyong Lin173ae082019-01-17 12:34:21 -08001413 /**
1414 * HDR10+ display.
1415 */
1416 public static final int HDR_TYPE_HDR10_PLUS = 4;
1417
Hangyu Kuangda802f52016-04-06 18:02:17 -07001418 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001419 @IntDef(prefix = { "HDR_TYPE_" }, value = {
1420 HDR_TYPE_DOLBY_VISION,
1421 HDR_TYPE_HDR10,
1422 HDR_TYPE_HLG,
Peiyong Lin173ae082019-01-17 12:34:21 -08001423 HDR_TYPE_HDR10_PLUS,
Ronghua Wuf173c322016-02-29 13:57:18 -08001424 })
1425 @Retention(RetentionPolicy.SOURCE)
1426 public @interface HdrType {}
1427
1428 private @HdrType int[] mSupportedHdrTypes = new int[0];
1429 private float mMaxLuminance = INVALID_LUMINANCE;
1430 private float mMaxAverageLuminance = INVALID_LUMINANCE;
1431 private float mMinLuminance = INVALID_LUMINANCE;
1432
Hangyu Kuangda802f52016-04-06 18:02:17 -07001433 /**
1434 * @hide
1435 */
Ronghua Wuf173c322016-02-29 13:57:18 -08001436 public HdrCapabilities() {
1437 }
1438
Hangyu Kuang1e7d1aa2016-05-17 14:21:01 -07001439 /**
1440 * @hide
1441 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001442 @UnsupportedAppUsage
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001443 public HdrCapabilities(int[] supportedHdrTypes, float maxLuminance,
1444 float maxAverageLuminance, float minLuminance) {
1445 mSupportedHdrTypes = supportedHdrTypes;
1446 mMaxLuminance = maxLuminance;
1447 mMaxAverageLuminance = maxAverageLuminance;
1448 mMinLuminance = minLuminance;
1449 }
1450
Ronghua Wuf173c322016-02-29 13:57:18 -08001451 /**
1452 * Gets the supported HDR types of this display.
1453 * Returns empty array if HDR is not supported by the display.
1454 */
1455 public @HdrType int[] getSupportedHdrTypes() {
1456 return mSupportedHdrTypes;
1457 }
1458 /**
1459 * Returns the desired content max luminance data in cd/m2 for this display.
1460 */
1461 public float getDesiredMaxLuminance() {
1462 return mMaxLuminance;
1463 }
1464 /**
1465 * Returns the desired content max frame-average luminance data in cd/m2 for this display.
1466 */
1467 public float getDesiredMaxAverageLuminance() {
1468 return mMaxAverageLuminance;
1469 }
1470 /**
1471 * Returns the desired content min luminance data in cd/m2 for this display.
1472 */
1473 public float getDesiredMinLuminance() {
1474 return mMinLuminance;
1475 }
1476
Michael Wright16ae0422016-07-26 18:18:53 +01001477 @Override
1478 public boolean equals(Object other) {
1479 if (this == other) {
1480 return true;
1481 }
1482
1483 if (!(other instanceof HdrCapabilities)) {
1484 return false;
1485 }
1486 HdrCapabilities that = (HdrCapabilities) other;
1487
1488 return Arrays.equals(mSupportedHdrTypes, that.mSupportedHdrTypes)
1489 && mMaxLuminance == that.mMaxLuminance
1490 && mMaxAverageLuminance == that.mMaxAverageLuminance
1491 && mMinLuminance == that.mMinLuminance;
1492 }
1493
1494 @Override
1495 public int hashCode() {
1496 int hash = 23;
1497 hash = hash * 17 + Arrays.hashCode(mSupportedHdrTypes);
1498 hash = hash * 17 + Float.floatToIntBits(mMaxLuminance);
1499 hash = hash * 17 + Float.floatToIntBits(mMaxAverageLuminance);
1500 hash = hash * 17 + Float.floatToIntBits(mMinLuminance);
1501 return hash;
1502 }
1503
Ronghua Wuf173c322016-02-29 13:57:18 -08001504 public static final Creator<HdrCapabilities> CREATOR = new Creator<HdrCapabilities>() {
1505 @Override
1506 public HdrCapabilities createFromParcel(Parcel source) {
1507 return new HdrCapabilities(source);
1508 }
1509
1510 @Override
1511 public HdrCapabilities[] newArray(int size) {
1512 return new HdrCapabilities[size];
1513 }
1514 };
1515
1516 private HdrCapabilities(Parcel source) {
1517 readFromParcel(source);
1518 }
1519
Hangyu Kuangda802f52016-04-06 18:02:17 -07001520 /**
1521 * @hide
1522 */
Ronghua Wuf173c322016-02-29 13:57:18 -08001523 public void readFromParcel(Parcel source) {
1524 int types = source.readInt();
1525 mSupportedHdrTypes = new int[types];
1526 for (int i = 0; i < types; ++i) {
1527 mSupportedHdrTypes[i] = source.readInt();
1528 }
1529 mMaxLuminance = source.readFloat();
1530 mMaxAverageLuminance = source.readFloat();
1531 mMinLuminance = source.readFloat();
1532 }
1533
1534 @Override
1535 public void writeToParcel(Parcel dest, int flags) {
1536 dest.writeInt(mSupportedHdrTypes.length);
1537 for (int i = 0; i < mSupportedHdrTypes.length; ++i) {
1538 dest.writeInt(mSupportedHdrTypes[i]);
1539 }
1540 dest.writeFloat(mMaxLuminance);
1541 dest.writeFloat(mMaxAverageLuminance);
1542 dest.writeFloat(mMinLuminance);
1543 }
1544
1545 @Override
1546 public int describeContents() {
1547 return 0;
1548 }
1549 }
Jeff Brown037c33e2014-04-09 00:31:55 -07001550}