diff --git a/core/api/current.txt b/core/api/current.txt index fb0cff5fe53a5..1bf0d0e23782d 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -48771,6 +48771,10 @@ package android.view { field public static final int KEYCODE_STEM_2 = 266; // 0x10a field public static final int KEYCODE_STEM_3 = 267; // 0x10b field public static final int KEYCODE_STEM_PRIMARY = 264; // 0x108 + field public static final int KEYCODE_STYLUS_BUTTON_PRIMARY = 308; // 0x134 + field public static final int KEYCODE_STYLUS_BUTTON_SECONDARY = 309; // 0x135 + field public static final int KEYCODE_STYLUS_BUTTON_TAIL = 311; // 0x137 + field public static final int KEYCODE_STYLUS_BUTTON_TERTIARY = 310; // 0x136 field public static final int KEYCODE_SWITCH_CHARSET = 95; // 0x5f field public static final int KEYCODE_SYM = 63; // 0x3f field public static final int KEYCODE_SYSRQ = 120; // 0x78 diff --git a/core/api/test-current.txt b/core/api/test-current.txt index f780e6f3b39b5..085bd5510da7b 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -2854,7 +2854,7 @@ package android.view { method public static String actionToString(int); method public final void setDisplayId(int); field public static final int FLAG_IS_ACCESSIBILITY_EVENT = 2048; // 0x800 - field public static final int LAST_KEYCODE = 307; // 0x133 + field public static final int LAST_KEYCODE = 311; // 0x137 } public final class KeyboardShortcutGroup implements android.os.Parcelable { diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java index 6c238e5698c55..9789b5670fbb9 100644 --- a/core/java/android/view/KeyEvent.java +++ b/core/java/android/view/KeyEvent.java @@ -872,13 +872,33 @@ public class KeyEvent extends InputEvent implements Parcelable { public static final int KEYCODE_KEYBOARD_BACKLIGHT_UP = 306; /** Key code constant: Keyboard backlight toggle */ public static final int KEYCODE_KEYBOARD_BACKLIGHT_TOGGLE = 307; + /** + * Key code constant: The primary button on the barrel of a stylus. + * This is usually the button closest to the tip of the stylus. + */ + public static final int KEYCODE_STYLUS_BUTTON_PRIMARY = 308; + /** + * Key code constant: The secondary button on the barrel of a stylus. + * This is usually the second button from the tip of the stylus. + */ + public static final int KEYCODE_STYLUS_BUTTON_SECONDARY = 309; + /** + * Key code constant: The tertiary button on the barrel of a stylus. + * This is usually the third button from the tip of the stylus. + */ + public static final int KEYCODE_STYLUS_BUTTON_TERTIARY = 310; + /** + * Key code constant: A button on the tail end of a stylus. + * The use of this button does not usually correspond to the function of an eraser. + */ + public static final int KEYCODE_STYLUS_BUTTON_TAIL = 311; /** * Integer value of the last KEYCODE. Increases as new keycodes are added to KeyEvent. * @hide */ @TestApi - public static final int LAST_KEYCODE = KEYCODE_KEYBOARD_BACKLIGHT_TOGGLE; + public static final int LAST_KEYCODE = KEYCODE_STYLUS_BUTTON_TAIL; // NOTE: If you add a new keycode here you must also add it to: // isSystem() diff --git a/data/keyboards/Generic.kl b/data/keyboards/Generic.kl index a186aca4648f4..af96c743f4000 100644 --- a/data/keyboards/Generic.kl +++ b/data/keyboards/Generic.kl @@ -302,6 +302,11 @@ key 317 BUTTON_THUMBL key 318 BUTTON_THUMBR +key 329 STYLUS_BUTTON_TERTIARY +key 331 STYLUS_BUTTON_PRIMARY +key 332 STYLUS_BUTTON_SECONDARY + + # key 352 "KEY_OK" key 353 DPAD_CENTER # key 354 "KEY_GOTO" @@ -424,6 +429,8 @@ key usage 0x0c007C KEYBOARD_BACKLIGHT_TOGGLE key usage 0x0c0173 MEDIA_AUDIO_TRACK key usage 0x0c019C PROFILE_SWITCH key usage 0x0c01A2 ALL_APPS +key usage 0x0d0044 STYLUS_BUTTON_PRIMARY +key usage 0x0d005a STYLUS_BUTTON_SECONDARY # Joystick and game controller axes. # Axes that are not mapped will be assigned generic axis numbers by the input subsystem. diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index e332ac765633a..675819a772438 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -3052,6 +3052,13 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } break; + case KeyEvent.KEYCODE_STYLUS_BUTTON_PRIMARY: + case KeyEvent.KEYCODE_STYLUS_BUTTON_SECONDARY: + case KeyEvent.KEYCODE_STYLUS_BUTTON_TERTIARY: + case KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL: + Slog.wtf(TAG, "KEYCODE_STYLUS_BUTTON_* should be handled in" + + " interceptKeyBeforeQueueing"); + return key_consumed; } if (isValidGlobalKey(keyCode) @@ -4104,6 +4111,14 @@ public class PhoneWindowManager implements WindowManagerPolicy { result &= ~ACTION_PASS_TO_USER; break; } + case KeyEvent.KEYCODE_STYLUS_BUTTON_PRIMARY: + case KeyEvent.KEYCODE_STYLUS_BUTTON_SECONDARY: + case KeyEvent.KEYCODE_STYLUS_BUTTON_TERTIARY: + case KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL: { + // TODO(go/android-stylus-buttons): Handle stylus button presses. + result &= ~ACTION_PASS_TO_USER; + break; + } } if (useHapticFeedback) {