blob: 1ea69d352d18d84ccb1b392b50532dac34ff8dc2 [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.
34 String8 name;
35 String8 location;
36 String8 uniqueId;
37 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.
48 String8 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,
Tim Kilbourn063ff532015-04-08 10:26:18 -070076 const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal,
77 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; }
83 inline const String8& getAlias() const { return mAlias; }
84 inline const String8& getDisplayName() const {
85 return mAlias.isEmpty() ? mIdentifier.name : mAlias;
86 }
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;
124 String8 mAlias;
125 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 */
152extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier(
153 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 */
165extern String8 getInputDeviceConfigurationFilePathByName(
166 const String8& name, InputDeviceConfigurationFileType type);
167
168} // namespace android
169
170#endif // _LIBINPUT_INPUT_DEVICE_H