blob: 20a17e33474a8d7c34319398bbfbf008e54aa0b0 [file] [log] [blame]
Jeff Brown5912f952013-07-01 19:10:31 -07001/*
2 * Copyright (C) 2012 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 _LIBINPUT_INPUT_DEVICE_H
18#define _LIBINPUT_INPUT_DEVICE_H
19
20#include <input/Input.h>
21#include <input/KeyCharacterMap.h>
Arthur Hung7c3ae9c2019-03-11 11:23:03 +080022#include <vector>
Jeff Brown5912f952013-07-01 19:10:31 -070023
24namespace android {
25
26/*
27 * Identifies a device.
28 */
29struct InputDeviceIdentifier {
30 inline InputDeviceIdentifier() :
31 bus(0), vendor(0), product(0), version(0) {
32 }
33
34 // Information provided by the kernel.
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010035 std::string name;
36 std::string location;
37 std::string uniqueId;
Jeff Brown5912f952013-07-01 19:10:31 -070038 uint16_t bus;
39 uint16_t vendor;
40 uint16_t product;
41 uint16_t version;
42
43 // A composite input device descriptor string that uniquely identifies the device
44 // even across reboots or reconnections. The value of this field is used by
45 // upper layers of the input system to associate settings with individual devices.
46 // It is hashed from whatever kernel provided information is available.
47 // Ideally, the way this value is computed should not change between Android releases
48 // because that would invalidate persistent settings that rely on it.
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010049 std::string descriptor;
RoboErikec2a15a2013-12-19 11:54:29 -080050
51 // A value added to uniquely identify a device in the absence of a unique id. This
52 // is intended to be a minimum way to distinguish from other active devices and may
53 // reuse values that are not associated with an input anymore.
54 uint16_t nonce;
Siarhei Vishniakoub45635c2019-02-20 19:22:09 -060055
56 /**
57 * Return InputDeviceIdentifier.name that has been adjusted as follows:
58 * - all characters besides alphanumerics, dash,
59 * and underscore have been replaced with underscores.
60 * This helps in situations where a file that matches the device name is needed,
61 * while conforming to the filename limitations.
62 */
63 std::string getCanonicalName() const;
Jeff Brown5912f952013-07-01 19:10:31 -070064};
65
66/*
67 * Describes the characteristics and capabilities of an input device.
68 */
69class InputDeviceInfo {
70public:
71 InputDeviceInfo();
72 InputDeviceInfo(const InputDeviceInfo& other);
73 ~InputDeviceInfo();
74
75 struct MotionRange {
76 int32_t axis;
77 uint32_t source;
78 float min;
79 float max;
80 float flat;
81 float fuzz;
82 float resolution;
83 };
84
Michael Wright0415d632013-07-17 13:23:26 -070085 void initialize(int32_t id, int32_t generation, int32_t controllerNumber,
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010086 const InputDeviceIdentifier& identifier, const std::string& alias, bool isExternal,
Tim Kilbourn063ff532015-04-08 10:26:18 -070087 bool hasMic);
Jeff Brown5912f952013-07-01 19:10:31 -070088
89 inline int32_t getId() const { return mId; }
Michael Wright0415d632013-07-17 13:23:26 -070090 inline int32_t getControllerNumber() const { return mControllerNumber; }
Jeff Brown5912f952013-07-01 19:10:31 -070091 inline int32_t getGeneration() const { return mGeneration; }
92 inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; }
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010093 inline const std::string& getAlias() const { return mAlias; }
94 inline const std::string& getDisplayName() const {
95 return mAlias.empty() ? mIdentifier.name : mAlias;
Jeff Brown5912f952013-07-01 19:10:31 -070096 }
97 inline bool isExternal() const { return mIsExternal; }
Tim Kilbourn063ff532015-04-08 10:26:18 -070098 inline bool hasMic() const { return mHasMic; }
Jeff Brown5912f952013-07-01 19:10:31 -070099 inline uint32_t getSources() const { return mSources; }
100
101 const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
102
103 void addSource(uint32_t source);
104 void addMotionRange(int32_t axis, uint32_t source,
105 float min, float max, float flat, float fuzz, float resolution);
106 void addMotionRange(const MotionRange& range);
107
108 inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
109 inline int32_t getKeyboardType() const { return mKeyboardType; }
110
111 inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) {
112 mKeyCharacterMap = value;
113 }
114
115 inline sp<KeyCharacterMap> getKeyCharacterMap() const {
116 return mKeyCharacterMap;
117 }
118
119 inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; }
120 inline bool hasVibrator() const { return mHasVibrator; }
121
Michael Wright931fd6d2013-07-10 18:05:15 -0700122 inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; }
123 inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; }
124
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800125 inline const std::vector<MotionRange>& getMotionRanges() const {
Jeff Brown5912f952013-07-01 19:10:31 -0700126 return mMotionRanges;
127 }
128
129private:
130 int32_t mId;
131 int32_t mGeneration;
Michael Wright0415d632013-07-17 13:23:26 -0700132 int32_t mControllerNumber;
Jeff Brown5912f952013-07-01 19:10:31 -0700133 InputDeviceIdentifier mIdentifier;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100134 std::string mAlias;
Jeff Brown5912f952013-07-01 19:10:31 -0700135 bool mIsExternal;
Tim Kilbourn063ff532015-04-08 10:26:18 -0700136 bool mHasMic;
Jeff Brown5912f952013-07-01 19:10:31 -0700137 uint32_t mSources;
138 int32_t mKeyboardType;
139 sp<KeyCharacterMap> mKeyCharacterMap;
140 bool mHasVibrator;
Michael Wright931fd6d2013-07-10 18:05:15 -0700141 bool mHasButtonUnderPad;
Jeff Brown5912f952013-07-01 19:10:31 -0700142
Arthur Hung7c3ae9c2019-03-11 11:23:03 +0800143 std::vector<MotionRange> mMotionRanges;
Jeff Brown5912f952013-07-01 19:10:31 -0700144};
145
146/* Types of input device configuration files. */
147enum InputDeviceConfigurationFileType {
148 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0, /* .idc file */
149 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1, /* .kl file */
150 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */
151};
152
153/*
154 * Gets the path of an input device configuration file, if one is available.
155 * Considers both system provided and user installed configuration files.
156 *
157 * The device identifier is used to construct several default configuration file
158 * names to try based on the device name, vendor, product, and version.
159 *
160 * Returns an empty string if not found.
161 */
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100162extern std::string getInputDeviceConfigurationFilePathByDeviceIdentifier(
Jeff Brown5912f952013-07-01 19:10:31 -0700163 const InputDeviceIdentifier& deviceIdentifier,
164 InputDeviceConfigurationFileType type);
165
166/*
167 * Gets the path of an input device configuration file, if one is available.
168 * Considers both system provided and user installed configuration files.
169 *
170 * The name is case-sensitive and is used to construct the filename to resolve.
171 * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores.
172 *
173 * Returns an empty string if not found.
174 */
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100175extern std::string getInputDeviceConfigurationFilePathByName(
176 const std::string& name, InputDeviceConfigurationFileType type);
Jeff Brown5912f952013-07-01 19:10:31 -0700177
Prabir Pradhancae4b3a2019-02-05 18:51:32 -0800178enum ReservedInputDeviceId : int32_t {
179 // Device id of a special "virtual" keyboard that is always present.
180 VIRTUAL_KEYBOARD_ID = -1,
181 // Device id of the "built-in" keyboard if there is one.
182 BUILT_IN_KEYBOARD_ID = 0,
Nathaniel R. Lewisa7b82e12020-02-12 15:40:45 -0800183 // First device id available for dynamic devices
184 END_RESERVED_ID = 1,
Prabir Pradhancae4b3a2019-02-05 18:51:32 -0800185};
186
Jeff Brown5912f952013-07-01 19:10:31 -0700187} // namespace android
188
189#endif // _LIBINPUT_INPUT_DEVICE_H