summaryrefslogtreecommitdiff
path: root/6515
diff options
context:
space:
mode:
authorNick Vaccaro <nvaccaro@google.com>2014-06-29 03:24:32 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-06-29 03:24:32 +0000
commit08aad91f08c1982bfa0a94f8fc2609f6d75686f1 (patch)
tree1f5b254ac28759c1392571d9cdce1c115263a794 /6515
parent98fdf2b4814602099a16b973f8bda9e5579c8672 (diff)
parent8099a732b0339f73daa1b87e291b4f99b294f31b (diff)
downloadinvensense-08aad91f08c1982bfa0a94f8fc2609f6d75686f1.tar.gz
am 8099a732: am c6a022ca: Invensense: 6515: Spoof flush complete for step counter
* commit '8099a732b0339f73daa1b87e291b4f99b294f31b': Invensense: 6515: Spoof flush complete for step counter
Diffstat (limited to '6515')
-rw-r--r--6515/libsensors_iio/MPLSensor.cpp5
-rwxr-xr-x6515/libsensors_iio/sensors_mpl.cpp54
2 files changed, 55 insertions, 4 deletions
diff --git a/6515/libsensors_iio/MPLSensor.cpp b/6515/libsensors_iio/MPLSensor.cpp
index c63d8b4..8db182d 100644
--- a/6515/libsensors_iio/MPLSensor.cpp
+++ b/6515/libsensors_iio/MPLSensor.cpp
@@ -5719,7 +5719,6 @@ int MPLSensor::batch(int handle, int flags, int64_t period_ns, int64_t timeout)
enablePedQuaternion(1);
}
}
-
/* case for Ped Quaternion */
if ((batchMode == 1) && (featureMask & INV_DMP_PED_QUATERNION) &&
(mEnabled & (1 << GameRotationVector)) &&
@@ -5841,7 +5840,7 @@ int MPLSensor::flush(int handle)
if (((what != StepDetector) && (!(mEnabled & (1 << what)))) ||
((what == StepDetector) && !(mFeatureActiveMask & INV_DMP_PEDOMETER))) {
LOGE_IF(ENG_VERBOSE, "HAL: flush - sensor %s not enabled", sname.string());
- return -EINVAL;
+ return -EINVAL;
}
if(!(mBatchEnabled & (1 << what))) {
@@ -5867,7 +5866,7 @@ int MPLSensor::flush(int handle)
LOGV_IF(ENG_VERBOSE, "HAl:flush - mFlushSensorEnabledVector=%d res=%d", handle, res);
mFlushBatchSet = 0;
- return 0;
+ return status;
}
int MPLSensor::selectAndSetQuaternion(int batchMode, int mEnabled, long long featureMask)
diff --git a/6515/libsensors_iio/sensors_mpl.cpp b/6515/libsensors_iio/sensors_mpl.cpp
index f15454c..70b2840 100755
--- a/6515/libsensors_iio/sensors_mpl.cpp
+++ b/6515/libsensors_iio/sensors_mpl.cpp
@@ -25,6 +25,8 @@
#include <pthread.h>
#include <stdlib.h>
+#include <sys/queue.h>
+
#include <linux/input.h>
#include <utils/Atomic.h>
@@ -50,6 +52,15 @@
#define LOCAL_SENSORS (NumSensors)
#endif
+struct handle_entry {
+ SIMPLEQ_ENTRY(handle_entry) entries;
+ int handle;
+};
+
+static SIMPLEQ_HEAD(simplehead, handle_entry) pending_flush_items_head;
+struct simplehead *headp;
+static pthread_mutex_t flush_handles_mutex = PTHREAD_MUTEX_INITIALIZER;
+
static struct sensor_t sSensorList[LOCAL_SENSORS];
static int sensors = (sizeof(sSensorList) / sizeof(sensor_t));
@@ -127,6 +138,9 @@ sensors_poll_context_t::sensors_poll_context_t() {
* MPLSensor *mplSensor = new MPLSensor(mCompassSensor, AccelLoadConfig);
*/
+ // Initialize pending flush queue
+ SIMPLEQ_INIT(&pending_flush_items_head);
+
// populate the sensor list
sensors =
mplSensor->populateSensorList(sSensorList, sizeof(sSensorList));
@@ -183,6 +197,24 @@ int sensors_poll_context_t::pollEvents(sensors_event_t *data, int count)
int nbEvents = 0;
int nb, polltime = -1;
+ struct handle_entry *handle_element;
+ pthread_mutex_lock(&flush_handles_mutex);
+ if (!SIMPLEQ_EMPTY(&pending_flush_items_head)) {
+ sensors_event_t flushCompleteEvent;
+ flushCompleteEvent.type = SENSOR_TYPE_META_DATA;
+ flushCompleteEvent.sensor = 0;
+ handle_element = SIMPLEQ_FIRST(&pending_flush_items_head);
+ flushCompleteEvent.meta_data.sensor = handle_element->handle;
+ SIMPLEQ_REMOVE_HEAD(&pending_flush_items_head, entries);
+ free(handle_element);
+ memcpy(data, (void *) &flushCompleteEvent, sizeof(flushCompleteEvent));
+ LOGI_IF(1, "pollEvents() Returning fake flush event completion for handle %d",
+ flushCompleteEvent.meta_data.sensor);
+ pthread_mutex_unlock(&flush_handles_mutex);
+ return 1;
+ }
+ pthread_mutex_unlock(&flush_handles_mutex);
+
polltime = ((MPLSensor*) mSensor)->getStepCountPollTime();
// look for new events
@@ -293,6 +325,20 @@ int sensors_poll_context_t::batch(int handle, int flags, int64_t period_ns,
}
#if defined ANDROID_KITKAT
+void inv_pending_flush(int handle) {
+ struct handle_entry *the_entry;
+ pthread_mutex_lock(&flush_handles_mutex);
+ the_entry = (struct handle_entry*) malloc(sizeof(struct handle_entry));
+ if (the_entry != NULL) {
+ LOGI_IF(0, "Inserting %d into pending list", handle);
+ the_entry->handle = handle;
+ SIMPLEQ_INSERT_TAIL(&pending_flush_items_head, the_entry, entries);
+ } else {
+ LOGE("ERROR malloc'ing space for pending handler flush entry");
+ }
+ pthread_mutex_unlock(&flush_handles_mutex);
+}
+
int sensors_poll_context_t::flush(int handle)
{
FUNC_LOG;
@@ -353,7 +399,13 @@ static int poll__flush(struct sensors_poll_device_1 *dev,
int handle)
{
sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
- return ctx->flush(handle);
+ int status = ctx->flush(handle);
+ if (handle == SENSORS_STEP_COUNTER_HANDLE) {
+ LOGI_IF(0, "creating flush completion event for handle %d", handle);
+ inv_pending_flush(handle);
+ return 0;
+ }
+ return status;
}
#endif
/******************************************************************************/