blob: 0dcb9cc5256e8b2d432f7b6b883aff798575eb6d [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;
Ahan Wuc54169a2020-01-02 19:23:27 +080022import android.annotation.NonNull;
Adrian Roosa4904792018-05-31 19:48:39 +020023import android.annotation.Nullable;
Michael Wright58e829f2015-09-15 00:13:26 +010024import android.annotation.RequiresPermission;
Galia Peycheva056b3ee2019-06-26 14:05:12 +020025import android.annotation.SuppressLint;
lumarkec75b422019-01-07 15:58:38 +080026import android.annotation.TestApi;
Adrian Roose99bc052017-11-20 17:55:31 +010027import android.app.KeyguardManager;
Artur Satayevad9254c2019-12-10 17:47:54 +000028import android.compat.annotation.UnsupportedAppUsage;
Craig Mautner48d0d182013-06-11 07:53:06 -070029import android.content.res.CompatibilityInfo;
Romain Guye89d0bb2017-06-20 12:23:42 -070030import android.content.res.Configuration;
Bryce Lee609bf652017-02-09 16:50:13 -080031import android.content.res.Resources;
Peiyong Lin277eaff2019-01-16 16:18:22 -080032import android.graphics.ColorSpace;
Jeff Brownfa25bf52012-07-23 19:26:30 -070033import android.graphics.PixelFormat;
Dianne Hackbornac8dea12011-04-20 18:18:51 -070034import android.graphics.Point;
35import android.graphics.Rect;
Andrii Kulian732a90a2017-08-17 17:21:20 -070036import android.hardware.display.DisplayManager;
Jeff Brownbd6e1502012-08-28 03:27:37 -070037import android.hardware.display.DisplayManagerGlobal;
Sergey Vasilinets669ad672019-02-07 13:42:33 +000038import android.os.Build;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -070039import android.os.Parcel;
40import android.os.Parcelable;
Jeff Browna506a6e2013-06-04 00:02:38 -070041import android.os.Process;
Dianne Hackbornac8dea12011-04-20 18:18:51 -070042import android.os.SystemClock;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.util.DisplayMetrics;
Jeff Brownfa25bf52012-07-23 19:26:30 -070044import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
Ronghua Wuf173c322016-02-29 13:57:18 -080046import java.lang.annotation.Retention;
47import java.lang.annotation.RetentionPolicy;
Ahan Wu287d8282019-12-17 16:23:17 +080048import java.util.ArrayList;
Michael Wright3f145a22014-07-22 19:46:03 -070049import java.util.Arrays;
Ahan Wu287d8282019-12-17 16:23:17 +080050import java.util.List;
Michael Wright3f145a22014-07-22 19:46:03 -070051
Jeff Brownbc68a592011-07-25 12:58:12 -070052/**
Jeff Brownfa25bf52012-07-23 19:26:30 -070053 * Provides information about the size and density of a logical display.
54 * <p>
55 * The display area is described in two different ways.
56 * <ul>
57 * <li>The application display area specifies the part of the display that may contain
58 * an application window, excluding the system decorations. The application display area may
59 * be smaller than the real display area because the system subtracts the space needed
Andrii Kulian0271e572020-01-28 21:00:09 -080060 * for decor elements such as the status bar. Use {@link WindowMetrics#getSize()} to query the
61 * application window size.</li>
Jeff Brownfa25bf52012-07-23 19:26:30 -070062 * <li>The real display area specifies the part of the display that contains content
63 * including the system decorations. Even so, the real display area may be smaller than the
64 * physical size of the display if the window manager is emulating a smaller display
Andrii Kuliancd097992017-03-23 18:31:59 -070065 * using (adb shell wm size). Use the following methods to query the
Jeff Brownfa25bf52012-07-23 19:26:30 -070066 * real display area: {@link #getRealSize}, {@link #getRealMetrics}.</li>
67 * </ul>
68 * </p><p>
69 * A logical display does not necessarily represent a particular physical display device
Dominik Laskowski26290bb2020-01-15 16:09:55 -080070 * such as the internal display or an external display. The contents of a logical
Jeff Brownfa25bf52012-07-23 19:26:30 -070071 * display may be presented on one or more physical displays according to the devices
72 * that are currently attached and whether mirroring has been enabled.
73 * </p>
Jeff Brownbc68a592011-07-25 12:58:12 -070074 */
Jeff Brownfa25bf52012-07-23 19:26:30 -070075public final class Display {
76 private static final String TAG = "Display";
Jeff Brownbd6e1502012-08-28 03:27:37 -070077 private static final boolean DEBUG = false;
Jeff Brownfa25bf52012-07-23 19:26:30 -070078
Jeff Brownbd6e1502012-08-28 03:27:37 -070079 private final DisplayManagerGlobal mGlobal;
Jeff Brownfa25bf52012-07-23 19:26:30 -070080 private final int mDisplayId;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070081 private final int mLayerStack;
Jeff Brown92130f62012-10-24 21:28:33 -070082 private final int mFlags;
83 private final int mType;
Dominik Laskowskidb845962019-01-27 21:20:00 -080084 private final DisplayAddress mAddress;
Jeff Browna506a6e2013-06-04 00:02:38 -070085 private final int mOwnerUid;
86 private final String mOwnerPackageName;
Bryce Lee609bf652017-02-09 16:50:13 -080087 private final Resources mResources;
88 private DisplayAdjustments mDisplayAdjustments;
Jeff Brownbd6e1502012-08-28 03:27:37 -070089
Mathew Inwooda570dee2018-08-17 14:56:00 +010090 @UnsupportedAppUsage
Jeff Brownbd6e1502012-08-28 03:27:37 -070091 private DisplayInfo mDisplayInfo; // never null
92 private boolean mIsValid;
Jeff Brownfa25bf52012-07-23 19:26:30 -070093
94 // Temporary display metrics structure used for compatibility mode.
95 private final DisplayMetrics mTempMetrics = new DisplayMetrics();
96
97 // We cache the app width and height properties briefly between calls
98 // to getHeight() and getWidth() to ensure that applications perceive
99 // consistent results when the size changes (most of the time).
Andrii Kulian0271e572020-01-28 21:00:09 -0800100 // Applications should now be using WindowMetrics instead.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700101 private static final int CACHED_APP_SIZE_DURATION_MILLIS = 20;
102 private long mLastCachedAppSizeUpdate;
103 private int mCachedAppWidthCompat;
104 private int mCachedAppHeightCompat;
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 /**
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800107 * The default Display id, which is the id of the primary display assuming there is one.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 */
109 public static final int DEFAULT_DISPLAY = 0;
110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 /**
Wale Ogunwale26698512015-06-05 16:55:33 -0700112 * Invalid display id.
113 */
114 public static final int INVALID_DISPLAY = -1;
115
116 /**
Jeff Brown77aebfd2012-10-01 21:07:03 -0700117 * Display flag: Indicates that the display supports compositing content
118 * that is stored in protected graphics buffers.
Jeff Brownc5df37c2012-09-13 11:45:07 -0700119 * <p>
Jeff Brownf0681b32012-10-23 17:35:57 -0700120 * If this flag is set then the display device supports compositing protected buffers.
121 * </p><p>
122 * If this flag is not set then the display device may not support compositing
123 * protected buffers; the user may see a blank region on the screen instead of
124 * the protected content.
125 * </p><p>
Jeff Brown77aebfd2012-10-01 21:07:03 -0700126 * Secure (DRM) video decoders may allocate protected graphics buffers to request that
127 * a hardware-protected path be provided between the video decoder and the external
128 * display sink. If a hardware-protected path is not available, then content stored
129 * in protected graphics buffers may not be composited.
Jeff Brownc5df37c2012-09-13 11:45:07 -0700130 * </p><p>
Jeff Brownf0681b32012-10-23 17:35:57 -0700131 * An application can use the absence of this flag as a hint that it should not use protected
132 * buffers for this display because the content may not be visible. For example,
133 * if the flag is not set then the application may choose not to show content on this
134 * display, show an informative error message, select an alternate content stream
135 * or adopt a different strategy for decoding content that does not rely on
136 * protected buffers.
Jeff Brownc5df37c2012-09-13 11:45:07 -0700137 * </p>
Jeff Brownf0681b32012-10-23 17:35:57 -0700138 *
139 * @see #getFlags
Jeff Brownc5df37c2012-09-13 11:45:07 -0700140 */
Jeff Brown77aebfd2012-10-01 21:07:03 -0700141 public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 0;
Jeff Brownc5df37c2012-09-13 11:45:07 -0700142
143 /**
Jeff Brownf0681b32012-10-23 17:35:57 -0700144 * Display flag: Indicates that the display has a secure video output and
145 * supports compositing secure surfaces.
146 * <p>
147 * If this flag is set then the display device has a secure video output
148 * and is capable of showing secure surfaces. It may also be capable of
149 * showing {@link #FLAG_SUPPORTS_PROTECTED_BUFFERS protected buffers}.
150 * </p><p>
151 * If this flag is not set then the display device may not have a secure video
152 * output; the user may see a blank region on the screen instead of
153 * the contents of secure surfaces or protected buffers.
154 * </p><p>
155 * Secure surfaces are used to prevent content rendered into those surfaces
156 * by applications from appearing in screenshots or from being viewed
157 * on non-secure displays. Protected buffers are used by secure video decoders
158 * for a similar purpose.
159 * </p><p>
160 * An application creates a window with a secure surface by specifying the
161 * {@link WindowManager.LayoutParams#FLAG_SECURE} window flag.
162 * Likewise, an application creates a {@link SurfaceView} with a secure surface
163 * by calling {@link SurfaceView#setSecure} before attaching the secure view to
164 * its containing window.
165 * </p><p>
166 * An application can use the absence of this flag as a hint that it should not create
167 * secure surfaces or protected buffers on this display because the content may
168 * not be visible. For example, if the flag is not set then the application may
169 * choose not to show content on this display, show an informative error message,
170 * select an alternate content stream or adopt a different strategy for decoding
171 * content that does not rely on secure surfaces or protected buffers.
172 * </p>
173 *
174 * @see #getFlags
175 */
176 public static final int FLAG_SECURE = 1 << 1;
177
178 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700179 * Display flag: Indicates that the display is private. Only the application that
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800180 * owns the display and apps that are already on the display can create windows on it.
Jeff Browna506a6e2013-06-04 00:02:38 -0700181 *
182 * @see #getFlags
183 */
184 public static final int FLAG_PRIVATE = 1 << 2;
185
186 /**
Jeff Brown7d00aff2013-08-02 19:03:49 -0700187 * Display flag: Indicates that the display is a presentation display.
188 * <p>
189 * This flag identifies secondary displays that are suitable for
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800190 * use as presentation displays such as external or wireless displays. Applications
Jeff Brown7d00aff2013-08-02 19:03:49 -0700191 * may automatically project their content to presentation displays to provide
192 * richer second screen experiences.
193 * </p>
194 *
195 * @see #getFlags
196 */
197 public static final int FLAG_PRESENTATION = 1 << 3;
198
199 /**
Adam Powell49e7ff92015-05-14 16:18:53 -0700200 * Display flag: Indicates that the display has a round shape.
201 * <p>
202 * This flag identifies displays that are circular, elliptical or otherwise
203 * do not permit the user to see all the way to the logical corners of the display.
204 * </p>
205 *
206 * @see #getFlags
207 */
208 public static final int FLAG_ROUND = 1 << 4;
209
210 /**
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800211 * Display flag: Indicates that the display can show its content when non-secure keyguard is
212 * shown.
213 * <p>
Andrii Kulian732a90a2017-08-17 17:21:20 -0700214 * This flag identifies secondary displays that will continue showing content if keyguard can be
215 * dismissed without entering credentials.
216 * </p><p>
217 * An example of usage is a virtual display which content is displayed on external hardware
218 * display that is not visible to the system directly.
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800219 * </p>
220 *
Andrii Kulian732a90a2017-08-17 17:21:20 -0700221 * @see DisplayManager#VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD
Adrian Roose99bc052017-11-20 17:55:31 +0100222 * @see KeyguardManager#isDeviceSecure()
223 * @see KeyguardManager#isDeviceLocked()
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800224 * @see #getFlags
Andrii Kulian22512e82017-04-13 11:34:43 -0700225 * @hide
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800226 */
Chilun8753ad32018-10-09 15:56:45 +0800227 // TODO (b/114338689): Remove the flag and use IWindowManager#shouldShowWithInsecureKeyguard
Andrii Kulian7211d2e2017-01-27 15:58:05 -0800228 public static final int FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 5;
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800229
230 /**
Louis Changbd48dca2018-08-29 17:44:34 +0800231 * Display flag: Indicates that the display should show system decorations.
232 * <p>
233 * This flag identifies secondary displays that should show system decorations, such as status
234 * bar, navigation bar, home activity or IME.
235 * </p>
236 *
Louis Changbd48dca2018-08-29 17:44:34 +0800237 * @hide
238 */
Chilun8753ad32018-10-09 15:56:45 +0800239 // TODO (b/114338689): Remove the flag and use IWindowManager#setShouldShowSystemDecors
Louis Changbd48dca2018-08-29 17:44:34 +0800240 public static final int FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS = 1 << 6;
241
242 /**
Jeff Brownd46747a2015-04-15 19:02:36 -0700243 * Display flag: Indicates that the contents of the display should not be scaled
244 * to fit the physical screen dimensions. Used for development only to emulate
245 * devices with smaller physicals screens while preserving density.
246 *
247 * @hide
248 */
249 public static final int FLAG_SCALING_DISABLED = 1 << 30;
250
251 /**
Jeff Brown92130f62012-10-24 21:28:33 -0700252 * Display type: Unknown display type.
253 * @hide
254 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100255 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700256 public static final int TYPE_UNKNOWN = 0;
257
258 /**
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800259 * Display type: Physical display connected through an internal port.
Jeff Brown92130f62012-10-24 21:28:33 -0700260 * @hide
261 */
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800262 public static final int TYPE_INTERNAL = 1;
Jeff Brown92130f62012-10-24 21:28:33 -0700263
264 /**
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800265 * Display type: Physical display connected through an external port.
Jeff Brown92130f62012-10-24 21:28:33 -0700266 * @hide
267 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100268 @UnsupportedAppUsage
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800269 public static final int TYPE_EXTERNAL = 2;
Jeff Brown92130f62012-10-24 21:28:33 -0700270
271 /**
272 * Display type: WiFi display.
273 * @hide
274 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100275 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700276 public static final int TYPE_WIFI = 3;
277
278 /**
279 * Display type: Overlay display.
280 * @hide
281 */
282 public static final int TYPE_OVERLAY = 4;
283
284 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700285 * Display type: Virtual display.
286 * @hide
287 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100288 @UnsupportedAppUsage
Jeff Browna506a6e2013-06-04 00:02:38 -0700289 public static final int TYPE_VIRTUAL = 5;
290
291 /**
Jeff Brown037c33e2014-04-09 00:31:55 -0700292 * Display state: The display state is unknown.
293 *
294 * @see #getState
295 */
Bookatz1a1b0462018-01-12 11:47:03 -0800296 public static final int STATE_UNKNOWN = ViewProtoEnums.DISPLAY_STATE_UNKNOWN; // 0
Jeff Brown037c33e2014-04-09 00:31:55 -0700297
298 /**
299 * Display state: The display is off.
300 *
301 * @see #getState
302 */
Bookatz1a1b0462018-01-12 11:47:03 -0800303 public static final int STATE_OFF = ViewProtoEnums.DISPLAY_STATE_OFF; // 1
Jeff Brown037c33e2014-04-09 00:31:55 -0700304
305 /**
306 * Display state: The display is on.
307 *
308 * @see #getState
309 */
Bookatz1a1b0462018-01-12 11:47:03 -0800310 public static final int STATE_ON = ViewProtoEnums.DISPLAY_STATE_ON; // 2
Jeff Brown037c33e2014-04-09 00:31:55 -0700311
312 /**
Jeff Brown5dc21912014-07-17 18:50:18 -0700313 * Display state: The display is dozing in a low power state; it is still
314 * on but is optimized for showing system-provided content while the
315 * device is non-interactive.
Jeff Brown037c33e2014-04-09 00:31:55 -0700316 *
317 * @see #getState
318 * @see android.os.PowerManager#isInteractive
319 */
Bookatz1a1b0462018-01-12 11:47:03 -0800320 public static final int STATE_DOZE = ViewProtoEnums.DISPLAY_STATE_DOZE; // 3
Jeff Brown5dc21912014-07-17 18:50:18 -0700321
322 /**
323 * Display state: The display is dozing in a suspended low power state; it is still
Chris Phoenix10a4a642017-09-25 13:21:00 -0700324 * on but the CPU is not updating it. This may be used in one of two ways: to show
325 * static system-provided content while the device is non-interactive, or to allow
326 * a "Sidekick" compute resource to update the display. For this reason, the
327 * CPU must not control the display in this mode.
Jeff Brown5dc21912014-07-17 18:50:18 -0700328 *
329 * @see #getState
330 * @see android.os.PowerManager#isInteractive
331 */
Bookatz1a1b0462018-01-12 11:47:03 -0800332 public static final int STATE_DOZE_SUSPEND = ViewProtoEnums.DISPLAY_STATE_DOZE_SUSPEND; // 4
Jeff Brown037c33e2014-04-09 00:31:55 -0700333
Santos Cordon3107d292016-09-20 15:50:35 -0700334 /**
335 * Display state: The display is on and optimized for VR mode.
336 *
337 * @see #getState
338 * @see android.os.PowerManager#isInteractive
Santos Cordon3107d292016-09-20 15:50:35 -0700339 */
Bookatz1a1b0462018-01-12 11:47:03 -0800340 public static final int STATE_VR = ViewProtoEnums.DISPLAY_STATE_VR; // 5
Santos Cordon3107d292016-09-20 15:50:35 -0700341
Chris Phoenix10a4a642017-09-25 13:21:00 -0700342 /**
343 * Display state: The display is in a suspended full power state; it is still
344 * on but the CPU is not updating it. This may be used in one of two ways: to show
345 * static system-provided content while the device is non-interactive, or to allow
346 * a "Sidekick" compute resource to update the display. For this reason, the
347 * CPU must not control the display in this mode.
348 *
349 * @see #getState
350 * @see android.os.PowerManager#isInteractive
351 */
Bookatz1a1b0462018-01-12 11:47:03 -0800352 public static final int STATE_ON_SUSPEND = ViewProtoEnums.DISPLAY_STATE_ON_SUSPEND; // 6
Chris Phoenix10a4a642017-09-25 13:21:00 -0700353
Michael Wright1c9977b2016-07-12 13:30:10 -0700354 /* The color mode constants defined below must be kept in sync with the ones in
Romain Guy6d228c22017-01-20 18:41:06 -0800355 * system/core/include/system/graphics-base.h */
Michael Wright1c9977b2016-07-12 13:30:10 -0700356
357 /**
358 * Display color mode: The current color mode is unknown or invalid.
359 * @hide
360 */
361 public static final int COLOR_MODE_INVALID = -1;
362
363 /**
364 * Display color mode: The default or native gamut of the display.
365 * @hide
366 */
367 public static final int COLOR_MODE_DEFAULT = 0;
368
Romain Guy6d228c22017-01-20 18:41:06 -0800369 /** @hide */
370 public static final int COLOR_MODE_BT601_625 = 1;
371 /** @hide */
372 public static final int COLOR_MODE_BT601_625_UNADJUSTED = 2;
373 /** @hide */
374 public static final int COLOR_MODE_BT601_525 = 3;
375 /** @hide */
376 public static final int COLOR_MODE_BT601_525_UNADJUSTED = 4;
377 /** @hide */
378 public static final int COLOR_MODE_BT709 = 5;
379 /** @hide */
380 public static final int COLOR_MODE_DCI_P3 = 6;
381 /** @hide */
Michael Wright1c9977b2016-07-12 13:30:10 -0700382 public static final int COLOR_MODE_SRGB = 7;
Romain Guy6d228c22017-01-20 18:41:06 -0800383 /** @hide */
384 public static final int COLOR_MODE_ADOBE_RGB = 8;
385 /** @hide */
386 public static final int COLOR_MODE_DISPLAY_P3 = 9;
Michael Wright1c9977b2016-07-12 13:30:10 -0700387
Ahan Wu287d8282019-12-17 16:23:17 +0800388 /** @hide **/
389 @IntDef(prefix = {"COLOR_MODE_"}, value = {
390 COLOR_MODE_INVALID,
391 COLOR_MODE_DEFAULT,
392 COLOR_MODE_BT601_625,
393 COLOR_MODE_BT601_625_UNADJUSTED,
394 COLOR_MODE_BT601_525,
395 COLOR_MODE_BT601_525_UNADJUSTED,
396 COLOR_MODE_BT709,
397 COLOR_MODE_DCI_P3,
398 COLOR_MODE_SRGB,
399 COLOR_MODE_ADOBE_RGB,
400 COLOR_MODE_DISPLAY_P3
401 })
402 @Retention(RetentionPolicy.SOURCE)
403 public @interface ColorMode {}
404
Jeff Brown037c33e2014-04-09 00:31:55 -0700405 /**
Andrii Kulian250d6532017-02-08 23:30:45 -0800406 * Indicates that when display is removed, all its activities will be moved to the primary
407 * display and the topmost activity should become focused.
408 *
409 * @hide
410 */
Chilun8753ad32018-10-09 15:56:45 +0800411 // TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_MOVE_TO_PRIMARY
Andrii Kulian250d6532017-02-08 23:30:45 -0800412 public static final int REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY = 0;
413 /**
414 * Indicates that when display is removed, all its stacks and tasks will be removed, all
415 * activities will be destroyed according to the usual lifecycle.
416 *
417 * @hide
418 */
Chilun8753ad32018-10-09 15:56:45 +0800419 // TODO (b/114338689): Remove the flag and use WindowManager#REMOVE_CONTENT_MODE_DESTROY
Andrii Kulian250d6532017-02-08 23:30:45 -0800420 public static final int REMOVE_MODE_DESTROY_CONTENT = 1;
421
422 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700423 * Internal method to create a display.
Bryce Lee609bf652017-02-09 16:50:13 -0800424 * The display created with this method will have a static {@link DisplayAdjustments} applied.
Andrii Kulian4a316972020-01-21 21:41:38 -0800425 * Applications should use {@link android.content.Context#getDisplay} with
426 * {@link android.app.Activity} or a context associated with a {@link Display} via
427 * {@link android.content.Context#createDisplayContext(Display)}
428 * to get a display object associated with a {@link android.app.Context}, or
429 * {@link android.hardware.display.DisplayManager#getDisplay} to get a display object by id.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700430 *
Andrii Kulian4a316972020-01-21 21:41:38 -0800431 * @see android.content.Context#getDisplay()
432 * @see android.content.Context#createDisplayContext(Display)
Jeff Brownfa25bf52012-07-23 19:26:30 -0700433 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 */
Bryce Lee609bf652017-02-09 16:50:13 -0800435 public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
Craig Mautner48d0d182013-06-11 07:53:06 -0700436 DisplayAdjustments daj) {
Bryce Lee609bf652017-02-09 16:50:13 -0800437 this(global, displayId, displayInfo, daj, null /*res*/);
438 }
439
440 /**
441 * Internal method to create a display.
442 * The display created with this method will be adjusted based on the adjustments in the
443 * supplied {@link Resources}.
444 *
445 * @hide
446 */
447 public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo,
448 Resources res) {
449 this(global, displayId, displayInfo, null /*daj*/, res);
450 }
451
452 private Display(DisplayManagerGlobal global, int displayId,
453 /*@NotNull*/ DisplayInfo displayInfo, DisplayAdjustments daj, Resources res) {
Jeff Brownbd6e1502012-08-28 03:27:37 -0700454 mGlobal = global;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700455 mDisplayId = displayId;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700456 mDisplayInfo = displayInfo;
Bryce Lee609bf652017-02-09 16:50:13 -0800457 mResources = res;
458 mDisplayAdjustments = mResources != null
459 ? new DisplayAdjustments(mResources.getConfiguration())
Andrii Kulian946e8df2019-12-12 12:15:33 -0800460 : daj != null ? new DisplayAdjustments(daj) : new DisplayAdjustments();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700461 mIsValid = true;
Jeff Brown92130f62012-10-24 21:28:33 -0700462
463 // Cache properties that cannot change as long as the display is valid.
464 mLayerStack = displayInfo.layerStack;
465 mFlags = displayInfo.flags;
466 mType = displayInfo.type;
467 mAddress = displayInfo.address;
Jeff Browna506a6e2013-06-04 00:02:38 -0700468 mOwnerUid = displayInfo.ownerUid;
469 mOwnerPackageName = displayInfo.ownerPackageName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 }
Dianne Hackborn5fd21692011-06-07 14:09:47 -0700471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700473 * Gets the display id.
474 * <p>
475 * Each logical display has a unique id.
476 * The default display has id {@link #DEFAULT_DISPLAY}.
477 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 */
479 public int getDisplayId() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700480 return mDisplayId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 }
482
483 /**
Garfield Tan891146c2018-10-09 12:14:00 -0700484 * Gets the display unique id.
485 * <p>
486 * Unique id is different from display id because physical displays have stable unique id across
487 * reboots.
488 *
489 * @see com.android.service.display.DisplayDevice#hasStableUniqueId().
490 * @hide
491 */
492 public String getUniqueId() {
493 return mDisplayInfo.uniqueId;
494 }
495
496 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -0700497 * Returns true if this display is still valid, false if the display has been removed.
498 *
499 * If the display is invalid, then the methods of this class will
500 * continue to report the most recently observed display information.
501 * However, it is unwise (and rather fruitless) to continue using a
502 * {@link Display} object after the display's demise.
503 *
504 * It's possible for a display that was previously invalid to become
505 * valid again if a display with the same id is reconnected.
506 *
507 * @return True if the display is still valid.
508 */
509 public boolean isValid() {
510 synchronized (this) {
511 updateDisplayInfoLocked();
512 return mIsValid;
513 }
514 }
515
516 /**
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700517 * Gets a full copy of the display information.
518 *
519 * @param outDisplayInfo The object to receive the copy of the display information.
Jeff Brownbd6e1502012-08-28 03:27:37 -0700520 * @return True if the display is still valid.
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700521 * @hide
522 */
Sergey Vasilinets669ad672019-02-07 13:42:33 +0000523 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Jeff Brownbd6e1502012-08-28 03:27:37 -0700524 public boolean getDisplayInfo(DisplayInfo outDisplayInfo) {
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700525 synchronized (this) {
526 updateDisplayInfoLocked();
527 outDisplayInfo.copyFrom(mDisplayInfo);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700528 return mIsValid;
Jeff Brown2ab1b7d92012-08-08 01:46:41 -0700529 }
530 }
531
532 /**
Jeff Brown98365d72012-08-19 20:30:52 -0700533 * Gets the display's layer stack.
534 *
535 * Each display has its own independent layer stack upon which surfaces
536 * are placed to be managed by surface flinger.
537 *
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700538 * @return The display's layer stack number.
Jeff Brown98365d72012-08-19 20:30:52 -0700539 * @hide
540 */
541 public int getLayerStack() {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700542 return mLayerStack;
Jeff Brown98365d72012-08-19 20:30:52 -0700543 }
544
545 /**
Jeff Brownc5df37c2012-09-13 11:45:07 -0700546 * Returns a combination of flags that describe the capabilities of the display.
547 *
548 * @return The display flags.
549 *
Jeff Brown77aebfd2012-10-01 21:07:03 -0700550 * @see #FLAG_SUPPORTS_PROTECTED_BUFFERS
Jeff Brownf0681b32012-10-23 17:35:57 -0700551 * @see #FLAG_SECURE
Jeff Browna506a6e2013-06-04 00:02:38 -0700552 * @see #FLAG_PRIVATE
Jeff Brownc5df37c2012-09-13 11:45:07 -0700553 */
554 public int getFlags() {
Jeff Brown92130f62012-10-24 21:28:33 -0700555 return mFlags;
556 }
557
558 /**
559 * Gets the display type.
560 *
561 * @return The display type.
562 *
563 * @see #TYPE_UNKNOWN
Dominik Laskowski26290bb2020-01-15 16:09:55 -0800564 * @see #TYPE_INTERNAL
565 * @see #TYPE_EXTERNAL
Jeff Brown92130f62012-10-24 21:28:33 -0700566 * @see #TYPE_WIFI
567 * @see #TYPE_OVERLAY
Jeff Browna506a6e2013-06-04 00:02:38 -0700568 * @see #TYPE_VIRTUAL
Jeff Brown92130f62012-10-24 21:28:33 -0700569 * @hide
570 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100571 @UnsupportedAppUsage
Jeff Brown92130f62012-10-24 21:28:33 -0700572 public int getType() {
573 return mType;
574 }
575
576 /**
577 * Gets the display address, or null if none.
578 * Interpretation varies by display type.
579 *
580 * @return The display address.
581 * @hide
582 */
Dominik Laskowskidb845962019-01-27 21:20:00 -0800583 public DisplayAddress getAddress() {
Jeff Brown92130f62012-10-24 21:28:33 -0700584 return mAddress;
Jeff Brownc5df37c2012-09-13 11:45:07 -0700585 }
586
587 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700588 * Gets the UID of the application that owns this display, or zero if it is
589 * owned by the system.
590 * <p>
591 * If the display is private, then only the owner can use it.
592 * </p>
593 *
594 * @hide
595 */
596 public int getOwnerUid() {
597 return mOwnerUid;
598 }
599
600 /**
601 * Gets the package name of the application that owns this display, or null if it is
602 * owned by the system.
603 * <p>
604 * If the display is private, then only the owner can use it.
605 * </p>
606 *
607 * @hide
608 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100609 @UnsupportedAppUsage
Jeff Browna506a6e2013-06-04 00:02:38 -0700610 public String getOwnerPackageName() {
611 return mOwnerPackageName;
612 }
613
614 /**
Jeff Brown98365d72012-08-19 20:30:52 -0700615 * Gets the compatibility info used by this display instance.
616 *
Craig Mautner48d0d182013-06-11 07:53:06 -0700617 * @return The display adjustments holder, or null if none is required.
Jeff Brown98365d72012-08-19 20:30:52 -0700618 * @hide
619 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100620 @UnsupportedAppUsage
Craig Mautner48d0d182013-06-11 07:53:06 -0700621 public DisplayAdjustments getDisplayAdjustments() {
Bryce Lee609bf652017-02-09 16:50:13 -0800622 if (mResources != null) {
623 final DisplayAdjustments currentAdjustements = mResources.getDisplayAdjustments();
624 if (!mDisplayAdjustments.equals(currentAdjustements)) {
625 mDisplayAdjustments = new DisplayAdjustments(currentAdjustements);
626 }
627 }
628
Craig Mautner48d0d182013-06-11 07:53:06 -0700629 return mDisplayAdjustments;
Jeff Brown98365d72012-08-19 20:30:52 -0700630 }
631
632 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700633 * Gets the name of the display.
Jeff Brown92130f62012-10-24 21:28:33 -0700634 * <p>
635 * Note that some displays may be renamed by the user.
636 * </p>
637 *
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700638 * @return The display's name.
639 */
640 public String getName() {
Jeff Brown92130f62012-10-24 21:28:33 -0700641 synchronized (this) {
642 updateDisplayInfoLocked();
643 return mDisplayInfo.name;
644 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700645 }
646
647 /**
Jeff Brownbc68a592011-07-25 12:58:12 -0700648 * Gets the size of the display, in pixels.
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700649 * Value returned by this method does not necessarily represent the actual raw size
650 * (native resolution) of the display.
Jeff Brownbc68a592011-07-25 12:58:12 -0700651 * <p>
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700652 * 1. The returned size may be adjusted to exclude certain system decor elements
653 * that are always visible.
Jeff Brownbc68a592011-07-25 12:58:12 -0700654 * </p><p>
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700655 * 2. It may be scaled to provide compatibility with older applications that
Jeff Brownbc68a592011-07-25 12:58:12 -0700656 * were originally designed for smaller displays.
Andrii Kulian5f57a3d2016-06-28 18:41:42 -0700657 * </p><p>
658 * 3. It can be different depending on the WindowManager to which the display belongs.
659 * </p><p>
660 * - If requested from non-Activity context (e.g. Application context via
661 * {@code (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)})
662 * it will report the size of the entire display based on current rotation and with subtracted
663 * system decoration areas.
664 * </p><p>
665 * - If requested from activity (either using {@code getWindowManager()} or
666 * {@code (WindowManager) getSystemService(Context.WINDOW_SERVICE)}) resulting size will
667 * correspond to current app window size. In this case it can be smaller than physical size in
668 * multi-window mode.
669 * </p><p>
670 * Typically for the purposes of layout apps should make a request from activity context
671 * to obtain size available for the app content.
Jeff Brownbc68a592011-07-25 12:58:12 -0700672 * </p>
673 *
674 * @param outSize A {@link Point} object to receive the size information.
Andrii Kulian0271e572020-01-28 21:00:09 -0800675 * @deprecated Use {@link WindowManager#getCurrentWindowMetrics()} to obtain an instance of
676 * {@link WindowMetrics} and use {@link WindowMetrics#getSize()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 */
Andrii Kulian0271e572020-01-28 21:00:09 -0800678 @Deprecated
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700679 public void getSize(Point outSize) {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700680 synchronized (this) {
681 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -0800682 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownfa25bf52012-07-23 19:26:30 -0700683 outSize.x = mTempMetrics.widthPixels;
684 outSize.y = mTempMetrics.heightPixels;
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700685 }
686 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 /**
Jeff Brownbc68a592011-07-25 12:58:12 -0700689 * Gets the size of the display as a rectangle, in pixels.
690 *
691 * @param outSize A {@link Rect} object to receive the size information.
Andrii Kulian0271e572020-01-28 21:00:09 -0800692 * @deprecated Use {@link WindowMetrics#getSize()} to get the dimensions of the application
693 * window area.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 */
Andrii Kulian0271e572020-01-28 21:00:09 -0800695 @Deprecated
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700696 public void getRectSize(Rect outSize) {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700697 synchronized (this) {
698 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -0800699 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownfa25bf52012-07-23 19:26:30 -0700700 outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels);
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700701 }
702 }
703
704 /**
Dianne Hackborn68c33ca2012-04-19 14:51:25 -0700705 * Return the range of display sizes an application can expect to encounter
706 * under normal operation, as long as there is no physical change in screen
707 * size. This is basically the sizes you will see as the orientation
708 * changes, taking into account whatever screen decoration there is in
709 * each rotation. For example, the status bar is always at the top of the
710 * screen, so it will reduce the height both in landscape and portrait, and
711 * the smallest height returned here will be the smaller of the two.
712 *
713 * This is intended for applications to get an idea of the range of sizes
714 * they will encounter while going through device rotations, to provide a
715 * stable UI through rotation. The sizes here take into account all standard
716 * system decorations that reduce the size actually available to the
717 * application: the status bar, navigation bar, system bar, etc. It does
718 * <em>not</em> take into account more transient elements like an IME
719 * soft keyboard.
720 *
721 * @param outSmallestSize Filled in with the smallest width and height
722 * that the application will encounter, in pixels (not dp units). The x
723 * (width) dimension here directly corresponds to
724 * {@link android.content.res.Configuration#smallestScreenWidthDp
725 * Configuration.smallestScreenWidthDp}, except the value here is in raw
726 * screen pixels rather than dp units. Your application may of course
727 * still get smaller space yet if, for example, a soft keyboard is
728 * being displayed.
729 * @param outLargestSize Filled in with the largest width and height
730 * that the application will encounter, in pixels (not dp units). Your
731 * application may of course still get larger space than this if,
732 * for example, screen decorations like the status bar are being hidden.
733 */
734 public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700735 synchronized (this) {
736 updateDisplayInfoLocked();
737 outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth;
738 outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight;
739 outLargestSize.x = mDisplayInfo.largestNominalAppWidth;
740 outLargestSize.y = mDisplayInfo.largestNominalAppHeight;
Dianne Hackborn68c33ca2012-04-19 14:51:25 -0700741 }
742 }
743
744 /**
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700745 * Return the maximum screen size dimension that will happen. This is
746 * mostly for wallpapers.
747 * @hide
748 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100749 @UnsupportedAppUsage
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700750 public int getMaximumSizeDimension() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700751 synchronized (this) {
752 updateDisplayInfoLocked();
753 return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700754 }
755 }
756
757 /**
Andrii Kulian0271e572020-01-28 21:00:09 -0800758 * @deprecated Use {@link WindowMetrics#getSize()} instead.
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700759 */
760 @Deprecated
761 public int getWidth() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700762 synchronized (this) {
763 updateCachedAppSizeIfNeededLocked();
764 return mCachedAppWidthCompat;
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700765 }
766 }
767
768 /**
Andrii Kulian0271e572020-01-28 21:00:09 -0800769 * @deprecated Use {@link WindowMetrics#getSize()} instead.
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700770 */
771 @Deprecated
772 public int getHeight() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700773 synchronized (this) {
774 updateCachedAppSizeIfNeededLocked();
775 return mCachedAppHeightCompat;
Dianne Hackbornac8dea12011-04-20 18:18:51 -0700776 }
777 }
778
Jeff Brownbc68a592011-07-25 12:58:12 -0700779 /**
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800780 * Returns the rotation of the screen from its "natural" orientation.
781 * The returned value may be {@link Surface#ROTATION_0 Surface.ROTATION_0}
782 * (no rotation), {@link Surface#ROTATION_90 Surface.ROTATION_90},
783 * {@link Surface#ROTATION_180 Surface.ROTATION_180}, or
784 * {@link Surface#ROTATION_270 Surface.ROTATION_270}. For
785 * example, if a device has a naturally tall screen, and the user has
786 * turned it on its side to go into a landscape orientation, the value
787 * returned here may be either {@link Surface#ROTATION_90 Surface.ROTATION_90}
788 * or {@link Surface#ROTATION_270 Surface.ROTATION_270} depending on
789 * the direction it was turned. The angle is the rotation of the drawn
790 * graphics on the screen, which is the opposite direction of the physical
791 * rotation of the device. For example, if the device is rotated 90
792 * degrees counter-clockwise, to compensate rendering will be rotated by
793 * 90 degrees clockwise and thus the returned value here will be
794 * {@link Surface#ROTATION_90 Surface.ROTATION_90}.
795 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700796 @Surface.Rotation
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800797 public int getRotation() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700798 synchronized (this) {
799 updateDisplayInfoLocked();
800 return mDisplayInfo.rotation;
801 }
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800802 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700803
Dianne Hackborn5cb70b52010-02-25 17:01:14 -0800804 /**
Joe Onorato4c904a32010-02-26 12:35:55 -0800805 * @deprecated use {@link #getRotation}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 * @return orientation of this display.
807 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700808 @Deprecated
Tor Norbyed9273d62013-05-30 15:59:53 -0700809 @Surface.Rotation
Jeff Brownfa25bf52012-07-23 19:26:30 -0700810 public int getOrientation() {
811 return getRotation();
812 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813
Adrian Roosa4904792018-05-31 19:48:39 +0200814
815 /**
816 * Returns the {@link DisplayCutout}, or {@code null} if there is none.
817 *
818 * @see DisplayCutout
819 */
820 @Nullable
821 public DisplayCutout getCutout() {
822 synchronized (this) {
823 updateDisplayInfoLocked();
824 return mDisplayInfo.displayCutout;
825 }
826 }
827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700829 * Gets the pixel format of the display.
830 * @return One of the constants defined in {@link android.graphics.PixelFormat}.
831 *
832 * @deprecated This method is no longer supported.
833 * The result is always {@link PixelFormat#RGBA_8888}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700835 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800836 public int getPixelFormat() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700837 return PixelFormat.RGBA_8888;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700841 * Gets the refresh rate of this display in frames per second.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 */
843 public float getRefreshRate() {
Jeff Brownfa25bf52012-07-23 19:26:30 -0700844 synchronized (this) {
845 updateDisplayInfoLocked();
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700846 return mDisplayInfo.getMode().getRefreshRate();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700847 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700849
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 /**
Michael Wright3f145a22014-07-22 19:46:03 -0700851 * Get the supported refresh rates of this display in frames per second.
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700852 * <p>
853 * This method only returns refresh rates for the display's default modes. For more options, use
854 * {@link #getSupportedModes()}.
855 *
856 * @deprecated use {@link #getSupportedModes()} instead
Michael Wright3f145a22014-07-22 19:46:03 -0700857 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700858 @Deprecated
Michael Wright3f145a22014-07-22 19:46:03 -0700859 public float[] getSupportedRefreshRates() {
860 synchronized (this) {
861 updateDisplayInfoLocked();
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700862 return mDisplayInfo.getDefaultRefreshRates();
863 }
864 }
865
866 /**
867 * Returns the active mode of the display.
868 */
869 public Mode getMode() {
870 synchronized (this) {
871 updateDisplayInfoLocked();
872 return mDisplayInfo.getMode();
873 }
874 }
875
876 /**
877 * Gets the supported modes of this display.
878 */
879 public Mode[] getSupportedModes() {
880 synchronized (this) {
881 updateDisplayInfoLocked();
882 final Display.Mode[] modes = mDisplayInfo.supportedModes;
883 return Arrays.copyOf(modes, modes.length);
Michael Wright3f145a22014-07-22 19:46:03 -0700884 }
885 }
886
887 /**
Galia Peycheva056b3ee2019-06-26 14:05:12 +0200888 * <p> Returns true if the connected display can be switched into a mode with minimal
889 * post processing. </p>
890 *
891 * <p> If the Display sink is connected via HDMI, this method will return true if the
892 * display supports either Auto Low Latency Mode or Game Content Type.
893 *
894 * <p> If the Display sink has an internal connection or uses some other protocol than
895 * HDMI, this method will return true if the sink can be switched into an
896 * implementation-defined low latency image processing mode. </p>
897 *
898 * <p> The ability to switch to a mode with minimal post processing may be disabled
899 * by a user setting in the system settings menu. In that case, this method returns
900 * false. </p>
901 *
902 * @see android.view.Window#setPreferMinimalPostProcessing
903 */
904 @SuppressLint("VisiblySynchronized")
905 public boolean isMinimalPostProcessingSupported() {
906 synchronized (this) {
907 updateDisplayInfoLocked();
908 return mDisplayInfo.minimalPostProcessingSupported;
909 }
910 }
911
912 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700913 * Request the display applies a color mode.
Michael Wright58e829f2015-09-15 00:13:26 +0100914 * @hide
915 */
Michael Wright1c9977b2016-07-12 13:30:10 -0700916 @RequiresPermission(CONFIGURE_DISPLAY_COLOR_MODE)
917 public void requestColorMode(int colorMode) {
918 mGlobal.requestColorMode(mDisplayId, colorMode);
Michael Wright58e829f2015-09-15 00:13:26 +0100919 }
920
921 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700922 * Returns the active color mode of this display
Michael Wright58e829f2015-09-15 00:13:26 +0100923 * @hide
924 */
Michael Wright1c9977b2016-07-12 13:30:10 -0700925 public int getColorMode() {
Michael Wright58e829f2015-09-15 00:13:26 +0100926 synchronized (this) {
927 updateDisplayInfoLocked();
Michael Wright1c9977b2016-07-12 13:30:10 -0700928 return mDisplayInfo.colorMode;
Michael Wright58e829f2015-09-15 00:13:26 +0100929 }
930 }
931
932 /**
Andrii Kulian250d6532017-02-08 23:30:45 -0800933 * @hide
934 * Get current remove mode of the display - what actions should be performed with the display's
935 * content when it is removed. Default behavior for public displays in this case is to move all
936 * activities to the primary display and make it focused. For private display - destroy all
937 * activities.
938 *
939 * @see #REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY
940 * @see #REMOVE_MODE_DESTROY_CONTENT
941 */
Chilun8753ad32018-10-09 15:56:45 +0800942 // TODO (b/114338689): Remove the method and use IWindowManager#getRemoveContentMode
Andrii Kulian250d6532017-02-08 23:30:45 -0800943 public int getRemoveMode() {
944 return mDisplayInfo.removeMode;
945 }
946
947 /**
Ronghua Wuf173c322016-02-29 13:57:18 -0800948 * Returns the display's HDR capabilities.
Romain Guy6d228c22017-01-20 18:41:06 -0800949 *
950 * @see #isHdr()
Ronghua Wuf173c322016-02-29 13:57:18 -0800951 */
952 public HdrCapabilities getHdrCapabilities() {
Michael Wright9ff94c02016-03-30 18:05:40 -0700953 synchronized (this) {
954 updateDisplayInfoLocked();
955 return mDisplayInfo.hdrCapabilities;
956 }
Ronghua Wuf173c322016-02-29 13:57:18 -0800957 }
958
959 /**
Romain Guy6d228c22017-01-20 18:41:06 -0800960 * Returns whether this display supports any HDR type.
961 *
962 * @see #getHdrCapabilities()
963 * @see HdrCapabilities#getSupportedHdrTypes()
964 */
965 public boolean isHdr() {
966 synchronized (this) {
967 updateDisplayInfoLocked();
Romain Guy408afbf2017-01-25 10:23:03 -0800968 return mDisplayInfo.isHdr();
Romain Guy6d228c22017-01-20 18:41:06 -0800969 }
970 }
971
972 /**
973 * Returns whether this display can be used to display wide color gamut content.
Romain Guye89d0bb2017-06-20 12:23:42 -0700974 * This does not necessarily mean the device itself can render wide color gamut
975 * content. To ensure wide color gamut content can be produced, refer to
976 * {@link Configuration#isScreenWideColorGamut()}.
Romain Guy6d228c22017-01-20 18:41:06 -0800977 */
978 public boolean isWideColorGamut() {
979 synchronized (this) {
980 updateDisplayInfoLocked();
Romain Guy408afbf2017-01-25 10:23:03 -0800981 return mDisplayInfo.isWideColorGamut();
Romain Guy6d228c22017-01-20 18:41:06 -0800982 }
983 }
984
985 /**
Peiyong Lin277eaff2019-01-16 16:18:22 -0800986 * Returns the preferred wide color space of the Display.
987 * The returned wide gamut color space is based on hardware capability and
988 * is preferred by the composition pipeline.
989 * Returns null if the display doesn't support wide color gamut.
990 * {@link Display#isWideColorGamut()}.
991 */
992 @Nullable
993 public ColorSpace getPreferredWideGamutColorSpace() {
994 synchronized (this) {
995 updateDisplayInfoLocked();
996 if (mDisplayInfo.isWideColorGamut()) {
997 return mGlobal.getPreferredWideGamutColorSpace();
998 }
999 return null;
1000 }
1001 }
1002
1003 /**
Michael Wright1c9977b2016-07-12 13:30:10 -07001004 * Gets the supported color modes of this device.
Michael Wright58e829f2015-09-15 00:13:26 +01001005 * @hide
1006 */
Michael Wright1c9977b2016-07-12 13:30:10 -07001007 public int[] getSupportedColorModes() {
Michael Wright58e829f2015-09-15 00:13:26 +01001008 synchronized (this) {
1009 updateDisplayInfoLocked();
Michael Wright1c9977b2016-07-12 13:30:10 -07001010 int[] colorModes = mDisplayInfo.supportedColorModes;
1011 return Arrays.copyOf(colorModes, colorModes.length);
Michael Wright58e829f2015-09-15 00:13:26 +01001012 }
1013 }
1014
1015 /**
Ahan Wu287d8282019-12-17 16:23:17 +08001016 * Gets the supported wide color gamuts of this device.
1017 *
1018 * @return Supported WCG color spaces.
1019 * @hide
1020 */
Ahan Wuc54169a2020-01-02 19:23:27 +08001021 @SuppressLint("VisiblySynchronized")
1022 @NonNull
1023 @TestApi
Ahan Wu287d8282019-12-17 16:23:17 +08001024 public @ColorMode ColorSpace[] getSupportedWideColorGamut() {
1025 synchronized (this) {
1026 final ColorSpace[] defaultColorSpaces = new ColorSpace[0];
1027 updateDisplayInfoLocked();
1028 if (!isWideColorGamut()) {
1029 return defaultColorSpaces;
1030 }
1031
1032 final int[] colorModes = getSupportedColorModes();
1033 final List<ColorSpace> colorSpaces = new ArrayList<>();
1034 for (int colorMode : colorModes) {
1035 // Refer to DisplayInfo#isWideColorGamut.
1036 switch (colorMode) {
1037 case COLOR_MODE_DCI_P3:
1038 colorSpaces.add(ColorSpace.get(ColorSpace.Named.DCI_P3));
1039 break;
1040 case COLOR_MODE_DISPLAY_P3:
1041 colorSpaces.add(ColorSpace.get(ColorSpace.Named.DISPLAY_P3));
1042 break;
1043 }
1044 }
1045 return colorSpaces.toArray(defaultColorSpaces);
1046 }
1047 }
1048
1049 /**
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001050 * Gets the app VSYNC offset, in nanoseconds. This is a positive value indicating
1051 * the phase offset of the VSYNC events provided by Choreographer relative to the
1052 * display refresh. For example, if Choreographer reports that the refresh occurred
1053 * at time N, it actually occurred at (N - appVsyncOffset).
1054 * <p>
1055 * Apps generally do not need to be aware of this. It's only useful for fine-grained
1056 * A/V synchronization.
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001057 */
1058 public long getAppVsyncOffsetNanos() {
1059 synchronized (this) {
1060 updateDisplayInfoLocked();
1061 return mDisplayInfo.appVsyncOffsetNanos;
1062 }
1063 }
1064
1065 /**
1066 * This is how far in advance a buffer must be queued for presentation at
1067 * a given time. If you want a buffer to appear on the screen at
1068 * time N, you must submit the buffer before (N - presentationDeadline).
1069 * <p>
1070 * The desired presentation time for GLES rendering may be set with
1071 * {@link android.opengl.EGLExt#eglPresentationTimeANDROID}. For video decoding, use
1072 * {@link android.media.MediaCodec#releaseOutputBuffer(int, long)}. Times are
1073 * expressed in nanoseconds, using the system monotonic clock
1074 * ({@link System#nanoTime}).
Andy McFaddene8b1aeb2014-06-13 14:05:40 -07001075 */
1076 public long getPresentationDeadlineNanos() {
1077 synchronized (this) {
1078 updateDisplayInfoLocked();
1079 return mDisplayInfo.presentationDeadlineNanos;
1080 }
1081 }
1082
1083 /**
Jeff Brownbc68a592011-07-25 12:58:12 -07001084 * Gets display metrics that describe the size and density of this display.
Jeff Brownbc68a592011-07-25 12:58:12 -07001085 * The size returned by this method does not necessarily represent the
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001086 * actual raw size (native resolution) of the display.
1087 * <p>
1088 * 1. The returned size may be adjusted to exclude certain system decor elements
1089 * that are always visible.
1090 * </p><p>
1091 * 2. It may be scaled to provide compatibility with older applications that
Jeff Brownbc68a592011-07-25 12:58:12 -07001092 * were originally designed for smaller displays.
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001093 * </p><p>
1094 * 3. It can be different depending on the WindowManager to which the display belongs.
Andrii Kulian5f57a3d2016-06-28 18:41:42 -07001095 * </p><p>
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001096 * - If requested from non-Activity context (e.g. Application context via
1097 * {@code (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)})
Andrii Kulian5f57a3d2016-06-28 18:41:42 -07001098 * metrics will report the size of the entire display based on current rotation and with
1099 * subtracted system decoration areas.
1100 * </p><p>
1101 * - If requested from activity (either using {@code getWindowManager()} or
1102 * {@code (WindowManager) getSystemService(Context.WINDOW_SERVICE)}) resulting metrics will
1103 * correspond to current app window metrics. In this case the size can be smaller than physical
1104 * size in multi-window mode.
Jeff Brownbc68a592011-07-25 12:58:12 -07001105 * </p>
1106 *
1107 * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
Andrii Kulian0271e572020-01-28 21:00:09 -08001108 * @deprecated Use {@link WindowMetrics#getSize()} to get the dimensions of the application
1109 * window area, and {@link Configuration#densityDpi} to get the current density.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 */
Andrii Kulian0271e572020-01-28 21:00:09 -08001111 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 public void getMetrics(DisplayMetrics outMetrics) {
Jeff Brownfa25bf52012-07-23 19:26:30 -07001113 synchronized (this) {
1114 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -08001115 mDisplayInfo.getAppMetrics(outMetrics, getDisplayAdjustments());
Dianne Hackborn68066c22011-04-21 17:26:39 -07001116 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001117 }
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001118
Jeff Brownfa25bf52012-07-23 19:26:30 -07001119 /**
1120 * Gets the real size of the display without subtracting any window decor or
1121 * applying any compatibility scale factors.
1122 * <p>
1123 * The size is adjusted based on the current rotation of the display.
1124 * </p><p>
1125 * The real size may be smaller than the physical size of the screen when the
Andrii Kuliancd097992017-03-23 18:31:59 -07001126 * window manager is emulating a smaller display (using adb shell wm size).
Jeff Brownfa25bf52012-07-23 19:26:30 -07001127 * </p>
1128 *
1129 * @param outSize Set to the real size of the display.
1130 */
1131 public void getRealSize(Point outSize) {
1132 synchronized (this) {
1133 updateDisplayInfoLocked();
1134 outSize.x = mDisplayInfo.logicalWidth;
1135 outSize.y = mDisplayInfo.logicalHeight;
1136 }
Dianne Hackborn68066c22011-04-21 17:26:39 -07001137 }
1138
1139 /**
Jeff Brownbc68a592011-07-25 12:58:12 -07001140 * Gets display metrics based on the real size of this display.
Jeff Brownfa25bf52012-07-23 19:26:30 -07001141 * <p>
1142 * The size is adjusted based on the current rotation of the display.
1143 * </p><p>
1144 * The real size may be smaller than the physical size of the screen when the
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001145 * window manager is emulating a smaller display (using adb shell wm size).
Jeff Brownfa25bf52012-07-23 19:26:30 -07001146 * </p>
1147 *
1148 * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
Dianne Hackborn68066c22011-04-21 17:26:39 -07001149 */
1150 public void getRealMetrics(DisplayMetrics outMetrics) {
Jeff Brownfa25bf52012-07-23 19:26:30 -07001151 synchronized (this) {
1152 updateDisplayInfoLocked();
Craig Mautner48d0d182013-06-11 07:53:06 -07001153 mDisplayInfo.getLogicalMetrics(outMetrics,
Andrii Kuliana4bb9d32016-03-11 11:52:22 -08001154 CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
Jeff Brownbc68a592011-07-25 12:58:12 -07001155 }
Dianne Hackborn68066c22011-04-21 17:26:39 -07001156 }
1157
Jeff Browna506a6e2013-06-04 00:02:38 -07001158 /**
Jeff Brown037c33e2014-04-09 00:31:55 -07001159 * Gets the state of the display, such as whether it is on or off.
1160 *
1161 * @return The state of the display: one of {@link #STATE_OFF}, {@link #STATE_ON},
Chris Phoenix10a4a642017-09-25 13:21:00 -07001162 * {@link #STATE_DOZE}, {@link #STATE_DOZE_SUSPEND}, {@link #STATE_ON_SUSPEND}, or
Santos Cordon3107d292016-09-20 15:50:35 -07001163 * {@link #STATE_UNKNOWN}.
Jeff Brown037c33e2014-04-09 00:31:55 -07001164 */
1165 public int getState() {
1166 synchronized (this) {
1167 updateDisplayInfoLocked();
1168 return mIsValid ? mDisplayInfo.state : STATE_UNKNOWN;
1169 }
1170 }
1171
1172 /**
Jeff Browna506a6e2013-06-04 00:02:38 -07001173 * Returns true if the specified UID has access to this display.
1174 * @hide
1175 */
lumarkec75b422019-01-07 15:58:38 +08001176 @TestApi
Jeff Browna506a6e2013-06-04 00:02:38 -07001177 public boolean hasAccess(int uid) {
lumarkec75b422019-01-07 15:58:38 +08001178 return hasAccess(uid, mFlags, mOwnerUid, mDisplayId);
Jeff Browna506a6e2013-06-04 00:02:38 -07001179 }
1180
1181 /** @hide */
lumarkec75b422019-01-07 15:58:38 +08001182 public static boolean hasAccess(int uid, int flags, int ownerUid, int displayId) {
Jeff Browna506a6e2013-06-04 00:02:38 -07001183 return (flags & Display.FLAG_PRIVATE) == 0
1184 || uid == ownerUid
1185 || uid == Process.SYSTEM_UID
lumarkec75b422019-01-07 15:58:38 +08001186 || uid == 0
1187 // Check if the UID is present on given display.
1188 || DisplayManagerGlobal.getInstance().isUidPresentOnDisplay(uid, displayId);
Jeff Browna506a6e2013-06-04 00:02:38 -07001189 }
1190
Jeff Brown69b07162013-11-07 00:30:16 -08001191 /**
1192 * Returns true if the display is a public presentation display.
1193 * @hide
1194 */
1195 public boolean isPublicPresentation() {
1196 return (mFlags & (Display.FLAG_PRIVATE | Display.FLAG_PRESENTATION)) ==
1197 Display.FLAG_PRESENTATION;
1198 }
1199
Jeff Brownfa25bf52012-07-23 19:26:30 -07001200 private void updateDisplayInfoLocked() {
Jeff Brownbd6e1502012-08-28 03:27:37 -07001201 // Note: The display manager caches display info objects on our behalf.
1202 DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId);
1203 if (newInfo == null) {
1204 // Preserve the old mDisplayInfo after the display is removed.
1205 if (mIsValid) {
1206 mIsValid = false;
1207 if (DEBUG) {
1208 Log.d(TAG, "Logical display " + mDisplayId + " was removed.");
1209 }
1210 }
1211 } else {
1212 // Use the new display info. (It might be the same object if nothing changed.)
1213 mDisplayInfo = newInfo;
1214 if (!mIsValid) {
1215 mIsValid = true;
1216 if (DEBUG) {
1217 Log.d(TAG, "Logical display " + mDisplayId + " was recreated.");
1218 }
1219 }
Jeff Brownfa25bf52012-07-23 19:26:30 -07001220 }
Jeff Brownbc68a592011-07-25 12:58:12 -07001221 }
1222
Jeff Brownfa25bf52012-07-23 19:26:30 -07001223 private void updateCachedAppSizeIfNeededLocked() {
1224 long now = SystemClock.uptimeMillis();
1225 if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) {
1226 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -08001227 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownfa25bf52012-07-23 19:26:30 -07001228 mCachedAppWidthCompat = mTempMetrics.widthPixels;
1229 mCachedAppHeightCompat = mTempMetrics.heightPixels;
1230 mLastCachedAppSizeUpdate = now;
1231 }
Jeff Brownbc68a592011-07-25 12:58:12 -07001232 }
Jeff Brownbf5740e2012-08-19 23:20:02 -07001233
1234 // For debugging purposes
1235 @Override
1236 public String toString() {
1237 synchronized (this) {
1238 updateDisplayInfoLocked();
Bryce Lee609bf652017-02-09 16:50:13 -08001239 mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments());
Jeff Brownbf5740e2012-08-19 23:20:02 -07001240 return "Display id " + mDisplayId + ": " + mDisplayInfo
Jeff Brownbd6e1502012-08-28 03:27:37 -07001241 + ", " + mTempMetrics + ", isValid=" + mIsValid;
Jeff Brownbf5740e2012-08-19 23:20:02 -07001242 }
1243 }
Jeff Brown92130f62012-10-24 21:28:33 -07001244
1245 /**
1246 * @hide
1247 */
1248 public static String typeToString(int type) {
1249 switch (type) {
1250 case TYPE_UNKNOWN:
1251 return "UNKNOWN";
Dominik Laskowski26290bb2020-01-15 16:09:55 -08001252 case TYPE_INTERNAL:
1253 return "INTERNAL";
1254 case TYPE_EXTERNAL:
1255 return "EXTERNAL";
Jeff Brown92130f62012-10-24 21:28:33 -07001256 case TYPE_WIFI:
1257 return "WIFI";
1258 case TYPE_OVERLAY:
1259 return "OVERLAY";
Jeff Browna506a6e2013-06-04 00:02:38 -07001260 case TYPE_VIRTUAL:
1261 return "VIRTUAL";
Jeff Brown92130f62012-10-24 21:28:33 -07001262 default:
1263 return Integer.toString(type);
1264 }
1265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001266
Jeff Brown037c33e2014-04-09 00:31:55 -07001267 /**
1268 * @hide
1269 */
1270 public static String stateToString(int state) {
1271 switch (state) {
1272 case STATE_UNKNOWN:
1273 return "UNKNOWN";
1274 case STATE_OFF:
1275 return "OFF";
1276 case STATE_ON:
1277 return "ON";
Jeff Brown5dc21912014-07-17 18:50:18 -07001278 case STATE_DOZE:
1279 return "DOZE";
1280 case STATE_DOZE_SUSPEND:
1281 return "DOZE_SUSPEND";
Santos Cordon3107d292016-09-20 15:50:35 -07001282 case STATE_VR:
1283 return "VR";
Chris Phoenix10a4a642017-09-25 13:21:00 -07001284 case STATE_ON_SUSPEND:
1285 return "ON_SUSPEND";
Jeff Brown037c33e2014-04-09 00:31:55 -07001286 default:
1287 return Integer.toString(state);
1288 }
1289 }
Jeff Brown970d4132014-07-19 11:33:47 -07001290
1291 /**
1292 * Returns true if display updates may be suspended while in the specified
Chris Phoenix10a4a642017-09-25 13:21:00 -07001293 * display power state. In SUSPEND states, updates are absolutely forbidden.
Jeff Brown970d4132014-07-19 11:33:47 -07001294 * @hide
1295 */
1296 public static boolean isSuspendedState(int state) {
Chris Phoenix10a4a642017-09-25 13:21:00 -07001297 return state == STATE_OFF || state == STATE_DOZE_SUSPEND || state == STATE_ON_SUSPEND;
Jeff Brown970d4132014-07-19 11:33:47 -07001298 }
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001299
1300 /**
Michael Wright05e76fe2017-07-20 18:18:33 +01001301 * Returns true if the display may be in a reduced operating mode while in the
1302 * specified display power state.
1303 * @hide
1304 */
1305 public static boolean isDozeState(int state) {
1306 return state == STATE_DOZE || state == STATE_DOZE_SUSPEND;
1307 }
1308
1309 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001310 * A mode supported by a given display.
1311 *
1312 * @see Display#getSupportedModes()
1313 */
1314 public static final class Mode implements Parcelable {
1315 /**
1316 * @hide
1317 */
1318 public static final Mode[] EMPTY_ARRAY = new Mode[0];
1319
1320 private final int mModeId;
1321 private final int mWidth;
1322 private final int mHeight;
1323 private final float mRefreshRate;
1324
1325 /**
1326 * @hide
1327 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001328 @UnsupportedAppUsage
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001329 public Mode(int modeId, int width, int height, float refreshRate) {
1330 mModeId = modeId;
1331 mWidth = width;
1332 mHeight = height;
1333 mRefreshRate = refreshRate;
1334 }
1335
1336 /**
1337 * Returns this mode's id.
1338 */
1339 public int getModeId() {
1340 return mModeId;
1341 }
1342
1343 /**
1344 * Returns the physical width of the display in pixels when configured in this mode's
1345 * resolution.
1346 * <p>
1347 * Note that due to application UI scaling, the number of pixels made available to
1348 * applications when the mode is active (as reported by {@link Display#getWidth()} may
1349 * differ from the mode's actual resolution (as reported by this function).
1350 * <p>
1351 * For example, applications running on a 4K display may have their UI laid out and rendered
1352 * in 1080p and then scaled up. Applications can take advantage of the extra resolution by
1353 * rendering content through a {@link android.view.SurfaceView} using full size buffers.
1354 */
1355 public int getPhysicalWidth() {
1356 return mWidth;
1357 }
1358
1359 /**
1360 * Returns the physical height of the display in pixels when configured in this mode's
1361 * resolution.
1362 * <p>
1363 * Note that due to application UI scaling, the number of pixels made available to
1364 * applications when the mode is active (as reported by {@link Display#getHeight()} may
1365 * differ from the mode's actual resolution (as reported by this function).
1366 * <p>
1367 * For example, applications running on a 4K display may have their UI laid out and rendered
1368 * in 1080p and then scaled up. Applications can take advantage of the extra resolution by
1369 * rendering content through a {@link android.view.SurfaceView} using full size buffers.
1370 */
1371 public int getPhysicalHeight() {
1372 return mHeight;
1373 }
1374
1375 /**
1376 * Returns the refresh rate in frames per second.
1377 */
1378 public float getRefreshRate() {
1379 return mRefreshRate;
1380 }
1381
1382 /**
1383 * Returns {@code true} if this mode matches the given parameters.
1384 *
1385 * @hide
1386 */
1387 public boolean matches(int width, int height, float refreshRate) {
1388 return mWidth == width &&
1389 mHeight == height &&
1390 Float.floatToIntBits(mRefreshRate) == Float.floatToIntBits(refreshRate);
1391 }
1392
1393 @Override
1394 public boolean equals(Object other) {
1395 if (this == other) {
1396 return true;
1397 }
1398 if (!(other instanceof Mode)) {
1399 return false;
1400 }
1401 Mode that = (Mode) other;
1402 return mModeId == that.mModeId && matches(that.mWidth, that.mHeight, that.mRefreshRate);
1403 }
1404
1405 @Override
1406 public int hashCode() {
1407 int hash = 1;
1408 hash = hash * 17 + mModeId;
1409 hash = hash * 17 + mWidth;
1410 hash = hash * 17 + mHeight;
1411 hash = hash * 17 + Float.floatToIntBits(mRefreshRate);
1412 return hash;
1413 }
1414
1415 @Override
1416 public String toString() {
1417 return new StringBuilder("{")
1418 .append("id=").append(mModeId)
1419 .append(", width=").append(mWidth)
1420 .append(", height=").append(mHeight)
1421 .append(", fps=").append(mRefreshRate)
1422 .append("}")
1423 .toString();
1424 }
1425
1426 @Override
1427 public int describeContents() {
1428 return 0;
1429 }
1430
1431 private Mode(Parcel in) {
1432 this(in.readInt(), in.readInt(), in.readInt(), in.readFloat());
1433 }
1434
1435 @Override
1436 public void writeToParcel(Parcel out, int parcelableFlags) {
1437 out.writeInt(mModeId);
1438 out.writeInt(mWidth);
1439 out.writeInt(mHeight);
1440 out.writeFloat(mRefreshRate);
1441 }
1442
1443 @SuppressWarnings("hiding")
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001444 public static final @android.annotation.NonNull Parcelable.Creator<Mode> CREATOR
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -07001445 = new Parcelable.Creator<Mode>() {
1446 @Override
1447 public Mode createFromParcel(Parcel in) {
1448 return new Mode(in);
1449 }
1450
1451 @Override
1452 public Mode[] newArray(int size) {
1453 return new Mode[size];
1454 }
1455 };
1456 }
Michael Wright58e829f2015-09-15 00:13:26 +01001457
1458 /**
Ronghua Wuf173c322016-02-29 13:57:18 -08001459 * Encapsulates the HDR capabilities of a given display.
1460 * For example, what HDR types it supports and details about the desired luminance data.
1461 * <p>You can get an instance for a given {@link Display} object with
1462 * {@link Display#getHdrCapabilities getHdrCapabilities()}.
Ronghua Wuf173c322016-02-29 13:57:18 -08001463 */
1464 public static final class HdrCapabilities implements Parcelable {
1465 /**
1466 * Invalid luminance value.
1467 */
1468 public static final float INVALID_LUMINANCE = -1;
1469 /**
1470 * Dolby Vision high dynamic range (HDR) display.
1471 */
1472 public static final int HDR_TYPE_DOLBY_VISION = 1;
1473 /**
1474 * HDR10 display.
1475 */
1476 public static final int HDR_TYPE_HDR10 = 2;
1477 /**
1478 * Hybrid Log-Gamma HDR display.
1479 */
1480 public static final int HDR_TYPE_HLG = 3;
1481
Peiyong Lin173ae082019-01-17 12:34:21 -08001482 /**
1483 * HDR10+ display.
1484 */
1485 public static final int HDR_TYPE_HDR10_PLUS = 4;
1486
Hangyu Kuangda802f52016-04-06 18:02:17 -07001487 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -07001488 @IntDef(prefix = { "HDR_TYPE_" }, value = {
1489 HDR_TYPE_DOLBY_VISION,
1490 HDR_TYPE_HDR10,
1491 HDR_TYPE_HLG,
Peiyong Lin173ae082019-01-17 12:34:21 -08001492 HDR_TYPE_HDR10_PLUS,
Ronghua Wuf173c322016-02-29 13:57:18 -08001493 })
1494 @Retention(RetentionPolicy.SOURCE)
1495 public @interface HdrType {}
1496
1497 private @HdrType int[] mSupportedHdrTypes = new int[0];
1498 private float mMaxLuminance = INVALID_LUMINANCE;
1499 private float mMaxAverageLuminance = INVALID_LUMINANCE;
1500 private float mMinLuminance = INVALID_LUMINANCE;
1501
Hangyu Kuangda802f52016-04-06 18:02:17 -07001502 /**
1503 * @hide
1504 */
Ronghua Wuf173c322016-02-29 13:57:18 -08001505 public HdrCapabilities() {
1506 }
1507
Hangyu Kuang1e7d1aa2016-05-17 14:21:01 -07001508 /**
1509 * @hide
1510 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001511 @UnsupportedAppUsage
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001512 public HdrCapabilities(int[] supportedHdrTypes, float maxLuminance,
1513 float maxAverageLuminance, float minLuminance) {
1514 mSupportedHdrTypes = supportedHdrTypes;
Marin Shalamanov677d3a72020-01-07 13:45:55 +01001515 Arrays.sort(mSupportedHdrTypes);
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001516 mMaxLuminance = maxLuminance;
1517 mMaxAverageLuminance = maxAverageLuminance;
1518 mMinLuminance = minLuminance;
1519 }
1520
Ronghua Wuf173c322016-02-29 13:57:18 -08001521 /**
1522 * Gets the supported HDR types of this display.
1523 * Returns empty array if HDR is not supported by the display.
1524 */
1525 public @HdrType int[] getSupportedHdrTypes() {
1526 return mSupportedHdrTypes;
1527 }
1528 /**
1529 * Returns the desired content max luminance data in cd/m2 for this display.
1530 */
1531 public float getDesiredMaxLuminance() {
1532 return mMaxLuminance;
1533 }
1534 /**
1535 * Returns the desired content max frame-average luminance data in cd/m2 for this display.
1536 */
1537 public float getDesiredMaxAverageLuminance() {
1538 return mMaxAverageLuminance;
1539 }
1540 /**
1541 * Returns the desired content min luminance data in cd/m2 for this display.
1542 */
1543 public float getDesiredMinLuminance() {
1544 return mMinLuminance;
1545 }
1546
Michael Wright16ae0422016-07-26 18:18:53 +01001547 @Override
1548 public boolean equals(Object other) {
1549 if (this == other) {
1550 return true;
1551 }
1552
1553 if (!(other instanceof HdrCapabilities)) {
1554 return false;
1555 }
1556 HdrCapabilities that = (HdrCapabilities) other;
1557
1558 return Arrays.equals(mSupportedHdrTypes, that.mSupportedHdrTypes)
1559 && mMaxLuminance == that.mMaxLuminance
1560 && mMaxAverageLuminance == that.mMaxAverageLuminance
1561 && mMinLuminance == that.mMinLuminance;
1562 }
1563
1564 @Override
1565 public int hashCode() {
1566 int hash = 23;
1567 hash = hash * 17 + Arrays.hashCode(mSupportedHdrTypes);
1568 hash = hash * 17 + Float.floatToIntBits(mMaxLuminance);
1569 hash = hash * 17 + Float.floatToIntBits(mMaxAverageLuminance);
1570 hash = hash * 17 + Float.floatToIntBits(mMinLuminance);
1571 return hash;
1572 }
1573
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001574 public static final @android.annotation.NonNull Creator<HdrCapabilities> CREATOR = new Creator<HdrCapabilities>() {
Ronghua Wuf173c322016-02-29 13:57:18 -08001575 @Override
1576 public HdrCapabilities createFromParcel(Parcel source) {
1577 return new HdrCapabilities(source);
1578 }
1579
1580 @Override
1581 public HdrCapabilities[] newArray(int size) {
1582 return new HdrCapabilities[size];
1583 }
1584 };
1585
1586 private HdrCapabilities(Parcel source) {
1587 readFromParcel(source);
1588 }
1589
Hangyu Kuangda802f52016-04-06 18:02:17 -07001590 /**
1591 * @hide
1592 */
Ronghua Wuf173c322016-02-29 13:57:18 -08001593 public void readFromParcel(Parcel source) {
1594 int types = source.readInt();
1595 mSupportedHdrTypes = new int[types];
1596 for (int i = 0; i < types; ++i) {
1597 mSupportedHdrTypes[i] = source.readInt();
1598 }
1599 mMaxLuminance = source.readFloat();
1600 mMaxAverageLuminance = source.readFloat();
1601 mMinLuminance = source.readFloat();
1602 }
1603
1604 @Override
1605 public void writeToParcel(Parcel dest, int flags) {
1606 dest.writeInt(mSupportedHdrTypes.length);
1607 for (int i = 0; i < mSupportedHdrTypes.length; ++i) {
1608 dest.writeInt(mSupportedHdrTypes[i]);
1609 }
1610 dest.writeFloat(mMaxLuminance);
1611 dest.writeFloat(mMaxAverageLuminance);
1612 dest.writeFloat(mMinLuminance);
1613 }
1614
1615 @Override
1616 public int describeContents() {
1617 return 0;
1618 }
Marin Shalamanov04c6a462019-12-10 15:47:59 +01001619
1620 @Override
1621 public String toString() {
1622 return "HdrCapabilities{"
1623 + "mSupportedHdrTypes=" + Arrays.toString(mSupportedHdrTypes)
1624 + ", mMaxLuminance=" + mMaxLuminance
1625 + ", mMaxAverageLuminance=" + mMaxAverageLuminance
1626 + ", mMinLuminance=" + mMinLuminance + '}';
1627 }
Ronghua Wuf173c322016-02-29 13:57:18 -08001628 }
Jeff Brown037c33e2014-04-09 00:31:55 -07001629}