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