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; 49 }; 50 51 /* 52 * Describes the characteristics and capabilities of an input device. 53 */ 54 class InputDeviceInfo { 55 public: 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 float resolution; 68 }; 69 70 void initialize(int32_t id, int32_t generation, int32_t controllerNumber, 71 const InputDeviceIdentifier& identifier, const String8& alias, bool isExternal); 72 73 inline int32_t getId() const { return mId; } 74 inline int32_t getControllerNumber() const { return mControllerNumber; } 75 inline int32_t getGeneration() const { return mGeneration; } 76 inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; } 77 inline const String8& getAlias() const { return mAlias; } 78 inline const String8& getDisplayName() const { 79 return mAlias.isEmpty() ? mIdentifier.name : mAlias; 80 } 81 inline bool isExternal() const { return mIsExternal; } 82 inline uint32_t getSources() const { return mSources; } 83 84 const MotionRange* getMotionRange(int32_t axis, uint32_t source) const; 85 86 void addSource(uint32_t source); 87 void addMotionRange(int32_t axis, uint32_t source, 88 float min, float max, float flat, float fuzz, float resolution); 89 void addMotionRange(const MotionRange& range); 90 91 inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; } 92 inline int32_t getKeyboardType() const { return mKeyboardType; } 93 94 inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) { 95 mKeyCharacterMap = value; 96 } 97 98 inline sp<KeyCharacterMap> getKeyCharacterMap() const { 99 return mKeyCharacterMap; 100 } 101 102 inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; } 103 inline bool hasVibrator() const { return mHasVibrator; } 104 105 inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; } 106 inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; } 107 108 inline const Vector<MotionRange>& getMotionRanges() const { 109 return mMotionRanges; 110 } 111 112 private: 113 int32_t mId; 114 int32_t mGeneration; 115 int32_t mControllerNumber; 116 InputDeviceIdentifier mIdentifier; 117 String8 mAlias; 118 bool mIsExternal; 119 uint32_t mSources; 120 int32_t mKeyboardType; 121 sp<KeyCharacterMap> mKeyCharacterMap; 122 bool mHasVibrator; 123 bool mHasButtonUnderPad; 124 125 Vector<MotionRange> mMotionRanges; 126 }; 127 128 /* Types of input device configuration files. */ 129 enum InputDeviceConfigurationFileType { 130 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0, /* .idc file */ 131 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1, /* .kl file */ 132 INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */ 133 }; 134 135 /* 136 * Gets the path of an input device configuration file, if one is available. 137 * Considers both system provided and user installed configuration files. 138 * 139 * The device identifier is used to construct several default configuration file 140 * names to try based on the device name, vendor, product, and version. 141 * 142 * Returns an empty string if not found. 143 */ 144 extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier( 145 const InputDeviceIdentifier& deviceIdentifier, 146 InputDeviceConfigurationFileType type); 147 148 /* 149 * Gets the path of an input device configuration file, if one is available. 150 * Considers both system provided and user installed configuration files. 151 * 152 * The name is case-sensitive and is used to construct the filename to resolve. 153 * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores. 154 * 155 * Returns an empty string if not found. 156 */ 157 extern String8 getInputDeviceConfigurationFilePathByName( 158 const String8& name, InputDeviceConfigurationFileType type); 159 160 } // namespace android 161 162 #endif // _LIBINPUT_INPUT_DEVICE_H 163