blob: 48ac88d50e59970101953e37f66ae70222e0dd4c [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>
22
23namespace android {
24
25/*
26 * Identifies a device.
27 */
28struct InputDeviceIdentifier {
29 inline InputDeviceIdentifier() :
30 bus(0), vendor(0), product(0), version(0) {
31 }
32
33 // Information provided by the kernel.
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010034 std::string name;
35 std::string location;
36 std::string uniqueId;
Jeff Brown5912f952013-07-01 19:10:31 -070037 uint16_t bus;
38 uint16_t vendor;
39 uint16_t product;
40 uint16_t version;
41
42 // A composite input device descriptor string that uniquely identifies the device
43 // even across reboots or reconnections. The value of this field is used by
44 // upper layers of the input system to associate settings with individual devices.
45 // It is hashed from whatever kernel provided information is available.
46 // Ideally, the way this value is computed should not change between Android releases
47 // because that would invalidate persistent settings that rely on it.
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010048 std::string descriptor;
RoboErikec2a15a2013-12-19 11:54:29 -080049
50 // A value added to uniquely identify a device in the absence of a unique id. This
51 // is intended to be a minimum way to distinguish from other active devices and may
52 // reuse values that are not associated with an input anymore.
53 uint16_t nonce;
Siarhei Vishniakoub45635c2019-02-20 19:22:09 -060054
55 /**
56 * Return InputDeviceIdentifier.name that has been adjusted as follows:
57 * - all characters besides alphanumerics, dash,
58 * and underscore have been replaced with underscores.
59 * This helps in situations where a file that matches the device name is needed,
60 * while conforming to the filename limitations.
61 */
62 std::string getCanonicalName() const;
Jeff Brown5912f952013-07-01 19:10:31 -070063};
64
65/*
66 * Describes the characteristics and capabilities of an input device.
67 */
68class InputDeviceInfo {
69public:
70 InputDeviceInfo();
71 InputDeviceInfo(const InputDeviceInfo& other);
72 ~InputDeviceInfo();
73
74 struct MotionRange {
75 int32_t axis;
76 uint32_t source;
77 float min;
78 float max;
79 float flat;
80 float fuzz;
81 float resolution;
82 };
83
Michael Wright0415d632013-07-17 13:23:26 -070084 void initialize(int32_t id, int32_t generation, int32_t controllerNumber,
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010085 const InputDeviceIdentifier& identifier, const std::string& alias, bool isExternal,
Tim Kilbourn063ff532015-04-08 10:26:18 -070086 bool hasMic);
Jeff Brown5912f952013-07-01 19:10:31 -070087
88 inline int32_t getId() const { return mId; }
Michael Wright0415d632013-07-17 13:23:26 -070089 inline int32_t getControllerNumber() const { return mControllerNumber; }
Jeff Brown5912f952013-07-01 19:10:31 -070090 inline int32_t getGeneration() const { return mGeneration; }
91 inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; }
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010092 inline const std::string& getAlias() const { return mAlias; }
93 inline const std::string& getDisplayName() const {
94 return mAlias.empty() ? mIdentifier.name : mAlias;
Jeff Brown5912f952013-07-01 19:10:31 -070095 }
96 inline bool isExternal() const { return mIsExternal; }
Tim Kilbourn063ff532015-04-08 10:26:18 -070097 inline bool hasMic() const { return mHasMic; }
Jeff Brown5912f952013-07-01 19:10:31 -070098 inline uint32_t getSources() const { return mSources; }
99
100 const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
101
102 void addSource(uint32_t source);
103 void addMotionRange(int32_t axis, uint32_t source,
104 float min, float max, float flat, float fuzz, float resolution);
105 void addMotionRange(const MotionRange& range);
106
107 inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
108 inline int32_t getKeyboardType() const { return mKeyboardType; }
109
110 inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) {
111 mKeyCharacterMap = value;
112 }
113
114 inline sp<KeyCharacterMap> getKeyCharacterMap() const {
115 return mKeyCharacterMap;
116 }
117
118 inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; }
119 inline bool hasVibrator() const { return mHasVibrator; }
120
Michael Wright931fd6d2013-07-10 18:05:15 -0700121 inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; }
122 inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; }
123
Jeff Brown5912f952013-07-01 19:10:31 -0700124 inline const Vector<MotionRange>& getMotionRanges() const {
125 return mMotionRanges;
126 }
127
128private:
129 int32_t mId;
130 int32_t mGeneration;
Michael Wright0415d632013-07-17 13:23:26 -0700131 int32_t mControllerNumber;
Jeff Brown5912f952013-07-01 19:10:31 -0700132 InputDeviceIdentifier mIdentifier;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100133 std::string mAlias;
Jeff Brown5912f952013-07-01 19:10:31 -0700134 bool mIsExternal;
Tim Kilbourn063ff532015-04-08 10:26:18 -0700135 bool mHasMic;
Jeff Brown5912f952013-07-01 19:10:31 -0700136 uint32_t mSources;
137 int32_t mKeyboardType;
138 sp<KeyCharacterMap> mKeyCharacterMap;
139 bool mHasVibrator;
Michael Wright931fd6d2013-07-10 18:05:15 -0700140 bool mHasButtonUnderPad;
Jeff Brown5912f952013-07-01 19:10:31 -0700141
142 Vector<MotionRange> mMotionRanges;
143};
144
145/* Types of input device configuration files. */
146enum InputDeviceConfigurationFileType {
147 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0, /* .idc file */
148 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1, /* .kl file */
149 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */
150};
151
152/*
153 * Gets the path of an input device configuration file, if one is available.
154 * Considers both system provided and user installed configuration files.
155 *
156 * The device identifier is used to construct several default configuration file
157 * names to try based on the device name, vendor, product, and version.
158 *
159 * Returns an empty string if not found.
160 */
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100161extern std::string getInputDeviceConfigurationFilePathByDeviceIdentifier(
Jeff Brown5912f952013-07-01 19:10:31 -0700162 const InputDeviceIdentifier& deviceIdentifier,
163 InputDeviceConfigurationFileType type);
164
165/*
166 * Gets the path of an input device configuration file, if one is available.
167 * Considers both system provided and user installed configuration files.
168 *
169 * The name is case-sensitive and is used to construct the filename to resolve.
170 * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores.
171 *
172 * Returns an empty string if not found.
173 */
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100174extern std::string getInputDeviceConfigurationFilePathByName(
175 const std::string& name, InputDeviceConfigurationFileType type);
Jeff Brown5912f952013-07-01 19:10:31 -0700176
Prabir Pradhancae4b3a2019-02-05 18:51:32 -0800177enum ReservedInputDeviceId : int32_t {
178 // Device id of a special "virtual" keyboard that is always present.
179 VIRTUAL_KEYBOARD_ID = -1,
180 // Device id of the "built-in" keyboard if there is one.
181 BUILT_IN_KEYBOARD_ID = 0,
182};
183
Jeff Brown5912f952013-07-01 19:10:31 -0700184} // namespace android
185
186#endif // _LIBINPUT_INPUT_DEVICE_H