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
cm-14.0
Ricardo Cerqueira 10 years ago
parent 181299d426
commit 6c2d936df8

@ -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("<BST> " "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);

@ -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;
}

Loading…
Cancel
Save