Sensor: Correct flush function for different types of sensors

JIRA: MARVIN-239

Fix bug in flush function for sensors:
1. for One-Shot sensor, return -EINVAL;
2. for sensors not using FIFO, return flush complete event;
3. for sensors using FIFO, flush data in FIFO.

Change-Id: I3e35a9be39150d2ca2be0166b516a722df8fefda
Signed-off-by: Fei Li <feix.f.li@intel.com>
Reviewed-on: https://android.intel.com/376695
Reviewed-by: Pujol, Benjamin <benjamin.pujol@intel.com>
diff --git a/libsensors_iio/src/HWSensorBase.cpp b/libsensors_iio/src/HWSensorBase.cpp
index ea7078b..24ed9f2 100644
--- a/libsensors_iio/src/HWSensorBase.cpp
+++ b/libsensors_iio/src/HWSensorBase.cpp
@@ -303,12 +303,14 @@
 {
 	int err;
 
-	if (GetStatus() && (current_fifo_len > HW_SENSOR_BASE_DEFAULT_IIO_BUFFER_LEN)) {
-		err = write_sysfs_int((char *)FILENAME_FLUSH, common_data.iio_sysfs_path, 1);
-		if (err < 0) {
-			ALOGE("%s: Failed to write flush file \"%s/%s\".",
-					common_data.device_name, common_data.iio_sysfs_path, FILENAME_FLUSH);
-			return -EINVAL;
+	if (GetStatus()) {
+		if (current_fifo_len > HW_SENSOR_BASE_DEFAULT_IIO_BUFFER_LEN) {
+			err = write_sysfs_int((char *)FILENAME_FLUSH, common_data.iio_sysfs_path, 1);
+			if (err < 0) {
+				ALOGE("%s: Failed to write flush file \"%s/%s\".",
+						common_data.device_name, common_data.iio_sysfs_path, FILENAME_FLUSH);
+				return -EINVAL;
+			}
 		}
 	} else
 		return -EINVAL;
diff --git a/libsensors_iio/src/SensorHAL.cpp b/libsensors_iio/src/SensorHAL.cpp
index e25771f..213cb85 100644
--- a/libsensors_iio/src/SensorHAL.cpp
+++ b/libsensors_iio/src/SensorHAL.cpp
@@ -584,6 +584,10 @@
 static int st_hal_dev_flush(struct sensors_poll_device_1 *dev, int handle)
 {
 	STSensorHAL_data *hal_data = (STSensorHAL_data *)dev;
+	ALOGD("st_hal_dev_flush type=%d", ((struct sensor_t) hal_data->sensor_t_list[handle]).type);
+	/* One-shot sensor must return -EINVAL and not generate any flush complete metadata event */
+	if (SENSOR_TYPE_SIGNIFICANT_MOTION == ((struct sensor_t) hal_data->sensor_t_list[handle]).type)
+		return -EINVAL;
 
 	return hal_data->sensor_classes[handle]->FlushData();
 }