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 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 19 | import android.content.res.CompatibilityInfo; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 20 | import android.graphics.PixelFormat; |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 21 | import android.graphics.Point; |
| 22 | import android.graphics.Rect; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 23 | import android.hardware.display.DisplayManagerGlobal; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 24 | import android.os.Process; |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 25 | import android.os.SystemClock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.util.DisplayMetrics; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 27 | import android.util.Log; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 29 | import java.util.Arrays; |
| 30 | |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 31 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 32 | * Provides information about the size and density of a logical display. |
| 33 | * <p> |
| 34 | * The display area is described in two different ways. |
| 35 | * <ul> |
| 36 | * <li>The application display area specifies the part of the display that may contain |
| 37 | * an application window, excluding the system decorations. The application display area may |
| 38 | * be smaller than the real display area because the system subtracts the space needed |
| 39 | * for decor elements such as the status bar. Use the following methods to query the |
| 40 | * application display area: {@link #getSize}, {@link #getRectSize} and {@link #getMetrics}.</li> |
| 41 | * <li>The real display area specifies the part of the display that contains content |
| 42 | * including the system decorations. Even so, the real display area may be smaller than the |
| 43 | * physical size of the display if the window manager is emulating a smaller display |
| 44 | * using (adb shell am display-size). Use the following methods to query the |
| 45 | * real display area: {@link #getRealSize}, {@link #getRealMetrics}.</li> |
| 46 | * </ul> |
| 47 | * </p><p> |
| 48 | * A logical display does not necessarily represent a particular physical display device |
| 49 | * such as the built-in screen or an external monitor. The contents of a logical |
| 50 | * display may be presented on one or more physical displays according to the devices |
| 51 | * that are currently attached and whether mirroring has been enabled. |
| 52 | * </p> |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 53 | */ |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 54 | public final class Display { |
| 55 | private static final String TAG = "Display"; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 56 | private static final boolean DEBUG = false; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 57 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 58 | private final DisplayManagerGlobal mGlobal; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 59 | private final int mDisplayId; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 60 | private final int mLayerStack; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 61 | private final int mFlags; |
| 62 | private final int mType; |
| 63 | private final String mAddress; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 64 | private final int mOwnerUid; |
| 65 | private final String mOwnerPackageName; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 66 | private final DisplayAdjustments mDisplayAdjustments; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 67 | |
| 68 | private DisplayInfo mDisplayInfo; // never null |
| 69 | private boolean mIsValid; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 70 | |
| 71 | // Temporary display metrics structure used for compatibility mode. |
| 72 | private final DisplayMetrics mTempMetrics = new DisplayMetrics(); |
| 73 | |
| 74 | // We cache the app width and height properties briefly between calls |
| 75 | // to getHeight() and getWidth() to ensure that applications perceive |
| 76 | // consistent results when the size changes (most of the time). |
| 77 | // Applications should now be using getSize() instead. |
| 78 | private static final int CACHED_APP_SIZE_DURATION_MILLIS = 20; |
| 79 | private long mLastCachedAppSizeUpdate; |
| 80 | private int mCachedAppWidthCompat; |
| 81 | private int mCachedAppHeightCompat; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 82 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 84 | * The default Display id, which is the id of the built-in primary display |
| 85 | * assuming there is one. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | */ |
| 87 | public static final int DEFAULT_DISPLAY = 0; |
| 88 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | /** |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 90 | * Display flag: Indicates that the display supports compositing content |
| 91 | * that is stored in protected graphics buffers. |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 92 | * <p> |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 93 | * If this flag is set then the display device supports compositing protected buffers. |
| 94 | * </p><p> |
| 95 | * If this flag is not set then the display device may not support compositing |
| 96 | * protected buffers; the user may see a blank region on the screen instead of |
| 97 | * the protected content. |
| 98 | * </p><p> |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 99 | * Secure (DRM) video decoders may allocate protected graphics buffers to request that |
| 100 | * a hardware-protected path be provided between the video decoder and the external |
| 101 | * display sink. If a hardware-protected path is not available, then content stored |
| 102 | * in protected graphics buffers may not be composited. |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 103 | * </p><p> |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 104 | * An application can use the absence of this flag as a hint that it should not use protected |
| 105 | * buffers for this display because the content may not be visible. For example, |
| 106 | * if the flag is not set then the application may choose not to show content on this |
| 107 | * display, show an informative error message, select an alternate content stream |
| 108 | * or adopt a different strategy for decoding content that does not rely on |
| 109 | * protected buffers. |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 110 | * </p> |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 111 | * |
| 112 | * @see #getFlags |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 113 | */ |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 114 | public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 0; |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 117 | * Display flag: Indicates that the display has a secure video output and |
| 118 | * supports compositing secure surfaces. |
| 119 | * <p> |
| 120 | * If this flag is set then the display device has a secure video output |
| 121 | * and is capable of showing secure surfaces. It may also be capable of |
| 122 | * showing {@link #FLAG_SUPPORTS_PROTECTED_BUFFERS protected buffers}. |
| 123 | * </p><p> |
| 124 | * If this flag is not set then the display device may not have a secure video |
| 125 | * output; the user may see a blank region on the screen instead of |
| 126 | * the contents of secure surfaces or protected buffers. |
| 127 | * </p><p> |
| 128 | * Secure surfaces are used to prevent content rendered into those surfaces |
| 129 | * by applications from appearing in screenshots or from being viewed |
| 130 | * on non-secure displays. Protected buffers are used by secure video decoders |
| 131 | * for a similar purpose. |
| 132 | * </p><p> |
| 133 | * An application creates a window with a secure surface by specifying the |
| 134 | * {@link WindowManager.LayoutParams#FLAG_SECURE} window flag. |
| 135 | * Likewise, an application creates a {@link SurfaceView} with a secure surface |
| 136 | * by calling {@link SurfaceView#setSecure} before attaching the secure view to |
| 137 | * its containing window. |
| 138 | * </p><p> |
| 139 | * An application can use the absence of this flag as a hint that it should not create |
| 140 | * secure surfaces or protected buffers on this display because the content may |
| 141 | * not be visible. For example, if the flag is not set then the application may |
| 142 | * choose not to show content on this display, show an informative error message, |
| 143 | * select an alternate content stream or adopt a different strategy for decoding |
| 144 | * content that does not rely on secure surfaces or protected buffers. |
| 145 | * </p> |
| 146 | * |
| 147 | * @see #getFlags |
| 148 | */ |
| 149 | public static final int FLAG_SECURE = 1 << 1; |
| 150 | |
| 151 | /** |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 152 | * Display flag: Indicates that the display is private. Only the application that |
| 153 | * owns the display can create windows on it. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 154 | * |
| 155 | * @see #getFlags |
| 156 | */ |
| 157 | public static final int FLAG_PRIVATE = 1 << 2; |
| 158 | |
| 159 | /** |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 160 | * Display flag: Indicates that the display is a presentation display. |
| 161 | * <p> |
| 162 | * This flag identifies secondary displays that are suitable for |
| 163 | * use as presentation displays such as HDMI or Wireless displays. Applications |
| 164 | * may automatically project their content to presentation displays to provide |
| 165 | * richer second screen experiences. |
| 166 | * </p> |
| 167 | * |
| 168 | * @see #getFlags |
| 169 | */ |
| 170 | public static final int FLAG_PRESENTATION = 1 << 3; |
| 171 | |
| 172 | /** |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 173 | * Display flag: Indicates that the contents of the display should not be scaled |
| 174 | * to fit the physical screen dimensions. Used for development only to emulate |
| 175 | * devices with smaller physicals screens while preserving density. |
| 176 | * |
| 177 | * @hide |
| 178 | */ |
| 179 | public static final int FLAG_SCALING_DISABLED = 1 << 30; |
| 180 | |
| 181 | /** |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 182 | * Display type: Unknown display type. |
| 183 | * @hide |
| 184 | */ |
| 185 | public static final int TYPE_UNKNOWN = 0; |
| 186 | |
| 187 | /** |
| 188 | * Display type: Built-in display. |
| 189 | * @hide |
| 190 | */ |
| 191 | public static final int TYPE_BUILT_IN = 1; |
| 192 | |
| 193 | /** |
| 194 | * Display type: HDMI display. |
| 195 | * @hide |
| 196 | */ |
| 197 | public static final int TYPE_HDMI = 2; |
| 198 | |
| 199 | /** |
| 200 | * Display type: WiFi display. |
| 201 | * @hide |
| 202 | */ |
| 203 | public static final int TYPE_WIFI = 3; |
| 204 | |
| 205 | /** |
| 206 | * Display type: Overlay display. |
| 207 | * @hide |
| 208 | */ |
| 209 | public static final int TYPE_OVERLAY = 4; |
| 210 | |
| 211 | /** |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 212 | * Display type: Virtual display. |
| 213 | * @hide |
| 214 | */ |
| 215 | public static final int TYPE_VIRTUAL = 5; |
| 216 | |
| 217 | /** |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 218 | * Display state: The display state is unknown. |
| 219 | * |
| 220 | * @see #getState |
| 221 | */ |
| 222 | public static final int STATE_UNKNOWN = 0; |
| 223 | |
| 224 | /** |
| 225 | * Display state: The display is off. |
| 226 | * |
| 227 | * @see #getState |
| 228 | */ |
| 229 | public static final int STATE_OFF = 1; |
| 230 | |
| 231 | /** |
| 232 | * Display state: The display is on. |
| 233 | * |
| 234 | * @see #getState |
| 235 | */ |
| 236 | public static final int STATE_ON = 2; |
| 237 | |
| 238 | /** |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 239 | * Display state: The display is dozing in a low power state; it is still |
| 240 | * on but is optimized for showing system-provided content while the |
| 241 | * device is non-interactive. |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 242 | * |
| 243 | * @see #getState |
| 244 | * @see android.os.PowerManager#isInteractive |
| 245 | */ |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 246 | public static final int STATE_DOZE = 3; |
| 247 | |
| 248 | /** |
| 249 | * Display state: The display is dozing in a suspended low power state; it is still |
| 250 | * on but is optimized for showing static system-provided content while the device |
| 251 | * is non-interactive. This mode may be used to conserve even more power by allowing |
| 252 | * the hardware to stop applying frame buffer updates from the graphics subsystem or |
| 253 | * to take over the display and manage it autonomously to implement low power always-on |
| 254 | * display functionality. |
| 255 | * |
| 256 | * @see #getState |
| 257 | * @see android.os.PowerManager#isInteractive |
| 258 | */ |
| 259 | public static final int STATE_DOZE_SUSPEND = 4; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 260 | |
| 261 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 262 | * Internal method to create a display. |
| 263 | * Applications should use {@link android.view.WindowManager#getDefaultDisplay()} |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 264 | * or {@link android.hardware.display.DisplayManager#getDisplay} |
| 265 | * to get a display object. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 266 | * |
| 267 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | */ |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 269 | public Display(DisplayManagerGlobal global, |
| 270 | int displayId, DisplayInfo displayInfo /*not null*/, |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 271 | DisplayAdjustments daj) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 272 | mGlobal = global; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 273 | mDisplayId = displayId; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 274 | mDisplayInfo = displayInfo; |
Craig Mautner | 1abaa53 | 2013-06-28 12:03:32 -0700 | [diff] [blame] | 275 | mDisplayAdjustments = new DisplayAdjustments(daj); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 276 | mIsValid = true; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 277 | |
| 278 | // Cache properties that cannot change as long as the display is valid. |
| 279 | mLayerStack = displayInfo.layerStack; |
| 280 | mFlags = displayInfo.flags; |
| 281 | mType = displayInfo.type; |
| 282 | mAddress = displayInfo.address; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 283 | mOwnerUid = displayInfo.ownerUid; |
| 284 | mOwnerPackageName = displayInfo.ownerPackageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | } |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 288 | * Gets the display id. |
| 289 | * <p> |
| 290 | * Each logical display has a unique id. |
| 291 | * The default display has id {@link #DEFAULT_DISPLAY}. |
| 292 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | */ |
| 294 | public int getDisplayId() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 295 | return mDisplayId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 299 | * Returns true if this display is still valid, false if the display has been removed. |
| 300 | * |
| 301 | * If the display is invalid, then the methods of this class will |
| 302 | * continue to report the most recently observed display information. |
| 303 | * However, it is unwise (and rather fruitless) to continue using a |
| 304 | * {@link Display} object after the display's demise. |
| 305 | * |
| 306 | * It's possible for a display that was previously invalid to become |
| 307 | * valid again if a display with the same id is reconnected. |
| 308 | * |
| 309 | * @return True if the display is still valid. |
| 310 | */ |
| 311 | public boolean isValid() { |
| 312 | synchronized (this) { |
| 313 | updateDisplayInfoLocked(); |
| 314 | return mIsValid; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /** |
Jeff Brown | 2ab1b7d9 | 2012-08-08 01:46:41 -0700 | [diff] [blame] | 319 | * Gets a full copy of the display information. |
| 320 | * |
| 321 | * @param outDisplayInfo The object to receive the copy of the display information. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 322 | * @return True if the display is still valid. |
Jeff Brown | 2ab1b7d9 | 2012-08-08 01:46:41 -0700 | [diff] [blame] | 323 | * @hide |
| 324 | */ |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 325 | public boolean getDisplayInfo(DisplayInfo outDisplayInfo) { |
Jeff Brown | 2ab1b7d9 | 2012-08-08 01:46:41 -0700 | [diff] [blame] | 326 | synchronized (this) { |
| 327 | updateDisplayInfoLocked(); |
| 328 | outDisplayInfo.copyFrom(mDisplayInfo); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 329 | return mIsValid; |
Jeff Brown | 2ab1b7d9 | 2012-08-08 01:46:41 -0700 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | |
| 333 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 334 | * Gets the display's layer stack. |
| 335 | * |
| 336 | * Each display has its own independent layer stack upon which surfaces |
| 337 | * are placed to be managed by surface flinger. |
| 338 | * |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 339 | * @return The display's layer stack number. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 340 | * @hide |
| 341 | */ |
| 342 | public int getLayerStack() { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 343 | return mLayerStack; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /** |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 347 | * Returns a combination of flags that describe the capabilities of the display. |
| 348 | * |
| 349 | * @return The display flags. |
| 350 | * |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 351 | * @see #FLAG_SUPPORTS_PROTECTED_BUFFERS |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 352 | * @see #FLAG_SECURE |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 353 | * @see #FLAG_PRIVATE |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 354 | */ |
| 355 | public int getFlags() { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 356 | return mFlags; |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Gets the display type. |
| 361 | * |
| 362 | * @return The display type. |
| 363 | * |
| 364 | * @see #TYPE_UNKNOWN |
| 365 | * @see #TYPE_BUILT_IN |
| 366 | * @see #TYPE_HDMI |
| 367 | * @see #TYPE_WIFI |
| 368 | * @see #TYPE_OVERLAY |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 369 | * @see #TYPE_VIRTUAL |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 370 | * @hide |
| 371 | */ |
| 372 | public int getType() { |
| 373 | return mType; |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Gets the display address, or null if none. |
| 378 | * Interpretation varies by display type. |
| 379 | * |
| 380 | * @return The display address. |
| 381 | * @hide |
| 382 | */ |
| 383 | public String getAddress() { |
| 384 | return mAddress; |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /** |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 388 | * Gets the UID of the application that owns this display, or zero if it is |
| 389 | * owned by the system. |
| 390 | * <p> |
| 391 | * If the display is private, then only the owner can use it. |
| 392 | * </p> |
| 393 | * |
| 394 | * @hide |
| 395 | */ |
| 396 | public int getOwnerUid() { |
| 397 | return mOwnerUid; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Gets the package name of the application that owns this display, or null if it is |
| 402 | * owned by the system. |
| 403 | * <p> |
| 404 | * If the display is private, then only the owner can use it. |
| 405 | * </p> |
| 406 | * |
| 407 | * @hide |
| 408 | */ |
| 409 | public String getOwnerPackageName() { |
| 410 | return mOwnerPackageName; |
| 411 | } |
| 412 | |
| 413 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 414 | * Gets the compatibility info used by this display instance. |
| 415 | * |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 416 | * @return The display adjustments holder, or null if none is required. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 417 | * @hide |
| 418 | */ |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 419 | public DisplayAdjustments getDisplayAdjustments() { |
| 420 | return mDisplayAdjustments; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 424 | * Gets the name of the display. |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 425 | * <p> |
| 426 | * Note that some displays may be renamed by the user. |
| 427 | * </p> |
| 428 | * |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 429 | * @return The display's name. |
| 430 | */ |
| 431 | public String getName() { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 432 | synchronized (this) { |
| 433 | updateDisplayInfoLocked(); |
| 434 | return mDisplayInfo.name; |
| 435 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /** |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 439 | * Gets the size of the display, in pixels. |
| 440 | * <p> |
| 441 | * Note that this value should <em>not</em> be used for computing layouts, |
| 442 | * since a device will typically have screen decoration (such as a status bar) |
Dianne Hackborn | 5cb70b5 | 2010-02-25 17:01:14 -0800 | [diff] [blame] | 443 | * along the edges of the display that reduce the amount of application |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 444 | * space available from the size returned here. Layouts should instead use |
| 445 | * the window size. |
| 446 | * </p><p> |
| 447 | * The size is adjusted based on the current rotation of the display. |
| 448 | * </p><p> |
| 449 | * The size returned by this method does not necessarily represent the |
| 450 | * actual raw size (native resolution) of the display. The returned size may |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 451 | * be adjusted to exclude certain system decoration elements that are always visible. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 452 | * It may also be scaled to provide compatibility with older applications that |
| 453 | * were originally designed for smaller displays. |
| 454 | * </p> |
| 455 | * |
| 456 | * @param outSize A {@link Point} object to receive the size information. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | */ |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 458 | public void getSize(Point outSize) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 459 | synchronized (this) { |
| 460 | updateDisplayInfoLocked(); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 461 | mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 462 | outSize.x = mTempMetrics.widthPixels; |
| 463 | outSize.y = mTempMetrics.heightPixels; |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 464 | } |
| 465 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | /** |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 468 | * Gets the size of the display as a rectangle, in pixels. |
| 469 | * |
| 470 | * @param outSize A {@link Rect} object to receive the size information. |
| 471 | * @see #getSize(Point) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | */ |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 473 | public void getRectSize(Rect outSize) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 474 | synchronized (this) { |
| 475 | updateDisplayInfoLocked(); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 476 | mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 477 | outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels); |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
| 481 | /** |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 482 | * Return the range of display sizes an application can expect to encounter |
| 483 | * under normal operation, as long as there is no physical change in screen |
| 484 | * size. This is basically the sizes you will see as the orientation |
| 485 | * changes, taking into account whatever screen decoration there is in |
| 486 | * each rotation. For example, the status bar is always at the top of the |
| 487 | * screen, so it will reduce the height both in landscape and portrait, and |
| 488 | * the smallest height returned here will be the smaller of the two. |
| 489 | * |
| 490 | * This is intended for applications to get an idea of the range of sizes |
| 491 | * they will encounter while going through device rotations, to provide a |
| 492 | * stable UI through rotation. The sizes here take into account all standard |
| 493 | * system decorations that reduce the size actually available to the |
| 494 | * application: the status bar, navigation bar, system bar, etc. It does |
| 495 | * <em>not</em> take into account more transient elements like an IME |
| 496 | * soft keyboard. |
| 497 | * |
| 498 | * @param outSmallestSize Filled in with the smallest width and height |
| 499 | * that the application will encounter, in pixels (not dp units). The x |
| 500 | * (width) dimension here directly corresponds to |
| 501 | * {@link android.content.res.Configuration#smallestScreenWidthDp |
| 502 | * Configuration.smallestScreenWidthDp}, except the value here is in raw |
| 503 | * screen pixels rather than dp units. Your application may of course |
| 504 | * still get smaller space yet if, for example, a soft keyboard is |
| 505 | * being displayed. |
| 506 | * @param outLargestSize Filled in with the largest width and height |
| 507 | * that the application will encounter, in pixels (not dp units). Your |
| 508 | * application may of course still get larger space than this if, |
| 509 | * for example, screen decorations like the status bar are being hidden. |
| 510 | */ |
| 511 | public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 512 | synchronized (this) { |
| 513 | updateDisplayInfoLocked(); |
| 514 | outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth; |
| 515 | outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight; |
| 516 | outLargestSize.x = mDisplayInfo.largestNominalAppWidth; |
| 517 | outLargestSize.y = mDisplayInfo.largestNominalAppHeight; |
Dianne Hackborn | 68c33ca | 2012-04-19 14:51:25 -0700 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | |
| 521 | /** |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 522 | * Return the maximum screen size dimension that will happen. This is |
| 523 | * mostly for wallpapers. |
| 524 | * @hide |
| 525 | */ |
| 526 | public int getMaximumSizeDimension() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 527 | synchronized (this) { |
| 528 | updateDisplayInfoLocked(); |
| 529 | return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight); |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * @deprecated Use {@link #getSize(Point)} instead. |
| 535 | */ |
| 536 | @Deprecated |
| 537 | public int getWidth() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 538 | synchronized (this) { |
| 539 | updateCachedAppSizeIfNeededLocked(); |
| 540 | return mCachedAppWidthCompat; |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * @deprecated Use {@link #getSize(Point)} instead. |
| 546 | */ |
| 547 | @Deprecated |
| 548 | public int getHeight() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 549 | synchronized (this) { |
| 550 | updateCachedAppSizeIfNeededLocked(); |
| 551 | return mCachedAppHeightCompat; |
Dianne Hackborn | ac8dea1 | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 555 | /** |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 556 | * @hide |
| 557 | * Return a rectangle defining the insets of the overscan region of the display. |
| 558 | * Each field of the rectangle is the number of pixels the overscan area extends |
| 559 | * into the display on that side. |
| 560 | */ |
| 561 | public void getOverscanInsets(Rect outRect) { |
| 562 | synchronized (this) { |
| 563 | updateDisplayInfoLocked(); |
| 564 | outRect.set(mDisplayInfo.overscanLeft, mDisplayInfo.overscanTop, |
| 565 | mDisplayInfo.overscanRight, mDisplayInfo.overscanBottom); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | /** |
Dianne Hackborn | 5cb70b5 | 2010-02-25 17:01:14 -0800 | [diff] [blame] | 570 | * Returns the rotation of the screen from its "natural" orientation. |
| 571 | * The returned value may be {@link Surface#ROTATION_0 Surface.ROTATION_0} |
| 572 | * (no rotation), {@link Surface#ROTATION_90 Surface.ROTATION_90}, |
| 573 | * {@link Surface#ROTATION_180 Surface.ROTATION_180}, or |
| 574 | * {@link Surface#ROTATION_270 Surface.ROTATION_270}. For |
| 575 | * example, if a device has a naturally tall screen, and the user has |
| 576 | * turned it on its side to go into a landscape orientation, the value |
| 577 | * returned here may be either {@link Surface#ROTATION_90 Surface.ROTATION_90} |
| 578 | * or {@link Surface#ROTATION_270 Surface.ROTATION_270} depending on |
| 579 | * the direction it was turned. The angle is the rotation of the drawn |
| 580 | * graphics on the screen, which is the opposite direction of the physical |
| 581 | * rotation of the device. For example, if the device is rotated 90 |
| 582 | * degrees counter-clockwise, to compensate rendering will be rotated by |
| 583 | * 90 degrees clockwise and thus the returned value here will be |
| 584 | * {@link Surface#ROTATION_90 Surface.ROTATION_90}. |
| 585 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 586 | @Surface.Rotation |
Dianne Hackborn | 5cb70b5 | 2010-02-25 17:01:14 -0800 | [diff] [blame] | 587 | public int getRotation() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 588 | synchronized (this) { |
| 589 | updateDisplayInfoLocked(); |
| 590 | return mDisplayInfo.rotation; |
| 591 | } |
Dianne Hackborn | 5cb70b5 | 2010-02-25 17:01:14 -0800 | [diff] [blame] | 592 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 593 | |
Dianne Hackborn | 5cb70b5 | 2010-02-25 17:01:14 -0800 | [diff] [blame] | 594 | /** |
Joe Onorato | 4c904a3 | 2010-02-26 12:35:55 -0800 | [diff] [blame] | 595 | * @deprecated use {@link #getRotation} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | * @return orientation of this display. |
| 597 | */ |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 598 | @Deprecated |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 599 | @Surface.Rotation |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 600 | public int getOrientation() { |
| 601 | return getRotation(); |
| 602 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | |
| 604 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 605 | * Gets the pixel format of the display. |
| 606 | * @return One of the constants defined in {@link android.graphics.PixelFormat}. |
| 607 | * |
| 608 | * @deprecated This method is no longer supported. |
| 609 | * The result is always {@link PixelFormat#RGBA_8888}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | */ |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 611 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | public int getPixelFormat() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 613 | return PixelFormat.RGBA_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 617 | * 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] | 618 | */ |
| 619 | public float getRefreshRate() { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 620 | synchronized (this) { |
| 621 | updateDisplayInfoLocked(); |
| 622 | return mDisplayInfo.refreshRate; |
| 623 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | /** |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 627 | * Get the supported refresh rates of this display in frames per second. |
| 628 | */ |
| 629 | public float[] getSupportedRefreshRates() { |
| 630 | synchronized (this) { |
| 631 | updateDisplayInfoLocked(); |
| 632 | final float[] refreshRates = mDisplayInfo.supportedRefreshRates; |
| 633 | return Arrays.copyOf(refreshRates, refreshRates.length); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | /** |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 638 | * Gets the app VSYNC offset, in nanoseconds. This is a positive value indicating |
| 639 | * the phase offset of the VSYNC events provided by Choreographer relative to the |
| 640 | * display refresh. For example, if Choreographer reports that the refresh occurred |
| 641 | * at time N, it actually occurred at (N - appVsyncOffset). |
| 642 | * <p> |
| 643 | * Apps generally do not need to be aware of this. It's only useful for fine-grained |
| 644 | * A/V synchronization. |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 645 | */ |
| 646 | public long getAppVsyncOffsetNanos() { |
| 647 | synchronized (this) { |
| 648 | updateDisplayInfoLocked(); |
| 649 | return mDisplayInfo.appVsyncOffsetNanos; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * This is how far in advance a buffer must be queued for presentation at |
| 655 | * a given time. If you want a buffer to appear on the screen at |
| 656 | * time N, you must submit the buffer before (N - presentationDeadline). |
| 657 | * <p> |
| 658 | * The desired presentation time for GLES rendering may be set with |
| 659 | * {@link android.opengl.EGLExt#eglPresentationTimeANDROID}. For video decoding, use |
| 660 | * {@link android.media.MediaCodec#releaseOutputBuffer(int, long)}. Times are |
| 661 | * expressed in nanoseconds, using the system monotonic clock |
| 662 | * ({@link System#nanoTime}). |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 663 | */ |
| 664 | public long getPresentationDeadlineNanos() { |
| 665 | synchronized (this) { |
| 666 | updateDisplayInfoLocked(); |
| 667 | return mDisplayInfo.presentationDeadlineNanos; |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | /** |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 672 | * Gets display metrics that describe the size and density of this display. |
| 673 | * <p> |
| 674 | * The size is adjusted based on the current rotation of the display. |
| 675 | * </p><p> |
| 676 | * The size returned by this method does not necessarily represent the |
| 677 | * actual raw size (native resolution) of the display. The returned size may |
| 678 | * be adjusted to exclude certain system decor elements that are always visible. |
| 679 | * It may also be scaled to provide compatibility with older applications that |
| 680 | * were originally designed for smaller displays. |
| 681 | * </p> |
| 682 | * |
| 683 | * @param outMetrics A {@link DisplayMetrics} object to receive the metrics. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | */ |
| 685 | public void getMetrics(DisplayMetrics outMetrics) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 686 | synchronized (this) { |
| 687 | updateDisplayInfoLocked(); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 688 | mDisplayInfo.getAppMetrics(outMetrics, mDisplayAdjustments); |
Dianne Hackborn | 68066c2 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 689 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 690 | } |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 691 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 692 | /** |
| 693 | * Gets the real size of the display without subtracting any window decor or |
| 694 | * applying any compatibility scale factors. |
| 695 | * <p> |
| 696 | * The size is adjusted based on the current rotation of the display. |
| 697 | * </p><p> |
| 698 | * The real size may be smaller than the physical size of the screen when the |
| 699 | * window manager is emulating a smaller display (using adb shell am display-size). |
| 700 | * </p> |
| 701 | * |
| 702 | * @param outSize Set to the real size of the display. |
| 703 | */ |
| 704 | public void getRealSize(Point outSize) { |
| 705 | synchronized (this) { |
| 706 | updateDisplayInfoLocked(); |
| 707 | outSize.x = mDisplayInfo.logicalWidth; |
| 708 | outSize.y = mDisplayInfo.logicalHeight; |
| 709 | } |
Dianne Hackborn | 68066c2 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /** |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 713 | * Gets display metrics based on the real size of this display. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 714 | * <p> |
| 715 | * The size is adjusted based on the current rotation of the display. |
| 716 | * </p><p> |
| 717 | * The real size may be smaller than the physical size of the screen when the |
| 718 | * window manager is emulating a smaller display (using adb shell am display-size). |
| 719 | * </p> |
| 720 | * |
| 721 | * @param outMetrics A {@link DisplayMetrics} object to receive the metrics. |
Dianne Hackborn | 68066c2 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 722 | */ |
| 723 | public void getRealMetrics(DisplayMetrics outMetrics) { |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 724 | synchronized (this) { |
| 725 | updateDisplayInfoLocked(); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 726 | mDisplayInfo.getLogicalMetrics(outMetrics, |
| 727 | CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 728 | mDisplayAdjustments.getConfiguration()); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 729 | } |
Dianne Hackborn | 68066c2 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 732 | /** |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 733 | * Gets the state of the display, such as whether it is on or off. |
| 734 | * |
| 735 | * @return The state of the display: one of {@link #STATE_OFF}, {@link #STATE_ON}, |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 736 | * {@link #STATE_DOZE}, {@link #STATE_DOZE_SUSPEND}, or {@link #STATE_UNKNOWN}. |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 737 | */ |
| 738 | public int getState() { |
| 739 | synchronized (this) { |
| 740 | updateDisplayInfoLocked(); |
| 741 | return mIsValid ? mDisplayInfo.state : STATE_UNKNOWN; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | /** |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 746 | * Returns true if the specified UID has access to this display. |
| 747 | * @hide |
| 748 | */ |
| 749 | public boolean hasAccess(int uid) { |
| 750 | return Display.hasAccess(uid, mFlags, mOwnerUid); |
| 751 | } |
| 752 | |
| 753 | /** @hide */ |
| 754 | public static boolean hasAccess(int uid, int flags, int ownerUid) { |
| 755 | return (flags & Display.FLAG_PRIVATE) == 0 |
| 756 | || uid == ownerUid |
| 757 | || uid == Process.SYSTEM_UID |
| 758 | || uid == 0; |
| 759 | } |
| 760 | |
Jeff Brown | 69b0716 | 2013-11-07 00:30:16 -0800 | [diff] [blame] | 761 | /** |
| 762 | * Returns true if the display is a public presentation display. |
| 763 | * @hide |
| 764 | */ |
| 765 | public boolean isPublicPresentation() { |
| 766 | return (mFlags & (Display.FLAG_PRIVATE | Display.FLAG_PRESENTATION)) == |
| 767 | Display.FLAG_PRESENTATION; |
| 768 | } |
| 769 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 770 | private void updateDisplayInfoLocked() { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 771 | // Note: The display manager caches display info objects on our behalf. |
| 772 | DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId); |
| 773 | if (newInfo == null) { |
| 774 | // Preserve the old mDisplayInfo after the display is removed. |
| 775 | if (mIsValid) { |
| 776 | mIsValid = false; |
| 777 | if (DEBUG) { |
| 778 | Log.d(TAG, "Logical display " + mDisplayId + " was removed."); |
| 779 | } |
| 780 | } |
| 781 | } else { |
| 782 | // Use the new display info. (It might be the same object if nothing changed.) |
| 783 | mDisplayInfo = newInfo; |
| 784 | if (!mIsValid) { |
| 785 | mIsValid = true; |
| 786 | if (DEBUG) { |
| 787 | Log.d(TAG, "Logical display " + mDisplayId + " was recreated."); |
| 788 | } |
| 789 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 790 | } |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 793 | private void updateCachedAppSizeIfNeededLocked() { |
| 794 | long now = SystemClock.uptimeMillis(); |
| 795 | if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) { |
| 796 | updateDisplayInfoLocked(); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 797 | mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 798 | mCachedAppWidthCompat = mTempMetrics.widthPixels; |
| 799 | mCachedAppHeightCompat = mTempMetrics.heightPixels; |
| 800 | mLastCachedAppSizeUpdate = now; |
| 801 | } |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 802 | } |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 803 | |
| 804 | // For debugging purposes |
| 805 | @Override |
| 806 | public String toString() { |
| 807 | synchronized (this) { |
| 808 | updateDisplayInfoLocked(); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 809 | mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments); |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 810 | return "Display id " + mDisplayId + ": " + mDisplayInfo |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 811 | + ", " + mTempMetrics + ", isValid=" + mIsValid; |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 812 | } |
| 813 | } |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 814 | |
| 815 | /** |
| 816 | * @hide |
| 817 | */ |
| 818 | public static String typeToString(int type) { |
| 819 | switch (type) { |
| 820 | case TYPE_UNKNOWN: |
| 821 | return "UNKNOWN"; |
| 822 | case TYPE_BUILT_IN: |
| 823 | return "BUILT_IN"; |
| 824 | case TYPE_HDMI: |
| 825 | return "HDMI"; |
| 826 | case TYPE_WIFI: |
| 827 | return "WIFI"; |
| 828 | case TYPE_OVERLAY: |
| 829 | return "OVERLAY"; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 830 | case TYPE_VIRTUAL: |
| 831 | return "VIRTUAL"; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 832 | default: |
| 833 | return Integer.toString(type); |
| 834 | } |
| 835 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 836 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 837 | /** |
| 838 | * @hide |
| 839 | */ |
| 840 | public static String stateToString(int state) { |
| 841 | switch (state) { |
| 842 | case STATE_UNKNOWN: |
| 843 | return "UNKNOWN"; |
| 844 | case STATE_OFF: |
| 845 | return "OFF"; |
| 846 | case STATE_ON: |
| 847 | return "ON"; |
Jeff Brown | 5dc2191 | 2014-07-17 18:50:18 -0700 | [diff] [blame] | 848 | case STATE_DOZE: |
| 849 | return "DOZE"; |
| 850 | case STATE_DOZE_SUSPEND: |
| 851 | return "DOZE_SUSPEND"; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 852 | default: |
| 853 | return Integer.toString(state); |
| 854 | } |
| 855 | } |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 856 | |
| 857 | /** |
| 858 | * Returns true if display updates may be suspended while in the specified |
| 859 | * display power state. |
| 860 | * @hide |
| 861 | */ |
| 862 | public static boolean isSuspendedState(int state) { |
| 863 | return state == STATE_OFF || state == STATE_DOZE_SUSPEND; |
| 864 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 865 | } |