diff options
| author | 2013-08-22 21:08:02 +0000 | |
|---|---|---|
| committer | 2013-08-22 21:08:02 +0000 | |
| commit | 8e3a41738fba4883f9951406f334567f621db102 (patch) | |
| tree | 7c09eb0d63210b3b4b1d2ff57a3d7e10046f95f1 | |
| parent | d5deafa45fcec7ac779d835132e90810225056cd (diff) | |
| parent | b7b2d4b490f5dd672e0b00ced579dc052e3637e9 (diff) | |
Merge "Expose API to query devices for supported keys" into klp-dev
| -rw-r--r-- | api/current.txt | 1 | ||||
| -rw-r--r-- | core/java/android/hardware/input/InputManager.java | 20 | ||||
| -rw-r--r-- | core/java/android/view/InputDevice.java | 10 |
3 files changed, 30 insertions, 1 deletions
diff --git a/api/current.txt b/api/current.txt index f341597f749e..ed3a2e5aa4e6 100644 --- a/api/current.txt +++ b/api/current.txt @@ -26139,6 +26139,7 @@ package android.view { method public int getSources(); method public int getVendorId(); method public android.os.Vibrator getVibrator(); + method public boolean[] hasKeys(int...); method public boolean isVirtual(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java index 761faaf85938..30e69a68d743 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -579,15 +579,33 @@ public final class InputManager { * @hide */ public boolean[] deviceHasKeys(int[] keyCodes) { + return deviceHasKeys(-1, keyCodes); + } + + /** + * Queries the framework about whether any physical keys exist on the + * any keyboard attached to the device that are capable of producing the given + * array of key codes. + * + * @param id The id of the device to query. + * @param keyCodes The array of key codes to query. + * @return A new array of the same size as the key codes array whose elements are set to true + * if the given device could produce the corresponding key code at the same index in the key + * codes array. + * + * @hide + */ + public boolean[] deviceHasKeys(int id, int[] keyCodes) { boolean[] ret = new boolean[keyCodes.length]; try { - mIm.hasKeys(-1, InputDevice.SOURCE_ANY, keyCodes, ret); + mIm.hasKeys(id, InputDevice.SOURCE_ANY, keyCodes, ret); } catch (RemoteException e) { // no fallback; just return the empty array } return ret; } + /** * Injects an input event into the event system on behalf of an application. * The synchronization mode determines whether the method blocks while waiting for diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java index f43e4ab3c133..afc7b3e789a6 100644 --- a/core/java/android/view/InputDevice.java +++ b/core/java/android/view/InputDevice.java @@ -574,6 +574,16 @@ public final class InputDevice implements Parcelable { } /** + * Gets whether the device is capable of producing the list of keycodes. + * @param keys The list of android keycodes to check for. + * @return An array of booleans where each member specifies whether the device is capable of + * generating the keycode given by the corresponding value at the same index in the keys array. + */ + public boolean[] hasKeys(int... keys) { + return InputManager.getInstance().deviceHasKeys(mId, keys); + } + + /** * Gets information about the range of values for a particular {@link MotionEvent} axis. * If the device supports multiple sources, the same axis may have different meanings * for each source. Returns information about the first axis found for any source. |