blob: 5c8301aa2638a28d6956a94895f6c4758a37b69b [file] [log] [blame]
Andreas Huberdb49a412016-10-10 13:23:59 -07001/*
2 * Copyright (C) 2016 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@1.0;
18
19interface ISensors {
20 /**
21 * Enumerate all available (static) sensors.
22 */
23 getSensorsList() generates (vec<SensorInfo> list);
24
25 /**
Peng Xu0873e642017-01-08 13:28:10 -080026 * Place the module in a specific mode. The following modes are defined
Andreas Huberdb49a412016-10-10 13:23:59 -070027 *
28 * SENSOR_HAL_NORMAL_MODE - Normal operation. Default state of the module.
29 *
30 * SENSOR_HAL_DATA_INJECTION_MODE - Loopback mode.
31 * Data is injected for the supported sensors by the sensor service in
32 * this mode.
33 *
34 * @return OK on success
35 * BAD_VALUE if requested mode is not supported
36 * PERMISSION_DENIED if operation is not allowed
37 */
38 setOperationMode(OperationMode mode) generates (Result result);
39
40 /* Activate/de-activate one sensor.
41 *
Andreas Huberdb49a412016-10-10 13:23:59 -070042 * After sensor de-activation, existing sensor events that have not
Peng Xu0873e642017-01-08 13:28:10 -080043 * been picked up by poll() must be abandoned immediately so that
Andreas Huberdb49a412016-10-10 13:23:59 -070044 * subsequent activation will not get stale sensor events (events
45 * that are generated prior to the latter activation).
46 *
Peng Xu0873e642017-01-08 13:28:10 -080047 * @param sensorHandle is the handle of the sensor to change.
48 * @param enabled set to true to enable, or false to disable the sensor.
49 *
50 * @return result OK on success, BAD_VALUE if sensorHandle is invalid.
Andreas Huberdb49a412016-10-10 13:23:59 -070051 */
52 activate(int32_t sensorHandle, bool enabled) generates (Result result);
53
54 /**
Andreas Huberdb49a412016-10-10 13:23:59 -070055 * Generate a vector of sensor events containing at most "maxCount"
56 * entries.
57 *
58 * Additionally a vector of SensorInfos is returned for any dynamic sensors
59 * connected as notified by returned events of type DYNAMIC_SENSOR_META.
60 *
Peng Xu0873e642017-01-08 13:28:10 -080061 * If there is no sensor event when this function is being called, block
62 * until there are sensor events available.
Andreas Huberdb49a412016-10-10 13:23:59 -070063 *
Peng Xucefa91b2017-01-16 03:10:40 -080064 * @param maxCount max number of samples can be returned, must be > 0.
65 * Actual number of events returned in data must be <= maxCount
66 * and > 0.
Peng Xu0873e642017-01-08 13:28:10 -080067 * @return result OK on success or BAD_VALUE if maxCount <= 0.
68 * @return data vector of Event contains sensor events.
69 * @return dynamicSensorsAdded vector of SensorInfo contains dynamic sensor
70 * added. Each element corresponds to a dynamic sensor meta events
71 * in data.
Andreas Huberdb49a412016-10-10 13:23:59 -070072 */
73 poll(int32_t maxCount)
74 generates (
75 Result result,
76 vec<Event> data,
77 vec<SensorInfo> dynamicSensorsAdded);
78
79 /*
80 * Sets a sensor’s parameters, including sampling frequency and maximum
81 * report latency. This function can be called while the sensor is
82 * activated, in which case it must not cause any sensor measurements to
83 * be lost: transitioning from one sampling rate to the other cannot cause
84 * lost events, nor can transitioning from a high maximum report latency to
85 * a low maximum report latency.
86 * See the Batching sensor results page for details:
87 * http://source.android.com/devices/sensors/batching.html
88 *
Peng Xu0873e642017-01-08 13:28:10 -080089 * @param sensorHandle handle of sensor to be changed.
90 * @param samplingPeriodNs specifies sensor sample period in nanoseconds.
91 * @param maxReportLatencyNs allowed delay time before an event is sampled
92 * to time of report.
93 * @return result OK on success, BAD_VALUE if any parameters are invalid.
Andreas Huberdb49a412016-10-10 13:23:59 -070094 */
95 batch(int32_t sensorHandle,
Andreas Huberdb49a412016-10-10 13:23:59 -070096 int64_t samplingPeriodNs,
97 int64_t maxReportLatencyNs) generates (Result result);
98
99 /*
Peng Xu0873e642017-01-08 13:28:10 -0800100 * Trigger a flush of internal FIFO.
101 *
Andreas Huberdb49a412016-10-10 13:23:59 -0700102 * Flush adds a FLUSH_COMPLETE metadata event to the end of the "batch mode"
Peng Xu0873e642017-01-08 13:28:10 -0800103 * FIFO for the specified sensor and flushes the FIFO. If the FIFO is empty
104 * or if the sensor doesn't support batching (FIFO size zero), return
105 * SUCCESS and add a trivial FLUSH_COMPLETE event added to the event stream.
106 * This applies to all sensors other than one-shot sensors. If the sensor
107 * is a one-shot sensor, flush must return BAD_VALUE and not generate any
108 * flush complete metadata. If the sensor is not active at the time flush()
109 * is called, flush() return BAD_VALUE.
110 *
111 * @param sensorHandle handle of sensor to be flushed.
112 * @return result OK on success and BAD_VALUE if sensorHandle is invalid.
Andreas Huberdb49a412016-10-10 13:23:59 -0700113 */
114 flush(int32_t sensorHandle) generates (Result result);
115
116 /*
Peng Xue82ec562017-01-06 15:27:09 -0800117 * Inject a single sensor event or push operation environment parameters to
118 * device.
119 *
120 * When device is in NORMAL mode, this function is called to push operation
121 * environment data to device. In this operation, Event is always of
122 * SensorType::AdditionalInfo type. See operation evironment parameters
123 * section in AdditionalInfoType.
124 *
125 * When device is in DATA_INJECTION mode, this function is also used for
126 * injecting sensor events.
127 *
128 * Regardless of OperationMode, injected SensorType::ADDITIONAL_INFO
129 * type events should not be routed back to poll() function.
130 *
131 * @see AdditionalInfoType
132 * @see OperationMode
133 * @param event sensor event to be injected
134 * @return result OK on success; PERMISSION_DENIED if operation is not
135 * allowed; INVALID_OPERATION, if this functionality is
136 * unsupported; BAD_VALUE if sensor event cannot be injected.
Andreas Huberdb49a412016-10-10 13:23:59 -0700137 */
138 injectSensorData(Event event) generates (Result result);
Peng Xu0f0df7e2017-01-05 23:39:08 -0800139
140 /*
141 * Register direct report channel.
142 *
143 * Register a direct channel with supplied shared memory information. Upon
144 * return, the sensor hardware is responsible for resetting the memory
145 * content to initial value (depending on memory format settings).
146 *
147 * @param mem shared memory info data structure.
148 * @return result OK on success; BAD_VALUE if shared memory information is
149 * not consistent; NO_MEMORY if shared memory cannot be used by
150 * sensor system; INVALID_OPERATION if functionality is not
151 * supported.
152 * @return channelHandle a positive integer used for referencing registered
153 * direct channel (>0) in configureDirectReport and
154 * unregisterDirectChannel if result is OK, -1 otherwise.
155 */
156 registerDirectChannel(SharedMemInfo mem)
157 generates (Result result, int32_t channelHandle);
158
159 /*
160 * Unregister direct report channel.
161 *
162 * Unregister a direct channel previously registered using
Peng Xu0873e642017-01-08 13:28:10 -0800163 * registerDirectChannel, and remove all active sensor report configured in
164 * still active sensor report configured in the direct channel.
Peng Xu0f0df7e2017-01-05 23:39:08 -0800165 *
166 * @param channelHandle handle of direct channel to be unregistered.
167 * @return result OK if direct report is supported; INVALID_OPERATION
168 * otherwise.
169 */
170 unregisterDirectChannel(int32_t channelHandle) generates (Result result);
171
172 /*
173 * Configure direct sensor event report in direct channel.
174 *
175 * This function start, modify rate or stop direct report of a sensor in a
176 * certain direct channel.
177 *
178 * @param sensorHandle handle of sensor to be configured. When combined
179 * with STOP rate, sensorHandle can be -1 to denote all active
180 * sensors in the direct channel specified by channel Handle.
181 * @param channelHandle handle of direct channel to be configured.
182 * @param rate rate level, see RateLevel enum.
183 *
184 * @return result OK on success; BAD_VALUE if parameter is invalid (such as
185 * rate level is not supported by sensor, channelHandle does not
186 * exist, etc); INVALID_OPERATION if functionality is not
187 * supported.
188 * @return reportToken positive integer to identify multiple sensors of
189 * the same type in a single direct channel. Ignored if rate is
190 * STOP. See SharedMemFormat.
191 */
192 configDirectReport(
193 int32_t sensorHandle, int32_t channelHandle, RateLevel rate)
194 generates (Result result, int32_t reportToken);
Andreas Huberdb49a412016-10-10 13:23:59 -0700195};