blob: 50296e29baa8edcdbc0c508419b4dcdab9561235 [file] [log] [blame]
Jeff Brown6b53e8d2010-11-10 16:03:06 -08001/*
2 * Copyright (C) 2010 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#ifndef _UI_KEYBOARD_H
18#define _UI_KEYBOARD_H
19
20#include <ui/Input.h>
21#include <utils/Errors.h>
22#include <utils/String8.h>
Jeff Brown47e6b1b2010-11-29 17:37:49 -080023#include <utils/PropertyMap.h>
Jeff Brown6b53e8d2010-11-10 16:03:06 -080024
25namespace android {
26
27enum {
28 /* Device id of the built in keyboard. */
29 DEVICE_ID_BUILT_IN_KEYBOARD = 0,
30
31 /* Device id of a generic virtual keyboard with a full layout that can be used
32 * to synthesize key events. */
33 DEVICE_ID_VIRTUAL_KEYBOARD = -1,
34};
35
Jeff Brown90655042010-12-02 13:50:46 -080036class KeyLayoutMap;
37class KeyCharacterMap;
38
39/**
40 * Loads the key layout map and key character map for a keyboard device.
41 */
42class KeyMap {
43public:
Jeff Brown6b53e8d2010-11-10 16:03:06 -080044 String8 keyLayoutFile;
Jeff Brown90655042010-12-02 13:50:46 -080045 KeyLayoutMap* keyLayoutMap;
46
Jeff Brown6b53e8d2010-11-10 16:03:06 -080047 String8 keyCharacterMapFile;
Jeff Brown90655042010-12-02 13:50:46 -080048 KeyCharacterMap* keyCharacterMap;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080049
Jeff Brown90655042010-12-02 13:50:46 -080050 KeyMap();
51 ~KeyMap();
52
53 status_t load(const InputDeviceIdentifier& deviceIdenfier,
54 const PropertyMap* deviceConfiguration);
55
56 inline bool haveKeyLayout() const {
57 return !keyLayoutFile.isEmpty();
Jeff Brown6b53e8d2010-11-10 16:03:06 -080058 }
Jeff Brown47e6b1b2010-11-29 17:37:49 -080059
Jeff Brown90655042010-12-02 13:50:46 -080060 inline bool haveKeyCharacterMap() const {
61 return !keyCharacterMapFile.isEmpty();
Jeff Brown47e6b1b2010-11-29 17:37:49 -080062 }
Jeff Brown90655042010-12-02 13:50:46 -080063
64 inline bool isComplete() const {
65 return haveKeyLayout() && haveKeyCharacterMap();
66 }
67
68private:
69 bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
70 status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
71 status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier,
72 const String8& name);
73 String8 getPath(const InputDeviceIdentifier& deviceIdentifier,
74 const String8& name, InputDeviceConfigurationFileType type);
Jeff Brown6b53e8d2010-11-10 16:03:06 -080075};
76
77/**
Jeff Brown90655042010-12-02 13:50:46 -080078 * Returns true if the keyboard is eligible for use as a built-in keyboard.
Jeff Brown6b53e8d2010-11-10 16:03:06 -080079 */
Jeff Brown90655042010-12-02 13:50:46 -080080extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
81 const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
Jeff Brown6b53e8d2010-11-10 16:03:06 -080082
83/**
84 * Sets keyboard system properties.
85 */
Jeff Brown90655042010-12-02 13:50:46 -080086extern void setKeyboardProperties(int32_t deviceId, const InputDeviceIdentifier& deviceIdentifier,
87 const String8& keyLayoutFile, const String8& keyCharacterMapFile);
Jeff Brown6b53e8d2010-11-10 16:03:06 -080088
89/**
90 * Clears keyboard system properties.
91 */
92extern void clearKeyboardProperties(int32_t deviceId);
93
94/**
95 * Gets the key character map filename for a device using inspecting system properties
96 * and then falling back on a default key character map if necessary.
97 * Returns a NAME_NOT_FOUND if none found.
98 */
99extern status_t getKeyCharacterMapFile(int32_t deviceId, String8& outKeyCharacterMapFile);
100
101/**
102 * Gets a key code by its short form label, eg. "HOME".
103 * Returns 0 if unknown.
104 */
105extern int32_t getKeyCodeByLabel(const char* label);
106
107/**
108 * Gets a key flag by its short form label, eg. "WAKE".
109 * Returns 0 if unknown.
110 */
111extern uint32_t getKeyFlagByLabel(const char* label);
112
113/**
114 * Updates a meta state field when a key is pressed or released.
115 */
116extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
117
118} // namespace android
119
120#endif // _UI_KEYBOARD_H