Display.java revision 1abaa53dccccc5c94a395bad5fa54cf6783b6974
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/* 29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2006 The Android Open Source Project 39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License. 69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at 79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and 149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License. 159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.view; 189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1948d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautnerimport android.content.res.CompatibilityInfo; 20fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brownimport android.graphics.PixelFormat; 21ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackbornimport android.graphics.Point; 22ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackbornimport android.graphics.Rect; 23bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brownimport android.hardware.display.DisplayManagerGlobal; 24a506a6ec94863a35acca9feb165db76ddac3892cJeff Brownimport android.os.Process; 25ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackbornimport android.os.SystemClock; 269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.DisplayMetrics; 27fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brownimport android.util.Log; 289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 29bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown/** 30fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * Provides information about the size and density of a logical display. 31fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <p> 32fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * The display area is described in two different ways. 33fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <ul> 34fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <li>The application display area specifies the part of the display that may contain 35fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * an application window, excluding the system decorations. The application display area may 36fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * be smaller than the real display area because the system subtracts the space needed 37fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * for decor elements such as the status bar. Use the following methods to query the 38fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * application display area: {@link #getSize}, {@link #getRectSize} and {@link #getMetrics}.</li> 39fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <li>The real display area specifies the part of the display that contains content 40fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * including the system decorations. Even so, the real display area may be smaller than the 41fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * physical size of the display if the window manager is emulating a smaller display 42fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * using (adb shell am display-size). Use the following methods to query the 43fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * real display area: {@link #getRealSize}, {@link #getRealMetrics}.</li> 44fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </ul> 45fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </p><p> 46fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * A logical display does not necessarily represent a particular physical display device 47fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * such as the built-in screen or an external monitor. The contents of a logical 48fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * display may be presented on one or more physical displays according to the devices 49fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * that are currently attached and whether mirroring has been enabled. 50fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </p> 51bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown */ 52fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brownpublic final class Display { 53fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown private static final String TAG = "Display"; 54bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown private static final boolean DEBUG = false; 55fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown 56bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown private final DisplayManagerGlobal mGlobal; 57fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown private final int mDisplayId; 584ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown private final int mLayerStack; 5992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown private final int mFlags; 6092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown private final int mType; 6192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown private final String mAddress; 62a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown private final int mOwnerUid; 63a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown private final String mOwnerPackageName; 6448d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner private final DisplayAdjustments mDisplayAdjustments; 65bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown 66bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown private DisplayInfo mDisplayInfo; // never null 67bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown private boolean mIsValid; 68fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown 69fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown // Temporary display metrics structure used for compatibility mode. 70fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown private final DisplayMetrics mTempMetrics = new DisplayMetrics(); 71fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown 72fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown // We cache the app width and height properties briefly between calls 73fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown // to getHeight() and getWidth() to ensure that applications perceive 74fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown // consistent results when the size changes (most of the time). 75fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown // Applications should now be using getSize() instead. 76fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown private static final int CACHED_APP_SIZE_DURATION_MILLIS = 20; 77fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown private long mLastCachedAppSizeUpdate; 78fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown private int mCachedAppWidthCompat; 79fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown private int mCachedAppHeightCompat; 805fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn 819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8298365d7663cbd82979a5700faf0050220b01084dJeff Brown * The default Display id, which is the id of the built-in primary display 8398365d7663cbd82979a5700faf0050220b01084dJeff Brown * assuming there is one. 849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT_DISPLAY = 0; 869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8877aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown * Display flag: Indicates that the display supports compositing content 8977aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown * that is stored in protected graphics buffers. 90c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown * <p> 91f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * If this flag is set then the display device supports compositing protected buffers. 92f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * </p><p> 93f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * If this flag is not set then the display device may not support compositing 94f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * protected buffers; the user may see a blank region on the screen instead of 95f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * the protected content. 96f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * </p><p> 9777aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown * Secure (DRM) video decoders may allocate protected graphics buffers to request that 9877aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown * a hardware-protected path be provided between the video decoder and the external 9977aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown * display sink. If a hardware-protected path is not available, then content stored 10077aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown * in protected graphics buffers may not be composited. 101c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown * </p><p> 102f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * An application can use the absence of this flag as a hint that it should not use protected 103f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * buffers for this display because the content may not be visible. For example, 104f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * if the flag is not set then the application may choose not to show content on this 105f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * display, show an informative error message, select an alternate content stream 106f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * or adopt a different strategy for decoding content that does not rely on 107f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * protected buffers. 108c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown * </p> 109f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * 110f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * @see #getFlags 111c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown */ 11277aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 0; 113c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown 114c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown /** 115f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * Display flag: Indicates that the display has a secure video output and 116f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * supports compositing secure surfaces. 117f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * <p> 118f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * If this flag is set then the display device has a secure video output 119f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * and is capable of showing secure surfaces. It may also be capable of 120f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * showing {@link #FLAG_SUPPORTS_PROTECTED_BUFFERS protected buffers}. 121f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * </p><p> 122f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * If this flag is not set then the display device may not have a secure video 123f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * output; the user may see a blank region on the screen instead of 124f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * the contents of secure surfaces or protected buffers. 125f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * </p><p> 126f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * Secure surfaces are used to prevent content rendered into those surfaces 127f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * by applications from appearing in screenshots or from being viewed 128f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * on non-secure displays. Protected buffers are used by secure video decoders 129f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * for a similar purpose. 130f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * </p><p> 131f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * An application creates a window with a secure surface by specifying the 132f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * {@link WindowManager.LayoutParams#FLAG_SECURE} window flag. 133f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * Likewise, an application creates a {@link SurfaceView} with a secure surface 134f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * by calling {@link SurfaceView#setSecure} before attaching the secure view to 135f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * its containing window. 136f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * </p><p> 137f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * An application can use the absence of this flag as a hint that it should not create 138f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * secure surfaces or protected buffers on this display because the content may 139f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * not be visible. For example, if the flag is not set then the application may 140f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * choose not to show content on this display, show an informative error message, 141f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * select an alternate content stream or adopt a different strategy for decoding 142f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * content that does not rely on secure surfaces or protected buffers. 143f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * </p> 144f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * 145f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * @see #getFlags 146f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown */ 147f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown public static final int FLAG_SECURE = 1 << 1; 148f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown 149f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown /** 150a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * Display flag: Indicates that the display is private. Only the application that 151a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * owns the display can create windows on it. 152a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * <p> 153a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * This flag is associated with displays that were created using 154a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * {@link android.hardware.display.DisplayManager#createPrivateVirtualDisplay}. 155a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * </p> 156a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * 157a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * @see #getFlags 158a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown */ 159a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown public static final int FLAG_PRIVATE = 1 << 2; 160a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown 161a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown /** 16292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * Display type: Unknown display type. 16392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @hide 16492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown */ 16592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown public static final int TYPE_UNKNOWN = 0; 16692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown 16792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown /** 16892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * Display type: Built-in display. 16992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @hide 17092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown */ 17192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown public static final int TYPE_BUILT_IN = 1; 17292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown 17392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown /** 17492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * Display type: HDMI display. 17592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @hide 17692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown */ 17792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown public static final int TYPE_HDMI = 2; 17892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown 17992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown /** 18092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * Display type: WiFi display. 18192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @hide 18292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown */ 18392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown public static final int TYPE_WIFI = 3; 18492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown 18592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown /** 18692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * Display type: Overlay display. 18792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @hide 18892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown */ 18992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown public static final int TYPE_OVERLAY = 4; 19092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown 19192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown /** 192a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * Display type: Virtual display. 193a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * @hide 194a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown */ 195a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown public static final int TYPE_VIRTUAL = 5; 196a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown 197a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown /** 198fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * Internal method to create a display. 199fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * Applications should use {@link android.view.WindowManager#getDefaultDisplay()} 20098365d7663cbd82979a5700faf0050220b01084dJeff Brown * or {@link android.hardware.display.DisplayManager#getDisplay} 20198365d7663cbd82979a5700faf0050220b01084dJeff Brown * to get a display object. 202fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * 203fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * @hide 2049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 205bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown public Display(DisplayManagerGlobal global, 206bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown int displayId, DisplayInfo displayInfo /*not null*/, 20748d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner DisplayAdjustments daj) { 208bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown mGlobal = global; 209fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown mDisplayId = displayId; 210bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown mDisplayInfo = displayInfo; 2111abaa53dccccc5c94a395bad5fa54cf6783b6974Craig Mautner mDisplayAdjustments = new DisplayAdjustments(daj); 212bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown mIsValid = true; 21392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown 21492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown // Cache properties that cannot change as long as the display is valid. 21592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown mLayerStack = displayInfo.layerStack; 21692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown mFlags = displayInfo.flags; 21792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown mType = displayInfo.type; 21892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown mAddress = displayInfo.address; 219a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown mOwnerUid = displayInfo.ownerUid; 220a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown mOwnerPackageName = displayInfo.ownerPackageName; 2215fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn } 2225fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn 2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 224fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * Gets the display id. 225fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <p> 226fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * Each logical display has a unique id. 227fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * The default display has id {@link #DEFAULT_DISPLAY}. 228fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </p> 2299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int getDisplayId() { 231fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown return mDisplayId; 2329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 235bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * Returns true if this display is still valid, false if the display has been removed. 236bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * 237bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * If the display is invalid, then the methods of this class will 238bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * continue to report the most recently observed display information. 239bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * However, it is unwise (and rather fruitless) to continue using a 240bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * {@link Display} object after the display's demise. 241bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * 242bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * It's possible for a display that was previously invalid to become 243bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * valid again if a display with the same id is reconnected. 244bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * 245bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * @return True if the display is still valid. 246bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown */ 247bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown public boolean isValid() { 248bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown synchronized (this) { 249bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown updateDisplayInfoLocked(); 250bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown return mIsValid; 251bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown } 252bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown } 253bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown 254bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown /** 2552ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown * Gets a full copy of the display information. 2562ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown * 2572ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown * @param outDisplayInfo The object to receive the copy of the display information. 258bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown * @return True if the display is still valid. 2592ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown * @hide 2602ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown */ 261bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown public boolean getDisplayInfo(DisplayInfo outDisplayInfo) { 2622ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown synchronized (this) { 2632ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown updateDisplayInfoLocked(); 2642ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown outDisplayInfo.copyFrom(mDisplayInfo); 265bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown return mIsValid; 2662ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown } 2672ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown } 2682ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown 2692ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown /** 27098365d7663cbd82979a5700faf0050220b01084dJeff Brown * Gets the display's layer stack. 27198365d7663cbd82979a5700faf0050220b01084dJeff Brown * 27298365d7663cbd82979a5700faf0050220b01084dJeff Brown * Each display has its own independent layer stack upon which surfaces 27398365d7663cbd82979a5700faf0050220b01084dJeff Brown * are placed to be managed by surface flinger. 27498365d7663cbd82979a5700faf0050220b01084dJeff Brown * 2754ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown * @return The display's layer stack number. 27698365d7663cbd82979a5700faf0050220b01084dJeff Brown * @hide 27798365d7663cbd82979a5700faf0050220b01084dJeff Brown */ 27898365d7663cbd82979a5700faf0050220b01084dJeff Brown public int getLayerStack() { 2794ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown return mLayerStack; 28098365d7663cbd82979a5700faf0050220b01084dJeff Brown } 28198365d7663cbd82979a5700faf0050220b01084dJeff Brown 28298365d7663cbd82979a5700faf0050220b01084dJeff Brown /** 283c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown * Returns a combination of flags that describe the capabilities of the display. 284c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown * 285c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown * @return The display flags. 286c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown * 28777aebfdbae489c3712ae3f9bca29d01fb1f09dc2Jeff Brown * @see #FLAG_SUPPORTS_PROTECTED_BUFFERS 288f0681b34dffc1510cbd9c3da5c3a7e695553fa8dJeff Brown * @see #FLAG_SECURE 289a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * @see #FLAG_PRIVATE 290c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown */ 291c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown public int getFlags() { 29292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown return mFlags; 29392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown } 29492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown 29592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown /** 29692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * Gets the display type. 29792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * 29892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @return The display type. 29992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * 30092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @see #TYPE_UNKNOWN 30192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @see #TYPE_BUILT_IN 30292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @see #TYPE_HDMI 30392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @see #TYPE_WIFI 30492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @see #TYPE_OVERLAY 305a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * @see #TYPE_VIRTUAL 30692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @hide 30792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown */ 30892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown public int getType() { 30992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown return mType; 31092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown } 31192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown 31292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown /** 31392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * Gets the display address, or null if none. 31492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * Interpretation varies by display type. 31592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * 31692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @return The display address. 31792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @hide 31892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown */ 31992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown public String getAddress() { 32092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown return mAddress; 321c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown } 322c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown 323c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown /** 324a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * Gets the UID of the application that owns this display, or zero if it is 325a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * owned by the system. 326a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * <p> 327a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * If the display is private, then only the owner can use it. 328a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * </p> 329a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * 330a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * @hide 331a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown */ 332a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown public int getOwnerUid() { 333a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown return mOwnerUid; 334a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown } 335a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown 336a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown /** 337a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * Gets the package name of the application that owns this display, or null if it is 338a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * owned by the system. 339a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * <p> 340a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * If the display is private, then only the owner can use it. 341a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * </p> 342a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * 343a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * @hide 344a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown */ 345a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown public String getOwnerPackageName() { 346a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown return mOwnerPackageName; 347a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown } 348a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown 349a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown /** 35098365d7663cbd82979a5700faf0050220b01084dJeff Brown * Gets the compatibility info used by this display instance. 35198365d7663cbd82979a5700faf0050220b01084dJeff Brown * 35248d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner * @return The display adjustments holder, or null if none is required. 35398365d7663cbd82979a5700faf0050220b01084dJeff Brown * @hide 35498365d7663cbd82979a5700faf0050220b01084dJeff Brown */ 35548d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner public DisplayAdjustments getDisplayAdjustments() { 35648d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner return mDisplayAdjustments; 35798365d7663cbd82979a5700faf0050220b01084dJeff Brown } 35898365d7663cbd82979a5700faf0050220b01084dJeff Brown 35998365d7663cbd82979a5700faf0050220b01084dJeff Brown /** 3604ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown * Gets the name of the display. 36192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * <p> 36292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * Note that some displays may be renamed by the user. 36392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * </p> 36492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * 3654ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown * @return The display's name. 3664ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown */ 3674ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown public String getName() { 36892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown synchronized (this) { 36992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown updateDisplayInfoLocked(); 37092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown return mDisplayInfo.name; 37192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown } 3724ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown } 3734ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown 3744ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown /** 375bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * Gets the size of the display, in pixels. 376bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * <p> 377bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * Note that this value should <em>not</em> be used for computing layouts, 378bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * since a device will typically have screen decoration (such as a status bar) 3795cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * along the edges of the display that reduce the amount of application 380bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * space available from the size returned here. Layouts should instead use 381bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * the window size. 382bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * </p><p> 383bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * The size is adjusted based on the current rotation of the display. 384bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * </p><p> 385bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * The size returned by this method does not necessarily represent the 386bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * actual raw size (native resolution) of the display. The returned size may 387fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * be adjusted to exclude certain system decoration elements that are always visible. 388bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * It may also be scaled to provide compatibility with older applications that 389bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * were originally designed for smaller displays. 390bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * </p> 391bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * 392bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * @param outSize A {@link Point} object to receive the size information. 3939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 394ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn public void getSize(Point outSize) { 395fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown synchronized (this) { 396fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateDisplayInfoLocked(); 39748d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments); 398fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown outSize.x = mTempMetrics.widthPixels; 399fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown outSize.y = mTempMetrics.heightPixels; 400ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn } 401ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn } 402fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown 4039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 404bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * Gets the size of the display as a rectangle, in pixels. 405bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * 406bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * @param outSize A {@link Rect} object to receive the size information. 407bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * @see #getSize(Point) 4089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 409ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn public void getRectSize(Rect outSize) { 410fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown synchronized (this) { 411fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateDisplayInfoLocked(); 41248d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments); 413fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels); 414ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn } 415ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn } 4169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 417ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn /** 41868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * Return the range of display sizes an application can expect to encounter 41968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * under normal operation, as long as there is no physical change in screen 42068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * size. This is basically the sizes you will see as the orientation 42168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * changes, taking into account whatever screen decoration there is in 42268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * each rotation. For example, the status bar is always at the top of the 42368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * screen, so it will reduce the height both in landscape and portrait, and 42468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * the smallest height returned here will be the smaller of the two. 42568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * 42668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * This is intended for applications to get an idea of the range of sizes 42768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * they will encounter while going through device rotations, to provide a 42868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * stable UI through rotation. The sizes here take into account all standard 42968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * system decorations that reduce the size actually available to the 43068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * application: the status bar, navigation bar, system bar, etc. It does 43168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * <em>not</em> take into account more transient elements like an IME 43268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * soft keyboard. 43368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * 43468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * @param outSmallestSize Filled in with the smallest width and height 43568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * that the application will encounter, in pixels (not dp units). The x 43668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * (width) dimension here directly corresponds to 43768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * {@link android.content.res.Configuration#smallestScreenWidthDp 43868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * Configuration.smallestScreenWidthDp}, except the value here is in raw 43968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * screen pixels rather than dp units. Your application may of course 44068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * still get smaller space yet if, for example, a soft keyboard is 44168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * being displayed. 44268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * @param outLargestSize Filled in with the largest width and height 44368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * that the application will encounter, in pixels (not dp units). Your 44468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * application may of course still get larger space than this if, 44568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn * for example, screen decorations like the status bar are being hidden. 44668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn */ 44768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) { 448fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown synchronized (this) { 449fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateDisplayInfoLocked(); 450fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth; 451fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight; 452fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown outLargestSize.x = mDisplayInfo.largestNominalAppWidth; 453fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown outLargestSize.y = mDisplayInfo.largestNominalAppHeight; 45468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn } 45568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn } 45668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn 45768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn /** 458ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn * Return the maximum screen size dimension that will happen. This is 459ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn * mostly for wallpapers. 460ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn * @hide 461ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn */ 462ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn public int getMaximumSizeDimension() { 463fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown synchronized (this) { 464fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateDisplayInfoLocked(); 465fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight); 466ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn } 467ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn } 468ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn 469ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn /** 470ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn * @deprecated Use {@link #getSize(Point)} instead. 471ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn */ 472ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn @Deprecated 473ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn public int getWidth() { 474fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown synchronized (this) { 475fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateCachedAppSizeIfNeededLocked(); 476fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown return mCachedAppWidthCompat; 477ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn } 478ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn } 479ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn 480ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn /** 481ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn * @deprecated Use {@link #getSize(Point)} instead. 482ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn */ 483ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn @Deprecated 484ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn public int getHeight() { 485fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown synchronized (this) { 486fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateCachedAppSizeIfNeededLocked(); 487fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown return mCachedAppHeightCompat; 488bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown } 489bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown } 490ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn 491bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown /** 492c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn * @hide 493c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn * Return a rectangle defining the insets of the overscan region of the display. 494c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn * Each field of the rectangle is the number of pixels the overscan area extends 495c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn * into the display on that side. 496c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn */ 497c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn public void getOverscanInsets(Rect outRect) { 498c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn synchronized (this) { 499c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn updateDisplayInfoLocked(); 500c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn outRect.set(mDisplayInfo.overscanLeft, mDisplayInfo.overscanTop, 501c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn mDisplayInfo.overscanRight, mDisplayInfo.overscanBottom); 502c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn } 503c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn } 504c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn 505c652de8141f5b8e3c6bcf8916842b6e106413b1aDianne Hackborn /** 5065cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * Returns the rotation of the screen from its "natural" orientation. 5075cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * The returned value may be {@link Surface#ROTATION_0 Surface.ROTATION_0} 5085cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * (no rotation), {@link Surface#ROTATION_90 Surface.ROTATION_90}, 5095cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * {@link Surface#ROTATION_180 Surface.ROTATION_180}, or 5105cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * {@link Surface#ROTATION_270 Surface.ROTATION_270}. For 5115cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * example, if a device has a naturally tall screen, and the user has 5125cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * turned it on its side to go into a landscape orientation, the value 5135cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * returned here may be either {@link Surface#ROTATION_90 Surface.ROTATION_90} 5145cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * or {@link Surface#ROTATION_270 Surface.ROTATION_270} depending on 5155cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * the direction it was turned. The angle is the rotation of the drawn 5165cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * graphics on the screen, which is the opposite direction of the physical 5175cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * rotation of the device. For example, if the device is rotated 90 5185cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * degrees counter-clockwise, to compensate rendering will be rotated by 5195cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * 90 degrees clockwise and thus the returned value here will be 5205cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn * {@link Surface#ROTATION_90 Surface.ROTATION_90}. 5215cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn */ 5225cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn public int getRotation() { 523fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown synchronized (this) { 524fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateDisplayInfoLocked(); 525fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown return mDisplayInfo.rotation; 526fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown } 5275cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn } 528fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown 5295cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn /** 5304c904a3bf3dbe98607b5e3f706ee8ef8887ee104Joe Onorato * @deprecated use {@link #getRotation} 5319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return orientation of this display. 5329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 533fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown @Deprecated 534fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown public int getOrientation() { 535fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown return getRotation(); 536fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown } 5379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 539fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * Gets the pixel format of the display. 540fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * @return One of the constants defined in {@link android.graphics.PixelFormat}. 541fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * 542fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * @deprecated This method is no longer supported. 543fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * The result is always {@link PixelFormat#RGBA_8888}. 5449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 545fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown @Deprecated 5469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public int getPixelFormat() { 547fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown return PixelFormat.RGBA_8888; 5489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 549fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown 5509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 551fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * Gets the refresh rate of this display in frames per second. 5529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public float getRefreshRate() { 554fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown synchronized (this) { 555fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateDisplayInfoLocked(); 556fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown return mDisplayInfo.refreshRate; 557fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown } 5589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 559fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown 5609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 561bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * Gets display metrics that describe the size and density of this display. 562bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * <p> 563bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * The size is adjusted based on the current rotation of the display. 564bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * </p><p> 565bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * The size returned by this method does not necessarily represent the 566bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * actual raw size (native resolution) of the display. The returned size may 567bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * be adjusted to exclude certain system decor elements that are always visible. 568bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * It may also be scaled to provide compatibility with older applications that 569bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * were originally designed for smaller displays. 570bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * </p> 571bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * 572bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown * @param outMetrics A {@link DisplayMetrics} object to receive the metrics. 5739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void getMetrics(DisplayMetrics outMetrics) { 575fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown synchronized (this) { 576fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateDisplayInfoLocked(); 57748d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner mDisplayInfo.getAppMetrics(outMetrics, mDisplayAdjustments); 57868066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn } 57968066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn } 58068066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn 58168066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn /** 582fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * Gets the real size of the display without subtracting any window decor or 583fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * applying any compatibility scale factors. 584fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <p> 585fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * The size is adjusted based on the current rotation of the display. 586fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </p><p> 587fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * The real size may be smaller than the physical size of the screen when the 588fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * window manager is emulating a smaller display (using adb shell am display-size). 589fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </p> 590fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * 591fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * @param outSize Set to the real size of the display. 59268066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn */ 593fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown public void getRealSize(Point outSize) { 594fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown synchronized (this) { 595fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateDisplayInfoLocked(); 596fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown outSize.x = mDisplayInfo.logicalWidth; 597fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown outSize.y = mDisplayInfo.logicalHeight; 598bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown } 599bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown } 600bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown 601bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown /** 602fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * Gets display metrics based on the real size of this display. 603fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <p> 604fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * The size is adjusted based on the current rotation of the display. 605fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </p><p> 606fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * The real size may be smaller than the physical size of the screen when the 607fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * window manager is emulating a smaller display (using adb shell am display-size). 608fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </p> 609fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * 610fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * @param outMetrics A {@link DisplayMetrics} object to receive the metrics. 61193de746e5554bc9397ca8109f57875d92e64eabcJeff Brown */ 612fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown public void getRealMetrics(DisplayMetrics outMetrics) { 613fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown synchronized (this) { 614fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateDisplayInfoLocked(); 61548d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner mDisplayInfo.getLogicalMetrics(outMetrics, 61648d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, 61748d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner mDisplayAdjustments.getActivityToken()); 618fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown } 61993de746e5554bc9397ca8109f57875d92e64eabcJeff Brown } 62093de746e5554bc9397ca8109f57875d92e64eabcJeff Brown 621a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown /** 622a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * Returns true if the specified UID has access to this display. 623a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown * @hide 624a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown */ 625a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown public boolean hasAccess(int uid) { 626a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown return Display.hasAccess(uid, mFlags, mOwnerUid); 627a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown } 628a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown 629a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown /** @hide */ 630a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown public static boolean hasAccess(int uid, int flags, int ownerUid) { 631a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown return (flags & Display.FLAG_PRIVATE) == 0 632a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown || uid == ownerUid 633a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown || uid == Process.SYSTEM_UID 634a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown || uid == 0; 635a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown } 636a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown 637fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown private void updateDisplayInfoLocked() { 638bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown // Note: The display manager caches display info objects on our behalf. 639bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId); 640bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown if (newInfo == null) { 641bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown // Preserve the old mDisplayInfo after the display is removed. 642bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown if (mIsValid) { 643bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown mIsValid = false; 644bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown if (DEBUG) { 645bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown Log.d(TAG, "Logical display " + mDisplayId + " was removed."); 646bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown } 647bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown } 648bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown } else { 649bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown // Use the new display info. (It might be the same object if nothing changed.) 650bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown mDisplayInfo = newInfo; 651bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown if (!mIsValid) { 652bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown mIsValid = true; 653bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown if (DEBUG) { 654bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown Log.d(TAG, "Logical display " + mDisplayId + " was recreated."); 655bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown } 656bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown } 657fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown } 6589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 660fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown private void updateCachedAppSizeIfNeededLocked() { 661fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown long now = SystemClock.uptimeMillis(); 662fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) { 663fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown updateDisplayInfoLocked(); 66448d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments); 665fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown mCachedAppWidthCompat = mTempMetrics.widthPixels; 666fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown mCachedAppHeightCompat = mTempMetrics.heightPixels; 667fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown mLastCachedAppSizeUpdate = now; 668fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown } 669ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn } 670bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown 671bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown // For debugging purposes 672bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown @Override 673bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown public String toString() { 674bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown synchronized (this) { 675bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown updateDisplayInfoLocked(); 67648d0d1886731ff19ed3fb47a5997be5df0d1bba8Craig Mautner mDisplayInfo.getAppMetrics(mTempMetrics, mDisplayAdjustments); 677bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown return "Display id " + mDisplayId + ": " + mDisplayInfo 678bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown + ", " + mTempMetrics + ", isValid=" + mIsValid; 679bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown } 680bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown } 68192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown 68292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown /** 68392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown * @hide 68492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown */ 68592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown public static String typeToString(int type) { 68692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown switch (type) { 68792130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown case TYPE_UNKNOWN: 68892130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown return "UNKNOWN"; 68992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown case TYPE_BUILT_IN: 69092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown return "BUILT_IN"; 69192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown case TYPE_HDMI: 69292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown return "HDMI"; 69392130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown case TYPE_WIFI: 69492130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown return "WIFI"; 69592130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown case TYPE_OVERLAY: 69692130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown return "OVERLAY"; 697a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown case TYPE_VIRTUAL: 698a506a6ec94863a35acca9feb165db76ddac3892cJeff Brown return "VIRTUAL"; 69992130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown default: 70092130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown return Integer.toString(type); 70192130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown } 70292130f6407dc51c58b3b941d28a6daf4e04b8d62Jeff Brown } 7039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 7049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 705