Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: ui/events/ozone/evdev/event_factory.cc

Issue 58473003: evdev: Fix crashing with touch devices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/ozone/evdev/event_factory.h" 5 #include "ui/events/ozone/evdev/event_factory.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <linux/input.h> 9 #include <linux/input.h>
10 #include <poll.h> 10 #include <poll.h>
11 #include <unistd.h> 11 #include <unistd.h>
12 12
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "ui/events/ozone/evdev/event_device_info.h"
14 #include "ui/events/ozone/evdev/key_event_converter.h" 15 #include "ui/events/ozone/evdev/key_event_converter.h"
15 #include "ui/events/ozone/evdev/touch_event_converter.h" 16 #include "ui/events/ozone/evdev/touch_event_converter.h"
16 #include "ui/events/ozone/event_factory_ozone.h" 17 #include "ui/events/ozone/event_factory_ozone.h"
17 18
18 namespace ui { 19 namespace ui {
19 20
21 namespace {
22
23 bool IsTouchPad(const EventDeviceInfo& devinfo) {
24 if (!devinfo.HasEventType(EV_ABS))
25 return false;
26
27 return devinfo.HasKeyEvent(BTN_LEFT) || devinfo.HasKeyEvent(BTN_MIDDLE) ||
28 devinfo.HasKeyEvent(BTN_RIGHT) || devinfo.HasKeyEvent(BTN_TOOL_FINGER);
29 }
30
31 bool IsTouchScreen(const EventDeviceInfo& devinfo) {
32 return devinfo.HasEventType(EV_ABS) && !IsTouchPad(devinfo);
33 }
34
35 } // namespace
36
20 EventFactoryEvdev::EventFactoryEvdev() {} 37 EventFactoryEvdev::EventFactoryEvdev() {}
21 38
22 EventFactoryEvdev::~EventFactoryEvdev() {} 39 EventFactoryEvdev::~EventFactoryEvdev() {}
23 40
24 void EventFactoryEvdev::StartProcessingEvents() { 41 void EventFactoryEvdev::StartProcessingEvents() {
25 // The number of devices in the directory is unknown without reading 42 // The number of devices in the directory is unknown without reading
26 // the contents of the directory. Further, with hot-plugging, the entries 43 // the contents of the directory. Further, with hot-plugging, the entries
27 // might decrease during the execution of this loop. So exciting from the 44 // might decrease during the execution of this loop. So exciting from the
28 // loop on the first failure of open below is both cheaper and more 45 // loop on the first failure of open below is both cheaper and more
29 // reliable. 46 // reliable.
30 for (int id = 0; true; id++) { 47 for (int id = 0; true; id++) {
31 std::string path = base::StringPrintf("/dev/input/event%d", id); 48 std::string path = base::StringPrintf("/dev/input/event%d", id);
32 int fd = open(path.c_str(), O_RDONLY | O_NONBLOCK); 49 int fd = open(path.c_str(), O_RDONLY | O_NONBLOCK);
33 if (fd < 0) { 50 if (fd < 0) {
34 DLOG(ERROR) << "Cannot open '" << path << "': " << strerror(errno); 51 DLOG(ERROR) << "Cannot open '" << path << "': " << strerror(errno);
35 break; 52 break;
36 } 53 }
37 size_t evtype = 0; 54
38 COMPILE_ASSERT(sizeof(evtype) * 8 >= EV_MAX, evtype_wide_enough); 55 EventDeviceInfo devinfo;
39 if (ioctl(fd, EVIOCGBIT(0, sizeof(evtype)), &evtype) == -1) { 56 if (devinfo.Initialize(fd)) {
40 DLOG(ERROR) << "failed ioctl EVIOCGBIT 0" << path; 57 DLOG(ERROR) << "failed to get device information for " << path;
58 close(fd);
59 continue;
60 }
61
62 if (IsTouchPad(devinfo)) {
63 LOG(WARNING) << "touchpad device not supported: " << path;
41 close(fd); 64 close(fd);
42 continue; 65 continue;
43 } 66 }
44 67
45 scoped_ptr<EventConverterOzone> converter; 68 scoped_ptr<EventConverterOzone> converter;
46 // TODO(rjkroege) Add more device types. Support hot-plugging. 69 // TODO(rjkroege) Add more device types. Support hot-plugging.
47 if (evtype & (1 << EV_ABS)) 70 if (IsTouchScreen(devinfo))
48 converter.reset(new TouchEventConverterEvdev(fd, id)); 71 converter.reset(new TouchEventConverterEvdev(fd, id));
49 else if (evtype & (1 << EV_KEY)) 72 else if (devinfo.HasEventType(EV_KEY))
50 converter.reset(new KeyEventConverterEvdev(&modifiers_)); 73 converter.reset(new KeyEventConverterEvdev(&modifiers_));
51 74
52 if (converter) { 75 if (converter) {
53 AddEventConverter(fd, converter.Pass()); 76 AddEventConverter(fd, converter.Pass());
54 } else { 77 } else {
55 close(fd); 78 close(fd);
56 } 79 }
57 } 80 }
58 } 81 }
59 82
60 } // namespace ui 83 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698