blob: 939bf73715013a91316f8a14dc894dff78280598 [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
80 * sensor events, the HAL should write the sensor events to the Event FMQ.
Brian Stack1f0c5ea2018-09-18 16:04:09 -070081 * Once the HAL is finished writing sensor events to the Event FMQ, the HAL
82 * must call the Event FMQ's EventFlag wake() function with the
83 * EventQueueFlagBits::READ_AND_PROCESS mask which notifies the framework
84 * that sensor events are available to be read and processed.
Brian Stackee3f7202018-09-05 16:46:28 -070085 *
Brian Stack28c675f2018-09-06 09:57:29 -070086 * The Wake Lock FMQ is used by the framework to notify the HAL when it is
87 * safe to release its wake_lock. When the framework receives WAKE_UP events
88 * from the Event FMQ and the framework has acquired a wake_lock, the
89 * framework must write a WakeLockEvent to the Wake Lock FMQ with the number
90 * of WAKE_UP events processed. When the HAL reads the WakeLockEvent from
91 * the Wake Lock FMQ, the HAL should decrement its current count of
92 * unprocessed WAKE_UP events and release its wake_lock if the current
93 * count of unprocessed WAKE_UP events is zero.
Brian Stackee3f7202018-09-05 16:46:28 -070094 *
Brian Stack78aa4fc2018-09-18 13:45:36 -070095 * The ISensorsCallback is used by the HAL to notify the framework of
96 * asynchronous events, such as a dynamic sensor connection.
97 *
Brian Stack28c675f2018-09-06 09:57:29 -070098 * The name of any wake_lock acquired by the Sensors HAL for WAKE_UP events
99 * must begin with "SensorsHAL_WAKEUP".
100 *
101 * If WAKE_LOCK_TIMEOUT_SECONDS has elapsed since the most recent WAKE_UP
102 * event was written to the Event FMQ without receiving a message on the
103 * Wake Lock FMQ, then any held wake_lock for WAKE_UP events must be
104 * released.
105 *
106 * If either the Event FMQ or the Wake Lock FMQ is already initialized when
Brian Stack78aa4fc2018-09-18 13:45:36 -0700107 * initialize is invoked, then both existing FMQs must be discarded and the
108 * new descriptors must be used to create new FMQs within the HAL. The
109 * number of outstanding WAKE_UP events should also be reset to zero, and
110 * any outstanding wake_locks held as a result of WAKE_UP events should be
111 * released.
Brian Stack28c675f2018-09-06 09:57:29 -0700112 *
Brian Stack78aa4fc2018-09-18 13:45:36 -0700113 * initialize must be thread safe and prevent concurrent calls
114 * to initialize from simultaneously modifying state.
Brian Stack28c675f2018-09-06 09:57:29 -0700115 *
116 * @param eventQueueDescriptor Fast Message Queue descriptor that is used to
117 * create the Event FMQ which is where sensor events are written. The
118 * descriptor is obtained from the framework's FMQ that is used to read
119 * sensor events.
120 * @param wakeLockDescriptor Fast Message Queue descriptor that is used to
121 * create the Wake Lock FMQ which is where wake_lock events are read
122 * from. The descriptor is obtained from the framework's FMQ that is
123 * used to write wake_lock events.
Brian Stack78aa4fc2018-09-18 13:45:36 -0700124 * @param sensorsCallback sensors callback that receives asynchronous data
125 * from the Sensors HAL.
Brian Stack28c675f2018-09-06 09:57:29 -0700126 * @return result OK on success; BAD_VALUE if descriptor is invalid (such
127 * as null)
Brian Stackee3f7202018-09-05 16:46:28 -0700128 */
Brian Stack28c675f2018-09-06 09:57:29 -0700129 @entry
130 @callflow(next = {"getSensorsList"})
Brian Stack78aa4fc2018-09-18 13:45:36 -0700131 initialize(fmq_sync<Event> eventQueueDescriptor,
132 fmq_sync<uint32_t> wakeLockDescriptor,
133 ISensorsCallback sensorsCallback)
134 generates
135 (Result result);
Brian Stackee3f7202018-09-05 16:46:28 -0700136
137 /**
138 * Sets a sensor’s parameters, including sampling frequency and maximum
139 * report latency. This function can be called while the sensor is
140 * activated, in which case it must not cause any sensor measurements to
141 * be lost: transitioning from one sampling rate to the other cannot cause
142 * lost events, nor can transitioning from a high maximum report latency to
143 * a low maximum report latency.
144 *
145 * @param sensorHandle handle of sensor to be changed.
146 * @param samplingPeriodNs specifies sensor sample period in nanoseconds.
147 * @param maxReportLatencyNs allowed delay time before an event is sampled
148 * to time of report.
149 * @return result OK on success, BAD_VALUE if any parameters are invalid.
150 */
151 batch(int32_t sensorHandle,
152 int64_t samplingPeriodNs,
153 int64_t maxReportLatencyNs)
154 generates (
155 Result result);
156
157 /**
158 * Trigger a flush of internal FIFO.
159 *
160 * Flush adds a FLUSH_COMPLETE metadata event to the end of the "batch mode"
161 * FIFO for the specified sensor and flushes the FIFO. If the FIFO is empty
162 * or if the sensor doesn't support batching (FIFO size zero), return
163 * SUCCESS and add a trivial FLUSH_COMPLETE event added to the event stream.
164 * This applies to all sensors other than one-shot sensors. If the sensor
165 * is a one-shot sensor, flush must return BAD_VALUE and not generate any
166 * flush complete metadata. If the sensor is not active at the time flush()
167 * is called, flush() return BAD_VALUE.
168 *
169 * @param sensorHandle handle of sensor to be flushed.
170 * @return result OK on success and BAD_VALUE if sensorHandle is invalid.
171 */
172 flush(int32_t sensorHandle) generates (Result result);
173
174 /**
175 * Inject a single sensor event or push operation environment parameters to
176 * device.
177 *
178 * When device is in NORMAL mode, this function is called to push operation
179 * environment data to device. In this operation, Event is always of
180 * SensorType::AdditionalInfo type. See operation evironment parameters
181 * section in AdditionalInfoType.
182 *
183 * When device is in DATA_INJECTION mode, this function is also used for
184 * injecting sensor events.
185 *
186 * Regardless of OperationMode, injected SensorType::ADDITIONAL_INFO
Brian Stack28c675f2018-09-06 09:57:29 -0700187 * type events should not be routed back to the sensor event queue.
Brian Stackee3f7202018-09-05 16:46:28 -0700188 *
189 * @see AdditionalInfoType
190 * @see OperationMode
191 * @param event sensor event to be injected
192 * @return result OK on success; PERMISSION_DENIED if operation is not
193 * allowed; INVALID_OPERATION, if this functionality is unsupported;
194 * BAD_VALUE if sensor event cannot be injected.
195 */
196 injectSensorData(Event event) generates (Result result);
197
198 /**
199 * Register direct report channel.
200 *
201 * Register a direct channel with supplied shared memory information. Upon
202 * return, the sensor hardware is responsible for resetting the memory
203 * content to initial value (depending on memory format settings).
204 *
205 * @param mem shared memory info data structure.
206 * @return result OK on success; BAD_VALUE if shared memory information is
207 * not consistent; NO_MEMORY if shared memory cannot be used by sensor
208 * system; INVALID_OPERATION if functionality is not supported.
209 * @return channelHandle a positive integer used for referencing registered
210 * direct channel (>0) in configureDirectReport and
211 * unregisterDirectChannel if result is OK, -1 otherwise.
212 */
213 registerDirectChannel(SharedMemInfo mem)
214 generates (Result result,
215 int32_t channelHandle);
216
217 /**
218 * Unregister direct report channel.
219 *
220 * Unregister a direct channel previously registered using
221 * registerDirectChannel, and remove all active sensor report configured in
222 * still active sensor report configured in the direct channel.
223 *
224 * @param channelHandle handle of direct channel to be unregistered.
225 * @return result OK if direct report is supported; INVALID_OPERATION
226 * otherwise.
227 */
228 unregisterDirectChannel(int32_t channelHandle) generates (Result result);
229
230 /**
231 * Configure direct sensor event report in direct channel.
232 *
233 * This function start, modify rate or stop direct report of a sensor in a
234 * certain direct channel.
235 *
236 * @param sensorHandle handle of sensor to be configured. When combined
237 * with STOP rate, sensorHandle can be -1 to denote all active sensors
238 * in the direct channel specified by channel Handle.
239 * @param channelHandle handle of direct channel to be configured.
240 * @param rate rate level, see RateLevel enum.
241 * @return result OK on success; BAD_VALUE if parameter is invalid (such as
242 * rate level is not supported by sensor, channelHandle does not exist,
243 * etc); INVALID_OPERATION if functionality is not supported.
244 * @return reportToken positive integer to identify multiple sensors of
245 * the same type in a single direct channel. Ignored if rate is STOP.
246 * See SharedMemFormat.
247 */
248 configDirectReport(
249 int32_t sensorHandle,
250 int32_t channelHandle,
251 RateLevel rate
252 ) generates (
253 Result result,
254 int32_t reportToken);
255};