Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | #define LOG_TAG "sensor" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include <android/looper.h> |
| 21 | #include <android/sensor.h> |
Peng Xu | 3b17017 | 2017-02-15 23:25:21 -0800 | [diff] [blame] | 22 | #include <android/sharedmem.h> |
| 23 | #include <cutils/native_handle.h> |
Mathias Agopian | caf8930 | 2017-03-06 16:06:49 -0800 | [diff] [blame] | 24 | #include <sensor/Sensor.h> |
| 25 | #include <sensor/SensorManager.h> |
| 26 | #include <sensor/SensorEventQueue.h> |
Peng Xu | 3b17017 | 2017-02-15 23:25:21 -0800 | [diff] [blame] | 27 | #include <utils/Looper.h> |
| 28 | #include <utils/RefBase.h> |
| 29 | #include <utils/Timers.h> |
Jesse Hall | 5f73ab7 | 2017-04-17 08:54:43 -0700 | [diff] [blame] | 30 | #include <vndk/hardware_buffer.h> |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 31 | |
| 32 | #include <poll.h> |
| 33 | |
| 34 | using android::sp; |
| 35 | using android::Sensor; |
| 36 | using android::SensorManager; |
| 37 | using android::SensorEventQueue; |
| 38 | using android::String8; |
Svet Ganov | cbb56a8 | 2015-05-07 10:49:07 -0700 | [diff] [blame] | 39 | using android::String16; |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 40 | |
| 41 | /*****************************************************************************/ |
Peng Xu | 3b17017 | 2017-02-15 23:25:21 -0800 | [diff] [blame] | 42 | #define ERROR_INVALID_PARAMETER(message) ALOGE("%s: " message, __func__) |
| 43 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 44 | // frequently used checks |
Peng Xu | 3b17017 | 2017-02-15 23:25:21 -0800 | [diff] [blame] | 45 | #define RETURN_IF_MANAGER_IS_NULL(retval) do {\ |
| 46 | if (manager == nullptr) { \ |
| 47 | ERROR_INVALID_PARAMETER("manager cannot be NULL"); \ |
| 48 | return retval; \ |
| 49 | } \ |
| 50 | } while (false) |
| 51 | #define RETURN_IF_SENSOR_IS_NULL(retval) do {\ |
| 52 | if (sensor == nullptr) { \ |
| 53 | ERROR_INVALID_PARAMETER("sensor cannot be NULL"); \ |
| 54 | return retval; \ |
| 55 | } \ |
| 56 | } while (false) |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 57 | #define RETURN_IF_QUEUE_IS_NULL(retval) do {\ |
| 58 | if (queue == nullptr) { \ |
| 59 | ERROR_INVALID_PARAMETER("queue cannot be NULL"); \ |
| 60 | return retval; \ |
| 61 | } \ |
| 62 | } while (false) |
Peng Xu | 3b17017 | 2017-02-15 23:25:21 -0800 | [diff] [blame] | 63 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 64 | ASensorManager* ASensorManager_getInstance() { |
| 65 | return ASensorManager_getInstanceForPackage(nullptr); |
Svet Ganov | cbb56a8 | 2015-05-07 10:49:07 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 68 | ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) { |
Svet Ganov | cbb56a8 | 2015-05-07 10:49:07 -0700 | [diff] [blame] | 69 | if (packageName) { |
| 70 | return &SensorManager::getInstanceForPackage(String16(packageName)); |
| 71 | } else { |
| 72 | return &SensorManager::getInstanceForPackage(String16()); |
| 73 | } |
| 74 | } |
| 75 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 76 | int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list) { |
| 77 | RETURN_IF_MANAGER_IS_NULL(android::BAD_VALUE); |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 78 | Sensor const* const* l; |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 79 | int c = static_cast<SensorManager*>(manager)->getSensorList(&l); |
| 80 | if (list) { |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 81 | *list = reinterpret_cast<ASensorList>(l); |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 82 | } |
| 83 | return c; |
| 84 | } |
| 85 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 86 | ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type) { |
| 87 | RETURN_IF_MANAGER_IS_NULL(nullptr); |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 88 | return static_cast<SensorManager*>(manager)->getDefaultSensor(type); |
| 89 | } |
| 90 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 91 | ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp) { |
| 92 | RETURN_IF_MANAGER_IS_NULL(nullptr); |
Aravind Akella | 99fe165 | 2014-08-05 15:02:11 -0700 | [diff] [blame] | 93 | Sensor const* const* sensorList; |
| 94 | size_t size = static_cast<SensorManager*>(manager)->getSensorList(&sensorList); |
| 95 | for (size_t i = 0; i < size; ++i) { |
| 96 | if (ASensor_getType(sensorList[i]) == type && |
| 97 | ASensor_isWakeUpSensor(sensorList[i]) == wakeUp) { |
| 98 | return reinterpret_cast<ASensor const *>(sensorList[i]); |
| 99 | } |
| 100 | } |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 101 | return nullptr; |
Aravind Akella | 99fe165 | 2014-08-05 15:02:11 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 104 | ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager, |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 105 | ALooper* looper, int ident, ALooper_callbackFunc callback, void* data) { |
| 106 | RETURN_IF_MANAGER_IS_NULL(nullptr); |
| 107 | |
| 108 | if (looper == nullptr) { |
| 109 | ERROR_INVALID_PARAMETER("looper cannot be NULL"); |
| 110 | return nullptr; |
| 111 | } |
| 112 | |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 113 | sp<SensorEventQueue> queue = |
| 114 | static_cast<SensorManager*>(manager)->createEventQueue(); |
| 115 | if (queue != 0) { |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 116 | ALooper_addFd(looper, queue->getFd(), ident, ALOOPER_EVENT_INPUT, callback, data); |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 117 | queue->looper = looper; |
| 118 | queue->incStrong(manager); |
| 119 | } |
| 120 | return static_cast<ASensorEventQueue*>(queue.get()); |
| 121 | } |
| 122 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 123 | int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue) { |
| 124 | RETURN_IF_MANAGER_IS_NULL(android::BAD_VALUE); |
| 125 | RETURN_IF_QUEUE_IS_NULL(android::BAD_VALUE); |
| 126 | |
| 127 | sp<SensorEventQueue> q = static_cast<SensorEventQueue*>(queue); |
| 128 | ALooper_removeFd(q->looper, q->getFd()); |
| 129 | q->decStrong(manager); |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 133 | int ASensorManager_createSharedMemoryDirectChannel(ASensorManager *manager, int fd, size_t size) { |
Peng Xu | 3b17017 | 2017-02-15 23:25:21 -0800 | [diff] [blame] | 134 | RETURN_IF_MANAGER_IS_NULL(android::BAD_VALUE); |
| 135 | |
| 136 | if (fd < 0) { |
| 137 | ERROR_INVALID_PARAMETER("fd is invalid."); |
| 138 | return android::BAD_VALUE; |
| 139 | } |
| 140 | |
| 141 | if (size < sizeof(ASensorEvent)) { |
| 142 | ERROR_INVALID_PARAMETER("size has to be greater or equal to sizeof(ASensorEvent)."); |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 143 | return android::BAD_VALUE; |
Peng Xu | 3b17017 | 2017-02-15 23:25:21 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | native_handle_t *resourceHandle = native_handle_create(1 /* nFd */, 0 /* nInt */); |
| 147 | if (!resourceHandle) { |
| 148 | return android::NO_MEMORY; |
| 149 | } |
| 150 | |
| 151 | resourceHandle->data[0] = fd; |
| 152 | int ret = static_cast<SensorManager *>(manager)->createDirectChannel( |
| 153 | size, ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY, resourceHandle); |
| 154 | native_handle_delete(resourceHandle); |
| 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | int ASensorManager_createHardwareBufferDirectChannel( |
| 159 | ASensorManager *manager, AHardwareBuffer const *buffer, size_t size) { |
| 160 | RETURN_IF_MANAGER_IS_NULL(android::BAD_VALUE); |
| 161 | |
| 162 | if (buffer == nullptr) { |
| 163 | ERROR_INVALID_PARAMETER("buffer cannot be NULL"); |
| 164 | return android::BAD_VALUE; |
| 165 | } |
| 166 | |
| 167 | if (size < sizeof(ASensorEvent)) { |
| 168 | ERROR_INVALID_PARAMETER("size has to be greater or equal to sizeof(ASensorEvent)."); |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 169 | return android::BAD_VALUE; |
Peng Xu | 3b17017 | 2017-02-15 23:25:21 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | const native_handle_t *resourceHandle = AHardwareBuffer_getNativeHandle(buffer); |
| 173 | if (!resourceHandle) { |
| 174 | return android::NO_MEMORY; |
| 175 | } |
| 176 | |
| 177 | return static_cast<SensorManager *>(manager)->createDirectChannel( |
| 178 | size, ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER, resourceHandle); |
| 179 | } |
| 180 | |
| 181 | void ASensorManager_destroyDirectChannel(ASensorManager *manager, int channelId) { |
| 182 | RETURN_IF_MANAGER_IS_NULL(void()); |
| 183 | |
| 184 | static_cast<SensorManager *>(manager)->destroyDirectChannel(channelId); |
| 185 | } |
| 186 | |
| 187 | int ASensorManager_configureDirectReport( |
| 188 | ASensorManager *manager, ASensor const *sensor, int channelId, int rate) { |
| 189 | RETURN_IF_MANAGER_IS_NULL(android::BAD_VALUE); |
| 190 | |
| 191 | int sensorHandle; |
| 192 | if (sensor == nullptr) { |
| 193 | if (rate != ASENSOR_DIRECT_RATE_STOP) { |
| 194 | ERROR_INVALID_PARAMETER( |
| 195 | "sensor cannot be null when rate is not ASENSOR_DIRECT_RATE_STOP"); |
| 196 | return android::BAD_VALUE; |
| 197 | } |
| 198 | sensorHandle = -1; |
| 199 | } else { |
| 200 | sensorHandle = static_cast<Sensor const *>(sensor)->getHandle(); |
| 201 | } |
| 202 | return static_cast<SensorManager *>(manager)->configureDirectChannel( |
| 203 | channelId, sensorHandle, rate); |
| 204 | } |
| 205 | |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 206 | /*****************************************************************************/ |
| 207 | |
Aniroop Mathur | ee5c18f | 2015-11-03 02:02:09 +0530 | [diff] [blame] | 208 | int ASensorEventQueue_registerSensor(ASensorEventQueue* queue, ASensor const* sensor, |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 209 | int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs) { |
| 210 | RETURN_IF_QUEUE_IS_NULL(android::BAD_VALUE); |
| 211 | RETURN_IF_SENSOR_IS_NULL(android::BAD_VALUE); |
| 212 | if (samplingPeriodUs < 0 || maxBatchReportLatencyUs < 0) { |
| 213 | ERROR_INVALID_PARAMETER("samplingPeriodUs and maxBatchReportLatencyUs cannot be negative"); |
| 214 | return android::BAD_VALUE; |
| 215 | } |
| 216 | |
Aniroop Mathur | ee5c18f | 2015-11-03 02:02:09 +0530 | [diff] [blame] | 217 | return static_cast<SensorEventQueue*>(queue)->enableSensor( |
| 218 | static_cast<Sensor const*>(sensor)->getHandle(), samplingPeriodUs, |
| 219 | maxBatchReportLatencyUs, 0); |
| 220 | } |
| 221 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 222 | int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor) { |
| 223 | RETURN_IF_QUEUE_IS_NULL(android::BAD_VALUE); |
| 224 | RETURN_IF_SENSOR_IS_NULL(android::BAD_VALUE); |
| 225 | |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 226 | return static_cast<SensorEventQueue*>(queue)->enableSensor( |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 227 | static_cast<Sensor const*>(sensor)); |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 230 | int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor) { |
| 231 | RETURN_IF_QUEUE_IS_NULL(android::BAD_VALUE); |
| 232 | RETURN_IF_SENSOR_IS_NULL(android::BAD_VALUE); |
| 233 | |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 234 | return static_cast<SensorEventQueue*>(queue)->disableSensor( |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 235 | static_cast<Sensor const*>(sensor)); |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 238 | int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec) { |
| 239 | RETURN_IF_QUEUE_IS_NULL(android::BAD_VALUE); |
| 240 | RETURN_IF_SENSOR_IS_NULL(android::BAD_VALUE); |
| 241 | |
| 242 | if (usec < 0) { |
| 243 | ERROR_INVALID_PARAMETER("usec cannot be negative"); |
| 244 | return android::BAD_VALUE; |
| 245 | } |
| 246 | |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 247 | return static_cast<SensorEventQueue*>(queue)->setEventRate( |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 248 | static_cast<Sensor const*>(sensor), us2ns(usec)); |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 251 | int ASensorEventQueue_hasEvents(ASensorEventQueue* queue) { |
| 252 | RETURN_IF_QUEUE_IS_NULL(android::BAD_VALUE); |
| 253 | |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 254 | struct pollfd pfd; |
| 255 | pfd.fd = static_cast<SensorEventQueue*>(queue)->getFd(); |
| 256 | pfd.events = POLLIN; |
| 257 | pfd.revents = 0; |
| 258 | |
| 259 | int nfd = poll(&pfd, 1, 0); |
| 260 | |
| 261 | if (nfd < 0) |
| 262 | return -errno; |
| 263 | |
| 264 | if (pfd.revents != POLLIN) |
| 265 | return -1; |
| 266 | |
| 267 | return (nfd == 0) ? 0 : 1; |
| 268 | } |
| 269 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 270 | ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, ASensorEvent* events, size_t count) { |
| 271 | RETURN_IF_QUEUE_IS_NULL(android::BAD_VALUE); |
| 272 | if (events == nullptr) { |
| 273 | ERROR_INVALID_PARAMETER("events cannot be NULL"); |
| 274 | return android::BAD_VALUE; |
| 275 | } |
| 276 | |
Aravind Akella | 35187bd | 2014-02-11 18:44:42 -0800 | [diff] [blame] | 277 | ssize_t actual = static_cast<SensorEventQueue*>(queue)->read(events, count); |
| 278 | if (actual > 0) { |
| 279 | static_cast<SensorEventQueue*>(queue)->sendAck(events, actual); |
| 280 | } |
| 281 | return actual; |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 284 | /*****************************************************************************/ |
| 285 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 286 | const char* ASensor_getName(ASensor const* sensor) { |
| 287 | RETURN_IF_SENSOR_IS_NULL(nullptr); |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 288 | return static_cast<Sensor const*>(sensor)->getName().string(); |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 291 | const char* ASensor_getVendor(ASensor const* sensor) { |
| 292 | RETURN_IF_SENSOR_IS_NULL(nullptr); |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 293 | return static_cast<Sensor const*>(sensor)->getVendor().string(); |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 296 | int ASensor_getType(ASensor const* sensor) { |
| 297 | RETURN_IF_SENSOR_IS_NULL(ASENSOR_TYPE_INVALID); |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 298 | return static_cast<Sensor const*>(sensor)->getType(); |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 301 | float ASensor_getResolution(ASensor const* sensor) { |
| 302 | RETURN_IF_SENSOR_IS_NULL(ASENSOR_RESOLUTION_INVALID); |
Mathias Agopian | 1bf7978 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 303 | return static_cast<Sensor const*>(sensor)->getResolution(); |
Mathias Agopian | b957b9d | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 306 | int ASensor_getMinDelay(ASensor const* sensor) { |
| 307 | RETURN_IF_SENSOR_IS_NULL(ASENSOR_DELAY_INVALID); |
Mathias Agopian | 050b562 | 2010-07-29 16:51:38 -0700 | [diff] [blame] | 308 | return static_cast<Sensor const*>(sensor)->getMinDelay(); |
| 309 | } |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 310 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 311 | int ASensor_getFifoMaxEventCount(ASensor const* sensor) { |
| 312 | RETURN_IF_SENSOR_IS_NULL(ASENSOR_FIFO_COUNT_INVALID); |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 313 | return static_cast<Sensor const*>(sensor)->getFifoMaxEventCount(); |
| 314 | } |
| 315 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 316 | int ASensor_getFifoReservedEventCount(ASensor const* sensor) { |
| 317 | RETURN_IF_SENSOR_IS_NULL(ASENSOR_FIFO_COUNT_INVALID); |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 318 | return static_cast<Sensor const*>(sensor)->getFifoReservedEventCount(); |
| 319 | } |
| 320 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 321 | const char* ASensor_getStringType(ASensor const* sensor) { |
| 322 | RETURN_IF_SENSOR_IS_NULL(nullptr); |
Aravind Akella | cd9a7bb | 2014-04-07 22:55:21 +0000 | [diff] [blame] | 323 | return static_cast<Sensor const*>(sensor)->getStringType().string(); |
| 324 | } |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 325 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 326 | int ASensor_getReportingMode(ASensor const* sensor) { |
| 327 | RETURN_IF_SENSOR_IS_NULL(AREPORTING_MODE_INVALID); |
Aravind Akella | 2790035 | 2014-06-03 19:20:42 -0700 | [diff] [blame] | 328 | return static_cast<Sensor const*>(sensor)->getReportingMode(); |
| 329 | } |
Aravind Akella | 99fe165 | 2014-08-05 15:02:11 -0700 | [diff] [blame] | 330 | |
Peng Xu | 63483ad | 2017-02-28 17:00:16 -0800 | [diff] [blame] | 331 | bool ASensor_isWakeUpSensor(ASensor const* sensor) { |
| 332 | RETURN_IF_SENSOR_IS_NULL(false); |
Aravind Akella | 99fe165 | 2014-08-05 15:02:11 -0700 | [diff] [blame] | 333 | return static_cast<Sensor const*>(sensor)->isWakeUpSensor(); |
Aravind Akella | 2af91d0 | 2015-07-29 18:39:52 -0700 | [diff] [blame] | 334 | } |
Peng Xu | 3b17017 | 2017-02-15 23:25:21 -0800 | [diff] [blame] | 335 | |
| 336 | bool ASensor_isDirectChannelTypeSupported(ASensor const *sensor, int channelType) { |
| 337 | RETURN_IF_SENSOR_IS_NULL(false); |
| 338 | return static_cast<Sensor const *>(sensor)->isDirectChannelTypeSupported(channelType); |
| 339 | } |
| 340 | |
| 341 | int ASensor_getHighestDirectReportRateLevel(ASensor const *sensor) { |
| 342 | RETURN_IF_SENSOR_IS_NULL(ASENSOR_DIRECT_RATE_STOP); |
| 343 | return static_cast<Sensor const *>(sensor)->getHighestDirectReportRateLevel(); |
| 344 | } |