blob: 2a57251103d8f0be41330831d19a06a501cf6372 [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.
30 */
31 getSensorsList() generates (vec<SensorInfo> list);
32
33 /**
34 * Place the module in a specific mode. The following modes are defined
35 *
36 * SENSOR_HAL_NORMAL_MODE - Normal operation. Default state of the module.
37 *
38 * SENSOR_HAL_DATA_INJECTION_MODE - Loopback mode.
39 * Data is injected for the supported sensors by the sensor service in
40 * this mode.
41 *
42 * @return OK on success
43 * BAD_VALUE if requested mode is not supported
44 * PERMISSION_DENIED if operation is not allowed
45 */
46 setOperationMode(OperationMode mode) generates (Result result);
47
48 /**
49 * Activate/de-activate one sensor.
50 *
51 * After sensor de-activation, existing sensor events that have not
Brian Stack28c675f2018-09-06 09:57:29 -070052 * been written to the event queue must be abandoned immediately so that
Brian Stackee3f7202018-09-05 16:46:28 -070053 * subsequent activations do not get stale sensor events (events
54 * that are generated prior to the latter activation).
55 *
56 * @param sensorHandle is the handle of the sensor to change.
57 * @param enabled set to true to enable, or false to disable the sensor.
58 * @return result OK on success, BAD_VALUE if sensorHandle is invalid.
59 */
60 activate(int32_t sensorHandle, bool enabled) generates (Result result);
61
62 /**
Brian Stack78aa4fc2018-09-18 13:45:36 -070063 * Initialize the Sensors HAL's Fast Message Queues (FMQ) and callback.
64 *
65 * The Fast Message Queues (FMQ) that are used to send data between the
66 * framework and the HAL. The callback is used by the HAL to notify the
67 * framework of asynchronous events, such as a dynamic sensor connection.
Brian Stackee3f7202018-09-05 16:46:28 -070068 *
Brian Stack28c675f2018-09-06 09:57:29 -070069 * The Event FMQ is used to transport sensor events from the HAL to the
70 * framework. The Event FMQ is created using the eventQueueDescriptor.
71 * Data may only be written to the Event FMQ. Data must not be read from
72 * the Event FMQ since the framework is the only reader. Upon receiving
73 * sensor events, the HAL should write the sensor events to the Event FMQ.
Brian Stack1f0c5ea2018-09-18 16:04:09 -070074 * Once the HAL is finished writing sensor events to the Event FMQ, the HAL
75 * must call the Event FMQ's EventFlag wake() function with the
76 * EventQueueFlagBits::READ_AND_PROCESS mask which notifies the framework
77 * that sensor events are available to be read and processed.
Brian Stackee3f7202018-09-05 16:46:28 -070078 *
Brian Stack28c675f2018-09-06 09:57:29 -070079 * The Wake Lock FMQ is used by the framework to notify the HAL when it is
80 * safe to release its wake_lock. When the framework receives WAKE_UP events
81 * from the Event FMQ and the framework has acquired a wake_lock, the
82 * framework must write a WakeLockEvent to the Wake Lock FMQ with the number
83 * of WAKE_UP events processed. When the HAL reads the WakeLockEvent from
84 * the Wake Lock FMQ, the HAL should decrement its current count of
85 * unprocessed WAKE_UP events and release its wake_lock if the current
86 * count of unprocessed WAKE_UP events is zero.
Brian Stackee3f7202018-09-05 16:46:28 -070087 *
Brian Stack78aa4fc2018-09-18 13:45:36 -070088 * The ISensorsCallback is used by the HAL to notify the framework of
89 * asynchronous events, such as a dynamic sensor connection.
90 *
Brian Stack28c675f2018-09-06 09:57:29 -070091 * The name of any wake_lock acquired by the Sensors HAL for WAKE_UP events
92 * must begin with "SensorsHAL_WAKEUP".
93 *
94 * If WAKE_LOCK_TIMEOUT_SECONDS has elapsed since the most recent WAKE_UP
95 * event was written to the Event FMQ without receiving a message on the
96 * Wake Lock FMQ, then any held wake_lock for WAKE_UP events must be
97 * released.
98 *
99 * If either the Event FMQ or the Wake Lock FMQ is already initialized when
Brian Stack78aa4fc2018-09-18 13:45:36 -0700100 * initialize is invoked, then both existing FMQs must be discarded and the
101 * new descriptors must be used to create new FMQs within the HAL. The
102 * number of outstanding WAKE_UP events should also be reset to zero, and
103 * any outstanding wake_locks held as a result of WAKE_UP events should be
104 * released.
Brian Stack28c675f2018-09-06 09:57:29 -0700105 *
Brian Stack78aa4fc2018-09-18 13:45:36 -0700106 * initialize must be thread safe and prevent concurrent calls
107 * to initialize from simultaneously modifying state.
Brian Stack28c675f2018-09-06 09:57:29 -0700108 *
109 * @param eventQueueDescriptor Fast Message Queue descriptor that is used to
110 * create the Event FMQ which is where sensor events are written. The
111 * descriptor is obtained from the framework's FMQ that is used to read
112 * sensor events.
113 * @param wakeLockDescriptor Fast Message Queue descriptor that is used to
114 * create the Wake Lock FMQ which is where wake_lock events are read
115 * from. The descriptor is obtained from the framework's FMQ that is
116 * used to write wake_lock events.
Brian Stack78aa4fc2018-09-18 13:45:36 -0700117 * @param sensorsCallback sensors callback that receives asynchronous data
118 * from the Sensors HAL.
Brian Stack28c675f2018-09-06 09:57:29 -0700119 * @return result OK on success; BAD_VALUE if descriptor is invalid (such
120 * as null)
Brian Stackee3f7202018-09-05 16:46:28 -0700121 */
Brian Stack28c675f2018-09-06 09:57:29 -0700122 @entry
123 @callflow(next = {"getSensorsList"})
Brian Stack78aa4fc2018-09-18 13:45:36 -0700124 initialize(fmq_sync<Event> eventQueueDescriptor,
125 fmq_sync<uint32_t> wakeLockDescriptor,
126 ISensorsCallback sensorsCallback)
127 generates
128 (Result result);
Brian Stackee3f7202018-09-05 16:46:28 -0700129
130 /**
131 * Sets a sensor’s parameters, including sampling frequency and maximum
132 * report latency. This function can be called while the sensor is
133 * activated, in which case it must not cause any sensor measurements to
134 * be lost: transitioning from one sampling rate to the other cannot cause
135 * lost events, nor can transitioning from a high maximum report latency to
136 * a low maximum report latency.
137 *
138 * @param sensorHandle handle of sensor to be changed.
139 * @param samplingPeriodNs specifies sensor sample period in nanoseconds.
140 * @param maxReportLatencyNs allowed delay time before an event is sampled
141 * to time of report.
142 * @return result OK on success, BAD_VALUE if any parameters are invalid.
143 */
144 batch(int32_t sensorHandle,
145 int64_t samplingPeriodNs,
146 int64_t maxReportLatencyNs)
147 generates (
148 Result result);
149
150 /**
151 * Trigger a flush of internal FIFO.
152 *
153 * Flush adds a FLUSH_COMPLETE metadata event to the end of the "batch mode"
154 * FIFO for the specified sensor and flushes the FIFO. If the FIFO is empty
155 * or if the sensor doesn't support batching (FIFO size zero), return
156 * SUCCESS and add a trivial FLUSH_COMPLETE event added to the event stream.
157 * This applies to all sensors other than one-shot sensors. If the sensor
158 * is a one-shot sensor, flush must return BAD_VALUE and not generate any
159 * flush complete metadata. If the sensor is not active at the time flush()
160 * is called, flush() return BAD_VALUE.
161 *
162 * @param sensorHandle handle of sensor to be flushed.
163 * @return result OK on success and BAD_VALUE if sensorHandle is invalid.
164 */
165 flush(int32_t sensorHandle) generates (Result result);
166
167 /**
168 * Inject a single sensor event or push operation environment parameters to
169 * device.
170 *
171 * When device is in NORMAL mode, this function is called to push operation
172 * environment data to device. In this operation, Event is always of
173 * SensorType::AdditionalInfo type. See operation evironment parameters
174 * section in AdditionalInfoType.
175 *
176 * When device is in DATA_INJECTION mode, this function is also used for
177 * injecting sensor events.
178 *
179 * Regardless of OperationMode, injected SensorType::ADDITIONAL_INFO
Brian Stack28c675f2018-09-06 09:57:29 -0700180 * type events should not be routed back to the sensor event queue.
Brian Stackee3f7202018-09-05 16:46:28 -0700181 *
182 * @see AdditionalInfoType
183 * @see OperationMode
184 * @param event sensor event to be injected
185 * @return result OK on success; PERMISSION_DENIED if operation is not
186 * allowed; INVALID_OPERATION, if this functionality is unsupported;
187 * BAD_VALUE if sensor event cannot be injected.
188 */
189 injectSensorData(Event event) generates (Result result);
190
191 /**
192 * Register direct report channel.
193 *
194 * Register a direct channel with supplied shared memory information. Upon
195 * return, the sensor hardware is responsible for resetting the memory
196 * content to initial value (depending on memory format settings).
197 *
198 * @param mem shared memory info data structure.
199 * @return result OK on success; BAD_VALUE if shared memory information is
200 * not consistent; NO_MEMORY if shared memory cannot be used by sensor
201 * system; INVALID_OPERATION if functionality is not supported.
202 * @return channelHandle a positive integer used for referencing registered
203 * direct channel (>0) in configureDirectReport and
204 * unregisterDirectChannel if result is OK, -1 otherwise.
205 */
206 registerDirectChannel(SharedMemInfo mem)
207 generates (Result result,
208 int32_t channelHandle);
209
210 /**
211 * Unregister direct report channel.
212 *
213 * Unregister a direct channel previously registered using
214 * registerDirectChannel, and remove all active sensor report configured in
215 * still active sensor report configured in the direct channel.
216 *
217 * @param channelHandle handle of direct channel to be unregistered.
218 * @return result OK if direct report is supported; INVALID_OPERATION
219 * otherwise.
220 */
221 unregisterDirectChannel(int32_t channelHandle) generates (Result result);
222
223 /**
224 * Configure direct sensor event report in direct channel.
225 *
226 * This function start, modify rate or stop direct report of a sensor in a
227 * certain direct channel.
228 *
229 * @param sensorHandle handle of sensor to be configured. When combined
230 * with STOP rate, sensorHandle can be -1 to denote all active sensors
231 * in the direct channel specified by channel Handle.
232 * @param channelHandle handle of direct channel to be configured.
233 * @param rate rate level, see RateLevel enum.
234 * @return result OK on success; BAD_VALUE if parameter is invalid (such as
235 * rate level is not supported by sensor, channelHandle does not exist,
236 * etc); INVALID_OPERATION if functionality is not supported.
237 * @return reportToken positive integer to identify multiple sensors of
238 * the same type in a single direct channel. Ignored if rate is STOP.
239 * See SharedMemFormat.
240 */
241 configDirectReport(
242 int32_t sensorHandle,
243 int32_t channelHandle,
244 RateLevel rate
245 ) generates (
246 Result result,
247 int32_t reportToken);
248};