summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Prabir Pradhan <prabirmsp@google.com> 2023-07-28 13:26:38 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-07-28 13:26:38 +0000
commitc99e15b556f91b861724c90efd1c460b5d307a5e (patch)
tree150638e66dc67ec92b692bbc5978d9e03e0f3456
parent906cd4ae5b99dc632e5a21b30b109efb995fd90e (diff)
parent2f13e022e739737f0a6cc4a31c6bcbb4cdadf387 (diff)
Merge changes from topic "uinput-cmd-label" into main
* changes: InputEventLabels: Support lookup of evdev event codes by label Move absolute axis validation from EventHub to InputDevice
-rw-r--r--include/input/InputEventLabels.h6
-rw-r--r--libs/input/InputEventLabels.cpp22
-rw-r--r--services/inputflinger/reader/EventHub.cpp26
-rw-r--r--services/inputflinger/reader/include/InputDevice.h13
4 files changed, 56 insertions, 11 deletions
diff --git a/include/input/InputEventLabels.h b/include/input/InputEventLabels.h
index 909bf087dd..44247c1249 100644
--- a/include/input/InputEventLabels.h
+++ b/include/input/InputEventLabels.h
@@ -69,6 +69,12 @@ public:
static EvdevEventLabel getLinuxEvdevLabel(int32_t type, int32_t code, int32_t value);
+ static std::optional<int> getLinuxEvdevEventTypeByLabel(const char* label);
+
+ static std::optional<int> getLinuxEvdevEventCodeByLabel(int32_t type, const char* label);
+
+ static std::optional<int> getLinuxEvdevInputPropByLabel(const char* label);
+
private:
InputEventLookup();
diff --git a/libs/input/InputEventLabels.cpp b/libs/input/InputEventLabels.cpp
index 50efac1314..c218e1e858 100644
--- a/libs/input/InputEventLabels.cpp
+++ b/libs/input/InputEventLabels.cpp
@@ -18,6 +18,7 @@
#include <linux/input-event-codes.h>
#include <linux/input.h>
+#include <strings.h>
#define DEFINE_KEYCODE(key) { #key, AKEYCODE_##key }
#define DEFINE_AXIS(axis) { #axis, AMOTION_EVENT_AXIS_##axis }
@@ -523,6 +524,14 @@ std::string getLabel(const label* labels, int value) {
return labels->name != nullptr ? labels->name : std::to_string(value);
}
+std::optional<int> getValue(const label* labels, const char* searchLabel) {
+ if (labels == nullptr) return {};
+ while (labels->name != nullptr && ::strcasecmp(labels->name, searchLabel) != 0) {
+ labels++;
+ }
+ return labels->name != nullptr ? std::make_optional(labels->value) : std::nullopt;
+}
+
const label* getCodeLabelsForType(int32_t type) {
switch (type) {
case EV_SYN:
@@ -572,4 +581,17 @@ EvdevEventLabel InputEventLookup::getLinuxEvdevLabel(int32_t type, int32_t code,
};
}
+std::optional<int> InputEventLookup::getLinuxEvdevEventTypeByLabel(const char* label) {
+ return getValue(ev_labels, label);
+}
+
+std::optional<int> InputEventLookup::getLinuxEvdevEventCodeByLabel(int32_t type,
+ const char* label) {
+ return getValue(getCodeLabelsForType(type), label);
+}
+
+std::optional<int> InputEventLookup::getLinuxEvdevInputPropByLabel(const char* label) {
+ return getValue(input_prop_labels, label);
+}
+
} // namespace android
diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp
index bc4cdd1192..e69c99e9b5 100644
--- a/services/inputflinger/reader/EventHub.cpp
+++ b/services/inputflinger/reader/EventHub.cpp
@@ -643,9 +643,6 @@ void EventHub::Device::populateAbsoluteAxisStates() {
identifier.name.c_str(), fd, strerror(errno));
continue;
}
- if (info.minimum == info.maximum) {
- continue;
- }
auto& [axisInfo, value] = absState[axis];
axisInfo.valid = true;
axisInfo.minValue = info.minimum;
@@ -778,26 +775,35 @@ void EventHub::Device::trackInputEvent(const struct input_event& event) {
LOG_ALWAYS_FATAL_IF(!currentFrameDropped &&
!keyState.set(static_cast<size_t>(event.code),
event.value != 0),
- "%s: received invalid EV_KEY event code: %s", __func__,
+ "%s: device '%s' received invalid EV_KEY event code: %s value: %d",
+ __func__, identifier.name.c_str(),
InputEventLookup::getLinuxEvdevLabel(EV_KEY, event.code, 1)
- .code.c_str());
+ .code.c_str(),
+ event.value);
break;
}
case EV_SW: {
LOG_ALWAYS_FATAL_IF(!currentFrameDropped &&
!swState.set(static_cast<size_t>(event.code),
event.value != 0),
- "%s: received invalid EV_SW event code: %s", __func__,
+ "%s: device '%s' received invalid EV_SW event code: %s value: %d",
+ __func__, identifier.name.c_str(),
InputEventLookup::getLinuxEvdevLabel(EV_SW, event.code, 1)
- .code.c_str());
+ .code.c_str(),
+ event.value);
break;
}
case EV_ABS: {
+ if (currentFrameDropped) {
+ break;
+ }
auto it = absState.find(event.code);
- LOG_ALWAYS_FATAL_IF(!currentFrameDropped && it == absState.end(),
- "%s: received invalid EV_ABS event code: %s", __func__,
+ LOG_ALWAYS_FATAL_IF(it == absState.end(),
+ "%s: device '%s' received invalid EV_ABS event code: %s value: %d",
+ __func__, identifier.name.c_str(),
InputEventLookup::getLinuxEvdevLabel(EV_ABS, event.code, 0)
- .code.c_str());
+ .code.c_str(),
+ event.value);
it->second.value = event.value;
break;
}
diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h
index aae3fe79e0..1cbcbf47b4 100644
--- a/services/inputflinger/reader/include/InputDevice.h
+++ b/services/inputflinger/reader/include/InputDevice.h
@@ -289,7 +289,18 @@ public:
return mEventHub->getDeviceControllerNumber(mId);
}
inline status_t getAbsoluteAxisInfo(int32_t code, RawAbsoluteAxisInfo* axisInfo) const {
- return mEventHub->getAbsoluteAxisInfo(mId, code, axisInfo);
+ if (const auto status = mEventHub->getAbsoluteAxisInfo(mId, code, axisInfo); status != OK) {
+ return status;
+ }
+
+ // Validate axis info for InputDevice.
+ if (axisInfo->valid && axisInfo->minValue == axisInfo->maxValue) {
+ // Historically, we deem axes with the same min and max values as invalid to avoid
+ // dividing by zero when scaling by max - min.
+ // TODO(b/291772515): Perform axis info validation on a per-axis basis when it is used.
+ axisInfo->valid = false;
+ }
+ return OK;
}
inline bool hasRelativeAxis(int32_t code) const {
return mEventHub->hasRelativeAxis(mId, code);