blob: 38203afac1495afc827698b18b77af80926d5c10 [file] [log] [blame]
Jeff Brown9f25b7f2012-04-10 14:30:49 -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 _ANDROIDFW_INPUT_DEVICE_H
18#define _ANDROIDFW_INPUT_DEVICE_H
19
20#include <androidfw/Input.h>
21#include <androidfw/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;
49};
50
51/*
52 * Describes the characteristics and capabilities of an input device.
53 */
54class InputDeviceInfo {
55public:
56 InputDeviceInfo();
57 InputDeviceInfo(const InputDeviceInfo& other);
58 ~InputDeviceInfo();
59
60 struct MotionRange {
61 int32_t axis;
62 uint32_t source;
63 float min;
64 float max;
65 float flat;
66 float fuzz;
67 };
68
Jeff Brownaf9e8d32012-04-12 17:32:48 -070069 void initialize(int32_t id, int32_t generation,
70 const String8& name, const String8& descriptor);
Jeff Brown9f25b7f2012-04-10 14:30:49 -070071
72 inline int32_t getId() const { return mId; }
Jeff Brownaf9e8d32012-04-12 17:32:48 -070073 inline int32_t getGeneration() const { return mGeneration; }
Jeff Brown9f25b7f2012-04-10 14:30:49 -070074 inline const String8 getName() const { return mName; }
75 inline const String8 getDescriptor() const { return mDescriptor; }
76 inline uint32_t getSources() const { return mSources; }
77
78 const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
79
80 void addSource(uint32_t source);
81 void addMotionRange(int32_t axis, uint32_t source,
82 float min, float max, float flat, float fuzz);
83 void addMotionRange(const MotionRange& range);
84
85 inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
86 inline int32_t getKeyboardType() const { return mKeyboardType; }
87
88 inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) {
89 mKeyCharacterMap = value;
90 }
91
92 inline sp<KeyCharacterMap> getKeyCharacterMap() const {
93 return mKeyCharacterMap;
94 }
95
Jeff Browna47425a2012-04-13 04:09:27 -070096 inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; }
97 inline bool hasVibrator() const { return mHasVibrator; }
98
Jeff Brown9f25b7f2012-04-10 14:30:49 -070099 inline const Vector<MotionRange>& getMotionRanges() const {
100 return mMotionRanges;
101 }
102
103private:
104 int32_t mId;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700105 int32_t mGeneration;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700106 String8 mName;
107 String8 mDescriptor;
108 uint32_t mSources;
109 int32_t mKeyboardType;
110 sp<KeyCharacterMap> mKeyCharacterMap;
Jeff Browna47425a2012-04-13 04:09:27 -0700111 bool mHasVibrator;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700112
113 Vector<MotionRange> mMotionRanges;
114};
115
116/* Types of input device configuration files. */
117enum InputDeviceConfigurationFileType {
118 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0, /* .idc file */
119 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1, /* .kl file */
120 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */
121};
122
123/*
124 * Gets the path of an input device configuration file, if one is available.
125 * Considers both system provided and user installed configuration files.
126 *
127 * The device identifier is used to construct several default configuration file
128 * names to try based on the device name, vendor, product, and version.
129 *
130 * Returns an empty string if not found.
131 */
132extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier(
133 const InputDeviceIdentifier& deviceIdentifier,
134 InputDeviceConfigurationFileType type);
135
136/*
137 * Gets the path of an input device configuration file, if one is available.
138 * Considers both system provided and user installed configuration files.
139 *
140 * The name is case-sensitive and is used to construct the filename to resolve.
141 * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores.
142 *
143 * Returns an empty string if not found.
144 */
145extern String8 getInputDeviceConfigurationFilePathByName(
146 const String8& name, InputDeviceConfigurationFileType type);
147
148} // namespace android
149
150#endif // _ANDROIDFW_INPUT_DEVICE_H