Display.java revision c5df37c285221d0fb113f55b9e78b35632241d3f
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
19fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brownimport android.graphics.PixelFormat;
20ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackbornimport android.graphics.Point;
21ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackbornimport android.graphics.Rect;
22bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brownimport android.hardware.display.DisplayManagerGlobal;
23ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackbornimport android.os.SystemClock;
249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.DisplayMetrics;
25fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brownimport android.util.Log;
269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
27bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown/**
28fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * Provides information about the size and density of a logical display.
29fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <p>
30fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * The display area is described in two different ways.
31fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <ul>
32fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <li>The application display area specifies the part of the display that may contain
33fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * an application window, excluding the system decorations.  The application display area may
34fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * be smaller than the real display area because the system subtracts the space needed
35fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * for decor elements such as the status bar.  Use the following methods to query the
36fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * application display area: {@link #getSize}, {@link #getRectSize} and {@link #getMetrics}.</li>
37fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * <li>The real display area specifies the part of the display that contains content
38fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * including the system decorations.  Even so, the real display area may be smaller than the
39fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * physical size of the display if the window manager is emulating a smaller display
40fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * using (adb shell am display-size).  Use the following methods to query the
41fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * real display area: {@link #getRealSize}, {@link #getRealMetrics}.</li>
42fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </ul>
43fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </p><p>
44fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * A logical display does not necessarily represent a particular physical display device
45fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * such as the built-in screen or an external monitor.  The contents of a logical
46fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * display may be presented on one or more physical displays according to the devices
47fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * that are currently attached and whether mirroring has been enabled.
48fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown * </p>
49bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown */
50fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brownpublic final class Display {
51fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private static final String TAG = "Display";
52bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    private static final boolean DEBUG = false;
53fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
54bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    private final DisplayManagerGlobal mGlobal;
55fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private final int mDisplayId;
564ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown    private final int mLayerStack;
574ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown    private final String mName;
58fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private final CompatibilityInfoHolder mCompatibilityInfo;
59bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown
60bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    private DisplayInfo mDisplayInfo; // never null
61bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    private boolean mIsValid;
62fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
63fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // Temporary display metrics structure used for compatibility mode.
64fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private final DisplayMetrics mTempMetrics = new DisplayMetrics();
65fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
66fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // We cache the app width and height properties briefly between calls
67fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // to getHeight() and getWidth() to ensure that applications perceive
68fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // consistent results when the size changes (most of the time).
69fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // Applications should now be using getSize() instead.
70fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private static final int CACHED_APP_SIZE_DURATION_MILLIS = 20;
71fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private long mLastCachedAppSizeUpdate;
72fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private int mCachedAppWidthCompat;
73fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private int mCachedAppHeightCompat;
745fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn
759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7698365d7663cbd82979a5700faf0050220b01084dJeff Brown     * The default Display id, which is the id of the built-in primary display
7798365d7663cbd82979a5700faf0050220b01084dJeff Brown     * assuming there is one.
789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int DEFAULT_DISPLAY = 0;
809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
82c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * Display flag: Indicates that the display supports secure video output.
83c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * <p>
84c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * This flag is used to indicate that the display supports content protection
85c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * mechanisms for secure video output at the display interface, such as HDCP.
86c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * These mechanisms may be used to protect secure content as it leaves the device.
87c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * </p><p>
88c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * While mirroring content to multiple displays, it can happen that certain
89c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * display devices support secure video output while other display devices do not.
90c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * The secure content will be shown only on the display devices that support
91c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * secure video output and will be blanked on other display devices that do
92c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * not support secure video output.
93c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * </p><p>
94c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * This flag mainly applies to external display devices such as HDMI or
95c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * Wifi display.  Built-in display devices are usually considered secure.
96c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * </p>
97c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     *
98c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * @hide pending review
99c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     */
100c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown    public static final int FLAG_SUPPORTS_SECURE_VIDEO_OUTPUT = 1 << 0;
101c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown
102c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown    /**
103c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * Display flag: Indicates that the display supports secure in-memory video buffers.
104c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * <p>
105c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * This flag is used to indicate that the display supports content protection
106c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * mechanisms for decrypted in-memory video buffers, such as secure memory areas.
107c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * These mechanisms may be used to protect secure video buffers in memory from
108c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * the video decoder to the display compositor and the video interface.
109c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * </p>
110c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     *
111c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * @hide pending review
112c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     */
113c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown    public static final int FLAG_SUPPORTS_SECURE_VIDEO_BUFFERS = 1 << 1;
114c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown
115c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown    /**
116fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Internal method to create a display.
117fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Applications should use {@link android.view.WindowManager#getDefaultDisplay()}
11898365d7663cbd82979a5700faf0050220b01084dJeff Brown     * or {@link android.hardware.display.DisplayManager#getDisplay}
11998365d7663cbd82979a5700faf0050220b01084dJeff Brown     * to get a display object.
120fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
121fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @hide
1229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
123bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    public Display(DisplayManagerGlobal global,
124bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            int displayId, DisplayInfo displayInfo /*not null*/,
125bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            CompatibilityInfoHolder compatibilityInfo) {
126bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        mGlobal = global;
127fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        mDisplayId = displayId;
128bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        mDisplayInfo = displayInfo;
1294ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown        mLayerStack = displayInfo.layerStack; // can never change as long as the display is valid
1304ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown        mName = displayInfo.name; // cannot change as long as the display is valid
131fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        mCompatibilityInfo = compatibilityInfo;
132bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        mIsValid = true;
1335fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn    }
1345fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn
1359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
136fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the display id.
137fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * <p>
138fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Each logical display has a unique id.
139fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The default display has id {@link #DEFAULT_DISPLAY}.
140fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p>
1419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int getDisplayId() {
143fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        return mDisplayId;
1449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
147bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * Returns true if this display is still valid, false if the display has been removed.
148bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     *
149bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * If the display is invalid, then the methods of this class will
150bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * continue to report the most recently observed display information.
151bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * However, it is unwise (and rather fruitless) to continue using a
152bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * {@link Display} object after the display's demise.
153bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     *
154bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * It's possible for a display that was previously invalid to become
155bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * valid again if a display with the same id is reconnected.
156bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     *
157bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * @return True if the display is still valid.
158bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     */
159bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    public boolean isValid() {
160bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        synchronized (this) {
161bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            updateDisplayInfoLocked();
162bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            return mIsValid;
163bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        }
164bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    }
165bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown
166bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    /**
1672ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     * Gets a full copy of the display information.
1682ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     *
1692ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     * @param outDisplayInfo The object to receive the copy of the display information.
170bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * @return True if the display is still valid.
1712ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     * @hide
1722ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     */
173bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    public boolean getDisplayInfo(DisplayInfo outDisplayInfo) {
1742ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown        synchronized (this) {
1752ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown            updateDisplayInfoLocked();
1762ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown            outDisplayInfo.copyFrom(mDisplayInfo);
177bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            return mIsValid;
1782ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown        }
1792ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown    }
1802ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown
1812ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown    /**
18298365d7663cbd82979a5700faf0050220b01084dJeff Brown     * Gets the display's layer stack.
18398365d7663cbd82979a5700faf0050220b01084dJeff Brown     *
18498365d7663cbd82979a5700faf0050220b01084dJeff Brown     * Each display has its own independent layer stack upon which surfaces
18598365d7663cbd82979a5700faf0050220b01084dJeff Brown     * are placed to be managed by surface flinger.
18698365d7663cbd82979a5700faf0050220b01084dJeff Brown     *
1874ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown     * @return The display's layer stack number.
18898365d7663cbd82979a5700faf0050220b01084dJeff Brown     * @hide
18998365d7663cbd82979a5700faf0050220b01084dJeff Brown     */
19098365d7663cbd82979a5700faf0050220b01084dJeff Brown    public int getLayerStack() {
1914ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown        return mLayerStack;
19298365d7663cbd82979a5700faf0050220b01084dJeff Brown    }
19398365d7663cbd82979a5700faf0050220b01084dJeff Brown
19498365d7663cbd82979a5700faf0050220b01084dJeff Brown    /**
195c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * Returns a combination of flags that describe the capabilities of the display.
196c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     *
197c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * @return The display flags.
198c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     *
199c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     * @hide pending review
200c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown     */
201c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown    public int getFlags() {
202c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown        synchronized (this) {
203c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown            updateDisplayInfoLocked();
204c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown            return mDisplayInfo.flags;
205c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown        }
206c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown    }
207c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown
208c5df37c285221d0fb113f55b9e78b35632241d3fJeff Brown    /**
20998365d7663cbd82979a5700faf0050220b01084dJeff Brown     * Gets the compatibility info used by this display instance.
21098365d7663cbd82979a5700faf0050220b01084dJeff Brown     *
21198365d7663cbd82979a5700faf0050220b01084dJeff Brown     * @return The compatibility info holder, or null if none is required.
21298365d7663cbd82979a5700faf0050220b01084dJeff Brown     * @hide
21398365d7663cbd82979a5700faf0050220b01084dJeff Brown     */
21498365d7663cbd82979a5700faf0050220b01084dJeff Brown    public CompatibilityInfoHolder getCompatibilityInfo() {
21598365d7663cbd82979a5700faf0050220b01084dJeff Brown        return mCompatibilityInfo;
21698365d7663cbd82979a5700faf0050220b01084dJeff Brown    }
21798365d7663cbd82979a5700faf0050220b01084dJeff Brown
21898365d7663cbd82979a5700faf0050220b01084dJeff Brown    /**
2194ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown     * Gets the name of the display.
2204ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown     * @return The display's name.
2214ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown     */
2224ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown    public String getName() {
2234ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown        return mName;
2244ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown    }
2254ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown
2264ed8fe75e1dde1a2b9576f3862aecc5a572c56b5Jeff Brown    /**
227bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * Gets the size of the display, in pixels.
228bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * <p>
229bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * Note that this value should <em>not</em> be used for computing layouts,
230bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * since a device will typically have screen decoration (such as a status bar)
2315cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * along the edges of the display that reduce the amount of application
232bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * space available from the size returned here.  Layouts should instead use
233bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * the window size.
234bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p><p>
235bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * The size is adjusted based on the current rotation of the display.
236bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p><p>
237bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * The size returned by this method does not necessarily represent the
238bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * actual raw size (native resolution) of the display.  The returned size may
239fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * be adjusted to exclude certain system decoration elements that are always visible.
240bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * It may also be scaled to provide compatibility with older applications that
241bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * were originally designed for smaller displays.
242bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p>
243bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     *
244bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @param outSize A {@link Point} object to receive the size information.
2459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
246ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public void getSize(Point outSize) {
247fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
248fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
249fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mDisplayInfo.getAppMetrics(mTempMetrics, mCompatibilityInfo);
250fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.x = mTempMetrics.widthPixels;
251fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.y = mTempMetrics.heightPixels;
252ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
253ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
254fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
2559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
256bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * Gets the size of the display as a rectangle, in pixels.
257bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     *
258bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @param outSize A {@link Rect} object to receive the size information.
259bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @see #getSize(Point)
2609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
261ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public void getRectSize(Rect outSize) {
262fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
263fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
264fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mDisplayInfo.getAppMetrics(mTempMetrics, mCompatibilityInfo);
265fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels);
266ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
267ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
2689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
269ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    /**
27068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * Return the range of display sizes an application can expect to encounter
27168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * under normal operation, as long as there is no physical change in screen
27268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * size.  This is basically the sizes you will see as the orientation
27368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * changes, taking into account whatever screen decoration there is in
27468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * each rotation.  For example, the status bar is always at the top of the
27568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * screen, so it will reduce the height both in landscape and portrait, and
27668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * the smallest height returned here will be the smaller of the two.
27768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     *
27868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * This is intended for applications to get an idea of the range of sizes
27968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * they will encounter while going through device rotations, to provide a
28068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * stable UI through rotation.  The sizes here take into account all standard
28168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * system decorations that reduce the size actually available to the
28268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * application: the status bar, navigation bar, system bar, etc.  It does
28368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * <em>not</em> take into account more transient elements like an IME
28468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * soft keyboard.
28568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     *
28668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * @param outSmallestSize Filled in with the smallest width and height
28768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * that the application will encounter, in pixels (not dp units).  The x
28868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * (width) dimension here directly corresponds to
28968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * {@link android.content.res.Configuration#smallestScreenWidthDp
29068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * Configuration.smallestScreenWidthDp}, except the value here is in raw
29168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * screen pixels rather than dp units.  Your application may of course
29268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * still get smaller space yet if, for example, a soft keyboard is
29368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * being displayed.
29468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * @param outLargestSize Filled in with the largest width and height
29568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * that the application will encounter, in pixels (not dp units).  Your
29668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * application may of course still get larger space than this if,
29768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * for example, screen decorations like the status bar are being hidden.
29868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     */
29968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn    public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) {
300fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
301fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
302fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth;
303fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight;
304fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outLargestSize.x = mDisplayInfo.largestNominalAppWidth;
305fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outLargestSize.y = mDisplayInfo.largestNominalAppHeight;
30668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn        }
30768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn    }
30868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn
30968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn    /**
310ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * Return the maximum screen size dimension that will happen.  This is
311ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * mostly for wallpapers.
312ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * @hide
313ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     */
314ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public int getMaximumSizeDimension() {
315fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
316fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
317fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
318ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
319ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
320ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn
321ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    /**
322ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * @deprecated Use {@link #getSize(Point)} instead.
323ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     */
324ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    @Deprecated
325ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public int getWidth() {
326fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
327fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateCachedAppSizeIfNeededLocked();
328fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return mCachedAppWidthCompat;
329ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
330ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
331ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn
332ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    /**
333ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * @deprecated Use {@link #getSize(Point)} instead.
334ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     */
335ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    @Deprecated
336ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public int getHeight() {
337fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
338fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateCachedAppSizeIfNeededLocked();
339fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return mCachedAppHeightCompat;
340bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown        }
341bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    }
342ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn
343bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    /**
3445cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * Returns the rotation of the screen from its "natural" orientation.
3455cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * The returned value may be {@link Surface#ROTATION_0 Surface.ROTATION_0}
3465cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * (no rotation), {@link Surface#ROTATION_90 Surface.ROTATION_90},
3475cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * {@link Surface#ROTATION_180 Surface.ROTATION_180}, or
3485cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * {@link Surface#ROTATION_270 Surface.ROTATION_270}.  For
3495cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * example, if a device has a naturally tall screen, and the user has
3505cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * turned it on its side to go into a landscape orientation, the value
3515cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * returned here may be either {@link Surface#ROTATION_90 Surface.ROTATION_90}
3525cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * or {@link Surface#ROTATION_270 Surface.ROTATION_270} depending on
3535cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * the direction it was turned.  The angle is the rotation of the drawn
3545cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * graphics on the screen, which is the opposite direction of the physical
3555cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * rotation of the device.  For example, if the device is rotated 90
3565cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * degrees counter-clockwise, to compensate rendering will be rotated by
3575cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * 90 degrees clockwise and thus the returned value here will be
3585cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * {@link Surface#ROTATION_90 Surface.ROTATION_90}.
3595cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     */
3605cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn    public int getRotation() {
361fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
362fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
363fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return mDisplayInfo.rotation;
364fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
3655cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn    }
366fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
3675cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn    /**
3684c904a3bf3dbe98607b5e3f706ee8ef8887ee104Joe Onorato     * @deprecated use {@link #getRotation}
3699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return orientation of this display.
3709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
371fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    @Deprecated
372fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    public int getOrientation() {
373fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        return getRotation();
374fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    }
3759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
377fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the pixel format of the display.
378fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @return One of the constants defined in {@link android.graphics.PixelFormat}.
379fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
380fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @deprecated This method is no longer supported.
381fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The result is always {@link PixelFormat#RGBA_8888}.
3829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
383fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    @Deprecated
3849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int getPixelFormat() {
385fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        return PixelFormat.RGBA_8888;
3869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
387fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
3889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
389fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the refresh rate of this display in frames per second.
3909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public float getRefreshRate() {
392fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
393fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
394fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return mDisplayInfo.refreshRate;
395fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
3969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
397fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
3989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
399bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * Gets display metrics that describe the size and density of this display.
400bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * <p>
401bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * The size is adjusted based on the current rotation of the display.
402bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p><p>
403bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * The size returned by this method does not necessarily represent the
404bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * actual raw size (native resolution) of the display.  The returned size may
405bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * be adjusted to exclude certain system decor elements that are always visible.
406bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * It may also be scaled to provide compatibility with older applications that
407bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * were originally designed for smaller displays.
408bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p>
409bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     *
410bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
4119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void getMetrics(DisplayMetrics outMetrics) {
413fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
414fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
415fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mDisplayInfo.getAppMetrics(outMetrics, mCompatibilityInfo);
41668066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn        }
41768066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn    }
41868066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn
41968066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn    /**
420fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the real size of the display without subtracting any window decor or
421fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * applying any compatibility scale factors.
422fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * <p>
423fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The size is adjusted based on the current rotation of the display.
424fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p><p>
425fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The real size may be smaller than the physical size of the screen when the
426fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * window manager is emulating a smaller display (using adb shell am display-size).
427fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p>
428fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
429fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @param outSize Set to the real size of the display.
43068066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn     */
431fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    public void getRealSize(Point outSize) {
432fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
433fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
434fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.x = mDisplayInfo.logicalWidth;
435fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.y = mDisplayInfo.logicalHeight;
436bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown        }
437bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    }
438bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown
439bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    /**
440fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets display metrics based on the real size of this display.
441fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * <p>
442fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The size is adjusted based on the current rotation of the display.
443fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p><p>
444fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The real size may be smaller than the physical size of the screen when the
445fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * window manager is emulating a smaller display (using adb shell am display-size).
446fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p>
447fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
448fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
44993de746e5554bc9397ca8109f57875d92e64eabcJeff Brown     */
450fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    public void getRealMetrics(DisplayMetrics outMetrics) {
451fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
452fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
453fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mDisplayInfo.getLogicalMetrics(outMetrics, null);
454fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
45593de746e5554bc9397ca8109f57875d92e64eabcJeff Brown    }
45693de746e5554bc9397ca8109f57875d92e64eabcJeff Brown
457fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private void updateDisplayInfoLocked() {
458bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        // Note: The display manager caches display info objects on our behalf.
459bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId);
460bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        if (newInfo == null) {
461bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            // Preserve the old mDisplayInfo after the display is removed.
462bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            if (mIsValid) {
463bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                mIsValid = false;
464bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                if (DEBUG) {
465bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                    Log.d(TAG, "Logical display " + mDisplayId + " was removed.");
466bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                }
467bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            }
468bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        } else {
469bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            // Use the new display info.  (It might be the same object if nothing changed.)
470bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            mDisplayInfo = newInfo;
471bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            if (!mIsValid) {
472bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                mIsValid = true;
473bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                if (DEBUG) {
474bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                    Log.d(TAG, "Logical display " + mDisplayId + " was recreated.");
475bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                }
476bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            }
477fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
4789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
480fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private void updateCachedAppSizeIfNeededLocked() {
481fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        long now = SystemClock.uptimeMillis();
482fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) {
483fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
484fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mDisplayInfo.getAppMetrics(mTempMetrics, mCompatibilityInfo);
485fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mCachedAppWidthCompat = mTempMetrics.widthPixels;
486fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mCachedAppHeightCompat = mTempMetrics.heightPixels;
487fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mLastCachedAppSizeUpdate = now;
488fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
489ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
490bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown
491bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    // For debugging purposes
492bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    @Override
493bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    public String toString() {
494bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown        synchronized (this) {
495bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown            updateDisplayInfoLocked();
496bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown            mDisplayInfo.getAppMetrics(mTempMetrics, mCompatibilityInfo);
497bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown            return "Display id " + mDisplayId + ": " + mDisplayInfo
498bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                    + ", " + mTempMetrics + ", isValid=" + mIsValid;
499bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown        }
500bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    }
5019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
5029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
503