blob: 34d164c280e9fdcad2a9c345255e8b69767fb7ad [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;
Jeff Brown5912f952013-07-01 19:10:31 -070054};
55
56/*
57 * Describes the characteristics and capabilities of an input device.
58 */
59class InputDeviceInfo {
60public:
61 InputDeviceInfo();
62 InputDeviceInfo(const InputDeviceInfo& other);
63 ~InputDeviceInfo();
64
65 struct MotionRange {
66 int32_t axis;
67 uint32_t source;
68 float min;
69 float max;
70 float flat;
71 float fuzz;
72 float resolution;
73 };
74
Michael Wright0415d632013-07-17 13:23:26 -070075 void initialize(int32_t id, int32_t generation, int32_t controllerNumber,
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010076 const InputDeviceIdentifier& identifier, const std::string& alias, bool isExternal,
Tim Kilbourn063ff532015-04-08 10:26:18 -070077 bool hasMic);
Jeff Brown5912f952013-07-01 19:10:31 -070078
79 inline int32_t getId() const { return mId; }
Michael Wright0415d632013-07-17 13:23:26 -070080 inline int32_t getControllerNumber() const { return mControllerNumber; }
Jeff Brown5912f952013-07-01 19:10:31 -070081 inline int32_t getGeneration() const { return mGeneration; }
82 inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; }
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010083 inline const std::string& getAlias() const { return mAlias; }
84 inline const std::string& getDisplayName() const {
85 return mAlias.empty() ? mIdentifier.name : mAlias;
Jeff Brown5912f952013-07-01 19:10:31 -070086 }
87 inline bool isExternal() const { return mIsExternal; }
Tim Kilbourn063ff532015-04-08 10:26:18 -070088 inline bool hasMic() const { return mHasMic; }
Jeff Brown5912f952013-07-01 19:10:31 -070089 inline uint32_t getSources() const { return mSources; }
90
91 const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
92
93 void addSource(uint32_t source);
94 void addMotionRange(int32_t axis, uint32_t source,
95 float min, float max, float flat, float fuzz, float resolution);
96 void addMotionRange(const MotionRange& range);
97
98 inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
99 inline int32_t getKeyboardType() const { return mKeyboardType; }
100
101 inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) {
102 mKeyCharacterMap = value;
103 }
104
105 inline sp<KeyCharacterMap> getKeyCharacterMap() const {
106 return mKeyCharacterMap;
107 }
108
109 inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; }
110 inline bool hasVibrator() const { return mHasVibrator; }
111
Michael Wright931fd6d2013-07-10 18:05:15 -0700112 inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; }
113 inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; }
114
Jeff Brown5912f952013-07-01 19:10:31 -0700115 inline const Vector<MotionRange>& getMotionRanges() const {
116 return mMotionRanges;
117 }
118
119private:
120 int32_t mId;
121 int32_t mGeneration;
Michael Wright0415d632013-07-17 13:23:26 -0700122 int32_t mControllerNumber;
Jeff Brown5912f952013-07-01 19:10:31 -0700123 InputDeviceIdentifier mIdentifier;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100124 std::string mAlias;
Jeff Brown5912f952013-07-01 19:10:31 -0700125 bool mIsExternal;
Tim Kilbourn063ff532015-04-08 10:26:18 -0700126 bool mHasMic;
Jeff Brown5912f952013-07-01 19:10:31 -0700127 uint32_t mSources;
128 int32_t mKeyboardType;
129 sp<KeyCharacterMap> mKeyCharacterMap;
130 bool mHasVibrator;
Michael Wright931fd6d2013-07-10 18:05:15 -0700131 bool mHasButtonUnderPad;
Jeff Brown5912f952013-07-01 19:10:31 -0700132
133 Vector<MotionRange> mMotionRanges;
134};
135
136/* Types of input device configuration files. */
137enum InputDeviceConfigurationFileType {
138 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0, /* .idc file */
139 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1, /* .kl file */
140 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */
141};
142
143/*
144 * Gets the path of an input device configuration file, if one is available.
145 * Considers both system provided and user installed configuration files.
146 *
147 * The device identifier is used to construct several default configuration file
148 * names to try based on the device name, vendor, product, and version.
149 *
150 * Returns an empty string if not found.
151 */
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100152extern std::string getInputDeviceConfigurationFilePathByDeviceIdentifier(
Jeff Brown5912f952013-07-01 19:10:31 -0700153 const InputDeviceIdentifier& deviceIdentifier,
154 InputDeviceConfigurationFileType type);
155
156/*
157 * Gets the path of an input device configuration file, if one is available.
158 * Considers both system provided and user installed configuration files.
159 *
160 * The name is case-sensitive and is used to construct the filename to resolve.
161 * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores.
162 *
163 * Returns an empty string if not found.
164 */
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100165extern std::string getInputDeviceConfigurationFilePathByName(
166 const std::string& name, InputDeviceConfigurationFileType type);
Jeff Brown5912f952013-07-01 19:10:31 -0700167
168} // namespace android
169
170#endif // _LIBINPUT_INPUT_DEVICE_H