From 6c2d936df88ee23b3e0f5c5a72a32ee4af4a81a1 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Wed, 7 Oct 2015 20:33:40 +0100 Subject: [PATCH] sensors: Proximity: Fix batch flushing Flushing a pending batch of requested events is blocking for several causes. The readEvents API call wasn't properly returning the state of the pendings, and even after that's corrected we were still blocking on the input reader _after_ filling out the pending requests. While we're at it, follow the CDD recommendation synchronize with SystemClock.elapsedRealtimeNano() clock. Replace the monotonic time with boot time as reference time. Fixes android.hardware.cts.SensorTest#testBatchAndFlush, addresses CRACKLING-641 Change-Id: Iae460f503e1ad408a0cb7855000daabec414a459 --- sensors/bst/hal/ProximitySensor.cpp | 7 +++++-- sensors/bst/hal/SensorBase.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sensors/bst/hal/ProximitySensor.cpp b/sensors/bst/hal/ProximitySensor.cpp index 02b0200..bc36d03 100755 --- a/sensors/bst/hal/ProximitySensor.cpp +++ b/sensors/bst/hal/ProximitySensor.cpp @@ -184,7 +184,8 @@ int ProximitySensor::enable(int32_t, int en) { write(fd, buf, sizeof(buf)); close(fd); mEnabled = flags; - setInitialState(); + if (mEnabled) + setInitialState(); return 0; } else { ALOGE("open %s failed.(%s)\n", input_sysfs_path, strerror(errno)); @@ -195,7 +196,7 @@ int ProximitySensor::enable(int32_t, int en) { } bool ProximitySensor::hasPendingEvents() const { - return mHasPendingEvent; + return mHasPendingEvent || mPendingFlushFinishEvent; } int ProximitySensor::readEvents(sensors_event_t* data, int count) @@ -222,6 +223,7 @@ int ProximitySensor::readEvents(sensors_event_t* data, int count) flush_finish_event.type = SENSOR_TYPE_META_DATA; flush_finish_event.meta_data.what = META_DATA_FLUSH_COMPLETE; flush_finish_event.meta_data.sensor = SENSORS_PROXIMITY_HANDLE; + int pEvents = mPendingFlushFinishEvent; while(mPendingFlushFinishEvent){ PINFO(" " "report flush finish event for sensor id: %d", flush_finish_event.meta_data.sensor); *data++ = flush_finish_event; @@ -229,6 +231,7 @@ int ProximitySensor::readEvents(sensors_event_t* data, int count) numEventReceived++; mPendingFlushFinishEvent--; } + if (pEvents) return pEvents; } #endif ssize_t n = mInputReader.fill(data_fd); diff --git a/sensors/bst/hal/SensorBase.cpp b/sensors/bst/hal/SensorBase.cpp index 4eebfe7..51f78d8 100755 --- a/sensors/bst/hal/SensorBase.cpp +++ b/sensors/bst/hal/SensorBase.cpp @@ -88,7 +88,7 @@ bool SensorBase::hasPendingEvents() const { int64_t SensorBase::getTimestamp() { struct timespec t; t.tv_sec = t.tv_nsec = 0; - clock_gettime(CLOCK_MONOTONIC, &t); + clock_gettime(CLOCK_BOOTTIME, &t); return int64_t(t.tv_sec)*1000000000LL + t.tv_nsec; }