Sensor

#include <sensor.h>

Structures and functions to receive and process sensor events in native code.

Summary

Enumerations

Anonymous Enum 59{
  ASENSOR_TYPE_INVALID = -1,
  ASENSOR_TYPE_ACCELEROMETER = 1,
  ASENSOR_TYPE_MAGNETIC_FIELD = 2,
  ASENSOR_TYPE_GYROSCOPE = 4,
  ASENSOR_TYPE_LIGHT = 5,
  ASENSOR_TYPE_PRESSURE = 6,
  ASENSOR_TYPE_PROXIMITY = 8,
  ASENSOR_TYPE_GRAVITY = 9,
  ASENSOR_TYPE_LINEAR_ACCELERATION = 10,
  ASENSOR_TYPE_ROTATION_VECTOR = 11,
  ASENSOR_TYPE_RELATIVE_HUMIDITY = 12,
  ASENSOR_TYPE_AMBIENT_TEMPERATURE = 13,
  ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14,
  ASENSOR_TYPE_GAME_ROTATION_VECTOR = 15,
  ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 16,
  ASENSOR_TYPE_SIGNIFICANT_MOTION = 17,
  ASENSOR_TYPE_STEP_DETECTOR = 18,
  ASENSOR_TYPE_STEP_COUNTER = 19,
  ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20,
  ASENSOR_TYPE_HEART_RATE = 21,
  ASENSOR_TYPE_POSE_6DOF = 28,
  ASENSOR_TYPE_STATIONARY_DETECT = 29,
  ASENSOR_TYPE_MOTION_DETECT = 30,
  ASENSOR_TYPE_HEART_BEAT = 31,
  ASENSOR_TYPE_DYNAMIC_SENSOR_META = 32,
  ASENSOR_TYPE_ADDITIONAL_INFO = 33,
  ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT = 34,
  ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35,
  ASENSOR_TYPE_HINGE_ANGLE = 36,
  ASENSOR_TYPE_HEAD_TRACKER = 37,
  ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES = 38,
  ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES = 39,
  ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED = 40,
  ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED = 41,
  ASENSOR_TYPE_HEADING = 42
}
enum
Sensor types.
Anonymous Enum 60{
  ASENSOR_STATUS_NO_CONTACT = -1,
  ASENSOR_STATUS_UNRELIABLE = 0,
  ASENSOR_STATUS_ACCURACY_LOW = 1,
  ASENSOR_STATUS_ACCURACY_MEDIUM = 2,
  ASENSOR_STATUS_ACCURACY_HIGH = 3
}
enum
Sensor accuracy measure.
Anonymous Enum 61{
  AREPORTING_MODE_INVALID = -1,
  AREPORTING_MODE_CONTINUOUS = 0,
  AREPORTING_MODE_ON_CHANGE = 1,
  AREPORTING_MODE_ONE_SHOT = 2,
  AREPORTING_MODE_SPECIAL_TRIGGER = 3
}
enum
Sensor Reporting Modes.
Anonymous Enum 62{
  ASENSOR_DIRECT_RATE_STOP = 0,
  ASENSOR_DIRECT_RATE_NORMAL = 1,
  ASENSOR_DIRECT_RATE_FAST = 2,
  ASENSOR_DIRECT_RATE_VERY_FAST = 3
}
enum
Sensor Direct Report Rates.
Anonymous Enum 63{
  ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1,
  ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2
}
enum
Sensor Direct Channel Type.
Anonymous Enum 64{
  ASENSOR_ADDITIONAL_INFO_BEGIN = 0,
  ASENSOR_ADDITIONAL_INFO_END = 1,
  ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY = 0x10000,
  ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE,
  ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION,
  ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT,
  ASENSOR_ADDITIONAL_INFO_SAMPLING
}
enum
Sensor Additional Info Types.

Typedefs

