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