InputDevice.h revision 9f25b7fdf216c9ef0bd2322cd223eeaf0d60f77f
1/*
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
69    void initialize(int32_t id, const String8& name, const String8& descriptor);
70
71    inline int32_t getId() const { return mId; }
72    inline const String8 getName() const { return mName; }
73    inline const String8 getDescriptor() const { return mDescriptor; }
74    inline uint32_t getSources() const { return mSources; }
75
76    const MotionRange* getMotionRange(int32_t axis, uint32_t source) const;
77
78    void addSource(uint32_t source);
79    void addMotionRange(int32_t axis, uint32_t source,
80            float min, float max, float flat, float fuzz);
81    void addMotionRange(const MotionRange& range);
82
83    inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
84    inline int32_t getKeyboardType() const { return mKeyboardType; }
85
86    inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) {
87        mKeyCharacterMap = value;
88    }
89
90    inline sp<KeyCharacterMap> getKeyCharacterMap() const {
91        return mKeyCharacterMap;
92    }
93
94    inline const Vector<MotionRange>& getMotionRanges() const {
95        return mMotionRanges;
96    }
97
98private:
99    int32_t mId;
100    String8 mName;
101    String8 mDescriptor;
102    uint32_t mSources;
103    int32_t mKeyboardType;
104    sp<KeyCharacterMap> mKeyCharacterMap;
105
106    Vector<MotionRange> mMotionRanges;
107};
108
109/* Types of input device configuration files. */
110enum InputDeviceConfigurationFileType {
111    INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0,     /* .idc file */
112    INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1,        /* .kl file */
113    INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */
114};
115
116/*
117 * Gets the path of an input device configuration file, if one is available.
118 * Considers both system provided and user installed configuration files.
119 *
120 * The device identifier is used to construct several default configuration file
121 * names to try based on the device name, vendor, product, and version.
122 *
123 * Returns an empty string if not found.
124 */
125extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier(
126        const InputDeviceIdentifier& deviceIdentifier,
127        InputDeviceConfigurationFileType type);
128
129/*
130 * Gets the path of an input device configuration file, if one is available.
131 * Considers both system provided and user installed configuration files.
132 *
133 * The name is case-sensitive and is used to construct the filename to resolve.
134 * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores.
135 *
136 * Returns an empty string if not found.
137 */
138extern String8 getInputDeviceConfigurationFilePathByName(
139        const String8& name, InputDeviceConfigurationFileType type);
140
141} // namespace android
142
143#endif // _ANDROIDFW_INPUT_DEVICE_H
144