AAdditionalInfoEvent typedef
ADynamicSensorEvent typedef
AHardwareBuffer typedef
struct AHardwareBuffer
AHeadTrackerEvent typedef
AHeadingEvent typedef
struct AHeadingEvent
AHeartRateEvent typedef
ALimitedAxesImuEvent typedef
ALimitedAxesImuUncalibratedEvent typedef
AMetaDataEvent typedef
ASensor typedef
struct ASensor
ASensor is an opaque type that provides information about an hardware sensors.
ASensorEvent typedef
struct ASensorEvent
Information that describes a sensor event, refer to SensorEvent for additional documentation.
ASensorEventQueue typedef
ASensorEventQueue is an opaque type that provides access to ASensorEvent from hardware sensors.
ASensorList typedef
ASensorRef const *
ASensorList is an array of reference to ASensor.
ASensorManager typedef
ASensorManager is an opaque type to manage sensors and events queues.
ASensorRef typedef
ASensor const *
ASensorRef is a type for constant pointers to ASensor.
ASensorVector typedef
struct ASensorVector
A sensor event.
AUncalibratedEvent typedef

Variables

instead

Functions

ASensorEventQueue_disableSensor(ASensorEventQueue *queue, ASensor const *sensor)
int
Disable the selected sensor.
ASensorEventQueue_enableSensor(ASensorEventQueue *queue, ASensor const *sensor)
int
Enable the selected sensor at default sampling rate.
ASensorEventQueue_getEvents(ASensorEventQueue *queue, ASensorEvent *events, size_t count)
ssize_t
Retrieve pending events in sensor event queue.
ASensorEventQueue_hasEvents(ASensorEventQueue *queue)
int
Determine if a sensor event queue has pending event to be processed.
ASensorEventQueue_registerSensor(ASensorEventQueue *queue, ASensor const *sensor, int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs)
int
Enable the selected sensor with sampling and report parameters.
ASensorEventQueue_requestAdditionalInfoEvents(ASensorEventQueue *queue, bool enable)
int
Request that ASENSOR_TYPE_ADDITIONAL_INFO events to be delivered on the given ASensorEventQueue.
ASensorEventQueue_setEventRate(ASensorEventQueue *queue, ASensor const *sensor, int32_t usec)
int
Sets the delivery rate of events in microseconds for the given sensor.
ASensorManager_configureDirectReport(ASensorManager *manager, ASensor const *sensor, int channelId, int rate)
int
Configure direct report on channel.
ASensorManager_createEventQueue(ASensorManager *manager, ALooper *looper, int ident, ALooper_callbackFunc callback, void *data)
Creates a new sensor event queue and associate it with a looper.
ASensorManager_createHardwareBufferDirectChannel(ASensorManager *manager, AHardwareBuffer const *buffer, size_t size)
int
Create direct channel based on AHardwareBuffer.
ASensorManager_createSharedMemoryDirectChannel(ASensorManager *manager, int fd, size_t size)
int
Create direct channel based on shared memory.
ASensorManager_destroyDirectChannel(ASensorManager *manager, int channelId)
void
Destroy a direct channel.
ASensorManager_destroyEventQueue(ASensorManager *manager, ASensorEventQueue *queue)
int
Destroys the event queue and free all resources associated to it.
ASensorManager_getDefaultSensor(ASensorManager *manager, int type)
ASensor const *
Returns the default sensor for the given type, or NULL if no sensor of that type exists.
ASensorManager_getDefaultSensorEx(ASensorManager *manager, int type, bool wakeUp)
ASensor const *
Returns the default sensor with the given type and wakeUp properties or NULL if no sensor of this type and wakeUp properties exists.
ASensorManager_getDynamicSensorList(ASensorManager *manager, ASensorList *list)
ssize_t
Returns the list of available dynamic sensors.
ASensorManager_getInstance() __DEPRECATED_IN(26
Get a reference to the sensor manager.
ASensorManager_getInstanceForPackage(const char *packageName)
Get a reference to the sensor manager.
ASensorManager_getSensorList(ASensorManager *manager, ASensorList *list)
int
Returns the list of available sensors.
ASensor_getFifoMaxEventCount(ASensor const *sensor)
int
Returns the maximum size of batches for this sensor.
ASensor_getFifoReservedEventCount(ASensor const *sensor)
int
Returns the hardware batch fifo size reserved to this sensor.
ASensor_getHandle(ASensor const *sensor)
int
Returns the sensor's handle.
ASensor_getHighestDirectReportRateLevel(ASensor const *sensor)
int
Get the highest direct rate level that a sensor supports.
ASensor_getMinDelay(ASensor const *sensor)
int
Returns the minimum delay allowed between events in microseconds.
ASensor_getName(ASensor const *sensor)
const char *
Returns this sensor's name (non localized)
ASensor_getReportingMode(ASensor const *sensor)
int
Returns the reporting mode for this sensor.
ASensor_getResolution(ASensor const *sensor)
float
Returns this sensors's resolution.
ASensor_getStringType(ASensor const *sensor)
const char *
Returns this sensor's string type.
ASensor_getType(ASensor const *sensor)
int
Return this sensor's type.
ASensor_getVendor(ASensor const *sensor)
const char *
Returns this sensor's vendor's name (non localized)
ASensor_isDirectChannelTypeSupported(ASensor const *sensor, int channelType)
bool
Test if sensor supports a certain type of direct channel.
ASensor_isWakeUpSensor(ASensor const *sensor)
bool
Returns true if this is a wake up sensor, false otherwise.

Structs

AAdditionalInfoEvent
ADynamicSensorEvent
AHeadTrackerEvent
AHeadingEvent
AHeartRateEvent
ALimitedAxesImuEvent
ALimitedAxesImuUncalibratedEvent
AMetaDataEvent
ASensorEvent

Information that describes a sensor event, refer to SensorEvent for additional documentation.

ASensorVector

A sensor event.

AUncalibratedEvent

Enumerations

Anonymous Enum 59

 Anonymous Enum 59

Sensor types.

See android.hardware.SensorEvent::values for detailed explanations of the data returned for each of these types.

Properties
ASENSOR_TYPE_ACCELEROMETER

ASENSOR_TYPE_ACCELEROMETER reporting-mode: continuous

All values are in SI units (m/s^2) and measure the acceleration of the device minus the force of gravity.

ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES

ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES reporting-mode: continuous

The first three values are in SI units (m/s^2) and measure the acceleration of the device minus the force of gravity. The last three values indicate which acceleration axes are supported. A value of 1.0 means supported and a value of 0 means not supported.

ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED

ASENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED reporting-mode: continuous

The first three values are in SI units (m/s^2) and measure the acceleration of the device minus the force of gravity. The middle three values represent the estimated bias for each axis. The last three values indicate which acceleration axes are supported. A value of 1.0 means supported and a value of 0 means not supported.

ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED

ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED

ASENSOR_TYPE_ADDITIONAL_INFO

This sensor type is for delivering additional sensor information aside from sensor event data.

Additional information may include:

This type will never bind to a sensor. In other words, no sensor in the sensor list can have the type ASENSOR_TYPE_ADDITIONAL_INFO.

If a device supports the sensor additional information feature, it will report additional information events via ASensorEvent and will have the type of ASensorEvent set to ASENSOR_TYPE_ADDITIONAL_INFO and the sensor of ASensorEvent set to the handle of the reporting sensor.

Additional information reports consist of multiple frames ordered by ASensorEvent#timestamp. The first frame in the report will have a AAdditionalInfoEvent#type of ASENSOR_ADDITIONAL_INFO_BEGIN, and the last frame in the report will have a AAdditionalInfoEvent#type of ASENSOR_ADDITIONAL_INFO_END.

ASENSOR_TYPE_AMBIENT_TEMPERATURE

ASENSOR_TYPE_AMBIENT_TEMPERATURE

The ambient temperature sensor value is returned in Celcius.

ASENSOR_TYPE_DYNAMIC_SENSOR_META

A constant describing a dynamic sensor meta event sensor.

A sensor event of this type is received when a dynamic sensor is added to or removed from the system. This sensor type should always use special trigger report mode.

ASENSOR_TYPE_GAME_ROTATION_VECTOR

ASENSOR_TYPE_GAME_ROTATION_VECTOR

ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR

ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR

ASENSOR_TYPE_GRAVITY

ASENSOR_TYPE_GRAVITY

All values are in SI units (m/s^2) and measure the direction and magnitude of gravity. When the device is at rest, the output of the gravity sensor should be identical to that of the accelerometer.

ASENSOR_TYPE_GYROSCOPE

ASENSOR_TYPE_GYROSCOPE reporting-mode: continuous

All values are in radians/second and measure the rate of rotation around the X, Y and Z axis.

ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES

ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES reporting-mode: continuous

The first three values are in radians/second and measure the rate of rotation around the X, Y and Z axis. The last three values indicate which rotation axes are supported. A value of 1.0 means supported and a value of 0 means not supported.

ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED

ASENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED reporting-mode: continuous

The first three values are in radians/second and measure the rate of rotation around the X, Y and Z axis. The middle three values represent the estimated drift around each axis in rad/s. The last three values indicate which rotation axes are supported. A value of 1.0 means supported and a value of 0 means not supported.

ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED

ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED

ASENSOR_TYPE_HEADING

ASENSOR_TYPE_HEADING reporting-mode: continuous

A heading sensor measures the direction in which the device is pointing relative to true north in degrees.

ASENSOR_TYPE_HEAD_TRACKER

ASENSOR_TYPE_HEAD_TRACKER reporting-mode: continuous

Measures the orientation and rotational velocity of a user's head. Only for internal use within the Android system.

ASENSOR_TYPE_HEART_BEAT

ASENSOR_TYPE_HEART_BEAT

ASENSOR_TYPE_HEART_RATE

ASENSOR_TYPE_HEART_RATE

ASENSOR_TYPE_HINGE_ANGLE

ASENSOR_TYPE_HINGE_ANGLE reporting-mode: on-change

The hinge angle sensor value is returned in degrees.

ASENSOR_TYPE_INVALID

Invalid sensor type.

Returned by ASensor_getType as error value.

ASENSOR_TYPE_LIGHT

ASENSOR_TYPE_LIGHT reporting-mode: on-change

The light sensor value is returned in SI lux units.

ASENSOR_TYPE_LINEAR_ACCELERATION

ASENSOR_TYPE_LINEAR_ACCELERATION reporting-mode: continuous

All values are in SI units (m/s^2) and measure the acceleration of the device not including the force of gravity.

ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT

ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT

ASENSOR_TYPE_MAGNETIC_FIELD

ASENSOR_TYPE_MAGNETIC_FIELD reporting-mode: continuous

All values are in micro-Tesla (uT) and measure the geomagnetic field in the X, Y and Z axis.

ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED

ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED

ASENSOR_TYPE_MOTION_DETECT

ASENSOR_TYPE_MOTION_DETECT

ASENSOR_TYPE_POSE_6DOF

ASENSOR_TYPE_POSE_6DOF

ASENSOR_TYPE_PRESSURE

ASENSOR_TYPE_PRESSURE

The pressure sensor value is returned in hPa (millibar).

ASENSOR_TYPE_PROXIMITY

ASENSOR_TYPE_PROXIMITY reporting-mode: on-change

The proximity sensor which turns the screen off and back on during calls is the wake-up proximity sensor. Implement wake-up proximity sensor before implementing a non wake-up proximity sensor. For the wake-up proximity sensor set the flag SENSOR_FLAG_WAKE_UP. The value corresponds to the distance to the nearest object in centimeters.

ASENSOR_TYPE_RELATIVE_HUMIDITY

ASENSOR_TYPE_RELATIVE_HUMIDITY

The relative humidity sensor value is returned in percent.

ASENSOR_TYPE_ROTATION_VECTOR

ASENSOR_TYPE_ROTATION_VECTOR

ASENSOR_TYPE_SIGNIFICANT_MOTION

ASENSOR_TYPE_SIGNIFICANT_MOTION

ASENSOR_TYPE_STATIONARY_DETECT

ASENSOR_TYPE_STATIONARY_DETECT

ASENSOR_TYPE_STEP_COUNTER

ASENSOR_TYPE_STEP_COUNTER

ASENSOR_TYPE_STEP_DETECTOR

ASENSOR_TYPE_STEP_DETECTOR

Anonymous Enum 60

 Anonymous Enum 60

Sensor accuracy measure.

Properties
ASENSOR_STATUS_ACCURACY_HIGH

high accuracy

ASENSOR_STATUS_ACCURACY_LOW

low accuracy

ASENSOR_STATUS_ACCURACY_MEDIUM

medium accuracy

ASENSOR_STATUS_NO_CONTACT

no contact

ASENSOR_STATUS_UNRELIABLE

unreliable

Anonymous Enum 61

 Anonymous Enum 61

Sensor Reporting Modes.

Properties
AREPORTING_MODE_CONTINUOUS

continuous reporting

AREPORTING_MODE_INVALID

invalid reporting mode

AREPORTING_MODE_ONE_SHOT

on shot reporting

AREPORTING_MODE_ON_CHANGE

reporting on change

AREPORTING_MODE_SPECIAL_TRIGGER

special trigger reporting

Anonymous Enum 62

 Anonymous Enum 62

Sensor Direct Report Rates.

Properties
ASENSOR_DIRECT_RATE_FAST

nominal 200Hz

ASENSOR_DIRECT_RATE_NORMAL

nominal 50Hz

ASENSOR_DIRECT_RATE_STOP

stopped

ASENSOR_DIRECT_RATE_VERY_FAST

nominal 800Hz

Anonymous Enum 63

 Anonymous Enum 63

Sensor Direct Channel Type.

Properties
ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER

AHardwareBuffer.

ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY

shared memory created by ASharedMemory_create

Anonymous Enum 64

 Anonymous Enum 64

Sensor Additional Info Types.

Used to populate AAdditionalInfoEvent#type.

Properties
ASENSOR_ADDITIONAL_INFO_BEGIN

Marks the beginning of additional information frames.

ASENSOR_ADDITIONAL_INFO_END

Marks the end of additional information frames.

ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE

float: Celsius temperature

ASENSOR_ADDITIONAL_INFO_SAMPLING

float[2]: raw sample period in seconds, standard deviation of sampling period

ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT

Location and orientation of sensor element in the device frame: origin is the geometric center of the mobile device screen surface; the axis definition corresponds to Android sensor definitions.

float[12]: 3x4 matrix in row major order

ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY

Estimation of the delay that is not tracked by sensor timestamps.

This includes delay introduced by sensor front-end filtering, data transport, etc. float[2]: delay in seconds, standard deviation of estimated value

ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION

First three rows of a homogeneous matrix, which represents calibration to a three-element vector raw sensor reading.

float[12]: 3x4 matrix in row major order

Typedefs

AAdditionalInfoEvent

struct AAdditionalInfoEvent AAdditionalInfoEvent

ADynamicSensorEvent

struct ADynamicSensorEvent ADynamicSensorEvent

AHardwareBuffer

struct AHardwareBuffer AHardwareBuffer

AHeadTrackerEvent

struct AHeadTrackerEvent AHeadTrackerEvent

AHeadingEvent

struct AHeadingEvent AHeadingEvent

AHeartRateEvent

struct AHeartRateEvent AHeartRateEvent

ALimitedAxesImuEvent

struct ALimitedAxesImuEvent ALimitedAxesImuEvent

ALimitedAxesImuUncalibratedEvent

struct ALimitedAxesImuUncalibratedEvent ALimitedAxesImuUncalibratedEvent

AMetaDataEvent

struct AMetaDataEvent AMetaDataEvent

ASensorEvent

struct ASensorEvent ASensorEvent

Information that describes a sensor event, refer to SensorEvent for additional documentation.

NOTE: changes to this struct has to be backward compatible and reflected in sensors_event_t

ASensorEventQueue

struct ASensorEventQueue ASensorEventQueue

ASensorEventQueue is an opaque type that provides access to ASensorEvent from hardware sensors.

A new ASensorEventQueue can be obtained using ASensorManager_createEventQueue().

This file provides a set of functions to enable and disable sensors, check and get events, and set event rates on a ASensorEventQueue.

ASensorList

ASensorRef const * ASensorList

ASensorList is an array of reference to ASensor.

A ASensorList can be initialized using ASensorManager_getSensorList().

ASensorManager

struct ASensorManager ASensorManager

ASensorManager is an opaque type to manage sensors and events queues.

ASensorManager is a singleton that can be obtained using ASensorManager_getInstance().

This file provides a set of functions that uses ASensorManager to access and list hardware sensors, and create and destroy event queues:

ASensorRef

ASensor const * ASensorRef

ASensorRef is a type for constant pointers to ASensor.

This is used to define entry in ASensorList arrays.

ASensorVector

struct ASensorVector ASensorVector

A sensor event.

AUncalibratedEvent

struct AUncalibratedEvent AUncalibratedEvent

Variables

instead

ASensorManager Use ASensorManager_getInstanceForPackage instead

Functions

ASensorEventQueue_disableSensor

int ASensorEventQueue_disableSensor(
  ASensorEventQueue *queue,
  ASensor const *sensor
)

Disable the selected sensor.

Stop event reports from the sensor to specified sensor event queue.

Details
Parameters
queue
ASensorEventQueue to be changed
sensor
ASensor to be disabled
Returns
0 on success or a negative error code on failure.

ASensorEventQueue_enableSensor

int ASensorEventQueue_enableSensor(
  ASensorEventQueue *queue,
  ASensor const *sensor
)

Enable the selected sensor at default sampling rate.

Start event reports of a sensor to specified sensor event queue at a default rate.

Details
Parameters
queue
ASensorEventQueue for sensor event to be report to.
sensor
ASensor to be enabled.
Returns
0 on success or a negative error code on failure.

ASensorEventQueue_getEvents

ssize_t ASensorEventQueue_getEvents(
  ASensorEventQueue *queue,
  ASensorEvent *events,
  size_t count
)

Retrieve pending events in sensor event queue.

Retrieve next available events from the queue to a specified event array.

Examples:

ASensorEvent event;
ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1);

