| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 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 _LIBINPUT_INPUT_DEVICE_H | 
 | 18 | #define _LIBINPUT_INPUT_DEVICE_H | 
 | 19 |  | 
 | 20 | #include <input/Input.h> | 
 | 21 | #include <input/KeyCharacterMap.h> | 
 | 22 |  | 
 | 23 | namespace android { | 
 | 24 |  | 
 | 25 | /* | 
 | 26 |  * Identifies a device. | 
 | 27 |  */ | 
 | 28 | struct 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; | 
| RoboErik | ec2a15a | 2013-12-19 11:54:29 -0800 | [diff] [blame] | 49 |  | 
 | 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 Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 54 | }; | 
 | 55 |  | 
 | 56 | /* | 
 | 57 |  * Describes the characteristics and capabilities of an input device. | 
 | 58 |  */ | 
 | 59 | class InputDeviceInfo { | 
 | 60 | public: | 
 | 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 Wright | 0415d63 | 2013-07-17 13:23:26 -0700 | [diff] [blame] | 75 |     void initialize(int32_t id, int32_t generation, int32_t controllerNumber, | 
| Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 76 |             const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal, | 
 | 77 |             bool hasMic); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 78 |  | 
 | 79 |     inline int32_t getId() const { return mId; } | 
| Michael Wright | 0415d63 | 2013-07-17 13:23:26 -0700 | [diff] [blame] | 80 |     inline int32_t getControllerNumber() const { return mControllerNumber; } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 81 |     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 Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 88 |     inline bool hasMic() const { return mHasMic; } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 89 |     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 Wright | 931fd6d | 2013-07-10 18:05:15 -0700 | [diff] [blame] | 112 |     inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; } | 
 | 113 |     inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; } | 
 | 114 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 115 |     inline const Vector<MotionRange>& getMotionRanges() const { | 
 | 116 |         return mMotionRanges; | 
 | 117 |     } | 
 | 118 |  | 
 | 119 | private: | 
 | 120 |     int32_t mId; | 
 | 121 |     int32_t mGeneration; | 
| Michael Wright | 0415d63 | 2013-07-17 13:23:26 -0700 | [diff] [blame] | 122 |     int32_t mControllerNumber; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 123 |     InputDeviceIdentifier mIdentifier; | 
 | 124 |     String8 mAlias; | 
 | 125 |     bool mIsExternal; | 
| Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 126 |     bool mHasMic; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 127 |     uint32_t mSources; | 
 | 128 |     int32_t mKeyboardType; | 
 | 129 |     sp<KeyCharacterMap> mKeyCharacterMap; | 
 | 130 |     bool mHasVibrator; | 
| Michael Wright | 931fd6d | 2013-07-10 18:05:15 -0700 | [diff] [blame] | 131 |     bool mHasButtonUnderPad; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 132 |  | 
 | 133 |     Vector<MotionRange> mMotionRanges; | 
 | 134 | }; | 
 | 135 |  | 
 | 136 | /* Types of input device configuration files. */ | 
 | 137 | enum 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 |  */ | 
 | 152 | extern 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 |  */ | 
 | 165 | extern String8 getInputDeviceConfigurationFilePathByName( | 
 | 166 |         const String8& name, InputDeviceConfigurationFileType type); | 
 | 167 |  | 
 | 168 | } // namespace android | 
 | 169 |  | 
 | 170 | #endif // _LIBINPUT_INPUT_DEVICE_H |