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