ASensorEvent eventBuffer[8];
ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8);

Details
Parameters
queue
ASensorEventQueue to get events from
events
pointer to an array of ASensorEvent.
count
max number of event that can be filled into array event.
Returns
number of events returned on success; negative error code when no events are pending or an error has occurred.

ASensorEventQueue_hasEvents

int ASensorEventQueue_hasEvents(
  ASensorEventQueue *queue
)

Determine if a sensor event queue has pending event to be processed.

Details
Parameters
queue
ASensorEventQueue to be queried
Returns
1 if the queue has events; 0 if it does not have events; or a negative value if there is an error.

ASensorEventQueue_registerSensor

int ASensorEventQueue_registerSensor(
  ASensorEventQueue *queue,
  ASensor const *sensor,
  int32_t samplingPeriodUs,
  int64_t maxBatchReportLatencyUs
)

Enable the selected sensor with sampling and report parameters.

Enable the selected sensor at a specified sampling period and max batch report latency. To disable sensor, use ASensorEventQueue_disableSensor.

Details
Parameters
queue
ASensorEventQueue for sensor event to be report to.
sensor
ASensor to be enabled.
samplingPeriodUs
sampling period of sensor in microseconds.
maxBatchReportLatencyUs
maximum time interval between two batches of sensor events are delievered in microseconds. For sensor streaming, set to 0.
Returns
0 on success or a negative error code on failure.

