Sensor.java revision 241e70d60733cdbb6206f6c26baac85f3a747105
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 18package android.hardware; 19 20import android.os.Build; 21 22/** 23 * Class representing a sensor. Use {@link SensorManager#getSensorList} to get 24 * the list of available Sensors. 25 * 26 * @see SensorManager 27 * @see SensorEventListener 28 * @see SensorEvent 29 * 30 */ 31public final class Sensor { 32 33 /** 34 * A constant describing an accelerometer sensor type. 35 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 36 * for more details. 37 */ 38 public static final int TYPE_ACCELEROMETER = 1; 39 40 /** 41 * A constant string describing an accelerometer sensor type. 42 * 43 * @see #TYPE_ACCELEROMETER 44 */ 45 public static final String STRING_TYPE_ACCELEROMETER = "android.sensor.accelerometer"; 46 47 /** 48 * A constant describing a magnetic field sensor type. 49 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 50 * for more details. 51 */ 52 public static final int TYPE_MAGNETIC_FIELD = 2; 53 54 /** 55 * A constant string describing a magnetic field sensor type. 56 * 57 * @see #TYPE_MAGNETIC_FIELD 58 */ 59 public static final String STRING_TYPE_MAGNETIC_FIELD = "android.sensor.magnetic_field"; 60 61 /** 62 * A constant describing an orientation sensor type. 63 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 64 * for more details. 65 * 66 * @deprecated use {@link android.hardware.SensorManager#getOrientation 67 * SensorManager.getOrientation()} instead. 68 */ 69 @Deprecated 70 public static final int TYPE_ORIENTATION = 3; 71 72 /** 73 * A constant string describing an orientation sensor type. 74 * 75 * @see #TYPE_ORIENTATION 76 * @deprecated use {@link android.hardware.SensorManager#getOrientation 77 * SensorManager.getOrientation()} instead. 78 */ 79 @Deprecated 80 public static final String STRING_TYPE_ORIENTATION = "android.sensor.orientation"; 81 82 /** 83 * A constant describing a gyroscope sensor type. 84 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 85 * for more details. */ 86 public static final int TYPE_GYROSCOPE = 4; 87 88 /** 89 * A constant string describing a gyroscope sensor type. 90 * 91 * @see #TYPE_GYROSCOPE 92 */ 93 public static final String STRING_TYPE_GYROSCOPE = "android.sensor.gyroscope"; 94 95 /** 96 * A constant describing a light sensor type. 97 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 98 * for more details. 99 */ 100 public static final int TYPE_LIGHT = 5; 101 102 /** 103 * A constant string describing a light sensor type. 104 * 105 * @see #TYPE_LIGHT 106 */ 107 public static final String STRING_TYPE_LIGHT = "android.sensor.light"; 108 109 /** 110 * A constant describing a pressure sensor type. 111 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 112 * for more details. 113 */ 114 public static final int TYPE_PRESSURE = 6; 115 116 /** 117 * A constant string describing a pressure sensor type. 118 * 119 * @see #TYPE_PRESSURE 120 */ 121 public static final String STRING_TYPE_PRESSURE = "android.sensor.pressure"; 122 123 /** 124 * A constant describing a temperature sensor type 125 * 126 * @deprecated use 127 * {@link android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE 128 * Sensor.TYPE_AMBIENT_TEMPERATURE} instead. 129 */ 130 @Deprecated 131 public static final int TYPE_TEMPERATURE = 7; 132 133 /** 134 * A constant string describing a temperature sensor type 135 * 136 * @see #TYPE_TEMPERATURE 137 * @deprecated use 138 * {@link android.hardware.Sensor#STRING_TYPE_AMBIENT_TEMPERATURE 139 * Sensor.STRING_TYPE_AMBIENT_TEMPERATURE} instead. 140 */ 141 @Deprecated 142 public static final String STRING_TYPE_TEMPERATURE = "android.sensor.temperature"; 143 144 /** 145 * A constant describing a proximity sensor type. This is a wake up sensor. 146 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 147 * for more details. 148 * @see #isWakeUpSensor() 149 */ 150 public static final int TYPE_PROXIMITY = 8; 151 152 /** 153 * A constant string describing a proximity sensor type. 154 * 155 * @see #TYPE_PROXIMITY 156 */ 157 public static final String STRING_TYPE_PROXIMITY = "android.sensor.proximity"; 158 159 /** 160 * A constant describing a gravity sensor type. 161 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 162 * for more details. 163 */ 164 public static final int TYPE_GRAVITY = 9; 165 166 /** 167 * A constant string describing a gravity sensor type. 168 * 169 * @see #TYPE_GRAVITY 170 */ 171 public static final String STRING_TYPE_GRAVITY = "android.sensor.gravity"; 172 173 /** 174 * A constant describing a linear acceleration sensor type. 175 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 176 * for more details. 177 */ 178 public static final int TYPE_LINEAR_ACCELERATION = 10; 179 180 /** 181 * A constant string describing a linear acceleration sensor type. 182 * 183 * @see #TYPE_LINEAR_ACCELERATION 184 */ 185 public static final String STRING_TYPE_LINEAR_ACCELERATION = 186 "android.sensor.linear_acceleration"; 187 188 /** 189 * A constant describing a rotation vector sensor type. 190 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 191 * for more details. 192 */ 193 public static final int TYPE_ROTATION_VECTOR = 11; 194 195 /** 196 * A constant string describing a rotation vector sensor type. 197 * 198 * @see #TYPE_ROTATION_VECTOR 199 */ 200 public static final String STRING_TYPE_ROTATION_VECTOR = "android.sensor.rotation_vector"; 201 202 /** 203 * A constant describing a relative humidity sensor type. 204 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 205 * for more details. 206 */ 207 public static final int TYPE_RELATIVE_HUMIDITY = 12; 208 209 /** 210 * A constant string describing a relative humidity sensor type 211 * 212 * @see #TYPE_RELATIVE_HUMIDITY 213 */ 214 public static final String STRING_TYPE_RELATIVE_HUMIDITY = "android.sensor.relative_humidity"; 215 216 /** 217 * A constant describing an ambient temperature sensor type. 218 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} 219 * for more details. 220 */ 221 public static final int TYPE_AMBIENT_TEMPERATURE = 13; 222 223 /** 224 * A constant string describing an ambient temperature sensor type. 225 * 226 * @see #TYPE_AMBIENT_TEMPERATURE 227 */ 228 public static final String STRING_TYPE_AMBIENT_TEMPERATURE = 229 "android.sensor.ambient_temperature"; 230 231 /** 232 * A constant describing an uncalibrated magnetic field sensor type. 233 * <p> 234 * Similar to {@link #TYPE_MAGNETIC_FIELD} but the hard iron calibration (device calibration 235 * due to distortions that arise from magnetized iron, steel or permanent magnets on the 236 * device) is not considered in the given sensor values. However, such hard iron bias values 237 * are returned to you separately in the result {@link android.hardware.SensorEvent#values} 238 * so you may use them for custom calibrations. 239 * <p>Also, no periodic calibration is performed 240 * (i.e. there are no discontinuities in the data stream while using this sensor) and 241 * assumptions that the magnetic field is due to the Earth's poles is avoided, but 242 * factory calibration and temperature compensation have been performed. 243 * </p> 244 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} for more 245 * details. 246 */ 247 public static final int TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14; 248 /** 249 * A constant string describing an uncalibrated magnetic field sensor type. 250 * 251 * @see #TYPE_MAGNETIC_FIELD_UNCALIBRATED 252 */ 253 public static final String STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 254 "android.sensor.magnetic_field_uncalibrated"; 255 256 /** 257 * A constant describing an uncalibrated rotation vector sensor type. 258 * <p>Identical to {@link #TYPE_ROTATION_VECTOR} except that it doesn't 259 * use the geomagnetic field. Therefore the Y axis doesn't 260 * point north, but instead to some other reference, that reference is 261 * allowed to drift by the same order of magnitude as the gyroscope 262 * drift around the Z axis. 263 * <p> 264 * In the ideal case, a phone rotated and returning to the same real-world 265 * orientation should report the same game rotation vector 266 * (without using the earth's geomagnetic field). However, the orientation 267 * may drift somewhat over time. 268 * </p> 269 * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} for more 270 * details. 271 */ 272 public static final int TYPE_GAME_ROTATION_VECTOR = 15; 273 274 /** 275 * A constant string describing an uncalibrated rotation vector sensor type. 276 * 277 * @see #TYPE_GAME_ROTATION_VECTOR 278 */ 279 public static final String STRING_TYPE_GAME_ROTATION_VECTOR = 280 "android.sensor.game_rotation_vector"; 281 282 /** 283 * A constant describing an uncalibrated gyroscope sensor type. 284 * <p>Similar to {@link #TYPE_GYROSCOPE} but no gyro-drift compensation has been performed 285 * to adjust the given sensor values. However, such gyro-drift bias values 286 * are returned to you separately in the result {@link android.hardware.SensorEvent#values} 287 * so you may use them for custom calibrations. 288 * <p>Factory calibration and temperature compensation is still applied 289 * to the rate of rotation (angular speeds). 290 * </p> 291 * <p> See {@link android.hardware.SensorEvent#values SensorEvent.values} for more 292 * details. 293 */ 294 public static final int TYPE_GYROSCOPE_UNCALIBRATED = 16; 295 296 /** 297 * A constant string describing an uncalibrated gyroscope sensor type. 298 * 299 * @see #TYPE_GYROSCOPE_UNCALIBRATED 300 */ 301 public static final String STRING_TYPE_GYROSCOPE_UNCALIBRATED = 302 "android.sensor.gyroscope_uncalibrated"; 303 304 /** 305 * A constant describing a significant motion trigger sensor. 306 * <p> 307 * It triggers when an event occurs and then automatically disables 308 * itself. The sensor continues to operate while the device is asleep 309 * and will automatically wake the device to notify when significant 310 * motion is detected. The application does not need to hold any wake 311 * locks for this sensor to trigger. This is a wake up sensor. 312 * <p>See {@link TriggerEvent} for more details. 313 * 314 * @see #isWakeUpSensor() 315 */ 316 public static final int TYPE_SIGNIFICANT_MOTION = 17; 317 318 /** 319 * A constant string describing a significant motion trigger sensor. 320 * 321 * @see #TYPE_SIGNIFICANT_MOTION 322 */ 323 public static final String STRING_TYPE_SIGNIFICANT_MOTION = 324 "android.sensor.significant_motion"; 325 326 /** 327 * A constant describing a step detector sensor. 328 * <p> 329 * A sensor of this type triggers an event each time a step is taken by the user. The only 330 * allowed value to return is 1.0 and an event is generated for each step. Like with any other 331 * event, the timestamp indicates when the event (here the step) occurred, this corresponds to 332 * when the foot hit the ground, generating a high variation in acceleration. 333 * <p> 334 * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details. 335 */ 336 public static final int TYPE_STEP_DETECTOR = 18; 337 338 /** 339 * A constant string describing a step detector sensor. 340 * 341 * @see #TYPE_STEP_DETECTOR 342 */ 343 public static final String STRING_TYPE_STEP_DETECTOR = "android.sensor.step_detector"; 344 345 /** 346 * A constant describing a step counter sensor. 347 * <p> 348 * A sensor of this type returns the number of steps taken by the user since the last reboot 349 * while activated. The value is returned as a float (with the fractional part set to zero) and 350 * is reset to zero only on a system reboot. The timestamp of the event is set to the time when 351 * the first step for that event was taken. This sensor is implemented in hardware and is 352 * expected to be low power. 353 * <p> 354 * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details. 355 */ 356 public static final int TYPE_STEP_COUNTER = 19; 357 358 /** 359 * A constant string describing a step counter sensor. 360 * 361 * @see #TYPE_STEP_COUNTER 362 */ 363 public static final String STRING_TYPE_STEP_COUNTER = "android.sensor.step_counter"; 364 365 /** 366 * A constant describing a geo-magnetic rotation vector. 367 * <p> 368 * Similar to {@link #TYPE_ROTATION_VECTOR}, but using a magnetometer instead of using a 369 * gyroscope. This sensor uses lower power than the other rotation vectors, because it doesn't 370 * use the gyroscope. However, it is more noisy and will work best outdoors. 371 * <p> 372 * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details. 373 */ 374 public static final int TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20; 375 376 /** 377 * A constant string describing a geo-magnetic rotation vector. 378 * 379 * @see #TYPE_GEOMAGNETIC_ROTATION_VECTOR 380 */ 381 public static final String STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 382 "android.sensor.geomagnetic_rotation_vector"; 383 384 /** 385 * A constant describing a heart rate monitor. 386 * <p> 387 * The reported value is the heart rate in beats per minute. 388 * <p> 389 * The reported accuracy represents the status of the monitor during the reading. See the 390 * {@code SENSOR_STATUS_*} constants in {@link android.hardware.SensorManager SensorManager} 391 * for more details on accuracy/status values. In particular, when the accuracy is 392 * {@code SENSOR_STATUS_UNRELIABLE} or {@code SENSOR_STATUS_NO_CONTACT}, the heart rate 393 * value should be discarded. 394 * <p> 395 * This sensor requires permission {@code android.permission.BODY_SENSORS}. 396 * It will not be returned by {@code SensorManager.getSensorsList} nor 397 * {@code SensorManager.getDefaultSensor} if the application doesn't have this permission. 398 */ 399 public static final int TYPE_HEART_RATE = 21; 400 401 /** 402 * A constant string describing a heart rate monitor. 403 * 404 * @see #TYPE_HEART_RATE 405 */ 406 public static final String STRING_TYPE_HEART_RATE = "android.sensor.heart_rate"; 407 408 /** 409 * A non-wake up variant of proximity sensor. 410 * 411 * @see #TYPE_PROXIMITY 412 */ 413 public static final int TYPE_NON_WAKE_UP_PROXIMITY_SENSOR = 22; 414 415 /** 416 * A constant string describing a non-wake up proximity sensor type. 417 * 418 * @see #TYPE_NON_WAKE_UP_PROXIMITY_SENSOR 419 */ 420 public static final String SENSOR_STRING_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR = 421 "android.sensor.non_wake_up_proximity_sensor"; 422 423 /** 424 * A constant describing a wake up variant of accelerometer sensor type. 425 * 426 * @see #isWakeUpSensor() 427 * @see #TYPE_ACCELEROMETER 428 */ 429 public static final int TYPE_WAKE_UP_ACCELEROMETER = 23; 430 431 /** 432 * A constant string describing a wake up accelerometer. 433 * 434 * @see #TYPE_WAKE_UP_ACCELEROMETER 435 */ 436 public static final String STRING_TYPE_WAKE_UP_ACCELEROMETER = 437 "android.sensor.wake_up_accelerometer"; 438 439 /** 440 * A constant describing a wake up variant of a magnetic field sensor type. 441 * 442 * @see #isWakeUpSensor() 443 * @see #TYPE_MAGNETIC_FIELD 444 */ 445 public static final int TYPE_WAKE_UP_MAGNETIC_FIELD = 24; 446 447 /** 448 * A constant string describing a wake up magnetic field sensor. 449 * 450 * @see #TYPE_WAKE_UP_MAGNETIC_FIELD 451 */ 452 public static final String STRING_TYPE_WAKE_UP_MAGNETIC_FIELD = 453 "android.sensor.wake_up_magnetic_field"; 454 455 /** 456 * A constant describing a wake up variant of an orientation sensor type. 457 * 458 * @see #isWakeUpSensor() 459 * @see #TYPE_ORIENTATION 460 */ 461 public static final int TYPE_WAKE_UP_ORIENTATION = 25; 462 463 /** 464 * A constant string describing a wake up orientation sensor. 465 * 466 * @see #TYPE_WAKE_UP_ORIENTATION 467 */ 468 public static final String STRING_TYPE_WAKE_UP_ORIENTATION = 469 "android.sensor.wake_up_orientation"; 470 471 /** 472 * A constant describing a wake up variant of a gyroscope sensor type. 473 * 474 * @see #isWakeUpSensor() 475 * @see #TYPE_GYROSCOPE 476 */ 477 public static final int TYPE_WAKE_UP_GYROSCOPE = 26; 478 479 /** 480 * A constant string describing a wake up gyroscope sensor type. 481 * 482 * @see #TYPE_WAKE_UP_GYROSCOPE 483 */ 484 public static final String STRING_TYPE_WAKE_UP_GYROSCOPE = "android.sensor.wake_up_gyroscope"; 485 486 /** 487 * A constant describing a wake up variant of a light sensor type. 488 * 489 * @see #isWakeUpSensor() 490 * @see #TYPE_LIGHT 491 */ 492 public static final int TYPE_WAKE_UP_LIGHT = 27; 493 494 /** 495 * A constant string describing a wake up light sensor type. 496 * 497 * @see #TYPE_WAKE_UP_LIGHT 498 */ 499 public static final String STRING_TYPE_WAKE_UP_LIGHT = "android.sensor.wake_up_light"; 500 501 /** 502 * A constant describing a wake up variant of a pressure sensor type. 503 * 504 * @see #isWakeUpSensor() 505 * @see #TYPE_PRESSURE 506 */ 507 public static final int TYPE_WAKE_UP_PRESSURE = 28; 508 509 /** 510 * A constant string describing a wake up pressure sensor type. 511 * 512 * @see #TYPE_WAKE_UP_PRESSURE 513 */ 514 public static final String STRING_TYPE_WAKE_UP_PRESSURE = "android.sensor.wake_up_pressure"; 515 516 /** 517 * A constant describing a wake up variant of a gravity sensor type. 518 * 519 * @see #isWakeUpSensor() 520 * @see #TYPE_GRAVITY 521 */ 522 public static final int TYPE_WAKE_UP_GRAVITY = 29; 523 524 /** 525 * A constant string describing a wake up gravity sensor type. 526 * 527 * @see #TYPE_WAKE_UP_GRAVITY 528 */ 529 public static final String STRING_TYPE_WAKE_UP_GRAVITY = "android.sensor.wake_up_gravity"; 530 531 /** 532 * A constant describing a wake up variant of a linear acceleration sensor type. 533 * 534 * @see #isWakeUpSensor() 535 * @see #TYPE_LINEAR_ACCELERATION 536 */ 537 public static final int TYPE_WAKE_UP_LINEAR_ACCELERATION = 30; 538 539 /** 540 * A constant string describing a wake up linear acceleration sensor type. 541 * 542 * @see #TYPE_WAKE_UP_LINEAR_ACCELERATION 543 */ 544 public static final String STRING_TYPE_WAKE_UP_LINEAR_ACCELERATION = 545 "android.sensor.wake_up_linear_acceleration"; 546 547 /** 548 * A constant describing a wake up variant of a rotation vector sensor type. 549 * 550 * @see #isWakeUpSensor() 551 * @see #TYPE_ROTATION_VECTOR 552 */ 553 public static final int TYPE_WAKE_UP_ROTATION_VECTOR = 31; 554 555 /** 556 * A constant string describing a wake up rotation vector sensor type. 557 * 558 * @see #TYPE_WAKE_UP_ROTATION_VECTOR 559 */ 560 public static final String STRING_TYPE_WAKE_UP_ROTATION_VECTOR = 561 "android.sensor.wake_up_rotation_vector"; 562 563 /** 564 * A constant describing a wake up variant of a relative humidity sensor type. 565 * 566 * @see #isWakeUpSensor() 567 * @see #TYPE_RELATIVE_HUMIDITY 568 */ 569 public static final int TYPE_WAKE_UP_RELATIVE_HUMIDITY = 32; 570 571 /** 572 * A constant string describing a wake up relative humidity sensor type. 573 * 574 * @see #TYPE_WAKE_UP_RELATIVE_HUMIDITY 575 */ 576 public static final String STRING_TYPE_WAKE_UP_RELATIVE_HUMIDITY = 577 "android.sensor.wake_up_relative_humidity"; 578 579 /** 580 * A constant describing a wake up variant of an ambient temperature sensor type. 581 * 582 * @see #isWakeUpSensor() 583 * @see #TYPE_AMBIENT_TEMPERATURE 584 */ 585 public static final int TYPE_WAKE_UP_AMBIENT_TEMPERATURE = 33; 586 587 /** 588 * A constant string describing a wake up ambient temperature sensor type. 589 * 590 * @see #TYPE_WAKE_UP_AMBIENT_TEMPERATURE 591 */ 592 public static final String STRING_TYPE_WAKE_UP_AMBIENT_TEMPERATURE = 593 "android.sensor.wake_up_ambient_temperature"; 594 595 /** 596 * A constant describing a wake up variant of an uncalibrated magnetic field sensor type. 597 * 598 * @see #isWakeUpSensor() 599 * @see #TYPE_MAGNETIC_FIELD_UNCALIBRATED 600 */ 601 public static final int TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED = 34; 602 603 /** 604 * A constant string describing a wake up uncalibrated magnetic field sensor type. 605 * 606 * @see #TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED 607 */ 608 public static final String STRING_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED = 609 "android.sensor.wake_up_magnetic_field_uncalibrated"; 610 611 /** 612 * A constant describing a wake up variant of a game rotation vector sensor type. 613 * 614 * @see #isWakeUpSensor() 615 * @see #TYPE_GAME_ROTATION_VECTOR 616 */ 617 public static final int TYPE_WAKE_UP_GAME_ROTATION_VECTOR = 35; 618 619 /** 620 * A constant string describing a wake up game rotation vector sensor type. 621 * 622 * @see #TYPE_WAKE_UP_GAME_ROTATION_VECTOR 623 */ 624 public static final String STRING_TYPE_WAKE_UP_GAME_ROTATION_VECTOR = 625 "android.sensor.wake_up_game_rotation_vector"; 626 627 /** 628 * A constant describing a wake up variant of an uncalibrated gyroscope sensor type. 629 * 630 * @see #isWakeUpSensor() 631 * @see #TYPE_GYROSCOPE_UNCALIBRATED 632 */ 633 public static final int TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED = 36; 634 635 /** 636 * A constant string describing a wake up uncalibrated gyroscope sensor type. 637 * 638 * @see #TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED 639 */ 640 public static final String STRING_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED = 641 "android.sensor.wake_up_gyroscope_uncalibrated"; 642 643 /** 644 * A constant describing a wake up variant of a step detector sensor type. 645 * 646 * @see #isWakeUpSensor() 647 * @see #TYPE_STEP_DETECTOR 648 */ 649 public static final int TYPE_WAKE_UP_STEP_DETECTOR = 37; 650 651 /** 652 * A constant string describing a wake up step detector sensor type. 653 * 654 * @see #TYPE_WAKE_UP_STEP_DETECTOR 655 */ 656 public static final String STRING_TYPE_WAKE_UP_STEP_DETECTOR = 657 "android.sensor.wake_up_step_detector"; 658 659 /** 660 * A constant describing a wake up variant of a step counter sensor type. 661 * 662 * @see #isWakeUpSensor() 663 * @see #TYPE_STEP_COUNTER 664 */ 665 public static final int TYPE_WAKE_UP_STEP_COUNTER = 38; 666 667 /** 668 * A constant string describing a wake up step counter sensor type. 669 * 670 * @see #TYPE_WAKE_UP_STEP_COUNTER 671 */ 672 public static final String STRING_TYPE_WAKE_UP_STEP_COUNTER = 673 "android.sensor.wake_up_step_counter"; 674 675 /** 676 * A constant describing a wake up variant of a geomagnetic rotation vector sensor type. 677 * 678 * @see #isWakeUpSensor() 679 * @see #TYPE_GEOMAGNETIC_ROTATION_VECTOR 680 */ 681 public static final int TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR = 39; 682 683 /** 684 * A constant string describing a wake up geomagnetic rotation vector sensor type. 685 * 686 * @see #TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR 687 */ 688 public static final String STRING_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR = 689 "android.sensor.wake_up_geomagnetic_rotation_vector"; 690 691 /** 692 * A constant describing a wake up variant of a heart rate sensor type. 693 * 694 * @see #isWakeUpSensor() 695 * @see #TYPE_HEART_RATE 696 */ 697 public static final int TYPE_WAKE_UP_HEART_RATE = 40; 698 699 /** 700 * A constant string describing a wake up heart rate sensor type. 701 * 702 * @see #TYPE_WAKE_UP_HEART_RATE 703 */ 704 public static final String STRING_TYPE_WAKE_UP_HEART_RATE = "android.sensor.wake_up_heart_rate"; 705 706 /** 707 * A sensor of this type generates an event each time a tilt event is detected. A tilt event 708 * is generated if the direction of the 2-seconds window average gravity changed by at 709 * least 35 degrees since the activation of the sensor. It is a wake up sensor. 710 * 711 * @hide 712 * @see #isWakeUpSensor() 713 */ 714 public static final int TYPE_WAKE_UP_TILT_DETECTOR = 41; 715 716 /** 717 * A constant string describing a wake up tilt detector sensor type. 718 * 719 * @hide 720 * @see #TYPE_WAKE_UP_TILT_DETECTOR 721 */ 722 public static final String SENSOR_STRING_TYPE_WAKE_UP_TILT_DETECTOR = 723 "android.sensor.wake_up_tilt_detector"; 724 725 /** 726 * A constant describing a wake gesture sensor. 727 * <p> 728 * Wake gesture sensors enable waking up the device based on a device specific motion. 729 * <p> 730 * When this sensor triggers, the device behaves as if the power button was pressed, turning the 731 * screen on. This behavior (turning on the screen when this sensor triggers) might be 732 * deactivated by the user in the device settings. Changes in settings do not impact the 733 * behavior of the sensor: only whether the framework turns the screen on when it triggers. 734 * <p> 735 * The actual gesture to be detected is not specified, and can be chosen by the manufacturer of 736 * the device. This sensor must be low power, as it is likely to be activated 24/7. 737 * Values of events created by this sensors should not be used. 738 * 739 * @see #isWakeUpSensor() 740 * @hide This sensor is expected to only be used by the system ui 741 */ 742 public static final int TYPE_WAKE_GESTURE = 42; 743 744 /** 745 * A constant string describing a wake gesture sensor. 746 * 747 * @hide This sensor is expected to only be used by the system ui 748 * @see #TYPE_WAKE_GESTURE 749 */ 750 public static final String STRING_TYPE_WAKE_GESTURE = "android.sensor.wake_gesture"; 751 752 /** 753 * A constant describing a wake gesture sensor. 754 * <p> 755 * A sensor enabling briefly turning the screen on to enable the user to 756 * glance content on screen based on a specific motion. The device should 757 * turn the screen off after a few moments. 758 * <p> 759 * When this sensor triggers, the device turns the screen on momentarily 760 * to allow the user to glance notifications or other content while the 761 * device remains locked in a non-interactive state (dozing). This behavior 762 * (briefly turning on the screen when this sensor triggers) might be deactivated 763 * by the user in the device settings. Changes in settings do not impact the 764 * behavior of the sensor: only whether the framework briefly turns the screen on 765 * when it triggers. 766 * <p> 767 * The actual gesture to be detected is not specified, and can be chosen by the manufacturer of 768 * the device. This sensor must be low power, as it is likely to be activated 24/7. 769 * Values of events created by this sensors should not be used. 770 * 771 * @see #isWakeUpSensor() 772 * @hide This sensor is expected to only be used by the system ui 773 */ 774 public static final int TYPE_GLANCE_GESTURE = 43; 775 776 /** 777 * A constant string describing a wake gesture sensor. 778 * 779 * @hide This sensor is expected to only be used by the system ui 780 * @see #TYPE_GLANCE_GESTURE 781 */ 782 public static final String STRING_TYPE_GLANCE_GESTURE = "android.sensor.glance_gesture"; 783 784 /** 785 * A constant describing all sensor types. 786 */ 787 public static final int TYPE_ALL = -1; 788 789 // If this flag is set, the sensor defined as a wake up sensor. This field and REPORTING_MODE_* 790 // constants are defined as flags in sensors.h. Modify at both places if needed. 791 private static final int SENSOR_FLAG_WAKE_UP_SENSOR = 1; 792 793 /** 794 * Events are reported at a constant rate which is set by the rate parameter of 795 * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)}. Note: If other 796 * applications are requesting a higher rate, the sensor data might be delivered at faster rates 797 * than requested. 798 */ 799 public static final int REPORTING_MODE_CONTINUOUS = 0; 800 801 /** 802 * Events are reported only when the value changes. Event delivery rate can be limited by 803 * setting appropriate value for rate parameter of 804 * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)} Note: If other 805 * applications are requesting a higher rate, the sensor data might be delivered at faster rates 806 * than requested. 807 */ 808 public static final int REPORTING_MODE_ON_CHANGE = 1; 809 810 /** 811 * Events are reported in one-shot mode. Upon detection of an event, the sensor deactivates 812 * itself and then sends a single event. Sensors of this reporting mode must be registered to 813 * using {@link SensorManager#requestTriggerSensor(TriggerEventListener, Sensor)}. 814 */ 815 public static final int REPORTING_MODE_ONE_SHOT = 2; 816 817 /** 818 * Events are reported as described in the description of the sensor. The rate passed to 819 * registerListener might not have an impact on the rate of event delivery. See the sensor 820 * definition for more information on when and how frequently the events are reported. For 821 * example, step detectors report events when a step is detected. 822 * 823 * @see SensorManager#registerListener(SensorEventListener, Sensor, int, int) 824 */ 825 public static final int REPORTING_MODE_SPECIAL_TRIGGER = 3; 826 827 // Mask for the LSB 2nd, 3rd and fourth bits. 828 private static final int REPORTING_MODE_MASK = 0xE; 829 private static final int REPORTING_MODE_SHIFT = 1; 830 831 // TODO(): The following arrays are fragile and error-prone. This needs to be refactored. 832 833 // Note: This needs to be updated, whenever a new sensor is added. 834 // Holds the reporting mode and maximum length of the values array 835 // associated with 836 // {@link SensorEvent} or {@link TriggerEvent} for the Sensor 837 private static final int[] sSensorReportingModes = { 838 0, // padding because sensor types start at 1 839 3, // SENSOR_TYPE_ACCELEROMETER 840 3, // SENSOR_TYPE_GEOMAGNETIC_FIELD 841 3, // SENSOR_TYPE_ORIENTATION 842 3, // SENSOR_TYPE_GYROSCOPE 843 3, // SENSOR_TYPE_LIGHT 844 3, // SENSOR_TYPE_PRESSURE 845 3, // SENSOR_TYPE_TEMPERATURE 846 3, // SENSOR_TYPE_PROXIMITY 847 3, // SENSOR_TYPE_GRAVITY 848 3, // SENSOR_TYPE_LINEAR_ACCELERATION 849 5, // SENSOR_TYPE_ROTATION_VECTOR 850 3, // SENSOR_TYPE_RELATIVE_HUMIDITY 851 3, // SENSOR_TYPE_AMBIENT_TEMPERATURE 852 6, // SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED 853 4, // SENSOR_TYPE_GAME_ROTATION_VECTOR 854 6, // SENSOR_TYPE_GYROSCOPE_UNCALIBRATED 855 1, // SENSOR_TYPE_SIGNIFICANT_MOTION 856 1, // SENSOR_TYPE_STEP_DETECTOR 857 1, // SENSOR_TYPE_STEP_COUNTER 858 5, // SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR 859 1, // SENSOR_TYPE_HEART_RATE_MONITOR 860 3, // SENSOR_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR 861 // wake up variants of base sensors 862 3, // SENSOR_TYPE_WAKE_UP_ACCELEROMETER 863 3, // SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD 864 3, // SENSOR_TYPE_WAKE_UP_ORIENTATION 865 3, // SENSOR_TYPE_WAKE_UP_GYROSCOPE 866 3, // SENSOR_TYPE_WAKE_UP_LIGHT 867 3, // SENSOR_TYPE_WAKE_UP_PRESSURE 868 3, // SENSOR_TYPE_WAKE_UP_GRAVITY 869 3, // SENSOR_TYPE_WAKE_UP_LINEAR_ACCELERATION 870 5, // SENSOR_TYPE_WAKE_UP_ROTATION_VECTOR 871 3, // SENSOR_TYPE_WAKE_UP_RELATIVE_HUMIDITY 872 3, // SENSOR_TYPE_WAKE_UP_AMBIENT_TEMPERATURE 873 6, // SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED 874 4, // SENSOR_TYPE_WAKE_UP_GAME_ROTATION_VECTOR 875 6, // SENSOR_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED 876 1, // SENSOR_TYPE_WAKE_UP_STEP_DETECTOR 877 1, // SENSOR_TYPE_WAKE_UP_STEP_COUNTER 878 5, // SENSOR_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR 879 1, // SENSOR_TYPE_WAKE_UP_HEART_RATE_MONITOR 880 1, // SENSOR_TYPE_WAKE_UP_TILT_DETECTOR 881 1, // SENSOR_TYPE_WAKE_GESTURE 882 1, // SENSOR_TYPE_GLANCE_GESTURE 883 }; 884 885 /** 886 * Each sensor has exactly one reporting mode associated with it. This method returns the 887 * reporting mode constant for this sensor type. 888 * 889 * @return Reporting mode for the input sensor, one of REPORTING_MODE_* constants. 890 * @see #REPORTING_MODE_CONTINUOUS 891 * @see #REPORTING_MODE_ON_CHANGE 892 * @see #REPORTING_MODE_ONE_SHOT 893 * @see #REPORTING_MODE_SPECIAL_TRIGGER 894 */ 895 public int getReportingMode() { 896 return ((mFlags & REPORTING_MODE_MASK) >> REPORTING_MODE_SHIFT); 897 } 898 899 static int getMaxLengthValuesArray(Sensor sensor, int sdkLevel) { 900 // RotationVector length has changed to 3 to 5 for API level 18 901 // Set it to 3 for backward compatibility. 902 if (sensor.mType == Sensor.TYPE_ROTATION_VECTOR && 903 sdkLevel <= Build.VERSION_CODES.JELLY_BEAN_MR1) { 904 return 3; 905 } 906 int offset = sensor.mType; 907 if (offset >= sSensorReportingModes.length) { 908 // we don't know about this sensor, so this is probably a 909 // vendor-defined sensor, in that case, we don't know how many value 910 // it has 911 // so we return the maximum and assume the app will know. 912 // FIXME: sensor HAL should advertise how much data is returned per 913 // sensor 914 return 16; 915 } 916 return sSensorReportingModes[offset]; 917 } 918 919 /* Some of these fields are set only by the native bindings in 920 * SensorManager. 921 */ 922 private String mName; 923 private String mVendor; 924 private int mVersion; 925 private int mHandle; 926 private int mType; 927 private float mMaxRange; 928 private float mResolution; 929 private float mPower; 930 private int mMinDelay; 931 private int mFifoReservedEventCount; 932 private int mFifoMaxEventCount; 933 private String mStringType; 934 private String mRequiredPermission; 935 private int mMaxDelay; 936 private int mFlags; 937 938 Sensor() { 939 } 940 941 /** 942 * @return name string of the sensor. 943 */ 944 public String getName() { 945 return mName; 946 } 947 948 /** 949 * @return vendor string of this sensor. 950 */ 951 public String getVendor() { 952 return mVendor; 953 } 954 955 /** 956 * @return generic type of this sensor. 957 */ 958 public int getType() { 959 return mType; 960 } 961 962 /** 963 * @return version of the sensor's module. 964 */ 965 public int getVersion() { 966 return mVersion; 967 } 968 969 /** 970 * @return maximum range of the sensor in the sensor's unit. 971 */ 972 public float getMaximumRange() { 973 return mMaxRange; 974 } 975 976 /** 977 * @return resolution of the sensor in the sensor's unit. 978 */ 979 public float getResolution() { 980 return mResolution; 981 } 982 983 /** 984 * @return the power in mA used by this sensor while in use 985 */ 986 public float getPower() { 987 return mPower; 988 } 989 990 /** 991 * @return the minimum delay allowed between two events in microsecond 992 * or zero if this sensor only returns a value when the data it's measuring 993 * changes. 994 */ 995 public int getMinDelay() { 996 return mMinDelay; 997 } 998 999 /** 1000 * @return Number of events reserved for this sensor in the batch mode FIFO. This gives a 1001 * guarantee on the minimum number of events that can be batched. 1002 */ 1003 public int getFifoReservedEventCount() { 1004 return mFifoReservedEventCount; 1005 } 1006 1007 /** 1008 * @return Maximum number of events of this sensor that could be batched. If this value is zero 1009 * it indicates that batch mode is not supported for this sensor. If other applications 1010 * registered to batched sensors, the actual number of events that can be batched might be 1011 * smaller because the hardware FiFo will be partially used to batch the other sensors. 1012 */ 1013 public int getFifoMaxEventCount() { 1014 return mFifoMaxEventCount; 1015 } 1016 1017 /** 1018 * @return The type of this sensor as a string. 1019 */ 1020 public String getStringType() { 1021 return mStringType; 1022 } 1023 1024 /** 1025 * @hide 1026 * @return The permission required to access this sensor. If empty, no permission is required. 1027 */ 1028 public String getRequiredPermission() { 1029 return mRequiredPermission; 1030 } 1031 1032 /** @hide */ 1033 public int getHandle() { 1034 return mHandle; 1035 } 1036 1037 /** 1038 * This value is defined only for continuous mode sensors. It is the delay between two 1039 * sensor events corresponding to the lowest frequency that this sensor supports. When 1040 * lower frequencies are requested through registerListener() the events will be generated 1041 * at this frequency instead. It can be used to estimate when the batch FIFO may be full. 1042 * Older devices may set this value to zero. Ignore this value in case it is negative 1043 * or zero. 1044 * 1045 * @return The max delay for this sensor in microseconds. 1046 */ 1047 public int getMaxDelay() { 1048 return mMaxDelay; 1049 } 1050 1051 /** 1052 * Returns whether this sensor is a wake-up sensor. 1053 * <p> 1054 * Wake up sensors wake the application processor up when they have events to deliver. When a 1055 * wake up sensor is registered to without batching enabled, each event will wake the 1056 * application processor up. 1057 * <p> 1058 * When a wake up sensor is registered to with batching enabled, it 1059 * wakes the application processor up when maxReportingLatency has elapsed or when the hardware 1060 * FIFO storing the events from wake up sensors is getting full. 1061 * <p> 1062 * Non-wake up sensors never wake the application processor up. Their events are only reported 1063 * when the application processor is awake, for example because the application holds a wake 1064 * lock, or another source woke the application processor up. 1065 * <p> 1066 * When a non-wake up sensor is registered to without batching enabled, the measurements made 1067 * while the application processor is asleep might be lost and never returned. 1068 * <p> 1069 * When a non-wake up sensor is registered to with batching enabled, the measurements made while 1070 * the application processor is asleep are stored in the hardware FIFO for non-wake up sensors. 1071 * When this FIFO gets full, new events start overwriting older events. When the application 1072 * then wakes up, the latest events are returned, and some old events might be lost. The number 1073 * of events actually returned depends on the hardware FIFO size, as well as on what other 1074 * sensors are activated. If losing sensor events is not acceptable during batching, you must 1075 * use the wake-up version of the sensor. 1076 * @return true if this is a wake up sensor, false otherwise. 1077 */ 1078 public boolean isWakeUpSensor() { 1079 return (mFlags & SENSOR_FLAG_WAKE_UP_SENSOR) != 0; 1080 } 1081 1082 void setRange(float max, float res) { 1083 mMaxRange = max; 1084 mResolution = res; 1085 } 1086 1087 @Override 1088 public String toString() { 1089 return "{Sensor name=\"" + mName + "\", vendor=\"" + mVendor + "\", version=" + mVersion 1090 + ", type=" + mType + ", maxRange=" + mMaxRange + ", resolution=" + mResolution 1091 + ", power=" + mPower + ", minDelay=" + mMinDelay + "}"; 1092 } 1093} 1094