virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs,
nsecs_t maxBatchReportLatencyNs, int reservedFlags) = 0;
virtual status_t setEventRate(int handle, nsecs_t ns) = 0;
- virtual status_t flushSensor(int handle) = 0;
+ virtual status_t flush() = 0;
};
// ----------------------------------------------------------------------------
status_t enableSensor(int32_t handle, int32_t samplingPeriodUs, int maxBatchReportLatencyUs,
int reservedFlags) const;
status_t disableSensor(int32_t handle) const;
- status_t flushSensor(int32_t handle) const;
+ status_t flush() const;
private:
sp<Looper> getLooper() const;
return reply.readInt32();
}
- virtual status_t flushSensor(int handle) {
+ virtual status_t flush() {
Parcel data, reply;
data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor());
- data.writeInt32(handle);
remote()->transact(FLUSH_SENSOR, data, &reply);
return reply.readInt32();
}
} break;
case FLUSH_SENSOR: {
CHECK_INTERFACE(ISensorEventConnection, data, reply);
- int handle = data.readInt32();
- status_t result = flushSensor(handle);
+ status_t result = flush();
reply->writeInt32(result);
return NO_ERROR;
} break;
us2ns(maxBatchReportLatencyUs), reservedFlags);
}
-status_t SensorEventQueue::flushSensor(int32_t handle) const {
- return mSensorEventConnection->flushSensor(handle);
+status_t SensorEventQueue::flush() const {
+ return mSensorEventConnection->flush();
}
status_t SensorEventQueue::disableSensor(int32_t handle) const {
int handle) {
if (mInitCheck != NO_ERROR) return mInitCheck;
SensorInterface* sensor = mSensorMap.valueFor(handle);
- if (sensor == NULL) {
- return BAD_VALUE;
+ if (sensor == NULL) {
+ return BAD_VALUE;
+ }
+ if (sensor->getSensor().getType() == SENSOR_TYPE_SIGNIFICANT_MOTION) {
+ ALOGE("flush called on Significant Motion sensor");
+ return INVALID_OPERATION;
}
SensorDevice& dev(SensorDevice::getInstance());
return mService->setEventRate(this, handle, samplingPeriodNs);
}
-status_t SensorService::SensorEventConnection::flushSensor(int handle) {
- return mService->flushSensor(this, handle);
+status_t SensorService::SensorEventConnection::flush() {
+ Mutex::Autolock _l(mConnectionLock);
+ status_t err(NO_ERROR);
+ for (size_t i = 0; i < mSensorInfo.size(); ++i) {
+ const int handle = mSensorInfo.keyAt(i);
+ status_t err_flush = mService->flushSensor(this, handle);
+ if (err_flush != NO_ERROR) {
+ ALOGE("Flush error handle=%d %s", handle, strerror(-err_flush));
+ }
+ err = (err_flush != NO_ERROR) ? err_flush : err;
+ }
+ return err;
}
// ---------------------------------------------------------------------------
virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs,
nsecs_t maxBatchReportLatencyNs, int reservedFlags);
virtual status_t setEventRate(int handle, nsecs_t samplingPeriodNs);
- virtual status_t flushSensor(int handle);
+ virtual status_t flush();
// Count the number of flush complete events which are about to be dropped in the buffer.
// Increment mPendingFlushEventsToSend in mSensorInfo. These flush complete events will be
// sent separately before the next batch of events.