ASensorEventQueue_requestAdditionalInfoEvents

int ASensorEventQueue_requestAdditionalInfoEvents(
  ASensorEventQueue *queue,
  bool enable
)

Request that ASENSOR_TYPE_ADDITIONAL_INFO events to be delivered on the given ASensorEventQueue.

Sensor data events are always delivered to the ASensorEventQueue.

The ASENSOR_TYPE_ADDITIONAL_INFO events will be returned through ASensorEventQueue_getEvents. The client is responsible for checking ASensorEvent#type to determine the event type prior to handling of the event.

The client must be tolerant of any value for AAdditionalInfoEvent#type, as new values may be defined in the future and may delivered to the client.

Available since API level 29.

Details
Parameters
queue
ASensorEventQueue to configure
enable
true to request ASENSOR_TYPE_ADDITIONAL_INFO events, false to stop receiving events
Returns
0 on success or a negative error code on failure

ASensorEventQueue_setEventRate

int ASensorEventQueue_setEventRate(
  ASensorEventQueue *queue,
  ASensor const *sensor,
  int32_t usec
)

Sets the delivery rate of events in microseconds for the given sensor.

This function has to be called after ASensorEventQueue_enableSensor. Note that this is a hint only, generally event will arrive at a higher rate. It is an error to set a rate inferior to the value returned by ASensor_getMinDelay().

