Index: ui/events/ozone/evdev/event_device_info.cc |
diff --git a/ui/events/ozone/evdev/event_device_info.cc b/ui/events/ozone/evdev/event_device_info.cc |
index dd297791ec6762d2d3c2513878c6062372c4d141..e3c9f73c34a07991629338169d44d248406d0040 100644 |
--- a/ui/events/ozone/evdev/event_device_info.cc |
+++ b/ui/events/ozone/evdev/event_device_info.cc |
@@ -17,6 +17,11 @@ namespace ui { |
namespace { |
+// USB vendor and product strings are pragmatically limited to 126 |
+// characters each, so device names more than twice that should be |
+// unusual. |
+const size_t kMaximumDeviceNameLength = 256; |
+ |
bool GetEventBits(int fd, unsigned int type, void* buf, unsigned int size) { |
if (ioctl(fd, EVIOCGBIT(type, size), buf) < 0) { |
PLOG(ERROR) << "EVIOCGBIT(" << type << ", " << size << ") on fd " << fd; |
@@ -43,6 +48,27 @@ bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) { |
return true; |
} |
+bool GetDeviceName(int fd, std::string* name) { |
+ char device_name[kMaximumDeviceNameLength]; |
+ if (ioctl(fd, EVIOCGNAME(kMaximumDeviceNameLength - 1), &device_name) < 0) { |
+ PLOG(INFO) << "Can't read device name on fd " << fd; |
+ return false; |
+ } |
+ *name = device_name; |
+ return true; |
+} |
+ |
+bool GetDeviceIdentifiers(int fd, uint16_t* vendor, uint16_t* product) { |
+ struct input_id evdev_id; |
+ if (ioctl(fd, EVIOCGID, &evdev_id) < 0) { |
+ PLOG(INFO) << "Can't read device name on fd " << fd; |
+ return false; |
+ } |
+ *vendor = evdev_id.vendor; |
+ *product = evdev_id.product; |
+ return true; |
+} |
+ |
// |request| needs to be the equivalent to: |
// struct input_mt_request_layout { |
// uint32_t code; |
@@ -135,6 +161,12 @@ bool EventDeviceInfo::Initialize(int fd) { |
slots->assign(request_slots, request_slots + max_num_slots); |
} |
+ if (!GetDeviceName(fd, &name_)) |
+ return false; |
+ |
+ if (!GetDeviceIdentifiers(fd, &vendor_id_, &product_id_)) |
+ return false; |
+ |
return true; |
} |