Brian Stack | ee3f720 | 2018-09-05 16:46:28 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.hardware.sensors@2.0; |
| 18 | |
| 19 | import @1.0::Event; |
| 20 | import @1.0::OperationMode; |
| 21 | import @1.0::RateLevel; |
| 22 | import @1.0::Result; |
| 23 | import @1.0::SensorInfo; |
| 24 | import @1.0::SharedMemInfo; |
Brian Stack | 78aa4fc | 2018-09-18 13:45:36 -0700 | [diff] [blame] | 25 | import @2.0::ISensorsCallback; |
Brian Stack | ee3f720 | 2018-09-05 16:46:28 -0700 | [diff] [blame] | 26 | |
| 27 | interface ISensors { |
| 28 | /** |
| 29 | * Enumerate all available (static) sensors. |
Brian Stack | 7ff9564 | 2018-10-01 16:06:39 -0700 | [diff] [blame] | 30 | * |
| 31 | * The SensorInfo for each sensor returned by getSensorsList must be stable |
| 32 | * from the initial call to getSensorsList after a device boot until the |
| 33 | * entire system restarts. The SensorInfo for each sensor must not change |
| 34 | * between subsequent calls to getSensorsList, even across restarts of the |
| 35 | * HAL and its dependencies (for example, the sensor handle for a given |
| 36 | * sensor must not change across HAL restarts). |
Brian Stack | ee3f720 | 2018-09-05 16:46:28 -0700 | [diff] [blame] | 37 | */ |
| 38 | getSensorsList() generates (vec<SensorInfo> list); |
| 39 | |
| 40 | /** |
| 41 | * Place the module in a specific mode. The following modes are defined |
| 42 | * |
| 43 | * SENSOR_HAL_NORMAL_MODE - Normal operation. Default state of the module. |
| 44 | * |
| 45 | * SENSOR_HAL_DATA_INJECTION_MODE - Loopback mode. |
| 46 | * Data is injected for the supported sensors by the sensor service in |
| 47 | * this mode. |
| 48 | * |
| 49 | * @return OK on success |
| 50 | * BAD_VALUE if requested mode is not supported |
| 51 | * PERMISSION_DENIED if operation is not allowed |
| 52 | */ |
| 53 | setOperationMode(OperationMode mode) generates (Result result); |
| 54 | |
| 55 | /** |
| 56 | * Activate/de-activate one sensor. |
| 57 | * |
| 58 | * After sensor de-activation, existing sensor events that have not |
Brian Stack | 28c675f | 2018-09-06 09:57:29 -0700 | [diff] [blame] | 59 | * been written to the event queue must be abandoned immediately so that |
Brian Stack | ee3f720 | 2018-09-05 16:46:28 -0700 | [diff] [blame] | 60 | * subsequent activations do not get stale sensor events (events |
| 61 | * that are generated prior to the latter activation). |
| 62 | * |
| 63 | * @param sensorHandle is the handle of the sensor to change. |
| 64 | * @param enabled set to true to enable, or false to disable the sensor. |
| 65 | * @return result OK on success, BAD_VALUE if sensorHandle is invalid. |
| 66 | */ |
| 67 | activate(int32_t sensorHandle, bool enabled) generates (Result result); |
| 68 | |
| 69 | /** |
Brian Stack | 78aa4fc | 2018-09-18 13:45:36 -0700 | [diff] [blame] | 70 | * Initialize the Sensors HAL's Fast Message Queues (FMQ) and callback. |
| 71 | * |
| 72 | * The Fast Message Queues (FMQ) that are used to send data between the |
| 73 | * framework and the HAL. The callback is used by the HAL to notify the |
| 74 | * framework of asynchronous events, such as a dynamic sensor connection. |
Brian Stack | ee3f720 | 2018-09-05 16:46:28 -0700 | [diff] [blame] | 75 | * |
Brian Stack | 28c675f | 2018-09-06 09:57:29 -0700 | [diff] [blame] | 76 | * The Event FMQ is used to transport sensor events from the HAL to the |
| 77 | * framework. The Event FMQ is created using the eventQueueDescriptor. |
| 78 | * Data may only be written to the Event FMQ. Data must not be read from |
| 79 | * the Event FMQ since the framework is the only reader. Upon receiving |
Brian Stack | 6e4a220 | 2018-12-11 13:39:07 -0800 | [diff] [blame] | 80 | * sensor events, the HAL writes the sensor events to the Event FMQ. |
| 81 | * |
Brian Stack | 1f0c5ea | 2018-09-18 16:04:09 -0700 | [diff] [blame] | 82 | * Once the HAL is finished writing sensor events to the Event FMQ, the HAL |
Brian Stack | 6e4a220 | 2018-12-11 13:39:07 -0800 | [diff] [blame] | 83 | * must notify the framework that sensor events are available to be read and |
| 84 | * processed. This is accomplished by either: |
| 85 | * 1) Calling the Event FMQ’s EventFlag::wake() function with |
| 86 | EventQueueFlagBits::READ_AND_PROCESS |
| 87 | * 2) Setting the write notification in the Event FMQ’s writeBlocking() |
| 88 | * function to EventQueueFlagBits::READ_AND_PROCESS. |
| 89 | * |
| 90 | * If the Event FMQ’s writeBlocking() function is used, the read |
| 91 | * notification must be set to EventQueueFlagBits::EVENTS_READ in order to |
| 92 | * be notified and unblocked when the framework has successfully read events |
| 93 | * from the Event FMQ. |
Brian Stack | ee3f720 | 2018-09-05 16:46:28 -0700 | [diff] [blame] | 94 | * |
Brian Stack | 28c675f | 2018-09-06 09:57:29 -0700 | [diff] [blame] | 95 | * The Wake Lock FMQ is used by the framework to notify the HAL when it is |
| 96 | * safe to release its wake_lock. When the framework receives WAKE_UP events |
| 97 | * from the Event FMQ and the framework has acquired a wake_lock, the |
Brian Stack | 2c31336 | 2019-01-08 13:09:49 -0800 | [diff] [blame] | 98 | * framework must write the number of WAKE_UP events processed to the Wake |
| 99 | * Lock FMQ. When the HAL reads the data from the Wake Lock FMQ, the HAL |
| 100 | * decrements its current count of unprocessed WAKE_UP events and releases |
| 101 | * its wake_lock if the current count of unprocessed WAKE_UP events is |
| 102 | * zero. |
| 103 | * |
| 104 | * The framework must use the WakeLockQueueFlagBits::DATA_WRITTEN value to |
| 105 | * notify the HAL that data has been written to the Wake Lock FMQ and must |
| 106 | * be read by HAL. |
Brian Stack | ee3f720 | 2018-09-05 16:46:28 -0700 | [diff] [blame] | 107 | * |
Brian Stack | 78aa4fc | 2018-09-18 13:45:36 -0700 | [diff] [blame] | 108 | * The ISensorsCallback is used by the HAL to notify the framework of |
| 109 | * asynchronous events, such as a dynamic sensor connection. |
| 110 | * |
Brian Stack | 28c675f | 2018-09-06 09:57:29 -0700 | [diff] [blame] | 111 | * The name of any wake_lock acquired by the Sensors HAL for WAKE_UP events |
| 112 | * must begin with "SensorsHAL_WAKEUP". |
| 113 | * |
| 114 | * If WAKE_LOCK_TIMEOUT_SECONDS has elapsed since the most recent WAKE_UP |
| 115 | * event was written to the Event FMQ without receiving a message on the |
| 116 | * Wake Lock FMQ, then any held wake_lock for WAKE_UP events must be |
| 117 | * released. |
| 118 | * |
| 119 | * If either the Event FMQ or the Wake Lock FMQ is already initialized when |
Brian Stack | 78aa4fc | 2018-09-18 13:45:36 -0700 | [diff] [blame] | 120 | * initialize is invoked, then both existing FMQs must be discarded and the |
| 121 | * new descriptors must be used to create new FMQs within the HAL. The |
| 122 | * number of outstanding WAKE_UP events should also be reset to zero, and |
| 123 | * any outstanding wake_locks held as a result of WAKE_UP events should be |
| 124 | * released. |
Brian Stack | 28c675f | 2018-09-06 09:57:29 -0700 | [diff] [blame] | 125 | * |
Brian Stack | 6e4a220 | 2018-12-11 13:39:07 -0800 | [diff] [blame] | 126 | * All active sensor requests and direct channels must be closed and |
| 127 | * properly cleaned up when initialize is called in order to ensure that the |
| 128 | * HAL and framework's state is consistent (e.g. after a runtime restart). |
| 129 | * |
Brian Stack | 78aa4fc | 2018-09-18 13:45:36 -0700 | [diff] [blame] | 130 | * initialize must be thread safe and prevent concurrent calls |
| 131 | * to initialize from simultaneously modifying state. |
Brian Stack | 28c675f | 2018-09-06 09:57:29 -0700 | [diff] [blame] | 132 | * |
| 133 | * @param eventQueueDescriptor Fast Message Queue descriptor that is used to |
| 134 | * create the Event FMQ which is where sensor events are written. The |
| 135 | * descriptor is obtained from the framework's FMQ that is used to read |
| 136 | * sensor events. |
| 137 | * @param wakeLockDescriptor Fast Message Queue descriptor that is used to |
| 138 | * create the Wake Lock FMQ which is where wake_lock events are read |
| 139 | * from. The descriptor is obtained from the framework's FMQ that is |
| 140 | * used to write wake_lock events. |
Brian Stack | 78aa4fc | 2018-09-18 13:45:36 -0700 | [diff] [blame] | 141 | * @param sensorsCallback sensors callback that receives asynchronous data |
| 142 | * from the Sensors HAL. |
Brian Stack | 28c675f | 2018-09-06 09:57:29 -0700 | [diff] [blame] | 143 | * @return result OK on success; BAD_VALUE if descriptor is invalid (such |
| 144 | * as null) |
Brian Stack | ee3f720 | 2018-09-05 16:46:28 -0700 | [diff] [blame] | 145 | */ |
Brian Stack | 28c675f | 2018-09-06 09:57:29 -0700 | [diff] [blame] | 146 | @entry |
| 147 | @callflow(next = {"getSensorsList"}) |
Brian Stack | 78aa4fc | 2018-09-18 13:45:36 -0700 | [diff] [blame] | 148 | initialize(fmq_sync<Event> eventQueueDescriptor, |
| 149 | fmq_sync<uint32_t> wakeLockDescriptor, |
| 150 | ISensorsCallback sensorsCallback) |
| 151 | generates |
| 152 | (Result result); |
Brian Stack | ee3f720 | 2018-09-05 16:46:28 -0700 | [diff] [blame] | 153 | |
| 154 | /** |
| 155 | * Sets a sensor’s parameters, including sampling frequency and maximum |
| 156 | * report latency. This function can be called while the sensor is |
| 157 | * activated, in which case it must not cause any sensor measurements to |
| 158 | * be lost: transitioning from one sampling rate to the other cannot cause |
| 159 | * lost events, nor can transitioning from a high maximum report latency to |
| 160 | * a low maximum report latency. |
| 161 | * |
| 162 | * @param sensorHandle handle of sensor to be changed. |
| 163 | * @param samplingPeriodNs specifies sensor sample period in nanoseconds. |
| 164 | * @param maxReportLatencyNs allowed delay time before an event is sampled |
| 165 | * to time of report. |
| 166 | * @return result OK on success, BAD_VALUE if any parameters are invalid. |
| 167 | */ |
| 168 | batch(int32_t sensorHandle, |
| 169 | int64_t samplingPeriodNs, |
| 170 | int64_t maxReportLatencyNs) |
| 171 | generates ( |
| 172 | Result result); |
| 173 | |
| 174 | /** |
| 175 | * Trigger a flush of internal FIFO. |
| 176 | * |
| 177 | * Flush adds a FLUSH_COMPLETE metadata event to the end of the "batch mode" |
| 178 | * FIFO for the specified sensor and flushes the FIFO. If the FIFO is empty |
| 179 | * or if the sensor doesn't support batching (FIFO size zero), return |
| 180 | * SUCCESS and add a trivial FLUSH_COMPLETE event added to the event stream. |
| 181 | * This applies to all sensors other than one-shot sensors. If the sensor |
| 182 | * is a one-shot sensor, flush must return BAD_VALUE and not generate any |
| 183 | * flush complete metadata. If the sensor is not active at the time flush() |
| 184 | * is called, flush() return BAD_VALUE. |
| 185 | * |
| 186 | * @param sensorHandle handle of sensor to be flushed. |
| 187 | * @return result OK on success and BAD_VALUE if sensorHandle is invalid. |
| 188 | */ |
| 189 | flush(int32_t sensorHandle) generates (Result result); |
| 190 | |
| 191 | /** |
| 192 | * Inject a single sensor event or push operation environment parameters to |
| 193 | * device. |
| 194 | * |
| 195 | * When device is in NORMAL mode, this function is called to push operation |
| 196 | * environment data to device. In this operation, Event is always of |
| 197 | * SensorType::AdditionalInfo type. See operation evironment parameters |
| 198 | * section in AdditionalInfoType. |
| 199 | * |
| 200 | * When device is in DATA_INJECTION mode, this function is also used for |
| 201 | * injecting sensor events. |
| 202 | * |
| 203 | * Regardless of OperationMode, injected SensorType::ADDITIONAL_INFO |
Brian Stack | 28c675f | 2018-09-06 09:57:29 -0700 | [diff] [blame] | 204 | * type events should not be routed back to the sensor event queue. |
Brian Stack | ee3f720 | 2018-09-05 16:46:28 -0700 | [diff] [blame] | 205 | * |
| 206 | * @see AdditionalInfoType |
| 207 | * @see OperationMode |
| 208 | * @param event sensor event to be injected |
| 209 | * @return result OK on success; PERMISSION_DENIED if operation is not |
| 210 | * allowed; INVALID_OPERATION, if this functionality is unsupported; |
| 211 | * BAD_VALUE if sensor event cannot be injected. |
| 212 | */ |
| 213 | injectSensorData(Event event) generates (Result result); |
| 214 | |
| 215 | /** |
| 216 | * Register direct report channel. |
| 217 | * |
| 218 | * Register a direct channel with supplied shared memory information. Upon |
| 219 | * return, the sensor hardware is responsible for resetting the memory |
| 220 | * content to initial value (depending on memory format settings). |
| 221 | * |
| 222 | * @param mem shared memory info data structure. |
| 223 | * @return result OK on success; BAD_VALUE if shared memory information is |
| 224 | * not consistent; NO_MEMORY if shared memory cannot be used by sensor |
| 225 | * system; INVALID_OPERATION if functionality is not supported. |
| 226 | * @return channelHandle a positive integer used for referencing registered |
| 227 | * direct channel (>0) in configureDirectReport and |
| 228 | * unregisterDirectChannel if result is OK, -1 otherwise. |
| 229 | */ |
| 230 | registerDirectChannel(SharedMemInfo mem) |
| 231 | generates (Result result, |
| 232 | int32_t channelHandle); |
| 233 | |
| 234 | /** |
| 235 | * Unregister direct report channel. |
| 236 | * |
| 237 | * Unregister a direct channel previously registered using |
| 238 | * registerDirectChannel, and remove all active sensor report configured in |
| 239 | * still active sensor report configured in the direct channel. |
| 240 | * |
| 241 | * @param channelHandle handle of direct channel to be unregistered. |
| 242 | * @return result OK if direct report is supported; INVALID_OPERATION |
| 243 | * otherwise. |
| 244 | */ |
| 245 | unregisterDirectChannel(int32_t channelHandle) generates (Result result); |
| 246 | |
| 247 | /** |
| 248 | * Configure direct sensor event report in direct channel. |
| 249 | * |
| 250 | * This function start, modify rate or stop direct report of a sensor in a |
| 251 | * certain direct channel. |
| 252 | * |
| 253 | * @param sensorHandle handle of sensor to be configured. When combined |
| 254 | * with STOP rate, sensorHandle can be -1 to denote all active sensors |
| 255 | * in the direct channel specified by channel Handle. |
| 256 | * @param channelHandle handle of direct channel to be configured. |
| 257 | * @param rate rate level, see RateLevel enum. |
| 258 | * @return result OK on success; BAD_VALUE if parameter is invalid (such as |
| 259 | * rate level is not supported by sensor, channelHandle does not exist, |
| 260 | * etc); INVALID_OPERATION if functionality is not supported. |
| 261 | * @return reportToken positive integer to identify multiple sensors of |
| 262 | * the same type in a single direct channel. Ignored if rate is STOP. |
| 263 | * See SharedMemFormat. |
| 264 | */ |
| 265 | configDirectReport( |
| 266 | int32_t sensorHandle, |
| 267 | int32_t channelHandle, |
| 268 | RateLevel rate |
| 269 | ) generates ( |
| 270 | Result result, |
| 271 | int32_t reportToken); |
| 272 | }; |