blob: 6df454d4fd44e3d370248d943807799a9df8d236 [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
51 * been picked up by poll() must be abandoned immediately so that
52 * 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 /**
62 * Generate a vector of sensor events containing at most "maxCount"
63 * entries.
64 *
65 * Additionally a vector of SensorInfos is returned for any dynamic sensors
66 * connected as notified by returned events of type DYNAMIC_SENSOR_META.
67 *
68 * If there is no sensor event when this function is being called, block
69 * until there are sensor events available.
70 *
71 * @param maxCount max number of samples can be returned, must be > 0.
72 * Actual number of events returned in data must be <= maxCount and > 0
73 * @return result OK on success or BAD_VALUE if maxCount <= 0.
74 * @return data vector of Event contains sensor events.
75 * @return dynamicSensorsAdded vector of SensorInfo contains dynamic sensor
76 * added. Each element corresponds to a dynamic sensor meta events in
77 * data.
78 */
79 poll(int32_t maxCount)
80 generates (
81 Result result,
82 vec<Event> data,
83 vec<SensorInfo> dynamicSensorsAdded);
84
85 /**
86 * Sets a sensor’s parameters, including sampling frequency and maximum
87 * report latency. This function can be called while the sensor is
88 * activated, in which case it must not cause any sensor measurements to
89 * be lost: transitioning from one sampling rate to the other cannot cause
90 * lost events, nor can transitioning from a high maximum report latency to
91 * a low maximum report latency.
92 *
93 * @param sensorHandle handle of sensor to be changed.
94 * @param samplingPeriodNs specifies sensor sample period in nanoseconds.
95 * @param maxReportLatencyNs allowed delay time before an event is sampled
96 * to time of report.
97 * @return result OK on success, BAD_VALUE if any parameters are invalid.
98 */
99 batch(int32_t sensorHandle,
100 int64_t samplingPeriodNs,
101 int64_t maxReportLatencyNs)
102 generates (
103 Result result);
104
105 /**
106 * Trigger a flush of internal FIFO.
107 *
108 * Flush adds a FLUSH_COMPLETE metadata event to the end of the "batch mode"
109 * FIFO for the specified sensor and flushes the FIFO. If the FIFO is empty
110 * or if the sensor doesn't support batching (FIFO size zero), return
111 * SUCCESS and add a trivial FLUSH_COMPLETE event added to the event stream.
112 * This applies to all sensors other than one-shot sensors. If the sensor
113 * is a one-shot sensor, flush must return BAD_VALUE and not generate any
114 * flush complete metadata. If the sensor is not active at the time flush()
115 * is called, flush() return BAD_VALUE.
116 *
117 * @param sensorHandle handle of sensor to be flushed.
118 * @return result OK on success and BAD_VALUE if sensorHandle is invalid.
119 */
120 flush(int32_t sensorHandle) generates (Result result);
121
122 /**
123 * Inject a single sensor event or push operation environment parameters to
124 * device.
125 *
126 * When device is in NORMAL mode, this function is called to push operation
127 * environment data to device. In this operation, Event is always of
128 * SensorType::AdditionalInfo type. See operation evironment parameters
129 * section in AdditionalInfoType.
130 *
131 * When device is in DATA_INJECTION mode, this function is also used for
132 * injecting sensor events.
133 *
134 * Regardless of OperationMode, injected SensorType::ADDITIONAL_INFO
135 * type events should not be routed back to poll() function.
136 *
137 * @see AdditionalInfoType
138 * @see OperationMode
139 * @param event sensor event to be injected
140 * @return result OK on success; PERMISSION_DENIED if operation is not
141 * allowed; INVALID_OPERATION, if this functionality is unsupported;
142 * BAD_VALUE if sensor event cannot be injected.
143 */
144 injectSensorData(Event event) generates (Result result);
145
146 /**
147 * Register direct report channel.
148 *
149 * Register a direct channel with supplied shared memory information. Upon
150 * return, the sensor hardware is responsible for resetting the memory
151 * content to initial value (depending on memory format settings).
152 *
153 * @param mem shared memory info data structure.
154 * @return result OK on success; BAD_VALUE if shared memory information is
155 * not consistent; NO_MEMORY if shared memory cannot be used by sensor
156 * system; INVALID_OPERATION if functionality is not supported.
157 * @return channelHandle a positive integer used for referencing registered
158 * direct channel (>0) in configureDirectReport and
159 * unregisterDirectChannel if result is OK, -1 otherwise.
160 */
161 registerDirectChannel(SharedMemInfo mem)
162 generates (Result result,
163 int32_t channelHandle);
164
165 /**
166 * Unregister direct report channel.
167 *
168 * Unregister a direct channel previously registered using
169 * registerDirectChannel, and remove all active sensor report configured in
170 * still active sensor report configured in the direct channel.
171 *
172 * @param channelHandle handle of direct channel to be unregistered.
173 * @return result OK if direct report is supported; INVALID_OPERATION
174 * otherwise.
175 */
176 unregisterDirectChannel(int32_t channelHandle) generates (Result result);
177
178 /**
179 * Configure direct sensor event report in direct channel.
180 *
181 * This function start, modify rate or stop direct report of a sensor in a
182 * certain direct channel.
183 *
184 * @param sensorHandle handle of sensor to be configured. When combined
185 * with STOP rate, sensorHandle can be -1 to denote all active sensors
186 * in the direct channel specified by channel Handle.
187 * @param channelHandle handle of direct channel to be configured.
188 * @param rate rate level, see RateLevel enum.
189 * @return result OK on success; BAD_VALUE if parameter is invalid (such as
190 * rate level is not supported by sensor, channelHandle does not exist,
191 * etc); INVALID_OPERATION if functionality is not supported.
192 * @return reportToken positive integer to identify multiple sensors of
193 * the same type in a single direct channel. Ignored if rate is STOP.
194 * See SharedMemFormat.
195 */
196 configDirectReport(
197 int32_t sensorHandle,
198 int32_t channelHandle,
199 RateLevel rate
200 ) generates (
201 Result result,
202 int32_t reportToken);
203};