summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2012-10-05 19:47:41 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-10-05 19:47:41 -0700
commit0a12b8e59ba576f7f2e90011d3fa3dc7b9f17acf (patch)
tree3f107fcb772f634ab9ba65672333c9a76a396e8d /services
parent72b04de04b1d2f99be68091b6fe569f0d364aa1f (diff)
parent4d12d5be8fafc7bfe2f677357d326514ad5986e3 (diff)
downloadframeworks_base-0a12b8e59ba576f7f2e90011d3fa3dc7b9f17acf.zip
frameworks_base-0a12b8e59ba576f7f2e90011d3fa3dc7b9f17acf.tar.gz
frameworks_base-0a12b8e59ba576f7f2e90011d3fa3dc7b9f17acf.tar.bz2
am 4d12d5be: Merge "Recover from bad input event timestamps from the kernel." into jb-mr1-dev
* commit '4d12d5be8fafc7bfe2f677357d326514ad5986e3': Recover from bad input event timestamps from the kernel.
Diffstat (limited to 'services')
-rw-r--r--services/input/EventHub.cpp34
-rw-r--r--services/input/InputReader.cpp5
2 files changed, 37 insertions, 2 deletions
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp
index f80ac18..1c9520d 100644
--- a/services/input/EventHub.cpp
+++ b/services/input/EventHub.cpp
@@ -787,6 +787,40 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz
event->when = nsecs_t(iev.time.tv_sec) * 1000000000LL
+ nsecs_t(iev.time.tv_usec) * 1000LL;
ALOGV("event time %lld, now %lld", event->when, now);
+
+ // Bug 7291243: Add a guard in case the kernel generates timestamps
+ // that appear to be far into the future because they were generated
+ // using the wrong clock source.
+ //
+ // This can happen because when the input device is initially opened
+ // it has a default clock source of CLOCK_REALTIME. Any input events
+ // enqueued right after the device is opened will have timestamps
+ // generated using CLOCK_REALTIME. We later set the clock source
+ // to CLOCK_MONOTONIC but it is already too late.
+ //
+ // Invalid input event timestamps can result in ANRs, crashes and
+ // and other issues that are hard to track down. We must not let them
+ // propagate through the system.
+ //
+ // Log a warning so that we notice the problem and recover gracefully.
+ if (event->when >= now + 10 * 1000000000LL) {
+ // Double-check. Time may have moved on.
+ nsecs_t time = systemTime(SYSTEM_TIME_MONOTONIC);
+ if (event->when > time) {
+ ALOGW("An input event from %s has a timestamp that appears to "
+ "have been generated using the wrong clock source "
+ "(expected CLOCK_MONOTONIC): "
+ "event time %lld, current time %lld, call time %lld. "
+ "Using current time instead.",
+ device->path.string(), event->when, time, now);
+ event->when = time;
+ } else {
+ ALOGV("Event time is ok but failed the fast path and required "
+ "an extra call to systemTime: "
+ "event time %lld, current time %lld, call time %lld.",
+ event->when, time, now);
+ }
+ }
#else
event->when = now;
#endif
diff --git a/services/input/InputReader.cpp b/services/input/InputReader.cpp
index cebfeb4..bc8df18 100644
--- a/services/input/InputReader.cpp
+++ b/services/input/InputReader.cpp
@@ -956,8 +956,9 @@ void InputDevice::process(const RawEvent* rawEvents, size_t count) {
size_t numMappers = mMappers.size();
for (const RawEvent* rawEvent = rawEvents; count--; rawEvent++) {
#if DEBUG_RAW_EVENTS
- ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08x",
- rawEvent->deviceId, rawEvent->type, rawEvent->code, rawEvent->value);
+ ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08x when=%lld",
+ rawEvent->deviceId, rawEvent->type, rawEvent->code, rawEvent->value,
+ rawEvent->when);
#endif
if (mDropUntilNextSync) {