Display.java revision bd6e1500aedc5461e832f69e76341bff0e55fa2b
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;
56fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private final CompatibilityInfoHolder mCompatibilityInfo;
57bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown
58bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    private DisplayInfo mDisplayInfo; // never null
59bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    private boolean mIsValid;
60fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
61fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // Temporary display metrics structure used for compatibility mode.
62fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private final DisplayMetrics mTempMetrics = new DisplayMetrics();
63fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
64fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // We cache the app width and height properties briefly between calls
65fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // to getHeight() and getWidth() to ensure that applications perceive
66fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // consistent results when the size changes (most of the time).
67fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    // Applications should now be using getSize() instead.
68fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private static final int CACHED_APP_SIZE_DURATION_MILLIS = 20;
69fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private long mLastCachedAppSizeUpdate;
70fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private int mCachedAppWidthCompat;
71fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private int mCachedAppHeightCompat;
725fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn
739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7498365d7663cbd82979a5700faf0050220b01084dJeff Brown     * The default Display id, which is the id of the built-in primary display
7598365d7663cbd82979a5700faf0050220b01084dJeff Brown     * assuming there is one.
769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int DEFAULT_DISPLAY = 0;
789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
80fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Internal method to create a display.
81fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Applications should use {@link android.view.WindowManager#getDefaultDisplay()}
8298365d7663cbd82979a5700faf0050220b01084dJeff Brown     * or {@link android.hardware.display.DisplayManager#getDisplay}
8398365d7663cbd82979a5700faf0050220b01084dJeff Brown     * to get a display object.
84fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
85fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @hide
869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
87bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    public Display(DisplayManagerGlobal global,
88bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            int displayId, DisplayInfo displayInfo /*not null*/,
89bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            CompatibilityInfoHolder compatibilityInfo) {
90bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        mGlobal = global;
91fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        mDisplayId = displayId;
92bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        mDisplayInfo = displayInfo;
93fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        mCompatibilityInfo = compatibilityInfo;
94bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        mIsValid = true;
955fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn    }
965fd2169eabd77e6bfafaf456e58051a3bafb2bcaDianne Hackborn
979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
98fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the display id.
99fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * <p>
100fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Each logical display has a unique id.
101fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The default display has id {@link #DEFAULT_DISPLAY}.
102fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p>
1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int getDisplayId() {
105fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        return mDisplayId;
1069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
109bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * Returns true if this display is still valid, false if the display has been removed.
110bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     *
111bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * If the display is invalid, then the methods of this class will
112bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * continue to report the most recently observed display information.
113bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * However, it is unwise (and rather fruitless) to continue using a
114bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * {@link Display} object after the display's demise.
115bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     *
116bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * It's possible for a display that was previously invalid to become
117bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * valid again if a display with the same id is reconnected.
118bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     *
119bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * @return True if the display is still valid.
120bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     */
121bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    public boolean isValid() {
122bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        synchronized (this) {
123bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            updateDisplayInfoLocked();
124bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            return mIsValid;
125bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        }
126bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    }
127bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown
128bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    /**
1292ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     * Gets a full copy of the display information.
1302ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     *
1312ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     * @param outDisplayInfo The object to receive the copy of the display information.
132bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown     * @return True if the display is still valid.
1332ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     * @hide
1342ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown     */
135bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown    public boolean getDisplayInfo(DisplayInfo outDisplayInfo) {
1362ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown        synchronized (this) {
1372ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown            updateDisplayInfoLocked();
1382ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown            outDisplayInfo.copyFrom(mDisplayInfo);
139bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            return mIsValid;
1402ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown        }
1412ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown    }
1422ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown
1432ab1b7d9abc1b720b63ae01abcf1df0dc780eed4Jeff Brown    /**
14498365d7663cbd82979a5700faf0050220b01084dJeff Brown     * Gets the display's layer stack.
14598365d7663cbd82979a5700faf0050220b01084dJeff Brown     *
14698365d7663cbd82979a5700faf0050220b01084dJeff Brown     * Each display has its own independent layer stack upon which surfaces
14798365d7663cbd82979a5700faf0050220b01084dJeff Brown     * are placed to be managed by surface flinger.
14898365d7663cbd82979a5700faf0050220b01084dJeff Brown     *
14998365d7663cbd82979a5700faf0050220b01084dJeff Brown     * @return The layer stack number.
15098365d7663cbd82979a5700faf0050220b01084dJeff Brown     * @hide
15198365d7663cbd82979a5700faf0050220b01084dJeff Brown     */
15298365d7663cbd82979a5700faf0050220b01084dJeff Brown    public int getLayerStack() {
15398365d7663cbd82979a5700faf0050220b01084dJeff Brown        // Note: This is the current convention but there is no requirement that
15498365d7663cbd82979a5700faf0050220b01084dJeff Brown        // the display id and layer stack id be the same.
15598365d7663cbd82979a5700faf0050220b01084dJeff Brown        return mDisplayId;
15698365d7663cbd82979a5700faf0050220b01084dJeff Brown    }
15798365d7663cbd82979a5700faf0050220b01084dJeff Brown
15898365d7663cbd82979a5700faf0050220b01084dJeff Brown    /**
15998365d7663cbd82979a5700faf0050220b01084dJeff Brown     * Gets the compatibility info used by this display instance.
16098365d7663cbd82979a5700faf0050220b01084dJeff Brown     *
16198365d7663cbd82979a5700faf0050220b01084dJeff Brown     * @return The compatibility info holder, or null if none is required.
16298365d7663cbd82979a5700faf0050220b01084dJeff Brown     * @hide
16398365d7663cbd82979a5700faf0050220b01084dJeff Brown     */
16498365d7663cbd82979a5700faf0050220b01084dJeff Brown    public CompatibilityInfoHolder getCompatibilityInfo() {
16598365d7663cbd82979a5700faf0050220b01084dJeff Brown        return mCompatibilityInfo;
16698365d7663cbd82979a5700faf0050220b01084dJeff Brown    }
16798365d7663cbd82979a5700faf0050220b01084dJeff Brown
16898365d7663cbd82979a5700faf0050220b01084dJeff Brown    /**
169bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * Gets the size of the display, in pixels.
170bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * <p>
171bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * Note that this value should <em>not</em> be used for computing layouts,
172bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * since a device will typically have screen decoration (such as a status bar)
1735cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * along the edges of the display that reduce the amount of application
174bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * space available from the size returned here.  Layouts should instead use
175bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * the window size.
176bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p><p>
177bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * The size is adjusted based on the current rotation of the display.
178bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p><p>
179bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * The size returned by this method does not necessarily represent the
180bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * actual raw size (native resolution) of the display.  The returned size may
181fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * be adjusted to exclude certain system decoration elements that are always visible.
182bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * It may also be scaled to provide compatibility with older applications that
183bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * were originally designed for smaller displays.
184bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p>
185bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     *
186bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @param outSize A {@link Point} object to receive the size information.
1879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
188ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public void getSize(Point outSize) {
189fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
190fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
191fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mDisplayInfo.getAppMetrics(mTempMetrics, mCompatibilityInfo);
192fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.x = mTempMetrics.widthPixels;
193fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.y = mTempMetrics.heightPixels;
194ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
195ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
196fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
1979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
198bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * Gets the size of the display as a rectangle, in pixels.
199bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     *
200bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @param outSize A {@link Rect} object to receive the size information.
201bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @see #getSize(Point)
2029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
203ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public void getRectSize(Rect outSize) {
204fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
205fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
206fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mDisplayInfo.getAppMetrics(mTempMetrics, mCompatibilityInfo);
207fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.set(0, 0, mTempMetrics.widthPixels, mTempMetrics.heightPixels);
208ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
209ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
2109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
211ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    /**
21268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * Return the range of display sizes an application can expect to encounter
21368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * under normal operation, as long as there is no physical change in screen
21468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * size.  This is basically the sizes you will see as the orientation
21568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * changes, taking into account whatever screen decoration there is in
21668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * each rotation.  For example, the status bar is always at the top of the
21768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * screen, so it will reduce the height both in landscape and portrait, and
21868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * the smallest height returned here will be the smaller of the two.
21968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     *
22068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * This is intended for applications to get an idea of the range of sizes
22168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * they will encounter while going through device rotations, to provide a
22268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * stable UI through rotation.  The sizes here take into account all standard
22368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * system decorations that reduce the size actually available to the
22468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * application: the status bar, navigation bar, system bar, etc.  It does
22568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * <em>not</em> take into account more transient elements like an IME
22668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * soft keyboard.
22768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     *
22868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * @param outSmallestSize Filled in with the smallest width and height
22968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * that the application will encounter, in pixels (not dp units).  The x
23068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * (width) dimension here directly corresponds to
23168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * {@link android.content.res.Configuration#smallestScreenWidthDp
23268c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * Configuration.smallestScreenWidthDp}, except the value here is in raw
23368c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * screen pixels rather than dp units.  Your application may of course
23468c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * still get smaller space yet if, for example, a soft keyboard is
23568c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * being displayed.
23668c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * @param outLargestSize Filled in with the largest width and height
23768c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * that the application will encounter, in pixels (not dp units).  Your
23868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * application may of course still get larger space than this if,
23968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     * for example, screen decorations like the status bar are being hidden.
24068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn     */
24168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn    public void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) {
242fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
243fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
244fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSmallestSize.x = mDisplayInfo.smallestNominalAppWidth;
245fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSmallestSize.y = mDisplayInfo.smallestNominalAppHeight;
246fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outLargestSize.x = mDisplayInfo.largestNominalAppWidth;
247fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outLargestSize.y = mDisplayInfo.largestNominalAppHeight;
24868c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn        }
24968c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn    }
25068c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn
25168c33ca7ce1f142eb5f1e1f90118aeba4c9db1e3Dianne Hackborn    /**
252ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * Return the maximum screen size dimension that will happen.  This is
253ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * mostly for wallpapers.
254ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * @hide
255ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     */
256ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public int getMaximumSizeDimension() {
257fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
258fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
259fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return Math.max(mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
260ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
261ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
262ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn
263ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    /**
264ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * @deprecated Use {@link #getSize(Point)} instead.
265ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     */
266ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    @Deprecated
267ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public int getWidth() {
268fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
269fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateCachedAppSizeIfNeededLocked();
270fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return mCachedAppWidthCompat;
271ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn        }
272ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
273ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn
274ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    /**
275ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     * @deprecated Use {@link #getSize(Point)} instead.
276ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn     */
277ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    @Deprecated
278ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    public int getHeight() {
279fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
280fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateCachedAppSizeIfNeededLocked();
281fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return mCachedAppHeightCompat;
282bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown        }
283bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    }
284ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn
285bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    /**
2865cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * Returns the rotation of the screen from its "natural" orientation.
2875cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * The returned value may be {@link Surface#ROTATION_0 Surface.ROTATION_0}
2885cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * (no rotation), {@link Surface#ROTATION_90 Surface.ROTATION_90},
2895cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * {@link Surface#ROTATION_180 Surface.ROTATION_180}, or
2905cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * {@link Surface#ROTATION_270 Surface.ROTATION_270}.  For
2915cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * example, if a device has a naturally tall screen, and the user has
2925cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * turned it on its side to go into a landscape orientation, the value
2935cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * returned here may be either {@link Surface#ROTATION_90 Surface.ROTATION_90}
2945cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * or {@link Surface#ROTATION_270 Surface.ROTATION_270} depending on
2955cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * the direction it was turned.  The angle is the rotation of the drawn
2965cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * graphics on the screen, which is the opposite direction of the physical
2975cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * rotation of the device.  For example, if the device is rotated 90
2985cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * degrees counter-clockwise, to compensate rendering will be rotated by
2995cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * 90 degrees clockwise and thus the returned value here will be
3005cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     * {@link Surface#ROTATION_90 Surface.ROTATION_90}.
3015cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn     */
3025cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn    public int getRotation() {
303fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
304fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
305fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return mDisplayInfo.rotation;
306fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
3075cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn    }
308fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
3095cb70b54156fb305d579a1cc167424c8705bfdf7Dianne Hackborn    /**
3104c904a3bf3dbe98607b5e3f706ee8ef8887ee104Joe Onorato     * @deprecated use {@link #getRotation}
3119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return orientation of this display.
3129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
313fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    @Deprecated
314fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    public int getOrientation() {
315fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        return getRotation();
316fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    }
3179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
319fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the pixel format of the display.
320fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @return One of the constants defined in {@link android.graphics.PixelFormat}.
321fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
322fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @deprecated This method is no longer supported.
323fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The result is always {@link PixelFormat#RGBA_8888}.
3249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
325fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    @Deprecated
3269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int getPixelFormat() {
327fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        return PixelFormat.RGBA_8888;
3289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
329fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
331fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the refresh rate of this display in frames per second.
3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public float getRefreshRate() {
334fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
335fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
336fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            return mDisplayInfo.refreshRate;
337fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
3389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
339fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown
3409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
341bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * Gets display metrics that describe the size and density of this display.
342bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * <p>
343bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * The size is adjusted based on the current rotation of the display.
344bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p><p>
345bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * The size returned by this method does not necessarily represent the
346bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * actual raw size (native resolution) of the display.  The returned size may
347bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * be adjusted to exclude certain system decor elements that are always visible.
348bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * It may also be scaled to provide compatibility with older applications that
349bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * were originally designed for smaller displays.
350bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * </p>
351bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     *
352bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown     * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
3539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public void getMetrics(DisplayMetrics outMetrics) {
355fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
356fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
357fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mDisplayInfo.getAppMetrics(outMetrics, mCompatibilityInfo);
35868066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn        }
35968066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn    }
36068066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn
36168066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn    /**
362fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets the real size of the display without subtracting any window decor or
363fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * applying any compatibility scale factors.
364fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * <p>
365fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The size is adjusted based on the current rotation of the display.
366fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p><p>
367fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The real size may be smaller than the physical size of the screen when the
368fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * window manager is emulating a smaller display (using adb shell am display-size).
369fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p>
370fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
371fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @param outSize Set to the real size of the display.
37268066c2f38e47b56f0510c56eafd827731a0dc08Dianne Hackborn     */
373fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    public void getRealSize(Point outSize) {
374fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
375fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
376fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.x = mDisplayInfo.logicalWidth;
377fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            outSize.y = mDisplayInfo.logicalHeight;
378bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown        }
379bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    }
380bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown
381bc68a59c024bdb745dac8e2ec7408a9f30595f1aJeff Brown    /**
382fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * Gets display metrics based on the real size of this display.
383fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * <p>
384fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The size is adjusted based on the current rotation of the display.
385fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p><p>
386fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * The real size may be smaller than the physical size of the screen when the
387fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * window manager is emulating a smaller display (using adb shell am display-size).
388fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * </p>
389fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     *
390fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown     * @param outMetrics A {@link DisplayMetrics} object to receive the metrics.
39193de746e5554bc9397ca8109f57875d92e64eabcJeff Brown     */
392fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    public void getRealMetrics(DisplayMetrics outMetrics) {
393fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        synchronized (this) {
394fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
395fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mDisplayInfo.getLogicalMetrics(outMetrics, null);
396fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
39793de746e5554bc9397ca8109f57875d92e64eabcJeff Brown    }
39893de746e5554bc9397ca8109f57875d92e64eabcJeff Brown
399fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private void updateDisplayInfoLocked() {
400bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        // Note: The display manager caches display info objects on our behalf.
401bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        DisplayInfo newInfo = mGlobal.getDisplayInfo(mDisplayId);
402bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        if (newInfo == null) {
403bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            // Preserve the old mDisplayInfo after the display is removed.
404bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            if (mIsValid) {
405bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                mIsValid = false;
406bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                if (DEBUG) {
407bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                    Log.d(TAG, "Logical display " + mDisplayId + " was removed.");
408bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                }
409bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            }
410bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown        } else {
411bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            // Use the new display info.  (It might be the same object if nothing changed.)
412bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            mDisplayInfo = newInfo;
413bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            if (!mIsValid) {
414bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                mIsValid = true;
415bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                if (DEBUG) {
416bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                    Log.d(TAG, "Logical display " + mDisplayId + " was recreated.");
417bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                }
418bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown            }
419fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
4219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
422fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown    private void updateCachedAppSizeIfNeededLocked() {
423fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        long now = SystemClock.uptimeMillis();
424fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        if (now > mLastCachedAppSizeUpdate + CACHED_APP_SIZE_DURATION_MILLIS) {
425fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            updateDisplayInfoLocked();
426fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mDisplayInfo.getAppMetrics(mTempMetrics, mCompatibilityInfo);
427fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mCachedAppWidthCompat = mTempMetrics.widthPixels;
428fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mCachedAppHeightCompat = mTempMetrics.heightPixels;
429fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown            mLastCachedAppSizeUpdate = now;
430fa25bf5382467b1018bd9af7f1cb30a23d7d59f7Jeff Brown        }
431ac8dea12c17aa047e03a358110aeb60401d36aa2Dianne Hackborn    }
432bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown
433bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    // For debugging purposes
434bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    @Override
435bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    public String toString() {
436bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown        synchronized (this) {
437bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown            updateDisplayInfoLocked();
438bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown            mDisplayInfo.getAppMetrics(mTempMetrics, mCompatibilityInfo);
439bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown            return "Display id " + mDisplayId + ": " + mDisplayInfo
440bd6e1500aedc5461e832f69e76341bff0e55fa2bJeff Brown                    + ", " + mTempMetrics + ", isValid=" + mIsValid;
441bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown        }
442bf5740e75efd87ae0213486e78e029403804c6f0Jeff Brown    }
4439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project}
4449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
445