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