blob: 63ee8d2e75d3bceb98eaef07eabd7444bd11a760 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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
17
18package android.hardware;
19
Nick Vaccarof5021f62015-01-23 15:09:45 -080020import android.annotation.SystemApi;
Peng Xua35b5532016-01-20 00:05:45 -080021import android.os.Build;
22
23import java.util.UUID;
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -070024
Mathias Agopian74cde2c2010-06-16 18:55:46 -070025/**
26 * Class representing a sensor. Use {@link SensorManager#getSensorList} to get
27 * the list of available Sensors.
Mathias Agopian0f791a72010-06-22 21:55:01 -070028 *
29 * @see SensorManager
30 * @see SensorEventListener
31 * @see SensorEvent
32 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033 */
Jeff Brown6a2ef122012-08-10 18:19:10 -070034public final class Sensor {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
Mathias Agopian74cde2c2010-06-16 18:55:46 -070036 /**
Scott Main92053f82013-06-13 16:32:50 -070037 * A constant describing an accelerometer sensor type.
38 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
39 * for more details.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 */
Mathias Agopian74cde2c2010-06-16 18:55:46 -070041 public static final int TYPE_ACCELEROMETER = 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
Mathias Agopian74cde2c2010-06-16 18:55:46 -070043 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +000044 * A constant string describing an accelerometer sensor type.
45 *
46 * @see #TYPE_ACCELEROMETER
47 */
48 public static final String STRING_TYPE_ACCELEROMETER = "android.sensor.accelerometer";
49
50 /**
Scott Main92053f82013-06-13 16:32:50 -070051 * A constant describing a magnetic field sensor type.
52 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
53 * for more details.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 */
55 public static final int TYPE_MAGNETIC_FIELD = 2;
Mathias Agopian74cde2c2010-06-16 18:55:46 -070056
57 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +000058 * A constant string describing a magnetic field sensor type.
59 *
60 * @see #TYPE_MAGNETIC_FIELD
61 */
62 public static final String STRING_TYPE_MAGNETIC_FIELD = "android.sensor.magnetic_field";
63
64 /**
Scott Main92053f82013-06-13 16:32:50 -070065 * A constant describing an orientation sensor type.
66 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
67 * for more details.
Mathias Agopian74cde2c2010-06-16 18:55:46 -070068 *
Mathias Agopian61a44932010-02-26 18:06:26 -080069 * @deprecated use {@link android.hardware.SensorManager#getOrientation
Mathias Agopian74cde2c2010-06-16 18:55:46 -070070 * SensorManager.getOrientation()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 */
Mathias Agopian61a44932010-02-26 18:06:26 -080072 @Deprecated
Mathias Agopian74cde2c2010-06-16 18:55:46 -070073 public static final int TYPE_ORIENTATION = 3;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
Aravind Akellacd9a7bb2014-04-07 22:55:21 +000075 /**
76 * A constant string describing an orientation sensor type.
77 *
78 * @see #TYPE_ORIENTATION
79 * @deprecated use {@link android.hardware.SensorManager#getOrientation
80 * SensorManager.getOrientation()} instead.
81 */
82 @Deprecated
83 public static final String STRING_TYPE_ORIENTATION = "android.sensor.orientation";
84
85 /**
86 * A constant describing a gyroscope sensor type.
Scott Main92053f82013-06-13 16:32:50 -070087 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
88 * for more details. */
Mathias Agopian74cde2c2010-06-16 18:55:46 -070089 public static final int TYPE_GYROSCOPE = 4;
90
Mike Lockwood4115c512009-11-03 10:35:43 -050091 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +000092 * A constant string describing a gyroscope sensor type.
93 *
94 * @see #TYPE_GYROSCOPE
95 */
96 public static final String STRING_TYPE_GYROSCOPE = "android.sensor.gyroscope";
97
98 /**
Scott Main92053f82013-06-13 16:32:50 -070099 * A constant describing a light sensor type.
100 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
101 * for more details.
Mike Lockwood4115c512009-11-03 10:35:43 -0500102 */
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700103 public static final int TYPE_LIGHT = 5;
Mathias Agopian210fc912010-02-26 13:51:39 -0800104
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000105 /**
106 * A constant string describing a light sensor type.
107 *
108 * @see #TYPE_LIGHT
109 */
110 public static final String STRING_TYPE_LIGHT = "android.sensor.light";
111
112 /**
113 * A constant describing a pressure sensor type.
Scott Main92053f82013-06-13 16:32:50 -0700114 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000115 * for more details.
116 */
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700117 public static final int TYPE_PRESSURE = 6;
Mathias Agopian210fc912010-02-26 13:51:39 -0800118
Mathias Agopian462db222011-03-22 18:44:26 -0700119 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000120 * A constant string describing a pressure sensor type.
121 *
122 * @see #TYPE_PRESSURE
123 */
124 public static final String STRING_TYPE_PRESSURE = "android.sensor.pressure";
125
126 /**
Mathias Agopian462db222011-03-22 18:44:26 -0700127 * A constant describing a temperature sensor type
128 *
129 * @deprecated use
130 * {@link android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE
131 * Sensor.TYPE_AMBIENT_TEMPERATURE} instead.
132 */
133 @Deprecated
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700134 public static final int TYPE_TEMPERATURE = 7;
Mathias Agopian210fc912010-02-26 13:51:39 -0800135
Mike Lockwood4115c512009-11-03 10:35:43 -0500136 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000137 * A constant string describing a temperature sensor type
138 *
139 * @see #TYPE_TEMPERATURE
140 * @deprecated use
141 * {@link android.hardware.Sensor#STRING_TYPE_AMBIENT_TEMPERATURE
142 * Sensor.STRING_TYPE_AMBIENT_TEMPERATURE} instead.
143 */
144 @Deprecated
145 public static final String STRING_TYPE_TEMPERATURE = "android.sensor.temperature";
146
147 /**
Aravind Akella2f8b9142014-05-12 14:39:29 -0700148 * A constant describing a proximity sensor type. This is a wake up sensor.
Scott Main92053f82013-06-13 16:32:50 -0700149 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
150 * for more details.
Aravind Akella2f8b9142014-05-12 14:39:29 -0700151 * @see #isWakeUpSensor()
Mike Lockwood4115c512009-11-03 10:35:43 -0500152 */
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700153 public static final int TYPE_PROXIMITY = 8;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700155 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000156 * A constant string describing a proximity sensor type.
157 *
158 * @see #TYPE_PROXIMITY
159 */
160 public static final String STRING_TYPE_PROXIMITY = "android.sensor.proximity";
161
162 /**
Kevin Powellf35fd952010-07-19 19:10:40 -0700163 * A constant describing a gravity sensor type.
Scott Main92053f82013-06-13 16:32:50 -0700164 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
Kevin Powellf35fd952010-07-19 19:10:40 -0700165 * for more details.
166 */
167 public static final int TYPE_GRAVITY = 9;
168
169 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000170 * A constant string describing a gravity sensor type.
171 *
172 * @see #TYPE_GRAVITY
173 */
174 public static final String STRING_TYPE_GRAVITY = "android.sensor.gravity";
175
176 /**
Kevin Powellf35fd952010-07-19 19:10:40 -0700177 * A constant describing a linear acceleration sensor type.
Scott Main92053f82013-06-13 16:32:50 -0700178 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
Kevin Powellf35fd952010-07-19 19:10:40 -0700179 * for more details.
180 */
181 public static final int TYPE_LINEAR_ACCELERATION = 10;
182
183 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000184 * A constant string describing a linear acceleration sensor type.
185 *
186 * @see #TYPE_LINEAR_ACCELERATION
187 */
188 public static final String STRING_TYPE_LINEAR_ACCELERATION =
189 "android.sensor.linear_acceleration";
190
191 /**
Kevin Powellf35fd952010-07-19 19:10:40 -0700192 * A constant describing a rotation vector sensor type.
Scott Main92053f82013-06-13 16:32:50 -0700193 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
Kevin Powellf35fd952010-07-19 19:10:40 -0700194 * for more details.
195 */
196 public static final int TYPE_ROTATION_VECTOR = 11;
197
Urs Fleisch58190512010-12-29 17:02:02 +0100198 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000199 * A constant string describing a rotation vector sensor type.
200 *
201 * @see #TYPE_ROTATION_VECTOR
202 */
203 public static final String STRING_TYPE_ROTATION_VECTOR = "android.sensor.rotation_vector";
204
205 /**
Urs Fleisch58190512010-12-29 17:02:02 +0100206 * A constant describing a relative humidity sensor type.
Scott Main92053f82013-06-13 16:32:50 -0700207 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
Urs Fleisch58190512010-12-29 17:02:02 +0100208 * for more details.
209 */
210 public static final int TYPE_RELATIVE_HUMIDITY = 12;
211
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000212 /**
213 * A constant string describing a relative humidity sensor type
214 *
215 * @see #TYPE_RELATIVE_HUMIDITY
216 */
217 public static final String STRING_TYPE_RELATIVE_HUMIDITY = "android.sensor.relative_humidity";
218
219 /**
220 * A constant describing an ambient temperature sensor type.
Scott Main92053f82013-06-13 16:32:50 -0700221 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000222 * for more details.
223 */
Mathias Agopian462db222011-03-22 18:44:26 -0700224 public static final int TYPE_AMBIENT_TEMPERATURE = 13;
225
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800226 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000227 * A constant string describing an ambient temperature sensor type.
228 *
229 * @see #TYPE_AMBIENT_TEMPERATURE
230 */
231 public static final String STRING_TYPE_AMBIENT_TEMPERATURE =
232 "android.sensor.ambient_temperature";
233
234 /**
Scott Main92053f82013-06-13 16:32:50 -0700235 * A constant describing an uncalibrated magnetic field sensor type.
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800236 * <p>
Scott Main92053f82013-06-13 16:32:50 -0700237 * Similar to {@link #TYPE_MAGNETIC_FIELD} but the hard iron calibration (device calibration
238 * due to distortions that arise from magnetized iron, steel or permanent magnets on the
239 * device) is not considered in the given sensor values. However, such hard iron bias values
240 * are returned to you separately in the result {@link android.hardware.SensorEvent#values}
Aravind Akella4b628cb2013-08-05 18:43:55 -0700241 * so you may use them for custom calibrations.
Scott Main92053f82013-06-13 16:32:50 -0700242 * <p>Also, no periodic calibration is performed
243 * (i.e. there are no discontinuities in the data stream while using this sensor) and
244 * assumptions that the magnetic field is due to the Earth's poles is avoided, but
245 * factory calibration and temperature compensation have been performed.
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800246 * </p>
Scott Main92053f82013-06-13 16:32:50 -0700247 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} for more
248 * details.
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800249 */
250 public static final int TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14;
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000251 /**
252 * A constant string describing an uncalibrated magnetic field sensor type.
253 *
254 * @see #TYPE_MAGNETIC_FIELD_UNCALIBRATED
255 */
256 public static final String STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED =
257 "android.sensor.magnetic_field_uncalibrated";
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800258
259 /**
Scott Main92053f82013-06-13 16:32:50 -0700260 * A constant describing an uncalibrated rotation vector sensor type.
261 * <p>Identical to {@link #TYPE_ROTATION_VECTOR} except that it doesn't
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800262 * use the geomagnetic field. Therefore the Y axis doesn't
263 * point north, but instead to some other reference, that reference is
264 * allowed to drift by the same order of magnitude as the gyroscope
265 * drift around the Z axis.
266 * <p>
267 * In the ideal case, a phone rotated and returning to the same real-world
268 * orientation should report the same game rotation vector
269 * (without using the earth's geomagnetic field). However, the orientation
270 * may drift somewhat over time.
271 * </p>
Scott Main92053f82013-06-13 16:32:50 -0700272 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} for more
273 * details.
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800274 */
Etienne Le Grand819239e2014-04-05 04:47:14 +0000275 public static final int TYPE_GAME_ROTATION_VECTOR = 15;
Etienne Le Grandfd53d832014-03-24 21:29:28 -0700276
277 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000278 * A constant string describing an uncalibrated rotation vector sensor type.
279 *
280 * @see #TYPE_GAME_ROTATION_VECTOR
281 */
282 public static final String STRING_TYPE_GAME_ROTATION_VECTOR =
283 "android.sensor.game_rotation_vector";
284
285 /**
Scott Main92053f82013-06-13 16:32:50 -0700286 * A constant describing an uncalibrated gyroscope sensor type.
287 * <p>Similar to {@link #TYPE_GYROSCOPE} but no gyro-drift compensation has been performed
288 * to adjust the given sensor values. However, such gyro-drift bias values
289 * are returned to you separately in the result {@link android.hardware.SensorEvent#values}
290 * so you may use them for custom calibrations.
291 * <p>Factory calibration and temperature compensation is still applied
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800292 * to the rate of rotation (angular speeds).
293 * </p>
Scott Main92053f82013-06-13 16:32:50 -0700294 * <p> See {@link android.hardware.SensorEvent#values SensorEvent.values} for more
295 * details.
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800296 */
297 public static final int TYPE_GYROSCOPE_UNCALIBRATED = 16;
298
299 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000300 * A constant string describing an uncalibrated gyroscope sensor type.
301 *
302 * @see #TYPE_GYROSCOPE_UNCALIBRATED
303 */
304 public static final String STRING_TYPE_GYROSCOPE_UNCALIBRATED =
305 "android.sensor.gyroscope_uncalibrated";
306
307 /**
Aravind Akella4b628cb2013-08-05 18:43:55 -0700308 * A constant describing a significant motion trigger sensor.
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800309 * <p>
310 * It triggers when an event occurs and then automatically disables
311 * itself. The sensor continues to operate while the device is asleep
312 * and will automatically wake the device to notify when significant
313 * motion is detected. The application does not need to hold any wake
Aravind Akella2f8b9142014-05-12 14:39:29 -0700314 * locks for this sensor to trigger. This is a wake up sensor.
Scott Main92053f82013-06-13 16:32:50 -0700315 * <p>See {@link TriggerEvent} for more details.
Aravind Akella2f8b9142014-05-12 14:39:29 -0700316 *
317 * @see #isWakeUpSensor()
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800318 */
319 public static final int TYPE_SIGNIFICANT_MOTION = 17;
320
321 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000322 * A constant string describing a significant motion trigger sensor.
323 *
324 * @see #TYPE_SIGNIFICANT_MOTION
325 */
326 public static final String STRING_TYPE_SIGNIFICANT_MOTION =
327 "android.sensor.significant_motion";
328
329 /**
Aravind Akella4b628cb2013-08-05 18:43:55 -0700330 * A constant describing a step detector sensor.
331 * <p>
332 * A sensor of this type triggers an event each time a step is taken by the user. The only
333 * allowed value to return is 1.0 and an event is generated for each step. Like with any other
334 * event, the timestamp indicates when the event (here the step) occurred, this corresponds to
Aravind Akella1f9b32f2014-09-16 15:21:44 -0700335 * when the foot hit the ground, generating a high variation in acceleration. This sensor is
336 * only for detecting every individual step as soon as it is taken, for example to perform dead
337 * reckoning. If you only need aggregate number of steps taken over a period of time, register
338 * for {@link #TYPE_STEP_COUNTER} instead. It is defined as a
339 * {@link Sensor#REPORTING_MODE_SPECIAL_TRIGGER} sensor.
Aravind Akella4b628cb2013-08-05 18:43:55 -0700340 * <p>
341 * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
342 */
343 public static final int TYPE_STEP_DETECTOR = 18;
344
345 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000346 * A constant string describing a step detector sensor.
347 *
348 * @see #TYPE_STEP_DETECTOR
349 */
350 public static final String STRING_TYPE_STEP_DETECTOR = "android.sensor.step_detector";
351
352 /**
Aravind Akella4b628cb2013-08-05 18:43:55 -0700353 * A constant describing a step counter sensor.
354 * <p>
355 * A sensor of this type returns the number of steps taken by the user since the last reboot
356 * while activated. The value is returned as a float (with the fractional part set to zero) and
357 * is reset to zero only on a system reboot. The timestamp of the event is set to the time when
Aravind Akella0c44d692014-08-19 18:28:12 -0700358 * the last step for that event was taken. This sensor is implemented in hardware and is
Aravind Akella1f9b32f2014-09-16 15:21:44 -0700359 * expected to be low power. If you want to continuously track the number of steps over a long
360 * period of time, do NOT unregister for this sensor, so that it keeps counting steps in the
361 * background even when the AP is in suspend mode and report the aggregate count when the AP
362 * is awake. Application needs to stay registered for this sensor because step counter does not
363 * count steps if it is not activated. This sensor is ideal for fitness tracking applications.
364 * It is defined as an {@link Sensor#REPORTING_MODE_ON_CHANGE} sensor.
Aravind Akella4b628cb2013-08-05 18:43:55 -0700365 * <p>
366 * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
367 */
368 public static final int TYPE_STEP_COUNTER = 19;
369
370 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000371 * A constant string describing a step counter sensor.
372 *
373 * @see #TYPE_STEP_COUNTER
374 */
375 public static final String STRING_TYPE_STEP_COUNTER = "android.sensor.step_counter";
376
377 /**
378 * A constant describing a geo-magnetic rotation vector.
Aravind Akella4b628cb2013-08-05 18:43:55 -0700379 * <p>
Aravind Akellaf0f4a832013-08-07 20:05:29 -0700380 * Similar to {@link #TYPE_ROTATION_VECTOR}, but using a magnetometer instead of using a
Aravind Akella4b628cb2013-08-05 18:43:55 -0700381 * gyroscope. This sensor uses lower power than the other rotation vectors, because it doesn't
382 * use the gyroscope. However, it is more noisy and will work best outdoors.
383 * <p>
384 * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
385 */
386 public static final int TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20;
387
388 /**
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000389 * A constant string describing a geo-magnetic rotation vector.
390 *
391 * @see #TYPE_GEOMAGNETIC_ROTATION_VECTOR
392 */
393 public static final String STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR =
394 "android.sensor.geomagnetic_rotation_vector";
395
396 /**
397 * A constant describing a heart rate monitor.
398 * <p>
Etienne Le Grandaf805102014-05-16 12:21:41 -0700399 * The reported value is the heart rate in beats per minute.
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000400 * <p>
Etienne Le Grandaf805102014-05-16 12:21:41 -0700401 * The reported accuracy represents the status of the monitor during the reading. See the
402 * {@code SENSOR_STATUS_*} constants in {@link android.hardware.SensorManager SensorManager}
403 * for more details on accuracy/status values. In particular, when the accuracy is
404 * {@code SENSOR_STATUS_UNRELIABLE} or {@code SENSOR_STATUS_NO_CONTACT}, the heart rate
405 * value should be discarded.
406 * <p>
407 * This sensor requires permission {@code android.permission.BODY_SENSORS}.
408 * It will not be returned by {@code SensorManager.getSensorsList} nor
409 * {@code SensorManager.getDefaultSensor} if the application doesn't have this permission.
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000410 */
411 public static final int TYPE_HEART_RATE = 21;
412
413 /**
414 * A constant string describing a heart rate monitor.
415 *
416 * @see #TYPE_HEART_RATE
417 */
418 public static final String STRING_TYPE_HEART_RATE = "android.sensor.heart_rate";
419
420 /**
Aravind Akella2f8b9142014-05-12 14:39:29 -0700421 * A sensor of this type generates an event each time a tilt event is detected. A tilt event
422 * is generated if the direction of the 2-seconds window average gravity changed by at
423 * least 35 degrees since the activation of the sensor. It is a wake up sensor.
424 *
Aravind Akella27900352014-06-03 19:20:42 -0700425 * @hide
Aravind Akella2f8b9142014-05-12 14:39:29 -0700426 * @see #isWakeUpSensor()
427 */
Aravind Akella0288ca62014-07-28 14:53:44 -0700428 public static final int TYPE_TILT_DETECTOR = 22;
Aravind Akella2f8b9142014-05-12 14:39:29 -0700429
430 /**
431 * A constant string describing a wake up tilt detector sensor type.
432 *
Aravind Akella27900352014-06-03 19:20:42 -0700433 * @hide
Aravind Akella2f8b9142014-05-12 14:39:29 -0700434 * @see #TYPE_WAKE_UP_TILT_DETECTOR
435 */
Aravind Akella0288ca62014-07-28 14:53:44 -0700436 public static final String SENSOR_STRING_TYPE_TILT_DETECTOR =
437 "android.sensor.tilt_detector";
Aravind Akella2f8b9142014-05-12 14:39:29 -0700438
439 /**
Etienne Le Grand28071e32014-05-07 19:47:43 -0700440 * A constant describing a wake gesture sensor.
441 * <p>
442 * Wake gesture sensors enable waking up the device based on a device specific motion.
443 * <p>
444 * When this sensor triggers, the device behaves as if the power button was pressed, turning the
445 * screen on. This behavior (turning on the screen when this sensor triggers) might be
446 * deactivated by the user in the device settings. Changes in settings do not impact the
447 * behavior of the sensor: only whether the framework turns the screen on when it triggers.
448 * <p>
449 * The actual gesture to be detected is not specified, and can be chosen by the manufacturer of
450 * the device. This sensor must be low power, as it is likely to be activated 24/7.
451 * Values of events created by this sensors should not be used.
452 *
Aravind Akella2f8b9142014-05-12 14:39:29 -0700453 * @see #isWakeUpSensor()
Jeff Brown241e70d2014-07-17 15:12:37 -0700454 * @hide This sensor is expected to only be used by the system ui
Etienne Le Grand28071e32014-05-07 19:47:43 -0700455 */
Aravind Akella0288ca62014-07-28 14:53:44 -0700456 public static final int TYPE_WAKE_GESTURE = 23;
Etienne Le Grand28071e32014-05-07 19:47:43 -0700457
458 /**
459 * A constant string describing a wake gesture sensor.
460 *
Jeff Brown241e70d2014-07-17 15:12:37 -0700461 * @hide This sensor is expected to only be used by the system ui
Etienne Le Grand28071e32014-05-07 19:47:43 -0700462 * @see #TYPE_WAKE_GESTURE
463 */
464 public static final String STRING_TYPE_WAKE_GESTURE = "android.sensor.wake_gesture";
465
466 /**
Jeff Brown241e70d2014-07-17 15:12:37 -0700467 * A constant describing a wake gesture sensor.
468 * <p>
469 * A sensor enabling briefly turning the screen on to enable the user to
470 * glance content on screen based on a specific motion. The device should
471 * turn the screen off after a few moments.
472 * <p>
473 * When this sensor triggers, the device turns the screen on momentarily
474 * to allow the user to glance notifications or other content while the
475 * device remains locked in a non-interactive state (dozing). This behavior
476 * (briefly turning on the screen when this sensor triggers) might be deactivated
477 * by the user in the device settings. Changes in settings do not impact the
478 * behavior of the sensor: only whether the framework briefly turns the screen on
479 * when it triggers.
480 * <p>
481 * The actual gesture to be detected is not specified, and can be chosen by the manufacturer of
482 * the device. This sensor must be low power, as it is likely to be activated 24/7.
483 * Values of events created by this sensors should not be used.
484 *
485 * @see #isWakeUpSensor()
486 * @hide This sensor is expected to only be used by the system ui
487 */
Aravind Akella0288ca62014-07-28 14:53:44 -0700488 public static final int TYPE_GLANCE_GESTURE = 24;
Jeff Brown241e70d2014-07-17 15:12:37 -0700489
490 /**
491 * A constant string describing a wake gesture sensor.
492 *
493 * @hide This sensor is expected to only be used by the system ui
494 * @see #TYPE_GLANCE_GESTURE
495 */
496 public static final String STRING_TYPE_GLANCE_GESTURE = "android.sensor.glance_gesture";
497
Aravind Akella96eb62c2014-07-17 12:42:00 -0700498 /**
499 * A constant describing a pick up sensor.
500 *
501 * A sensor of this type triggers when the device is picked up regardless of wherever it was
502 * before (desk, pocket, bag). The only allowed return value is 1.0. This sensor deactivates
503 * itself immediately after it triggers.
504 *
505 * @hide Expected to be used internally for always on display.
506 */
Aravind Akella0288ca62014-07-28 14:53:44 -0700507 public static final int TYPE_PICK_UP_GESTURE = 25;
Aravind Akella96eb62c2014-07-17 12:42:00 -0700508
509 /**
510 * A constant string describing a pick up sensor.
511 *
512 * @hide This sensor is expected to be used internally for always on display.
513 * @see #TYPE_PICK_UP_GESTURE
514 */
515 public static final String STRING_TYPE_PICK_UP_GESTURE = "android.sensor.pick_up_gesture";
516
Nick Vaccarof5021f62015-01-23 15:09:45 -0800517 /**
518 * A constant describing a wrist tilt gesture sensor.
519 *
520 * A sensor of this type triggers when the device face is tilted towards the user.
521 * The only allowed return value is 1.0.
522 * This sensor remains active until disabled.
523 *
524 * @hide This sensor is expected to only be used by the system ui
525 */
526 @SystemApi
527 public static final int TYPE_WRIST_TILT_GESTURE = 26;
528
529 /**
530 * A constant string describing a wrist tilt gesture sensor.
531 *
532 * @hide This sensor is expected to only be used by the system ui
533 * @see #TYPE_WRIST_TILT_GESTURE
534 */
535 @SystemApi
536 public static final String STRING_TYPE_WRIST_TILT_GESTURE = "android.sensor.wrist_tilt_gesture";
537
Jeff Brown241e70d2014-07-17 15:12:37 -0700538 /**
Trevor Bunker3c288e62016-01-08 11:11:13 -0800539 * The current orientation of the device.
540 * <p>
541 * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
542 *
543 * @hide Expected to be used internally for auto-rotate and speaker rotation.
544 *
545 */
546 public static final int TYPE_DEVICE_ORIENTATION = 27;
547
548 /**
549 * A constant string describing a device orientation sensor type.
550 *
551 * @hide
552 * @see #TYPE_DEVICE_ORIENTATION
553 */
554 public static final String STRING_TYPE_DEVICE_ORIENTATION = "android.sensor.device_orientation";
555
Ashutosh Joshi17efe022016-01-14 22:23:58 -0800556 /**
557 * A constant describing a pose sensor with 6 degrees of freedom.
558 *
559 * Similar to {@link #TYPE_ROTATION_VECTOR}, with additional delta
560 * translation from an arbitrary reference point.
561 *
Ashutosh Joshiaf1a2662016-01-25 20:24:20 -0800562 * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
563 *
Ashutosh Joshi17efe022016-01-14 22:23:58 -0800564 * Can use camera, depth sensor etc to compute output value.
565 *
566 * This is expected to be a high power sensor and expected only to be
567 * used when the screen is on.
568 *
569 * Expected to be more accurate than the rotation vector alone.
570 *
571 */
572 public static final int TYPE_POSE_6DOF = 28;
573
574 /**
575 * A constant string describing a pose sensor with 6 degrees of freedom.
576 *
577 * @see #TYPE_POSE_6DOF
578 */
579 public static final String STRING_TYPE_POSE_6DOF = "android.sensor.pose_6dof";
580
Ashutosh Joshiaf1a2662016-01-25 20:24:20 -0800581 /**
582 * A constant describing a stationary detect sensor.
583 *
584 * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
585 *
586 */
587 public static final int TYPE_STATIONARY_DETECT = 29;
588
589 /**
590 * A constant string describing a stationary detection sensor.
591 *
592 * @see #TYPE_STATIONARY_DETECT
593 */
594 public static final String STRING_TYPE_STATIONARY_DETECT = "android.sensor.stationary_detect";
595
596 /**
597 * A constant describing a motion detect sensor.
598 *
599 * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
600 *
601 */
602 public static final int TYPE_MOTION_DETECT = 30;
603
604 /**
605 * A constant string describing a motion detection sensor.
606 *
607 * @see #TYPE_MOTION_DETECT
608 */
609 public static final String STRING_TYPE_MOTION_DETECT = "android.sensor.motion_detect";
610
611 /**
612 * A constant describing a motion detect sensor.
613 *
614 * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
615 *
616 */
617 public static final int TYPE_HEART_BEAT = 31;
618
619 /**
620 * A constant string describing a heart beat sensor.
621 *
622 * @see #TYPE_HEART_BEAT
623 */
624
625 public static final String STRING_TYPE_HEART_BEAT = "android.sensor.heart_beat";
Trevor Bunker3c288e62016-01-08 11:11:13 -0800626 /**
Peng Xua35b5532016-01-20 00:05:45 -0800627 * A constant describing a dynamic sensor meta event sensor.
628 *
629 * A sensor event of this type is received when a dynamic sensor is added to or removed from
630 * the system. This sensor type should always use special trigger report mode ({@code
631 * SensorManager.REPORTING_MODE_SPECIAL_TRIGGER}).
632 *
633 * @hide This sensor is expected to be used only by system services.
634 */
635 @SystemApi
636 public static final int TYPE_DYNAMIC_SENSOR_META = 32;
637
638 /**
639 * A constant string describing a dynamic sensor meta event sensor.
640 *
641 * @see #TYPE_DYNAMIC_SENSOR_META
642 *
643 * @hide This sensor is expected to only be used by the system service
644 */
645 @SystemApi
646 public static final String STRING_TYPE_DYNAMIC_SENSOR_META =
647 "android.sensor.dynamic_sensor_meta";
648
649 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 * A constant describing all sensor types.
651 */
Ashutosh Joshiaf1a2662016-01-25 20:24:20 -0800652
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700653 public static final int TYPE_ALL = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654
Peng Xu370985d2016-03-04 11:09:24 -0800655 /**
656 * The lowest sensor type vendor defined sensors can use.
657 *
658 * All vendor sensor types are greater than or equal to this constant.
659 *
660 */
661 public static final int TYPE_DEVICE_PRIVATE_BASE = 0x10000;
662
Aravind Akella27900352014-06-03 19:20:42 -0700663 // If this flag is set, the sensor defined as a wake up sensor. This field and REPORTING_MODE_*
664 // constants are defined as flags in sensors.h. Modify at both places if needed.
665 private static final int SENSOR_FLAG_WAKE_UP_SENSOR = 1;
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800666
Aravind Akella27900352014-06-03 19:20:42 -0700667 /**
668 * Events are reported at a constant rate which is set by the rate parameter of
669 * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)}. Note: If other
670 * applications are requesting a higher rate, the sensor data might be delivered at faster rates
671 * than requested.
672 */
673 public static final int REPORTING_MODE_CONTINUOUS = 0;
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800674
Aravind Akella27900352014-06-03 19:20:42 -0700675 /**
676 * Events are reported only when the value changes. Event delivery rate can be limited by
677 * setting appropriate value for rate parameter of
678 * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)} Note: If other
679 * applications are requesting a higher rate, the sensor data might be delivered at faster rates
680 * than requested.
681 */
682 public static final int REPORTING_MODE_ON_CHANGE = 1;
683
684 /**
685 * Events are reported in one-shot mode. Upon detection of an event, the sensor deactivates
686 * itself and then sends a single event. Sensors of this reporting mode must be registered to
687 * using {@link SensorManager#requestTriggerSensor(TriggerEventListener, Sensor)}.
688 */
689 public static final int REPORTING_MODE_ONE_SHOT = 2;
690
691 /**
692 * Events are reported as described in the description of the sensor. The rate passed to
693 * registerListener might not have an impact on the rate of event delivery. See the sensor
694 * definition for more information on when and how frequently the events are reported. For
695 * example, step detectors report events when a step is detected.
696 *
697 * @see SensorManager#registerListener(SensorEventListener, Sensor, int, int)
698 */
699 public static final int REPORTING_MODE_SPECIAL_TRIGGER = 3;
700
701 // Mask for the LSB 2nd, 3rd and fourth bits.
702 private static final int REPORTING_MODE_MASK = 0xE;
703 private static final int REPORTING_MODE_SHIFT = 1;
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800704
Aravind Akella18ebf732b2015-04-20 17:39:51 -0700705 // MASK for LSB fifth bit. Used to know whether the sensor supports data injection or not.
706 private static final int DATA_INJECTION_MASK = 0x10;
707 private static final int DATA_INJECTION_SHIFT = 4;
708
Jaikumar Ganeshedb52422013-04-16 11:10:05 -0700709 // TODO(): The following arrays are fragile and error-prone. This needs to be refactored.
710
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800711 // Note: This needs to be updated, whenever a new sensor is added.
Mathias Agopianb25c0ef2013-07-03 15:38:29 -0700712 // Holds the reporting mode and maximum length of the values array
713 // associated with
714 // {@link SensorEvent} or {@link TriggerEvent} for the Sensor
715 private static final int[] sSensorReportingModes = {
Aravind Akella27900352014-06-03 19:20:42 -0700716 0, // padding because sensor types start at 1
717 3, // SENSOR_TYPE_ACCELEROMETER
718 3, // SENSOR_TYPE_GEOMAGNETIC_FIELD
719 3, // SENSOR_TYPE_ORIENTATION
720 3, // SENSOR_TYPE_GYROSCOPE
721 3, // SENSOR_TYPE_LIGHT
722 3, // SENSOR_TYPE_PRESSURE
723 3, // SENSOR_TYPE_TEMPERATURE
724 3, // SENSOR_TYPE_PROXIMITY
725 3, // SENSOR_TYPE_GRAVITY
726 3, // SENSOR_TYPE_LINEAR_ACCELERATION
727 5, // SENSOR_TYPE_ROTATION_VECTOR
728 3, // SENSOR_TYPE_RELATIVE_HUMIDITY
729 3, // SENSOR_TYPE_AMBIENT_TEMPERATURE
730 6, // SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
731 4, // SENSOR_TYPE_GAME_ROTATION_VECTOR
732 6, // SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
733 1, // SENSOR_TYPE_SIGNIFICANT_MOTION
734 1, // SENSOR_TYPE_STEP_DETECTOR
735 1, // SENSOR_TYPE_STEP_COUNTER
736 5, // SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
737 1, // SENSOR_TYPE_HEART_RATE_MONITOR
Aravind Akella27900352014-06-03 19:20:42 -0700738 1, // SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
739 1, // SENSOR_TYPE_WAKE_GESTURE
Jeff Brown241e70d2014-07-17 15:12:37 -0700740 1, // SENSOR_TYPE_GLANCE_GESTURE
Aravind Akella96eb62c2014-07-17 12:42:00 -0700741 1, // SENSOR_TYPE_PICK_UP_GESTURE
Nick Vaccarof5021f62015-01-23 15:09:45 -0800742 1, // SENSOR_TYPE_WRIST_TILT_GESTURE
Trevor Bunker3c288e62016-01-08 11:11:13 -0800743 1, // SENSOR_TYPE_DEVICE_ORIENTATION
Peng Xua35b5532016-01-20 00:05:45 -0800744 16,// SENSOR_TYPE_POSE_6DOF
745 1, // SENSOR_TYPE_STATIONARY_DETECT
746 1, // SENSOR_TYPE_MOTION_DETECT
747 1, // SENSOR_TYPE_HEART_BEAT
748 2, // SENSOR_TYPE_DYNAMIC_SENSOR_META
Mathias Agopianb25c0ef2013-07-03 15:38:29 -0700749 };
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700750
Aravind Akella27900352014-06-03 19:20:42 -0700751 /**
752 * Each sensor has exactly one reporting mode associated with it. This method returns the
753 * reporting mode constant for this sensor type.
754 *
755 * @return Reporting mode for the input sensor, one of REPORTING_MODE_* constants.
756 * @see #REPORTING_MODE_CONTINUOUS
757 * @see #REPORTING_MODE_ON_CHANGE
758 * @see #REPORTING_MODE_ONE_SHOT
759 * @see #REPORTING_MODE_SPECIAL_TRIGGER
760 */
761 public int getReportingMode() {
762 return ((mFlags & REPORTING_MODE_MASK) >> REPORTING_MODE_SHIFT);
Jaikumar Ganesh9a8df4d2013-02-12 16:31:32 -0800763 }
764
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700765 static int getMaxLengthValuesArray(Sensor sensor, int sdkLevel) {
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700766 // RotationVector length has changed to 3 to 5 for API level 18
767 // Set it to 3 for backward compatibility.
Aravind Akella27900352014-06-03 19:20:42 -0700768 if (sensor.mType == Sensor.TYPE_ROTATION_VECTOR &&
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700769 sdkLevel <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Mathias Agopianb25c0ef2013-07-03 15:38:29 -0700770 return 3;
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700771 }
Aravind Akella27900352014-06-03 19:20:42 -0700772 int offset = sensor.mType;
Mathias Agopianb25c0ef2013-07-03 15:38:29 -0700773 if (offset >= sSensorReportingModes.length) {
Peng Xua35b5532016-01-20 00:05:45 -0800774 // we don't know about this sensor, so this is probably a vendor-defined sensor, in that
775 // case, we don't know how many value it has so we return the maximum and assume the app
776 // will know.
777 // FIXME: sensor HAL should advertise how much data is returned per sensor
Mathias Agopianb25c0ef2013-07-03 15:38:29 -0700778 return 16;
779 }
780 return sSensorReportingModes[offset];
Jaikumar Ganesh6d0c1d782013-03-27 17:41:33 -0700781 }
782
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700783 /* Some of these fields are set only by the native bindings in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 * SensorManager.
785 */
786 private String mName;
787 private String mVendor;
788 private int mVersion;
789 private int mHandle;
790 private int mType;
791 private float mMaxRange;
792 private float mResolution;
793 private float mPower;
Mathias Agopian050b5622010-07-29 16:51:38 -0700794 private int mMinDelay;
Aravind Akellab4c76b12013-06-27 12:04:16 -0700795 private int mFifoReservedEventCount;
796 private int mFifoMaxEventCount;
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000797 private String mStringType;
798 private String mRequiredPermission;
Aravind Akella2f8b9142014-05-12 14:39:29 -0700799 private int mMaxDelay;
Aravind Akella27900352014-06-03 19:20:42 -0700800 private int mFlags;
Peng Xua35b5532016-01-20 00:05:45 -0800801 private UUID mUuid;
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700802
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 Sensor() {
804 }
805
806 /**
807 * @return name string of the sensor.
808 */
809 public String getName() {
810 return mName;
811 }
812
813 /**
814 * @return vendor string of this sensor.
815 */
816 public String getVendor() {
817 return mVendor;
818 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 /**
821 * @return generic type of this sensor.
822 */
823 public int getType() {
824 return mType;
825 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 /**
828 * @return version of the sensor's module.
829 */
830 public int getVersion() {
831 return mVersion;
832 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700833
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 /**
835 * @return maximum range of the sensor in the sensor's unit.
836 */
837 public float getMaximumRange() {
838 return mMaxRange;
839 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700840
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 /**
842 * @return resolution of the sensor in the sensor's unit.
843 */
844 public float getResolution() {
845 return mResolution;
846 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 /**
849 * @return the power in mA used by this sensor while in use
850 */
851 public float getPower() {
852 return mPower;
853 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700854
Mathias Agopian050b5622010-07-29 16:51:38 -0700855 /**
856 * @return the minimum delay allowed between two events in microsecond
857 * or zero if this sensor only returns a value when the data it's measuring
858 * changes.
859 */
860 public int getMinDelay() {
861 return mMinDelay;
862 }
863
Aravind Akellab4c76b12013-06-27 12:04:16 -0700864 /**
865 * @return Number of events reserved for this sensor in the batch mode FIFO. This gives a
Aravind Akellad405e0f2013-09-04 12:07:33 -0700866 * guarantee on the minimum number of events that can be batched.
Aravind Akellab4c76b12013-06-27 12:04:16 -0700867 */
868 public int getFifoReservedEventCount() {
869 return mFifoReservedEventCount;
870 }
871
872 /**
873 * @return Maximum number of events of this sensor that could be batched. If this value is zero
874 * it indicates that batch mode is not supported for this sensor. If other applications
875 * registered to batched sensors, the actual number of events that can be batched might be
876 * smaller because the hardware FiFo will be partially used to batch the other sensors.
Aravind Akellab4c76b12013-06-27 12:04:16 -0700877 */
878 public int getFifoMaxEventCount() {
879 return mFifoMaxEventCount;
880 }
881
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000882 /**
883 * @return The type of this sensor as a string.
884 */
885 public String getStringType() {
886 return mStringType;
887 }
888
889 /**
Peng Xua35b5532016-01-20 00:05:45 -0800890 * @return The type of this sensor as a string.
891 */
892 public UUID getUuid() {
893 return mUuid;
894 }
895
896 /**
Aravind Akellab613dba2014-05-21 14:14:45 -0700897 * @hide
Aravind Akellacd9a7bb2014-04-07 22:55:21 +0000898 * @return The permission required to access this sensor. If empty, no permission is required.
899 */
900 public String getRequiredPermission() {
901 return mRequiredPermission;
902 }
903
Mathias Agopian7f84c062013-02-04 19:22:47 -0800904 /** @hide */
905 public int getHandle() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 return mHandle;
907 }
Mathias Agopian74cde2c2010-06-16 18:55:46 -0700908
Aravind Akella2f8b9142014-05-12 14:39:29 -0700909 /**
Aravind Akellae57676b2014-09-04 16:24:41 -0700910 * This value is defined only for continuous and on-change sensors. It is the delay between two
911 * sensor events corresponding to the lowest frequency that this sensor supports. When lower
912 * frequencies are requested through registerListener() the events will be generated at this
913 * frequency instead. It can be used to estimate when the batch FIFO may be full. Older devices
914 * may set this value to zero. Ignore this value in case it is negative or zero.
Aravind Akella2f8b9142014-05-12 14:39:29 -0700915 *
916 * @return The max delay for this sensor in microseconds.
917 */
918 public int getMaxDelay() {
919 return mMaxDelay;
920 }
921
922 /**
Aravind Akella1f9b32f2014-09-16 15:21:44 -0700923 * Returns true if the sensor is a wake-up sensor.
Aravind Akella2f8b9142014-05-12 14:39:29 -0700924 * <p>
Aravind Akella1f9b32f2014-09-16 15:21:44 -0700925 * <b>Application Processor Power modes</b> <p>
926 * Application Processor(AP), is the processor on which applications run. When no wake lock is held
927 * and the user is not interacting with the device, this processor can enter a “Suspend” mode,
928 * reducing the power consumption by 10 times or more.
929 * </p>
Aravind Akella2f8b9142014-05-12 14:39:29 -0700930 * <p>
Aravind Akella1f9b32f2014-09-16 15:21:44 -0700931 * <b>Non-wake-up sensors</b> <p>
932 * Non-wake-up sensors are sensors that do not wake the AP out of suspend to report data. While
933 * the AP is in suspend mode, the sensors continue to function and generate events, which are
934 * put in a hardware FIFO. The events in the FIFO are delivered to the application when the AP
935 * wakes up. If the FIFO was too small to store all events generated while the AP was in
936 * suspend mode, the older events are lost: the oldest data is dropped to accommodate the newer
937 * data. In the extreme case where the FIFO is non-existent {@code maxFifoEventCount() == 0},
938 * all events generated while the AP was in suspend mode are lost. Applications using
939 * non-wake-up sensors should usually:
940 * <ul>
941 * <li>Either unregister from the sensors when they do not need them, usually in the activity’s
942 * {@code onPause} method. This is the most common case.
943 * <li>Or realize that the sensors are consuming some power while the AP is in suspend mode and
944 * that even then, some events might be lost.
945 * </ul>
946 * </p>
Aravind Akella2f8b9142014-05-12 14:39:29 -0700947 * <p>
Aravind Akella1f9b32f2014-09-16 15:21:44 -0700948 * <b>Wake-up sensors</b> <p>
949 * In opposition to non-wake-up sensors, wake-up sensors ensure that their data is delivered
950 * independently of the state of the AP. While the AP is awake, the wake-up sensors behave
951 * like non-wake-up-sensors. When the AP is asleep, wake-up sensors wake up the AP to deliver
952 * events. That is, the AP will wake up and the sensor will deliver the events before the
953 * maximum reporting latency is elapsed or the hardware FIFO gets full. See {@link
954 * SensorManager#registerListener(SensorEventListener, Sensor, int, int)} for more details.
955 * </p>
956 *
957 * @return <code>true</code> if this is a wake-up sensor, <code>false</code> otherwise.
Aravind Akella2f8b9142014-05-12 14:39:29 -0700958 */
959 public boolean isWakeUpSensor() {
Aravind Akella27900352014-06-03 19:20:42 -0700960 return (mFlags & SENSOR_FLAG_WAKE_UP_SENSOR) != 0;
Aravind Akella2f8b9142014-05-12 14:39:29 -0700961 }
962
Aravind Akella18ebf732b2015-04-20 17:39:51 -0700963 /**
964 * Returns true if the sensor supports data injection when the
965 * HAL is set to data injection mode.
966 *
967 * @return <code>true</code> if the sensor supports data
968 * injection when the HAL is set in injection mode,
969 * false otherwise.
970 * @hide
971 */
972 @SystemApi
973 public boolean isDataInjectionSupported() {
974 return (((mFlags & DATA_INJECTION_MASK) >> DATA_INJECTION_SHIFT)) != 0;
975 }
976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 void setRange(float max, float res) {
978 mMaxRange = max;
979 mResolution = res;
980 }
Jeff Brown6a2ef122012-08-10 18:19:10 -0700981
982 @Override
983 public String toString() {
984 return "{Sensor name=\"" + mName + "\", vendor=\"" + mVendor + "\", version=" + mVersion
985 + ", type=" + mType + ", maxRange=" + mMaxRange + ", resolution=" + mResolution
986 + ", power=" + mPower + ", minDelay=" + mMinDelay + "}";
987 }
destradaa9ba7c1c2015-02-10 15:04:43 -0800988
989 /**
990 * Sets the Type associated with the sensor.
991 * NOTE: to be used only by native bindings in SensorManager.
992 *
993 * This allows interned static strings to be used across all representations of the Sensor. If
994 * a sensor type is not referenced here, it will still be interned by the native SensorManager.
995 *
996 * @return {@code true} if the StringType was successfully set, {@code false} otherwise.
997 */
998 private boolean setType(int value) {
999 mType = value;
1000 switch (mType) {
1001 case TYPE_ACCELEROMETER:
1002 mStringType = STRING_TYPE_ACCELEROMETER;
1003 return true;
1004 case TYPE_AMBIENT_TEMPERATURE:
1005 mStringType = STRING_TYPE_AMBIENT_TEMPERATURE;
1006 return true;
1007 case TYPE_GAME_ROTATION_VECTOR:
1008 mStringType = STRING_TYPE_GAME_ROTATION_VECTOR;
1009 return true;
1010 case TYPE_GEOMAGNETIC_ROTATION_VECTOR:
1011 mStringType = STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR;
1012 return true;
1013 case TYPE_GLANCE_GESTURE:
1014 mStringType = STRING_TYPE_GLANCE_GESTURE;
1015 return true;
1016 case TYPE_GRAVITY:
1017 mStringType = STRING_TYPE_GRAVITY;
1018 return true;
1019 case TYPE_GYROSCOPE:
1020 mStringType = STRING_TYPE_GYROSCOPE;
1021 return true;
1022 case TYPE_GYROSCOPE_UNCALIBRATED:
1023 mStringType = STRING_TYPE_GYROSCOPE_UNCALIBRATED;
1024 return true;
1025 case TYPE_HEART_RATE:
1026 mStringType = STRING_TYPE_HEART_RATE;
1027 return true;
1028 case TYPE_LIGHT:
1029 mStringType = STRING_TYPE_LIGHT;
1030 return true;
1031 case TYPE_LINEAR_ACCELERATION:
1032 mStringType = STRING_TYPE_LINEAR_ACCELERATION;
1033 return true;
1034 case TYPE_MAGNETIC_FIELD:
1035 mStringType = STRING_TYPE_MAGNETIC_FIELD;
1036 return true;
1037 case TYPE_MAGNETIC_FIELD_UNCALIBRATED:
1038 mStringType = STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED;
1039 return true;
1040 case TYPE_PICK_UP_GESTURE:
1041 mStringType = STRING_TYPE_PICK_UP_GESTURE;
1042 return true;
1043 case TYPE_PRESSURE:
1044 mStringType = STRING_TYPE_PRESSURE;
1045 return true;
1046 case TYPE_PROXIMITY:
1047 mStringType = STRING_TYPE_PROXIMITY;
1048 return true;
1049 case TYPE_RELATIVE_HUMIDITY:
1050 mStringType = STRING_TYPE_RELATIVE_HUMIDITY;
1051 return true;
1052 case TYPE_ROTATION_VECTOR:
1053 mStringType = STRING_TYPE_ROTATION_VECTOR;
1054 return true;
1055 case TYPE_SIGNIFICANT_MOTION:
1056 mStringType = STRING_TYPE_SIGNIFICANT_MOTION;
1057 return true;
1058 case TYPE_STEP_COUNTER:
1059 mStringType = STRING_TYPE_STEP_COUNTER;
1060 return true;
1061 case TYPE_STEP_DETECTOR:
1062 mStringType = STRING_TYPE_STEP_DETECTOR;
1063 return true;
1064 case TYPE_TILT_DETECTOR:
1065 mStringType = SENSOR_STRING_TYPE_TILT_DETECTOR;
1066 return true;
1067 case TYPE_WAKE_GESTURE:
1068 mStringType = STRING_TYPE_WAKE_GESTURE;
1069 return true;
1070 case TYPE_ORIENTATION:
1071 mStringType = STRING_TYPE_ORIENTATION;
1072 return true;
1073 case TYPE_TEMPERATURE:
1074 mStringType = STRING_TYPE_TEMPERATURE;
1075 return true;
Trevor Bunker3c288e62016-01-08 11:11:13 -08001076 case TYPE_DEVICE_ORIENTATION:
1077 mStringType = STRING_TYPE_DEVICE_ORIENTATION;
1078 return true;
Peng Xua35b5532016-01-20 00:05:45 -08001079 case TYPE_DYNAMIC_SENSOR_META:
1080 mStringType = STRING_TYPE_DYNAMIC_SENSOR_META;
1081 return true;
destradaa9ba7c1c2015-02-10 15:04:43 -08001082 default:
1083 return false;
1084 }
1085 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001086}