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

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

Issue 58473003: evdev: Fix crashing with touch devices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: various comments from rjkroege 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/events/ozone/evdev/event_device_info.h"
6
7 #include <linux/input.h>
8
9 #include "base/logging.h"
10 #include "base/threading/thread_restrictions.h"
11
12 namespace ui {
13
14 namespace {
15
16 bool GetEventBits(int fd, unsigned int type, void* buf, unsigned int size) {
17 if (ioctl(fd, EVIOCGBIT(type, size), buf) < 0) {
18 DLOG(ERROR) << "failed EVIOCGBIT(" << type << ", " << size << ") on fd "
19 << fd;
20 return false;
21 }
22
23 return true;
24 }
25
26 bool GetPropBits(int fd, void* buf, unsigned int size) {
27 if (ioctl(fd, EVIOCGPROP(size), buf) < 0) {
28 DLOG(ERROR) << "failed EVIOCGPROP(" << size << ") on fd " << fd;
29 return false;
30 }
31
32 return true;
33 }
34
35 bool BitIsSet(const unsigned long* bits, unsigned int bit) {
36 return (bits[bit / EVDEV_LONG_BITS] & (1UL << (bit % EVDEV_LONG_BITS)));
37 }
38
39 } // namespace
40
41 EventDeviceInfo::EventDeviceInfo() {
42 memset(ev_bits_, 0, sizeof(ev_bits_));
43 memset(key_bits_, 0, sizeof(key_bits_));
44 memset(rel_bits_, 0, sizeof(rel_bits_));
45 memset(abs_bits_, 0, sizeof(abs_bits_));
46 memset(msc_bits_, 0, sizeof(msc_bits_));
47 memset(sw_bits_, 0, sizeof(sw_bits_));
48 memset(led_bits_, 0, sizeof(led_bits_));
49 memset(prop_bits_, 0, sizeof(prop_bits_));
50 }
51
52 EventDeviceInfo::~EventDeviceInfo() {}
53
54 bool EventDeviceInfo::Initialize(int fd) {
55 base::ThreadRestrictions::AssertIOAllowed();
rjkroege 2013/11/05 17:56:52 nit: move the assert to GetPropBits and GetEventBi
spang 2013/11/05 19:18:35 Done.
56
57 if (!GetEventBits(fd, 0, ev_bits_, sizeof(ev_bits_)))
58 return false;
59
60 if (!GetEventBits(fd, EV_KEY, key_bits_, sizeof(key_bits_)))
61 return false;
62
63 if (!GetEventBits(fd, EV_REL, rel_bits_, sizeof(rel_bits_)))
64 return false;
65
66 if (!GetEventBits(fd, EV_ABS, abs_bits_, sizeof(abs_bits_)))
67 return false;
68
69 if (!GetEventBits(fd, EV_MSC, msc_bits_, sizeof(msc_bits_)))
70 return false;
71
72 if (!GetEventBits(fd, EV_SW, sw_bits_, sizeof(sw_bits_)))
73 return false;
74
75 if (!GetEventBits(fd, EV_LED, led_bits_, sizeof(led_bits_)))
76 return false;
77
78 if (!GetPropBits(fd, prop_bits_, sizeof(prop_bits_)))
79 return false;
80
81 return true;
82 }
83
84 bool EventDeviceInfo::HasEventType(unsigned int type) const {
85 if (type > EV_MAX)
86 return false;
87 return BitIsSet(ev_bits_, type);
88 }
89
90 bool EventDeviceInfo::HasKeyEvent(unsigned int code) const {
91 if (code > KEY_MAX)
92 return false;
93 return BitIsSet(key_bits_, code);
94 }
95
96 bool EventDeviceInfo::HasRelEvent(unsigned int code) const {
97 if (code > REL_MAX)
98 return false;
99 return BitIsSet(rel_bits_, code);
100 }
101
102 bool EventDeviceInfo::HasAbsEvent(unsigned int code) const {
103 if (code > ABS_MAX)
104 return false;
105 return BitIsSet(abs_bits_, code);
106 }
107
108 bool EventDeviceInfo::HasMscEvent(unsigned int code) const {
109 if (code > MSC_MAX)
110 return false;
111 return BitIsSet(msc_bits_, code);
112 }
113
114 bool EventDeviceInfo::HasSwEvent(unsigned int code) const {
115 if (code > SW_MAX)
116 return false;
117 return BitIsSet(sw_bits_, code);
118 }
119
120 bool EventDeviceInfo::HasLedEvent(unsigned int code) const {
121 if (code > LED_MAX)
122 return false;
123 return BitIsSet(led_bits_, code);
124 }
125
126 bool EventDeviceInfo::HasProp(unsigned int code) const {
127 if (code > INPUT_PROP_MAX)
128 return false;
129 return BitIsSet(prop_bits_, code);
130 }
131
132 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698