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