Details
Parameters
queue
ASensorEventQueue to which sensor event is delivered.
sensor
ASensor of which sampling rate to be updated.
usec
sensor sampling period (1/sampling rate) in microseconds
Returns
0 on sucess or a negative error code on failure.

ASensorManager_configureDirectReport

int ASensorManager_configureDirectReport(
  ASensorManager *manager,
  ASensor const *sensor,
  int channelId,
  int rate
)

Configure direct report on channel.

Configure sensor direct report on a direct channel: set rate to value other than ASENSOR_DIRECT_RATE_STOP so that sensor event can be directly written into the shared memory region used for creating the buffer. It returns a positive token which can be used for identify sensor events from different sensors on success. Calling with rate ASENSOR_DIRECT_RATE_STOP will stop direct report of the sensor specified in the channel.

To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to ASENSOR_DIRECT_RATE_STOP.

In order to successfully configure a direct report, the sensor has to support the specified rate and the channel type, which can be checked by ASensor_getHighestDirectReportRateLevel and ASensor_isDirectChannelTypeSupported, respectively.

Example:

ASensorManager *manager = ...;
ASensor *sensor = ...;
int channelId = ...;

ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST);

Available since API level 26.

Details
Parameters
manager
sensor
a ASensor to denote which sensor to be operate. It can be NULL if rate is ASENSOR_DIRECT_RATE_STOP, denoting stopping of all active sensor direct report.
channelId
rate
one of predefined ASENSOR_DIRECT_RATE_... that is supported by the sensor.
Returns
positive token for success or negative error code.

