diff options
| author | 2020-10-16 12:55:26 -0700 | |
|---|---|---|
| committer | 2020-12-16 15:42:57 -0800 | |
| commit | f59a2f484d4765edd74c9bb3f911f66c4eb7a3f4 (patch) | |
| tree | b91d1eb60a4d61bf4a7bc44f2f170633f61b176f /include/input/InputDevice.h | |
| parent | ef7705d5695070d62ed58047021af5318d91d494 (diff) | |
Add SensorManager support in inputflinger.
Add sensor device, sensor input mapper, sens event dispatcher support
into inputflinger.
Bug: 161634265
Test: atest inputflinger_tests
Change-Id: I2dcb2c35d9dccefc4cd8d939b79cf340931a9410
Diffstat (limited to 'include/input/InputDevice.h')
| -rw-r--r-- | include/input/InputDevice.h | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/include/input/InputDevice.h b/include/input/InputDevice.h index 60638caaab..23692e92d4 100644 --- a/include/input/InputDevice.h +++ b/include/input/InputDevice.h @@ -17,8 +17,10 @@ #ifndef _LIBINPUT_INPUT_DEVICE_H #define _LIBINPUT_INPUT_DEVICE_H +#include <android/sensor.h> #include <input/Input.h> #include <input/KeyCharacterMap.h> +#include <unordered_map> #include <vector> namespace android { @@ -63,6 +65,97 @@ struct InputDeviceIdentifier { std::string getCanonicalName() const; }; +/* Types of input device sensors. Keep sync with core/java/android/hardware/Sensor.java */ +enum class InputDeviceSensorType : int32_t { + ACCELEROMETER = ASENSOR_TYPE_ACCELEROMETER, + MAGNETIC_FIELD = ASENSOR_TYPE_MAGNETIC_FIELD, + ORIENTATION = 3, + GYROSCOPE = ASENSOR_TYPE_GYROSCOPE, + LIGHT = ASENSOR_TYPE_LIGHT, + PRESSURE = ASENSOR_TYPE_PRESSURE, + TEMPERATURE = 7, + PROXIMITY = ASENSOR_TYPE_PROXIMITY, + GRAVITY = ASENSOR_TYPE_GRAVITY, + LINEAR_ACCELERATION = ASENSOR_TYPE_LINEAR_ACCELERATION, + ROTATION_VECTOR = ASENSOR_TYPE_ROTATION_VECTOR, + RELATIVE_HUMIDITY = ASENSOR_TYPE_RELATIVE_HUMIDITY, + AMBIENT_TEMPERATURE = ASENSOR_TYPE_AMBIENT_TEMPERATURE, + MAGNETIC_FIELD_UNCALIBRATED = ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED, + GAME_ROTATION_VECTOR = ASENSOR_TYPE_GAME_ROTATION_VECTOR, + GYROSCOPE_UNCALIBRATED = ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED, + SIGNIFICANT_MOTION = ASENSOR_TYPE_SIGNIFICANT_MOTION, +}; + +enum class InputDeviceSensorAccuracy : int32_t { + ACCURACY_NONE = 0, + ACCURACY_LOW = 1, + ACCURACY_MEDIUM = 2, + ACCURACY_HIGH = 3, +}; + +enum class InputDeviceSensorReportingMode : int32_t { + CONTINUOUS = 0, + ON_CHANGE = 1, + ONE_SHOT = 2, + SPECIAL_TRIGGER = 3, +}; + +struct InputDeviceSensorInfo { + explicit InputDeviceSensorInfo(std::string name, std::string vendor, int32_t version, + InputDeviceSensorType type, InputDeviceSensorAccuracy accuracy, + float maxRange, float resolution, float power, int32_t minDelay, + int32_t fifoReservedEventCount, int32_t fifoMaxEventCount, + std::string stringType, int32_t maxDelay, int32_t flags, + int32_t id) + : name(name), + vendor(vendor), + version(version), + type(type), + accuracy(accuracy), + maxRange(maxRange), + resolution(resolution), + power(power), + minDelay(minDelay), + fifoReservedEventCount(fifoReservedEventCount), + fifoMaxEventCount(fifoMaxEventCount), + stringType(stringType), + maxDelay(maxDelay), + flags(flags), + id(id) {} + // Name string of the sensor. + std::string name; + // Vendor string of this sensor. + std::string vendor; + // Version of the sensor's module. + int32_t version; + // Generic type of this sensor. + InputDeviceSensorType type; + // The current accuracy of sensor event. + InputDeviceSensorAccuracy accuracy; + // Maximum range of the sensor in the sensor's unit. + float maxRange; + // Resolution of the sensor in the sensor's unit. + float resolution; + // The power in mA used by this sensor while in use. + float power; + // The minimum delay allowed between two events in microsecond or zero if this sensor only + // returns a value when the data it's measuring changes. + int32_t minDelay; + // Number of events reserved for this sensor in the batch mode FIFO. + int32_t fifoReservedEventCount; + // Maximum number of events of this sensor that could be batched. + int32_t fifoMaxEventCount; + // The type of this sensor as a string. + std::string stringType; + // The delay between two sensor events corresponding to the lowest frequency that this sensor + // supports. + int32_t maxDelay; + // Sensor flags + int32_t flags; + // Sensor id, same as the input device ID it belongs to. + int32_t id; +}; + /* * Describes the characteristics and capabilities of an input device. */ @@ -104,6 +197,7 @@ public: void addMotionRange(int32_t axis, uint32_t source, float min, float max, float flat, float fuzz, float resolution); void addMotionRange(const MotionRange& range); + void addSensorInfo(const InputDeviceSensorInfo& info); inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; } inline int32_t getKeyboardType() const { return mKeyboardType; } @@ -122,10 +216,17 @@ public: inline void setButtonUnderPad(bool hasButton) { mHasButtonUnderPad = hasButton; } inline bool hasButtonUnderPad() const { return mHasButtonUnderPad; } + inline void setHasSensor(bool hasSensor) { mHasSensor = hasSensor; } + inline bool hasSensor() const { return mHasSensor; } + inline const std::vector<MotionRange>& getMotionRanges() const { return mMotionRanges; } + const InputDeviceSensorInfo* getSensorInfo(InputDeviceSensorType type); + + const std::vector<InputDeviceSensorType> getSensorTypes(); + private: int32_t mId; int32_t mGeneration; @@ -139,8 +240,10 @@ private: std::shared_ptr<KeyCharacterMap> mKeyCharacterMap; bool mHasVibrator; bool mHasButtonUnderPad; + bool mHasSensor; std::vector<MotionRange> mMotionRanges; + std::unordered_map<InputDeviceSensorType, InputDeviceSensorInfo> mSensors; }; /* Types of input device configuration files. */ |