summaryrefslogtreecommitdiffstats
path: root/services/input/EventHub.cpp
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2013-04-10 01:03:19 -0700
committerJeff Brown <jeffbrown@google.com>2013-04-10 03:51:18 -0700
commit4dac901f011e7c15882e260441225633a6435e49 (patch)
treec7023a841c1630bf6713b145a91723c4b91423f0 /services/input/EventHub.cpp
parenta9574e3361e168671d627071e26280f69d0d081b (diff)
downloadframeworks_base-4dac901f011e7c15882e260441225633a6435e49.zip
frameworks_base-4dac901f011e7c15882e260441225633a6435e49.tar.gz
frameworks_base-4dac901f011e7c15882e260441225633a6435e49.tar.bz2
Rewrite touch navigation dpad synthesis.
The new implementation more accurately tracks the velocity of flings and takes care to avoid obvious discontinuities. The main goal is for a fling to appear to be a linear extension of the movement already in progress. The minimum fling velocity is set to ensure that flings appear to be fairly smooth despite being discretized. Use sequences of repeated key events instead of individual down/up events to represent continuous motions in one direction which can be helpful for stopping flings at boundaries such as when flinging the cursor position within a text view. Compute the movement thresholds based on the physical size of the touch pad, if known. If not known, we assume a nominal size. Support stopping flings with a tap just like we do for normal touch events elsewhere in the framework. Moved the detection of ASSIST swipes into the InputReader where it belongs. These swipes must be detected globally to ensure consistent behavior across the all applications. Added a custom protocol in EventHub to enable input device drivers to override the timestamp of the following events in a packet. This change enables input device drivers that have a better idea of when an input event was actually generated to pass this information to the input system. Particularly useful with uinput. Bug: 8583760 Change-Id: I8ef4e827804786d549cfaa00793a2b9dd0fda465
Diffstat (limited to 'services/input/EventHub.cpp')
-rw-r--r--services/input/EventHub.cpp36
1 files changed, 31 insertions, 5 deletions
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp
index 0773afb..f4e1cec 100644
--- a/services/input/EventHub.cpp
+++ b/services/input/EventHub.cpp
@@ -40,7 +40,6 @@
#include <androidfw/KeyCharacterMap.h>
#include <androidfw/VirtualKeyMap.h>
-#include <sha1.h>
#include <string.h>
#include <stdint.h>
#include <dirent.h>
@@ -49,6 +48,7 @@
#include <sys/epoll.h>
#include <sys/ioctl.h>
#include <sys/limits.h>
+#include <sys/sha1.h>
/* this macro is used to tell if "bit" is set in "array"
* it selects a byte from the array, and does a boolean AND
@@ -162,7 +162,8 @@ EventHub::Device::Device(int fd, int32_t id, const String8& path,
next(NULL),
fd(fd), id(id), path(path), identifier(identifier),
classes(0), configuration(NULL), virtualKeyMap(NULL),
- ffEffectPlaying(false), ffEffectId(-1) {
+ ffEffectPlaying(false), ffEffectId(-1),
+ timestampOverrideSec(0), timestampOverrideUsec(0) {
memset(keyBitmask, 0, sizeof(keyBitmask));
memset(absBitmask, 0, sizeof(absBitmask));
memset(relBitmask, 0, sizeof(relBitmask));
@@ -766,12 +767,37 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz
size_t count = size_t(readSize) / sizeof(struct input_event);
for (size_t i = 0; i < count; i++) {
- const struct input_event& iev = readBuffer[i];
- ALOGV("%s got: t0=%d, t1=%d, type=%d, code=%d, value=%d",
+ struct input_event& iev = readBuffer[i];
+ ALOGV("%s got: time=%d.%06d, type=%d, code=%d, value=%d",
device->path.string(),
(int) iev.time.tv_sec, (int) iev.time.tv_usec,
iev.type, iev.code, iev.value);
+ // Some input devices may have a better concept of the time
+ // when an input event was actually generated than the kernel
+ // which simply timestamps all events on entry to evdev.
+ // This is a custom Android extension of the input protocol
+ // mainly intended for use with uinput based device drivers.
+ if (iev.type == EV_MSC) {
+ if (iev.code == MSC_ANDROID_TIME_SEC) {
+ device->timestampOverrideSec = iev.value;
+ continue;
+ } else if (iev.code == MSC_ANDROID_TIME_USEC) {
+ device->timestampOverrideUsec = iev.value;
+ continue;
+ }
+ }
+ if (device->timestampOverrideSec || device->timestampOverrideUsec) {
+ iev.time.tv_sec = device->timestampOverrideSec;
+ iev.time.tv_usec = device->timestampOverrideUsec;
+ if (iev.type == EV_SYN && iev.code == SYN_REPORT) {
+ device->timestampOverrideSec = 0;
+ device->timestampOverrideUsec = 0;
+ }
+ ALOGV("applied override time %d.%06d",
+ int(iev.time.tv_sec), int(iev.time.tv_usec));
+ }
+
#ifdef HAVE_POSIX_CLOCKS
// Use the time specified in the event instead of the current time
// so that downstream code can get more accurate estimates of
@@ -829,8 +855,8 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz
event->code = iev.code;
event->value = iev.value;
event += 1;
+ capacity -= 1;
}
- capacity -= count;
if (capacity == 0) {
// The result buffer is full. Reset the pending event index
// so we will try to read the device again on the next iteration.