| 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> | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 22 | #include <vector> | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 23 |  | 
|  | 24 | namespace android { | 
|  | 25 |  | 
|  | 26 | /* | 
|  | 27 | * Identifies a device. | 
|  | 28 | */ | 
|  | 29 | struct InputDeviceIdentifier { | 
|  | 30 | inline InputDeviceIdentifier() : | 
|  | 31 | bus(0), vendor(0), product(0), version(0) { | 
|  | 32 | } | 
|  | 33 |  | 
|  | 34 | // Information provided by the kernel. | 
| Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 35 | std::string name; | 
|  | 36 | std::string location; | 
|  | 37 | std::string uniqueId; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 38 | uint16_t bus; | 
|  | 39 | uint16_t vendor; | 
|  | 40 | uint16_t product; | 
|  | 41 | uint16_t version; | 
|  | 42 |  | 
|  | 43 | // A composite input device descriptor string that uniquely identifies the device | 
|  | 44 | // even across reboots or reconnections.  The value of this field is used by | 
|  | 45 | // upper layers of the input system to associate settings with individual devices. | 
|  | 46 | // It is hashed from whatever kernel provided information is available. | 
|  | 47 | // Ideally, the way this value is computed should not change between Android releases | 
|  | 48 | // because that would invalidate persistent settings that rely on it. | 
| Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 49 | std::string descriptor; | 
| RoboErik | ec2a15a | 2013-12-19 11:54:29 -0800 | [diff] [blame] | 50 |  | 
|  | 51 | // A value added to uniquely identify a device in the absence of a unique id. This | 
|  | 52 | // is intended to be a minimum way to distinguish from other active devices and may | 
|  | 53 | // reuse values that are not associated with an input anymore. | 
|  | 54 | uint16_t nonce; | 
| Siarhei Vishniakou | b45635c | 2019-02-20 19:22:09 -0600 | [diff] [blame] | 55 |  | 
|  | 56 | /** | 
|  | 57 | * Return InputDeviceIdentifier.name that has been adjusted as follows: | 
|  | 58 | *     - all characters besides alphanumerics, dash, | 
|  | 59 | *       and underscore have been replaced with underscores. | 
|  | 60 | * This helps in situations where a file that matches the device name is needed, | 
|  | 61 | * while conforming to the filename limitations. | 
|  | 62 | */ | 
|  | 63 | std::string getCanonicalName() const; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 64 | }; | 
|  | 65 |  | 
|  | 66 | /* | 
|  | 67 | * Describes the characteristics and capabilities of an input device. | 
|  | 68 | */ | 
|  | 69 | class InputDeviceInfo { | 
|  | 70 | public: | 
|  | 71 | InputDeviceInfo(); | 
|  | 72 | InputDeviceInfo(const InputDeviceInfo& other); | 
|  | 73 | ~InputDeviceInfo(); | 
|  | 74 |  | 
|  | 75 | struct MotionRange { | 
|  | 76 | int32_t axis; | 
|  | 77 | uint32_t source; | 
|  | 78 | float min; | 
|  | 79 | float max; | 
|  | 80 | float flat; | 
|  | 81 | float fuzz; | 
|  | 82 | float resolution; | 
|  | 83 | }; | 
|  | 84 |  | 
| Michael Wright | 0415d63 | 2013-07-17 13:23:26 -0700 | [diff] [blame] | 85 | void initialize(int32_t id, int32_t generation, int32_t controllerNumber, | 
| Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 86 | const InputDeviceIdentifier& identifier, const std::string& alias, bool isExternal, | 
| Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 87 | bool hasMic); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 88 |  | 
|  | 89 | inline int32_t getId() const { return mId; } | 
| Michael Wright | 0415d63 | 2013-07-17 13:23:26 -0700 | [diff] [blame] | 90 | inline int32_t getControllerNumber() const { return mControllerNumber; } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 91 | inline int32_t getGeneration() const { return mGeneration; } | 
|  | 92 | inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; } | 
| Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 93 | inline const std::string& getAlias() const { return mAlias; } | 
|  | 94 | inline const std::string& getDisplayName() const { | 
|  | 95 | return mAlias.empty() ? mIdentifier.name : mAlias; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 96 | } | 
|  | 97 | inline bool isExternal() const { return mIsExternal; } | 
| Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 98 | inline bool hasMic() const { return mHasMic; } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 99 | inline uint32_t getSources() const { return mSources; } | 
|  | 100 |  | 
|  | 101 | const MotionRange* getMotionRange(int32_t axis, uint32_t source) const; | 
|  | 102 |  | 
|  | 103 | void addSource(uint32_t source); | 
|  | 104 | void addMotionRange(int32_t axis, uint32_t source, | 
|  | 105 | float min, float max, float flat, float fuzz, float resolution); | 
|  | 106 | void addMotionRange(const MotionRange& range); | 
|  | 107 |  | 
|  | 108 | inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; } | 
|  | 109 | inline int32_t getKeyboardType() const { return mKeyboardType; } | 
|  | 110 |  | 
|  | 111 | inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) { | 
|  | 112 | mKeyCharacterMap = value; | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | inline sp<KeyCharacterMap> getKeyCharacterMap() const { | 
|  | 116 | return mKeyCharacterMap; | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; } | 
|  | 120 | inline bool hasVibrator() const { return mHasVibrator; } | 
|  | 121 |  | 
| Michael Wright | 931fd6d | 2013-07-10 18:05:15 -0700 | [diff] [blame] | 122 | inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; } | 
|  | 123 | inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; } | 
|  | 124 |  | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 125 | inline const std::vector<MotionRange>& getMotionRanges() const { | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 126 | return mMotionRanges; | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | private: | 
|  | 130 | int32_t mId; | 
|  | 131 | int32_t mGeneration; | 
| Michael Wright | 0415d63 | 2013-07-17 13:23:26 -0700 | [diff] [blame] | 132 | int32_t mControllerNumber; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 133 | InputDeviceIdentifier mIdentifier; | 
| Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 134 | std::string mAlias; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 135 | bool mIsExternal; | 
| Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 136 | bool mHasMic; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 137 | uint32_t mSources; | 
|  | 138 | int32_t mKeyboardType; | 
|  | 139 | sp<KeyCharacterMap> mKeyCharacterMap; | 
|  | 140 | bool mHasVibrator; | 
| Michael Wright | 931fd6d | 2013-07-10 18:05:15 -0700 | [diff] [blame] | 141 | bool mHasButtonUnderPad; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 142 |  | 
| Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 143 | std::vector<MotionRange> mMotionRanges; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 144 | }; | 
|  | 145 |  | 
|  | 146 | /* Types of input device configuration files. */ | 
|  | 147 | enum InputDeviceConfigurationFileType { | 
|  | 148 | INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0,     /* .idc file */ | 
|  | 149 | INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1,        /* .kl file */ | 
|  | 150 | INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */ | 
|  | 151 | }; | 
|  | 152 |  | 
|  | 153 | /* | 
|  | 154 | * Gets the path of an input device configuration file, if one is available. | 
|  | 155 | * Considers both system provided and user installed configuration files. | 
|  | 156 | * | 
|  | 157 | * The device identifier is used to construct several default configuration file | 
|  | 158 | * names to try based on the device name, vendor, product, and version. | 
|  | 159 | * | 
|  | 160 | * Returns an empty string if not found. | 
|  | 161 | */ | 
| Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 162 | extern std::string getInputDeviceConfigurationFilePathByDeviceIdentifier( | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 163 | const InputDeviceIdentifier& deviceIdentifier, | 
|  | 164 | InputDeviceConfigurationFileType type); | 
|  | 165 |  | 
|  | 166 | /* | 
|  | 167 | * Gets the path of an input device configuration file, if one is available. | 
|  | 168 | * Considers both system provided and user installed configuration files. | 
|  | 169 | * | 
|  | 170 | * The name is case-sensitive and is used to construct the filename to resolve. | 
|  | 171 | * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores. | 
|  | 172 | * | 
|  | 173 | * Returns an empty string if not found. | 
|  | 174 | */ | 
| Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 175 | extern std::string getInputDeviceConfigurationFilePathByName( | 
|  | 176 | const std::string& name, InputDeviceConfigurationFileType type); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 177 |  | 
| Prabir Pradhan | cae4b3a | 2019-02-05 18:51:32 -0800 | [diff] [blame] | 178 | enum ReservedInputDeviceId : int32_t { | 
|  | 179 | // Device id of a special "virtual" keyboard that is always present. | 
|  | 180 | VIRTUAL_KEYBOARD_ID = -1, | 
|  | 181 | // Device id of the "built-in" keyboard if there is one. | 
|  | 182 | BUILT_IN_KEYBOARD_ID = 0, | 
|  | 183 | }; | 
|  | 184 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 185 | } // namespace android | 
|  | 186 |  | 
|  | 187 | #endif // _LIBINPUT_INPUT_DEVICE_H |