ASensorManager_createEventQueue

ASensorEventQueue * ASensorManager_createEventQueue(
  ASensorManager *manager,
  ALooper *looper,
  int ident,
  ALooper_callbackFunc callback,
  void *data
)

Creates a new sensor event queue and associate it with a looper.

"ident" is a identifier for the events that will be returned when calling ALooper_pollOnce(). The identifier must be >= 0, or ALOOPER_POLL_CALLBACK if providing a non-NULL callback.

ASensorManager_createHardwareBufferDirectChannel

int ASensorManager_createHardwareBufferDirectChannel(
  ASensorManager *manager,
  AHardwareBuffer const *buffer,
  size_t size
)

Create direct channel based on AHardwareBuffer.

Create a direct channel of ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER type to be used for configuring sensor direct report.

Available since API level 26.

Details
Parameters
manager
buffer
size
the intended size to be used, must be less or equal to size of buffer.
Returns
a positive integer as a channel id to be used in ASensorManager_destroyDirectChannel and ASensorManager_configureDirectReport, or value less or equal to 0 for failures.

ASensorManager_createSharedMemoryDirectChannel

int ASensorManager_createSharedMemoryDirectChannel(
  ASensorManager *manager,
  int fd,
  size_t size
)

Create direct channel based on shared memory.

