Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2012 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #ifndef _ANDROIDFW_INPUT_DEVICE_H |
michael@0 | 18 | #define _ANDROIDFW_INPUT_DEVICE_H |
michael@0 | 19 | |
michael@0 | 20 | #include "Input.h" |
michael@0 | 21 | #include "KeyCharacterMap.h" |
michael@0 | 22 | |
michael@0 | 23 | namespace android { |
michael@0 | 24 | |
michael@0 | 25 | /* |
michael@0 | 26 | * Identifies a device. |
michael@0 | 27 | */ |
michael@0 | 28 | struct InputDeviceIdentifier { |
michael@0 | 29 | inline InputDeviceIdentifier() : |
michael@0 | 30 | bus(0), vendor(0), product(0), version(0) { |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | // Information provided by the kernel. |
michael@0 | 34 | String8 name; |
michael@0 | 35 | String8 location; |
michael@0 | 36 | String8 uniqueId; |
michael@0 | 37 | uint16_t bus; |
michael@0 | 38 | uint16_t vendor; |
michael@0 | 39 | uint16_t product; |
michael@0 | 40 | uint16_t version; |
michael@0 | 41 | |
michael@0 | 42 | // A composite input device descriptor string that uniquely identifies the device |
michael@0 | 43 | // even across reboots or reconnections. The value of this field is used by |
michael@0 | 44 | // upper layers of the input system to associate settings with individual devices. |
michael@0 | 45 | // It is hashed from whatever kernel provided information is available. |
michael@0 | 46 | // Ideally, the way this value is computed should not change between Android releases |
michael@0 | 47 | // because that would invalidate persistent settings that rely on it. |
michael@0 | 48 | String8 descriptor; |
michael@0 | 49 | }; |
michael@0 | 50 | |
michael@0 | 51 | /* |
michael@0 | 52 | * Describes the characteristics and capabilities of an input device. |
michael@0 | 53 | */ |
michael@0 | 54 | class InputDeviceInfo { |
michael@0 | 55 | public: |
michael@0 | 56 | InputDeviceInfo(); |
michael@0 | 57 | InputDeviceInfo(const InputDeviceInfo& other); |
michael@0 | 58 | ~InputDeviceInfo(); |
michael@0 | 59 | |
michael@0 | 60 | struct MotionRange { |
michael@0 | 61 | int32_t axis; |
michael@0 | 62 | uint32_t source; |
michael@0 | 63 | float min; |
michael@0 | 64 | float max; |
michael@0 | 65 | float flat; |
michael@0 | 66 | float fuzz; |
michael@0 | 67 | float resolution; |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | void initialize(int32_t id, int32_t generation, const InputDeviceIdentifier& identifier, |
michael@0 | 71 | const String8& alias, bool isExternal); |
michael@0 | 72 | |
michael@0 | 73 | inline int32_t getId() const { return mId; } |
michael@0 | 74 | inline int32_t getGeneration() const { return mGeneration; } |
michael@0 | 75 | inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; } |
michael@0 | 76 | inline const String8& getAlias() const { return mAlias; } |
michael@0 | 77 | inline const String8& getDisplayName() const { |
michael@0 | 78 | return mAlias.isEmpty() ? mIdentifier.name : mAlias; |
michael@0 | 79 | } |
michael@0 | 80 | inline bool isExternal() const { return mIsExternal; } |
michael@0 | 81 | inline uint32_t getSources() const { return mSources; } |
michael@0 | 82 | |
michael@0 | 83 | const MotionRange* getMotionRange(int32_t axis, uint32_t source) const; |
michael@0 | 84 | |
michael@0 | 85 | void addSource(uint32_t source); |
michael@0 | 86 | void addMotionRange(int32_t axis, uint32_t source, |
michael@0 | 87 | float min, float max, float flat, float fuzz, float resolution); |
michael@0 | 88 | void addMotionRange(const MotionRange& range); |
michael@0 | 89 | |
michael@0 | 90 | inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; } |
michael@0 | 91 | inline int32_t getKeyboardType() const { return mKeyboardType; } |
michael@0 | 92 | |
michael@0 | 93 | inline void setKeyCharacterMap(const sp<KeyCharacterMap>& value) { |
michael@0 | 94 | mKeyCharacterMap = value; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | inline sp<KeyCharacterMap> getKeyCharacterMap() const { |
michael@0 | 98 | return mKeyCharacterMap; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; } |
michael@0 | 102 | inline bool hasVibrator() const { return mHasVibrator; } |
michael@0 | 103 | |
michael@0 | 104 | inline const Vector<MotionRange>& getMotionRanges() const { |
michael@0 | 105 | return mMotionRanges; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | private: |
michael@0 | 109 | int32_t mId; |
michael@0 | 110 | int32_t mGeneration; |
michael@0 | 111 | InputDeviceIdentifier mIdentifier; |
michael@0 | 112 | String8 mAlias; |
michael@0 | 113 | bool mIsExternal; |
michael@0 | 114 | uint32_t mSources; |
michael@0 | 115 | int32_t mKeyboardType; |
michael@0 | 116 | sp<KeyCharacterMap> mKeyCharacterMap; |
michael@0 | 117 | bool mHasVibrator; |
michael@0 | 118 | |
michael@0 | 119 | Vector<MotionRange> mMotionRanges; |
michael@0 | 120 | }; |
michael@0 | 121 | |
michael@0 | 122 | /* Types of input device configuration files. */ |
michael@0 | 123 | enum InputDeviceConfigurationFileType { |
michael@0 | 124 | INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0, /* .idc file */ |
michael@0 | 125 | INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1, /* .kl file */ |
michael@0 | 126 | INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */ |
michael@0 | 127 | }; |
michael@0 | 128 | |
michael@0 | 129 | /* |
michael@0 | 130 | * Gets the path of an input device configuration file, if one is available. |
michael@0 | 131 | * Considers both system provided and user installed configuration files. |
michael@0 | 132 | * |
michael@0 | 133 | * The device identifier is used to construct several default configuration file |
michael@0 | 134 | * names to try based on the device name, vendor, product, and version. |
michael@0 | 135 | * |
michael@0 | 136 | * Returns an empty string if not found. |
michael@0 | 137 | */ |
michael@0 | 138 | extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier( |
michael@0 | 139 | const InputDeviceIdentifier& deviceIdentifier, |
michael@0 | 140 | InputDeviceConfigurationFileType type); |
michael@0 | 141 | |
michael@0 | 142 | /* |
michael@0 | 143 | * Gets the path of an input device configuration file, if one is available. |
michael@0 | 144 | * Considers both system provided and user installed configuration files. |
michael@0 | 145 | * |
michael@0 | 146 | * The name is case-sensitive and is used to construct the filename to resolve. |
michael@0 | 147 | * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores. |
michael@0 | 148 | * |
michael@0 | 149 | * Returns an empty string if not found. |
michael@0 | 150 | */ |
michael@0 | 151 | extern String8 getInputDeviceConfigurationFilePathByName( |
michael@0 | 152 | const String8& name, InputDeviceConfigurationFileType type); |
michael@0 | 153 | |
michael@0 | 154 | } // namespace android |
michael@0 | 155 | |
michael@0 | 156 | #endif // _ANDROIDFW_INPUT_DEVICE_H |