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