• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
18 package android.hardware;
19 
20 import android.annotation.SystemApi;
21 import android.compat.annotation.UnsupportedAppUsage;
22 import android.hardware.input.InputSensorInfo;
23 import android.os.Build;
24 
25 /**
26  * Class representing a sensor. Use {@link SensorManager#getSensorList} to get
27  * the list of available sensors. For more information about Android sensors,
28  * read the
29  * <a href="/guide/topics/sensors/sensors_motion.html">Motion Sensors guide</a>.</p>
30  *
31  * @see SensorManager
32  * @see SensorEventListener
33  * @see SensorEvent
34  *
35  */
36 public final class Sensor {
37 
38     /**
39      * A constant describing an accelerometer sensor type.
40      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
41      * for more details.
42      */
43     public static final int TYPE_ACCELEROMETER = 1;
44 
45     /**
46      * A constant string describing an accelerometer sensor type.
47      *
48      * @see #TYPE_ACCELEROMETER
49      */
50     public static final String STRING_TYPE_ACCELEROMETER = "android.sensor.accelerometer";
51 
52     /**
53      * A constant describing a magnetic field sensor type.
54      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
55      * for more details.
56      */
57     public static final int TYPE_MAGNETIC_FIELD = 2;
58 
59     /**
60      * A constant string describing a magnetic field sensor type.
61      *
62      * @see #TYPE_MAGNETIC_FIELD
63      */
64     public static final String STRING_TYPE_MAGNETIC_FIELD = "android.sensor.magnetic_field";
65 
66     /**
67      * A constant describing an orientation sensor type.
68      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
69      * for more details.
70      *
71      * @deprecated use {@link android.hardware.SensorManager#getOrientation
72      *             SensorManager.getOrientation()} instead.
73      */
74     @Deprecated
75     public static final int TYPE_ORIENTATION = 3;
76 
77     /**
78      * A constant string describing an orientation sensor type.
79      *
80      * @see #TYPE_ORIENTATION
81      * @deprecated use {@link android.hardware.SensorManager#getOrientation
82      *             SensorManager.getOrientation()} instead.
83      */
84     @Deprecated
85     public static final String STRING_TYPE_ORIENTATION = "android.sensor.orientation";
86 
87     /**
88      * A constant describing a gyroscope sensor type.
89      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
90      * for more details. */
91     public static final int TYPE_GYROSCOPE = 4;
92 
93     /**
94      * A constant string describing a gyroscope sensor type.
95      *
96      * @see #TYPE_GYROSCOPE
97      */
98     public static final String STRING_TYPE_GYROSCOPE = "android.sensor.gyroscope";
99 
100     /**
101      * A constant describing a light sensor type.
102      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
103      * for more details.
104      */
105     public static final int TYPE_LIGHT = 5;
106 
107     /**
108      * A constant string describing a light sensor type.
109      *
110      * @see #TYPE_LIGHT
111      */
112     public static final String STRING_TYPE_LIGHT = "android.sensor.light";
113 
114     /**
115      * A constant describing a pressure sensor type.
116      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
117      * for more details.
118      */
119     public static final int TYPE_PRESSURE = 6;
120 
121     /**
122      * A constant string describing a pressure sensor type.
123      *
124      * @see #TYPE_PRESSURE
125      */
126     public static final String STRING_TYPE_PRESSURE = "android.sensor.pressure";
127 
128     /**
129      * A constant describing a temperature sensor type
130      *
131      * @deprecated use
132      *             {@link android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE
133      *             Sensor.TYPE_AMBIENT_TEMPERATURE} instead.
134      */
135     @Deprecated
136     public static final int TYPE_TEMPERATURE = 7;
137 
138     /**
139      * A constant string describing a temperature sensor type
140      *
141      * @see #TYPE_TEMPERATURE
142      * @deprecated use
143      *             {@link android.hardware.Sensor#STRING_TYPE_AMBIENT_TEMPERATURE
144      *             Sensor.STRING_TYPE_AMBIENT_TEMPERATURE} instead.
145      */
146     @Deprecated
147     public static final String STRING_TYPE_TEMPERATURE = "android.sensor.temperature";
148 
149     /**
150      * A constant describing a proximity sensor type. This is a wake up sensor.
151      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
152      * for more details.
153      * @see #isWakeUpSensor()
154      */
155     public static final int TYPE_PROXIMITY = 8;
156 
157     /**
158      * A constant string describing a proximity sensor type.
159      *
160      * @see #TYPE_PROXIMITY
161      */
162     public static final String STRING_TYPE_PROXIMITY = "android.sensor.proximity";
163 
164     /**
165      * A constant describing a gravity sensor type.
166      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
167      * for more details.
168      */
169     public static final int TYPE_GRAVITY = 9;
170 
171     /**
172      * A constant string describing a gravity sensor type.
173      *
174      * @see #TYPE_GRAVITY
175      */
176     public static final String STRING_TYPE_GRAVITY = "android.sensor.gravity";
177 
178     /**
179      * A constant describing a linear acceleration sensor type.
180      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
181      * for more details.
182      */
183     public static final int TYPE_LINEAR_ACCELERATION = 10;
184 
185     /**
186      * A constant string describing a linear acceleration sensor type.
187      *
188      * @see #TYPE_LINEAR_ACCELERATION
189      */
190     public static final String STRING_TYPE_LINEAR_ACCELERATION =
191             "android.sensor.linear_acceleration";
192 
193     /**
194      * A constant describing a rotation vector sensor type.
195      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
196      * for more details.
197      */
198     public static final int TYPE_ROTATION_VECTOR = 11;
199 
200     /**
201      * A constant string describing a rotation vector sensor type.
202      *
203      * @see #TYPE_ROTATION_VECTOR
204      */
205     public static final String STRING_TYPE_ROTATION_VECTOR = "android.sensor.rotation_vector";
206 
207     /**
208      * A constant describing a relative humidity sensor type.
209      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
210      * for more details.
211      */
212     public static final int TYPE_RELATIVE_HUMIDITY = 12;
213 
214     /**
215      * A constant string describing a relative humidity sensor type
216      *
217      * @see #TYPE_RELATIVE_HUMIDITY
218      */
219     public static final String STRING_TYPE_RELATIVE_HUMIDITY = "android.sensor.relative_humidity";
220 
221     /**
222      * A constant describing an ambient temperature sensor type.
223      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values}
224      * for more details.
225      */
226     public static final int TYPE_AMBIENT_TEMPERATURE = 13;
227 
228     /**
229      * A constant string describing an ambient temperature sensor type.
230      *
231      * @see #TYPE_AMBIENT_TEMPERATURE
232      */
233     public static final String STRING_TYPE_AMBIENT_TEMPERATURE =
234             "android.sensor.ambient_temperature";
235 
236     /**
237      * A constant describing an uncalibrated magnetic field sensor type.
238      * <p>
239      * Similar to {@link #TYPE_MAGNETIC_FIELD} but the hard iron calibration (device calibration
240      * due to distortions that arise from magnetized iron, steel or permanent magnets on the
241      * device) is not considered in the given sensor values. However, such hard iron bias values
242      * are returned to you separately in the result {@link android.hardware.SensorEvent#values}
243      * so you may use them for custom calibrations.
244      * <p>Also, no periodic calibration is performed
245      * (i.e. there are no discontinuities in the data stream while using this sensor) and
246      * assumptions that the magnetic field is due to the Earth's poles is avoided, but
247      * factory calibration and temperature compensation have been performed.
248      * </p>
249      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} for more
250      * details.
251      */
252     public static final int TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14;
253     /**
254      * A constant string describing an uncalibrated magnetic field sensor type.
255      *
256      * @see #TYPE_MAGNETIC_FIELD_UNCALIBRATED
257      */
258     public static final String STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED =
259             "android.sensor.magnetic_field_uncalibrated";
260 
261     /**
262      * A constant describing an uncalibrated rotation vector sensor type.
263      * <p>Identical to {@link #TYPE_ROTATION_VECTOR} except that it doesn't
264      * use the geomagnetic field. Therefore the Y axis doesn't
265      * point north, but instead to some other reference, that reference is
266      * allowed to drift by the same order of magnitude as the gyroscope
267      * drift around the Z axis.
268      * <p>
269      * In the ideal case, a phone rotated and returning to the same real-world
270      * orientation should report the same game rotation vector
271      * (without using the earth's geomagnetic field). However, the orientation
272      * may drift somewhat over time.
273      * </p>
274      * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} for more
275      * details.
276      */
277     public static final int TYPE_GAME_ROTATION_VECTOR = 15;
278 
279     /**
280      * A constant string describing an uncalibrated rotation vector sensor type.
281      *
282      * @see #TYPE_GAME_ROTATION_VECTOR
283      */
284     public static final String STRING_TYPE_GAME_ROTATION_VECTOR =
285             "android.sensor.game_rotation_vector";
286 
287     /**
288      * A constant describing an uncalibrated gyroscope sensor type.
289      * <p>Similar to {@link #TYPE_GYROSCOPE} but no gyro-drift compensation has been performed
290      * to adjust the given sensor values. However, such gyro-drift bias values
291      * are returned to you separately in the result {@link android.hardware.SensorEvent#values}
292      * so you may use them for custom calibrations.
293      * <p>Factory calibration and temperature compensation is still applied
294      * to the rate of rotation (angular speeds).
295      * </p>
296      * <p> See {@link android.hardware.SensorEvent#values SensorEvent.values} for more
297      * details.
298      */
299     public static final int TYPE_GYROSCOPE_UNCALIBRATED = 16;
300 
301     /**
302      * A constant string describing an uncalibrated gyroscope sensor type.
303      *
304      * @see #TYPE_GYROSCOPE_UNCALIBRATED
305      */
306     public static final String STRING_TYPE_GYROSCOPE_UNCALIBRATED =
307             "android.sensor.gyroscope_uncalibrated";
308 
309     /**
310      * A constant describing a significant motion trigger sensor.
311      * <p>
312      * It triggers when an event occurs and then automatically disables
313      * itself. The sensor continues to operate while the device is asleep
314      * and will automatically wake the device to notify when significant
315      * motion is detected. The application does not need to hold any wake
316      * locks for this sensor to trigger. This is a wake up sensor.
317      * <p>See {@link TriggerEvent} for more details.
318      *
319      * @see #isWakeUpSensor()
320      */
321     public static final int TYPE_SIGNIFICANT_MOTION = 17;
322 
323     /**
324      * A constant string describing a significant motion trigger sensor.
325      *
326      * @see #TYPE_SIGNIFICANT_MOTION
327      */
328     public static final String STRING_TYPE_SIGNIFICANT_MOTION =
329             "android.sensor.significant_motion";
330 
331     /**
332      * A constant describing a step detector sensor.
333      * <p>
334      * A sensor of this type triggers an event each time a step is taken by the user. The only
335      * allowed value to return is 1.0 and an event is generated for each step. Like with any other
336      * event, the timestamp indicates when the event (here the step) occurred, this corresponds to
337      * when the foot hit the ground, generating a high variation in acceleration. This sensor is
338      * only for detecting every individual step as soon as it is taken, for example to perform dead
339      * reckoning. If you only need aggregate number of steps taken over a period of time, register
340      * for {@link #TYPE_STEP_COUNTER} instead. It is defined as a
341      * {@link Sensor#REPORTING_MODE_SPECIAL_TRIGGER} sensor.
342      * <p>
343      * This sensor requires permission {@code android.permission.ACTIVITY_RECOGNITION}.
344      * <p>
345      * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
346      */
347     public static final int TYPE_STEP_DETECTOR = 18;
348 
349     /**
350      * A constant string describing a step detector sensor.
351      *
352      * @see #TYPE_STEP_DETECTOR
353      */
354     public static final String STRING_TYPE_STEP_DETECTOR = "android.sensor.step_detector";
355 
356     /**
357      * A constant describing a step counter sensor.
358      * <p>
359      * A sensor of this type returns the number of steps taken by the user since the last reboot
360      * while activated. The value is returned as a float (with the fractional part set to zero) and
361      * is reset to zero only on a system reboot. The timestamp of the event is set to the time when
362      * the last step for that event was taken. This sensor is implemented in hardware and is
363      * expected to be low power. If you want to continuously track the number of steps over a long
364      * period of time, do NOT unregister for this sensor, so that it keeps counting steps in the
365      * background even when the AP is in suspend mode and report the aggregate count when the AP
366      * is awake. Application needs to stay registered for this sensor because step counter does not
367      * count steps if it is not activated. This sensor is ideal for fitness tracking applications.
368      * It is defined as an {@link Sensor#REPORTING_MODE_ON_CHANGE} sensor.
369      * <p>
370      * This sensor requires permission {@code android.permission.ACTIVITY_RECOGNITION}.
371      * <p>
372      * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
373      */
374     public static final int TYPE_STEP_COUNTER = 19;
375 
376     /**
377      * A constant string describing a step counter sensor.
378      *
379      * @see #TYPE_STEP_COUNTER
380      */
381     public static final String STRING_TYPE_STEP_COUNTER = "android.sensor.step_counter";
382 
383     /**
384      * A constant describing a geo-magnetic rotation vector.
385      * <p>
386      * Similar to {@link #TYPE_ROTATION_VECTOR}, but using a magnetometer instead of using a
387      * gyroscope. This sensor uses lower power than the other rotation vectors, because it doesn't
388      * use the gyroscope. However, it is more noisy and will work best outdoors.
389      * <p>
390      * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
391      */
392     public static final int TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20;
393 
394     /**
395      * A constant string describing a geo-magnetic rotation vector.
396      *
397      * @see #TYPE_GEOMAGNETIC_ROTATION_VECTOR
398      */
399     public static final String STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR =
400             "android.sensor.geomagnetic_rotation_vector";
401 
402     /**
403      * A constant describing a heart rate monitor.
404      * <p>
405      * The reported value is the heart rate in beats per minute.
406      * <p>
407      * The reported accuracy represents the status of the monitor during the reading. See the
408      * {@code SENSOR_STATUS_*} constants in {@link android.hardware.SensorManager SensorManager}
409      * for more details on accuracy/status values. In particular, when the accuracy is
410      * {@code SENSOR_STATUS_UNRELIABLE} or {@code SENSOR_STATUS_NO_CONTACT}, the heart rate
411      * value should be discarded.
412      * <p>
413      * This sensor requires permission {@code android.permission.BODY_SENSORS}.
414      * It will not be returned by {@code SensorManager.getSensorsList} nor
415      * {@code SensorManager.getDefaultSensor} if the application doesn't have this permission.
416      */
417     public static final int TYPE_HEART_RATE = 21;
418 
419     /**
420      * A constant string describing a heart rate monitor.
421      *
422      * @see #TYPE_HEART_RATE
423      */
424     public static final String STRING_TYPE_HEART_RATE = "android.sensor.heart_rate";
425 
426     /**
427      * A sensor of this type generates an event each time a tilt event is detected. A tilt event
428      * is generated if the direction of the 2-seconds window average gravity changed by at
429      * least 35 degrees since the activation of the sensor. It is a wake up sensor.
430      *
431      * @hide
432      * @see #isWakeUpSensor()
433      */
434     public static final int TYPE_TILT_DETECTOR = 22;
435 
436     /**
437      * A constant string describing a wake up tilt detector sensor type.
438      *
439      * @hide
440      * @see #TYPE_TILT_DETECTOR
441      */
442     public static final String SENSOR_STRING_TYPE_TILT_DETECTOR =
443             "android.sensor.tilt_detector";
444 
445     /**
446      * A constant describing a wake gesture sensor.
447      * <p>
448      * Wake gesture sensors enable waking up the device based on a device specific motion.
449      * <p>
450      * When this sensor triggers, the device behaves as if the power button was pressed, turning the
451      * screen on. This behavior (turning on the screen when this sensor triggers) might be
452      * deactivated by the user in the device settings. Changes in settings do not impact the
453      * behavior of the sensor: only whether the framework turns the screen on when it triggers.
454      * <p>
455      * The actual gesture to be detected is not specified, and can be chosen by the manufacturer of
456      * the device. This sensor must be low power, as it is likely to be activated 24/7.
457      * Values of events created by this sensors should not be used.
458      *
459      * @see #isWakeUpSensor()
460      * @hide This sensor is expected to only be used by the system ui
461      */
462     public static final int TYPE_WAKE_GESTURE = 23;
463 
464     /**
465      * A constant string describing a wake gesture sensor.
466      *
467      * @hide This sensor is expected to only be used by the system ui
468      * @see #TYPE_WAKE_GESTURE
469      */
470     public static final String STRING_TYPE_WAKE_GESTURE = "android.sensor.wake_gesture";
471 
472     /**
473      * A constant describing a wake gesture sensor.
474      * <p>
475      * A sensor enabling briefly turning the screen on to enable the user to
476      * glance content on screen based on a specific motion.  The device should
477      * turn the screen off after a few moments.
478      * <p>
479      * When this sensor triggers, the device turns the screen on momentarily
480      * to allow the user to glance notifications or other content while the
481      * device remains locked in a non-interactive state (dozing). This behavior
482      * (briefly turning on the screen when this sensor triggers) might be deactivated
483      * by the user in the device settings. Changes in settings do not impact the
484      * behavior of the sensor: only whether the framework briefly turns the screen on
485      * when it triggers.
486      * <p>
487      * The actual gesture to be detected is not specified, and can be chosen by the manufacturer of
488      * the device. This sensor must be low power, as it is likely to be activated 24/7.
489      * Values of events created by this sensors should not be used.
490      *
491      * @see #isWakeUpSensor()
492      * @hide This sensor is expected to only be used by the system ui
493      */
494     public static final int TYPE_GLANCE_GESTURE = 24;
495 
496     /**
497      * A constant string describing a wake gesture sensor.
498      *
499      * @hide This sensor is expected to only be used by the system ui
500      * @see #TYPE_GLANCE_GESTURE
501      */
502     public static final String STRING_TYPE_GLANCE_GESTURE = "android.sensor.glance_gesture";
503 
504     /**
505      * A constant describing a pick up sensor.
506      *
507      * A sensor of this type triggers when the device is picked up regardless of wherever it was
508      * before (desk, pocket, bag). The only allowed return value is 1.0. This sensor deactivates
509      * itself immediately after it triggers.
510      *
511      * @hide Expected to be used internally for always on display.
512      */
513     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
514     public static final int TYPE_PICK_UP_GESTURE = 25;
515 
516     /**
517      * A constant string describing a pick up sensor.
518      *
519      * @hide This sensor is expected to be used internally for always on display.
520      * @see #TYPE_PICK_UP_GESTURE
521      */
522     public static final String STRING_TYPE_PICK_UP_GESTURE = "android.sensor.pick_up_gesture";
523 
524     /**
525      * A constant describing a wrist tilt gesture sensor.
526      *
527      * A sensor of this type triggers when the device face is tilted towards the user.
528      * The only allowed return value is 1.0.
529      * This sensor remains active until disabled.
530      *
531      * @hide This sensor is expected to only be used by the system ui
532      */
533     @SystemApi
534     public static final int TYPE_WRIST_TILT_GESTURE = 26;
535 
536     /**
537      * A constant string describing a wrist tilt gesture sensor.
538      *
539      * @hide This sensor is expected to only be used by the system ui
540      * @see #TYPE_WRIST_TILT_GESTURE
541      */
542     @SystemApi
543     public static final String STRING_TYPE_WRIST_TILT_GESTURE = "android.sensor.wrist_tilt_gesture";
544 
545     /**
546      * The current orientation of the device.
547      * <p>
548      * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
549      *
550      * @hide Expected to be used internally for auto-rotate and speaker rotation.
551      *
552      */
553     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
554     public static final int TYPE_DEVICE_ORIENTATION = 27;
555 
556     /**
557      * A constant string describing a device orientation sensor type.
558      *
559      * @hide
560      * @see #TYPE_DEVICE_ORIENTATION
561      */
562     public static final String STRING_TYPE_DEVICE_ORIENTATION = "android.sensor.device_orientation";
563 
564     /**
565      * A constant describing a pose sensor with 6 degrees of freedom.
566      *
567      * Similar to {@link #TYPE_ROTATION_VECTOR}, with additional delta
568      * translation from an arbitrary reference point.
569      *
570      * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
571      *
572      * Can use camera, depth sensor etc to compute output value.
573      *
574      * This is expected to be a high power sensor and expected only to be
575      * used when the screen is on.
576      *
577      * Expected to be more accurate than the rotation vector alone.
578      *
579      */
580     public static final int TYPE_POSE_6DOF = 28;
581 
582     /**
583      * A constant string describing a pose sensor with 6 degrees of freedom.
584      *
585      * @see #TYPE_POSE_6DOF
586      */
587     public static final String STRING_TYPE_POSE_6DOF = "android.sensor.pose_6dof";
588 
589     /**
590      * A constant describing a stationary detect sensor.
591      *
592      * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
593      *
594      */
595     public static final int TYPE_STATIONARY_DETECT = 29;
596 
597     /**
598      * A constant string describing a stationary detection sensor.
599      *
600      * @see #TYPE_STATIONARY_DETECT
601      */
602     public static final String STRING_TYPE_STATIONARY_DETECT = "android.sensor.stationary_detect";
603 
604     /**
605      * A constant describing a motion detect sensor.
606      *
607      * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
608      *
609      */
610     public static final int TYPE_MOTION_DETECT = 30;
611 
612     /**
613      * A constant string describing a motion detection sensor.
614      *
615      * @see #TYPE_MOTION_DETECT
616      */
617     public static final String STRING_TYPE_MOTION_DETECT = "android.sensor.motion_detect";
618 
619     /**
620      * A constant describing a heart beat sensor.
621      *
622      * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
623      *
624      */
625     public static final int TYPE_HEART_BEAT = 31;
626 
627     /**
628      * A constant string describing a heart beat sensor.
629      *
630      * @see #TYPE_HEART_BEAT
631      */
632 
633     public static final String STRING_TYPE_HEART_BEAT = "android.sensor.heart_beat";
634     /**
635      * A constant describing a dynamic sensor meta event sensor.
636      *
637      * A sensor event of this type is received when a dynamic sensor is added to or removed from
638      * the system. This sensor type should always use special trigger report mode ({@code
639      * SensorManager.REPORTING_MODE_SPECIAL_TRIGGER}).
640      *
641      * @hide This sensor is expected to be used only by system services.
642      */
643     @SystemApi
644     public static final int TYPE_DYNAMIC_SENSOR_META = 32;
645 
646     /**
647      * A constant string describing a dynamic sensor meta event sensor.
648      *
649      * @see #TYPE_DYNAMIC_SENSOR_META
650      *
651      * @hide This sensor is expected to only be used by the system service
652      */
653     @SystemApi
654     public static final String STRING_TYPE_DYNAMIC_SENSOR_META =
655             "android.sensor.dynamic_sensor_meta";
656 
657     /* TYPE_ADDITIONAL_INFO - defined as type 33 in the HAL is not exposed to
658      * applications. There are parts of the framework that require the sensors
659      * to be in the same order as the HAL. Skipping this sensor
660      */
661 
662     /**
663      * A constant describing a low latency off-body detect sensor.
664      *
665      * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
666      *
667      */
668     public static final int TYPE_LOW_LATENCY_OFFBODY_DETECT = 34;
669 
670 
671     /**
672      * A constant string describing a low-latency offbody detector sensor.
673      *
674      * @see #TYPE_LOW_LATENCY_OFFBODY_DETECT
675      */
676     public static final String STRING_TYPE_LOW_LATENCY_OFFBODY_DETECT =
677             "android.sensor.low_latency_offbody_detect";
678 
679     /**
680      * A constant describing an uncalibrated accelerometer sensor.
681      *
682      * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
683      *
684      */
685     public static final int TYPE_ACCELEROMETER_UNCALIBRATED = 35;
686 
687     /**
688      * A constant string describing an uncalibrated accelerometer sensor.
689      *
690      * @see #TYPE_ACCELEROMETER_UNCALIBRATED
691      *
692      */
693     public static final String STRING_TYPE_ACCELEROMETER_UNCALIBRATED =
694             "android.sensor.accelerometer_uncalibrated";
695 
696     /**
697      * A constant describing a hinge angle sensor.
698      *
699      * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details.
700      *
701      */
702     public static final int TYPE_HINGE_ANGLE = 36;
703 
704     /**
705      * A constant string describing a hinge angle sensor.
706      *
707      * @see #TYPE_HINGE_ANGLE
708      *
709      */
710     public static final String STRING_TYPE_HINGE_ANGLE = "android.sensor.hinge_angle";
711 
712     /**
713      * A constant describing all sensor types.
714      */
715 
716     public static final int TYPE_ALL = -1;
717 
718     /**
719      * The lowest sensor type vendor defined sensors can use.
720      *
721      * All vendor sensor types are greater than or equal to this constant.
722      *
723      */
724     public static final int TYPE_DEVICE_PRIVATE_BASE = 0x10000;
725 
726     // If this flag is set, the sensor defined as a wake up sensor. This field and REPORTING_MODE_*
727     // constants are defined as flags in sensors.h. Modify at both places if needed.
728     private static final int SENSOR_FLAG_WAKE_UP_SENSOR = 1;
729 
730     /**
731      * Events are reported at a constant rate which is set by the rate parameter of
732      * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)}. Note: If other
733      * applications are requesting a higher rate, the sensor data might be delivered at faster rates
734      * than requested.
735      */
736     public static final int REPORTING_MODE_CONTINUOUS = 0;
737 
738     /**
739      * Events are reported only when the value changes. Event delivery rate can be limited by
740      * setting appropriate value for rate parameter of
741      * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)} Note: If other
742      * applications are requesting a higher rate, the sensor data might be delivered at faster rates
743      * than requested.
744      */
745     public static final int REPORTING_MODE_ON_CHANGE = 1;
746 
747     /**
748      * Events are reported in one-shot mode. Upon detection of an event, the sensor deactivates
749      * itself and then sends a single event. Sensors of this reporting mode must be registered to
750      * using {@link SensorManager#requestTriggerSensor(TriggerEventListener, Sensor)}.
751      */
752     public static final int REPORTING_MODE_ONE_SHOT = 2;
753 
754     /**
755      * Events are reported as described in the description of the sensor. The rate passed to
756      * registerListener might not have an impact on the rate of event delivery. See the sensor
757      * definition for more information on when and how frequently the events are reported. For
758      * example, step detectors report events when a step is detected.
759      *
760      * @see SensorManager#registerListener(SensorEventListener, Sensor, int, int)
761      */
762     public static final int REPORTING_MODE_SPECIAL_TRIGGER = 3;
763 
764     // Mask for the LSB 2nd, 3rd and fourth bits.
765     private static final int REPORTING_MODE_MASK = 0xE;
766     private static final int REPORTING_MODE_SHIFT = 1;
767 
768     // MASK for LSB fifth bit. Used to know whether the sensor supports data injection or not.
769     private static final int DATA_INJECTION_MASK = 0x10;
770     private static final int DATA_INJECTION_SHIFT = 4;
771 
772     // MASK for dynamic sensor (sensor that added during runtime), bit 5.
773     private static final int DYNAMIC_SENSOR_MASK = 0x20;
774     private static final int DYNAMIC_SENSOR_SHIFT = 5;
775 
776     // MASK for indication bit of sensor additional information support, bit 6.
777     private static final int ADDITIONAL_INFO_MASK = 0x40;
778     private static final int ADDITIONAL_INFO_SHIFT = 6;
779 
780     // Mask for direct mode highest rate level, bit 7, 8, 9.
781     private static final int DIRECT_REPORT_MASK = 0x380;
782     private static final int DIRECT_REPORT_SHIFT = 7;
783 
784     // Mask for supported direct channel, bit 10, 11
785     private static final int DIRECT_CHANNEL_MASK = 0xC00;
786     private static final int DIRECT_CHANNEL_SHIFT = 10;
787 
788     // TODO(): The following arrays are fragile and error-prone. This needs to be refactored.
789 
790     // Note: This needs to be updated, whenever a new sensor is added.
791     // Holds the reporting mode and maximum length of the values array
792     // associated with
793     // {@link SensorEvent} or {@link TriggerEvent} for the Sensor
794     private static final int[] sSensorReportingModes = {
795             0, // padding because sensor types start at 1
796             3, // SENSOR_TYPE_ACCELEROMETER
797             3, // SENSOR_TYPE_GEOMAGNETIC_FIELD
798             3, // SENSOR_TYPE_ORIENTATION
799             3, // SENSOR_TYPE_GYROSCOPE
800             1, // SENSOR_TYPE_LIGHT
801             1, // SENSOR_TYPE_PRESSURE
802             1, // SENSOR_TYPE_TEMPERATURE
803             1, // SENSOR_TYPE_PROXIMITY
804             3, // SENSOR_TYPE_GRAVITY
805             3, // SENSOR_TYPE_LINEAR_ACCELERATION
806             5, // SENSOR_TYPE_ROTATION_VECTOR
807             1, // SENSOR_TYPE_RELATIVE_HUMIDITY
808             1, // SENSOR_TYPE_AMBIENT_TEMPERATURE
809             6, // SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
810             4, // SENSOR_TYPE_GAME_ROTATION_VECTOR
811             6, // SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
812             1, // SENSOR_TYPE_SIGNIFICANT_MOTION
813             1, // SENSOR_TYPE_STEP_DETECTOR
814             1, // SENSOR_TYPE_STEP_COUNTER
815             5, // SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
816             1, // SENSOR_TYPE_HEART_RATE_MONITOR
817             1, // SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
818             1, // SENSOR_TYPE_WAKE_GESTURE
819             1, // SENSOR_TYPE_GLANCE_GESTURE
820             1, // SENSOR_TYPE_PICK_UP_GESTURE
821             1, // SENSOR_TYPE_WRIST_TILT_GESTURE
822             1, // SENSOR_TYPE_DEVICE_ORIENTATION
823             16, // SENSOR_TYPE_POSE_6DOF
824             1, // SENSOR_TYPE_STATIONARY_DETECT
825             1, // SENSOR_TYPE_MOTION_DETECT
826             1, // SENSOR_TYPE_HEART_BEAT
827             2, // SENSOR_TYPE_DYNAMIC_SENSOR_META
828             16, // skip over additional sensor info type
829             1, // SENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT
830             6, // SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED
831             1, // SENSOR_TYPE_HINGE_ANGLE
832     };
833 
834     /**
835      * Each sensor has exactly one reporting mode associated with it. This method returns the
836      * reporting mode constant for this sensor type.
837      *
838      * @return Reporting mode for the input sensor, one of REPORTING_MODE_* constants.
839      * @see #REPORTING_MODE_CONTINUOUS
840      * @see #REPORTING_MODE_ON_CHANGE
841      * @see #REPORTING_MODE_ONE_SHOT
842      * @see #REPORTING_MODE_SPECIAL_TRIGGER
843      */
getReportingMode()844     public int getReportingMode() {
845         return ((mFlags & REPORTING_MODE_MASK) >> REPORTING_MODE_SHIFT);
846     }
847 
848     /**
849      * Get the highest supported direct report mode rate level of the sensor.
850      *
851      * @return Highest direct report rate level of this sensor. Note that if the app does not have
852      * the {@link android.Manifest.permission#HIGH_SAMPLING_RATE_SENSORS} permission, the highest
853      * direct report rate level is {@link SensorDirectChannel#RATE_NORMAL}. If the sensor
854      * does not support direct report mode, this returns {@link SensorDirectChannel#RATE_STOP}.
855      * @see SensorDirectChannel#RATE_STOP
856      * @see SensorDirectChannel#RATE_NORMAL
857      * @see SensorDirectChannel#RATE_FAST
858      * @see SensorDirectChannel#RATE_VERY_FAST
859      */
860     @SensorDirectChannel.RateLevel
getHighestDirectReportRateLevel()861     public int getHighestDirectReportRateLevel() {
862         int rateLevel = ((mFlags & DIRECT_REPORT_MASK) >> DIRECT_REPORT_SHIFT);
863         return rateLevel <= SensorDirectChannel.RATE_VERY_FAST
864                 ? rateLevel : SensorDirectChannel.RATE_VERY_FAST;
865     }
866 
867     /**
868      * Test if a sensor supports a specified direct channel type.
869      *
870      * @param sharedMemType type of shared memory used by direct channel.
871      * @return <code>true</code> if the specified shared memory type is supported.
872      * @see SensorDirectChannel#TYPE_MEMORY_FILE
873      * @see SensorDirectChannel#TYPE_HARDWARE_BUFFER
874      */
isDirectChannelTypeSupported(@ensorDirectChannel.MemoryType int sharedMemType)875     public boolean isDirectChannelTypeSupported(@SensorDirectChannel.MemoryType int sharedMemType) {
876         switch (sharedMemType) {
877             case SensorDirectChannel.TYPE_MEMORY_FILE:
878                 return (mFlags & (1 << DIRECT_CHANNEL_SHIFT)) > 0;
879             case SensorDirectChannel.TYPE_HARDWARE_BUFFER:
880                 return (mFlags & (1 << DIRECT_CHANNEL_SHIFT + 1)) > 0;
881             default:
882                 return false;
883         }
884     }
885 
886     /**
887      * Return sensor's maximum length of values array
888      * @hide
889      */
getMaxLengthValuesArray(Sensor sensor, int sdkLevel)890     public static int getMaxLengthValuesArray(Sensor sensor, int sdkLevel) {
891         // RotationVector length has changed to 3 to 5 for API level 18
892         // Set it to 3 for backward compatibility.
893         if (sensor.mType == Sensor.TYPE_ROTATION_VECTOR
894                 && sdkLevel <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
895             return 3;
896         }
897         int offset = sensor.mType;
898         if (offset >= sSensorReportingModes.length) {
899             // we don't know about this sensor, so this is probably a vendor-defined sensor, in that
900             // case, we don't know how many value it has so we return the maximum and assume the app
901             // will know.
902             // FIXME: sensor HAL should advertise how much data is returned per sensor
903             return 16;
904         }
905         return sSensorReportingModes[offset];
906     }
907 
908     /* Some of these fields are set only by the native bindings in
909      * SensorManager.
910      */
911     private String  mName;
912     private String  mVendor;
913     private int     mVersion;
914     private int     mHandle;
915     private int     mType;
916     private float   mMaxRange;
917     private float   mResolution;
918     private float   mPower;
919     private int     mMinDelay;
920     private int     mFifoReservedEventCount;
921     private int     mFifoMaxEventCount;
922     private String  mStringType;
923     private String  mRequiredPermission;
924     private int     mMaxDelay;
925     @UnsupportedAppUsage
926     private int     mFlags;
927     private int     mId;
928 
Sensor()929     Sensor() {
930     }
931 
932     /**
933      * Construct a sensor object from SensorInfo of an input device.
934      * This is only used for constructing an input device sensor object.
935      * @hide
936      */
Sensor(InputSensorInfo sensorInfo)937     public Sensor(InputSensorInfo sensorInfo) {
938         this.mName = sensorInfo.getName();
939         this.mVendor = sensorInfo.getVendor();
940         this.mVersion = sensorInfo.getVersion();
941         this.mHandle = sensorInfo.getHandle();
942         this.mType = sensorInfo.getType();
943         this.mMaxRange = sensorInfo.getMaxRange();
944         this.mResolution = sensorInfo.getResolution();
945         this.mPower = sensorInfo.getPower();
946         this.mMinDelay = sensorInfo.getMinDelay();
947         this.mFifoReservedEventCount = sensorInfo.getFifoReservedEventCount();
948         this.mFifoMaxEventCount = sensorInfo.getFifoMaxEventCount();
949         this.mStringType = sensorInfo.getStringType();
950         this.mRequiredPermission = sensorInfo.getRequiredPermission();
951         this.mMaxDelay = sensorInfo.getMaxDelay();
952         this.mFlags = sensorInfo.getFlags();
953         this.mId = sensorInfo.getId();
954     }
955 
956     /**
957      * @return name string of the sensor. The name is guaranteed to be unique
958      * for a particular sensor type.
959      */
getName()960     public String getName() {
961         return mName;
962     }
963 
964     /**
965      * @return vendor string of this sensor.
966      */
getVendor()967     public String getVendor() {
968         return mVendor;
969     }
970 
971     /**
972      * @return generic type of this sensor.
973      */
getType()974     public int getType() {
975         return mType;
976     }
977 
978     /**
979      * @return version of the sensor's module.
980      */
getVersion()981     public int getVersion() {
982         return mVersion;
983     }
984 
985     /**
986      * @return maximum range of the sensor in the sensor's unit.
987      */
getMaximumRange()988     public float getMaximumRange() {
989         return mMaxRange;
990     }
991 
992     /**
993      * @return resolution of the sensor in the sensor's unit.
994      */
getResolution()995     public float getResolution() {
996         return mResolution;
997     }
998 
999     /**
1000      * @return the power in mA used by this sensor while in use
1001      */
getPower()1002     public float getPower() {
1003         return mPower;
1004     }
1005 
1006     /**
1007      * @return the minimum delay allowed between two events in microseconds
1008      * or zero if this sensor only returns a value when the data it's measuring
1009      * changes. Note that if the app does not have the
1010      * {@link android.Manifest.permission#HIGH_SAMPLING_RATE_SENSORS} permission, the
1011      * minimum delay is capped at 5000 microseconds (200 Hz).
1012      */
getMinDelay()1013     public int getMinDelay() {
1014         return mMinDelay;
1015     }
1016 
1017     /**
1018      * @return Number of events reserved for this sensor in the batch mode FIFO. This gives a
1019      * guarantee on the minimum number of events that can be batched.
1020      */
getFifoReservedEventCount()1021     public int getFifoReservedEventCount() {
1022         return mFifoReservedEventCount;
1023     }
1024 
1025     /**
1026      * @return Maximum number of events of this sensor that could be batched. If this value is zero
1027      * it indicates that batch mode is not supported for this sensor. If other applications
1028      * registered to batched sensors, the actual number of events that can be batched might be
1029      * smaller because the hardware FiFo will be partially used to batch the other sensors.
1030      */
getFifoMaxEventCount()1031     public int getFifoMaxEventCount() {
1032         return mFifoMaxEventCount;
1033     }
1034 
1035     /**
1036      * @return The type of this sensor as a string.
1037      */
getStringType()1038     public String getStringType() {
1039         return mStringType;
1040     }
1041 
1042     /**
1043      * Do not use.
1044      *
1045      * This method throws an UnsupportedOperationException.
1046      *
1047      * Use getId() if you want a unique ID.
1048      *
1049      * @see getId
1050      *
1051      * @hide
1052      */
1053     @SystemApi
getUuid()1054     public java.util.UUID getUuid() {
1055         throw new UnsupportedOperationException();
1056     }
1057 
1058     /**
1059      * @return The sensor id that will be unique for the same app unless the device is factory
1060      * reset. Return value of 0 means this sensor does not support this function; return value of -1
1061      * means this sensor can be uniquely identified in system by combination of its type and name.
1062      */
getId()1063     public int getId() {
1064         return mId;
1065     }
1066 
1067     /**
1068      * @hide
1069      * @return The permission required to access this sensor. If empty, no permission is required.
1070      */
getRequiredPermission()1071     public String getRequiredPermission() {
1072         return mRequiredPermission;
1073     }
1074 
1075     /** @hide */
1076     @UnsupportedAppUsage
getHandle()1077     public int getHandle() {
1078         return mHandle;
1079     }
1080 
1081     /**
1082      * This value is defined only for continuous and on-change sensors. It is the delay between two
1083      * sensor events corresponding to the lowest frequency that this sensor supports. When lower
1084      * frequencies are requested through registerListener() the events will be generated at this
1085      * frequency instead. It can be used to estimate when the batch FIFO may be full. Older devices
1086      * may set this value to zero. Ignore this value in case it is negative or zero.
1087      *
1088      * @return The max delay for this sensor in microseconds.
1089      */
getMaxDelay()1090     public int getMaxDelay() {
1091         return mMaxDelay;
1092     }
1093 
1094     /**
1095      * Returns true if the sensor is a wake-up sensor.
1096      * <p>
1097      * <b>Application Processor Power modes</b> <p>
1098      * Application Processor(AP), is the processor on which applications run.  When no wake lock is
1099      * held and the user is not interacting with the device, this processor can enter a “Suspend”
1100      * mode, reducing the power consumption by 10 times or more.
1101      * </p>
1102      * <p>
1103      * <b>Non-wake-up sensors</b> <p>
1104      * Non-wake-up sensors are sensors that do not wake the AP out of suspend to report data. While
1105      * the AP is in suspend mode, the sensors continue to function and generate events, which are
1106      * put in a hardware FIFO. The events in the FIFO are delivered to the application when the AP
1107      * wakes up. If the FIFO was too small to store all events generated while the AP was in
1108      * suspend mode, the older events are lost: the oldest data is dropped to accommodate the newer
1109      * data. In the extreme case where the FIFO is non-existent {@code maxFifoEventCount() == 0},
1110      * all events generated while the AP was in suspend mode are lost. Applications using
1111      * non-wake-up sensors should usually:
1112      * <ul>
1113      * <li>Either unregister from the sensors when they do not need them, usually in the activity’s
1114      * {@code onPause} method. This is the most common case.
1115      * <li>Or realize that the sensors are consuming some power while the AP is in suspend mode and
1116      * that even then, some events might be lost.
1117      * </ul>
1118      * </p>
1119      * <p>
1120      * <b>Wake-up sensors</b> <p>
1121      * In opposition to non-wake-up sensors, wake-up sensors ensure that their data is delivered
1122      * independently of the state of the AP. While the AP is awake, the wake-up sensors behave
1123      * like non-wake-up-sensors. When the AP is asleep, wake-up sensors wake up the AP to deliver
1124      * events. That is, the AP will wake up and the sensor will deliver the events before the
1125      * maximum reporting latency is elapsed or the hardware FIFO gets full. See {@link
1126      * SensorManager#registerListener(SensorEventListener, Sensor, int, int)} for more details.
1127      * </p>
1128      *
1129      * @return <code>true</code> if this is a wake-up sensor, <code>false</code> otherwise.
1130      */
isWakeUpSensor()1131     public boolean isWakeUpSensor() {
1132         return (mFlags & SENSOR_FLAG_WAKE_UP_SENSOR) != 0;
1133     }
1134 
1135     /**
1136      * Returns true if the sensor is a dynamic sensor.
1137      *
1138      * @return <code>true</code> if the sensor is a dynamic sensor (sensor added at runtime).
1139      * @see SensorManager.DynamicSensorCallback
1140      */
isDynamicSensor()1141     public boolean isDynamicSensor() {
1142         return (mFlags & DYNAMIC_SENSOR_MASK) != 0;
1143     }
1144 
1145     /**
1146      * Returns true if the sensor supports sensor additional information API
1147      *
1148      * @return <code>true</code> if the sensor supports sensor additional information API
1149      * @see SensorAdditionalInfo
1150      */
isAdditionalInfoSupported()1151     public boolean isAdditionalInfoSupported() {
1152         return (mFlags & ADDITIONAL_INFO_MASK) != 0;
1153     }
1154 
1155     /**
1156      * Returns true if the sensor supports data injection when the
1157      * HAL is set to data injection mode.
1158      *
1159      * @return <code>true</code> if the sensor supports data
1160      *         injection when the HAL is set in injection mode,
1161      *         false otherwise.
1162      * @hide
1163      */
1164     @SystemApi
isDataInjectionSupported()1165     public boolean isDataInjectionSupported() {
1166         return (((mFlags & DATA_INJECTION_MASK) >> DATA_INJECTION_SHIFT)) != 0;
1167     }
1168 
setRange(float max, float res)1169     void setRange(float max, float res) {
1170         mMaxRange = max;
1171         mResolution = res;
1172     }
1173 
1174     @Override
toString()1175     public String toString() {
1176         return "{Sensor name=\"" + mName + "\", vendor=\"" + mVendor + "\", version=" + mVersion
1177                 + ", type=" + mType + ", maxRange=" + mMaxRange + ", resolution=" + mResolution
1178                 + ", power=" + mPower + ", minDelay=" + mMinDelay + "}";
1179     }
1180 
1181     /**
1182      * Sets the Type associated with the sensor.
1183      * NOTE: to be used only by native bindings in SensorManager.
1184      *
1185      * This allows interned static strings to be used across all representations of the Sensor. If
1186      * a sensor type is not referenced here, it will still be interned by the native SensorManager.
1187      *
1188      * @return {@code true} if the StringType was successfully set, {@code false} otherwise.
1189      */
setType(int value)1190     private boolean setType(int value) {
1191         mType = value;
1192         switch (mType) {
1193             case TYPE_ACCELEROMETER:
1194                 mStringType = STRING_TYPE_ACCELEROMETER;
1195                 return true;
1196             case TYPE_AMBIENT_TEMPERATURE:
1197                 mStringType = STRING_TYPE_AMBIENT_TEMPERATURE;
1198                 return true;
1199             case TYPE_GAME_ROTATION_VECTOR:
1200                 mStringType = STRING_TYPE_GAME_ROTATION_VECTOR;
1201                 return true;
1202             case TYPE_GEOMAGNETIC_ROTATION_VECTOR:
1203                 mStringType = STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR;
1204                 return true;
1205             case TYPE_GLANCE_GESTURE:
1206                 mStringType = STRING_TYPE_GLANCE_GESTURE;
1207                 return true;
1208             case TYPE_GRAVITY:
1209                 mStringType = STRING_TYPE_GRAVITY;
1210                 return true;
1211             case TYPE_GYROSCOPE:
1212                 mStringType = STRING_TYPE_GYROSCOPE;
1213                 return true;
1214             case TYPE_GYROSCOPE_UNCALIBRATED:
1215                 mStringType = STRING_TYPE_GYROSCOPE_UNCALIBRATED;
1216                 return true;
1217             case TYPE_HEART_RATE:
1218                 mStringType = STRING_TYPE_HEART_RATE;
1219                 return true;
1220             case TYPE_LIGHT:
1221                 mStringType = STRING_TYPE_LIGHT;
1222                 return true;
1223             case TYPE_LINEAR_ACCELERATION:
1224                 mStringType = STRING_TYPE_LINEAR_ACCELERATION;
1225                 return true;
1226             case TYPE_MAGNETIC_FIELD:
1227                 mStringType = STRING_TYPE_MAGNETIC_FIELD;
1228                 return true;
1229             case TYPE_MAGNETIC_FIELD_UNCALIBRATED:
1230                 mStringType = STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED;
1231                 return true;
1232             case TYPE_PICK_UP_GESTURE:
1233                 mStringType = STRING_TYPE_PICK_UP_GESTURE;
1234                 return true;
1235             case TYPE_PRESSURE:
1236                 mStringType = STRING_TYPE_PRESSURE;
1237                 return true;
1238             case TYPE_PROXIMITY:
1239                 mStringType = STRING_TYPE_PROXIMITY;
1240                 return true;
1241             case TYPE_RELATIVE_HUMIDITY:
1242                 mStringType = STRING_TYPE_RELATIVE_HUMIDITY;
1243                 return true;
1244             case TYPE_ROTATION_VECTOR:
1245                 mStringType = STRING_TYPE_ROTATION_VECTOR;
1246                 return true;
1247             case TYPE_SIGNIFICANT_MOTION:
1248                 mStringType = STRING_TYPE_SIGNIFICANT_MOTION;
1249                 return true;
1250             case TYPE_STEP_COUNTER:
1251                 mStringType = STRING_TYPE_STEP_COUNTER;
1252                 return true;
1253             case TYPE_STEP_DETECTOR:
1254                 mStringType = STRING_TYPE_STEP_DETECTOR;
1255                 return true;
1256             case TYPE_TILT_DETECTOR:
1257                 mStringType = SENSOR_STRING_TYPE_TILT_DETECTOR;
1258                 return true;
1259             case TYPE_WAKE_GESTURE:
1260                 mStringType = STRING_TYPE_WAKE_GESTURE;
1261                 return true;
1262             case TYPE_ORIENTATION:
1263                 mStringType = STRING_TYPE_ORIENTATION;
1264                 return true;
1265             case TYPE_TEMPERATURE:
1266                 mStringType = STRING_TYPE_TEMPERATURE;
1267                 return true;
1268             case TYPE_DEVICE_ORIENTATION:
1269                 mStringType = STRING_TYPE_DEVICE_ORIENTATION;
1270                 return true;
1271             case TYPE_DYNAMIC_SENSOR_META:
1272                 mStringType = STRING_TYPE_DYNAMIC_SENSOR_META;
1273                 return true;
1274             case TYPE_LOW_LATENCY_OFFBODY_DETECT:
1275                 mStringType = STRING_TYPE_LOW_LATENCY_OFFBODY_DETECT;
1276                 return true;
1277             case TYPE_ACCELEROMETER_UNCALIBRATED:
1278                 mStringType = STRING_TYPE_ACCELEROMETER_UNCALIBRATED;
1279                 return true;
1280             case TYPE_HINGE_ANGLE:
1281                 mStringType = STRING_TYPE_HINGE_ANGLE;
1282                 return true;
1283             default:
1284                 return false;
1285         }
1286     }
1287 
1288     /**
1289      * Sets the ID associated with the sensor.
1290      *
1291      * The method name is misleading; while this ID is based on the UUID,
1292      * we do not pass in the actual UUID.
1293      *
1294      * NOTE: to be used only by native bindings in SensorManager.
1295      *
1296      * @see #getId
1297      */
setUuid(long msb, long lsb)1298     private void setUuid(long msb, long lsb) {
1299         // TODO(b/29547335): Rename this method to setId.
1300         mId = (int) msb;
1301     }
1302 }
1303