summaryrefslogtreecommitdiff
path: root/libs/input/InputDevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/input/InputDevice.cpp')
-rw-r--r--libs/input/InputDevice.cpp81
1 files changed, 69 insertions, 12 deletions
diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp
index 4db9e06d8d..30c42a3daa 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;
@@ -46,9 +47,9 @@ static bool isValidNameChar(char ch) {
static void appendInputDeviceConfigurationFileRelativePath(std::string& path,
const std::string& name, InputDeviceConfigurationFileType type) {
- path += CONFIGURATION_FILE_DIR[type];
+ path += CONFIGURATION_FILE_DIR[static_cast<int32_t>(type)];
path += name;
- path += CONFIGURATION_FILE_EXTENSION[type];
+ path += CONFIGURATION_FILE_EXTENSION[static_cast<int32_t>(type)];
}
std::string getInputDeviceConfigurationFilePathByDeviceIdentifier(
@@ -86,8 +87,10 @@ std::string getInputDeviceConfigurationFilePathByName(
// Search system repository.
std::string path;
- // Treblized input device config files will be located /odm/usr or /vendor/usr.
- const char *rootsForPartition[] {"/odm", "/vendor", getenv("ANDROID_ROOT")};
+ // Treblized input device config files will be located /product/usr, /system_ext/usr,
+ // /odm/usr or /vendor/usr.
+ const char* rootsForPartition[]{"/product", "/system_ext", "/odm", "/vendor",
+ getenv("ANDROID_ROOT")};
for (size_t i = 0; i < size(rootsForPartition); i++) {
if (rootsForPartition[i] == nullptr) {
continue;
@@ -153,14 +156,24 @@ InputDeviceInfo::InputDeviceInfo() {
initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false);
}
-InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) :
- mId(other.mId), mGeneration(other.mGeneration), mControllerNumber(other.mControllerNumber),
- mIdentifier(other.mIdentifier), mAlias(other.mAlias), mIsExternal(other.mIsExternal),
- mHasMic(other.mHasMic), mSources(other.mSources),
- mKeyboardType(other.mKeyboardType), mKeyCharacterMap(other.mKeyCharacterMap),
- mHasVibrator(other.mHasVibrator), mHasButtonUnderPad(other.mHasButtonUnderPad),
- mMotionRanges(other.mMotionRanges) {
-}
+InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
+ : mId(other.mId),
+ mGeneration(other.mGeneration),
+ mControllerNumber(other.mControllerNumber),
+ mIdentifier(other.mIdentifier),
+ mAlias(other.mAlias),
+ mIsExternal(other.mIsExternal),
+ mHasMic(other.mHasMic),
+ mSources(other.mSources),
+ mKeyboardType(other.mKeyboardType),
+ mKeyCharacterMap(other.mKeyCharacterMap),
+ mHasVibrator(other.mHasVibrator),
+ mHasBattery(other.mHasBattery),
+ mHasButtonUnderPad(other.mHasButtonUnderPad),
+ mHasSensor(other.mHasSensor),
+ mMotionRanges(other.mMotionRanges),
+ mSensors(other.mSensors),
+ mLights(other.mLights) {}
InputDeviceInfo::~InputDeviceInfo() {
}
@@ -178,8 +191,12 @@ void InputDeviceInfo::initialize(int32_t id, int32_t generation, int32_t control
mSources = 0;
mKeyboardType = AINPUT_KEYBOARD_TYPE_NONE;
mHasVibrator = false;
+ mHasBattery = false;
mHasButtonUnderPad = false;
+ mHasSensor = false;
mMotionRanges.clear();
+ mSensors.clear();
+ mLights.clear();
}
const InputDeviceInfo::MotionRange* InputDeviceInfo::getMotionRange(
@@ -208,4 +225,44 @@ 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);
+}
+
+void InputDeviceInfo::addBatteryInfo(const InputDeviceBatteryInfo& info) {
+ if (mBatteries.find(info.id) != mBatteries.end()) {
+ ALOGW("Battery id %d already exists, will be replaced by new battery added.", info.id);
+ }
+ mBatteries.insert_or_assign(info.id, info);
+}
+
+void InputDeviceInfo::addLightInfo(const InputDeviceLightInfo& info) {
+ if (mLights.find(info.id) != mLights.end()) {
+ ALOGW("Light id %d already exists, will be replaced by new light added.", info.id);
+ }
+ mLights.insert_or_assign(info.id, info);
+}
+
+std::vector<InputDeviceSensorInfo> InputDeviceInfo::getSensors() {
+ std::vector<InputDeviceSensorInfo> infos;
+ infos.reserve(mSensors.size());
+ for (const auto& [type, info] : mSensors) {
+ infos.push_back(info);
+ }
+ return infos;
+}
+
+std::vector<InputDeviceLightInfo> InputDeviceInfo::getLights() {
+ std::vector<InputDeviceLightInfo> infos;
+ infos.reserve(mLights.size());
+ for (const auto& [id, info] : mLights) {
+ infos.push_back(info);
+ }
+ return infos;
+}
+
} // namespace android