Move key attribute information out of native.

Native doesn't ever actually care about the attributes of keys, so
move all of it up into the managed layer and move all of the key
names down so they're defined once.

Change-Id: Ic8ded13ce050b2b98744735ff50d11e8d882d7d5
This commit is contained in:
Michael Wright 2014-04-22 15:03:51 -07:00
parent 4cbf3c5344
commit 872db4f11e
11 changed files with 428 additions and 527 deletions

View File

@ -71,7 +71,7 @@ enum {
* Constants for LEDs. Hidden from the API since we don't actually expose a way to interact
* with LEDs to developers
*
* NOTE: If you add LEDs here, you must also add them to KeycodeLabels.h
* NOTE: If you add LEDs here, you must also add them to InputEventLabels.h
*/
ALED_NUM_LOCK = 0x00,
@ -146,18 +146,12 @@ class Parcel;
*/
enum {
/* These flags originate in RawEvents and are generally set in the key map.
* NOTE: If you edit these flags, also edit labels in KeycodeLabels.h. */
* NOTE: If you want a flag to be able to set in a keylayout file, then you must add it to
* InputEventLabels.h as well. */
POLICY_FLAG_WAKE = 0x00000001,
POLICY_FLAG_WAKE_DROPPED = 0x00000002,
POLICY_FLAG_SHIFT = 0x00000004,
POLICY_FLAG_CAPS_LOCK = 0x00000008,
POLICY_FLAG_ALT = 0x00000010,
POLICY_FLAG_ALT_GR = 0x00000020,
POLICY_FLAG_MENU = 0x00000040,
POLICY_FLAG_LAUNCHER = 0x00000080,
POLICY_FLAG_VIRTUAL = 0x00000100,
POLICY_FLAG_FUNCTION = 0x00000200,
POLICY_FLAG_VIRTUAL = 0x00000002,
POLICY_FLAG_FUNCTION = 0x00000004,
POLICY_FLAG_RAW_MASK = 0x0000ffff,
@ -312,13 +306,8 @@ public:
inline nsecs_t getEventTime() const { return mEventTime; }
// Return true if this event may have a default action implementation.
static bool hasDefaultAction(int32_t keyCode);
bool hasDefaultAction() const;
// Return true if this event represents a system key.
static bool isSystemKey(int32_t keyCode);
bool isSystemKey() const;
static const char* getLabel(int32_t keyCode);
static int32_t getKeyCodeFromLabel(const char* label);
void initialize(
int32_t deviceId,
@ -578,6 +567,9 @@ public:
return mSamplePointerCoords.array();
}
static const char* getLabel(int32_t axis);
static int32_t getAxisFromLabel(const char* label);
protected:
int32_t mAction;
int32_t mFlags;

View File

@ -0,0 +1,396 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_INPUT_EVENT_LABELS_H
#define _LIBINPUT_INPUT_EVENT_LABELS_H
#include <input/Input.h>
#include <android/keycodes.h>
#define DEFINE_KEYCODE(key) { #key, AKEYCODE_##key }
#define DEFINE_AXIS(axis) { #axis, AMOTION_EVENT_AXIS_##axis }
#define DEFINE_LED(led) { #led, ALED_##led }
#define DEFINE_FLAG(flag) { #flag, POLICY_FLAG_##flag }
namespace android {
template<typename T, size_t N>
size_t size(T (&)[N]) { return N; }
struct InputEventLabel {
const char *literal;
int value;
};
static const InputEventLabel KEYCODES[] = {
// NOTE: If you add a new keycode here you must also add it to several other files.
// Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
DEFINE_KEYCODE(UNKNOWN),
DEFINE_KEYCODE(SOFT_LEFT),
DEFINE_KEYCODE(SOFT_RIGHT),
DEFINE_KEYCODE(HOME),
DEFINE_KEYCODE(BACK),
DEFINE_KEYCODE(CALL),
DEFINE_KEYCODE(ENDCALL),
DEFINE_KEYCODE(0),
DEFINE_KEYCODE(1),
DEFINE_KEYCODE(2),
DEFINE_KEYCODE(3),
DEFINE_KEYCODE(4),
DEFINE_KEYCODE(5),
DEFINE_KEYCODE(6),
DEFINE_KEYCODE(7),
DEFINE_KEYCODE(8),
DEFINE_KEYCODE(9),
DEFINE_KEYCODE(STAR),
DEFINE_KEYCODE(POUND),
DEFINE_KEYCODE(DPAD_UP),
DEFINE_KEYCODE(DPAD_DOWN),
DEFINE_KEYCODE(DPAD_LEFT),
DEFINE_KEYCODE(DPAD_RIGHT),
DEFINE_KEYCODE(DPAD_CENTER),
DEFINE_KEYCODE(VOLUME_UP),
DEFINE_KEYCODE(VOLUME_DOWN),
DEFINE_KEYCODE(POWER),
DEFINE_KEYCODE(CAMERA),
DEFINE_KEYCODE(CLEAR),
DEFINE_KEYCODE(A),
DEFINE_KEYCODE(B),
DEFINE_KEYCODE(C),
DEFINE_KEYCODE(D),
DEFINE_KEYCODE(E),
DEFINE_KEYCODE(F),
DEFINE_KEYCODE(G),
DEFINE_KEYCODE(H),
DEFINE_KEYCODE(I),
DEFINE_KEYCODE(J),
DEFINE_KEYCODE(K),
DEFINE_KEYCODE(L),
DEFINE_KEYCODE(M),
DEFINE_KEYCODE(N),
DEFINE_KEYCODE(O),
DEFINE_KEYCODE(P),
DEFINE_KEYCODE(Q),
DEFINE_KEYCODE(R),
DEFINE_KEYCODE(S),
DEFINE_KEYCODE(T),
DEFINE_KEYCODE(U),
DEFINE_KEYCODE(V),
DEFINE_KEYCODE(W),
DEFINE_KEYCODE(X),
DEFINE_KEYCODE(Y),
DEFINE_KEYCODE(Z),
DEFINE_KEYCODE(COMMA),
DEFINE_KEYCODE(PERIOD),
DEFINE_KEYCODE(ALT_LEFT),
DEFINE_KEYCODE(ALT_RIGHT),
DEFINE_KEYCODE(SHIFT_LEFT),
DEFINE_KEYCODE(SHIFT_RIGHT),
DEFINE_KEYCODE(TAB),
DEFINE_KEYCODE(SPACE),
DEFINE_KEYCODE(SYM),
DEFINE_KEYCODE(EXPLORER),
DEFINE_KEYCODE(ENVELOPE),
DEFINE_KEYCODE(ENTER),
DEFINE_KEYCODE(DEL),
DEFINE_KEYCODE(GRAVE),
DEFINE_KEYCODE(MINUS),
DEFINE_KEYCODE(EQUALS),
DEFINE_KEYCODE(LEFT_BRACKET),
DEFINE_KEYCODE(RIGHT_BRACKET),
DEFINE_KEYCODE(BACKSLASH),
DEFINE_KEYCODE(SEMICOLON),
DEFINE_KEYCODE(APOSTROPHE),
DEFINE_KEYCODE(SLASH),
DEFINE_KEYCODE(AT),
DEFINE_KEYCODE(NUM),
DEFINE_KEYCODE(HEADSETHOOK),
DEFINE_KEYCODE(FOCUS), // *Camera* focus
DEFINE_KEYCODE(PLUS),
DEFINE_KEYCODE(MENU),
DEFINE_KEYCODE(NOTIFICATION),
DEFINE_KEYCODE(SEARCH),
DEFINE_KEYCODE(MEDIA_PLAY_PAUSE),
DEFINE_KEYCODE(MEDIA_STOP),
DEFINE_KEYCODE(MEDIA_NEXT),
DEFINE_KEYCODE(MEDIA_PREVIOUS),
DEFINE_KEYCODE(MEDIA_REWIND),
DEFINE_KEYCODE(MEDIA_FAST_FORWARD),
DEFINE_KEYCODE(MUTE),
DEFINE_KEYCODE(PAGE_UP),
DEFINE_KEYCODE(PAGE_DOWN),
DEFINE_KEYCODE(PICTSYMBOLS),
DEFINE_KEYCODE(SWITCH_CHARSET),
DEFINE_KEYCODE(BUTTON_A),
DEFINE_KEYCODE(BUTTON_B),
DEFINE_KEYCODE(BUTTON_C),
DEFINE_KEYCODE(BUTTON_X),
DEFINE_KEYCODE(BUTTON_Y),
DEFINE_KEYCODE(BUTTON_Z),
DEFINE_KEYCODE(BUTTON_L1),
DEFINE_KEYCODE(BUTTON_R1),
DEFINE_KEYCODE(BUTTON_L2),
DEFINE_KEYCODE(BUTTON_R2),
DEFINE_KEYCODE(BUTTON_THUMBL),
DEFINE_KEYCODE(BUTTON_THUMBR),
DEFINE_KEYCODE(BUTTON_START),
DEFINE_KEYCODE(BUTTON_SELECT),
DEFINE_KEYCODE(BUTTON_MODE),
DEFINE_KEYCODE(ESCAPE),
DEFINE_KEYCODE(FORWARD_DEL),
DEFINE_KEYCODE(CTRL_LEFT),
DEFINE_KEYCODE(CTRL_RIGHT),
DEFINE_KEYCODE(CAPS_LOCK),
DEFINE_KEYCODE(SCROLL_LOCK),
DEFINE_KEYCODE(META_LEFT),
DEFINE_KEYCODE(META_RIGHT),
DEFINE_KEYCODE(FUNCTION),
DEFINE_KEYCODE(SYSRQ),
DEFINE_KEYCODE(BREAK),
DEFINE_KEYCODE(MOVE_HOME),
DEFINE_KEYCODE(MOVE_END),
DEFINE_KEYCODE(INSERT),
DEFINE_KEYCODE(FORWARD),
DEFINE_KEYCODE(MEDIA_PLAY),
DEFINE_KEYCODE(MEDIA_PAUSE),
DEFINE_KEYCODE(MEDIA_CLOSE),
DEFINE_KEYCODE(MEDIA_EJECT),
DEFINE_KEYCODE(MEDIA_RECORD),
DEFINE_KEYCODE(F1),
DEFINE_KEYCODE(F2),
DEFINE_KEYCODE(F3),
DEFINE_KEYCODE(F4),
DEFINE_KEYCODE(F5),
DEFINE_KEYCODE(F6),
DEFINE_KEYCODE(F7),
DEFINE_KEYCODE(F8),
DEFINE_KEYCODE(F9),
DEFINE_KEYCODE(F10),
DEFINE_KEYCODE(F11),
DEFINE_KEYCODE(F12),
DEFINE_KEYCODE(NUM_LOCK),
DEFINE_KEYCODE(NUMPAD_0),
DEFINE_KEYCODE(NUMPAD_1),
DEFINE_KEYCODE(NUMPAD_2),
DEFINE_KEYCODE(NUMPAD_3),
DEFINE_KEYCODE(NUMPAD_4),
DEFINE_KEYCODE(NUMPAD_5),
DEFINE_KEYCODE(NUMPAD_6),
DEFINE_KEYCODE(NUMPAD_7),
DEFINE_KEYCODE(NUMPAD_8),
DEFINE_KEYCODE(NUMPAD_9),
DEFINE_KEYCODE(NUMPAD_DIVIDE),
DEFINE_KEYCODE(NUMPAD_MULTIPLY),
DEFINE_KEYCODE(NUMPAD_SUBTRACT),
DEFINE_KEYCODE(NUMPAD_ADD),
DEFINE_KEYCODE(NUMPAD_DOT),
DEFINE_KEYCODE(NUMPAD_COMMA),
DEFINE_KEYCODE(NUMPAD_ENTER),
DEFINE_KEYCODE(NUMPAD_EQUALS),
DEFINE_KEYCODE(NUMPAD_LEFT_PAREN),
DEFINE_KEYCODE(NUMPAD_RIGHT_PAREN),
DEFINE_KEYCODE(VOLUME_MUTE),
DEFINE_KEYCODE(INFO),
DEFINE_KEYCODE(CHANNEL_UP),
DEFINE_KEYCODE(CHANNEL_DOWN),
DEFINE_KEYCODE(ZOOM_IN),
DEFINE_KEYCODE(ZOOM_OUT),
DEFINE_KEYCODE(TV),
DEFINE_KEYCODE(WINDOW),
DEFINE_KEYCODE(GUIDE),
DEFINE_KEYCODE(DVR),
DEFINE_KEYCODE(BOOKMARK),
DEFINE_KEYCODE(CAPTIONS),
DEFINE_KEYCODE(SETTINGS),
DEFINE_KEYCODE(TV_POWER),
DEFINE_KEYCODE(TV_INPUT),
DEFINE_KEYCODE(STB_POWER),
DEFINE_KEYCODE(STB_INPUT),
DEFINE_KEYCODE(AVR_POWER),
DEFINE_KEYCODE(AVR_INPUT),
DEFINE_KEYCODE(PROG_RED),
DEFINE_KEYCODE(PROG_GREEN),
DEFINE_KEYCODE(PROG_YELLOW),
DEFINE_KEYCODE(PROG_BLUE),
DEFINE_KEYCODE(APP_SWITCH),
DEFINE_KEYCODE(BUTTON_1),
DEFINE_KEYCODE(BUTTON_2),
DEFINE_KEYCODE(BUTTON_3),
DEFINE_KEYCODE(BUTTON_4),
DEFINE_KEYCODE(BUTTON_5),
DEFINE_KEYCODE(BUTTON_6),
DEFINE_KEYCODE(BUTTON_7),
DEFINE_KEYCODE(BUTTON_8),
DEFINE_KEYCODE(BUTTON_9),
DEFINE_KEYCODE(BUTTON_10),
DEFINE_KEYCODE(BUTTON_11),
DEFINE_KEYCODE(BUTTON_12),
DEFINE_KEYCODE(BUTTON_13),
DEFINE_KEYCODE(BUTTON_14),
DEFINE_KEYCODE(BUTTON_15),
DEFINE_KEYCODE(BUTTON_16),
DEFINE_KEYCODE(LANGUAGE_SWITCH),
DEFINE_KEYCODE(MANNER_MODE),
DEFINE_KEYCODE(3D_MODE),
DEFINE_KEYCODE(CONTACTS),
DEFINE_KEYCODE(CALENDAR),
DEFINE_KEYCODE(MUSIC),
DEFINE_KEYCODE(CALCULATOR),
DEFINE_KEYCODE(ZENKAKU_HANKAKU),
DEFINE_KEYCODE(EISU),
DEFINE_KEYCODE(MUHENKAN),
DEFINE_KEYCODE(HENKAN),
DEFINE_KEYCODE(KATAKANA_HIRAGANA),
DEFINE_KEYCODE(YEN),
DEFINE_KEYCODE(RO),
DEFINE_KEYCODE(KANA),
DEFINE_KEYCODE(ASSIST),
DEFINE_KEYCODE(BRIGHTNESS_DOWN),
DEFINE_KEYCODE(BRIGHTNESS_UP),
DEFINE_KEYCODE(MEDIA_AUDIO_TRACK),
DEFINE_KEYCODE(SLEEP),
DEFINE_KEYCODE(WAKEUP),
{ NULL, 0 }
};
static const InputEventLabel AXES[] = {
DEFINE_AXIS(X),
DEFINE_AXIS(Y),
DEFINE_AXIS(PRESSURE),
DEFINE_AXIS(SIZE),
DEFINE_AXIS(TOUCH_MAJOR),
DEFINE_AXIS(TOUCH_MINOR),
DEFINE_AXIS(TOOL_MAJOR),
DEFINE_AXIS(TOOL_MINOR),
DEFINE_AXIS(ORIENTATION),
DEFINE_AXIS(VSCROLL),
DEFINE_AXIS(HSCROLL),
DEFINE_AXIS(Z),
DEFINE_AXIS(RX),
DEFINE_AXIS(RY),
DEFINE_AXIS(RZ),
DEFINE_AXIS(HAT_X),
DEFINE_AXIS(HAT_Y),
DEFINE_AXIS(LTRIGGER),
DEFINE_AXIS(RTRIGGER),
DEFINE_AXIS(THROTTLE),
DEFINE_AXIS(RUDDER),
DEFINE_AXIS(WHEEL),
DEFINE_AXIS(GAS),
DEFINE_AXIS(BRAKE),
DEFINE_AXIS(DISTANCE),
DEFINE_AXIS(TILT),
DEFINE_AXIS(GENERIC_1),
DEFINE_AXIS(GENERIC_2),
DEFINE_AXIS(GENERIC_3),
DEFINE_AXIS(GENERIC_4),
DEFINE_AXIS(GENERIC_5),
DEFINE_AXIS(GENERIC_6),
DEFINE_AXIS(GENERIC_7),
DEFINE_AXIS(GENERIC_8),
DEFINE_AXIS(GENERIC_9),
DEFINE_AXIS(GENERIC_10),
DEFINE_AXIS(GENERIC_11),
DEFINE_AXIS(GENERIC_12),
DEFINE_AXIS(GENERIC_13),
DEFINE_AXIS(GENERIC_14),
DEFINE_AXIS(GENERIC_15),
DEFINE_AXIS(GENERIC_16),
// NOTE: If you add a new axis here you must also add it to several other files.
// Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list.
{ NULL, 0 }
};
static const InputEventLabel LEDS[] = {
DEFINE_LED(NUM_LOCK),
DEFINE_LED(CAPS_LOCK),
DEFINE_LED(SCROLL_LOCK),
DEFINE_LED(COMPOSE),
DEFINE_LED(KANA),
DEFINE_LED(SLEEP),
DEFINE_LED(SUSPEND),
DEFINE_LED(MUTE),
DEFINE_LED(MISC),
DEFINE_LED(MAIL),
DEFINE_LED(CHARGING),
DEFINE_LED(CONTROLLER_1),
DEFINE_LED(CONTROLLER_2),
DEFINE_LED(CONTROLLER_3),
DEFINE_LED(CONTROLLER_4),
// NOTE: If you add new LEDs here, you must also add them to Input.h
{ NULL, 0 }
};
static const InputEventLabel FLAGS[] = {
DEFINE_FLAG(FUNCTION),
{ NULL, 0 }
};
static int lookupValueByLabel(const char* literal, const InputEventLabel *list) {
while (list->literal) {
if (strcmp(literal, list->literal) == 0) {
return list->value;
}
list++;
}
return list->value;
}
static const char* lookupLabelByValue(int value, const InputEventLabel* list) {
while (list->literal) {
if (list->value == value) {
return list->literal;
}
list++;
}
return NULL;
}
static int32_t getKeyCodeByLabel(const char* label) {
return int32_t(lookupValueByLabel(label, KEYCODES));
}
static const char* getLabelByKeyCode(int32_t keyCode) {
if (keyCode >= 0 && keyCode < size(KEYCODES)) {
return KEYCODES[keyCode].literal;
}
return NULL;
}
static uint32_t getKeyFlagByLabel(const char* label) {
return uint32_t(lookupValueByLabel(label, FLAGS));
}
static int32_t getAxisByLabel(const char* label) {
return int32_t(lookupValueByLabel(label, AXES));
}
static const char* getAxisLabel(int32_t axisId) {
return lookupLabelByValue(axisId, AXES);
}
static int32_t getLedByLabel(const char* label) {
return int32_t(lookupValueByLabel(label, LEDS));
}
} // namespace android
#endif // _LIBINPUT_INPUT_EVENT_LABELS_H

View File

@ -19,6 +19,7 @@
#include <input/Input.h>
#include <input/InputDevice.h>
#include <input/InputEventLabels.h>
#include <utils/Errors.h>
#include <utils/String8.h>
#include <utils/PropertyMap.h>
@ -81,36 +82,6 @@ private:
extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
/**
* Gets a key code by its short form label, eg. "HOME".
* Returns 0 if unknown.
*/
extern int32_t getKeyCodeByLabel(const char* label);
/**
* Gets a key flag by its short form label, eg. "WAKE".
* Returns 0 if unknown.
*/
extern uint32_t getKeyFlagByLabel(const char* label);
/**
* Gets an axis by its short form label, eg. "X".
* Returns -1 if unknown.
*/
extern int32_t getAxisByLabel(const char* label);
/**
* Gets an axis label by its id.
* Returns NULL if unknown.
*/
extern const char* getAxisLabel(int32_t axisId);
/**
* Gets an LED by its short form label, eg. "CAPS_LOCK".
* Returns -1 if unknown.
*/
extern int32_t getLedByLabel(const char* label);
/**
* Updates a meta state field when a key is pressed or released.
*/

View File

@ -1,346 +0,0 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _LIBINPUT_KEYCODE_LABELS_H
#define _LIBINPUT_KEYCODE_LABELS_H
#include <android/keycodes.h>
struct KeycodeLabel {
const char *literal;
int value;
};
static const KeycodeLabel KEYCODES[] = {
{ "SOFT_LEFT", 1 },
{ "SOFT_RIGHT", 2 },
{ "HOME", 3 },
{ "BACK", 4 },
{ "CALL", 5 },
{ "ENDCALL", 6 },
{ "0", 7 },
{ "1", 8 },
{ "2", 9 },
{ "3", 10 },
{ "4", 11 },
{ "5", 12 },
{ "6", 13 },
{ "7", 14 },
{ "8", 15 },
{ "9", 16 },
{ "STAR", 17 },
{ "POUND", 18 },
{ "DPAD_UP", 19 },
{ "DPAD_DOWN", 20 },
{ "DPAD_LEFT", 21 },
{ "DPAD_RIGHT", 22 },
{ "DPAD_CENTER", 23 },
{ "VOLUME_UP", 24 },
{ "VOLUME_DOWN", 25 },
{ "POWER", 26 },
{ "CAMERA", 27 },
{ "CLEAR", 28 },
{ "A", 29 },
{ "B", 30 },
{ "C", 31 },
{ "D", 32 },
{ "E", 33 },
{ "F", 34 },
{ "G", 35 },
{ "H", 36 },
{ "I", 37 },
{ "J", 38 },
{ "K", 39 },
{ "L", 40 },
{ "M", 41 },
{ "N", 42 },
{ "O", 43 },
{ "P", 44 },
{ "Q", 45 },
{ "R", 46 },
{ "S", 47 },
{ "T", 48 },
{ "U", 49 },
{ "V", 50 },
{ "W", 51 },
{ "X", 52 },
{ "Y", 53 },
{ "Z", 54 },
{ "COMMA", 55 },
{ "PERIOD", 56 },
{ "ALT_LEFT", 57 },
{ "ALT_RIGHT", 58 },
{ "SHIFT_LEFT", 59 },
{ "SHIFT_RIGHT", 60 },
{ "TAB", 61 },
{ "SPACE", 62 },
{ "SYM", 63 },
{ "EXPLORER", 64 },
{ "ENVELOPE", 65 },
{ "ENTER", 66 },
{ "DEL", 67 },
{ "GRAVE", 68 },
{ "MINUS", 69 },
{ "EQUALS", 70 },
{ "LEFT_BRACKET", 71 },
{ "RIGHT_BRACKET", 72 },
{ "BACKSLASH", 73 },
{ "SEMICOLON", 74 },
{ "APOSTROPHE", 75 },
{ "SLASH", 76 },
{ "AT", 77 },
{ "NUM", 78 },
{ "HEADSETHOOK", 79 },
{ "FOCUS", 80 },
{ "PLUS", 81 },
{ "MENU", 82 },
{ "NOTIFICATION", 83 },
{ "SEARCH", 84 },
{ "MEDIA_PLAY_PAUSE", 85 },
{ "MEDIA_STOP", 86 },
{ "MEDIA_NEXT", 87 },
{ "MEDIA_PREVIOUS", 88 },
{ "MEDIA_REWIND", 89 },
{ "MEDIA_FAST_FORWARD", 90 },
{ "MUTE", 91 },
{ "PAGE_UP", 92 },
{ "PAGE_DOWN", 93 },
{ "PICTSYMBOLS", 94 },
{ "SWITCH_CHARSET", 95 },
{ "BUTTON_A", 96 },
{ "BUTTON_B", 97 },
{ "BUTTON_C", 98 },
{ "BUTTON_X", 99 },
{ "BUTTON_Y", 100 },
{ "BUTTON_Z", 101 },
{ "BUTTON_L1", 102 },
{ "BUTTON_R1", 103 },
{ "BUTTON_L2", 104 },
{ "BUTTON_R2", 105 },
{ "BUTTON_THUMBL", 106 },
{ "BUTTON_THUMBR", 107 },
{ "BUTTON_START", 108 },
{ "BUTTON_SELECT", 109 },
{ "BUTTON_MODE", 110 },
{ "ESCAPE", 111 },
{ "FORWARD_DEL", 112 },
{ "CTRL_LEFT", 113 },
{ "CTRL_RIGHT", 114 },
{ "CAPS_LOCK", 115 },
{ "SCROLL_LOCK", 116 },
{ "META_LEFT", 117 },
{ "META_RIGHT", 118 },
{ "FUNCTION", 119 },
{ "SYSRQ", 120 },
{ "BREAK", 121 },
{ "MOVE_HOME", 122 },
{ "MOVE_END", 123 },
{ "INSERT", 124 },
{ "FORWARD", 125 },
{ "MEDIA_PLAY", 126 },
{ "MEDIA_PAUSE", 127 },
{ "MEDIA_CLOSE", 128 },
{ "MEDIA_EJECT", 129 },
{ "MEDIA_RECORD", 130 },
{ "F1", 131 },
{ "F2", 132 },
{ "F3", 133 },
{ "F4", 134 },
{ "F5", 135 },
{ "F6", 136 },
{ "F7", 137 },
{ "F8", 138 },
{ "F9", 139 },
{ "F10", 140 },
{ "F11", 141 },
{ "F12", 142 },
{ "NUM_LOCK", 143 },
{ "NUMPAD_0", 144 },
{ "NUMPAD_1", 145 },
{ "NUMPAD_2", 146 },
{ "NUMPAD_3", 147 },
{ "NUMPAD_4", 148 },
{ "NUMPAD_5", 149 },
{ "NUMPAD_6", 150 },
{ "NUMPAD_7", 151 },
{ "NUMPAD_8", 152 },
{ "NUMPAD_9", 153 },
{ "NUMPAD_DIVIDE", 154 },
{ "NUMPAD_MULTIPLY", 155 },
{ "NUMPAD_SUBTRACT", 156 },
{ "NUMPAD_ADD", 157 },
{ "NUMPAD_DOT", 158 },
{ "NUMPAD_COMMA", 159 },
{ "NUMPAD_ENTER", 160 },
{ "NUMPAD_EQUALS", 161 },
{ "NUMPAD_LEFT_PAREN", 162 },
{ "NUMPAD_RIGHT_PAREN", 163 },
{ "VOLUME_MUTE", 164 },
{ "INFO", 165 },
{ "CHANNEL_UP", 166 },
{ "CHANNEL_DOWN", 167 },
{ "ZOOM_IN", 168 },
{ "ZOOM_OUT", 169 },
{ "TV", 170 },
{ "WINDOW", 171 },
{ "GUIDE", 172 },
{ "DVR", 173 },
{ "BOOKMARK", 174 },
{ "CAPTIONS", 175 },
{ "SETTINGS", 176 },
{ "TV_POWER", 177 },
{ "TV_INPUT", 178 },
{ "STB_POWER", 179 },
{ "STB_INPUT", 180 },
{ "AVR_POWER", 181 },
{ "AVR_INPUT", 182 },
{ "PROG_RED", 183 },
{ "PROG_GREEN", 184 },
{ "PROG_YELLOW", 185 },
{ "PROG_BLUE", 186 },
{ "APP_SWITCH", 187 },
{ "BUTTON_1", 188 },
{ "BUTTON_2", 189 },
{ "BUTTON_3", 190 },
{ "BUTTON_4", 191 },
{ "BUTTON_5", 192 },
{ "BUTTON_6", 193 },
{ "BUTTON_7", 194 },
{ "BUTTON_8", 195 },
{ "BUTTON_9", 196 },
{ "BUTTON_10", 197 },
{ "BUTTON_11", 198 },
{ "BUTTON_12", 199 },
{ "BUTTON_13", 200 },
{ "BUTTON_14", 201 },
{ "BUTTON_15", 202 },
{ "BUTTON_16", 203 },
{ "LANGUAGE_SWITCH", 204 },
{ "MANNER_MODE", 205 },
{ "3D_MODE", 206 },
{ "CONTACTS", 207 },
{ "CALENDAR", 208 },
{ "MUSIC", 209 },
{ "CALCULATOR", 210 },
{ "ZENKAKU_HANKAKU", 211 },
{ "EISU", 212 },
{ "MUHENKAN", 213 },
{ "HENKAN", 214 },
{ "KATAKANA_HIRAGANA", 215 },
{ "YEN", 216 },
{ "RO", 217 },
{ "KANA", 218 },
{ "ASSIST", 219 },
{ "BRIGHTNESS_DOWN", 220 },
{ "BRIGHTNESS_UP", 221 },
{ "MEDIA_AUDIO_TRACK", 222 },
{ "SLEEP", 223 },
{ "WAKEUP", 224 },
// NOTE: If you add a new keycode here you must also add it to several other files.
// Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
{ NULL, 0 }
};
// NOTE: If you edit these flags, also edit policy flags in Input.h.
static const KeycodeLabel FLAGS[] = {
{ "WAKE", 0x00000001 },
{ "WAKE_DROPPED", 0x00000002 },
{ "SHIFT", 0x00000004 },
{ "CAPS_LOCK", 0x00000008 },
{ "ALT", 0x00000010 },
{ "ALT_GR", 0x00000020 },
{ "MENU", 0x00000040 },
{ "LAUNCHER", 0x00000080 },
{ "VIRTUAL", 0x00000100 },
{ "FUNCTION", 0x00000200 },
{ NULL, 0 }
};
static const KeycodeLabel AXES[] = {
{ "X", 0 },
{ "Y", 1 },
{ "PRESSURE", 2 },
{ "SIZE", 3 },
{ "TOUCH_MAJOR", 4 },
{ "TOUCH_MINOR", 5 },
{ "TOOL_MAJOR", 6 },
{ "TOOL_MINOR", 7 },
{ "ORIENTATION", 8 },
{ "VSCROLL", 9 },
{ "HSCROLL", 10 },
{ "Z", 11 },
{ "RX", 12 },
{ "RY", 13 },
{ "RZ", 14 },
{ "HAT_X", 15 },
{ "HAT_Y", 16 },
{ "LTRIGGER", 17 },
{ "RTRIGGER", 18 },
{ "THROTTLE", 19 },
{ "RUDDER", 20 },
{ "WHEEL", 21 },
{ "GAS", 22 },
{ "BRAKE", 23 },
{ "DISTANCE", 24 },
{ "TILT", 25 },
{ "GENERIC_1", 32 },
{ "GENERIC_2", 33 },
{ "GENERIC_3", 34 },
{ "GENERIC_4", 35 },
{ "GENERIC_5", 36 },
{ "GENERIC_6", 37 },
{ "GENERIC_7", 38 },
{ "GENERIC_8", 39 },
{ "GENERIC_9", 40 },
{ "GENERIC_10", 41 },
{ "GENERIC_11", 42 },
{ "GENERIC_12", 43 },
{ "GENERIC_13", 44 },
{ "GENERIC_14", 45 },
{ "GENERIC_15", 46 },
{ "GENERIC_16", 47 },
// NOTE: If you add a new axis here you must also add it to several other files.
// Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list.
{ NULL, -1 }
};
static const KeycodeLabel LEDS[] = {
{ "NUM_LOCK", 0x00 },
{ "CAPS_LOCK", 0x01 },
{ "SCROLL_LOCK", 0x02 },
{ "COMPOSE", 0x03 },
{ "KANA", 0x04 },
{ "SLEEP", 0x05 },
{ "SUSPEND", 0x06 },
{ "MUTE", 0x07 },
{ "MISC", 0x08 },
{ "MAIL", 0x09 },
{ "CHARGING", 0x0a },
{ "CONTROLLER_1", 0x10 },
{ "CONTROLLER_2", 0x11 },
{ "CONTROLLER_3", 0x12 },
{ "CONTROLLER_4", 0x13 },
// NOTE: If you add new LEDs here, you must also add them to Input.h
{ NULL, -1 }
};
#endif // _LIBINPUT_KEYCODE_LABELS_H

View File

@ -21,6 +21,7 @@
#include <limits.h>
#include <input/Input.h>
#include <input/InputEventLabels.h>
#ifdef HAVE_ANDROID_OS
#include <binder/Parcel.h>
@ -42,82 +43,12 @@ void InputEvent::initialize(const InputEvent& from) {
// --- KeyEvent ---
bool KeyEvent::hasDefaultAction(int32_t keyCode) {
switch (keyCode) {
case AKEYCODE_HOME:
case AKEYCODE_BACK:
case AKEYCODE_CALL:
case AKEYCODE_ENDCALL:
case AKEYCODE_VOLUME_UP:
case AKEYCODE_VOLUME_DOWN:
case AKEYCODE_VOLUME_MUTE:
case AKEYCODE_POWER:
case AKEYCODE_CAMERA:
case AKEYCODE_HEADSETHOOK:
case AKEYCODE_MENU:
case AKEYCODE_NOTIFICATION:
case AKEYCODE_FOCUS:
case AKEYCODE_SEARCH:
case AKEYCODE_MEDIA_PLAY:
case AKEYCODE_MEDIA_PAUSE:
case AKEYCODE_MEDIA_PLAY_PAUSE:
case AKEYCODE_MEDIA_STOP:
case AKEYCODE_MEDIA_NEXT:
case AKEYCODE_MEDIA_PREVIOUS:
case AKEYCODE_MEDIA_REWIND:
case AKEYCODE_MEDIA_RECORD:
case AKEYCODE_MEDIA_FAST_FORWARD:
case AKEYCODE_MUTE:
case AKEYCODE_BRIGHTNESS_DOWN:
case AKEYCODE_BRIGHTNESS_UP:
case AKEYCODE_MEDIA_AUDIO_TRACK:
return true;
}
return false;
const char* KeyEvent::getLabel(int32_t keyCode) {
return getLabelByKeyCode(keyCode);
}
bool KeyEvent::hasDefaultAction() const {
return hasDefaultAction(getKeyCode());
}
bool KeyEvent::isSystemKey(int32_t keyCode) {
switch (keyCode) {
case AKEYCODE_MENU:
case AKEYCODE_SOFT_RIGHT:
case AKEYCODE_HOME:
case AKEYCODE_BACK:
case AKEYCODE_CALL:
case AKEYCODE_ENDCALL:
case AKEYCODE_VOLUME_UP:
case AKEYCODE_VOLUME_DOWN:
case AKEYCODE_VOLUME_MUTE:
case AKEYCODE_MUTE:
case AKEYCODE_POWER:
case AKEYCODE_HEADSETHOOK:
case AKEYCODE_MEDIA_PLAY:
case AKEYCODE_MEDIA_PAUSE:
case AKEYCODE_MEDIA_PLAY_PAUSE:
case AKEYCODE_MEDIA_STOP:
case AKEYCODE_MEDIA_NEXT:
case AKEYCODE_MEDIA_PREVIOUS:
case AKEYCODE_MEDIA_REWIND:
case AKEYCODE_MEDIA_RECORD:
case AKEYCODE_MEDIA_FAST_FORWARD:
case AKEYCODE_CAMERA:
case AKEYCODE_FOCUS:
case AKEYCODE_SEARCH:
case AKEYCODE_BRIGHTNESS_DOWN:
case AKEYCODE_BRIGHTNESS_UP:
case AKEYCODE_MEDIA_AUDIO_TRACK:
return true;
}
return false;
}
bool KeyEvent::isSystemKey() const {
return isSystemKey(getKeyCode());
int32_t KeyEvent::getKeyCodeFromLabel(const char* label) {
return getKeyCodeByLabel(label);
}
void KeyEvent::initialize(
@ -591,6 +522,14 @@ bool MotionEvent::isTouchEvent(int32_t source, int32_t action) {
return false;
}
const char* MotionEvent::getLabel(int32_t axis) {
return getAxisLabel(axis);
}
int32_t MotionEvent::getAxisFromLabel(const char* label) {
return getAxisByLabel(label);
}
// --- PooledInputEventFactory ---

View File

@ -312,7 +312,7 @@ status_t InputPublisher::publishMotionEvent(
}
if (pointerCount > MAX_POINTERS || pointerCount < 1) {
ALOGE("channel '%s' publisher ~ Invalid number of pointers provided: %d.",
ALOGE("channel '%s' publisher ~ Invalid number of pointers provided: %zu.",
mChannel->getName().string(), pointerCount);
return BAD_VALUE;
}

View File

@ -24,6 +24,7 @@
#endif
#include <android/keycodes.h>
#include <input/InputEventLabels.h>
#include <input/Keyboard.h>
#include <input/KeyCharacterMap.h>

View File

@ -19,6 +19,7 @@
#include <stdlib.h>
#include <android/keycodes.h>
#include <input/InputEventLabels.h>
#include <input/Keyboard.h>
#include <input/KeyLayoutMap.h>
#include <utils/Log.h>

View File

@ -21,7 +21,7 @@
#include <limits.h>
#include <input/Keyboard.h>
#include <input/KeycodeLabels.h>
#include <input/InputEventLabels.h>
#include <input/KeyLayoutMap.h>
#include <input/KeyCharacterMap.h>
#include <input/InputDevice.h>
@ -167,46 +167,6 @@ bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
return strstr(deviceIdentifier.name.string(), "-keypad");
}
static int lookupValueByLabel(const char* literal, const KeycodeLabel *list) {
while (list->literal) {
if (strcmp(literal, list->literal) == 0) {
return list->value;
}
list++;
}
return list->value;
}
static const char* lookupLabelByValue(int value, const KeycodeLabel *list) {
while (list->literal) {
if (list->value == value) {
return list->literal;
}
list++;
}
return NULL;
}
int32_t getKeyCodeByLabel(const char* label) {
return int32_t(lookupValueByLabel(label, KEYCODES));
}
uint32_t getKeyFlagByLabel(const char* label) {
return uint32_t(lookupValueByLabel(label, FLAGS));
}
int32_t getAxisByLabel(const char* label) {
return int32_t(lookupValueByLabel(label, AXES));
}
const char* getAxisLabel(int32_t axisId) {
return lookupLabelByValue(axisId, AXES);
}
int32_t getLedByLabel(const char* label) {
return int32_t(lookupValueByLabel(label, LEDS));
}
static int32_t setEphemeralMetaState(int32_t mask, bool down, int32_t oldMetaState) {
int32_t newMetaState;
if (down) {

View File

@ -2360,18 +2360,6 @@ void InputDispatcher::notifyKey(const NotifyKeyArgs* args) {
policyFlags |= POLICY_FLAG_VIRTUAL;
flags |= AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY;
}
if (policyFlags & POLICY_FLAG_ALT) {
metaState |= AMETA_ALT_ON | AMETA_ALT_LEFT_ON;
}
if (policyFlags & POLICY_FLAG_ALT_GR) {
metaState |= AMETA_ALT_ON | AMETA_ALT_RIGHT_ON;
}
if (policyFlags & POLICY_FLAG_SHIFT) {
metaState |= AMETA_SHIFT_ON | AMETA_SHIFT_LEFT_ON;
}
if (policyFlags & POLICY_FLAG_CAPS_LOCK) {
metaState |= AMETA_CAPS_LOCK_ON;
}
if (policyFlags & POLICY_FLAG_FUNCTION) {
metaState |= AMETA_FUNCTION_ON;
}

View File

@ -2167,9 +2167,8 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,
// For internal keyboards, the key layout file should specify the policy flags for
// each wake key individually.
// TODO: Use the input device configuration to control this behavior more finely.
if (down && getDevice()->isExternal()
&& !(policyFlags & (POLICY_FLAG_WAKE | POLICY_FLAG_WAKE_DROPPED))) {
policyFlags |= POLICY_FLAG_WAKE_DROPPED;
if (down && getDevice()->isExternal()) {
policyFlags |= POLICY_FLAG_WAKE;
}
if (mParameters.handlesKeyRepeat) {
@ -2510,7 +2509,7 @@ void CursorInputMapper::sync(nsecs_t when) {
// TODO: Use the input device configuration to control this behavior more finely.
uint32_t policyFlags = 0;
if ((buttonsPressed || moved || scrolled) && getDevice()->isExternal()) {
policyFlags |= POLICY_FLAG_WAKE_DROPPED;
policyFlags |= POLICY_FLAG_WAKE;
}
// Synthesize key down from buttons if needed.
@ -3787,7 +3786,7 @@ void TouchInputMapper::sync(nsecs_t when) {
}
if (mParameters.wake) {
policyFlags |= POLICY_FLAG_WAKE_DROPPED;
policyFlags |= POLICY_FLAG_WAKE;
}
}