Fix issue #2148939: Sholes slow to wake up in landscape mode

This was introduced when I did the fading of the lock screen,
which relies on setting the policy visibility of the windows behind
it to be hidden.  As a result, when the orientation changed or
the activity was restarted, they wouldn't be resized or reported
as drawn, and the activity manager would wait until its timeout
before unfreezing the screen.

We now have a new method on WindowState to find out if a window
has drawn itself, which is used in the appropriate places.

Change-Id: If05f8b1947d3029917f62ad0f89b43544bd0a4dc
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 8ebbc93..228d25e 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -4174,7 +4174,7 @@
             final int N = mWindows.size();
             for (int i=0; i<N; i++) {
                 WindowState w = (WindowState)mWindows.get(i);
-                if (w.isVisibleLw() && !w.isDisplayedLw()) {
+                if (w.isVisibleLw() && !w.isDrawnLw()) {
                     return;
                 }
             }
@@ -7664,6 +7664,16 @@
                         || mAnimating);
         }
 
+        /**
+         * Returns true if the window has a surface that it has drawn a
+         * complete UI in to.
+         */
+        public boolean isDrawnLw() {
+            final AppWindowToken atoken = mAppToken;
+            return mSurface != null && !mDestroying
+                && !mDrawPending && !mCommitDrawPending;
+        }
+
         public boolean fillsScreenLw(int screenWidth, int screenHeight,
                                    boolean shownFrame, boolean onlyOpaque) {
             if (mSurface == null) {
@@ -8268,10 +8278,10 @@
                     continue;
                 }
                 if (DEBUG_VISIBILITY) {
-                    Log.v(TAG, "Win " + win + ": isDisplayed="
-                            + win.isDisplayedLw()
+                    Log.v(TAG, "Win " + win + ": isDrawn="
+                            + win.isDrawnLw()
                             + ", isAnimating=" + win.isAnimating());
-                    if (!win.isDisplayedLw()) {
+                    if (!win.isDrawnLw()) {
                         Log.v(TAG, "Not displayed: s=" + win.mSurface
                                 + " pv=" + win.mPolicyVisibility
                                 + " dp=" + win.mDrawPending
@@ -8284,7 +8294,7 @@
                     }
                 }
                 numInteresting++;
-                if (win.isDisplayedLw()) {
+                if (win.isDrawnLw()) {
                     if (!win.isAnimating()) {
                         numVisible++;
                     }
@@ -9007,7 +9017,6 @@
                         || !win.mRelayoutCalled
                         || win.mRootToken.hidden
                         || (atoken != null && atoken.hiddenRequested)
-                        || !win.mPolicyVisibility
                         || win.mAttachedHidden
                         || win.mExiting || win.mDestroying;
 
@@ -9217,10 +9226,10 @@
                                 == WindowManager.LayoutParams.TYPE_BASE_APPLICATION)
                                 && !w.mExiting && !w.mDestroying) {
                             if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
-                                Log.v(TAG, "Eval win " + w + ": isDisplayed="
-                                        + w.isDisplayedLw()
+                                Log.v(TAG, "Eval win " + w + ": isDrawn="
+                                        + w.isDrawnLw()
                                         + ", isAnimating=" + w.isAnimating());
-                                if (!w.isDisplayedLw()) {
+                                if (!w.isDrawnLw()) {
                                     Log.v(TAG, "Not displayed: s=" + w.mSurface
                                             + " pv=" + w.mPolicyVisibility
                                             + " dp=" + w.mDrawPending
@@ -9233,7 +9242,7 @@
                             if (w != atoken.startingWindow) {
                                 if (!atoken.freezingScreen || !w.mAppFreezing) {
                                     atoken.numInterestingWindows++;
-                                    if (w.isDisplayedLw()) {
+                                    if (w.isDrawnLw()) {
                                         atoken.numDrawnWindows++;
                                         if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Log.v(TAG,
                                                 "tokenMayBeDrawn: " + atoken
@@ -9242,7 +9251,7 @@
                                         tokenMayBeDrawn = true;
                                     }
                                 }
-                            } else if (w.isDisplayedLw()) {
+                            } else if (w.isDrawnLw()) {
                                 atoken.startingDisplayed = true;
                             }
                         }