Add Android keycodes for stylus buttons

Ensure the new stylus buttons are not yet sent to apps.
DD: go/android-stylus-buttons

Bug: 246394583
Test: Build, Presubmit
Change-Id: I440a359ec8cffb60b9e87f2e51304c9b0320e16f
This commit is contained in:
Prabir Pradhan
2022-09-12 20:41:40 +00:00
parent c1527fea2a
commit ad914db014
5 changed files with 48 additions and 2 deletions

View File

@@ -48770,6 +48770,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

View File

@@ -2849,7 +2849,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 {

View File

@@ -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()

View File

@@ -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.

View File

@@ -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) {