blob: 537025e8ee0ac0e6792aab7c6e5ff599af2192eb [file] [log] [blame]
Clay Murphyd01c5512014-09-18 18:28:04 -07001page.title=Sensors
Clay Murphy4ea104f2013-10-28 17:44:33 -07002@jd:body
3
4<!--
Heidi von Markham1e7b8b72015-03-09 10:13:48 -07005 Copyright 2015 The Android Open Source Project
Clay Murphy4ea104f2013-10-28 17:44:33 -07006
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18-->
19<div id="qv-wrapper">
20 <div id="qv">
21 <h2>In this document</h2>
22 <ol id="auto-toc">
23 </ol>
24 </div>
25</div>
Heidi von Markhamb493fb62015-03-25 12:35:11 -070026<img style="float: right; margin: 0px 15px 15px 15px;" src="images/ape_fwk_hal_sensors.png" alt="Android Sensors HAL icon"/>
Clay Murphy4ea104f2013-10-28 17:44:33 -070027
Heidi von Markham1e7b8b72015-03-09 10:13:48 -070028<p>Android sensors give applications access to a mobile device's underlying physical sensors. They are data-providing virtual devices defined by <a href="{@docRoot}devices/halref/sensors_8h.html">sensors.h</a>, the sensor Hardware Abstraction Layer (HAL).</p>
29
30<h2 id="what_are_“android_sensors”">What are Android sensors?</h2>
31<p>Android sensors are virtual devices that provide data coming from a set of physical sensors: accelerometers, gyroscopes, magnetometers, barometer, humidity, pressure, light, proximity and heart rate sensors.</p>
32<p>Not included in the list of physical devices providing data are camera, fingerprint sensor, microphone, and touch screen. These devices have their own reporting mechanism; the separation is arbitrary, but in general, Android sensors provide lower bandwidth data. For example, “100hz x 3 channels” for an accelerometer versus “25hz x 8 MP x 3 channels” for a camera or “44kHz x 1 channel” for a microphone.</p>
33 <p>Android does not define how the different physical sensors are connected to the system on chip (SoC).</p>
Clay Murphyd01c5512014-09-18 18:28:04 -070034 <ul>
35 <li> Often, sensor chips are connected to the SoC through a <a href="sensor-stack.html#sensor_hub">sensor hub</a>, allowing some low-power monitoring and processing of the data. </li>
36 <li> Often, Inter-Integrated Circuit (I2C) or Serial Peripheral Interface
37 (SPI) is used as the transport mechanism. </li>
38 <li> To reduce power consumption, some architectures are hierarchical, with some
39 minimal processing being done in the application-specific integrated
40 circuit (ASIC - like motion detection on the accelerometer chip), and
41 more is done in a microcontroller (like step detection
42 in a sensor hub). </li>
43 <li> It is up to the device manufacturer to choose an architecture based on
44 accuracy, power, price and package-size characteristics. See <a
45 href="sensor-stack.html">Sensor stack</a> for more information. </li>
46 <li> Batching capabilities are an important consideration for power optimization.
47 See <a href="batching.html">Batching</a> for more information. </li>
48 </ul>
49 <p>Each Android sensor has a “type” representing how the sensor behaves and what
50 data it provides.</p>
51 <ul>
Clay Murphy92c38f92014-10-30 18:19:30 -070052 <li> The official Android <a href="sensor-types.html">Sensor types</a> are defined in <a href="{@docRoot}devices/halref/sensors_8h.html">sensors.h</a> under the names SENSOR_TYPE_…
Clay Murphyd01c5512014-09-18 18:28:04 -070053 <ul>
54 <li> The vast majority of sensors have an official sensor type. </li>
55 <li> Those types are documented in the Android SDK. </li>
56 <li> Behavior of sensors with those types are tested in the Android
57 Compatibility Test Suite (CTS). </li>
58 </ul>
59 </li>
60 <li> If a manufacturer integrates a new kind of sensor on an Android device, the
61 manufacturer can define its own temporary type to refer to it.
62 <ul>
63 <li> Those types are undocumented, so application developers are unlikely to use
64 them, either because they don’t know about them, or know that they are rarely
65 present (only on some devices from this specific manufacturer). </li>
66 <li> They are not tested by CTS. </li>
67 <li> Once Android defines an official sensor type for this kind of
68 sensor, manufacturers must stop using their own temporary type
69 and use the official type instead. This way, the sensor will be
70 used by more application developers. </li>
71 </ul>
72 </li>
73 <li> The list of all sensors present on the device is reported by the HAL
74 implementation.
75 <ul>
76 <li> There can be several sensors of the same type. For example, two proximity
77 sensors or two accelerometers. </li>
78 <li> The vast majority of applications request only a single sensor of a given type.
79 For example, an application requesting the default accelerometer will get the
80 first accelerometer in the list. </li>
81 <li> Sensors are often defined by <a href="suspend-mode.html#wake-up_sensors">wake-up</a> and <a href="suspend-mode.html#non-wake-up_sensors">non-wake-up</a> pairs, both sensors sharing the same type, but differing by their wake-up
82 characteristic. </li>
83 </ul>
84 </li>
85 </ul>
86<p>Android sensors provide data as a series of sensor events.</p>
87 <p> Each <a href="hal-interface.html#sensors_event_t">event</a> contains:</p>
88 <ul>
89 <li> a handle to the sensor that generated it </li>
90 <li> the timestamp at which the event was detected or measured </li>
91 <li> and some data </li>
92 </ul>
93 <p>The interpretation of the reported data depends on the sensor type.
94 See the <a href="sensor-types.html">sensor type</a> definitions for details on
95 what data is reported for each sensor type.</p>
96
97<h2 id="existing_documentation2">Existing documentation</h2>
98 <h3 id="targeted_at_developers">Targeted at developers</h3>
99 <ul>
100 <li> Overview
101 <ul>
102 <li><a href="https://developer.android.com/guide/topics/sensors/sensors_overview.html"> https://developer.android.com/guide/topics/sensors/sensors_overview.html </a></li>
103 </ul>
104 </li>
105 <li> SDK reference
106 <ul>
107 <li> <a href="https://developer.android.com/reference/android/hardware/SensorManager.html">https://developer.android.com/reference/android/hardware/SensorManager.html</a></li>
108 <li><a href="https://developer.android.com/reference/android/hardware/SensorEventListener.html"> https://developer.android.com/reference/android/hardware/SensorEventListener.html</a></li>
109 <li> <a href="https://developer.android.com/reference/android/hardware/SensorEvent.html">https://developer.android.com/reference/android/hardware/SensorEvent.html</a></li>
110 <li><a href="https://developer.android.com/reference/android/hardware/Sensor.html"> https://developer.android.com/reference/android/hardware/Sensor.html</a></li>
111 </ul>
112 </li>
113 <li> StackOverflow and tutorial websites
114 <ul>
115 <li> Because sensors documentation was sometimes lacking, developers resorted to Q&amp;A
116 websites like StackOverflow to find answers. </li>
117 <li> Some tutorial websites exist as well, but do not cover the latest features like
118 batching, significant motion and game rotation vectors. </li>
119 <li> The answers over there are not always right, and show where more documentation
120 is needed. </li>
121 </ul>
122 </li>
123 </ul>
124<h3 id="targeted_at_manufacturers_public">Targeted at manufacturers</h3>
125 <ul>
126 <li> Overview
127 <ul>
128 <li>This <a href="{@docRoot}devices/sensors/index.html">Sensors</a>
129 page and its sub-pages. </li>
130 </ul>
131 </li>
132 <li> Hardware abstraction layer (HAL)
133 <ul>
Clay Murphy92c38f92014-10-30 18:19:30 -0700134 <li> <a href="{@docRoot}devices/halref/sensors_8h_source.html">https://source.android.com/devices/halref/sensors_8h_source.html</a></li>
Clay Murphyd01c5512014-09-18 18:28:04 -0700135 <li> Also known as “sensors.h” </li>
136 <li> The source of truth. First document to be updated when new features are
137 developed. </li>
138 </ul>
139 </li>
140 <li> Android CDD (Compatibility Definition Document)
141 <ul>
142 <li><a href="{@docRoot}compatibility/android-cdd.pdf">https://source.android.com/compatibility/android-cdd.pdf</a></li>
143 <li> See sections relative to sensors. </li>
144 <li> The CDD is lenient, so satisfying the CDD requirements is not enough to ensure
145 high quality sensors. </li>
146 </ul>
147 </li>
148 </ul>