Create a direct channel of ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY to be used for configuring sensor direct report.

Available since API level 26.

Details
Parameters
manager
fd
file descriptor representing a shared memory created by ASharedMemory_create
size
size to be used, must be less or equal to size of shared memory.
Returns
a positive integer as a channel id to be used in ASensorManager_destroyDirectChannel and ASensorManager_configureDirectReport, or value less or equal to 0 for failures.

ASensorManager_destroyDirectChannel

void ASensorManager_destroyDirectChannel(
  ASensorManager *manager,
  int channelId
)

Destroy a direct channel.

Destroy a direct channel previously created by using one of ASensorManager_create*DirectChannel() derivative functions. Note that the buffer used for creating the direct channel does not get destroyed with ASensorManager_destroyDirectChannel and has to be closed or released separately.

Available since API level 26.

Details
Parameters
manager
channelId

ASensorManager_destroyEventQueue

int ASensorManager_destroyEventQueue(
  ASensorManager *manager,
  ASensorEventQueue *queue
)

Destroys the event queue and free all resources associated to it.

ASensorManager_getDefaultSensor

ASensor const * ASensorManager_getDefaultSensor(
  ASensorManager *manager,
  int type
)

Returns the default sensor for the given type, or NULL if no sensor of that type exists.

ASensorManager_getDefaultSensorEx

ASensor const * ASensorManager_getDefaultSensorEx(
  ASensorManager *manager,
  int type,
  bool wakeUp
)

Returns the default sensor with the given type and wakeUp properties or NULL if no sensor of this type and wakeUp properties exists.

Available since API level 21.

ASensorManager_getDynamicSensorList

ssize_t ASensorManager_getDynamicSensorList(
  ASensorManager *manager,
  ASensorList *list
)

Returns the list of available dynamic sensors.

If there are no dynamic sensors available, returns nullptr in list.

Each time this is called, the previously returned list is deallocated and must no longer be used.

Clients should call this if they receive a sensor update from ASENSOR_TYPE_DYNAMIC_SENSOR_META indicating the sensors have changed. If this happens, previously received lists from this method will be stale.

