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