From da8385cb97ba40ab87e7e9b8d5b7c8f0ba5ba0fd Mon Sep 17 00:00:00 2001 From: Peng Xu Date: Tue, 28 Feb 2017 20:19:47 -0800 Subject: Add ASensorEventQueue_registerSensor and default error value ASensorEventQueue_registerSensor is new function created in 2016 but is never exported at NDK level. In this CL the function signature is formalized and the function name is added to NDK function export table. Internal class SensorEventQueue is also changed to adapt. Default error values are also defined. Test: cts-tradefed run cts --module CtsSensorTestCases \ --test android.hardware.cts.SensorNativeTest Change-Id: I74dc72e50ea4bae6d2d8944ce6d2e191ed2f495e --- include/android/sensor.h | 28 ++++++++++++++++++--------- libs/sensor/SensorEventQueue.cpp | 2 +- libs/sensor/include/sensor/SensorEventQueue.h | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/android/sensor.h b/include/android/sensor.h index a5e5c057f8..d9998ba425 100644 --- a/include/android/sensor.h +++ b/include/android/sensor.h @@ -48,16 +48,22 @@ * */ -#include - #include +#include +#include +#include + #ifdef __cplusplus extern "C" { #endif typedef struct AHardwareBuffer AHardwareBuffer; +#define ASENSOR_RESOLUTION_INVALID (nanf("")) +#define ASENSOR_FIFO_COUNT_INVALID (-1) +#define ASENSOR_DELAY_INVALID INT32_MIN + /** * Sensor types. * (keep in sync with hardware/sensors.h) @@ -112,7 +118,11 @@ enum { * All values are in SI units (m/s^2) and measure the acceleration of the * device not including the force of gravity. */ - ASENSOR_TYPE_LINEAR_ACCELERATION = 10 + ASENSOR_TYPE_LINEAR_ACCELERATION = 10, + /** + * Invalid sensor type. Returned by {@link ASensor_getType} as error value. + */ + ASENSOR_TYPE_INVALID = -1 }; /** @@ -142,7 +152,9 @@ enum { /** on shot reporting */ AREPORTING_MODE_ONE_SHOT = 2, /** special trigger reporting */ - AREPORTING_MODE_SPECIAL_TRIGGER = 3 + AREPORTING_MODE_SPECIAL_TRIGGER = 3, + /** invalid reporting mode */ + AREPORTING_MODE_INVALID = -1 }; /** @@ -397,8 +409,7 @@ ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor * of this type and wakeUp properties exists. */ -ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, - bool wakeUp); +ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp); #endif /** @@ -516,7 +527,7 @@ int ASensorManager_configureDirectReport( * Note: To disable the selected sensor, use ASensorEventQueue_disableSensor() same as before. */ int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor, - int32_t samplingPeriodUs, int maxBatchReportLatencyUs); + int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs); /** * Enable the selected sensor. Returns a negative error code on failure. @@ -557,8 +568,7 @@ int ASensorEventQueue_hasEvents(ASensorEventQueue* queue); * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8); * */ -ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, - ASensorEvent* events, size_t count); +ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count); /*****************************************************************************/ diff --git a/libs/sensor/SensorEventQueue.cpp b/libs/sensor/SensorEventQueue.cpp index 8ba3ebe17d..6f68fb5f7b 100644 --- a/libs/sensor/SensorEventQueue.cpp +++ b/libs/sensor/SensorEventQueue.cpp @@ -135,7 +135,7 @@ status_t SensorEventQueue::disableSensor(Sensor const* sensor) const { } status_t SensorEventQueue::enableSensor(int32_t handle, int32_t samplingPeriodUs, - int maxBatchReportLatencyUs, int reservedFlags) const { + int64_t maxBatchReportLatencyUs, int reservedFlags) const { return mSensorEventConnection->enableDisable(handle, true, us2ns(samplingPeriodUs), us2ns(maxBatchReportLatencyUs), reservedFlags); } diff --git a/libs/sensor/include/sensor/SensorEventQueue.h b/libs/sensor/include/sensor/SensorEventQueue.h index 84b6ab25de..a03c7eeea3 100644 --- a/libs/sensor/include/sensor/SensorEventQueue.h +++ b/libs/sensor/include/sensor/SensorEventQueue.h @@ -84,7 +84,7 @@ public: status_t setEventRate(Sensor const* sensor, nsecs_t ns) const; // these are here only to support SensorManager.java - status_t enableSensor(int32_t handle, int32_t samplingPeriodUs, int maxBatchReportLatencyUs, + status_t enableSensor(int32_t handle, int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs, int reservedFlags) const; status_t disableSensor(int32_t handle) const; status_t flush() const; -- cgit v1.2.3-59-g8ed1b