Available since API level 33.

Details
Parameters
manager
list
the returned list of dynamic sensors.
Returns
positive number of returned sensors or negative error code. BAD_VALUE: manager is NULL.

ASensorManager_getInstance

ASensorManager * ASensorManager_getInstance() __DEPRECATED_IN(26

Get a reference to the sensor manager.

ASensorManager is a singleton per package as different packages may have access to different sensors.

Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead.

Example:

ASensorManager* sensorManager = ASensorManager_getInstance();

ASensorManager_getInstanceForPackage

ASensorManager * ASensorManager_getInstanceForPackage(
  const char *packageName
)

Get a reference to the sensor manager.

ASensorManager is a singleton per package as different packages may have access to different sensors.

Example:

ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz");

Available since API level 26.

ASensorManager_getSensorList

int ASensorManager_getSensorList(
  ASensorManager *manager,
  ASensorList *list
)

Returns the list of available sensors.

The returned list is owned by the sensor manager and will not change between calls to this function.

Details
Parameters
manager
list
the returned list of sensors.
Returns
positive number of returned sensors or negative error code. BAD_VALUE: manager is NULL.

ASensor_getFifoMaxEventCount

int ASensor_getFifoMaxEventCount(
  ASensor const *sensor
)

Returns the maximum size of batches for this sensor.

Batches will often be smaller, as the hardware fifo might be used for other sensors.

Available since API level 21.

ASensor_getFifoReservedEventCount

int ASensor_getFifoReservedEventCount(
  ASensor const *sensor
)

Returns the hardware batch fifo size reserved to this sensor.

Available since API level 21.

ASensor_getHandle

int ASensor_getHandle(
  ASensor const *sensor
)

Returns the sensor's handle.

The handle identifies the sensor within the system and is included in the sensor field of ASensorEvent, including those sent with type ASENSOR_TYPE_ADDITIONAL_INFO.

A sensor's handle is able to be used to map ASENSOR_TYPE_ADDITIONAL_INFO events to the sensor that generated the event.

It is important to note that the value returned by ASensor_getHandle is not the same as the value returned by the Java API android.hardware.Sensor's getId() and no mapping exists between the values.

Available since API level 29.

ASensor_getHighestDirectReportRateLevel

int ASensor_getHighestDirectReportRateLevel(
  ASensor const *sensor
)

Get the highest direct rate level that a sensor supports.

Available since API level 26.

Details
Parameters
sensor
a ASensor to denote the sensor to be checked.
Returns
a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor. If return value is ASENSOR_DIRECT_RATE_STOP, it means the sensor does not support direct report.

ASensor_getMinDelay

int ASensor_getMinDelay(
  ASensor const *sensor
)

Returns the minimum delay allowed between events in microseconds.

A value of zero means that this sensor doesn't report events at a constant rate, but rather only when a new data is available.

ASensor_getName

const char * ASensor_getName(
  ASensor const *sensor
)

Returns this sensor's name (non localized)

ASensor_getReportingMode

int ASensor_getReportingMode(
  ASensor const *sensor
)

Returns the reporting mode for this sensor.

One of AREPORTING_MODE_* constants.

Available since API level 21.

ASensor_getResolution

float ASensor_getResolution(
  ASensor const *sensor
)

Returns this sensors's resolution.

ASensor_getStringType

const char * ASensor_getStringType(
  ASensor const *sensor
)

Returns this sensor's string type.

Available since API level 21.

ASensor_getType

int ASensor_getType(
  ASensor const *sensor
)

Return this sensor's type.

ASensor_getVendor

const char * ASensor_getVendor(
  ASensor const *sensor
)

Returns this sensor's vendor's name (non localized)

ASensor_isDirectChannelTypeSupported

bool ASensor_isDirectChannelTypeSupported(
  ASensor const *sensor,
  int channelType
)

Test if sensor supports a certain type of direct channel.

Available since API level 26.

Details
Parameters
sensor
a ASensor to denote the sensor to be checked.
channelType
Returns
true if sensor supports the specified direct channel type.

ASensor_isWakeUpSensor

bool ASensor_isWakeUpSensor(
  ASensor const *sensor
)

Returns true if this is a wake up sensor, false otherwise.

Available since API level 21.