The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.view; |
| 18 | |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE; |
| 20 | |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 21 | import android.annotation.IntDef; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 22 | import android.annotation.RequiresPermission; |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 23 | import android.annotation.UnsupportedAppUsage; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 24 | import android.app.KeyguardManager; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 25 | import android.content.res.CompatibilityInfo; |
Romain Guy | e89d0bb | 2017-06-20 12:23:42 -0700 | [diff] [blame] | 26 | import android.content.res.Configuration; |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 27 | import android.content.res.Resources; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 28 | import android.graphics.PixelFormat; |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 29 | import android.graphics.Point; |
| 30 | import android.graphics.Rect; |
Andrii Kulian | 732a90a | 2017-08-17 17:21:20 -0700 | [diff] [blame] | 31 | import android.hardware.display.DisplayManager; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 32 | import android.hardware.display.DisplayManagerGlobal; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 33 | import android.os.Parcel; |
| 34 | import android.os.Parcelable; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 35 | import android.os.Process; |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 36 | import android.os.SystemClock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.util.DisplayMetrics; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 38 | import android.util.Log; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 40 | import java.lang.annotation.Retention; |
| 41 | import java.lang.annotation.RetentionPolicy; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 42 | import java.util.Arrays; |
| 43 | |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 44 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 45 | * Provides information about the size and density of a logical display. |
| 46 | * <p> |
| 47 | * The display area is described in two different ways. |
| 48 | * <ul> |
| 49 | * <li>The application display area specifies the part of the display that may contain |
| 50 | * an application window, excluding the system decorations. The application display area may |
| 51 | * be smaller than the real display area because the system subtracts the space needed |
| 52 | * for decor elements such as the status bar. Use the following methods to query the |
| 53 | * application display area: {@link #getSize}, {@link #getRectSize} and {@link #getMetrics}.</li> |
| 54 | * <li>The real display area specifies the part of the display that contains content |
| 55 | * including the system decorations. Even so, the real display area may be smaller than the |
| 56 | * physical size of the display if the window manager is emulating a smaller display |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 57 | * using (adb shell wm size). Use the following methods to query the |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 58 | * real display area: {@link #getRealSize}, {@link #getRealMetrics}.</li> |
| 59 | * </ul> |
| 60 | * </p><p> |
| 61 | * A logical display does not necessarily represent a particular physical display device |
| 62 | * such as the built-in screen or an external monitor. The contents of a logical |
| 63 | * display may be presented on one or more physical displays according to the devices |
| 64 | * that are currently attached and whether mirroring has been enabled. |
| 65 | * </p> |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 66 | */ |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 67 | public final class Display { |
| 68 | private static final String TAG = "Display"; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 69 | private static final boolean DEBUG = false; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 70 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 71 | private final DisplayManagerGlobal mGlobal; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 72 | private final int mDisplayId; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 73 | private final int mLayerStack; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 74 | private final int mFlags; |
| 75 | private final int mType; |
| 76 | private final String mAddress; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 77 | private final int mOwnerUid; |
| 78 | private final String mOwnerPackageName; |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 79 | private final Resources mResources; |
| 80 | private DisplayAdjustments mDisplayAdjustments; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 81 | |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 82 | @UnsupportedAppUsage |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 83 | private DisplayInfo mDisplayInfo; // never null |
| 84 | private boolean mIsValid; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 85 | |
| 86 | // Temporary display metrics structure used for compatibility mode. |
| 87 | private final DisplayMetrics mTempMetrics = new DisplayMetrics(); |
| 88 | |
| 89 | // We cache the app width and height properties briefly between calls |
| 90 | // to getHeight() and getWidth() to ensure that applications perceive |
| 91 | // consistent results when the size changes (most of the time). |
| 92 | // Applications should now be using getSize() instead. |
| 93 | private static final int CACHED_APP_SIZE_DURATION_MILLIS = 20; |
| 94 | private long mLastCachedAppSizeUpdate; |
| 95 | private int mCachedAppWidthCompat; |
| 96 | private int mCachedAppHeightCompat; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 97 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 99 | * The default Display id, which is the id of the built-in primary display |
| 100 | * assuming there is one. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | */ |
| 102 | public static final int DEFAULT_DISPLAY = 0; |
| 103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | /** |
Wale Ogunwale | 2669851 | 2015-06-05 16:55:33 -0700 | [diff] [blame] | 105 | * Invalid display id. |
| 106 | */ |
| 107 | public static final int INVALID_DISPLAY = -1; |
| 108 | |
| 109 | /** |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 110 | * Display flag: Indicates that the display supports compositing content |
| 111 | * that is stored in protected graphics buffers. |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 112 | * <p> |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 113 | * If this flag is set then the display device supports compositing protected buffers. |
| 114 | * </p><p> |
| 115 | * If this flag is not set then the display device may not support compositing |
| 116 | * protected buffers; the user may see a blank region on the screen instead of |
| 117 | * the protected content. |
| 118 | * </p><p> |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 119 | * Secure (DRM) video decoders may allocate protected graphics buffers to request that |
| 120 | * a hardware-protected path be provided between the video decoder and the external |
| 121 | * display sink. If a hardware-protected path is not available, then content stored |
| 122 | * in protected graphics buffers may not be composited. |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 123 | * </p><p> |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 124 | * An application can use the absence of this flag as a hint that it should not use protected |
| 125 | * buffers for this display because the content may not be visible. For example, |
| 126 | * if the flag is not set then the application may choose not to show content on this |
| 127 | * display, show an informative error message, select an alternate content stream |
| 128 | * or adopt a different strategy for decoding content that does not rely on |
| 129 | * protected buffers. |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 130 | * </p> |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 131 | * |
| 132 | * @see #getFlags |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 133 | */ |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 134 | public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 0; |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 135 | |
| 136 | /** |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 137 | * Display flag: Indicates that the display has a secure video output and |
| 138 | * supports compositing secure surfaces. |
| 139 | * <p> |
| 140 | * If this flag is set then the display device has a secure video output |
| 141 | * and is capable of showing secure surfaces. It may also be capable of |
| 142 | * showing {@link #FLAG_SUPPORTS_PROTECTED_BUFFERS protected buffers}. |
| 143 | * </p><p> |
| 144 | * If this flag is not set then the display device may not have a secure video |
| 145 | * output; the user may see a blank region on the screen instead of |
| 146 | * the contents of secure surfaces or protected buffers. |
| 147 | * </p><p> |
| 148 | * Secure surfaces are used to prevent content rendered into those surfaces |
| 149 | * by applications from appearing in screenshots or from being viewed |
| 150 | * on non-secure displays. Protected buffers are used by secure video decoders |
| 151 | * for a similar purpose. |
| 152 | * </p><p> |
| 153 | * An application creates a window with a secure surface by specifying the |
| 154 | * {@link WindowManager.LayoutParams#FLAG_SECURE} window flag. |
| 155 | * Likewise, an application creates a {@link SurfaceView} with a secure surface |
| 156 | * by calling {@link SurfaceView#setSecure} before attaching the secure view to |
| 157 | * its containing window. |
| 158 | * </p><p> |
| 159 | * An application can use the absence of this flag as a hint that it should not create |
| 160 | * secure surfaces or protected buffers on this display because the content may |
| 161 | * not be visible. For example, if the flag is not set then the application may |
| 162 | * choose not to show content on this display, show an informative error message, |
| 163 | * select an alternate content stream or adopt a different strategy for decoding |
| 164 | * content that does not rely on secure surfaces or protected buffers. |
| 165 | * </p> |
| 166 | * |
| 167 | * @see #getFlags |
| 168 | */ |
| 169 | public static final int FLAG_SECURE = 1 << 1; |
| 170 | |
| 171 | /** |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 172 | * Display flag: Indicates that the display is private. Only the application that |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 173 | * owns the display and apps that are already on the display can create windows on it. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 174 | * |
| 175 | * @see #getFlags |
| 176 | */ |
| 177 | public static final int FLAG_PRIVATE = 1 << 2; |
| 178 | |
| 179 | /** |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 180 | * Display flag: Indicates that the display is a presentation display. |
| 181 | * <p> |
| 182 | * This flag identifies secondary displays that are suitable for |
| 183 | * use as presentation displays such as HDMI or Wireless displays. Applications |
| 184 | * may automatically project their content to presentation displays to provide |
| 185 | * richer second screen experiences. |
| 186 | * </p> |
| 187 | * |
| 188 | * @see #getFlags |
| 189 | */ |
| 190 | public static final int FLAG_PRESENTATION = 1 << 3; |
| 191 | |
| 192 | /** |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 193 | * Display flag: Indicates that the display has a round shape. |
| 194 | * <p> |
| 195 | * This flag identifies displays that are circular, elliptical or otherwise |
| 196 | * do not permit the user to see all the way to the logical corners of the display. |
| 197 | * </p> |
| 198 | * |
| 199 | * @see #getFlags |
| 200 | */ |
| 201 | public static final int FLAG_ROUND = 1 << 4; |
| 202 | |
| 203 | /** |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 204 | * Display flag: Indicates that the display can show its content when non-secure keyguard is |
| 205 | * shown. |
| 206 | * <p> |
Andrii Kulian | 732a90a | 2017-08-17 17:21:20 -0700 | [diff] [blame] | 207 | * This flag identifies secondary displays that will continue showing content if keyguard can be |
| 208 | * dismissed without entering credentials. |
| 209 | * </p><p> |
| 210 | * An example of usage is a virtual display which content is displayed on external hardware |
| 211 | * display that is not visible to the system directly. |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 212 | * </p> |
| 213 | * |
Andrii Kulian | 732a90a | 2017-08-17 17:21:20 -0700 | [diff] [blame] | 214 | * @see DisplayManager#VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 215 | * @see KeyguardManager#isDeviceSecure() |
| 216 | * @see KeyguardManager#isDeviceLocked() |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 217 | * @see #getFlags |
Andrii Kulian | 22512e8 | 2017-04-13 11:34:43 -0700 | [diff] [blame] | 218 | * @hide |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 219 | */ |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 220 | public static final int FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 5; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 221 | |
| 222 | /** |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 223 | * Display flag: Indicates that the contents of the display should not be scaled |
| 224 | * to fit the physical screen dimensions. Used for development only to emulate |
| 225 | * devices with smaller physicals screens while preserving density. |
| 226 | * |
| 227 | * @hide |
| 228 | */ |
| 229 | public static final int FLAG_SCALING_DISABLED = 1 << 30; |
| 230 | |
| 231 | /** |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 232 | * Display type: Unknown display type. |
| 233 | * @hide |
| 234 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 235 | @UnsupportedAppUsage |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 236 | public static final int TYPE_UNKNOWN = 0; |
| 237 | |
| 238 | /** |
| 239 | * Display type: Built-in display. |
| 240 | * @hide |
| 241 | */ |
| 242 | public static final int TYPE_BUILT_IN = 1; |
| 243 | |
| 244 | /** |
| 245 | * Display type: HDMI display. |
| 246 | * @hide |
| 247 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 248 | @UnsupportedAppUsage |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 249 | public static final int TYPE_HDMI = 2; |
| 250 | |
| 251 | /** |
| 252 | * Display type: WiFi display. |
| 253 | * @hide |
| 254 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 255 | @UnsupportedAppUsage |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 256 | public static final int TYPE_WIFI = 3; |
| 257 | |
| 258 | /** |
| 259 | * Display type: Overlay display. |
| 260 | * @hide |
| 261 | */ |
| 262 | public static final int TYPE_OVERLAY = 4; |
| 263 | |
| 264 | /** |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 265 | * Display type: Virtual display. |
| 266 | * @hide |
| 267 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 268 | @UnsupportedAppUsage |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 269 | public static final int TYPE_VIRTUAL = 5; |
| 270 | |
| 271 | /** |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 272 | * Display state: The display state is unknown. |
| 273 | * |
| 274 | * @see #getState |
| 275 | */ |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 276 | public static final int STATE_UNKNOWN = ViewProtoEnums.DISPLAY_STATE_UNKNOWN; // 0 |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 277 | |
| 278 | /** |
| 279 | * Display state: The display is off. |
| 280 | * |
| 281 | * @see #getState |
| 282 | */ |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 283 | public static final int STATE_OFF = ViewProtoEnums.DISPLAY_STATE_OFF; // 1 |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 284 | |
| 285 | /** |
| 286 | * Display state: The display is on. |
| 287 | * |
| 288 | * @see #getState |
| 289 | */ |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 290 | public static final int STATE_ON = ViewProtoEnums.DISPLAY_STATE_ON; // 2 |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 291 | |
| 292 | /** |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 293 | * Display state: The display is dozing in a low power state; it is still |
| 294 | * on but is optimized for showing system-provided content while the |
| 295 | * device is non-interactive. |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 296 | * |
| 297 | * @see #getState |
| 298 | * @see android.os.PowerManager#isInteractive |
| 299 | */ |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 300 | public static final int STATE_DOZE = ViewProtoEnums.DISPLAY_STATE_DOZE; // 3 |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 301 | |
| 302 | /** |
| 303 | * Display state: The display is dozing in a suspended low power state; it is still |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 304 | * on but the CPU is not updating it. This may be used in one of two ways: to show |
| 305 | * static system-provided content while the device is non-interactive, or to allow |
| 306 | * a "Sidekick" compute resource to update the display. For this reason, the |
| 307 | * CPU must not control the display in this mode. |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 308 | * |
| 309 | * @see #getState |
| 310 | * @see android.os.PowerManager#isInteractive |
| 311 | */ |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 312 | public static final int STATE_DOZE_SUSPEND = ViewProtoEnums.DISPLAY_STATE_DOZE_SUSPEND; // 4 |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 313 | |
Santos Cordon | 3107d29 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 314 | /** |
| 315 | * Display state: The display is on and optimized for VR mode. |
| 316 | * |
| 317 | * @see #getState |
| 318 | * @see android.os.PowerManager#isInteractive |
Santos Cordon | 3107d29 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 319 | */ |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 320 | public static final int STATE_VR = ViewProtoEnums.DISPLAY_STATE_VR; // 5 |
Santos Cordon | 3107d29 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 321 | |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 322 | /** |
| 323 | * Display state: The display is in a suspended full power state; it is still |
| 324 | * 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. |
| 328 | * |
| 329 | * @see #getState |
| 330 | * @see android.os.PowerManager#isInteractive |
| 331 | */ |
Bookatz | 1a1b046 | 2018-01-12 11:47:03 -0800 | [diff] [blame] | 332 | public static final int STATE_ON_SUSPEND = ViewProtoEnums.DISPLAY_STATE_ON_SUSPEND; // 6 |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 333 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 334 | /* The color mode constants defined below must be kept in sync with the ones in |
Romain Guy | 6d228c2 | 2017-01-20 18:41:06 -0800 | [diff] [blame] | 335 | * system/core/include/system/graphics-base.h */ |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 336 | |
| 337 | /** |
| 338 | * Display color mode: The current color mode is unknown or invalid. |
| 339 | * @hide |
| 340 | */ |
| 341 | public static final int COLOR_MODE_INVALID = -1; |
| 342 | |
| 343 | /** |
| 344 | * Display color mode: The default or native gamut of the display. |
| 345 | * @hide |
| 346 | */ |
| 347 | public static final int COLOR_MODE_DEFAULT = 0; |
| 348 | |
Romain Guy | 6d228c2 | 2017-01-20 18:41:06 -0800 | [diff] [blame] | 349 | /** @hide */ |
| 350 | public static final int COLOR_MODE_BT601_625 = 1; |
| 351 | /** @hide */ |
| 352 | public static final int COLOR_MODE_BT601_625_UNADJUSTED = 2; |
| 353 | /** @hide */ |
| 354 | public static final int COLOR_MODE_BT601_525 = 3; |
| 355 | /** @hide */ |
| 356 | public static final int COLOR_MODE_BT601_525_UNADJUSTED = 4; |
| 357 | /** @hide */ |
| 358 | public static final int COLOR_MODE_BT709 = 5; |
| 359 | /** @hide */ |
| 360 | public static final int COLOR_MODE_DCI_P3 = 6; |
| 361 | /** @hide */ |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 362 | public static final int COLOR_MODE_SRGB = 7; |
Romain Guy | 6d228c2 | 2017-01-20 18:41:06 -0800 | [diff] [blame] | 363 | /** @hide */ |
| 364 | public static final int COLOR_MODE_ADOBE_RGB = 8; |
| 365 | /** @hide */ |
| 366 | public static final int COLOR_MODE_DISPLAY_P3 = 9; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 367 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 368 | /** |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 369 | * Indicates that when display is removed, all its activities will be moved to the primary |
| 370 | * display and the topmost activity should become focused. |
| 371 | * |
| 372 | * @hide |
| 373 | */ |
| 374 | public static final int REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY = 0; |
| 375 | /** |
| 376 | * Indicates that when display is removed, all its stacks and tasks will be removed, all |
| 377 | * activities will be destroyed according to the usual lifecycle. |
| 378 | * |
| 379 | * @hide |
| 380 | */ |
| 381 | public static final int REMOVE_MODE_DESTROY_CONTENT = 1; |
| 382 | |
| 383 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 384 | * Internal method to create a display. |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 385 | * The display created with this method will have a static {@link DisplayAdjustments} applied. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 386 | * Applications should use {@link android.view.WindowManager#getDefaultDisplay()} |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 387 | * or {@link android.hardware.display.DisplayManager#getDisplay} |
| 388 | * to get a display object. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 389 | * |
| 390 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | */ |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 392 | public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo, |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 393 | DisplayAdjustments daj) { |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 394 | this(global, displayId, displayInfo, daj, null /*res*/); |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Internal method to create a display. |
| 399 | * The display created with this method will be adjusted based on the adjustments in the |
| 400 | * supplied {@link Resources}. |
| 401 | * |
| 402 | * @hide |
| 403 | */ |
| 404 | public Display(DisplayManagerGlobal global, int displayId, /*@NotNull*/ DisplayInfo displayInfo, |
| 405 | Resources res) { |
| 406 | this(global, displayId, displayInfo, null /*daj*/, res); |
| 407 | } |
| 408 | |
| 409 | private Display(DisplayManagerGlobal global, int displayId, |
| 410 | /*@NotNull*/ DisplayInfo displayInfo, DisplayAdjustments daj, Resources res) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 411 | mGlobal = global; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 412 | mDisplayId = displayId; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 413 | mDisplayInfo = displayInfo; |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 414 | mResources = res; |
| 415 | mDisplayAdjustments = mResources != null |
| 416 | ? new DisplayAdjustments(mResources.getConfiguration()) |
| 417 | : daj != null ? new DisplayAdjustments(daj) : null; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 418 | mIsValid = true; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 419 | |
| 420 | // Cache properties that cannot change as long as the display is valid. |
| 421 | mLayerStack = displayInfo.layerStack; |
| 422 | mFlags = displayInfo.flags; |
| 423 | mType = displayInfo.type; |
| 424 | mAddress = displayInfo.address; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 425 | mOwnerUid = displayInfo.ownerUid; |
| 426 | mOwnerPackageName = displayInfo.ownerPackageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | } |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 430 | * Gets the display id. |
| 431 | * <p> |
| 432 | * Each logical display has a unique id. |
| 433 | * The default display has id {@link #DEFAULT_DISPLAY}. |
| 434 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | */ |
| 436 | public int getDisplayId() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 437 | return mDisplayId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 441 | * Returns true if this display is still valid, false if the display has been removed. |
| 442 | * |
| 443 | * If the display is invalid, then the methods of this class will |
| 444 | * continue to report the most recently observed display information. |
| 445 | * However, it is unwise (and rather fruitless) to continue using a |
| 446 | * {@link Display} object after the display's demise. |
| 447 | * |
| 448 | * It's possible for a display that was previously invalid to become |
| 449 | * valid again if a display with the same id is reconnected. |
| 450 | * |
| 451 | * @return True if the display is still valid. |
| 452 | */ |
| 453 | public boolean isValid() { |
| 454 | synchronized (this) { |
| 455 | updateDisplayInfoLocked(); |
| 456 | return mIsValid; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | /** |
Jeff Brown | 2ab1b7d9 | 2012-08-08 01:46:41 -0700 | [diff] [blame] | 461 | * Gets a full copy of the display information. |
| 462 | * |
| 463 | * @param outDisplayInfo The object to receive the copy of the display information. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 464 | * @return True if the display is still valid. |
Jeff Brown | 2ab1b7d9 | 2012-08-08 01:46:41 -0700 | [diff] [blame] | 465 | * @hide |
| 466 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 467 | @UnsupportedAppUsage |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 468 | public boolean getDisplayInfo(DisplayInfo outDisplayInfo) { |
Jeff Brown | 2ab1b7d9 | 2012-08-08 01:46:41 -0700 | [diff] [blame] | 469 | synchronized (this) { |
| 470 | updateDisplayInfoLocked(); |
| 471 | outDisplayInfo.copyFrom(mDisplayInfo); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 472 | return mIsValid; |
Jeff Brown | 2ab1b7d9 | 2012-08-08 01:46:41 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
| 476 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 477 | * Gets the display's layer stack. |
| 478 | * |
| 479 | * Each display has its own independent layer stack upon which surfaces |
| 480 | * are placed to be managed by surface flinger. |
| 481 | * |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 482 | * @return The display's layer stack number. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 483 | * @hide |
| 484 | */ |
| 485 | public int getLayerStack() { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 486 | return mLayerStack; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /** |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 490 | * Returns a combination of flags that describe the capabilities of the display. |
| 491 | * |
| 492 | * @return The display flags. |
| 493 | * |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 494 | * @see #FLAG_SUPPORTS_PROTECTED_BUFFERS |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 495 | * @see #FLAG_SECURE |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 496 | * @see #FLAG_PRIVATE |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 497 | */ |
| 498 | public int getFlags() { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 499 | return mFlags; |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Gets the display type. |
| 504 | * |
| 505 | * @return The display type. |
| 506 | * |
| 507 | * @see #TYPE_UNKNOWN |
| 508 | * @see #TYPE_BUILT_IN |
| 509 | * @see #TYPE_HDMI |
| 510 | * @see #TYPE_WIFI |
| 511 | * @see #TYPE_OVERLAY |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 512 | * @see #TYPE_VIRTUAL |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 513 | * @hide |
| 514 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 515 | @UnsupportedAppUsage |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 516 | public int getType() { |
| 517 | return mType; |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * Gets the display address, or null if none. |
| 522 | * Interpretation varies by display type. |
| 523 | * |
| 524 | * @return The display address. |
| 525 | * @hide |
| 526 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 527 | @UnsupportedAppUsage |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 528 | public String getAddress() { |
| 529 | return mAddress; |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /** |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 533 | * Gets the UID of the application that owns this display, or zero if it is |
| 534 | * owned by the system. |
| 535 | * <p> |
| 536 | * If the display is private, then only the owner can use it. |
| 537 | * </p> |
| 538 | * |
| 539 | * @hide |
| 540 | */ |
| 541 | public int getOwnerUid() { |
| 542 | return mOwnerUid; |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * Gets the package name of the application that owns this display, or null if it is |
| 547 | * owned by the system. |
| 548 | * <p> |
| 549 | * If the display is private, then only the owner can use it. |
| 550 | * </p> |
| 551 | * |
| 552 | * @hide |
| 553 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 554 | @UnsupportedAppUsage |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 555 | public String getOwnerPackageName() { |
| 556 | return mOwnerPackageName; |
| 557 | } |
| 558 | |
| 559 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 560 | * Gets the compatibility info used by this display instance. |
| 561 | * |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 562 | * @return The display adjustments holder, or null if none is required. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 563 | * @hide |
| 564 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 565 | @UnsupportedAppUsage |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 566 | public DisplayAdjustments getDisplayAdjustments() { |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 567 | if (mResources != null) { |
| 568 | final DisplayAdjustments currentAdjustements = mResources.getDisplayAdjustments(); |
| 569 | if (!mDisplayAdjustments.equals(currentAdjustements)) { |
| 570 | mDisplayAdjustments = new DisplayAdjustments(currentAdjustements); |
| 571 | } |
| 572 | } |
| 573 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 574 | return mDisplayAdjustments; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 578 | * Gets the name of the display. |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 579 | * <p> |
| 580 | * Note that some displays may be renamed by the user. |
| 581 | * </p> |
| 582 | * |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 583 | * @return The display's name. |
| 584 | */ |
| 585 | public String getName() { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 586 | synchronized (this) { |
| 587 | updateDisplayInfoLocked(); |
| 588 | return mDisplayInfo.name; |
| 589 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /** |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 593 | * Gets the size of the display, in pixels. |
Andrii Kulian | 5f57a3d | 2016-06-28 18:41:42 -0700 | [diff] [blame] | 594 | * Value returned by this method does not necessarily represent the actual raw size |
| 595 | * (native resolution) of the display. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 596 | * <p> |
Andrii Kulian | 5f57a3d | 2016-06-28 18:41:42 -0700 | [diff] [blame] | 597 | * 1. The returned size may be adjusted to exclude certain system decor elements |
| 598 | * that are always visible. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 599 | * </p><p> |
Andrii Kulian | 5f57a3d | 2016-06-28 18:41:42 -0700 | [diff] [blame] | 600 | * 2. It may be scaled to provide compatibility with older applications that |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 601 | * were originally designed for smaller displays. |
Andrii Kulian | 5f57a3d | 2016-06-28 18:41:42 -0700 | [diff] [blame] | 602 | * </p><p> |
| 603 | * 3. It can be different depending on the WindowManager to which the display belongs. |
| 604 | * </p><p> |
| 605 | * - If requested from non-Activity context (e.g. Application context via |
| 606 | * {@code (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)}) |
| 607 | * it will report the size of the entire display based on current rotation and with subtracted |
| 608 | * system decoration areas. |
| 609 | * </p><p> |
| 610 | * - If requested from activity (either using {@code getWindowManager()} or |
| 611 | * {@code (WindowManager) getSystemService(Context.WINDOW_SERVICE)}) resulting size will |
| 612 | * correspond to current app window size. In this case it can be smaller than physical size in |
| 613 | * multi-window mode. |
| 614 | * </p><p> |
| 615 | * Typically for the purposes of layout apps should make a request from activity context |
| 616 | * to obtain size available for the app content. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 617 | * </p> |
| 618 | * |
| 619 | * @param outSize A {@link Point} object to receive the size information. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | */ |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 621 | public void getSize(Point outSize) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 622 | synchronized (this) { |
| 623 | updateDisplayInfoLocked(); |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 624 | mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments()); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 625 | outSize.x = mTempMetrics.widthPixels; |
| 626 | outSize.y = mTempMetrics.heightPixels; |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | /** |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 631 | * Gets the size of the display as a rectangle, in pixels. |
| 632 | * |
| 633 | * @param outSize A {@link Rect} object to receive the size information. |
| 634 | * @see #getSize(Point) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | */ |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 636 | public void getRectSize(Rect outSize) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 637 | synchronized (this) { |
| 638 | updateDisplayInfoLocked(); |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 639 | mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments()); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 640 | outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels); |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
| 644 | /** |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 645 | * Return the range of display sizes an application can expect to encounter |
| 646 | * under normal operation, as long as there is no physical change in screen |
| 647 | * size. This is basically the sizes you will see as the orientation |
| 648 | * changes, taking into account whatever screen decoration there is in |
| 649 | * each rotation. For example, the status bar is always at the top of the |
| 650 | * screen, so it will reduce the height both in landscape and portrait, and |
| 651 | * the smallest height returned here will be the smaller of the two. |
| 652 | * |
| 653 | * This is intended for applications to get an idea of the range of sizes |
| 654 | * they will encounter while going through device rotations, to provide a |
| 655 | * stable UI through rotation. The sizes here take into account all standard |
| 656 | * system decorations that reduce the size actually available to the |
| 657 | * application: the status bar, navigation bar, system bar, etc. It does |
| 658 | * <em>not</em> take into account more transient elements like an IME |
| 659 | * soft keyboard. |
| 660 | * |
| 661 | * @param outSmallestSize Filled in with the smallest width and height |
| 662 | * that the application will encounter, in pixels (not dp units). The x |
| 663 | * (width) dimension here directly corresponds to |
| 664 | * {@link android.content.res.Configuration#smallestScreenWidthDp |
| 665 | * Configuration.smallestScreenWidthDp}, except the value here is in raw |
| 666 | * screen pixels rather than dp units. Your application may of course |
| 667 | * still get smaller space yet if, for example, a soft keyboard is |
| 668 | * being displayed. |
| 669 | * @param outLargestSize Filled in with the largest width and height |
| 670 | * that the application will encounter, in pixels (not dp units). Your |
| 671 | * application may of course still get larger space than this if, |
| 672 | * for example, screen decorations like the status bar are being hidden. |
| 673 | */ |
| 674 | public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 675 | synchronized (this) { |
| 676 | updateDisplayInfoLocked(); |
| 677 | outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth; |
| 678 | outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight; |
| 679 | outLargestSize.x = mDisplayInfo.largestNominalAppWidth; |
| 680 | outLargestSize.y = mDisplayInfo.largestNominalAppHeight; |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | |
| 684 | /** |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 685 | * Return the maximum screen size dimension that will happen. This is |
| 686 | * mostly for wallpapers. |
| 687 | * @hide |
| 688 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 689 | @UnsupportedAppUsage |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 690 | public int getMaximumSizeDimension() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 691 | synchronized (this) { |
| 692 | updateDisplayInfoLocked(); |
| 693 | return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight); |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
| 697 | /** |
| 698 | * @deprecated Use {@link #getSize(Point)} instead. |
| 699 | */ |
| 700 | @Deprecated |
| 701 | public int getWidth() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 702 | synchronized (this) { |
| 703 | updateCachedAppSizeIfNeededLocked(); |
| 704 | return mCachedAppWidthCompat; |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * @deprecated Use {@link #getSize(Point)} instead. |
| 710 | */ |
| 711 | @Deprecated |
| 712 | public int getHeight() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 713 | synchronized (this) { |
| 714 | updateCachedAppSizeIfNeededLocked(); |
| 715 | return mCachedAppHeightCompat; |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 719 | /** |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 720 | * @hide |
| 721 | * Return a rectangle defining the insets of the overscan region of the display. |
| 722 | * Each field of the rectangle is the number of pixels the overscan area extends |
| 723 | * into the display on that side. |
| 724 | */ |
| 725 | public void getOverscanInsets(Rect outRect) { |
| 726 | synchronized (this) { |
| 727 | updateDisplayInfoLocked(); |
| 728 | outRect.set(mDisplayInfo.overscanLeft, mDisplayInfo.overscanTop, |
| 729 | mDisplayInfo.overscanRight, mDisplayInfo.overscanBottom); |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | /** |
Dianne Hackborn | 5cb70b5 | 2010-02-25 17:01:14 -0800 | [diff] [blame] | 734 | * Returns the rotation of the screen from its "natural" orientation. |
| 735 | * The returned value may be {@link Surface#ROTATION_0 Surface.ROTATION_0} |
| 736 | * (no rotation), {@link Surface#ROTATION_90 Surface.ROTATION_90}, |
| 737 | * {@link Surface#ROTATION_180 Surface.ROTATION_180}, or |
| 738 | * {@link Surface#ROTATION_270 Surface.ROTATION_270}. For |
| 739 | * example, if a device has a naturally tall screen, and the user has |
| 740 | * turned it on its side to go into a landscape orientation, the value |
| 741 | * returned here may be either {@link Surface#ROTATION_90 Surface.ROTATION_90} |
| 742 | * or {@link Surface#ROTATION_270 Surface.ROTATION_270} depending on |
| 743 | * the direction it was turned. The angle is the rotation of the drawn |
| 744 | * graphics on the screen, which is the opposite direction of the physical |
| 745 | * rotation of the device. For example, if the device is rotated 90 |
| 746 | * degrees counter-clockwise, to compensate rendering will be rotated by |
| 747 | * 90 degrees clockwise and thus the returned value here will be |
| 748 | * {@link Surface#ROTATION_90 Surface.ROTATION_90}. |
| 749 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 750 | @Surface.Rotation |
Dianne Hackborn | 5cb70b5 | 2010-02-25 17:01:14 -0800 | [diff] [blame] | 751 | public int getRotation() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 752 | synchronized (this) { |
| 753 | updateDisplayInfoLocked(); |
| 754 | return mDisplayInfo.rotation; |
| 755 | } |
Dianne Hackborn | 5cb70b5 | 2010-02-25 17:01:14 -0800 | [diff] [blame] | 756 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 757 | |
Dianne Hackborn | 5cb70b5 | 2010-02-25 17:01:14 -0800 | [diff] [blame] | 758 | /** |
Joe Onorato | 4c904a3 | 2010-02-26 12:35:55 -0800 | [diff] [blame] | 759 | * @deprecated use {@link #getRotation} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | * @return orientation of this display. |
| 761 | */ |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 762 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 763 | @Surface.Rotation |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 764 | public int getOrientation() { |
| 765 | return getRotation(); |
| 766 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | |
| 768 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 769 | * Gets the pixel format of the display. |
| 770 | * @return One of the constants defined in {@link android.graphics.PixelFormat}. |
| 771 | * |
| 772 | * @deprecated This method is no longer supported. |
| 773 | * The result is always {@link PixelFormat#RGBA_8888}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | */ |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 775 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | public int getPixelFormat() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 777 | return PixelFormat.RGBA_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 781 | * Gets the refresh rate of this display in frames per second. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | */ |
| 783 | public float getRefreshRate() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 784 | synchronized (this) { |
| 785 | updateDisplayInfoLocked(); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 786 | return mDisplayInfo.getMode().getRefreshRate(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 787 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 790 | /** |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 791 | * Get the supported refresh rates of this display in frames per second. |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 792 | * <p> |
| 793 | * This method only returns refresh rates for the display's default modes. For more options, use |
| 794 | * {@link #getSupportedModes()}. |
| 795 | * |
| 796 | * @deprecated use {@link #getSupportedModes()} instead |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 797 | */ |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 798 | @Deprecated |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 799 | public float[] getSupportedRefreshRates() { |
| 800 | synchronized (this) { |
| 801 | updateDisplayInfoLocked(); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 802 | return mDisplayInfo.getDefaultRefreshRates(); |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | /** |
| 807 | * Returns the active mode of the display. |
| 808 | */ |
| 809 | public Mode getMode() { |
| 810 | synchronized (this) { |
| 811 | updateDisplayInfoLocked(); |
| 812 | return mDisplayInfo.getMode(); |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | /** |
| 817 | * Gets the supported modes of this display. |
| 818 | */ |
| 819 | public Mode[] getSupportedModes() { |
| 820 | synchronized (this) { |
| 821 | updateDisplayInfoLocked(); |
| 822 | final Display.Mode[] modes = mDisplayInfo.supportedModes; |
| 823 | return Arrays.copyOf(modes, modes.length); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | |
| 827 | /** |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 828 | * Request the display applies a color mode. |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 829 | * @hide |
| 830 | */ |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 831 | @RequiresPermission(CONFIGURE_DISPLAY_COLOR_MODE) |
| 832 | public void requestColorMode(int colorMode) { |
| 833 | mGlobal.requestColorMode(mDisplayId, colorMode); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | /** |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 837 | * Returns the active color mode of this display |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 838 | * @hide |
| 839 | */ |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 840 | public int getColorMode() { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 841 | synchronized (this) { |
| 842 | updateDisplayInfoLocked(); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 843 | return mDisplayInfo.colorMode; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | |
| 847 | /** |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 848 | * @hide |
| 849 | * Get current remove mode of the display - what actions should be performed with the display's |
| 850 | * content when it is removed. Default behavior for public displays in this case is to move all |
| 851 | * activities to the primary display and make it focused. For private display - destroy all |
| 852 | * activities. |
| 853 | * |
| 854 | * @see #REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY |
| 855 | * @see #REMOVE_MODE_DESTROY_CONTENT |
| 856 | */ |
| 857 | public int getRemoveMode() { |
| 858 | return mDisplayInfo.removeMode; |
| 859 | } |
| 860 | |
| 861 | /** |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 862 | * Returns the display's HDR capabilities. |
Romain Guy | 6d228c2 | 2017-01-20 18:41:06 -0800 | [diff] [blame] | 863 | * |
| 864 | * @see #isHdr() |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 865 | */ |
| 866 | public HdrCapabilities getHdrCapabilities() { |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 867 | synchronized (this) { |
| 868 | updateDisplayInfoLocked(); |
| 869 | return mDisplayInfo.hdrCapabilities; |
| 870 | } |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /** |
Romain Guy | 6d228c2 | 2017-01-20 18:41:06 -0800 | [diff] [blame] | 874 | * Returns whether this display supports any HDR type. |
| 875 | * |
| 876 | * @see #getHdrCapabilities() |
| 877 | * @see HdrCapabilities#getSupportedHdrTypes() |
| 878 | */ |
| 879 | public boolean isHdr() { |
| 880 | synchronized (this) { |
| 881 | updateDisplayInfoLocked(); |
Romain Guy | 408afbf | 2017-01-25 10:23:03 -0800 | [diff] [blame] | 882 | return mDisplayInfo.isHdr(); |
Romain Guy | 6d228c2 | 2017-01-20 18:41:06 -0800 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | |
| 886 | /** |
| 887 | * Returns whether this display can be used to display wide color gamut content. |
Romain Guy | e89d0bb | 2017-06-20 12:23:42 -0700 | [diff] [blame] | 888 | * This does not necessarily mean the device itself can render wide color gamut |
| 889 | * content. To ensure wide color gamut content can be produced, refer to |
| 890 | * {@link Configuration#isScreenWideColorGamut()}. |
Romain Guy | 6d228c2 | 2017-01-20 18:41:06 -0800 | [diff] [blame] | 891 | */ |
| 892 | public boolean isWideColorGamut() { |
| 893 | synchronized (this) { |
| 894 | updateDisplayInfoLocked(); |
Romain Guy | 408afbf | 2017-01-25 10:23:03 -0800 | [diff] [blame] | 895 | return mDisplayInfo.isWideColorGamut(); |
Romain Guy | 6d228c2 | 2017-01-20 18:41:06 -0800 | [diff] [blame] | 896 | } |
| 897 | } |
| 898 | |
| 899 | /** |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 900 | * Gets the supported color modes of this device. |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 901 | * @hide |
| 902 | */ |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 903 | public int[] getSupportedColorModes() { |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 904 | synchronized (this) { |
| 905 | updateDisplayInfoLocked(); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 906 | int[] colorModes = mDisplayInfo.supportedColorModes; |
| 907 | return Arrays.copyOf(colorModes, colorModes.length); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
| 911 | /** |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 912 | * Gets the app VSYNC offset, in nanoseconds. This is a positive value indicating |
| 913 | * the phase offset of the VSYNC events provided by Choreographer relative to the |
| 914 | * display refresh. For example, if Choreographer reports that the refresh occurred |
| 915 | * at time N, it actually occurred at (N - appVsyncOffset). |
| 916 | * <p> |
| 917 | * Apps generally do not need to be aware of this. It's only useful for fine-grained |
| 918 | * A/V synchronization. |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 919 | */ |
| 920 | public long getAppVsyncOffsetNanos() { |
| 921 | synchronized (this) { |
| 922 | updateDisplayInfoLocked(); |
| 923 | return mDisplayInfo.appVsyncOffsetNanos; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | /** |
| 928 | * This is how far in advance a buffer must be queued for presentation at |
| 929 | * a given time. If you want a buffer to appear on the screen at |
| 930 | * time N, you must submit the buffer before (N - presentationDeadline). |
| 931 | * <p> |
| 932 | * The desired presentation time for GLES rendering may be set with |
| 933 | * {@link android.opengl.EGLExt#eglPresentationTimeANDROID}. For video decoding, use |
| 934 | * {@link android.media.MediaCodec#releaseOutputBuffer(int, long)}. Times are |
| 935 | * expressed in nanoseconds, using the system monotonic clock |
| 936 | * ({@link System#nanoTime}). |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 937 | */ |
| 938 | public long getPresentationDeadlineNanos() { |
| 939 | synchronized (this) { |
| 940 | updateDisplayInfoLocked(); |
| 941 | return mDisplayInfo.presentationDeadlineNanos; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | /** |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 946 | * Gets display metrics that describe the size and density of this display. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 947 | * The size returned by this method does not necessarily represent the |
Andrii Kulian | a4bb9d3 | 2016-03-11 11:52:22 -0800 | [diff] [blame] | 948 | * actual raw size (native resolution) of the display. |
| 949 | * <p> |
| 950 | * 1. The returned size may be adjusted to exclude certain system decor elements |
| 951 | * that are always visible. |
| 952 | * </p><p> |
| 953 | * 2. It may be scaled to provide compatibility with older applications that |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 954 | * were originally designed for smaller displays. |
Andrii Kulian | a4bb9d3 | 2016-03-11 11:52:22 -0800 | [diff] [blame] | 955 | * </p><p> |
| 956 | * 3. It can be different depending on the WindowManager to which the display belongs. |
Andrii Kulian | 5f57a3d | 2016-06-28 18:41:42 -0700 | [diff] [blame] | 957 | * </p><p> |
Andrii Kulian | a4bb9d3 | 2016-03-11 11:52:22 -0800 | [diff] [blame] | 958 | * - If requested from non-Activity context (e.g. Application context via |
| 959 | * {@code (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)}) |
Andrii Kulian | 5f57a3d | 2016-06-28 18:41:42 -0700 | [diff] [blame] | 960 | * metrics will report the size of the entire display based on current rotation and with |
| 961 | * subtracted system decoration areas. |
| 962 | * </p><p> |
| 963 | * - If requested from activity (either using {@code getWindowManager()} or |
| 964 | * {@code (WindowManager) getSystemService(Context.WINDOW_SERVICE)}) resulting metrics will |
| 965 | * correspond to current app window metrics. In this case the size can be smaller than physical |
| 966 | * size in multi-window mode. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 967 | * </p> |
| 968 | * |
| 969 | * @param outMetrics A {@link DisplayMetrics} object to receive the metrics. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | */ |
| 971 | public void getMetrics(DisplayMetrics outMetrics) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 972 | synchronized (this) { |
| 973 | updateDisplayInfoLocked(); |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 974 | mDisplayInfo.getAppMetrics(outMetrics, getDisplayAdjustments()); |
Dianne Hackborn | 68066c2 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 975 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 976 | } |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 977 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 978 | /** |
| 979 | * Gets the real size of the display without subtracting any window decor or |
| 980 | * applying any compatibility scale factors. |
| 981 | * <p> |
| 982 | * The size is adjusted based on the current rotation of the display. |
| 983 | * </p><p> |
| 984 | * The real size may be smaller than the physical size of the screen when the |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 985 | * window manager is emulating a smaller display (using adb shell wm size). |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 986 | * </p> |
| 987 | * |
| 988 | * @param outSize Set to the real size of the display. |
| 989 | */ |
| 990 | public void getRealSize(Point outSize) { |
| 991 | synchronized (this) { |
| 992 | updateDisplayInfoLocked(); |
| 993 | outSize.x = mDisplayInfo.logicalWidth; |
| 994 | outSize.y = mDisplayInfo.logicalHeight; |
| 995 | } |
Dianne Hackborn | 68066c2 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | /** |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 999 | * Gets display metrics based on the real size of this display. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1000 | * <p> |
| 1001 | * The size is adjusted based on the current rotation of the display. |
| 1002 | * </p><p> |
| 1003 | * The real size may be smaller than the physical size of the screen when the |
Andrii Kulian | a4bb9d3 | 2016-03-11 11:52:22 -0800 | [diff] [blame] | 1004 | * window manager is emulating a smaller display (using adb shell wm size). |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1005 | * </p> |
| 1006 | * |
| 1007 | * @param outMetrics A {@link DisplayMetrics} object to receive the metrics. |
Dianne Hackborn | 68066c2 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1008 | */ |
| 1009 | public void getRealMetrics(DisplayMetrics outMetrics) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1010 | synchronized (this) { |
| 1011 | updateDisplayInfoLocked(); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1012 | mDisplayInfo.getLogicalMetrics(outMetrics, |
Andrii Kulian | a4bb9d3 | 2016-03-11 11:52:22 -0800 | [diff] [blame] | 1013 | CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1014 | } |
Dianne Hackborn | 68066c2 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1017 | /** |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1018 | * Gets the state of the display, such as whether it is on or off. |
| 1019 | * |
| 1020 | * @return The state of the display: one of {@link #STATE_OFF}, {@link #STATE_ON}, |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 1021 | * {@link #STATE_DOZE}, {@link #STATE_DOZE_SUSPEND}, {@link #STATE_ON_SUSPEND}, or |
Santos Cordon | 3107d29 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 1022 | * {@link #STATE_UNKNOWN}. |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1023 | */ |
| 1024 | public int getState() { |
| 1025 | synchronized (this) { |
| 1026 | updateDisplayInfoLocked(); |
| 1027 | return mIsValid ? mDisplayInfo.state : STATE_UNKNOWN; |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | /** |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1032 | * Returns true if the specified UID has access to this display. |
| 1033 | * @hide |
| 1034 | */ |
| 1035 | public boolean hasAccess(int uid) { |
| 1036 | return Display.hasAccess(uid, mFlags, mOwnerUid); |
| 1037 | } |
| 1038 | |
| 1039 | /** @hide */ |
| 1040 | public static boolean hasAccess(int uid, int flags, int ownerUid) { |
| 1041 | return (flags & Display.FLAG_PRIVATE) == 0 |
| 1042 | || uid == ownerUid |
| 1043 | || uid == Process.SYSTEM_UID |
| 1044 | || uid == 0; |
| 1045 | } |
| 1046 | |
Jeff Brown | 69b0716 | 2013-11-07 00:30:16 -0800 | [diff] [blame] | 1047 | /** |
| 1048 | * Returns true if the display is a public presentation display. |
| 1049 | * @hide |
| 1050 | */ |
| 1051 | public boolean isPublicPresentation() { |
| 1052 | return (mFlags & (Display.FLAG_PRIVATE | Display.FLAG_PRESENTATION)) == |
| 1053 | Display.FLAG_PRESENTATION; |
| 1054 | } |
| 1055 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1056 | private void updateDisplayInfoLocked() { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1057 | // Note: The display manager caches display info objects on our behalf. |
| 1058 | DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId); |
| 1059 | if (newInfo == null) { |
| 1060 | // Preserve the old mDisplayInfo after the display is removed. |
| 1061 | if (mIsValid) { |
| 1062 | mIsValid = false; |
| 1063 | if (DEBUG) { |
| 1064 | Log.d(TAG, "Logical display " + mDisplayId + " was removed."); |
| 1065 | } |
| 1066 | } |
| 1067 | } else { |
| 1068 | // Use the new display info. (It might be the same object if nothing changed.) |
| 1069 | mDisplayInfo = newInfo; |
| 1070 | if (!mIsValid) { |
| 1071 | mIsValid = true; |
| 1072 | if (DEBUG) { |
| 1073 | Log.d(TAG, "Logical display " + mDisplayId + " was recreated."); |
| 1074 | } |
| 1075 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1076 | } |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1079 | private void updateCachedAppSizeIfNeededLocked() { |
| 1080 | long now = SystemClock.uptimeMillis(); |
| 1081 | if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) { |
| 1082 | updateDisplayInfoLocked(); |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 1083 | mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments()); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1084 | mCachedAppWidthCompat = mTempMetrics.widthPixels; |
| 1085 | mCachedAppHeightCompat = mTempMetrics.heightPixels; |
| 1086 | mLastCachedAppSizeUpdate = now; |
| 1087 | } |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1088 | } |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 1089 | |
| 1090 | // For debugging purposes |
| 1091 | @Override |
| 1092 | public String toString() { |
| 1093 | synchronized (this) { |
| 1094 | updateDisplayInfoLocked(); |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 1095 | mDisplayInfo.getAppMetrics(mTempMetrics, getDisplayAdjustments()); |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 1096 | return "Display id " + mDisplayId + ": " + mDisplayInfo |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 1097 | + ", " + mTempMetrics + ", isValid=" + mIsValid; |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 1098 | } |
| 1099 | } |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 1100 | |
| 1101 | /** |
| 1102 | * @hide |
| 1103 | */ |
| 1104 | public static String typeToString(int type) { |
| 1105 | switch (type) { |
| 1106 | case TYPE_UNKNOWN: |
| 1107 | return "UNKNOWN"; |
| 1108 | case TYPE_BUILT_IN: |
| 1109 | return "BUILT_IN"; |
| 1110 | case TYPE_HDMI: |
| 1111 | return "HDMI"; |
| 1112 | case TYPE_WIFI: |
| 1113 | return "WIFI"; |
| 1114 | case TYPE_OVERLAY: |
| 1115 | return "OVERLAY"; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 1116 | case TYPE_VIRTUAL: |
| 1117 | return "VIRTUAL"; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 1118 | default: |
| 1119 | return Integer.toString(type); |
| 1120 | } |
| 1121 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1123 | /** |
| 1124 | * @hide |
| 1125 | */ |
| 1126 | public static String stateToString(int state) { |
| 1127 | switch (state) { |
| 1128 | case STATE_UNKNOWN: |
| 1129 | return "UNKNOWN"; |
| 1130 | case STATE_OFF: |
| 1131 | return "OFF"; |
| 1132 | case STATE_ON: |
| 1133 | return "ON"; |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 1134 | case STATE_DOZE: |
| 1135 | return "DOZE"; |
| 1136 | case STATE_DOZE_SUSPEND: |
| 1137 | return "DOZE_SUSPEND"; |
Santos Cordon | 3107d29 | 2016-09-20 15:50:35 -0700 | [diff] [blame] | 1138 | case STATE_VR: |
| 1139 | return "VR"; |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 1140 | case STATE_ON_SUSPEND: |
| 1141 | return "ON_SUSPEND"; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1142 | default: |
| 1143 | return Integer.toString(state); |
| 1144 | } |
| 1145 | } |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 1146 | |
| 1147 | /** |
| 1148 | * Returns true if display updates may be suspended while in the specified |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 1149 | * display power state. In SUSPEND states, updates are absolutely forbidden. |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 1150 | * @hide |
| 1151 | */ |
| 1152 | public static boolean isSuspendedState(int state) { |
Chris Phoenix | 10a4a64 | 2017-09-25 13:21:00 -0700 | [diff] [blame] | 1153 | return state == STATE_OFF || state == STATE_DOZE_SUSPEND || state == STATE_ON_SUSPEND; |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 1154 | } |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1155 | |
| 1156 | /** |
Michael Wright | 05e76fe | 2017-07-20 18:18:33 +0100 | [diff] [blame] | 1157 | * Returns true if the display may be in a reduced operating mode while in the |
| 1158 | * specified display power state. |
| 1159 | * @hide |
| 1160 | */ |
| 1161 | public static boolean isDozeState(int state) { |
| 1162 | return state == STATE_DOZE || state == STATE_DOZE_SUSPEND; |
| 1163 | } |
| 1164 | |
| 1165 | /** |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1166 | * A mode supported by a given display. |
| 1167 | * |
| 1168 | * @see Display#getSupportedModes() |
| 1169 | */ |
| 1170 | public static final class Mode implements Parcelable { |
| 1171 | /** |
| 1172 | * @hide |
| 1173 | */ |
| 1174 | public static final Mode[] EMPTY_ARRAY = new Mode[0]; |
| 1175 | |
| 1176 | private final int mModeId; |
| 1177 | private final int mWidth; |
| 1178 | private final int mHeight; |
| 1179 | private final float mRefreshRate; |
| 1180 | |
| 1181 | /** |
| 1182 | * @hide |
| 1183 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 1184 | @UnsupportedAppUsage |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 1185 | public Mode(int modeId, int width, int height, float refreshRate) { |
| 1186 | mModeId = modeId; |
| 1187 | mWidth = width; |
| 1188 | mHeight = height; |
| 1189 | mRefreshRate = refreshRate; |
| 1190 | } |
| 1191 | |
| 1192 | /** |
| 1193 | * Returns this mode's id. |
| 1194 | */ |
| 1195 | public int getModeId() { |
| 1196 | return mModeId; |
| 1197 | } |
| 1198 | |
| 1199 | /** |
| 1200 | * Returns the physical width of the display in pixels when configured in this mode's |
| 1201 | * resolution. |
| 1202 | * <p> |
| 1203 | * Note that due to application UI scaling, the number of pixels made available to |
| 1204 | * applications when the mode is active (as reported by {@link Display#getWidth()} may |
| 1205 | * differ from the mode's actual resolution (as reported by this function). |
| 1206 | * <p> |
| 1207 | * For example, applications running on a 4K display may have their UI laid out and rendered |
| 1208 | * in 1080p and then scaled up. Applications can take advantage of the extra resolution by |
| 1209 | * rendering content through a {@link android.view.SurfaceView} using full size buffers. |
| 1210 | */ |
| 1211 | public int getPhysicalWidth() { |
| 1212 | return mWidth; |
| 1213 | } |
| 1214 | |
| 1215 | /** |
| 1216 | * Returns the physical height of the display in pixels when configured in this mode's |
| 1217 | * resolution. |
| 1218 | * <p> |
| 1219 | * Note that due to application UI scaling, the number of pixels made available to |
| 1220 | * applications when the mode is active (as reported by {@link Display#getHeight()} may |
| 1221 | * differ from the mode's actual resolution (as reported by this function). |
| 1222 | * <p> |
| 1223 | * For example, applications running on a 4K display may have their UI laid out and rendered |
| 1224 | * in 1080p and then scaled up. Applications can take advantage of the extra resolution by |
| 1225 | * rendering content through a {@link android.view.SurfaceView} using full size buffers. |
| 1226 | */ |
| 1227 | public int getPhysicalHeight() { |
| 1228 | return mHeight; |
| 1229 | } |
| 1230 | |
| 1231 | /** |
| 1232 | * Returns the refresh rate in frames per second. |
| 1233 | */ |
| 1234 | public float getRefreshRate() { |
| 1235 | return mRefreshRate; |
| 1236 | } |
| 1237 | |
| 1238 | /** |
| 1239 | * Returns {@code true} if this mode matches the given parameters. |
| 1240 | * |
| 1241 | * @hide |
| 1242 | */ |
| 1243 | public boolean matches(int width, int height, float refreshRate) { |
| 1244 | return mWidth == width && |
| 1245 | mHeight == height && |
| 1246 | Float.floatToIntBits(mRefreshRate) == Float.floatToIntBits(refreshRate); |
| 1247 | } |
| 1248 | |
| 1249 | @Override |
| 1250 | public boolean equals(Object other) { |
| 1251 | if (this == other) { |
| 1252 | return true; |
| 1253 | } |
| 1254 | if (!(other instanceof Mode)) { |
| 1255 | return false; |
| 1256 | } |
| 1257 | Mode that = (Mode) other; |
| 1258 | return mModeId == that.mModeId && matches(that.mWidth, that.mHeight, that.mRefreshRate); |
| 1259 | } |
| 1260 | |
| 1261 | @Override |
| 1262 | public int hashCode() { |
| 1263 | int hash = 1; |
| 1264 | hash = hash * 17 + mModeId; |
| 1265 | hash = hash * 17 + mWidth; |
| 1266 | hash = hash * 17 + mHeight; |
| 1267 | hash = hash * 17 + Float.floatToIntBits(mRefreshRate); |
| 1268 | return hash; |
| 1269 | } |
| 1270 | |
| 1271 | @Override |
| 1272 | public String toString() { |
| 1273 | return new StringBuilder("{") |
| 1274 | .append("id=").append(mModeId) |
| 1275 | .append(", width=").append(mWidth) |
| 1276 | .append(", height=").append(mHeight) |
| 1277 | .append(", fps=").append(mRefreshRate) |
| 1278 | .append("}") |
| 1279 | .toString(); |
| 1280 | } |
| 1281 | |
| 1282 | @Override |
| 1283 | public int describeContents() { |
| 1284 | return 0; |
| 1285 | } |
| 1286 | |
| 1287 | private Mode(Parcel in) { |
| 1288 | this(in.readInt(), in.readInt(), in.readInt(), in.readFloat()); |
| 1289 | } |
| 1290 | |
| 1291 | @Override |
| 1292 | public void writeToParcel(Parcel out, int parcelableFlags) { |
| 1293 | out.writeInt(mModeId); |
| 1294 | out.writeInt(mWidth); |
| 1295 | out.writeInt(mHeight); |
| 1296 | out.writeFloat(mRefreshRate); |
| 1297 | } |
| 1298 | |
| 1299 | @SuppressWarnings("hiding") |
| 1300 | public static final Parcelable.Creator<Mode> CREATOR |
| 1301 | = new Parcelable.Creator<Mode>() { |
| 1302 | @Override |
| 1303 | public Mode createFromParcel(Parcel in) { |
| 1304 | return new Mode(in); |
| 1305 | } |
| 1306 | |
| 1307 | @Override |
| 1308 | public Mode[] newArray(int size) { |
| 1309 | return new Mode[size]; |
| 1310 | } |
| 1311 | }; |
| 1312 | } |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 1313 | |
| 1314 | /** |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 1315 | * Encapsulates the HDR capabilities of a given display. |
| 1316 | * For example, what HDR types it supports and details about the desired luminance data. |
| 1317 | * <p>You can get an instance for a given {@link Display} object with |
| 1318 | * {@link Display#getHdrCapabilities getHdrCapabilities()}. |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 1319 | */ |
| 1320 | public static final class HdrCapabilities implements Parcelable { |
| 1321 | /** |
| 1322 | * Invalid luminance value. |
| 1323 | */ |
| 1324 | public static final float INVALID_LUMINANCE = -1; |
| 1325 | /** |
| 1326 | * Dolby Vision high dynamic range (HDR) display. |
| 1327 | */ |
| 1328 | public static final int HDR_TYPE_DOLBY_VISION = 1; |
| 1329 | /** |
| 1330 | * HDR10 display. |
| 1331 | */ |
| 1332 | public static final int HDR_TYPE_HDR10 = 2; |
| 1333 | /** |
| 1334 | * Hybrid Log-Gamma HDR display. |
| 1335 | */ |
| 1336 | public static final int HDR_TYPE_HLG = 3; |
| 1337 | |
Hangyu Kuang | da802f5 | 2016-04-06 18:02:17 -0700 | [diff] [blame] | 1338 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 1339 | @IntDef(prefix = { "HDR_TYPE_" }, value = { |
| 1340 | HDR_TYPE_DOLBY_VISION, |
| 1341 | HDR_TYPE_HDR10, |
| 1342 | HDR_TYPE_HLG, |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 1343 | }) |
| 1344 | @Retention(RetentionPolicy.SOURCE) |
| 1345 | public @interface HdrType {} |
| 1346 | |
| 1347 | private @HdrType int[] mSupportedHdrTypes = new int[0]; |
| 1348 | private float mMaxLuminance = INVALID_LUMINANCE; |
| 1349 | private float mMaxAverageLuminance = INVALID_LUMINANCE; |
| 1350 | private float mMinLuminance = INVALID_LUMINANCE; |
| 1351 | |
Hangyu Kuang | da802f5 | 2016-04-06 18:02:17 -0700 | [diff] [blame] | 1352 | /** |
| 1353 | * @hide |
| 1354 | */ |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 1355 | public HdrCapabilities() { |
| 1356 | } |
| 1357 | |
Hangyu Kuang | 1e7d1aa | 2016-05-17 14:21:01 -0700 | [diff] [blame] | 1358 | /** |
| 1359 | * @hide |
| 1360 | */ |
Mathew Inwood | e5ad598 | 2018-08-17 15:07:52 +0100 | [diff] [blame] | 1361 | @UnsupportedAppUsage |
Hangyu Kuang | 54ac219 | 2016-04-25 13:22:02 -0700 | [diff] [blame] | 1362 | public HdrCapabilities(int[] supportedHdrTypes, float maxLuminance, |
| 1363 | float maxAverageLuminance, float minLuminance) { |
| 1364 | mSupportedHdrTypes = supportedHdrTypes; |
| 1365 | mMaxLuminance = maxLuminance; |
| 1366 | mMaxAverageLuminance = maxAverageLuminance; |
| 1367 | mMinLuminance = minLuminance; |
| 1368 | } |
| 1369 | |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 1370 | /** |
| 1371 | * Gets the supported HDR types of this display. |
| 1372 | * Returns empty array if HDR is not supported by the display. |
| 1373 | */ |
| 1374 | public @HdrType int[] getSupportedHdrTypes() { |
| 1375 | return mSupportedHdrTypes; |
| 1376 | } |
| 1377 | /** |
| 1378 | * Returns the desired content max luminance data in cd/m2 for this display. |
| 1379 | */ |
| 1380 | public float getDesiredMaxLuminance() { |
| 1381 | return mMaxLuminance; |
| 1382 | } |
| 1383 | /** |
| 1384 | * Returns the desired content max frame-average luminance data in cd/m2 for this display. |
| 1385 | */ |
| 1386 | public float getDesiredMaxAverageLuminance() { |
| 1387 | return mMaxAverageLuminance; |
| 1388 | } |
| 1389 | /** |
| 1390 | * Returns the desired content min luminance data in cd/m2 for this display. |
| 1391 | */ |
| 1392 | public float getDesiredMinLuminance() { |
| 1393 | return mMinLuminance; |
| 1394 | } |
| 1395 | |
Michael Wright | 16ae042 | 2016-07-26 18:18:53 +0100 | [diff] [blame] | 1396 | @Override |
| 1397 | public boolean equals(Object other) { |
| 1398 | if (this == other) { |
| 1399 | return true; |
| 1400 | } |
| 1401 | |
| 1402 | if (!(other instanceof HdrCapabilities)) { |
| 1403 | return false; |
| 1404 | } |
| 1405 | HdrCapabilities that = (HdrCapabilities) other; |
| 1406 | |
| 1407 | return Arrays.equals(mSupportedHdrTypes, that.mSupportedHdrTypes) |
| 1408 | && mMaxLuminance == that.mMaxLuminance |
| 1409 | && mMaxAverageLuminance == that.mMaxAverageLuminance |
| 1410 | && mMinLuminance == that.mMinLuminance; |
| 1411 | } |
| 1412 | |
| 1413 | @Override |
| 1414 | public int hashCode() { |
| 1415 | int hash = 23; |
| 1416 | hash = hash * 17 + Arrays.hashCode(mSupportedHdrTypes); |
| 1417 | hash = hash * 17 + Float.floatToIntBits(mMaxLuminance); |
| 1418 | hash = hash * 17 + Float.floatToIntBits(mMaxAverageLuminance); |
| 1419 | hash = hash * 17 + Float.floatToIntBits(mMinLuminance); |
| 1420 | return hash; |
| 1421 | } |
| 1422 | |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 1423 | public static final Creator<HdrCapabilities> CREATOR = new Creator<HdrCapabilities>() { |
| 1424 | @Override |
| 1425 | public HdrCapabilities createFromParcel(Parcel source) { |
| 1426 | return new HdrCapabilities(source); |
| 1427 | } |
| 1428 | |
| 1429 | @Override |
| 1430 | public HdrCapabilities[] newArray(int size) { |
| 1431 | return new HdrCapabilities[size]; |
| 1432 | } |
| 1433 | }; |
| 1434 | |
| 1435 | private HdrCapabilities(Parcel source) { |
| 1436 | readFromParcel(source); |
| 1437 | } |
| 1438 | |
Hangyu Kuang | da802f5 | 2016-04-06 18:02:17 -0700 | [diff] [blame] | 1439 | /** |
| 1440 | * @hide |
| 1441 | */ |
Ronghua Wu | f173c32 | 2016-02-29 13:57:18 -0800 | [diff] [blame] | 1442 | public void readFromParcel(Parcel source) { |
| 1443 | int types = source.readInt(); |
| 1444 | mSupportedHdrTypes = new int[types]; |
| 1445 | for (int i = 0; i < types; ++i) { |
| 1446 | mSupportedHdrTypes[i] = source.readInt(); |
| 1447 | } |
| 1448 | mMaxLuminance = source.readFloat(); |
| 1449 | mMaxAverageLuminance = source.readFloat(); |
| 1450 | mMinLuminance = source.readFloat(); |
| 1451 | } |
| 1452 | |
| 1453 | @Override |
| 1454 | public void writeToParcel(Parcel dest, int flags) { |
| 1455 | dest.writeInt(mSupportedHdrTypes.length); |
| 1456 | for (int i = 0; i < mSupportedHdrTypes.length; ++i) { |
| 1457 | dest.writeInt(mSupportedHdrTypes[i]); |
| 1458 | } |
| 1459 | dest.writeFloat(mMaxLuminance); |
| 1460 | dest.writeFloat(mMaxAverageLuminance); |
| 1461 | dest.writeFloat(mMinLuminance); |
| 1462 | } |
| 1463 | |
| 1464 | @Override |
| 1465 | public int describeContents() { |
| 1466 | return 0; |
| 1467 | } |
| 1468 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 1469 | } |