Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.hardware.sensors@1.0; |
| 18 | |
| 19 | interface ISensors { |
| 20 | /** |
| 21 | * Enumerate all available (static) sensors. |
| 22 | */ |
| 23 | getSensorsList() generates (vec<SensorInfo> list); |
| 24 | |
| 25 | /** |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 26 | * Place the module in a specific mode. The following modes are defined |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 27 | * |
| 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 Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 42 | * After sensor de-activation, existing sensor events that have not |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 43 | * been picked up by poll() must be abandoned immediately so that |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 44 | * subsequent activation will not get stale sensor events (events |
| 45 | * that are generated prior to the latter activation). |
| 46 | * |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 47 | * @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 Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 51 | */ |
| 52 | activate(int32_t sensorHandle, bool enabled) generates (Result result); |
| 53 | |
| 54 | /** |
| 55 | * Set the sampling period in nanoseconds for a given sensor. |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 56 | * |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 57 | * If samplingPeriodNs > maxDelay it will be truncated to |
| 58 | * maxDelay and if samplingPeriodNs < minDelay it will be |
| 59 | * replaced by minDelay. |
| 60 | * |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 61 | * @param sensorHandle handle of sensor to be changed. |
| 62 | * @param samplngPeriodNs specified sampling period in nanoseconds. |
| 63 | * @return result OK on success, BAD_VALUE if sensorHandle is invalid. |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 64 | */ |
| 65 | setDelay(int32_t sensorHandle, int64_t samplingPeriodNs) |
| 66 | generates (Result result); |
| 67 | |
| 68 | /** |
| 69 | * Generate a vector of sensor events containing at most "maxCount" |
| 70 | * entries. |
| 71 | * |
| 72 | * Additionally a vector of SensorInfos is returned for any dynamic sensors |
| 73 | * connected as notified by returned events of type DYNAMIC_SENSOR_META. |
| 74 | * |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 75 | * If there is no sensor event when this function is being called, block |
| 76 | * until there are sensor events available. |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 77 | * |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 78 | * @param maxCount max number of samples can be returned. |
| 79 | * @return result OK on success or BAD_VALUE if maxCount <= 0. |
| 80 | * @return data vector of Event contains sensor events. |
| 81 | * @return dynamicSensorsAdded vector of SensorInfo contains dynamic sensor |
| 82 | * added. Each element corresponds to a dynamic sensor meta events |
| 83 | * in data. |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 84 | */ |
| 85 | poll(int32_t maxCount) |
| 86 | generates ( |
| 87 | Result result, |
| 88 | vec<Event> data, |
| 89 | vec<SensorInfo> dynamicSensorsAdded); |
| 90 | |
| 91 | /* |
| 92 | * Sets a sensor’s parameters, including sampling frequency and maximum |
| 93 | * report latency. This function can be called while the sensor is |
| 94 | * activated, in which case it must not cause any sensor measurements to |
| 95 | * be lost: transitioning from one sampling rate to the other cannot cause |
| 96 | * lost events, nor can transitioning from a high maximum report latency to |
| 97 | * a low maximum report latency. |
| 98 | * See the Batching sensor results page for details: |
| 99 | * http://source.android.com/devices/sensors/batching.html |
| 100 | * |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 101 | * @param sensorHandle handle of sensor to be changed. |
| 102 | * @param samplingPeriodNs specifies sensor sample period in nanoseconds. |
| 103 | * @param maxReportLatencyNs allowed delay time before an event is sampled |
| 104 | * to time of report. |
| 105 | * @return result OK on success, BAD_VALUE if any parameters are invalid. |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 106 | */ |
| 107 | batch(int32_t sensorHandle, |
| 108 | int32_t flags, |
| 109 | int64_t samplingPeriodNs, |
| 110 | int64_t maxReportLatencyNs) generates (Result result); |
| 111 | |
| 112 | /* |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 113 | * Trigger a flush of internal FIFO. |
| 114 | * |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 115 | * Flush adds a FLUSH_COMPLETE metadata event to the end of the "batch mode" |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 116 | * FIFO for the specified sensor and flushes the FIFO. If the FIFO is empty |
| 117 | * or if the sensor doesn't support batching (FIFO size zero), return |
| 118 | * SUCCESS and add a trivial FLUSH_COMPLETE event added to the event stream. |
| 119 | * This applies to all sensors other than one-shot sensors. If the sensor |
| 120 | * is a one-shot sensor, flush must return BAD_VALUE and not generate any |
| 121 | * flush complete metadata. If the sensor is not active at the time flush() |
| 122 | * is called, flush() return BAD_VALUE. |
| 123 | * |
| 124 | * @param sensorHandle handle of sensor to be flushed. |
| 125 | * @return result OK on success and BAD_VALUE if sensorHandle is invalid. |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 126 | */ |
| 127 | flush(int32_t sensorHandle) generates (Result result); |
| 128 | |
| 129 | /* |
| 130 | * Inject a single sensor sample to this device. |
| 131 | * data points to the sensor event to be injected |
| 132 | * Returns OK on success |
| 133 | * PERMISSION_DENIED if operation is not allowed |
| 134 | * INVALID_OPERATION, if this functionality is unsupported |
| 135 | * BAD_VALUE if sensor event cannot be injected |
| 136 | */ |
| 137 | injectSensorData(Event event) generates (Result result); |
Peng Xu | 0f0df7e | 2017-01-05 23:39:08 -0800 | [diff] [blame] | 138 | |
| 139 | /* |
| 140 | * Register direct report channel. |
| 141 | * |
| 142 | * Register a direct channel with supplied shared memory information. Upon |
| 143 | * return, the sensor hardware is responsible for resetting the memory |
| 144 | * content to initial value (depending on memory format settings). |
| 145 | * |
| 146 | * @param mem shared memory info data structure. |
| 147 | * @return result OK on success; BAD_VALUE if shared memory information is |
| 148 | * not consistent; NO_MEMORY if shared memory cannot be used by |
| 149 | * sensor system; INVALID_OPERATION if functionality is not |
| 150 | * supported. |
| 151 | * @return channelHandle a positive integer used for referencing registered |
| 152 | * direct channel (>0) in configureDirectReport and |
| 153 | * unregisterDirectChannel if result is OK, -1 otherwise. |
| 154 | */ |
| 155 | registerDirectChannel(SharedMemInfo mem) |
| 156 | generates (Result result, int32_t channelHandle); |
| 157 | |
| 158 | /* |
| 159 | * Unregister direct report channel. |
| 160 | * |
| 161 | * Unregister a direct channel previously registered using |
Peng Xu | 0873e64 | 2017-01-08 13:28:10 -0800 | [diff] [blame] | 162 | * registerDirectChannel, and remove all active sensor report configured in |
| 163 | * still active sensor report configured in the direct channel. |
Peng Xu | 0f0df7e | 2017-01-05 23:39:08 -0800 | [diff] [blame] | 164 | * |
| 165 | * @param channelHandle handle of direct channel to be unregistered. |
| 166 | * @return result OK if direct report is supported; INVALID_OPERATION |
| 167 | * otherwise. |
| 168 | */ |
| 169 | unregisterDirectChannel(int32_t channelHandle) generates (Result result); |
| 170 | |
| 171 | /* |
| 172 | * Configure direct sensor event report in direct channel. |
| 173 | * |
| 174 | * This function start, modify rate or stop direct report of a sensor in a |
| 175 | * certain direct channel. |
| 176 | * |
| 177 | * @param sensorHandle handle of sensor to be configured. When combined |
| 178 | * with STOP rate, sensorHandle can be -1 to denote all active |
| 179 | * sensors in the direct channel specified by channel Handle. |
| 180 | * @param channelHandle handle of direct channel to be configured. |
| 181 | * @param rate rate level, see RateLevel enum. |
| 182 | * |
| 183 | * @return result OK on success; BAD_VALUE if parameter is invalid (such as |
| 184 | * rate level is not supported by sensor, channelHandle does not |
| 185 | * exist, etc); INVALID_OPERATION if functionality is not |
| 186 | * supported. |
| 187 | * @return reportToken positive integer to identify multiple sensors of |
| 188 | * the same type in a single direct channel. Ignored if rate is |
| 189 | * STOP. See SharedMemFormat. |
| 190 | */ |
| 191 | configDirectReport( |
| 192 | int32_t sensorHandle, int32_t channelHandle, RateLevel rate) |
| 193 | generates (Result result, int32_t reportToken); |
Andreas Huber | db49a41 | 2016-10-10 13:23:59 -0700 | [diff] [blame] | 194 | }; |