blob: 6447844b061cd6978bb39531b80dad6418fa0359 [file] [log] [blame]
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070017/**
Leon Scroggins III4883c522020-01-30 15:10:11 -050018 * Structures and functions to receive and process sensor events in
19 * native code.
20 *
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070021 * @addtogroup Sensor
22 * @{
23 */
24
25/**
26 * @file sensor.h
27 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070028
29#ifndef ANDROID_SENSOR_H
30#define ANDROID_SENSOR_H
31
32/******************************************************************
33 *
34 * IMPORTANT NOTICE:
35 *
36 * This file is part of Android's set of stable system headers
37 * exposed by the Android NDK (Native Development Kit).
38 *
39 * Third-party source AND binary code relies on the definitions
40 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
41 *
42 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
43 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
44 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
45 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
46 */
47
Mathias Agopiane1c61d32012-03-23 14:19:36 -070048#include <android/looper.h>
49
Dan Albert8f860fd2017-04-25 12:24:28 -070050#include <stdbool.h>
Peng Xuda8385c2017-02-28 20:19:47 -080051#include <sys/types.h>
52#include <math.h>
53#include <stdint.h>
54
Elliott Hughesb7425072021-01-26 14:55:48 -080055#if !defined(__INTRODUCED_IN)
56#define __INTRODUCED_IN(__api_level) /* nothing */
57#endif
58#if !defined(__DEPRECATED_IN)
59#define __DEPRECATED_IN(__api_level) __attribute__((__deprecated__))
60#endif
61
Mathias Agopiane1c61d32012-03-23 14:19:36 -070062#ifdef __cplusplus
63extern "C" {
64#endif
65
Peng Xu47cddca2017-02-15 23:31:22 -080066typedef struct AHardwareBuffer AHardwareBuffer;
Mathias Agopiane1c61d32012-03-23 14:19:36 -070067
Peng Xuda8385c2017-02-28 20:19:47 -080068#define ASENSOR_RESOLUTION_INVALID (nanf(""))
69#define ASENSOR_FIFO_COUNT_INVALID (-1)
70#define ASENSOR_DELAY_INVALID INT32_MIN
Brian Stack8228fa72019-01-04 14:15:13 -080071#define ASENSOR_INVALID (-1)
Peng Xuda8385c2017-02-28 20:19:47 -080072
Elliott Hughesf78be362018-01-23 15:33:56 -080073/* (Keep in sync with hardware/sensors-base.h and Sensor.java.) */
74
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070075/**
76 * Sensor types.
Elliott Hughesf78be362018-01-23 15:33:56 -080077 *
78 * See
79 * [android.hardware.SensorEvent#values](https://developer.android.com/reference/android/hardware/SensorEvent.html#values)
80 * for detailed explanations of the data returned for each of these types.
Mathias Agopiane1c61d32012-03-23 14:19:36 -070081 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070082enum {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070083 /**
Peng Xu37317b62017-03-07 17:49:31 -080084 * Invalid sensor type. Returned by {@link ASensor_getType} as error value.
85 */
86 ASENSOR_TYPE_INVALID = -1,
87 /**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070088 * {@link ASENSOR_TYPE_ACCELEROMETER}
89 * reporting-mode: continuous
90 *
91 * All values are in SI units (m/s^2) and measure the acceleration of the
92 * device minus the force of gravity.
93 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -070094 ASENSOR_TYPE_ACCELEROMETER = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070095 /**
96 * {@link ASENSOR_TYPE_MAGNETIC_FIELD}
97 * reporting-mode: continuous
98 *
99 * All values are in micro-Tesla (uT) and measure the geomagnetic
100 * field in the X, Y and Z axis.
101 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700102 ASENSOR_TYPE_MAGNETIC_FIELD = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700103 /**
104 * {@link ASENSOR_TYPE_GYROSCOPE}
105 * reporting-mode: continuous
106 *
107 * All values are in radians/second and measure the rate of rotation
108 * around the X, Y and Z axis.
109 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700110 ASENSOR_TYPE_GYROSCOPE = 4,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700111 /**
112 * {@link ASENSOR_TYPE_LIGHT}
113 * reporting-mode: on-change
114 *
115 * The light sensor value is returned in SI lux units.
116 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700117 ASENSOR_TYPE_LIGHT = 5,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700118 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800119 * {@link ASENSOR_TYPE_PRESSURE}
120 *
121 * The pressure sensor value is returned in hPa (millibar).
122 */
123 ASENSOR_TYPE_PRESSURE = 6,
124 /**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700125 * {@link ASENSOR_TYPE_PROXIMITY}
126 * reporting-mode: on-change
127 *
128 * The proximity sensor which turns the screen off and back on during calls is the
129 * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
130 * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
131 * SENSOR_FLAG_WAKE_UP.
132 * The value corresponds to the distance to the nearest object in centimeters.
133 */
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700134 ASENSOR_TYPE_PROXIMITY = 8,
135 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800136 * {@link ASENSOR_TYPE_GRAVITY}
137 *
138 * All values are in SI units (m/s^2) and measure the direction and
139 * magnitude of gravity. When the device is at rest, the output of
140 * the gravity sensor should be identical to that of the accelerometer.
141 */
142 ASENSOR_TYPE_GRAVITY = 9,
143 /**
Johan Euphrosine7d319fc2015-08-20 18:13:43 -0700144 * {@link ASENSOR_TYPE_LINEAR_ACCELERATION}
145 * reporting-mode: continuous
146 *
147 * All values are in SI units (m/s^2) and measure the acceleration of the
148 * device not including the force of gravity.
149 */
Elliott Hughesf78be362018-01-23 15:33:56 -0800150 ASENSOR_TYPE_LINEAR_ACCELERATION = 10,
151 /**
152 * {@link ASENSOR_TYPE_ROTATION_VECTOR}
153 */
154 ASENSOR_TYPE_ROTATION_VECTOR = 11,
155 /**
156 * {@link ASENSOR_TYPE_RELATIVE_HUMIDITY}
157 *
158 * The relative humidity sensor value is returned in percent.
159 */
160 ASENSOR_TYPE_RELATIVE_HUMIDITY = 12,
161 /**
162 * {@link ASENSOR_TYPE_AMBIENT_TEMPERATURE}
163 *
164 * The ambient temperature sensor value is returned in Celcius.
165 */
166 ASENSOR_TYPE_AMBIENT_TEMPERATURE = 13,
167 /**
168 * {@link ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED}
169 */
170 ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14,
171 /**
172 * {@link ASENSOR_TYPE_GAME_ROTATION_VECTOR}
173 */
174 ASENSOR_TYPE_GAME_ROTATION_VECTOR = 15,
175 /**
176 * {@link ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED}
177 */
178 ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 16,
179 /**
180 * {@link ASENSOR_TYPE_SIGNIFICANT_MOTION}
181 */
182 ASENSOR_TYPE_SIGNIFICANT_MOTION = 17,
183 /**
184 * {@link ASENSOR_TYPE_STEP_DETECTOR}
185 */
186 ASENSOR_TYPE_STEP_DETECTOR = 18,
187 /**
188 * {@link ASENSOR_TYPE_STEP_COUNTER}
189 */
190 ASENSOR_TYPE_STEP_COUNTER = 19,
191 /**
192 * {@link ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR}
193 */
194 ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20,
195 /**
196 * {@link ASENSOR_TYPE_HEART_RATE}
197 */
198 ASENSOR_TYPE_HEART_RATE = 21,
199 /**
200 * {@link ASENSOR_TYPE_POSE_6DOF}
201 */
202 ASENSOR_TYPE_POSE_6DOF = 28,
203 /**
204 * {@link ASENSOR_TYPE_STATIONARY_DETECT}
205 */
206 ASENSOR_TYPE_STATIONARY_DETECT = 29,
207 /**
208 * {@link ASENSOR_TYPE_MOTION_DETECT}
209 */
210 ASENSOR_TYPE_MOTION_DETECT = 30,
211 /**
212 * {@link ASENSOR_TYPE_HEART_BEAT}
213 */
214 ASENSOR_TYPE_HEART_BEAT = 31,
215 /**
Brian Stackccd88432019-01-08 17:04:18 -0800216 * This sensor type is for delivering additional sensor information aside
217 * from sensor event data.
218 *
219 * Additional information may include:
220 * - {@link ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE}
221 * - {@link ASENSOR_ADDITIONAL_INFO_SAMPLING}
222 * - {@link ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT}
223 * - {@link ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY}
224 * - {@link ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION}
225 *
226 * This type will never bind to a sensor. In other words, no sensor in the
227 * sensor list can have the type {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
228 *
229 * If a device supports the sensor additional information feature, it will
230 * report additional information events via {@link ASensorEvent} and will
231 * have {@link ASensorEvent#type} set to
232 * {@link ASENSOR_TYPE_ADDITIONAL_INFO} and {@link ASensorEvent#sensor} set
233 * to the handle of the reporting sensor.
234 *
235 * Additional information reports consist of multiple frames ordered by
236 * {@link ASensorEvent#timestamp}. The first frame in the report will have
237 * a {@link AAdditionalInfoEvent#type} of
238 * {@link ASENSOR_ADDITIONAL_INFO_BEGIN}, and the last frame in the report
239 * will have a {@link AAdditionalInfoEvent#type} of
240 * {@link ASENSOR_ADDITIONAL_INFO_END}.
241 *
242 */
243 ASENSOR_TYPE_ADDITIONAL_INFO = 33,
244 /**
Elliott Hughesf78be362018-01-23 15:33:56 -0800245 * {@link ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT}
246 */
247 ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT = 34,
248 /**
249 * {@link ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED}
250 */
251 ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35,
Anthony Stangefdb1fc82020-01-16 15:02:48 -0500252 /**
253 * {@link ASENSOR_TYPE_HINGE_ANGLE}
Anthony Stanged7a703c2020-02-18 12:02:22 -0500254 * reporting-mode: on-change
255 *
256 * The hinge angle sensor value is returned in degrees.
Anthony Stangefdb1fc82020-01-16 15:02:48 -0500257 */
258 ASENSOR_TYPE_HINGE_ANGLE = 36,
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700259};
260
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700261/**
262 * Sensor accuracy measure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700263 */
264enum {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700265 /** no contact */
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700266 ASENSOR_STATUS_NO_CONTACT = -1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700267 /** unreliable */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700268 ASENSOR_STATUS_UNRELIABLE = 0,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700269 /** low accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700270 ASENSOR_STATUS_ACCURACY_LOW = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700271 /** medium accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700272 ASENSOR_STATUS_ACCURACY_MEDIUM = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700273 /** high accuracy */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700274 ASENSOR_STATUS_ACCURACY_HIGH = 3
275};
276
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700277/**
Aravind Akella0e025c52014-06-03 19:19:57 -0700278 * Sensor Reporting Modes.
279 */
280enum {
Peng Xu37317b62017-03-07 17:49:31 -0800281 /** invalid reporting mode */
282 AREPORTING_MODE_INVALID = -1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700283 /** continuous reporting */
Aravind Akella0e025c52014-06-03 19:19:57 -0700284 AREPORTING_MODE_CONTINUOUS = 0,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700285 /** reporting on change */
Aravind Akella0e025c52014-06-03 19:19:57 -0700286 AREPORTING_MODE_ON_CHANGE = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700287 /** on shot reporting */
Aravind Akella0e025c52014-06-03 19:19:57 -0700288 AREPORTING_MODE_ONE_SHOT = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700289 /** special trigger reporting */
Peng Xu37317b62017-03-07 17:49:31 -0800290 AREPORTING_MODE_SPECIAL_TRIGGER = 3
Aravind Akella0e025c52014-06-03 19:19:57 -0700291};
292
Peng Xu47cddca2017-02-15 23:31:22 -0800293/**
294 * Sensor Direct Report Rates.
295 */
296enum {
297 /** stopped */
298 ASENSOR_DIRECT_RATE_STOP = 0,
299 /** nominal 50Hz */
300 ASENSOR_DIRECT_RATE_NORMAL = 1,
301 /** nominal 200Hz */
302 ASENSOR_DIRECT_RATE_FAST = 2,
303 /** nominal 800Hz */
304 ASENSOR_DIRECT_RATE_VERY_FAST = 3
305};
306
307/**
308 * Sensor Direct Channel Type.
309 */
310enum {
311 /** shared memory created by ASharedMemory_create */
312 ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1,
313 /** AHardwareBuffer */
314 ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2
315};
316
Brian Stackccd88432019-01-08 17:04:18 -0800317/**
318 * Sensor Additional Info Types.
319 *
320 * Used to populate {@link AAdditionalInfoEvent#type}.
321 */
322enum {
323 /** Marks the beginning of additional information frames */
324 ASENSOR_ADDITIONAL_INFO_BEGIN = 0,
325
326 /** Marks the end of additional information frames */
327 ASENSOR_ADDITIONAL_INFO_END = 1,
328
329 /**
330 * Estimation of the delay that is not tracked by sensor timestamps. This
331 * includes delay introduced by sensor front-end filtering, data transport,
332 * etc.
333 * float[2]: delay in seconds, standard deviation of estimated value
334 */
335 ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY = 0x10000,
336
337 /** float: Celsius temperature */
338 ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE,
339
340 /**
341 * First three rows of a homogeneous matrix, which represents calibration to
342 * a three-element vector raw sensor reading.
343 * float[12]: 3x4 matrix in row major order
344 */
345 ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION,
346
347 /**
348 * Location and orientation of sensor element in the device frame: origin is
349 * the geometric center of the mobile device screen surface; the axis
350 * definition corresponds to Android sensor definitions.
351 * float[12]: 3x4 matrix in row major order
352 */
353 ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT,
354
355 /**
356 * float[2]: raw sample period in seconds,
357 * standard deviation of sampling period
358 */
359 ASENSOR_ADDITIONAL_INFO_SAMPLING,
360};
361
Aravind Akella0e025c52014-06-03 19:19:57 -0700362/*
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700363 * A few useful constants
364 */
365
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700366/** Earth's gravity in m/s^2 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700367#define ASENSOR_STANDARD_GRAVITY (9.80665f)
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700368/** Maximum magnetic field on Earth's surface in uT */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700369#define ASENSOR_MAGNETIC_FIELD_EARTH_MAX (60.0f)
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700370/** Minimum magnetic field on Earth's surface in uT*/
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700371#define ASENSOR_MAGNETIC_FIELD_EARTH_MIN (30.0f)
372
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700373/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700374 * A sensor event.
375 */
376
Peng Xu70b98382017-08-07 14:09:11 -0700377/* NOTE: changes to these structs have to be backward compatible */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700378typedef struct ASensorVector {
379 union {
380 float v[3];
381 struct {
382 float x;
383 float y;
384 float z;
385 };
386 struct {
387 float azimuth;
388 float pitch;
389 float roll;
390 };
391 };
392 int8_t status;
393 uint8_t reserved[3];
394} ASensorVector;
395
Aravind Akella724d91d2013-06-27 12:04:23 -0700396typedef struct AMetaDataEvent {
397 int32_t what;
398 int32_t sensor;
399} AMetaDataEvent;
400
401typedef struct AUncalibratedEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800402 union {
403 float uncalib[3];
404 struct {
405 float x_uncalib;
406 float y_uncalib;
407 float z_uncalib;
408 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700409 };
Peng Xu9e720462016-01-26 18:48:54 -0800410 union {
411 float bias[3];
412 struct {
413 float x_bias;
414 float y_bias;
415 float z_bias;
416 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700417 };
Aravind Akella724d91d2013-06-27 12:04:23 -0700418} AUncalibratedEvent;
419
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700420typedef struct AHeartRateEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800421 float bpm;
422 int8_t status;
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700423} AHeartRateEvent;
424
Peng Xu2576cb62016-01-20 00:22:09 -0800425typedef struct ADynamicSensorEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800426 int32_t connected;
427 int32_t handle;
Peng Xu2576cb62016-01-20 00:22:09 -0800428} ADynamicSensorEvent;
429
Brian Stackccd88432019-01-08 17:04:18 -0800430typedef struct AAdditionalInfoEvent {
Peng Xu9e720462016-01-26 18:48:54 -0800431 int32_t type;
432 int32_t serial;
433 union {
434 int32_t data_int32[14];
435 float data_float[14];
436 };
437} AAdditionalInfoEvent;
438
Peng Xu70b98382017-08-07 14:09:11 -0700439/* NOTE: changes to this struct has to be backward compatible */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700440typedef struct ASensorEvent {
441 int32_t version; /* sizeof(struct ASensorEvent) */
442 int32_t sensor;
443 int32_t type;
444 int32_t reserved0;
445 int64_t timestamp;
446 union {
Mathias Agopianba02cd22013-07-03 16:20:57 -0700447 union {
448 float data[16];
449 ASensorVector vector;
450 ASensorVector acceleration;
451 ASensorVector magnetic;
452 float temperature;
453 float distance;
454 float light;
455 float pressure;
Aravind Akella724d91d2013-06-27 12:04:23 -0700456 float relative_humidity;
457 AUncalibratedEvent uncalibrated_gyro;
458 AUncalibratedEvent uncalibrated_magnetic;
459 AMetaDataEvent meta_data;
Etienne Le Grand630e31d2014-05-22 17:15:08 -0700460 AHeartRateEvent heart_rate;
Peng Xu2576cb62016-01-20 00:22:09 -0800461 ADynamicSensorEvent dynamic_sensor_meta;
Peng Xu9e720462016-01-26 18:48:54 -0800462 AAdditionalInfoEvent additional_info;
Mathias Agopianba02cd22013-07-03 16:20:57 -0700463 };
464 union {
465 uint64_t data[8];
466 uint64_t step_counter;
467 } u64;
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700468 };
Aravind Akella9a844cf2014-02-11 18:58:52 -0800469
470 uint32_t flags;
471 int32_t reserved1[3];
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700472} ASensorEvent;
473
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700474struct ASensorManager;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700475/**
476 * {@link ASensorManager} is an opaque type to manage sensors and
477 * events queues.
478 *
479 * {@link ASensorManager} is a singleton that can be obtained using
480 * ASensorManager_getInstance().
481 *
482 * This file provides a set of functions that uses {@link
483 * ASensorManager} to access and list hardware sensors, and
484 * create and destroy event queues:
485 * - ASensorManager_getSensorList()
486 * - ASensorManager_getDefaultSensor()
487 * - ASensorManager_getDefaultSensorEx()
488 * - ASensorManager_createEventQueue()
489 * - ASensorManager_destroyEventQueue()
490 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700491typedef struct ASensorManager ASensorManager;
492
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700493
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700494struct ASensorEventQueue;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700495/**
496 * {@link ASensorEventQueue} is an opaque type that provides access to
497 * {@link ASensorEvent} from hardware sensors.
498 *
499 * A new {@link ASensorEventQueue} can be obtained using ASensorManager_createEventQueue().
500 *
501 * This file provides a set of functions to enable and disable
502 * sensors, check and get events, and set event rates on a {@link
503 * ASensorEventQueue}.
504 * - ASensorEventQueue_enableSensor()
505 * - ASensorEventQueue_disableSensor()
506 * - ASensorEventQueue_hasEvents()
507 * - ASensorEventQueue_getEvents()
508 * - ASensorEventQueue_setEventRate()
Brian Stack65089d52019-01-11 10:52:07 -0800509 * - ASensorEventQueue_requestAdditionalInfoEvents()
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700510 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700511typedef struct ASensorEventQueue ASensorEventQueue;
512
513struct ASensor;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700514/**
515 * {@link ASensor} is an opaque type that provides information about
516 * an hardware sensors.
517 *
518 * A {@link ASensor} pointer can be obtained using
519 * ASensorManager_getDefaultSensor(),
520 * ASensorManager_getDefaultSensorEx() or from a {@link ASensorList}.
521 *
522 * This file provides a set of functions to access properties of a
523 * {@link ASensor}:
524 * - ASensor_getName()
525 * - ASensor_getVendor()
526 * - ASensor_getType()
527 * - ASensor_getResolution()
528 * - ASensor_getMinDelay()
529 * - ASensor_getFifoMaxEventCount()
530 * - ASensor_getFifoReservedEventCount()
531 * - ASensor_getStringType()
532 * - ASensor_getReportingMode()
533 * - ASensor_isWakeUpSensor()
Brian Stack8228fa72019-01-04 14:15:13 -0800534 * - ASensor_getHandle()
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700535 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700536typedef struct ASensor ASensor;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700537/**
538 * {@link ASensorRef} is a type for constant pointers to {@link ASensor}.
539 *
540 * This is used to define entry in {@link ASensorList} arrays.
541 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700542typedef ASensor const* ASensorRef;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700543/**
544 * {@link ASensorList} is an array of reference to {@link ASensor}.
545 *
546 * A {@link ASensorList} can be initialized using ASensorManager_getSensorList().
547 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700548typedef ASensorRef const* ASensorList;
549
550/*****************************************************************************/
551
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700552/**
Svet Ganov5fa32d42015-05-07 10:50:59 -0700553 * Get a reference to the sensor manager. ASensorManager is a singleton
554 * per package as different packages may have access to different sensors.
555 *
556 * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead.
557 *
558 * Example:
559 *
560 * ASensorManager* sensorManager = ASensorManager_getInstance();
561 *
562 */
Elliott Hughesb7425072021-01-26 14:55:48 -0800563ASensorManager* ASensorManager_getInstance() __DEPRECATED_IN(26);
Svet Ganov5fa32d42015-05-07 10:50:59 -0700564
Peng Xu80df0162017-08-05 19:00:23 -0700565/**
Svet Ganov5fa32d42015-05-07 10:50:59 -0700566 * Get a reference to the sensor manager. ASensorManager is a singleton
567 * per package as different packages may have access to different sensors.
568 *
569 * Example:
570 *
Peng Xu80df0162017-08-05 19:00:23 -0700571 * ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz");
Svet Ganov5fa32d42015-05-07 10:50:59 -0700572 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700573 * Available since API level 26.
Svet Ganov5fa32d42015-05-07 10:50:59 -0700574 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700575ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26);
Svet Ganov5fa32d42015-05-07 10:50:59 -0700576
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700577/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700578 * Returns the list of available sensors.
579 */
580int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list);
581
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700582/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700583 * Returns the default sensor for the given type, or NULL if no sensor
Aravind Akellab37ba392014-08-05 14:53:07 -0700584 * of that type exists.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700585 */
586ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type);
587
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700588/**
Aravind Akellab37ba392014-08-05 14:53:07 -0700589 * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor
590 * of this type and wakeUp properties exists.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700591 *
592 * Available since API level 21.
Aravind Akellab37ba392014-08-05 14:53:07 -0700593 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700594ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp) __INTRODUCED_IN(21);
Aravind Akellab37ba392014-08-05 14:53:07 -0700595
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700596/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700597 * Creates a new sensor event queue and associate it with a looper.
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700598 *
599 * "ident" is a identifier for the events that will be returned when
600 * calling ALooper_pollOnce(). The identifier must be >= 0, or
601 * ALOOPER_POLL_CALLBACK if providing a non-NULL callback.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700602 */
603ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
604 ALooper* looper, int ident, ALooper_callbackFunc callback, void* data);
605
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700606/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700607 * Destroys the event queue and free all resources associated to it.
608 */
609int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue);
610
Peng Xu47cddca2017-02-15 23:31:22 -0800611/**
612 * Create direct channel based on shared memory
613 *
614 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} to be used
615 * for configuring sensor direct report.
616 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700617 * Available since API level 26.
618 *
Peng Xu47cddca2017-02-15 23:31:22 -0800619 * \param manager the {@link ASensorManager} instance obtained from
620 * {@link ASensorManager_getInstanceForPackage}.
621 * \param fd file descriptor representing a shared memory created by
622 * {@link ASharedMemory_create}
623 * \param size size to be used, must be less or equal to size of shared memory.
624 *
625 * \return a positive integer as a channel id to be used in
626 * {@link ASensorManager_destroyDirectChannel} and
627 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
628 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700629int ASensorManager_createSharedMemoryDirectChannel(ASensorManager* manager, int fd, size_t size) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800630
631/**
632 * Create direct channel based on AHardwareBuffer
633 *
634 * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER} type to be used
635 * for configuring sensor direct report.
636 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700637 * Available since API level 26.
638 *
Peng Xu47cddca2017-02-15 23:31:22 -0800639 * \param manager the {@link ASensorManager} instance obtained from
640 * {@link ASensorManager_getInstanceForPackage}.
641 * \param buffer {@link AHardwareBuffer} instance created by {@link AHardwareBuffer_allocate}.
642 * \param size the intended size to be used, must be less or equal to size of buffer.
643 *
644 * \return a positive integer as a channel id to be used in
645 * {@link ASensorManager_destroyDirectChannel} and
646 * {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
647 */
648int ASensorManager_createHardwareBufferDirectChannel(
Elliott Hughes9db409b2018-06-18 12:28:46 -0700649 ASensorManager* manager, AHardwareBuffer const * buffer, size_t size) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800650
651/**
652 * Destroy a direct channel
653 *
654 * Destroy a direct channel previously created using {@link ASensorManager_createDirectChannel}.
655 * The buffer used for creating direct channel does not get destroyed with
656 * {@link ASensorManager_destroy} and has to be close or released separately.
657 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700658 * Available since API level 26.
659 *
Peng Xu47cddca2017-02-15 23:31:22 -0800660 * \param manager the {@link ASensorManager} instance obtained from
661 * {@link ASensorManager_getInstanceForPackage}.
662 * \param channelId channel id (a positive integer) returned from
663 * {@link ASensorManager_createSharedMemoryDirectChannel} or
664 * {@link ASensorManager_createHardwareBufferDirectChannel}.
665 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700666void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800667
668/**
669 * Configure direct report on channel
670 *
671 * Configure sensor direct report on a direct channel: set rate to value other than
672 * {@link ASENSOR_DIRECT_RATE_STOP} so that sensor event can be directly
Peng Xuec53d022017-04-06 18:02:29 -0700673 * written into the shared memory region used for creating the buffer. It returns a positive token
674 * which can be used for identify sensor events from different sensors on success. Calling with rate
675 * {@link ASENSOR_DIRECT_RATE_STOP} will stop direct report of the sensor specified in the channel.
Peng Xu47cddca2017-02-15 23:31:22 -0800676 *
677 * To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to
678 * {@link ASENSOR_DIRECT_RATE_STOP}.
679 *
680 * In order to successfully configure a direct report, the sensor has to support the specified rate
681 * and the channel type, which can be checked by {@link ASensor_getHighestDirectReportRateLevel} and
682 * {@link ASensor_isDirectChannelTypeSupported}, respectively.
683 *
684 * Example:
Peng Xu47cddca2017-02-15 23:31:22 -0800685 *
Peng Xu80df0162017-08-05 19:00:23 -0700686 * ASensorManager *manager = ...;
687 * ASensor *sensor = ...;
688 * int channelId = ...;
689 *
690 * ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST);
Peng Xu47cddca2017-02-15 23:31:22 -0800691 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700692 * Available since API level 26.
693 *
Peng Xu47cddca2017-02-15 23:31:22 -0800694 * \param manager the {@link ASensorManager} instance obtained from
695 * {@link ASensorManager_getInstanceForPackage}.
696 * \param sensor a {@link ASensor} to denote which sensor to be operate. It can be NULL if rate
697 * is {@link ASENSOR_DIRECT_RATE_STOP}, denoting stopping of all active sensor
698 * direct report.
699 * \param channelId channel id (a positive integer) returned from
700 * {@link ASensorManager_createSharedMemoryDirectChannel} or
701 * {@link ASensorManager_createHardwareBufferDirectChannel}.
702 *
Peng Xuec53d022017-04-06 18:02:29 -0700703 * \return positive token for success or negative error code.
Peng Xu47cddca2017-02-15 23:31:22 -0800704 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700705int ASensorManager_configureDirectReport(ASensorManager* manager,
706 ASensor const* sensor, int channelId, int rate) __INTRODUCED_IN(26);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700707
708/*****************************************************************************/
709
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700710/**
Peng Xu80df0162017-08-05 19:00:23 -0700711 * Enable the selected sensor with sampling and report parameters
712 *
713 * Enable the selected sensor at a specified sampling period and max batch report latency.
714 * To disable sensor, use {@link ASensorEventQueue_disableSensor}.
715 *
716 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
717 * \param sensor {@link ASensor} to be enabled.
718 * \param samplingPeriodUs sampling period of sensor in microseconds.
719 * \param maxBatchReportLatencyus maximum time interval between two batch of sensor events are
720 * delievered in microseconds. For sensor streaming, set to 0.
721 * \return 0 on success or a negative error code on failure.
Aniroop Mathurda94fd82015-11-03 01:47:46 +0530722 */
723int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor,
Peng Xuda8385c2017-02-28 20:19:47 -0800724 int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs);
Aniroop Mathurda94fd82015-11-03 01:47:46 +0530725
726/**
Peng Xu80df0162017-08-05 19:00:23 -0700727 * Enable the selected sensor at default sampling rate.
728 *
729 * Start event reports of a sensor to specified sensor event queue at a default rate.
730 *
731 * \param queue {@link ASensorEventQueue} for sensor event to be report to.
732 * \param sensor {@link ASensor} to be enabled.
733 *
734 * \return 0 on success or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700735 */
736int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor);
737
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700738/**
Peng Xu80df0162017-08-05 19:00:23 -0700739 * Disable the selected sensor.
740 *
741 * Stop event reports from the sensor to specified sensor event queue.
742 *
743 * \param queue {@link ASensorEventQueue} to be changed
744 * \param sensor {@link ASensor} to be disabled
745 * \return 0 on success or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700746 */
747int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor);
748
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700749/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700750 * Sets the delivery rate of events in microseconds for the given sensor.
Peng Xu80df0162017-08-05 19:00:23 -0700751 *
752 * This function has to be called after {@link ASensorEventQueue_enableSensor}.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700753 * Note that this is a hint only, generally event will arrive at a higher
754 * rate. It is an error to set a rate inferior to the value returned by
755 * ASensor_getMinDelay().
Peng Xu80df0162017-08-05 19:00:23 -0700756 *
757 * \param queue {@link ASensorEventQueue} to which sensor event is delivered.
758 * \param sensor {@link ASensor} of which sampling rate to be updated.
759 * \param usec sensor sampling period (1/sampling rate) in microseconds
760 * \return 0 on sucess or a negative error code on failure.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700761 */
762int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec);
763
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700764/**
Peng Xu80df0162017-08-05 19:00:23 -0700765 * Determine if a sensor event queue has pending event to be processed.
766 *
767 * \param queue {@link ASensorEventQueue} to be queried
768 * \return 1 if the queue has events; 0 if it does not have events;
769 * or a negative value if there is an error.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700770 */
771int ASensorEventQueue_hasEvents(ASensorEventQueue* queue);
772
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700773/**
Peng Xu80df0162017-08-05 19:00:23 -0700774 * Retrieve pending events in sensor event queue
775 *
776 * Retrieve next available events from the queue to a specified event array.
777 *
778 * \param queue {@link ASensorEventQueue} to get events from
779 * \param events pointer to an array of {@link ASensorEvents}.
780 * \param count max number of event that can be filled into array event.
781 * \return number of events returned on success; negative error code when
782 * no events are pending or an error has occurred.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700783 *
784 * Examples:
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700785 *
Peng Xu80df0162017-08-05 19:00:23 -0700786 * ASensorEvent event;
787 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1);
788 *
789 * ASensorEvent eventBuffer[8];
790 * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700791 *
792 */
Peng Xuda8385c2017-02-28 20:19:47 -0800793ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700794
Brian Stack65089d52019-01-11 10:52:07 -0800795/**
796 * Request that {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to be delivered on
797 * the given {@link ASensorEventQueue}.
798 *
799 * Sensor data events are always delivered to the {@ASensorEventQueue}.
800 *
801 * The {@link ASENSOR_TYPE_ADDITIONAL_INFO} events will be returned through
802 * {@link ASensorEventQueue_getEvents}. The client is responsible for checking
803 * {@link ASensorEvent#type} to determine the event type prior to handling of
804 * the event.
805 *
806 * The client must be tolerant of any value for
807 * {@link AAdditionalInfoEvent#type}, as new values may be defined in the future
808 * and may delivered to the client.
809 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700810 * Available since API level 29.
811 *
Brian Stack65089d52019-01-11 10:52:07 -0800812 * \param queue {@link ASensorEventQueue} to configure
813 * \param enable true to request {@link ASENSOR_TYPE_ADDITIONAL_INFO} events,
814 * false to stop receiving events
815 * \return 0 on success or a negative error code on failure
816 */
Elliott Hughes3d70e532019-10-29 08:59:39 -0700817int ASensorEventQueue_requestAdditionalInfoEvents(ASensorEventQueue* queue, bool enable) __INTRODUCED_IN(29);
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700818
819/*****************************************************************************/
820
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700821/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700822 * Returns this sensor's name (non localized)
823 */
824const char* ASensor_getName(ASensor const* sensor);
825
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700826/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700827 * Returns this sensor's vendor's name (non localized)
828 */
829const char* ASensor_getVendor(ASensor const* sensor);
830
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700831/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700832 * Return this sensor's type
833 */
834int ASensor_getType(ASensor const* sensor);
835
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700836/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700837 * Returns this sensors's resolution
838 */
839float ASensor_getResolution(ASensor const* sensor);
840
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700841/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700842 * Returns the minimum delay allowed between events in microseconds.
843 * A value of zero means that this sensor doesn't report events at a
844 * constant rate, but rather only when a new data is available.
845 */
846int ASensor_getMinDelay(ASensor const* sensor);
847
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700848/**
Aravind Akella70018042014-04-07 22:52:37 +0000849 * Returns the maximum size of batches for this sensor. Batches will often be
850 * smaller, as the hardware fifo might be used for other sensors.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700851 *
852 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +0000853 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700854int ASensor_getFifoMaxEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +0000855
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700856/**
Aravind Akella70018042014-04-07 22:52:37 +0000857 * Returns the hardware batch fifo size reserved to this sensor.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700858 *
859 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +0000860 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700861int ASensor_getFifoReservedEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +0000862
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700863/**
Aravind Akella70018042014-04-07 22:52:37 +0000864 * Returns this sensor's string type.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700865 *
866 * Available since API level 21.
Aravind Akella70018042014-04-07 22:52:37 +0000867 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700868const char* ASensor_getStringType(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella70018042014-04-07 22:52:37 +0000869
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700870/**
Aravind Akella0e025c52014-06-03 19:19:57 -0700871 * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700872 *
873 * Available since API level 21.
Aravind Akella0e025c52014-06-03 19:19:57 -0700874 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700875int ASensor_getReportingMode(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akella0e025c52014-06-03 19:19:57 -0700876
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700877/**
Aravind Akellab37ba392014-08-05 14:53:07 -0700878 * Returns true if this is a wake up sensor, false otherwise.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700879 *
880 * Available since API level 21.
Aravind Akellab37ba392014-08-05 14:53:07 -0700881 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700882bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21);
Aravind Akellab37ba392014-08-05 14:53:07 -0700883
Peng Xu47cddca2017-02-15 23:31:22 -0800884/**
885 * Test if sensor supports a certain type of direct channel.
886 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700887 * Available since API level 26.
888 *
Peng Xu47cddca2017-02-15 23:31:22 -0800889 * \param sensor a {@link ASensor} to denote the sensor to be checked.
890 * \param channelType Channel type constant, either
891 * {@ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY}
892 * or {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER}.
893 * \returns true if sensor supports the specified direct channel type.
894 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700895bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType) __INTRODUCED_IN(26);
896
Peng Xu47cddca2017-02-15 23:31:22 -0800897/**
Elliott Hughes3d70e532019-10-29 08:59:39 -0700898 * Get the highest direct rate level that a sensor supports.
899 *
900 * Available since API level 26.
Peng Xu47cddca2017-02-15 23:31:22 -0800901 *
902 * \param sensor a {@link ASensor} to denote the sensor to be checked.
903 *
904 * \return a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor.
905 * If return value is {@link ASENSOR_DIRECT_RATE_STOP}, it means the sensor
906 * does not support direct report.
907 */
Elliott Hughes9db409b2018-06-18 12:28:46 -0700908int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_IN(26);
Peng Xu47cddca2017-02-15 23:31:22 -0800909
Brian Stack8228fa72019-01-04 14:15:13 -0800910/**
911 * Returns the sensor's handle.
912 *
913 * The handle identifies the sensor within the system and is included in the
914 * {@link ASensorEvent#sensor} field of sensor events, including those sent with type
915 * {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
916 *
917 * A sensor's handle is able to be used to map {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to the
918 * sensor that generated the event.
919 *
920 * It is important to note that the value returned by {@link ASensor_getHandle} is not the same as
921 * the value returned by the Java API {@link android.hardware.Sensor#getId} and no mapping exists
922 * between the values.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700923 *
924 * Available since API level 29.
Brian Stack8228fa72019-01-04 14:15:13 -0800925 */
Elliott Hughes3d70e532019-10-29 08:59:39 -0700926int ASensor_getHandle(ASensor const* sensor) __INTRODUCED_IN(29);
Brian Stack8228fa72019-01-04 14:15:13 -0800927
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700928#ifdef __cplusplus
929};
930#endif
931
932#endif // ANDROID_SENSOR_H
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700933
934/** @} */