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 | |
Prabir Pradhan | c08b0db | 2022-09-10 00:57:15 +0000 | [diff] [blame] | 17 | #pragma once |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 18 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 19 | #include <android/sensor.h> |
Vaibhav Devmurari | 82b37d6 | 2022-09-12 13:36:48 +0000 | [diff] [blame] | 20 | #include <ftl/flags.h> |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 21 | #include <input/Input.h> |
| 22 | #include <input/KeyCharacterMap.h> |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 23 | #include <unordered_map> |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 24 | #include <vector> |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 25 | |
Sandro Meier | d3d4060 | 2022-10-19 16:18:26 +0000 | [diff] [blame^] | 26 | #include <android/os/IInputConstants.h> |
Vaibhav Devmurari | dd82b8e | 2022-08-16 15:34:01 +0000 | [diff] [blame] | 27 | #include "android/hardware/input/InputDeviceCountryCode.h" |
| 28 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 29 | namespace android { |
| 30 | |
| 31 | /* |
| 32 | * Identifies a device. |
| 33 | */ |
| 34 | struct InputDeviceIdentifier { |
| 35 | inline InputDeviceIdentifier() : |
| 36 | bus(0), vendor(0), product(0), version(0) { |
| 37 | } |
| 38 | |
| 39 | // Information provided by the kernel. |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 40 | std::string name; |
| 41 | std::string location; |
| 42 | std::string uniqueId; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 43 | uint16_t bus; |
| 44 | uint16_t vendor; |
| 45 | uint16_t product; |
| 46 | uint16_t version; |
| 47 | |
| 48 | // A composite input device descriptor string that uniquely identifies the device |
| 49 | // even across reboots or reconnections. The value of this field is used by |
| 50 | // upper layers of the input system to associate settings with individual devices. |
| 51 | // It is hashed from whatever kernel provided information is available. |
| 52 | // Ideally, the way this value is computed should not change between Android releases |
| 53 | // because that would invalidate persistent settings that rely on it. |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 54 | std::string descriptor; |
RoboErik | ec2a15a | 2013-12-19 11:54:29 -0800 | [diff] [blame] | 55 | |
| 56 | // A value added to uniquely identify a device in the absence of a unique id. This |
| 57 | // is intended to be a minimum way to distinguish from other active devices and may |
| 58 | // reuse values that are not associated with an input anymore. |
| 59 | uint16_t nonce; |
Siarhei Vishniakou | b45635c | 2019-02-20 19:22:09 -0600 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Return InputDeviceIdentifier.name that has been adjusted as follows: |
| 63 | * - all characters besides alphanumerics, dash, |
| 64 | * and underscore have been replaced with underscores. |
| 65 | * This helps in situations where a file that matches the device name is needed, |
| 66 | * while conforming to the filename limitations. |
| 67 | */ |
| 68 | std::string getCanonicalName() const; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 71 | /* Types of input device sensors. Keep sync with core/java/android/hardware/Sensor.java */ |
| 72 | enum class InputDeviceSensorType : int32_t { |
| 73 | ACCELEROMETER = ASENSOR_TYPE_ACCELEROMETER, |
| 74 | MAGNETIC_FIELD = ASENSOR_TYPE_MAGNETIC_FIELD, |
| 75 | ORIENTATION = 3, |
| 76 | GYROSCOPE = ASENSOR_TYPE_GYROSCOPE, |
| 77 | LIGHT = ASENSOR_TYPE_LIGHT, |
| 78 | PRESSURE = ASENSOR_TYPE_PRESSURE, |
| 79 | TEMPERATURE = 7, |
| 80 | PROXIMITY = ASENSOR_TYPE_PROXIMITY, |
| 81 | GRAVITY = ASENSOR_TYPE_GRAVITY, |
| 82 | LINEAR_ACCELERATION = ASENSOR_TYPE_LINEAR_ACCELERATION, |
| 83 | ROTATION_VECTOR = ASENSOR_TYPE_ROTATION_VECTOR, |
| 84 | RELATIVE_HUMIDITY = ASENSOR_TYPE_RELATIVE_HUMIDITY, |
| 85 | AMBIENT_TEMPERATURE = ASENSOR_TYPE_AMBIENT_TEMPERATURE, |
| 86 | MAGNETIC_FIELD_UNCALIBRATED = ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED, |
| 87 | GAME_ROTATION_VECTOR = ASENSOR_TYPE_GAME_ROTATION_VECTOR, |
| 88 | GYROSCOPE_UNCALIBRATED = ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED, |
| 89 | SIGNIFICANT_MOTION = ASENSOR_TYPE_SIGNIFICANT_MOTION, |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 90 | |
| 91 | ftl_first = ACCELEROMETER, |
| 92 | ftl_last = SIGNIFICANT_MOTION |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | enum class InputDeviceSensorAccuracy : int32_t { |
| 96 | ACCURACY_NONE = 0, |
| 97 | ACCURACY_LOW = 1, |
| 98 | ACCURACY_MEDIUM = 2, |
| 99 | ACCURACY_HIGH = 3, |
| 100 | }; |
| 101 | |
| 102 | enum class InputDeviceSensorReportingMode : int32_t { |
| 103 | CONTINUOUS = 0, |
| 104 | ON_CHANGE = 1, |
| 105 | ONE_SHOT = 2, |
| 106 | SPECIAL_TRIGGER = 3, |
| 107 | }; |
| 108 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 109 | enum class InputDeviceLightType : int32_t { |
Vaibhav Devmurari | 82b37d6 | 2022-09-12 13:36:48 +0000 | [diff] [blame] | 110 | INPUT = 0, |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 111 | PLAYER_ID = 1, |
Vaibhav Devmurari | 82b37d6 | 2022-09-12 13:36:48 +0000 | [diff] [blame] | 112 | KEYBOARD_BACKLIGHT = 2, |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 113 | |
Vaibhav Devmurari | 82b37d6 | 2022-09-12 13:36:48 +0000 | [diff] [blame] | 114 | ftl_last = KEYBOARD_BACKLIGHT |
| 115 | }; |
| 116 | |
| 117 | enum class InputDeviceLightCapability : uint32_t { |
| 118 | /** Capability to change brightness of the light */ |
| 119 | BRIGHTNESS = 0x00000001, |
| 120 | /** Capability to change color of the light */ |
| 121 | RGB = 0x00000002, |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 124 | struct InputDeviceSensorInfo { |
| 125 | explicit InputDeviceSensorInfo(std::string name, std::string vendor, int32_t version, |
| 126 | InputDeviceSensorType type, InputDeviceSensorAccuracy accuracy, |
| 127 | float maxRange, float resolution, float power, int32_t minDelay, |
| 128 | int32_t fifoReservedEventCount, int32_t fifoMaxEventCount, |
| 129 | std::string stringType, int32_t maxDelay, int32_t flags, |
| 130 | int32_t id) |
| 131 | : name(name), |
| 132 | vendor(vendor), |
| 133 | version(version), |
| 134 | type(type), |
| 135 | accuracy(accuracy), |
| 136 | maxRange(maxRange), |
| 137 | resolution(resolution), |
| 138 | power(power), |
| 139 | minDelay(minDelay), |
| 140 | fifoReservedEventCount(fifoReservedEventCount), |
| 141 | fifoMaxEventCount(fifoMaxEventCount), |
| 142 | stringType(stringType), |
| 143 | maxDelay(maxDelay), |
| 144 | flags(flags), |
| 145 | id(id) {} |
| 146 | // Name string of the sensor. |
| 147 | std::string name; |
| 148 | // Vendor string of this sensor. |
| 149 | std::string vendor; |
| 150 | // Version of the sensor's module. |
| 151 | int32_t version; |
| 152 | // Generic type of this sensor. |
| 153 | InputDeviceSensorType type; |
| 154 | // The current accuracy of sensor event. |
| 155 | InputDeviceSensorAccuracy accuracy; |
| 156 | // Maximum range of the sensor in the sensor's unit. |
| 157 | float maxRange; |
| 158 | // Resolution of the sensor in the sensor's unit. |
| 159 | float resolution; |
| 160 | // The power in mA used by this sensor while in use. |
| 161 | float power; |
| 162 | // The minimum delay allowed between two events in microsecond or zero if this sensor only |
| 163 | // returns a value when the data it's measuring changes. |
| 164 | int32_t minDelay; |
| 165 | // Number of events reserved for this sensor in the batch mode FIFO. |
| 166 | int32_t fifoReservedEventCount; |
| 167 | // Maximum number of events of this sensor that could be batched. |
| 168 | int32_t fifoMaxEventCount; |
| 169 | // The type of this sensor as a string. |
| 170 | std::string stringType; |
| 171 | // The delay between two sensor events corresponding to the lowest frequency that this sensor |
| 172 | // supports. |
| 173 | int32_t maxDelay; |
| 174 | // Sensor flags |
| 175 | int32_t flags; |
| 176 | // Sensor id, same as the input device ID it belongs to. |
| 177 | int32_t id; |
| 178 | }; |
| 179 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 180 | struct InputDeviceLightInfo { |
| 181 | explicit InputDeviceLightInfo(std::string name, int32_t id, InputDeviceLightType type, |
Vaibhav Devmurari | 82b37d6 | 2022-09-12 13:36:48 +0000 | [diff] [blame] | 182 | ftl::Flags<InputDeviceLightCapability> capabilityFlags, |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 183 | int32_t ordinal) |
Vaibhav Devmurari | 82b37d6 | 2022-09-12 13:36:48 +0000 | [diff] [blame] | 184 | : name(name), id(id), type(type), capabilityFlags(capabilityFlags), ordinal(ordinal) {} |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 185 | // Name string of the light. |
| 186 | std::string name; |
| 187 | // Light id |
| 188 | int32_t id; |
| 189 | // Type of the light. |
| 190 | InputDeviceLightType type; |
Vaibhav Devmurari | 82b37d6 | 2022-09-12 13:36:48 +0000 | [diff] [blame] | 191 | // Light capabilities. |
| 192 | ftl::Flags<InputDeviceLightCapability> capabilityFlags; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 193 | // Ordinal of the light |
| 194 | int32_t ordinal; |
| 195 | }; |
| 196 | |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 197 | struct InputDeviceBatteryInfo { |
| 198 | explicit InputDeviceBatteryInfo(std::string name, int32_t id) : name(name), id(id) {} |
| 199 | // Name string of the battery. |
| 200 | std::string name; |
| 201 | // Battery id |
| 202 | int32_t id; |
| 203 | }; |
| 204 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 205 | /* |
| 206 | * Describes the characteristics and capabilities of an input device. |
| 207 | */ |
| 208 | class InputDeviceInfo { |
| 209 | public: |
| 210 | InputDeviceInfo(); |
| 211 | InputDeviceInfo(const InputDeviceInfo& other); |
| 212 | ~InputDeviceInfo(); |
| 213 | |
| 214 | struct MotionRange { |
| 215 | int32_t axis; |
| 216 | uint32_t source; |
| 217 | float min; |
| 218 | float max; |
| 219 | float flat; |
| 220 | float fuzz; |
| 221 | float resolution; |
| 222 | }; |
| 223 | |
Michael Wright | 0415d63 | 2013-07-17 13:23:26 -0700 | [diff] [blame] | 224 | void initialize(int32_t id, int32_t generation, int32_t controllerNumber, |
Vaibhav Devmurari | dd82b8e | 2022-08-16 15:34:01 +0000 | [diff] [blame] | 225 | const InputDeviceIdentifier& identifier, const std::string& alias, |
| 226 | bool isExternal, bool hasMic, |
| 227 | hardware::input::InputDeviceCountryCode countryCode = |
| 228 | hardware::input::InputDeviceCountryCode::INVALID); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 229 | |
| 230 | inline int32_t getId() const { return mId; } |
Michael Wright | 0415d63 | 2013-07-17 13:23:26 -0700 | [diff] [blame] | 231 | inline int32_t getControllerNumber() const { return mControllerNumber; } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 232 | inline int32_t getGeneration() const { return mGeneration; } |
| 233 | inline const InputDeviceIdentifier& getIdentifier() const { return mIdentifier; } |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 234 | inline const std::string& getAlias() const { return mAlias; } |
| 235 | inline const std::string& getDisplayName() const { |
| 236 | return mAlias.empty() ? mIdentifier.name : mAlias; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 237 | } |
| 238 | inline bool isExternal() const { return mIsExternal; } |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 239 | inline bool hasMic() const { return mHasMic; } |
Vaibhav Devmurari | dd82b8e | 2022-08-16 15:34:01 +0000 | [diff] [blame] | 240 | inline hardware::input::InputDeviceCountryCode getCountryCode() const { return mCountryCode; } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 241 | inline uint32_t getSources() const { return mSources; } |
| 242 | |
| 243 | const MotionRange* getMotionRange(int32_t axis, uint32_t source) const; |
| 244 | |
| 245 | void addSource(uint32_t source); |
| 246 | void addMotionRange(int32_t axis, uint32_t source, |
| 247 | float min, float max, float flat, float fuzz, float resolution); |
| 248 | void addMotionRange(const MotionRange& range); |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 249 | void addSensorInfo(const InputDeviceSensorInfo& info); |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 250 | void addBatteryInfo(const InputDeviceBatteryInfo& info); |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 251 | void addLightInfo(const InputDeviceLightInfo& info); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 252 | |
Philip Junker | f843796 | 2022-01-25 21:20:19 +0100 | [diff] [blame] | 253 | void setKeyboardType(int32_t keyboardType); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 254 | inline int32_t getKeyboardType() const { return mKeyboardType; } |
| 255 | |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 256 | inline void setKeyCharacterMap(const std::shared_ptr<KeyCharacterMap> value) { |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 257 | mKeyCharacterMap = value; |
| 258 | } |
| 259 | |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 260 | inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const { |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 261 | return mKeyCharacterMap; |
| 262 | } |
| 263 | |
| 264 | inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; } |
| 265 | inline bool hasVibrator() const { return mHasVibrator; } |
| 266 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 267 | inline void setHasBattery(bool hasBattery) { mHasBattery = hasBattery; } |
| 268 | inline bool hasBattery() const { return mHasBattery; } |
| 269 | |
Michael Wright | 931fd6d | 2013-07-10 18:05:15 -0700 | [diff] [blame] | 270 | inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; } |
| 271 | inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; } |
| 272 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 273 | inline void setHasSensor(bool hasSensor) { mHasSensor = hasSensor; } |
| 274 | inline bool hasSensor() const { return mHasSensor; } |
| 275 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 276 | inline const std::vector<MotionRange>& getMotionRanges() const { |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 277 | return mMotionRanges; |
| 278 | } |
| 279 | |
Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 280 | std::vector<InputDeviceSensorInfo> getSensors(); |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 281 | |
Siarhei Vishniakou | 1983a71 | 2021-06-04 19:27:09 +0000 | [diff] [blame] | 282 | std::vector<InputDeviceLightInfo> getLights(); |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 283 | |
Prabir Pradhan | 167c270 | 2022-09-14 00:37:24 +0000 | [diff] [blame] | 284 | inline void setSupportsUsi(bool supportsUsi) { mSupportsUsi = supportsUsi; } |
| 285 | inline bool supportsUsi() const { return mSupportsUsi; } |
| 286 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 287 | private: |
| 288 | int32_t mId; |
| 289 | int32_t mGeneration; |
Michael Wright | 0415d63 | 2013-07-17 13:23:26 -0700 | [diff] [blame] | 290 | int32_t mControllerNumber; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 291 | InputDeviceIdentifier mIdentifier; |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 292 | std::string mAlias; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 293 | bool mIsExternal; |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 294 | bool mHasMic; |
Vaibhav Devmurari | dd82b8e | 2022-08-16 15:34:01 +0000 | [diff] [blame] | 295 | hardware::input::InputDeviceCountryCode mCountryCode; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 296 | uint32_t mSources; |
| 297 | int32_t mKeyboardType; |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 298 | std::shared_ptr<KeyCharacterMap> mKeyCharacterMap; |
Prabir Pradhan | 167c270 | 2022-09-14 00:37:24 +0000 | [diff] [blame] | 299 | // Whether this device supports the Universal Stylus Initiative (USI) protocol for styluses. |
| 300 | bool mSupportsUsi; |
Vaibhav Devmurari | dd82b8e | 2022-08-16 15:34:01 +0000 | [diff] [blame] | 301 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 302 | bool mHasVibrator; |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 303 | bool mHasBattery; |
Michael Wright | 931fd6d | 2013-07-10 18:05:15 -0700 | [diff] [blame] | 304 | bool mHasButtonUnderPad; |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 305 | bool mHasSensor; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 306 | |
Arthur Hung | 7c3ae9c | 2019-03-11 11:23:03 +0800 | [diff] [blame] | 307 | std::vector<MotionRange> mMotionRanges; |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 308 | std::unordered_map<InputDeviceSensorType, InputDeviceSensorInfo> mSensors; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 309 | /* Map from light ID to light info */ |
| 310 | std::unordered_map<int32_t, InputDeviceLightInfo> mLights; |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 311 | /* Map from battery ID to battery info */ |
| 312 | std::unordered_map<int32_t, InputDeviceBatteryInfo> mBatteries; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | /* Types of input device configuration files. */ |
Chris Ye | 1d927aa | 2020-07-04 18:22:41 -0700 | [diff] [blame] | 316 | enum class InputDeviceConfigurationFileType : int32_t { |
| 317 | CONFIGURATION = 0, /* .idc file */ |
| 318 | KEY_LAYOUT = 1, /* .kl file */ |
| 319 | KEY_CHARACTER_MAP = 2, /* .kcm file */ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 320 | }; |
| 321 | |
| 322 | /* |
| 323 | * Gets the path of an input device configuration file, if one is available. |
| 324 | * Considers both system provided and user installed configuration files. |
Siarhei Vishniakou | a9fd82c | 2022-05-18 09:42:52 -0700 | [diff] [blame] | 325 | * The optional suffix is appended to the end of the file name (before the |
| 326 | * extension). |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 327 | * |
| 328 | * The device identifier is used to construct several default configuration file |
| 329 | * names to try based on the device name, vendor, product, and version. |
| 330 | * |
| 331 | * Returns an empty string if not found. |
| 332 | */ |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 333 | extern std::string getInputDeviceConfigurationFilePathByDeviceIdentifier( |
Siarhei Vishniakou | a9fd82c | 2022-05-18 09:42:52 -0700 | [diff] [blame] | 334 | const InputDeviceIdentifier& deviceIdentifier, InputDeviceConfigurationFileType type, |
| 335 | const char* suffix = ""); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 336 | |
| 337 | /* |
| 338 | * Gets the path of an input device configuration file, if one is available. |
| 339 | * Considers both system provided and user installed configuration files. |
| 340 | * |
| 341 | * The name is case-sensitive and is used to construct the filename to resolve. |
| 342 | * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores. |
| 343 | * |
| 344 | * Returns an empty string if not found. |
| 345 | */ |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 346 | extern std::string getInputDeviceConfigurationFilePathByName( |
| 347 | const std::string& name, InputDeviceConfigurationFileType type); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 348 | |
Prabir Pradhan | cae4b3a | 2019-02-05 18:51:32 -0800 | [diff] [blame] | 349 | enum ReservedInputDeviceId : int32_t { |
Sandro Meier | d3d4060 | 2022-10-19 16:18:26 +0000 | [diff] [blame^] | 350 | // Device id representing an invalid device |
| 351 | INVALID_INPUT_DEVICE_ID = android::os::IInputConstants::INVALID_INPUT_DEVICE_ID, |
Prabir Pradhan | cae4b3a | 2019-02-05 18:51:32 -0800 | [diff] [blame] | 352 | // Device id of a special "virtual" keyboard that is always present. |
| 353 | VIRTUAL_KEYBOARD_ID = -1, |
| 354 | // Device id of the "built-in" keyboard if there is one. |
| 355 | BUILT_IN_KEYBOARD_ID = 0, |
Nathaniel R. Lewis | a7b82e1 | 2020-02-12 15:40:45 -0800 | [diff] [blame] | 356 | // First device id available for dynamic devices |
| 357 | END_RESERVED_ID = 1, |
Prabir Pradhan | cae4b3a | 2019-02-05 18:51:32 -0800 | [diff] [blame] | 358 | }; |
| 359 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 360 | } // namespace android |