diff options
Diffstat (limited to 'libs/input/InputDevice.cpp')
-rw-r--r-- | libs/input/InputDevice.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp index 34eba5be7f..2ed441d8b4 100644 --- a/libs/input/InputDevice.cpp +++ b/libs/input/InputDevice.cpp @@ -23,6 +23,7 @@ #include <android-base/stringprintf.h> #include <input/InputDevice.h> #include <input/InputEventLabels.h> +#include <input/NamedEnum.h> using android::base::StringPrintf; @@ -166,7 +167,9 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) mKeyCharacterMap(other.mKeyCharacterMap), mHasVibrator(other.mHasVibrator), mHasButtonUnderPad(other.mHasButtonUnderPad), - mMotionRanges(other.mMotionRanges) {} + mHasSensor(other.mHasSensor), + mMotionRanges(other.mMotionRanges), + mSensors(other.mSensors) {} InputDeviceInfo::~InputDeviceInfo() { } @@ -185,7 +188,9 @@ void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t control mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE; mHasVibrator = false; mHasButtonUnderPad = false; + mHasSensor = false; mMotionRanges.clear(); + mSensors.clear(); } const InputDeviceInfo::MotionRange* InputDeviceInfo::getMotionRange( @@ -214,4 +219,28 @@ void InputDeviceInfo::addMotionRange(const MotionRange& range) { mMotionRanges.push_back(range); } +void InputDeviceInfo::addSensorInfo(const InputDeviceSensorInfo& info) { + if (mSensors.find(info.type) != mSensors.end()) { + ALOGW("Sensor type %s already exists, will be replaced by new sensor added.", + NamedEnum::string(info.type).c_str()); + } + mSensors.insert_or_assign(info.type, info); +} + +const std::vector<InputDeviceSensorType> InputDeviceInfo::getSensorTypes() { + std::vector<InputDeviceSensorType> types; + for (const auto& [type, info] : mSensors) { + types.push_back(type); + } + return types; +} + +const InputDeviceSensorInfo* InputDeviceInfo::getSensorInfo(InputDeviceSensorType type) { + auto it = mSensors.find(type); + if (it == mSensors.end()) { + return nullptr; + } + return &it->second; +} + } // namespace android |