auto import from //depot/cupcake/@132589
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index a3ceb71..10a2d29 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -3954,10 +3954,6 @@
         synchronized(mWindowMap) {
             mKeyWaiter.bindTargetWindowLocked(focus);
         }
-
-        // NOSHIP extra state logging
-        mKeyWaiter.recordDispatchState(event, focus);
-        // END NOSHIP
         
         try {
             if (DEBUG_INPUT || DEBUG_FOCUS) {
@@ -4101,55 +4097,6 @@
      * but not the other way around.
      */
     final class KeyWaiter {
-        // NOSHIP debugging
-        public class DispatchState {
-            private KeyEvent event;
-            private WindowState focus;
-            private long time;
-            private WindowState lastWin;
-            private IBinder lastBinder;
-            private boolean finished;
-            private boolean gotFirstWindow;
-            private boolean eventDispatching;
-            private long timeToSwitch;
-            private boolean wasFrozen;
-            private boolean focusPaused;
-            
-            DispatchState(KeyEvent theEvent, WindowState theFocus) {
-                focus = theFocus;
-                event = theEvent;
-                time = System.currentTimeMillis();
-                // snapshot KeyWaiter state
-                lastWin = mLastWin;
-                lastBinder = mLastBinder;
-                finished = mFinished;
-                gotFirstWindow = mGotFirstWindow;
-                eventDispatching = mEventDispatching;
-                timeToSwitch = mTimeToSwitch;
-                wasFrozen = mWasFrozen;
-                // cache the paused state at ctor time as well
-                if (theFocus == null || theFocus.mToken == null) {
-                    Log.i(TAG, "focus " + theFocus + " mToken is null at event dispatch!");
-                    focusPaused = false;
-                } else {
-                    focusPaused = theFocus.mToken.paused;
-                }
-            }
-            
-            public String toString() {
-                return "{{" + event + " to " + focus + " @ " + time
-                        + " lw=" + lastWin + " lb=" + lastBinder
-                        + " fin=" + finished + " gfw=" + gotFirstWindow
-                        + " ed=" + eventDispatching + " tts=" + timeToSwitch
-                        + " wf=" + wasFrozen + " fp=" + focusPaused + "}}";
-            }
-        };
-        private DispatchState mDispatchState = null;
-        public void recordDispatchState(KeyEvent theEvent, WindowState theFocus) {
-            mDispatchState = new DispatchState(theEvent, theFocus);
-        }
-        // END NOSHIP
-
         public static final int RETURN_NOTHING = 0;
         public static final int RETURN_PENDING_POINTER = 1;
         public static final int RETURN_PENDING_TRACKBALL = 2;
@@ -4311,10 +4258,6 @@
                         Log.w(TAG, "Key dispatching timed out sending to " +
                               (targetWin != null ? targetWin.mAttrs.getTitle()
                               : "<null>"));
-                        // NOSHIP debugging
-                        Log.w(TAG, "Dispatch state: " + mDispatchState);
-                        Log.w(TAG, "Current state:  " + new DispatchState(nextKey, targetWin));
-                        // END NOSHIP
                         //dump();
                         if (targetWin != null) {
                             at = targetWin.getAppToken();
@@ -4697,7 +4640,7 @@
                 newWindow.mToken.paused = false;
 
                 mGotFirstWindow = true;
-                boolean doNotify = false;
+                boolean doNotify = true;
 
                 if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) {
                     if (DEBUG_INPUT) Log.v(TAG,
@@ -4706,7 +4649,6 @@
                     mLastBinder = null;
                     mMotionTarget = null;
                     mFinished = true;
-                    doNotify = true;    // ensure that we reset the key waiters after hijacking
                 } else if (mLastWin != null) {
                     // If the new window is above the window we are
                     // waiting on, then stop waiting and let key dispatching
@@ -4715,15 +4657,15 @@
                         TAG, "Last win layer=" + mLastWin.mLayer
                         + ", new win layer=" + newWindow.mLayer);
                     if (newWindow.mLayer >= mLastWin.mLayer) {
-                        // The new window is above the old; finish pending input to the last
-                        // window and start directing it to the new one.
-                        mLastWin.mToken.paused = false;
-                        doFinishedKeyLocked(true);  // does a notifyAll()
+                        if (!mLastWin.canReceiveKeys()) {
+                            mLastWin.mToken.paused = false;
+                            doFinishedKeyLocked(true);  // does a notifyAll()
+                            doNotify = false;
+                        }
+                    } else {
+                        // the new window is lower; no need to wake key waiters
+                        doNotify = false;
                     }
-                    // Either the new window is lower, so there is no need to wake key waiters,
-                    // or we just finished key input to the previous window, which implicitly
-                    // notified the key waiters.  In both cases, we don't need to issue the
-                    // notification here, so we do not set doNotify.
                 }
 
                 if (doNotify) {
@@ -6463,7 +6405,7 @@
         public String toString() {
             return "Window{"
                 + Integer.toHexString(System.identityHashCode(this))
-                + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}";
+                + " " + mAttrs.getTitle() + "}";
         }
     }
     
@@ -8702,7 +8644,7 @@
                     + " mLastBinder=" + mKeyWaiter.mLastBinder);
             pw.println("    mFinished=" + mKeyWaiter.mFinished
                     + " mGotFirstWindow=" + mKeyWaiter.mGotFirstWindow
-                    + " mEventDispatching=" + mKeyWaiter.mEventDispatching
+                    + " mEventDispatching" + mKeyWaiter.mEventDispatching
                     + " mTimeToSwitch=" + mKeyWaiter.mTimeToSwitch);
         }
     }