1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <input/InputEventLabels.h>
18
19 #define DEFINE_KEYCODE(key) { #key, AKEYCODE_##key }
20 #define DEFINE_AXIS(axis) { #axis, AMOTION_EVENT_AXIS_##axis }
21 #define DEFINE_LED(led) { #led, ALED_##led }
22 #define DEFINE_FLAG(flag) { #flag, POLICY_FLAG_##flag }
23
24 namespace android {
25
26 // NOTE: If you add a new keycode here you must also add it to several other files.
27 // Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
28 #define KEYCODES_SEQUENCE \
29 DEFINE_KEYCODE(UNKNOWN), \
30 DEFINE_KEYCODE(SOFT_LEFT), \
31 DEFINE_KEYCODE(SOFT_RIGHT), \
32 DEFINE_KEYCODE(HOME), \
33 DEFINE_KEYCODE(BACK), \
34 DEFINE_KEYCODE(CALL), \
35 DEFINE_KEYCODE(ENDCALL), \
36 DEFINE_KEYCODE(0), \
37 DEFINE_KEYCODE(1), \
38 DEFINE_KEYCODE(2), \
39 DEFINE_KEYCODE(3), \
40 DEFINE_KEYCODE(4), \
41 DEFINE_KEYCODE(5), \
42 DEFINE_KEYCODE(6), \
43 DEFINE_KEYCODE(7), \
44 DEFINE_KEYCODE(8), \
45 DEFINE_KEYCODE(9), \
46 DEFINE_KEYCODE(STAR), \
47 DEFINE_KEYCODE(POUND), \
48 DEFINE_KEYCODE(DPAD_UP), \
49 DEFINE_KEYCODE(DPAD_DOWN), \
50 DEFINE_KEYCODE(DPAD_LEFT), \
51 DEFINE_KEYCODE(DPAD_RIGHT), \
52 DEFINE_KEYCODE(DPAD_CENTER), \
53 DEFINE_KEYCODE(VOLUME_UP), \
54 DEFINE_KEYCODE(VOLUME_DOWN), \
55 DEFINE_KEYCODE(POWER), \
56 DEFINE_KEYCODE(CAMERA), \
57 DEFINE_KEYCODE(CLEAR), \
58 DEFINE_KEYCODE(A), \
59 DEFINE_KEYCODE(B), \
60 DEFINE_KEYCODE(C), \
61 DEFINE_KEYCODE(D), \
62 DEFINE_KEYCODE(E), \
63 DEFINE_KEYCODE(F), \
64 DEFINE_KEYCODE(G), \
65 DEFINE_KEYCODE(H), \
66 DEFINE_KEYCODE(I), \
67 DEFINE_KEYCODE(J), \
68 DEFINE_KEYCODE(K), \
69 DEFINE_KEYCODE(L), \
70 DEFINE_KEYCODE(M), \
71 DEFINE_KEYCODE(N), \
72 DEFINE_KEYCODE(O), \
73 DEFINE_KEYCODE(P), \
74 DEFINE_KEYCODE(Q), \
75 DEFINE_KEYCODE(R), \
76 DEFINE_KEYCODE(S), \
77 DEFINE_KEYCODE(T), \
78 DEFINE_KEYCODE(U), \
79 DEFINE_KEYCODE(V), \
80 DEFINE_KEYCODE(W), \
81 DEFINE_KEYCODE(X), \
82 DEFINE_KEYCODE(Y), \
83 DEFINE_KEYCODE(Z), \
84 DEFINE_KEYCODE(COMMA), \
85 DEFINE_KEYCODE(PERIOD), \
86 DEFINE_KEYCODE(ALT_LEFT), \
87 DEFINE_KEYCODE(ALT_RIGHT), \
88 DEFINE_KEYCODE(SHIFT_LEFT), \
89 DEFINE_KEYCODE(SHIFT_RIGHT), \
90 DEFINE_KEYCODE(TAB), \
91 DEFINE_KEYCODE(SPACE), \
92 DEFINE_KEYCODE(SYM), \
93 DEFINE_KEYCODE(EXPLORER), \
94 DEFINE_KEYCODE(ENVELOPE), \
95 DEFINE_KEYCODE(ENTER), \
96 DEFINE_KEYCODE(DEL), \
97 DEFINE_KEYCODE(GRAVE), \
98 DEFINE_KEYCODE(MINUS), \
99 DEFINE_KEYCODE(EQUALS), \
100 DEFINE_KEYCODE(LEFT_BRACKET), \
101 DEFINE_KEYCODE(RIGHT_BRACKET), \
102 DEFINE_KEYCODE(BACKSLASH), \
103 DEFINE_KEYCODE(SEMICOLON), \
104 DEFINE_KEYCODE(APOSTROPHE), \
105 DEFINE_KEYCODE(SLASH), \
106 DEFINE_KEYCODE(AT), \
107 DEFINE_KEYCODE(NUM), \
108 DEFINE_KEYCODE(HEADSETHOOK), \
109 DEFINE_KEYCODE(FOCUS), \
110 DEFINE_KEYCODE(PLUS), \
111 DEFINE_KEYCODE(MENU), \
112 DEFINE_KEYCODE(NOTIFICATION), \
113 DEFINE_KEYCODE(SEARCH), \
114 DEFINE_KEYCODE(MEDIA_PLAY_PAUSE), \
115 DEFINE_KEYCODE(MEDIA_STOP), \
116 DEFINE_KEYCODE(MEDIA_NEXT), \
117 DEFINE_KEYCODE(MEDIA_PREVIOUS), \
118 DEFINE_KEYCODE(MEDIA_REWIND), \
119 DEFINE_KEYCODE(MEDIA_FAST_FORWARD), \
120 DEFINE_KEYCODE(MUTE), \
121 DEFINE_KEYCODE(PAGE_UP), \
122 DEFINE_KEYCODE(PAGE_DOWN), \
123 DEFINE_KEYCODE(PICTSYMBOLS), \
124 DEFINE_KEYCODE(SWITCH_CHARSET), \
125 DEFINE_KEYCODE(BUTTON_A), \
126 DEFINE_KEYCODE(BUTTON_B), \
127 DEFINE_KEYCODE(BUTTON_C), \
128 DEFINE_KEYCODE(BUTTON_X), \
129 DEFINE_KEYCODE(BUTTON_Y), \
130 DEFINE_KEYCODE(BUTTON_Z), \
131 DEFINE_KEYCODE(BUTTON_L1), \
132 DEFINE_KEYCODE(BUTTON_R1), \
133 DEFINE_KEYCODE(BUTTON_L2), \
134 DEFINE_KEYCODE(BUTTON_R2), \
135 DEFINE_KEYCODE(BUTTON_THUMBL), \
136 DEFINE_KEYCODE(BUTTON_THUMBR), \
137 DEFINE_KEYCODE(BUTTON_START), \
138 DEFINE_KEYCODE(BUTTON_SELECT), \
139 DEFINE_KEYCODE(BUTTON_MODE), \
140 DEFINE_KEYCODE(ESCAPE), \
141 DEFINE_KEYCODE(FORWARD_DEL), \
142 DEFINE_KEYCODE(CTRL_LEFT), \
143 DEFINE_KEYCODE(CTRL_RIGHT), \
144 DEFINE_KEYCODE(CAPS_LOCK), \
145 DEFINE_KEYCODE(SCROLL_LOCK), \
146 DEFINE_KEYCODE(META_LEFT), \
147 DEFINE_KEYCODE(META_RIGHT), \
148 DEFINE_KEYCODE(FUNCTION), \
149 DEFINE_KEYCODE(SYSRQ), \
150 DEFINE_KEYCODE(BREAK), \
151 DEFINE_KEYCODE(MOVE_HOME), \
152 DEFINE_KEYCODE(MOVE_END), \
153 DEFINE_KEYCODE(INSERT), \
154 DEFINE_KEYCODE(FORWARD), \
155 DEFINE_KEYCODE(MEDIA_PLAY), \
156 DEFINE_KEYCODE(MEDIA_PAUSE), \
157 DEFINE_KEYCODE(MEDIA_CLOSE), \
158 DEFINE_KEYCODE(MEDIA_EJECT), \
159 DEFINE_KEYCODE(MEDIA_RECORD), \
160 DEFINE_KEYCODE(F1), \
161 DEFINE_KEYCODE(F2), \
162 DEFINE_KEYCODE(F3), \
163 DEFINE_KEYCODE(F4), \
164 DEFINE_KEYCODE(F5), \
165 DEFINE_KEYCODE(F6), \
166 DEFINE_KEYCODE(F7), \
167 DEFINE_KEYCODE(F8), \
168 DEFINE_KEYCODE(F9), \
169 DEFINE_KEYCODE(F10), \
170 DEFINE_KEYCODE(F11), \
171 DEFINE_KEYCODE(F12), \
172 DEFINE_KEYCODE(NUM_LOCK), \
173 DEFINE_KEYCODE(NUMPAD_0), \
174 DEFINE_KEYCODE(NUMPAD_1), \
175 DEFINE_KEYCODE(NUMPAD_2), \
176 DEFINE_KEYCODE(NUMPAD_3), \
177 DEFINE_KEYCODE(NUMPAD_4), \
178 DEFINE_KEYCODE(NUMPAD_5), \
179 DEFINE_KEYCODE(NUMPAD_6), \
180 DEFINE_KEYCODE(NUMPAD_7), \
181 DEFINE_KEYCODE(NUMPAD_8), \
182 DEFINE_KEYCODE(NUMPAD_9), \
183 DEFINE_KEYCODE(NUMPAD_DIVIDE), \
184 DEFINE_KEYCODE(NUMPAD_MULTIPLY), \
185 DEFINE_KEYCODE(NUMPAD_SUBTRACT), \
186 DEFINE_KEYCODE(NUMPAD_ADD), \
187 DEFINE_KEYCODE(NUMPAD_DOT), \
188 DEFINE_KEYCODE(NUMPAD_COMMA), \
189 DEFINE_KEYCODE(NUMPAD_ENTER), \
190 DEFINE_KEYCODE(NUMPAD_EQUALS), \
191 DEFINE_KEYCODE(NUMPAD_LEFT_PAREN), \
192 DEFINE_KEYCODE(NUMPAD_RIGHT_PAREN), \
193 DEFINE_KEYCODE(VOLUME_MUTE), \
194 DEFINE_KEYCODE(INFO), \
195 DEFINE_KEYCODE(CHANNEL_UP), \
196 DEFINE_KEYCODE(CHANNEL_DOWN), \
197 DEFINE_KEYCODE(ZOOM_IN), \
198 DEFINE_KEYCODE(ZOOM_OUT), \
199 DEFINE_KEYCODE(TV), \
200 DEFINE_KEYCODE(WINDOW), \
201 DEFINE_KEYCODE(GUIDE), \
202 DEFINE_KEYCODE(DVR), \
203 DEFINE_KEYCODE(BOOKMARK), \
204 DEFINE_KEYCODE(CAPTIONS), \
205 DEFINE_KEYCODE(SETTINGS), \
206 DEFINE_KEYCODE(TV_POWER), \
207 DEFINE_KEYCODE(TV_INPUT), \
208 DEFINE_KEYCODE(STB_POWER), \
209 DEFINE_KEYCODE(STB_INPUT), \
210 DEFINE_KEYCODE(AVR_POWER), \
211 DEFINE_KEYCODE(AVR_INPUT), \
212 DEFINE_KEYCODE(PROG_RED), \
213 DEFINE_KEYCODE(PROG_GREEN), \
214 DEFINE_KEYCODE(PROG_YELLOW), \
215 DEFINE_KEYCODE(PROG_BLUE), \
216 DEFINE_KEYCODE(APP_SWITCH), \
217 DEFINE_KEYCODE(BUTTON_1), \
218 DEFINE_KEYCODE(BUTTON_2), \
219 DEFINE_KEYCODE(BUTTON_3), \
220 DEFINE_KEYCODE(BUTTON_4), \
221 DEFINE_KEYCODE(BUTTON_5), \
222 DEFINE_KEYCODE(BUTTON_6), \
223 DEFINE_KEYCODE(BUTTON_7), \
224 DEFINE_KEYCODE(BUTTON_8), \
225 DEFINE_KEYCODE(BUTTON_9), \
226 DEFINE_KEYCODE(BUTTON_10), \
227 DEFINE_KEYCODE(BUTTON_11), \
228 DEFINE_KEYCODE(BUTTON_12), \
229 DEFINE_KEYCODE(BUTTON_13), \
230 DEFINE_KEYCODE(BUTTON_14), \
231 DEFINE_KEYCODE(BUTTON_15), \
232 DEFINE_KEYCODE(BUTTON_16), \
233 DEFINE_KEYCODE(LANGUAGE_SWITCH), \
234 DEFINE_KEYCODE(MANNER_MODE), \
235 DEFINE_KEYCODE(3D_MODE), \
236 DEFINE_KEYCODE(CONTACTS), \
237 DEFINE_KEYCODE(CALENDAR), \
238 DEFINE_KEYCODE(MUSIC), \
239 DEFINE_KEYCODE(CALCULATOR), \
240 DEFINE_KEYCODE(ZENKAKU_HANKAKU), \
241 DEFINE_KEYCODE(EISU), \
242 DEFINE_KEYCODE(MUHENKAN), \
243 DEFINE_KEYCODE(HENKAN), \
244 DEFINE_KEYCODE(KATAKANA_HIRAGANA), \
245 DEFINE_KEYCODE(YEN), \
246 DEFINE_KEYCODE(RO), \
247 DEFINE_KEYCODE(KANA), \
248 DEFINE_KEYCODE(ASSIST), \
249 DEFINE_KEYCODE(BRIGHTNESS_DOWN), \
250 DEFINE_KEYCODE(BRIGHTNESS_UP), \
251 DEFINE_KEYCODE(MEDIA_AUDIO_TRACK), \
252 DEFINE_KEYCODE(SLEEP), \
253 DEFINE_KEYCODE(WAKEUP), \
254 DEFINE_KEYCODE(PAIRING), \
255 DEFINE_KEYCODE(MEDIA_TOP_MENU), \
256 DEFINE_KEYCODE(11), \
257 DEFINE_KEYCODE(12), \
258 DEFINE_KEYCODE(LAST_CHANNEL), \
259 DEFINE_KEYCODE(TV_DATA_SERVICE), \
260 DEFINE_KEYCODE(VOICE_ASSIST), \
261 DEFINE_KEYCODE(TV_RADIO_SERVICE), \
262 DEFINE_KEYCODE(TV_TELETEXT), \
263 DEFINE_KEYCODE(TV_NUMBER_ENTRY), \
264 DEFINE_KEYCODE(TV_TERRESTRIAL_ANALOG), \
265 DEFINE_KEYCODE(TV_TERRESTRIAL_DIGITAL), \
266 DEFINE_KEYCODE(TV_SATELLITE), \
267 DEFINE_KEYCODE(TV_SATELLITE_BS), \
268 DEFINE_KEYCODE(TV_SATELLITE_CS), \
269 DEFINE_KEYCODE(TV_SATELLITE_SERVICE), \
270 DEFINE_KEYCODE(TV_NETWORK), \
271 DEFINE_KEYCODE(TV_ANTENNA_CABLE), \
272 DEFINE_KEYCODE(TV_INPUT_HDMI_1), \
273 DEFINE_KEYCODE(TV_INPUT_HDMI_2), \
274 DEFINE_KEYCODE(TV_INPUT_HDMI_3), \
275 DEFINE_KEYCODE(TV_INPUT_HDMI_4), \
276 DEFINE_KEYCODE(TV_INPUT_COMPOSITE_1), \
277 DEFINE_KEYCODE(TV_INPUT_COMPOSITE_2), \
278 DEFINE_KEYCODE(TV_INPUT_COMPONENT_1), \
279 DEFINE_KEYCODE(TV_INPUT_COMPONENT_2), \
280 DEFINE_KEYCODE(TV_INPUT_VGA_1), \
281 DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION), \
282 DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION_MIX_UP), \
283 DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION_MIX_DOWN), \
284 DEFINE_KEYCODE(TV_ZOOM_MODE), \
285 DEFINE_KEYCODE(TV_CONTENTS_MENU), \
286 DEFINE_KEYCODE(TV_MEDIA_CONTEXT_MENU), \
287 DEFINE_KEYCODE(TV_TIMER_PROGRAMMING), \
288 DEFINE_KEYCODE(HELP), \
289 DEFINE_KEYCODE(NAVIGATE_PREVIOUS), \
290 DEFINE_KEYCODE(NAVIGATE_NEXT), \
291 DEFINE_KEYCODE(NAVIGATE_IN), \
292 DEFINE_KEYCODE(NAVIGATE_OUT), \
293 DEFINE_KEYCODE(STEM_PRIMARY), \
294 DEFINE_KEYCODE(STEM_1), \
295 DEFINE_KEYCODE(STEM_2), \
296 DEFINE_KEYCODE(STEM_3), \
297 DEFINE_KEYCODE(DPAD_UP_LEFT), \
298 DEFINE_KEYCODE(DPAD_DOWN_LEFT), \
299 DEFINE_KEYCODE(DPAD_UP_RIGHT), \
300 DEFINE_KEYCODE(DPAD_DOWN_RIGHT), \
301 DEFINE_KEYCODE(MEDIA_SKIP_FORWARD), \
302 DEFINE_KEYCODE(MEDIA_SKIP_BACKWARD), \
303 DEFINE_KEYCODE(MEDIA_STEP_FORWARD), \
304 DEFINE_KEYCODE(MEDIA_STEP_BACKWARD), \
305 DEFINE_KEYCODE(SOFT_SLEEP), \
306 DEFINE_KEYCODE(CUT), \
307 DEFINE_KEYCODE(COPY), \
308 DEFINE_KEYCODE(PASTE), \
309 DEFINE_KEYCODE(SYSTEM_NAVIGATION_UP), \
310 DEFINE_KEYCODE(SYSTEM_NAVIGATION_DOWN), \
311 DEFINE_KEYCODE(SYSTEM_NAVIGATION_LEFT), \
312 DEFINE_KEYCODE(SYSTEM_NAVIGATION_RIGHT), \
313 DEFINE_KEYCODE(ALL_APPS), \
314 DEFINE_KEYCODE(REFRESH), \
315 DEFINE_KEYCODE(THUMBS_UP), \
316 DEFINE_KEYCODE(THUMBS_DOWN), \
317 DEFINE_KEYCODE(PROFILE_SWITCH), \
318 DEFINE_KEYCODE(VIDEO_APP_1), \
319 DEFINE_KEYCODE(VIDEO_APP_2), \
320 DEFINE_KEYCODE(VIDEO_APP_3), \
321 DEFINE_KEYCODE(VIDEO_APP_4), \
322 DEFINE_KEYCODE(VIDEO_APP_5), \
323 DEFINE_KEYCODE(VIDEO_APP_6), \
324 DEFINE_KEYCODE(VIDEO_APP_7), \
325 DEFINE_KEYCODE(VIDEO_APP_8), \
326 DEFINE_KEYCODE(FEATURED_APP_1), \
327 DEFINE_KEYCODE(FEATURED_APP_2), \
328 DEFINE_KEYCODE(FEATURED_APP_3), \
329 DEFINE_KEYCODE(FEATURED_APP_4), \
330 DEFINE_KEYCODE(DEMO_APP_1), \
331 DEFINE_KEYCODE(DEMO_APP_2), \
332 DEFINE_KEYCODE(DEMO_APP_3), \
333 DEFINE_KEYCODE(DEMO_APP_4)
334
335 // NOTE: If you add a new axis here you must also add it to several other files.
336 // Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list.
337 #define AXES_SEQUENCE \
338 DEFINE_AXIS(X), \
339 DEFINE_AXIS(Y), \
340 DEFINE_AXIS(PRESSURE), \
341 DEFINE_AXIS(SIZE), \
342 DEFINE_AXIS(TOUCH_MAJOR), \
343 DEFINE_AXIS(TOUCH_MINOR), \
344 DEFINE_AXIS(TOOL_MAJOR), \
345 DEFINE_AXIS(TOOL_MINOR), \
346 DEFINE_AXIS(ORIENTATION), \
347 DEFINE_AXIS(VSCROLL), \
348 DEFINE_AXIS(HSCROLL), \
349 DEFINE_AXIS(Z), \
350 DEFINE_AXIS(RX), \
351 DEFINE_AXIS(RY), \
352 DEFINE_AXIS(RZ), \
353 DEFINE_AXIS(HAT_X), \
354 DEFINE_AXIS(HAT_Y), \
355 DEFINE_AXIS(LTRIGGER), \
356 DEFINE_AXIS(RTRIGGER), \
357 DEFINE_AXIS(THROTTLE), \
358 DEFINE_AXIS(RUDDER), \
359 DEFINE_AXIS(WHEEL), \
360 DEFINE_AXIS(GAS), \
361 DEFINE_AXIS(BRAKE), \
362 DEFINE_AXIS(DISTANCE), \
363 DEFINE_AXIS(TILT), \
364 DEFINE_AXIS(SCROLL), \
365 DEFINE_AXIS(RELATIVE_X), \
366 DEFINE_AXIS(RELATIVE_Y), \
367 {"RESERVED_29", 29}, \
368 {"RESERVED_30", 30}, \
369 {"RESERVED_31", 31}, \
370 DEFINE_AXIS(GENERIC_1), \
371 DEFINE_AXIS(GENERIC_2), \
372 DEFINE_AXIS(GENERIC_3), \
373 DEFINE_AXIS(GENERIC_4), \
374 DEFINE_AXIS(GENERIC_5), \
375 DEFINE_AXIS(GENERIC_6), \
376 DEFINE_AXIS(GENERIC_7), \
377 DEFINE_AXIS(GENERIC_8), \
378 DEFINE_AXIS(GENERIC_9), \
379 DEFINE_AXIS(GENERIC_10), \
380 DEFINE_AXIS(GENERIC_11), \
381 DEFINE_AXIS(GENERIC_12), \
382 DEFINE_AXIS(GENERIC_13), \
383 DEFINE_AXIS(GENERIC_14), \
384 DEFINE_AXIS(GENERIC_15), \
385 DEFINE_AXIS(GENERIC_16)
386
387
388 // NOTE: If you add new LEDs here, you must also add them to Input.h
389 #define LEDS_SEQUENCE \
390 DEFINE_LED(NUM_LOCK), \
391 DEFINE_LED(CAPS_LOCK), \
392 DEFINE_LED(SCROLL_LOCK), \
393 DEFINE_LED(COMPOSE), \
394 DEFINE_LED(KANA), \
395 DEFINE_LED(SLEEP), \
396 DEFINE_LED(SUSPEND), \
397 DEFINE_LED(MUTE), \
398 DEFINE_LED(MISC), \
399 DEFINE_LED(MAIL), \
400 DEFINE_LED(CHARGING), \
401 DEFINE_LED(CONTROLLER_1), \
402 DEFINE_LED(CONTROLLER_2), \
403 DEFINE_LED(CONTROLLER_3), \
404 DEFINE_LED(CONTROLLER_4)
405
406 #define FLAGS_SEQUENCE \
407 DEFINE_FLAG(VIRTUAL), \
408 DEFINE_FLAG(FUNCTION), \
409 DEFINE_FLAG(GESTURE), \
410 DEFINE_FLAG(WAKE)
411
412 // --- InputEventLookup ---
413 const std::unordered_map<std::string, int> InputEventLookup::KEYCODES = {KEYCODES_SEQUENCE};
414
415 const std::vector<InputEventLabel> InputEventLookup::KEY_NAMES = {KEYCODES_SEQUENCE};
416
417 const std::unordered_map<std::string, int> InputEventLookup::AXES = {AXES_SEQUENCE};
418
419 const std::vector<InputEventLabel> InputEventLookup::AXES_NAMES = {AXES_SEQUENCE};
420
421 const std::unordered_map<std::string, int> InputEventLookup::LEDS = {LEDS_SEQUENCE};
422
423 const std::unordered_map<std::string, int> InputEventLookup::FLAGS = {FLAGS_SEQUENCE};
424
lookupValueByLabel(const std::unordered_map<std::string,int> & map,const char * literal)425 int InputEventLookup::lookupValueByLabel(const std::unordered_map<std::string, int>& map,
426 const char* literal) {
427 std::string str(literal);
428 auto it = map.find(str);
429 return it != map.end() ? it->second : 0;
430 }
431
lookupLabelByValue(const std::vector<InputEventLabel> & vec,int value)432 const char* InputEventLookup::lookupLabelByValue(const std::vector<InputEventLabel>& vec,
433 int value) {
434 if (static_cast<size_t>(value) < vec.size()) {
435 return vec[value].literal;
436 }
437 return nullptr;
438 }
439
getKeyCodeByLabel(const char * label)440 int32_t InputEventLookup::getKeyCodeByLabel(const char* label) {
441 return int32_t(lookupValueByLabel(KEYCODES, label));
442 }
443
getLabelByKeyCode(int32_t keyCode)444 const char* InputEventLookup::getLabelByKeyCode(int32_t keyCode) {
445 if (keyCode >= 0 && static_cast<size_t>(keyCode) < KEYCODES.size()) {
446 return lookupLabelByValue(KEY_NAMES, keyCode);
447 }
448 return nullptr;
449 }
450
getKeyFlagByLabel(const char * label)451 uint32_t InputEventLookup::getKeyFlagByLabel(const char* label) {
452 return uint32_t(lookupValueByLabel(FLAGS, label));
453 }
454
getAxisByLabel(const char * label)455 int32_t InputEventLookup::getAxisByLabel(const char* label) {
456 return int32_t(lookupValueByLabel(AXES, label));
457 }
458
getAxisLabel(int32_t axisId)459 const char* InputEventLookup::getAxisLabel(int32_t axisId) {
460 return lookupLabelByValue(AXES_NAMES, axisId);
461 }
462
getLedByLabel(const char * label)463 int32_t InputEventLookup::getLedByLabel(const char* label) {
464 return int32_t(lookupValueByLabel(LEDS, label));
465 }
466
467 } // namespace android
468