The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 20 | import android.os.Build; |
Nick Vaccaro | f5021f6 | 2015-01-23 15:09:45 -0800 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 22 | |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Class representing a sensor. Use {@link SensorManager#getSensorList} to get |
| 25 | * the list of available Sensors. |
Mathias Agopian | 0f791a7 | 2010-06-22 21:55:01 -0700 | [diff] [blame] | 26 | * |
| 27 | * @see SensorManager |
| 28 | * @see SensorEventListener |
| 29 | * @see SensorEvent |
| 30 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | */ |
Jeff Brown | 6a2ef12 | 2012-08-10 18:19:10 -0700 | [diff] [blame] | 32 | public final class Sensor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 34 | /** |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 35 | * A constant describing an accelerometer sensor type. |
| 36 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
| 37 | * for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | */ |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 39 | public static final int TYPE_ACCELEROMETER = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 41 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 42 | * A constant string describing an accelerometer sensor type. |
| 43 | * |
| 44 | * @see #TYPE_ACCELEROMETER |
| 45 | */ |
| 46 | public static final String STRING_TYPE_ACCELEROMETER = "android.sensor.accelerometer"; |
| 47 | |
| 48 | /** |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 49 | * A constant describing a magnetic field sensor type. |
| 50 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
| 51 | * for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | */ |
| 53 | public static final int TYPE_MAGNETIC_FIELD = 2; |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 56 | * A constant string describing a magnetic field sensor type. |
| 57 | * |
| 58 | * @see #TYPE_MAGNETIC_FIELD |
| 59 | */ |
| 60 | public static final String STRING_TYPE_MAGNETIC_FIELD = "android.sensor.magnetic_field"; |
| 61 | |
| 62 | /** |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 63 | * A constant describing an orientation sensor type. |
| 64 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
| 65 | * for more details. |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 66 | * |
Mathias Agopian | 61a4493 | 2010-02-26 18:06:26 -0800 | [diff] [blame] | 67 | * @deprecated use {@link android.hardware.SensorManager#getOrientation |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 68 | * SensorManager.getOrientation()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | */ |
Mathias Agopian | 61a4493 | 2010-02-26 18:06:26 -0800 | [diff] [blame] | 70 | @Deprecated |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 71 | public static final int TYPE_ORIENTATION = 3; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 73 | /** |
| 74 | * A constant string describing an orientation sensor type. |
| 75 | * |
| 76 | * @see #TYPE_ORIENTATION |
| 77 | * @deprecated use {@link android.hardware.SensorManager#getOrientation |
| 78 | * SensorManager.getOrientation()} instead. |
| 79 | */ |
| 80 | @Deprecated |
| 81 | public static final String STRING_TYPE_ORIENTATION = "android.sensor.orientation"; |
| 82 | |
| 83 | /** |
| 84 | * A constant describing a gyroscope sensor type. |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 85 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
| 86 | * for more details. */ |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 87 | public static final int TYPE_GYROSCOPE = 4; |
| 88 | |
Mike Lockwood | 4115c51 | 2009-11-03 10:35:43 -0500 | [diff] [blame] | 89 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 90 | * A constant string describing a gyroscope sensor type. |
| 91 | * |
| 92 | * @see #TYPE_GYROSCOPE |
| 93 | */ |
| 94 | public static final String STRING_TYPE_GYROSCOPE = "android.sensor.gyroscope"; |
| 95 | |
| 96 | /** |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 97 | * A constant describing a light sensor type. |
| 98 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
| 99 | * for more details. |
Mike Lockwood | 4115c51 | 2009-11-03 10:35:43 -0500 | [diff] [blame] | 100 | */ |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 101 | public static final int TYPE_LIGHT = 5; |
Mathias Agopian | 210fc91 | 2010-02-26 13:51:39 -0800 | [diff] [blame] | 102 | |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 103 | /** |
| 104 | * A constant string describing a light sensor type. |
| 105 | * |
| 106 | * @see #TYPE_LIGHT |
| 107 | */ |
| 108 | public static final String STRING_TYPE_LIGHT = "android.sensor.light"; |
| 109 | |
| 110 | /** |
| 111 | * A constant describing a pressure sensor type. |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 112 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 113 | * for more details. |
| 114 | */ |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 115 | public static final int TYPE_PRESSURE = 6; |
Mathias Agopian | 210fc91 | 2010-02-26 13:51:39 -0800 | [diff] [blame] | 116 | |
Mathias Agopian | 462db22 | 2011-03-22 18:44:26 -0700 | [diff] [blame] | 117 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 118 | * A constant string describing a pressure sensor type. |
| 119 | * |
| 120 | * @see #TYPE_PRESSURE |
| 121 | */ |
| 122 | public static final String STRING_TYPE_PRESSURE = "android.sensor.pressure"; |
| 123 | |
| 124 | /** |
Mathias Agopian | 462db22 | 2011-03-22 18:44:26 -0700 | [diff] [blame] | 125 | * A constant describing a temperature sensor type |
| 126 | * |
| 127 | * @deprecated use |
| 128 | * {@link android.hardware.Sensor#TYPE_AMBIENT_TEMPERATURE |
| 129 | * Sensor.TYPE_AMBIENT_TEMPERATURE} instead. |
| 130 | */ |
| 131 | @Deprecated |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 132 | public static final int TYPE_TEMPERATURE = 7; |
Mathias Agopian | 210fc91 | 2010-02-26 13:51:39 -0800 | [diff] [blame] | 133 | |
Mike Lockwood | 4115c51 | 2009-11-03 10:35:43 -0500 | [diff] [blame] | 134 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 135 | * A constant string describing a temperature sensor type |
| 136 | * |
| 137 | * @see #TYPE_TEMPERATURE |
| 138 | * @deprecated use |
| 139 | * {@link android.hardware.Sensor#STRING_TYPE_AMBIENT_TEMPERATURE |
| 140 | * Sensor.STRING_TYPE_AMBIENT_TEMPERATURE} instead. |
| 141 | */ |
| 142 | @Deprecated |
| 143 | public static final String STRING_TYPE_TEMPERATURE = "android.sensor.temperature"; |
| 144 | |
| 145 | /** |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 146 | * A constant describing a proximity sensor type. This is a wake up sensor. |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 147 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
| 148 | * for more details. |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 149 | * @see #isWakeUpSensor() |
Mike Lockwood | 4115c51 | 2009-11-03 10:35:43 -0500 | [diff] [blame] | 150 | */ |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 151 | public static final int TYPE_PROXIMITY = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 153 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 154 | * A constant string describing a proximity sensor type. |
| 155 | * |
| 156 | * @see #TYPE_PROXIMITY |
| 157 | */ |
| 158 | public static final String STRING_TYPE_PROXIMITY = "android.sensor.proximity"; |
| 159 | |
| 160 | /** |
Kevin Powell | f35fd95 | 2010-07-19 19:10:40 -0700 | [diff] [blame] | 161 | * A constant describing a gravity sensor type. |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 162 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
Kevin Powell | f35fd95 | 2010-07-19 19:10:40 -0700 | [diff] [blame] | 163 | * for more details. |
| 164 | */ |
| 165 | public static final int TYPE_GRAVITY = 9; |
| 166 | |
| 167 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 168 | * A constant string describing a gravity sensor type. |
| 169 | * |
| 170 | * @see #TYPE_GRAVITY |
| 171 | */ |
| 172 | public static final String STRING_TYPE_GRAVITY = "android.sensor.gravity"; |
| 173 | |
| 174 | /** |
Kevin Powell | f35fd95 | 2010-07-19 19:10:40 -0700 | [diff] [blame] | 175 | * A constant describing a linear acceleration sensor type. |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 176 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
Kevin Powell | f35fd95 | 2010-07-19 19:10:40 -0700 | [diff] [blame] | 177 | * for more details. |
| 178 | */ |
| 179 | public static final int TYPE_LINEAR_ACCELERATION = 10; |
| 180 | |
| 181 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 182 | * A constant string describing a linear acceleration sensor type. |
| 183 | * |
| 184 | * @see #TYPE_LINEAR_ACCELERATION |
| 185 | */ |
| 186 | public static final String STRING_TYPE_LINEAR_ACCELERATION = |
| 187 | "android.sensor.linear_acceleration"; |
| 188 | |
| 189 | /** |
Kevin Powell | f35fd95 | 2010-07-19 19:10:40 -0700 | [diff] [blame] | 190 | * A constant describing a rotation vector sensor type. |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 191 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
Kevin Powell | f35fd95 | 2010-07-19 19:10:40 -0700 | [diff] [blame] | 192 | * for more details. |
| 193 | */ |
| 194 | public static final int TYPE_ROTATION_VECTOR = 11; |
| 195 | |
Urs Fleisch | 5819051 | 2010-12-29 17:02:02 +0100 | [diff] [blame] | 196 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 197 | * A constant string describing a rotation vector sensor type. |
| 198 | * |
| 199 | * @see #TYPE_ROTATION_VECTOR |
| 200 | */ |
| 201 | public static final String STRING_TYPE_ROTATION_VECTOR = "android.sensor.rotation_vector"; |
| 202 | |
| 203 | /** |
Urs Fleisch | 5819051 | 2010-12-29 17:02:02 +0100 | [diff] [blame] | 204 | * A constant describing a relative humidity sensor type. |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 205 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
Urs Fleisch | 5819051 | 2010-12-29 17:02:02 +0100 | [diff] [blame] | 206 | * for more details. |
| 207 | */ |
| 208 | public static final int TYPE_RELATIVE_HUMIDITY = 12; |
| 209 | |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 210 | /** |
| 211 | * A constant string describing a relative humidity sensor type |
| 212 | * |
| 213 | * @see #TYPE_RELATIVE_HUMIDITY |
| 214 | */ |
| 215 | public static final String STRING_TYPE_RELATIVE_HUMIDITY = "android.sensor.relative_humidity"; |
| 216 | |
| 217 | /** |
| 218 | * A constant describing an ambient temperature sensor type. |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 219 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 220 | * for more details. |
| 221 | */ |
Mathias Agopian | 462db22 | 2011-03-22 18:44:26 -0700 | [diff] [blame] | 222 | public static final int TYPE_AMBIENT_TEMPERATURE = 13; |
| 223 | |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 224 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 225 | * A constant string describing an ambient temperature sensor type. |
| 226 | * |
| 227 | * @see #TYPE_AMBIENT_TEMPERATURE |
| 228 | */ |
| 229 | public static final String STRING_TYPE_AMBIENT_TEMPERATURE = |
| 230 | "android.sensor.ambient_temperature"; |
| 231 | |
| 232 | /** |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 233 | * A constant describing an uncalibrated magnetic field sensor type. |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 234 | * <p> |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 235 | * Similar to {@link #TYPE_MAGNETIC_FIELD} but the hard iron calibration (device calibration |
| 236 | * due to distortions that arise from magnetized iron, steel or permanent magnets on the |
| 237 | * device) is not considered in the given sensor values. However, such hard iron bias values |
| 238 | * are returned to you separately in the result {@link android.hardware.SensorEvent#values} |
Aravind Akella | 4b628cb | 2013-08-05 18:43:55 -0700 | [diff] [blame] | 239 | * so you may use them for custom calibrations. |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 240 | * <p>Also, no periodic calibration is performed |
| 241 | * (i.e. there are no discontinuities in the data stream while using this sensor) and |
| 242 | * assumptions that the magnetic field is due to the Earth's poles is avoided, but |
| 243 | * factory calibration and temperature compensation have been performed. |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 244 | * </p> |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 245 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} for more |
| 246 | * details. |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 247 | */ |
| 248 | public static final int TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14; |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 249 | /** |
| 250 | * A constant string describing an uncalibrated magnetic field sensor type. |
| 251 | * |
| 252 | * @see #TYPE_MAGNETIC_FIELD_UNCALIBRATED |
| 253 | */ |
| 254 | public static final String STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED = |
| 255 | "android.sensor.magnetic_field_uncalibrated"; |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 256 | |
| 257 | /** |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 258 | * A constant describing an uncalibrated rotation vector sensor type. |
| 259 | * <p>Identical to {@link #TYPE_ROTATION_VECTOR} except that it doesn't |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 260 | * use the geomagnetic field. Therefore the Y axis doesn't |
| 261 | * point north, but instead to some other reference, that reference is |
| 262 | * allowed to drift by the same order of magnitude as the gyroscope |
| 263 | * drift around the Z axis. |
| 264 | * <p> |
| 265 | * In the ideal case, a phone rotated and returning to the same real-world |
| 266 | * orientation should report the same game rotation vector |
| 267 | * (without using the earth's geomagnetic field). However, the orientation |
| 268 | * may drift somewhat over time. |
| 269 | * </p> |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 270 | * <p>See {@link android.hardware.SensorEvent#values SensorEvent.values} for more |
| 271 | * details. |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 272 | */ |
Etienne Le Grand | 819239e | 2014-04-05 04:47:14 +0000 | [diff] [blame] | 273 | public static final int TYPE_GAME_ROTATION_VECTOR = 15; |
Etienne Le Grand | fd53d83 | 2014-03-24 21:29:28 -0700 | [diff] [blame] | 274 | |
| 275 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 276 | * A constant string describing an uncalibrated rotation vector sensor type. |
| 277 | * |
| 278 | * @see #TYPE_GAME_ROTATION_VECTOR |
| 279 | */ |
| 280 | public static final String STRING_TYPE_GAME_ROTATION_VECTOR = |
| 281 | "android.sensor.game_rotation_vector"; |
| 282 | |
| 283 | /** |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 284 | * A constant describing an uncalibrated gyroscope sensor type. |
| 285 | * <p>Similar to {@link #TYPE_GYROSCOPE} but no gyro-drift compensation has been performed |
| 286 | * to adjust the given sensor values. However, such gyro-drift bias values |
| 287 | * are returned to you separately in the result {@link android.hardware.SensorEvent#values} |
| 288 | * so you may use them for custom calibrations. |
| 289 | * <p>Factory calibration and temperature compensation is still applied |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 290 | * to the rate of rotation (angular speeds). |
| 291 | * </p> |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 292 | * <p> See {@link android.hardware.SensorEvent#values SensorEvent.values} for more |
| 293 | * details. |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 294 | */ |
| 295 | public static final int TYPE_GYROSCOPE_UNCALIBRATED = 16; |
| 296 | |
| 297 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 298 | * A constant string describing an uncalibrated gyroscope sensor type. |
| 299 | * |
| 300 | * @see #TYPE_GYROSCOPE_UNCALIBRATED |
| 301 | */ |
| 302 | public static final String STRING_TYPE_GYROSCOPE_UNCALIBRATED = |
| 303 | "android.sensor.gyroscope_uncalibrated"; |
| 304 | |
| 305 | /** |
Aravind Akella | 4b628cb | 2013-08-05 18:43:55 -0700 | [diff] [blame] | 306 | * A constant describing a significant motion trigger sensor. |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 307 | * <p> |
| 308 | * It triggers when an event occurs and then automatically disables |
| 309 | * itself. The sensor continues to operate while the device is asleep |
| 310 | * and will automatically wake the device to notify when significant |
| 311 | * motion is detected. The application does not need to hold any wake |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 312 | * locks for this sensor to trigger. This is a wake up sensor. |
Scott Main | 92053f8 | 2013-06-13 16:32:50 -0700 | [diff] [blame] | 313 | * <p>See {@link TriggerEvent} for more details. |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 314 | * |
| 315 | * @see #isWakeUpSensor() |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 316 | */ |
| 317 | public static final int TYPE_SIGNIFICANT_MOTION = 17; |
| 318 | |
| 319 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 320 | * A constant string describing a significant motion trigger sensor. |
| 321 | * |
| 322 | * @see #TYPE_SIGNIFICANT_MOTION |
| 323 | */ |
| 324 | public static final String STRING_TYPE_SIGNIFICANT_MOTION = |
| 325 | "android.sensor.significant_motion"; |
| 326 | |
| 327 | /** |
Aravind Akella | 4b628cb | 2013-08-05 18:43:55 -0700 | [diff] [blame] | 328 | * A constant describing a step detector sensor. |
| 329 | * <p> |
| 330 | * A sensor of this type triggers an event each time a step is taken by the user. The only |
| 331 | * allowed value to return is 1.0 and an event is generated for each step. Like with any other |
| 332 | * event, the timestamp indicates when the event (here the step) occurred, this corresponds to |
Aravind Akella | 1f9b32f | 2014-09-16 15:21:44 -0700 | [diff] [blame] | 333 | * when the foot hit the ground, generating a high variation in acceleration. This sensor is |
| 334 | * only for detecting every individual step as soon as it is taken, for example to perform dead |
| 335 | * reckoning. If you only need aggregate number of steps taken over a period of time, register |
| 336 | * for {@link #TYPE_STEP_COUNTER} instead. It is defined as a |
| 337 | * {@link Sensor#REPORTING_MODE_SPECIAL_TRIGGER} sensor. |
Aravind Akella | 4b628cb | 2013-08-05 18:43:55 -0700 | [diff] [blame] | 338 | * <p> |
| 339 | * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details. |
| 340 | */ |
| 341 | public static final int TYPE_STEP_DETECTOR = 18; |
| 342 | |
| 343 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 344 | * A constant string describing a step detector sensor. |
| 345 | * |
| 346 | * @see #TYPE_STEP_DETECTOR |
| 347 | */ |
| 348 | public static final String STRING_TYPE_STEP_DETECTOR = "android.sensor.step_detector"; |
| 349 | |
| 350 | /** |
Aravind Akella | 4b628cb | 2013-08-05 18:43:55 -0700 | [diff] [blame] | 351 | * A constant describing a step counter sensor. |
| 352 | * <p> |
| 353 | * A sensor of this type returns the number of steps taken by the user since the last reboot |
| 354 | * while activated. The value is returned as a float (with the fractional part set to zero) and |
| 355 | * is reset to zero only on a system reboot. The timestamp of the event is set to the time when |
Aravind Akella | 0c44d69 | 2014-08-19 18:28:12 -0700 | [diff] [blame] | 356 | * the last step for that event was taken. This sensor is implemented in hardware and is |
Aravind Akella | 1f9b32f | 2014-09-16 15:21:44 -0700 | [diff] [blame] | 357 | * expected to be low power. If you want to continuously track the number of steps over a long |
| 358 | * period of time, do NOT unregister for this sensor, so that it keeps counting steps in the |
| 359 | * background even when the AP is in suspend mode and report the aggregate count when the AP |
| 360 | * is awake. Application needs to stay registered for this sensor because step counter does not |
| 361 | * count steps if it is not activated. This sensor is ideal for fitness tracking applications. |
| 362 | * It is defined as an {@link Sensor#REPORTING_MODE_ON_CHANGE} sensor. |
Aravind Akella | 4b628cb | 2013-08-05 18:43:55 -0700 | [diff] [blame] | 363 | * <p> |
| 364 | * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details. |
| 365 | */ |
| 366 | public static final int TYPE_STEP_COUNTER = 19; |
| 367 | |
| 368 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 369 | * A constant string describing a step counter sensor. |
| 370 | * |
| 371 | * @see #TYPE_STEP_COUNTER |
| 372 | */ |
| 373 | public static final String STRING_TYPE_STEP_COUNTER = "android.sensor.step_counter"; |
| 374 | |
| 375 | /** |
| 376 | * A constant describing a geo-magnetic rotation vector. |
Aravind Akella | 4b628cb | 2013-08-05 18:43:55 -0700 | [diff] [blame] | 377 | * <p> |
Aravind Akella | f0f4a83 | 2013-08-07 20:05:29 -0700 | [diff] [blame] | 378 | * Similar to {@link #TYPE_ROTATION_VECTOR}, but using a magnetometer instead of using a |
Aravind Akella | 4b628cb | 2013-08-05 18:43:55 -0700 | [diff] [blame] | 379 | * gyroscope. This sensor uses lower power than the other rotation vectors, because it doesn't |
| 380 | * use the gyroscope. However, it is more noisy and will work best outdoors. |
| 381 | * <p> |
| 382 | * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details. |
| 383 | */ |
| 384 | public static final int TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20; |
| 385 | |
| 386 | /** |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 387 | * A constant string describing a geo-magnetic rotation vector. |
| 388 | * |
| 389 | * @see #TYPE_GEOMAGNETIC_ROTATION_VECTOR |
| 390 | */ |
| 391 | public static final String STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR = |
| 392 | "android.sensor.geomagnetic_rotation_vector"; |
| 393 | |
| 394 | /** |
| 395 | * A constant describing a heart rate monitor. |
| 396 | * <p> |
Etienne Le Grand | af80510 | 2014-05-16 12:21:41 -0700 | [diff] [blame] | 397 | * The reported value is the heart rate in beats per minute. |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 398 | * <p> |
Etienne Le Grand | af80510 | 2014-05-16 12:21:41 -0700 | [diff] [blame] | 399 | * The reported accuracy represents the status of the monitor during the reading. See the |
| 400 | * {@code SENSOR_STATUS_*} constants in {@link android.hardware.SensorManager SensorManager} |
| 401 | * for more details on accuracy/status values. In particular, when the accuracy is |
| 402 | * {@code SENSOR_STATUS_UNRELIABLE} or {@code SENSOR_STATUS_NO_CONTACT}, the heart rate |
| 403 | * value should be discarded. |
| 404 | * <p> |
| 405 | * This sensor requires permission {@code android.permission.BODY_SENSORS}. |
| 406 | * It will not be returned by {@code SensorManager.getSensorsList} nor |
| 407 | * {@code SensorManager.getDefaultSensor} if the application doesn't have this permission. |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 408 | */ |
| 409 | public static final int TYPE_HEART_RATE = 21; |
| 410 | |
| 411 | /** |
| 412 | * A constant string describing a heart rate monitor. |
| 413 | * |
| 414 | * @see #TYPE_HEART_RATE |
| 415 | */ |
| 416 | public static final String STRING_TYPE_HEART_RATE = "android.sensor.heart_rate"; |
| 417 | |
| 418 | /** |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 419 | * A sensor of this type generates an event each time a tilt event is detected. A tilt event |
| 420 | * is generated if the direction of the 2-seconds window average gravity changed by at |
| 421 | * least 35 degrees since the activation of the sensor. It is a wake up sensor. |
| 422 | * |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 423 | * @hide |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 424 | * @see #isWakeUpSensor() |
| 425 | */ |
Aravind Akella | 0288ca6 | 2014-07-28 14:53:44 -0700 | [diff] [blame] | 426 | public static final int TYPE_TILT_DETECTOR = 22; |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 427 | |
| 428 | /** |
| 429 | * A constant string describing a wake up tilt detector sensor type. |
| 430 | * |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 431 | * @hide |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 432 | * @see #TYPE_WAKE_UP_TILT_DETECTOR |
| 433 | */ |
Aravind Akella | 0288ca6 | 2014-07-28 14:53:44 -0700 | [diff] [blame] | 434 | public static final String SENSOR_STRING_TYPE_TILT_DETECTOR = |
| 435 | "android.sensor.tilt_detector"; |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 436 | |
| 437 | /** |
Etienne Le Grand | 28071e3 | 2014-05-07 19:47:43 -0700 | [diff] [blame] | 438 | * A constant describing a wake gesture sensor. |
| 439 | * <p> |
| 440 | * Wake gesture sensors enable waking up the device based on a device specific motion. |
| 441 | * <p> |
| 442 | * When this sensor triggers, the device behaves as if the power button was pressed, turning the |
| 443 | * screen on. This behavior (turning on the screen when this sensor triggers) might be |
| 444 | * deactivated by the user in the device settings. Changes in settings do not impact the |
| 445 | * behavior of the sensor: only whether the framework turns the screen on when it triggers. |
| 446 | * <p> |
| 447 | * The actual gesture to be detected is not specified, and can be chosen by the manufacturer of |
| 448 | * the device. This sensor must be low power, as it is likely to be activated 24/7. |
| 449 | * Values of events created by this sensors should not be used. |
| 450 | * |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 451 | * @see #isWakeUpSensor() |
Jeff Brown | 241e70d | 2014-07-17 15:12:37 -0700 | [diff] [blame] | 452 | * @hide This sensor is expected to only be used by the system ui |
Etienne Le Grand | 28071e3 | 2014-05-07 19:47:43 -0700 | [diff] [blame] | 453 | */ |
Aravind Akella | 0288ca6 | 2014-07-28 14:53:44 -0700 | [diff] [blame] | 454 | public static final int TYPE_WAKE_GESTURE = 23; |
Etienne Le Grand | 28071e3 | 2014-05-07 19:47:43 -0700 | [diff] [blame] | 455 | |
| 456 | /** |
| 457 | * A constant string describing a wake gesture sensor. |
| 458 | * |
Jeff Brown | 241e70d | 2014-07-17 15:12:37 -0700 | [diff] [blame] | 459 | * @hide This sensor is expected to only be used by the system ui |
Etienne Le Grand | 28071e3 | 2014-05-07 19:47:43 -0700 | [diff] [blame] | 460 | * @see #TYPE_WAKE_GESTURE |
| 461 | */ |
| 462 | public static final String STRING_TYPE_WAKE_GESTURE = "android.sensor.wake_gesture"; |
| 463 | |
| 464 | /** |
Jeff Brown | 241e70d | 2014-07-17 15:12:37 -0700 | [diff] [blame] | 465 | * A constant describing a wake gesture sensor. |
| 466 | * <p> |
| 467 | * A sensor enabling briefly turning the screen on to enable the user to |
| 468 | * glance content on screen based on a specific motion. The device should |
| 469 | * turn the screen off after a few moments. |
| 470 | * <p> |
| 471 | * When this sensor triggers, the device turns the screen on momentarily |
| 472 | * to allow the user to glance notifications or other content while the |
| 473 | * device remains locked in a non-interactive state (dozing). This behavior |
| 474 | * (briefly turning on the screen when this sensor triggers) might be deactivated |
| 475 | * by the user in the device settings. Changes in settings do not impact the |
| 476 | * behavior of the sensor: only whether the framework briefly turns the screen on |
| 477 | * when it triggers. |
| 478 | * <p> |
| 479 | * The actual gesture to be detected is not specified, and can be chosen by the manufacturer of |
| 480 | * the device. This sensor must be low power, as it is likely to be activated 24/7. |
| 481 | * Values of events created by this sensors should not be used. |
| 482 | * |
| 483 | * @see #isWakeUpSensor() |
| 484 | * @hide This sensor is expected to only be used by the system ui |
| 485 | */ |
Aravind Akella | 0288ca6 | 2014-07-28 14:53:44 -0700 | [diff] [blame] | 486 | public static final int TYPE_GLANCE_GESTURE = 24; |
Jeff Brown | 241e70d | 2014-07-17 15:12:37 -0700 | [diff] [blame] | 487 | |
| 488 | /** |
| 489 | * A constant string describing a wake gesture sensor. |
| 490 | * |
| 491 | * @hide This sensor is expected to only be used by the system ui |
| 492 | * @see #TYPE_GLANCE_GESTURE |
| 493 | */ |
| 494 | public static final String STRING_TYPE_GLANCE_GESTURE = "android.sensor.glance_gesture"; |
| 495 | |
Aravind Akella | 96eb62c | 2014-07-17 12:42:00 -0700 | [diff] [blame] | 496 | /** |
| 497 | * A constant describing a pick up sensor. |
| 498 | * |
| 499 | * A sensor of this type triggers when the device is picked up regardless of wherever it was |
| 500 | * before (desk, pocket, bag). The only allowed return value is 1.0. This sensor deactivates |
| 501 | * itself immediately after it triggers. |
| 502 | * |
| 503 | * @hide Expected to be used internally for always on display. |
| 504 | */ |
Aravind Akella | 0288ca6 | 2014-07-28 14:53:44 -0700 | [diff] [blame] | 505 | public static final int TYPE_PICK_UP_GESTURE = 25; |
Aravind Akella | 96eb62c | 2014-07-17 12:42:00 -0700 | [diff] [blame] | 506 | |
| 507 | /** |
| 508 | * A constant string describing a pick up sensor. |
| 509 | * |
| 510 | * @hide This sensor is expected to be used internally for always on display. |
| 511 | * @see #TYPE_PICK_UP_GESTURE |
| 512 | */ |
| 513 | public static final String STRING_TYPE_PICK_UP_GESTURE = "android.sensor.pick_up_gesture"; |
| 514 | |
Nick Vaccaro | f5021f6 | 2015-01-23 15:09:45 -0800 | [diff] [blame] | 515 | /** |
| 516 | * A constant describing a wrist tilt gesture sensor. |
| 517 | * |
| 518 | * A sensor of this type triggers when the device face is tilted towards the user. |
| 519 | * The only allowed return value is 1.0. |
| 520 | * This sensor remains active until disabled. |
| 521 | * |
| 522 | * @hide This sensor is expected to only be used by the system ui |
| 523 | */ |
| 524 | @SystemApi |
| 525 | public static final int TYPE_WRIST_TILT_GESTURE = 26; |
| 526 | |
| 527 | /** |
| 528 | * A constant string describing a wrist tilt gesture sensor. |
| 529 | * |
| 530 | * @hide This sensor is expected to only be used by the system ui |
| 531 | * @see #TYPE_WRIST_TILT_GESTURE |
| 532 | */ |
| 533 | @SystemApi |
| 534 | public static final String STRING_TYPE_WRIST_TILT_GESTURE = "android.sensor.wrist_tilt_gesture"; |
| 535 | |
Jeff Brown | 241e70d | 2014-07-17 15:12:37 -0700 | [diff] [blame] | 536 | /** |
Trevor Bunker | 3c288e6 | 2016-01-08 11:11:13 -0800 | [diff] [blame] | 537 | * The current orientation of the device. |
| 538 | * <p> |
| 539 | * See {@link android.hardware.SensorEvent#values SensorEvent.values} for more details. |
| 540 | * |
| 541 | * @hide Expected to be used internally for auto-rotate and speaker rotation. |
| 542 | * |
| 543 | */ |
| 544 | public static final int TYPE_DEVICE_ORIENTATION = 27; |
| 545 | |
| 546 | /** |
| 547 | * A constant string describing a device orientation sensor type. |
| 548 | * |
| 549 | * @hide |
| 550 | * @see #TYPE_DEVICE_ORIENTATION |
| 551 | */ |
| 552 | public static final String STRING_TYPE_DEVICE_ORIENTATION = "android.sensor.device_orientation"; |
| 553 | |
| 554 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | * A constant describing all sensor types. |
| 556 | */ |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 557 | public static final int TYPE_ALL = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 559 | // If this flag is set, the sensor defined as a wake up sensor. This field and REPORTING_MODE_* |
| 560 | // constants are defined as flags in sensors.h. Modify at both places if needed. |
| 561 | private static final int SENSOR_FLAG_WAKE_UP_SENSOR = 1; |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 562 | |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 563 | /** |
| 564 | * Events are reported at a constant rate which is set by the rate parameter of |
| 565 | * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)}. Note: If other |
| 566 | * applications are requesting a higher rate, the sensor data might be delivered at faster rates |
| 567 | * than requested. |
| 568 | */ |
| 569 | public static final int REPORTING_MODE_CONTINUOUS = 0; |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 570 | |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 571 | /** |
| 572 | * Events are reported only when the value changes. Event delivery rate can be limited by |
| 573 | * setting appropriate value for rate parameter of |
| 574 | * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)} Note: If other |
| 575 | * applications are requesting a higher rate, the sensor data might be delivered at faster rates |
| 576 | * than requested. |
| 577 | */ |
| 578 | public static final int REPORTING_MODE_ON_CHANGE = 1; |
| 579 | |
| 580 | /** |
| 581 | * Events are reported in one-shot mode. Upon detection of an event, the sensor deactivates |
| 582 | * itself and then sends a single event. Sensors of this reporting mode must be registered to |
| 583 | * using {@link SensorManager#requestTriggerSensor(TriggerEventListener, Sensor)}. |
| 584 | */ |
| 585 | public static final int REPORTING_MODE_ONE_SHOT = 2; |
| 586 | |
| 587 | /** |
| 588 | * Events are reported as described in the description of the sensor. The rate passed to |
| 589 | * registerListener might not have an impact on the rate of event delivery. See the sensor |
| 590 | * definition for more information on when and how frequently the events are reported. For |
| 591 | * example, step detectors report events when a step is detected. |
| 592 | * |
| 593 | * @see SensorManager#registerListener(SensorEventListener, Sensor, int, int) |
| 594 | */ |
| 595 | public static final int REPORTING_MODE_SPECIAL_TRIGGER = 3; |
| 596 | |
| 597 | // Mask for the LSB 2nd, 3rd and fourth bits. |
| 598 | private static final int REPORTING_MODE_MASK = 0xE; |
| 599 | private static final int REPORTING_MODE_SHIFT = 1; |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 600 | |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame] | 601 | // MASK for LSB fifth bit. Used to know whether the sensor supports data injection or not. |
| 602 | private static final int DATA_INJECTION_MASK = 0x10; |
| 603 | private static final int DATA_INJECTION_SHIFT = 4; |
| 604 | |
Jaikumar Ganesh | edb5242 | 2013-04-16 11:10:05 -0700 | [diff] [blame] | 605 | // TODO(): The following arrays are fragile and error-prone. This needs to be refactored. |
| 606 | |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 607 | // Note: This needs to be updated, whenever a new sensor is added. |
Mathias Agopian | b25c0ef | 2013-07-03 15:38:29 -0700 | [diff] [blame] | 608 | // Holds the reporting mode and maximum length of the values array |
| 609 | // associated with |
| 610 | // {@link SensorEvent} or {@link TriggerEvent} for the Sensor |
| 611 | private static final int[] sSensorReportingModes = { |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 612 | 0, // padding because sensor types start at 1 |
| 613 | 3, // SENSOR_TYPE_ACCELEROMETER |
| 614 | 3, // SENSOR_TYPE_GEOMAGNETIC_FIELD |
| 615 | 3, // SENSOR_TYPE_ORIENTATION |
| 616 | 3, // SENSOR_TYPE_GYROSCOPE |
| 617 | 3, // SENSOR_TYPE_LIGHT |
| 618 | 3, // SENSOR_TYPE_PRESSURE |
| 619 | 3, // SENSOR_TYPE_TEMPERATURE |
| 620 | 3, // SENSOR_TYPE_PROXIMITY |
| 621 | 3, // SENSOR_TYPE_GRAVITY |
| 622 | 3, // SENSOR_TYPE_LINEAR_ACCELERATION |
| 623 | 5, // SENSOR_TYPE_ROTATION_VECTOR |
| 624 | 3, // SENSOR_TYPE_RELATIVE_HUMIDITY |
| 625 | 3, // SENSOR_TYPE_AMBIENT_TEMPERATURE |
| 626 | 6, // SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED |
| 627 | 4, // SENSOR_TYPE_GAME_ROTATION_VECTOR |
| 628 | 6, // SENSOR_TYPE_GYROSCOPE_UNCALIBRATED |
| 629 | 1, // SENSOR_TYPE_SIGNIFICANT_MOTION |
| 630 | 1, // SENSOR_TYPE_STEP_DETECTOR |
| 631 | 1, // SENSOR_TYPE_STEP_COUNTER |
| 632 | 5, // SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR |
| 633 | 1, // SENSOR_TYPE_HEART_RATE_MONITOR |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 634 | 1, // SENSOR_TYPE_WAKE_UP_TILT_DETECTOR |
| 635 | 1, // SENSOR_TYPE_WAKE_GESTURE |
Jeff Brown | 241e70d | 2014-07-17 15:12:37 -0700 | [diff] [blame] | 636 | 1, // SENSOR_TYPE_GLANCE_GESTURE |
Aravind Akella | 96eb62c | 2014-07-17 12:42:00 -0700 | [diff] [blame] | 637 | 1, // SENSOR_TYPE_PICK_UP_GESTURE |
Nick Vaccaro | f5021f6 | 2015-01-23 15:09:45 -0800 | [diff] [blame] | 638 | 1, // SENSOR_TYPE_WRIST_TILT_GESTURE |
Trevor Bunker | 3c288e6 | 2016-01-08 11:11:13 -0800 | [diff] [blame] | 639 | 1, // SENSOR_TYPE_DEVICE_ORIENTATION |
Mathias Agopian | b25c0ef | 2013-07-03 15:38:29 -0700 | [diff] [blame] | 640 | }; |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 641 | |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 642 | /** |
| 643 | * Each sensor has exactly one reporting mode associated with it. This method returns the |
| 644 | * reporting mode constant for this sensor type. |
| 645 | * |
| 646 | * @return Reporting mode for the input sensor, one of REPORTING_MODE_* constants. |
| 647 | * @see #REPORTING_MODE_CONTINUOUS |
| 648 | * @see #REPORTING_MODE_ON_CHANGE |
| 649 | * @see #REPORTING_MODE_ONE_SHOT |
| 650 | * @see #REPORTING_MODE_SPECIAL_TRIGGER |
| 651 | */ |
| 652 | public int getReportingMode() { |
| 653 | return ((mFlags & REPORTING_MODE_MASK) >> REPORTING_MODE_SHIFT); |
Jaikumar Ganesh | 9a8df4d | 2013-02-12 16:31:32 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 656 | static int getMaxLengthValuesArray(Sensor sensor, int sdkLevel) { |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 657 | // RotationVector length has changed to 3 to 5 for API level 18 |
| 658 | // Set it to 3 for backward compatibility. |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 659 | if (sensor.mType == Sensor.TYPE_ROTATION_VECTOR && |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 660 | sdkLevel <= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
Mathias Agopian | b25c0ef | 2013-07-03 15:38:29 -0700 | [diff] [blame] | 661 | return 3; |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 662 | } |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 663 | int offset = sensor.mType; |
Mathias Agopian | b25c0ef | 2013-07-03 15:38:29 -0700 | [diff] [blame] | 664 | if (offset >= sSensorReportingModes.length) { |
| 665 | // we don't know about this sensor, so this is probably a |
| 666 | // vendor-defined sensor, in that case, we don't know how many value |
| 667 | // it has |
| 668 | // so we return the maximum and assume the app will know. |
| 669 | // FIXME: sensor HAL should advertise how much data is returned per |
| 670 | // sensor |
| 671 | return 16; |
| 672 | } |
| 673 | return sSensorReportingModes[offset]; |
Jaikumar Ganesh | 6d0c1d78 | 2013-03-27 17:41:33 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 676 | /* Some of these fields are set only by the native bindings in |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | * SensorManager. |
| 678 | */ |
| 679 | private String mName; |
| 680 | private String mVendor; |
| 681 | private int mVersion; |
| 682 | private int mHandle; |
| 683 | private int mType; |
| 684 | private float mMaxRange; |
| 685 | private float mResolution; |
| 686 | private float mPower; |
Mathias Agopian | 050b562 | 2010-07-29 16:51:38 -0700 | [diff] [blame] | 687 | private int mMinDelay; |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 688 | private int mFifoReservedEventCount; |
| 689 | private int mFifoMaxEventCount; |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 690 | private String mStringType; |
| 691 | private String mRequiredPermission; |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 692 | private int mMaxDelay; |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 693 | private int mFlags; |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | Sensor() { |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * @return name string of the sensor. |
| 700 | */ |
| 701 | public String getName() { |
| 702 | return mName; |
| 703 | } |
| 704 | |
| 705 | /** |
| 706 | * @return vendor string of this sensor. |
| 707 | */ |
| 708 | public String getVendor() { |
| 709 | return mVendor; |
| 710 | } |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 712 | /** |
| 713 | * @return generic type of this sensor. |
| 714 | */ |
| 715 | public int getType() { |
| 716 | return mType; |
| 717 | } |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 718 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | /** |
| 720 | * @return version of the sensor's module. |
| 721 | */ |
| 722 | public int getVersion() { |
| 723 | return mVersion; |
| 724 | } |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | /** |
| 727 | * @return maximum range of the sensor in the sensor's unit. |
| 728 | */ |
| 729 | public float getMaximumRange() { |
| 730 | return mMaxRange; |
| 731 | } |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | /** |
| 734 | * @return resolution of the sensor in the sensor's unit. |
| 735 | */ |
| 736 | public float getResolution() { |
| 737 | return mResolution; |
| 738 | } |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 739 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | /** |
| 741 | * @return the power in mA used by this sensor while in use |
| 742 | */ |
| 743 | public float getPower() { |
| 744 | return mPower; |
| 745 | } |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 746 | |
Mathias Agopian | 050b562 | 2010-07-29 16:51:38 -0700 | [diff] [blame] | 747 | /** |
| 748 | * @return the minimum delay allowed between two events in microsecond |
| 749 | * or zero if this sensor only returns a value when the data it's measuring |
| 750 | * changes. |
| 751 | */ |
| 752 | public int getMinDelay() { |
| 753 | return mMinDelay; |
| 754 | } |
| 755 | |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 756 | /** |
| 757 | * @return Number of events reserved for this sensor in the batch mode FIFO. This gives a |
Aravind Akella | d405e0f | 2013-09-04 12:07:33 -0700 | [diff] [blame] | 758 | * guarantee on the minimum number of events that can be batched. |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 759 | */ |
| 760 | public int getFifoReservedEventCount() { |
| 761 | return mFifoReservedEventCount; |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * @return Maximum number of events of this sensor that could be batched. If this value is zero |
| 766 | * it indicates that batch mode is not supported for this sensor. If other applications |
| 767 | * registered to batched sensors, the actual number of events that can be batched might be |
| 768 | * smaller because the hardware FiFo will be partially used to batch the other sensors. |
Aravind Akella | b4c76b1 | 2013-06-27 12:04:16 -0700 | [diff] [blame] | 769 | */ |
| 770 | public int getFifoMaxEventCount() { |
| 771 | return mFifoMaxEventCount; |
| 772 | } |
| 773 | |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 774 | /** |
| 775 | * @return The type of this sensor as a string. |
| 776 | */ |
| 777 | public String getStringType() { |
| 778 | return mStringType; |
| 779 | } |
| 780 | |
| 781 | /** |
Aravind Akella | b613dba | 2014-05-21 14:14:45 -0700 | [diff] [blame] | 782 | * @hide |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 783 | * @return The permission required to access this sensor. If empty, no permission is required. |
| 784 | */ |
| 785 | public String getRequiredPermission() { |
| 786 | return mRequiredPermission; |
| 787 | } |
| 788 | |
Mathias Agopian | 7f84c06 | 2013-02-04 19:22:47 -0800 | [diff] [blame] | 789 | /** @hide */ |
| 790 | public int getHandle() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 791 | return mHandle; |
| 792 | } |
Mathias Agopian | 74cde2c | 2010-06-16 18:55:46 -0700 | [diff] [blame] | 793 | |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 794 | /** |
Aravind Akella | e57676b | 2014-09-04 16:24:41 -0700 | [diff] [blame] | 795 | * This value is defined only for continuous and on-change sensors. It is the delay between two |
| 796 | * sensor events corresponding to the lowest frequency that this sensor supports. When lower |
| 797 | * frequencies are requested through registerListener() the events will be generated at this |
| 798 | * frequency instead. It can be used to estimate when the batch FIFO may be full. Older devices |
| 799 | * may set this value to zero. Ignore this value in case it is negative or zero. |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 800 | * |
| 801 | * @return The max delay for this sensor in microseconds. |
| 802 | */ |
| 803 | public int getMaxDelay() { |
| 804 | return mMaxDelay; |
| 805 | } |
| 806 | |
| 807 | /** |
Aravind Akella | 1f9b32f | 2014-09-16 15:21:44 -0700 | [diff] [blame] | 808 | * Returns true if the sensor is a wake-up sensor. |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 809 | * <p> |
Aravind Akella | 1f9b32f | 2014-09-16 15:21:44 -0700 | [diff] [blame] | 810 | * <b>Application Processor Power modes</b> <p> |
| 811 | * Application Processor(AP), is the processor on which applications run. When no wake lock is held |
| 812 | * and the user is not interacting with the device, this processor can enter a “Suspend” mode, |
| 813 | * reducing the power consumption by 10 times or more. |
| 814 | * </p> |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 815 | * <p> |
Aravind Akella | 1f9b32f | 2014-09-16 15:21:44 -0700 | [diff] [blame] | 816 | * <b>Non-wake-up sensors</b> <p> |
| 817 | * Non-wake-up sensors are sensors that do not wake the AP out of suspend to report data. While |
| 818 | * the AP is in suspend mode, the sensors continue to function and generate events, which are |
| 819 | * put in a hardware FIFO. The events in the FIFO are delivered to the application when the AP |
| 820 | * wakes up. If the FIFO was too small to store all events generated while the AP was in |
| 821 | * suspend mode, the older events are lost: the oldest data is dropped to accommodate the newer |
| 822 | * data. In the extreme case where the FIFO is non-existent {@code maxFifoEventCount() == 0}, |
| 823 | * all events generated while the AP was in suspend mode are lost. Applications using |
| 824 | * non-wake-up sensors should usually: |
| 825 | * <ul> |
| 826 | * <li>Either unregister from the sensors when they do not need them, usually in the activity’s |
| 827 | * {@code onPause} method. This is the most common case. |
| 828 | * <li>Or realize that the sensors are consuming some power while the AP is in suspend mode and |
| 829 | * that even then, some events might be lost. |
| 830 | * </ul> |
| 831 | * </p> |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 832 | * <p> |
Aravind Akella | 1f9b32f | 2014-09-16 15:21:44 -0700 | [diff] [blame] | 833 | * <b>Wake-up sensors</b> <p> |
| 834 | * In opposition to non-wake-up sensors, wake-up sensors ensure that their data is delivered |
| 835 | * independently of the state of the AP. While the AP is awake, the wake-up sensors behave |
| 836 | * like non-wake-up-sensors. When the AP is asleep, wake-up sensors wake up the AP to deliver |
| 837 | * events. That is, the AP will wake up and the sensor will deliver the events before the |
| 838 | * maximum reporting latency is elapsed or the hardware FIFO gets full. See {@link |
| 839 | * SensorManager#registerListener(SensorEventListener, Sensor, int, int)} for more details. |
| 840 | * </p> |
| 841 | * |
| 842 | * @return <code>true</code> if this is a wake-up sensor, <code>false</code> otherwise. |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 843 | */ |
| 844 | public boolean isWakeUpSensor() { |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 845 | return (mFlags & SENSOR_FLAG_WAKE_UP_SENSOR) != 0; |
Aravind Akella | 2f8b914 | 2014-05-12 14:39:29 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Aravind Akella | 18ebf732b | 2015-04-20 17:39:51 -0700 | [diff] [blame] | 848 | /** |
| 849 | * Returns true if the sensor supports data injection when the |
| 850 | * HAL is set to data injection mode. |
| 851 | * |
| 852 | * @return <code>true</code> if the sensor supports data |
| 853 | * injection when the HAL is set in injection mode, |
| 854 | * false otherwise. |
| 855 | * @hide |
| 856 | */ |
| 857 | @SystemApi |
| 858 | public boolean isDataInjectionSupported() { |
| 859 | return (((mFlags & DATA_INJECTION_MASK) >> DATA_INJECTION_SHIFT)) != 0; |
| 860 | } |
| 861 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 862 | void setRange(float max, float res) { |
| 863 | mMaxRange = max; |
| 864 | mResolution = res; |
| 865 | } |
Jeff Brown | 6a2ef12 | 2012-08-10 18:19:10 -0700 | [diff] [blame] | 866 | |
| 867 | @Override |
| 868 | public String toString() { |
| 869 | return "{Sensor name=\"" + mName + "\", vendor=\"" + mVendor + "\", version=" + mVersion |
| 870 | + ", type=" + mType + ", maxRange=" + mMaxRange + ", resolution=" + mResolution |
| 871 | + ", power=" + mPower + ", minDelay=" + mMinDelay + "}"; |
| 872 | } |
destradaa | 9ba7c1c | 2015-02-10 15:04:43 -0800 | [diff] [blame] | 873 | |
| 874 | /** |
| 875 | * Sets the Type associated with the sensor. |
| 876 | * NOTE: to be used only by native bindings in SensorManager. |
| 877 | * |
| 878 | * This allows interned static strings to be used across all representations of the Sensor. If |
| 879 | * a sensor type is not referenced here, it will still be interned by the native SensorManager. |
| 880 | * |
| 881 | * @return {@code true} if the StringType was successfully set, {@code false} otherwise. |
| 882 | */ |
| 883 | private boolean setType(int value) { |
| 884 | mType = value; |
| 885 | switch (mType) { |
| 886 | case TYPE_ACCELEROMETER: |
| 887 | mStringType = STRING_TYPE_ACCELEROMETER; |
| 888 | return true; |
| 889 | case TYPE_AMBIENT_TEMPERATURE: |
| 890 | mStringType = STRING_TYPE_AMBIENT_TEMPERATURE; |
| 891 | return true; |
| 892 | case TYPE_GAME_ROTATION_VECTOR: |
| 893 | mStringType = STRING_TYPE_GAME_ROTATION_VECTOR; |
| 894 | return true; |
| 895 | case TYPE_GEOMAGNETIC_ROTATION_VECTOR: |
| 896 | mStringType = STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR; |
| 897 | return true; |
| 898 | case TYPE_GLANCE_GESTURE: |
| 899 | mStringType = STRING_TYPE_GLANCE_GESTURE; |
| 900 | return true; |
| 901 | case TYPE_GRAVITY: |
| 902 | mStringType = STRING_TYPE_GRAVITY; |
| 903 | return true; |
| 904 | case TYPE_GYROSCOPE: |
| 905 | mStringType = STRING_TYPE_GYROSCOPE; |
| 906 | return true; |
| 907 | case TYPE_GYROSCOPE_UNCALIBRATED: |
| 908 | mStringType = STRING_TYPE_GYROSCOPE_UNCALIBRATED; |
| 909 | return true; |
| 910 | case TYPE_HEART_RATE: |
| 911 | mStringType = STRING_TYPE_HEART_RATE; |
| 912 | return true; |
| 913 | case TYPE_LIGHT: |
| 914 | mStringType = STRING_TYPE_LIGHT; |
| 915 | return true; |
| 916 | case TYPE_LINEAR_ACCELERATION: |
| 917 | mStringType = STRING_TYPE_LINEAR_ACCELERATION; |
| 918 | return true; |
| 919 | case TYPE_MAGNETIC_FIELD: |
| 920 | mStringType = STRING_TYPE_MAGNETIC_FIELD; |
| 921 | return true; |
| 922 | case TYPE_MAGNETIC_FIELD_UNCALIBRATED: |
| 923 | mStringType = STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED; |
| 924 | return true; |
| 925 | case TYPE_PICK_UP_GESTURE: |
| 926 | mStringType = STRING_TYPE_PICK_UP_GESTURE; |
| 927 | return true; |
| 928 | case TYPE_PRESSURE: |
| 929 | mStringType = STRING_TYPE_PRESSURE; |
| 930 | return true; |
| 931 | case TYPE_PROXIMITY: |
| 932 | mStringType = STRING_TYPE_PROXIMITY; |
| 933 | return true; |
| 934 | case TYPE_RELATIVE_HUMIDITY: |
| 935 | mStringType = STRING_TYPE_RELATIVE_HUMIDITY; |
| 936 | return true; |
| 937 | case TYPE_ROTATION_VECTOR: |
| 938 | mStringType = STRING_TYPE_ROTATION_VECTOR; |
| 939 | return true; |
| 940 | case TYPE_SIGNIFICANT_MOTION: |
| 941 | mStringType = STRING_TYPE_SIGNIFICANT_MOTION; |
| 942 | return true; |
| 943 | case TYPE_STEP_COUNTER: |
| 944 | mStringType = STRING_TYPE_STEP_COUNTER; |
| 945 | return true; |
| 946 | case TYPE_STEP_DETECTOR: |
| 947 | mStringType = STRING_TYPE_STEP_DETECTOR; |
| 948 | return true; |
| 949 | case TYPE_TILT_DETECTOR: |
| 950 | mStringType = SENSOR_STRING_TYPE_TILT_DETECTOR; |
| 951 | return true; |
| 952 | case TYPE_WAKE_GESTURE: |
| 953 | mStringType = STRING_TYPE_WAKE_GESTURE; |
| 954 | return true; |
| 955 | case TYPE_ORIENTATION: |
| 956 | mStringType = STRING_TYPE_ORIENTATION; |
| 957 | return true; |
| 958 | case TYPE_TEMPERATURE: |
| 959 | mStringType = STRING_TYPE_TEMPERATURE; |
| 960 | return true; |
Trevor Bunker | 3c288e6 | 2016-01-08 11:11:13 -0800 | [diff] [blame] | 961 | case TYPE_DEVICE_ORIENTATION: |
| 962 | mStringType = STRING_TYPE_DEVICE_ORIENTATION; |
| 963 | return true; |
destradaa | 9ba7c1c | 2015-02-10 15:04:43 -0800 | [diff] [blame] | 964 | default: |
| 965 | return false; |
| 966 | } |
| 967 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | } |