blob: 1685a0a11cdafae9186a2fd3d8c42cf7be64cc91 [file] [log] [blame]
Brian Stackee3f7202018-09-05 16:46:28 -07001/*
2 * Copyright (C) 2018 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
17package android.hardware.sensors@2.0;
18
19import @1.0::Event;
20import @1.0::OperationMode;
21import @1.0::RateLevel;
22import @1.0::Result;
23import @1.0::SensorInfo;
24import @1.0::SharedMemInfo;
Brian Stack78aa4fc2018-09-18 13:45:36 -070025import @2.0::ISensorsCallback;
Brian Stackee3f7202018-09-05 16:46:28 -070026
27interface ISensors {
28 /**
29 * Enumerate all available (static) sensors.
Brian Stack7ff95642018-10-01 16:06:39 -070030 *
31 * The SensorInfo for each sensor returned by getSensorsList must be stable
32 * from the initial call to getSensorsList after a device boot until the
33 * entire system restarts. The SensorInfo for each sensor must not change
34 * between subsequent calls to getSensorsList, even across restarts of the
35 * HAL and its dependencies (for example, the sensor handle for a given
36 * sensor must not change across HAL restarts).
Brian Stackee3f7202018-09-05 16:46:28 -070037 */
38 getSensorsList() generates (vec<SensorInfo> list);
39
40 /**
41 * Place the module in a specific mode. The following modes are defined
42 *
43 * SENSOR_HAL_NORMAL_MODE - Normal operation. Default state of the module.
44 *
45 * SENSOR_HAL_DATA_INJECTION_MODE - Loopback mode.
46 * Data is injected for the supported sensors by the sensor service in
47 * this mode.
48 *
49 * @return OK on success
50 * BAD_VALUE if requested mode is not supported
51 * PERMISSION_DENIED if operation is not allowed
52 */
53 setOperationMode(OperationMode mode) generates (Result result);
54
55 /**
56 * Activate/de-activate one sensor.
57 *
58 * After sensor de-activation, existing sensor events that have not
Brian Stack28c675f2018-09-06 09:57:29 -070059 * been written to the event queue must be abandoned immediately so that
Brian Stackee3f7202018-09-05 16:46:28 -070060 * subsequent activations do not get stale sensor events (events
61 * that are generated prior to the latter activation).
62 *
63 * @param sensorHandle is the handle of the sensor to change.
64 * @param enabled set to true to enable, or false to disable the sensor.
65 * @return result OK on success, BAD_VALUE if sensorHandle is invalid.
66 */
67 activate(int32_t sensorHandle, bool enabled) generates (Result result);
68
69 /**
Brian Stack78aa4fc2018-09-18 13:45:36 -070070 * Initialize the Sensors HAL's Fast Message Queues (FMQ) and callback.
71 *
72 * The Fast Message Queues (FMQ) that are used to send data between the
73 * framework and the HAL. The callback is used by the HAL to notify the
74 * framework of asynchronous events, such as a dynamic sensor connection.
Brian Stackee3f7202018-09-05 16:46:28 -070075 *
Brian Stack28c675f2018-09-06 09:57:29 -070076 * The Event FMQ is used to transport sensor events from the HAL to the
77 * framework. The Event FMQ is created using the eventQueueDescriptor.
78 * Data may only be written to the Event FMQ. Data must not be read from
79 * the Event FMQ since the framework is the only reader. Upon receiving
Brian Stack6e4a2202018-12-11 13:39:07 -080080 * sensor events, the HAL writes the sensor events to the Event FMQ.
81 *
Brian Stack1f0c5ea2018-09-18 16:04:09 -070082 * Once the HAL is finished writing sensor events to the Event FMQ, the HAL
Brian Stack6e4a2202018-12-11 13:39:07 -080083 * must notify the framework that sensor events are available to be read and
84 * processed. This is accomplished by either:
85 * 1) Calling the Event FMQ’s EventFlag::wake() function with
86 EventQueueFlagBits::READ_AND_PROCESS
87 * 2) Setting the write notification in the Event FMQ’s writeBlocking()
88 * function to EventQueueFlagBits::READ_AND_PROCESS.
89 *
90 * If the Event FMQ’s writeBlocking() function is used, the read
91 * notification must be set to EventQueueFlagBits::EVENTS_READ in order to
92 * be notified and unblocked when the framework has successfully read events
93 * from the Event FMQ.
Brian Stackee3f7202018-09-05 16:46:28 -070094 *
Brian Stack28c675f2018-09-06 09:57:29 -070095 * The Wake Lock FMQ is used by the framework to notify the HAL when it is
96 * safe to release its wake_lock. When the framework receives WAKE_UP events
97 * from the Event FMQ and the framework has acquired a wake_lock, the
98 * framework must write a WakeLockEvent to the Wake Lock FMQ with the number
99 * of WAKE_UP events processed. When the HAL reads the WakeLockEvent from
100 * the Wake Lock FMQ, the HAL should decrement its current count of
101 * unprocessed WAKE_UP events and release its wake_lock if the current
102 * count of unprocessed WAKE_UP events is zero.
Brian Stackee3f7202018-09-05 16:46:28 -0700103 *
Brian Stack78aa4fc2018-09-18 13:45:36 -0700104 * The ISensorsCallback is used by the HAL to notify the framework of
105 * asynchronous events, such as a dynamic sensor connection.
106 *
Brian Stack28c675f2018-09-06 09:57:29 -0700107 * The name of any wake_lock acquired by the Sensors HAL for WAKE_UP events
108 * must begin with "SensorsHAL_WAKEUP".
109 *
110 * If WAKE_LOCK_TIMEOUT_SECONDS has elapsed since the most recent WAKE_UP
111 * event was written to the Event FMQ without receiving a message on the
112 * Wake Lock FMQ, then any held wake_lock for WAKE_UP events must be
113 * released.
114 *
115 * If either the Event FMQ or the Wake Lock FMQ is already initialized when
Brian Stack78aa4fc2018-09-18 13:45:36 -0700116 * initialize is invoked, then both existing FMQs must be discarded and the
117 * new descriptors must be used to create new FMQs within the HAL. The
118 * number of outstanding WAKE_UP events should also be reset to zero, and
119 * any outstanding wake_locks held as a result of WAKE_UP events should be
120 * released.
Brian Stack28c675f2018-09-06 09:57:29 -0700121 *
Brian Stack6e4a2202018-12-11 13:39:07 -0800122 * All active sensor requests and direct channels must be closed and
123 * properly cleaned up when initialize is called in order to ensure that the
124 * HAL and framework's state is consistent (e.g. after a runtime restart).
125 *
Brian Stack78aa4fc2018-09-18 13:45:36 -0700126 * initialize must be thread safe and prevent concurrent calls
127 * to initialize from simultaneously modifying state.
Brian Stack28c675f2018-09-06 09:57:29 -0700128 *
129 * @param eventQueueDescriptor Fast Message Queue descriptor that is used to
130 * create the Event FMQ which is where sensor events are written. The
131 * descriptor is obtained from the framework's FMQ that is used to read
132 * sensor events.
133 * @param wakeLockDescriptor Fast Message Queue descriptor that is used to
134 * create the Wake Lock FMQ which is where wake_lock events are read
135 * from. The descriptor is obtained from the framework's FMQ that is
136 * used to write wake_lock events.
Brian Stack78aa4fc2018-09-18 13:45:36 -0700137 * @param sensorsCallback sensors callback that receives asynchronous data
138 * from the Sensors HAL.
Brian Stack28c675f2018-09-06 09:57:29 -0700139 * @return result OK on success; BAD_VALUE if descriptor is invalid (such
140 * as null)
Brian Stackee3f7202018-09-05 16:46:28 -0700141 */
Brian Stack28c675f2018-09-06 09:57:29 -0700142 @entry
143 @callflow(next = {"getSensorsList"})
Brian Stack78aa4fc2018-09-18 13:45:36 -0700144 initialize(fmq_sync<Event> eventQueueDescriptor,
145 fmq_sync<uint32_t> wakeLockDescriptor,
146 ISensorsCallback sensorsCallback)
147 generates
148 (Result result);
Brian Stackee3f7202018-09-05 16:46:28 -0700149
150 /**
151 * Sets a sensor’s parameters, including sampling frequency and maximum
152 * report latency. This function can be called while the sensor is
153 * activated, in which case it must not cause any sensor measurements to
154 * be lost: transitioning from one sampling rate to the other cannot cause
155 * lost events, nor can transitioning from a high maximum report latency to
156 * a low maximum report latency.
157 *
158 * @param sensorHandle handle of sensor to be changed.
159 * @param samplingPeriodNs specifies sensor sample period in nanoseconds.
160 * @param maxReportLatencyNs allowed delay time before an event is sampled
161 * to time of report.
162 * @return result OK on success, BAD_VALUE if any parameters are invalid.
163 */
164 batch(int32_t sensorHandle,
165 int64_t samplingPeriodNs,
166 int64_t maxReportLatencyNs)
167 generates (
168 Result result);
169
170 /**
171 * Trigger a flush of internal FIFO.
172 *
173 * Flush adds a FLUSH_COMPLETE metadata event to the end of the "batch mode"
174 * FIFO for the specified sensor and flushes the FIFO. If the FIFO is empty
175 * or if the sensor doesn't support batching (FIFO size zero), return
176 * SUCCESS and add a trivial FLUSH_COMPLETE event added to the event stream.
177 * This applies to all sensors other than one-shot sensors. If the sensor
178 * is a one-shot sensor, flush must return BAD_VALUE and not generate any
179 * flush complete metadata. If the sensor is not active at the time flush()
180 * is called, flush() return BAD_VALUE.
181 *
182 * @param sensorHandle handle of sensor to be flushed.
183 * @return result OK on success and BAD_VALUE if sensorHandle is invalid.
184 */
185 flush(int32_t sensorHandle) generates (Result result);
186
187 /**
188 * Inject a single sensor event or push operation environment parameters to
189 * device.
190 *
191 * When device is in NORMAL mode, this function is called to push operation
192 * environment data to device. In this operation, Event is always of
193 * SensorType::AdditionalInfo type. See operation evironment parameters
194 * section in AdditionalInfoType.
195 *
196 * When device is in DATA_INJECTION mode, this function is also used for
197 * injecting sensor events.
198 *
199 * Regardless of OperationMode, injected SensorType::ADDITIONAL_INFO
Brian Stack28c675f2018-09-06 09:57:29 -0700200 * type events should not be routed back to the sensor event queue.
Brian Stackee3f7202018-09-05 16:46:28 -0700201 *
202 * @see AdditionalInfoType
203 * @see OperationMode
204 * @param event sensor event to be injected
205 * @return result OK on success; PERMISSION_DENIED if operation is not
206 * allowed; INVALID_OPERATION, if this functionality is unsupported;
207 * BAD_VALUE if sensor event cannot be injected.
208 */
209 injectSensorData(Event event) generates (Result result);
210
211 /**
212 * Register direct report channel.
213 *
214 * Register a direct channel with supplied shared memory information. Upon
215 * return, the sensor hardware is responsible for resetting the memory
216 * content to initial value (depending on memory format settings).
217 *
218 * @param mem shared memory info data structure.
219 * @return result OK on success; BAD_VALUE if shared memory information is
220 * not consistent; NO_MEMORY if shared memory cannot be used by sensor
221 * system; INVALID_OPERATION if functionality is not supported.
222 * @return channelHandle a positive integer used for referencing registered
223 * direct channel (>0) in configureDirectReport and
224 * unregisterDirectChannel if result is OK, -1 otherwise.
225 */
226 registerDirectChannel(SharedMemInfo mem)
227 generates (Result result,
228 int32_t channelHandle);
229
230 /**
231 * Unregister direct report channel.
232 *
233 * Unregister a direct channel previously registered using
234 * registerDirectChannel, and remove all active sensor report configured in
235 * still active sensor report configured in the direct channel.
236 *
237 * @param channelHandle handle of direct channel to be unregistered.
238 * @return result OK if direct report is supported; INVALID_OPERATION
239 * otherwise.
240 */
241 unregisterDirectChannel(int32_t channelHandle) generates (Result result);
242
243 /**
244 * Configure direct sensor event report in direct channel.
245 *
246 * This function start, modify rate or stop direct report of a sensor in a
247 * certain direct channel.
248 *
249 * @param sensorHandle handle of sensor to be configured. When combined
250 * with STOP rate, sensorHandle can be -1 to denote all active sensors
251 * in the direct channel specified by channel Handle.
252 * @param channelHandle handle of direct channel to be configured.
253 * @param rate rate level, see RateLevel enum.
254 * @return result OK on success; BAD_VALUE if parameter is invalid (such as
255 * rate level is not supported by sensor, channelHandle does not exist,
256 * etc); INVALID_OPERATION if functionality is not supported.
257 * @return reportToken positive integer to identify multiple sensors of
258 * the same type in a single direct channel. Ignored if rate is STOP.
259 * See SharedMemFormat.
260 */
261 configDirectReport(
262 int32_t sensorHandle,
263 int32_t channelHandle,
264 RateLevel rate
265 ) generates (
266 Result result,
267 int32_t reportToken);
268};