Fix issue #2149145: Safe Mode does not work on Sholes device

The APIs for checking whether keys are held down now also look
at virtual keys.

However it turns out there is less than a second between the time we
start the input thread and check for safe mode, so there is not enough
time to actually open all of the devices and get the data from them
about the finger being down to determine if a virtual key is down.

So now you can also hold DPAD center, trackball center, or s to
enter safe mode.  Also give some vibrator feedback.

Change-Id: I55edce63bc0c375813bd3751766b8070beeb0153
diff --git a/services/java/com/android/server/KeyInputQueue.java b/services/java/com/android/server/KeyInputQueue.java
index d9f4c9c..d7b8f57 100644
--- a/services/java/com/android/server/KeyInputQueue.java
+++ b/services/java/com/android/server/KeyInputQueue.java
@@ -337,6 +337,54 @@
         }
     }
     
+    public int getScancodeState(int code) {
+        synchronized (mFirst) {
+            VirtualKey vk = mPressedVirtualKey;
+            if (vk != null) {
+                if (vk.scancode == code) {
+                    return 2;
+                }
+            }
+            return nativeGetScancodeState(code);
+        }
+    }
+    
+    public int getScancodeState(int deviceId, int code) {
+        synchronized (mFirst) {
+            VirtualKey vk = mPressedVirtualKey;
+            if (vk != null) {
+                if (vk.scancode == code) {
+                    return 2;
+                }
+            }
+            return nativeGetScancodeState(deviceId, code);
+        }
+    }
+    
+    public int getKeycodeState(int code) {
+        synchronized (mFirst) {
+            VirtualKey vk = mPressedVirtualKey;
+            if (vk != null) {
+                if (vk.lastKeycode == code) {
+                    return 2;
+                }
+            }
+            return nativeGetKeycodeState(code);
+        }
+    }
+    
+    public int getKeycodeState(int deviceId, int code) {
+        synchronized (mFirst) {
+            VirtualKey vk = mPressedVirtualKey;
+            if (vk != null) {
+                if (vk.lastKeycode == code) {
+                    return 2;
+                }
+            }
+            return nativeGetKeycodeState(deviceId, code);
+        }
+    }
+    
     public static native String getDeviceName(int deviceId);
     public static native int getDeviceClasses(int deviceId);
     public static native void addExcludedDevice(String deviceName);
@@ -344,10 +392,10 @@
             InputDevice.AbsoluteInfo outInfo);
     public static native int getSwitchState(int sw);
     public static native int getSwitchState(int deviceId, int sw);
-    public static native int getScancodeState(int sw);
-    public static native int getScancodeState(int deviceId, int sw);
-    public static native int getKeycodeState(int sw);
-    public static native int getKeycodeState(int deviceId, int sw);
+    public static native int nativeGetScancodeState(int code);
+    public static native int nativeGetScancodeState(int deviceId, int code);
+    public static native int nativeGetKeycodeState(int code);
+    public static native int nativeGetKeycodeState(int deviceId, int code);
     public static native int scancodeToKeycode(int deviceId, int scancode);
     public static native boolean hasKeys(int[] keycodes, boolean[] keyExists);