Last big work on #1991910: Make swipes work with capacitive keys

This takes care of allowing us to cancel the back button.  The
back button is a bear because it is strewn all over the place --
everywhere you can close something, there is some code looking
for the back button that now needs to deal with being canceled.

The main things changed are activity (of course), dialog,
input method, search dialog.  There are some other misc places
in the framework (and some I missed here that I will get in a
second pass).

To facility all of this, the key dispatching APIs now provide
a lot more support for dealing with looking for cancelled keys,
and incidentally also provide an actual API for catching long
key presses.  This also helped clean up the code in PhoneWindow
where it deals with all of the combinations of key pressed and
releases.  (And also allows people to override
Activity.onKeyLongPress() to provide a different long press
action for a standard key like search.)

And while I was doing this, I reworked how we detect long
presses by having this be part of the key event delivered by
the window manager.  This should greatly reduce (hopefully
outright eliminate) the problems with long presses being
mis-detected when an application is being slow.

Change-Id: Ia19066b8d588d573df3eee6d96e1c90fdc19f57d
diff --git a/services/java/com/android/server/KeyInputQueue.java b/services/java/com/android/server/KeyInputQueue.java
index 244e136..d9f4c9c 100644
--- a/services/java/com/android/server/KeyInputQueue.java
+++ b/services/java/com/android/server/KeyInputQueue.java
@@ -981,6 +981,29 @@
         }
     }
 
+    /**
+     * Return true if the queue has an up event pending that corresponds
+     * to the same key as the given key event.
+     */
+    boolean hasKeyUpEvent(KeyEvent origEvent) {
+        synchronized (mFirst) {
+            final int keyCode = origEvent.getKeyCode();
+            QueuedEvent cur = mLast.prev;
+            while (cur.prev != null) {
+                if (cur.classType == RawInputEvent.CLASS_KEYBOARD) {
+                    KeyEvent ke = (KeyEvent)cur.event;
+                    if (ke.getAction() == KeyEvent.ACTION_UP
+                            && ke.getKeyCode() == keyCode) {
+                        return true;
+                    }
+                }
+                cur = cur.prev;
+            }
+        }
+        
+        return false;
+    }
+    
     void recycleEvent(QueuedEvent ev) {
         synchronized (mFirst) {
             //Log.i(TAG, "Recycle event: " + ev);