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