Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Nick Vaccaro | 8a83708 | 2016-12-12 16:50:57 -0800 | [diff] [blame^] | 17 | #include "SensorEventQueue.h" |
| 18 | #include "multihal.h" |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 19 | |
| 20 | #define LOG_NDEBUG 1 |
| 21 | #include <cutils/log.h> |
Nick Vaccaro | 8a83708 | 2016-12-12 16:50:57 -0800 | [diff] [blame^] | 22 | #include <cutils/atomic.h> |
| 23 | #include <hardware/sensors.h> |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 24 | |
| 25 | #include <vector> |
Satya Durga Srinivasu Prabhala | 1fd3618 | 2015-01-20 18:53:35 -0800 | [diff] [blame] | 26 | #include <string> |
| 27 | #include <fstream> |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 28 | #include <map> |
| 29 | |
Nick Vaccaro | 8a83708 | 2016-12-12 16:50:57 -0800 | [diff] [blame^] | 30 | #include <dirent.h> |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 31 | #include <dlfcn.h> |
Nick Vaccaro | 8a83708 | 2016-12-12 16:50:57 -0800 | [diff] [blame^] | 32 | #include <errno.h> |
| 33 | #include <fcntl.h> |
Ching Tzung Lin | 4fd217a | 2015-07-23 10:18:06 -0700 | [diff] [blame] | 34 | #include <limits.h> |
Nick Vaccaro | 8a83708 | 2016-12-12 16:50:57 -0800 | [diff] [blame^] | 35 | #include <math.h> |
| 36 | #include <poll.h> |
| 37 | #include <pthread.h> |
| 38 | #include <stdio.h> |
Ching Tzung Lin | 4fd217a | 2015-07-23 10:18:06 -0700 | [diff] [blame] | 39 | #include <stdlib.h> |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 40 | |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 41 | |
| 42 | static pthread_mutex_t init_modules_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 43 | static pthread_mutex_t init_sensors_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 44 | |
| 45 | // This mutex is shared by all queues |
| 46 | static pthread_mutex_t queue_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 47 | |
| 48 | // Used to pause the multihal poll(). Broadcasted by sub-polling tasks if waiting_for_data. |
| 49 | static pthread_cond_t data_available_cond = PTHREAD_COND_INITIALIZER; |
| 50 | bool waiting_for_data = false; |
| 51 | |
| 52 | /* |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 53 | * Vector of sub modules, whose indexes are referred to in this file as module_index. |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 54 | */ |
| 55 | static std::vector<hw_module_t *> *sub_hw_modules = NULL; |
| 56 | |
| 57 | /* |
| 58 | * Comparable class that globally identifies a sensor, by module index and local handle. |
| 59 | * A module index is the module's index in sub_hw_modules. |
| 60 | * A local handle is the handle the sub-module assigns to a sensor. |
| 61 | */ |
| 62 | struct FullHandle { |
| 63 | int moduleIndex; |
| 64 | int localHandle; |
| 65 | |
| 66 | bool operator<(const FullHandle &that) const { |
| 67 | if (moduleIndex < that.moduleIndex) { |
| 68 | return true; |
| 69 | } |
| 70 | if (moduleIndex > that.moduleIndex) { |
| 71 | return false; |
| 72 | } |
| 73 | return localHandle < that.localHandle; |
| 74 | } |
| 75 | |
| 76 | bool operator==(const FullHandle &that) const { |
| 77 | return moduleIndex == that.moduleIndex && localHandle == that.localHandle; |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | std::map<int, FullHandle> global_to_full; |
| 82 | std::map<FullHandle, int> full_to_global; |
| 83 | int next_global_handle = 1; |
| 84 | |
| 85 | static int assign_global_handle(int module_index, int local_handle) { |
| 86 | int global_handle = next_global_handle++; |
| 87 | FullHandle full_handle; |
| 88 | full_handle.moduleIndex = module_index; |
| 89 | full_handle.localHandle = local_handle; |
| 90 | full_to_global[full_handle] = global_handle; |
| 91 | global_to_full[global_handle] = full_handle; |
| 92 | return global_handle; |
| 93 | } |
| 94 | |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 95 | // Returns the local handle, or -1 if it does not exist. |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 96 | static int get_local_handle(int global_handle) { |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 97 | if (global_to_full.count(global_handle) == 0) { |
| 98 | ALOGW("Unknown global_handle %d", global_handle); |
| 99 | return -1; |
| 100 | } |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 101 | return global_to_full[global_handle].localHandle; |
| 102 | } |
| 103 | |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 104 | // Returns the sub_hw_modules index of the module that contains the sensor associates with this |
| 105 | // global_handle, or -1 if that global_handle does not exist. |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 106 | static int get_module_index(int global_handle) { |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 107 | if (global_to_full.count(global_handle) == 0) { |
| 108 | ALOGW("Unknown global_handle %d", global_handle); |
| 109 | return -1; |
| 110 | } |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 111 | FullHandle f = global_to_full[global_handle]; |
| 112 | ALOGV("FullHandle for global_handle %d: moduleIndex %d, localHandle %d", |
| 113 | global_handle, f.moduleIndex, f.localHandle); |
| 114 | return f.moduleIndex; |
| 115 | } |
| 116 | |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 117 | // Returns the global handle for this full_handle, or -1 if the full_handle is unknown. |
| 118 | static int get_global_handle(FullHandle* full_handle) { |
| 119 | int global_handle = -1; |
| 120 | if (full_to_global.count(*full_handle)) { |
| 121 | global_handle = full_to_global[*full_handle]; |
| 122 | } else { |
| 123 | ALOGW("Unknown FullHandle: moduleIndex %d, localHandle %d", |
| 124 | full_handle->moduleIndex, full_handle->localHandle); |
| 125 | } |
| 126 | return global_handle; |
| 127 | } |
| 128 | |
Nick Vaccaro | 98d5e94 | 2016-02-09 14:56:17 -0800 | [diff] [blame] | 129 | static const int SENSOR_EVENT_QUEUE_CAPACITY = 36; |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 130 | |
| 131 | struct TaskContext { |
| 132 | sensors_poll_device_t* device; |
| 133 | SensorEventQueue* queue; |
| 134 | }; |
| 135 | |
| 136 | void *writerTask(void* ptr) { |
| 137 | ALOGV("writerTask STARTS"); |
| 138 | TaskContext* ctx = (TaskContext*)ptr; |
| 139 | sensors_poll_device_t* device = ctx->device; |
| 140 | SensorEventQueue* queue = ctx->queue; |
| 141 | sensors_event_t* buffer; |
| 142 | int eventsPolled; |
| 143 | while (1) { |
| 144 | pthread_mutex_lock(&queue_mutex); |
| 145 | if (queue->waitForSpace(&queue_mutex)) { |
| 146 | ALOGV("writerTask waited for space"); |
| 147 | } |
| 148 | int bufferSize = queue->getWritableRegion(SENSOR_EVENT_QUEUE_CAPACITY, &buffer); |
| 149 | // Do blocking poll outside of lock |
| 150 | pthread_mutex_unlock(&queue_mutex); |
| 151 | |
| 152 | ALOGV("writerTask before poll() - bufferSize = %d", bufferSize); |
| 153 | eventsPolled = device->poll(device, buffer, bufferSize); |
| 154 | ALOGV("writerTask poll() got %d events.", eventsPolled); |
Nick Vaccaro | 59d9fb4 | 2016-07-19 10:34:00 -0700 | [diff] [blame] | 155 | if (eventsPolled <= 0) { |
| 156 | if (eventsPolled < 0) { |
| 157 | ALOGV("writerTask ignored error %d from %s", eventsPolled, device->common.module->name); |
| 158 | ALOGE("ERROR: Fix %s so it does not return error from poll()", device->common.module->name); |
| 159 | } |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 160 | continue; |
| 161 | } |
| 162 | pthread_mutex_lock(&queue_mutex); |
| 163 | queue->markAsWritten(eventsPolled); |
| 164 | ALOGV("writerTask wrote %d events", eventsPolled); |
| 165 | if (waiting_for_data) { |
| 166 | ALOGV("writerTask - broadcast data_available_cond"); |
| 167 | pthread_cond_broadcast(&data_available_cond); |
| 168 | } |
| 169 | pthread_mutex_unlock(&queue_mutex); |
| 170 | } |
| 171 | // never actually returns |
| 172 | return NULL; |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * Cache of all sensors, with original handles replaced by global handles. |
| 177 | * This will be handled to get_sensors_list() callers. |
| 178 | */ |
| 179 | static struct sensor_t const* global_sensors_list = NULL; |
| 180 | static int global_sensors_count = -1; |
| 181 | |
| 182 | /* |
| 183 | * Extends a sensors_poll_device_1 by including all the sub-module's devices. |
| 184 | */ |
| 185 | struct sensors_poll_context_t { |
| 186 | /* |
| 187 | * This is the device that SensorDevice.cpp uses to make API calls |
| 188 | * to the multihal, which fans them out to sub-HALs. |
| 189 | */ |
| 190 | sensors_poll_device_1 proxy_device; // must be first |
| 191 | |
| 192 | void addSubHwDevice(struct hw_device_t*); |
| 193 | |
| 194 | int activate(int handle, int enabled); |
| 195 | int setDelay(int handle, int64_t ns); |
| 196 | int poll(sensors_event_t* data, int count); |
| 197 | int batch(int handle, int flags, int64_t period_ns, int64_t timeout); |
| 198 | int flush(int handle); |
Nick Vaccaro | c1ded2a | 2016-10-14 10:24:10 -0700 | [diff] [blame] | 199 | int inject_sensor_data(struct sensors_poll_device_1 *dev, const sensors_event_t *data); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 200 | int close(); |
| 201 | |
| 202 | std::vector<hw_device_t*> sub_hw_devices; |
| 203 | std::vector<SensorEventQueue*> queues; |
| 204 | std::vector<pthread_t> threads; |
| 205 | int nextReadIndex; |
| 206 | |
| 207 | sensors_poll_device_t* get_v0_device_by_handle(int global_handle); |
| 208 | sensors_poll_device_1_t* get_v1_device_by_handle(int global_handle); |
| 209 | int get_device_version_by_handle(int global_handle); |
| 210 | |
| 211 | void copy_event_remap_handle(sensors_event_t* src, sensors_event_t* dest, int sub_index); |
| 212 | }; |
| 213 | |
| 214 | void sensors_poll_context_t::addSubHwDevice(struct hw_device_t* sub_hw_device) { |
| 215 | ALOGV("addSubHwDevice"); |
| 216 | this->sub_hw_devices.push_back(sub_hw_device); |
| 217 | |
| 218 | SensorEventQueue *queue = new SensorEventQueue(SENSOR_EVENT_QUEUE_CAPACITY); |
| 219 | this->queues.push_back(queue); |
| 220 | |
| 221 | TaskContext* taskContext = new TaskContext(); |
| 222 | taskContext->device = (sensors_poll_device_t*) sub_hw_device; |
| 223 | taskContext->queue = queue; |
| 224 | |
| 225 | pthread_t writerThread; |
| 226 | pthread_create(&writerThread, NULL, writerTask, taskContext); |
| 227 | this->threads.push_back(writerThread); |
| 228 | } |
| 229 | |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 230 | // Returns the device pointer, or NULL if the global handle is invalid. |
| 231 | sensors_poll_device_t* sensors_poll_context_t::get_v0_device_by_handle(int global_handle) { |
| 232 | int sub_index = get_module_index(global_handle); |
Nick Vaccaro | a889c09 | 2016-04-15 10:17:07 -0700 | [diff] [blame] | 233 | if (sub_index < 0 || sub_index >= (int) this->sub_hw_devices.size()) { |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 234 | return NULL; |
| 235 | } |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 236 | return (sensors_poll_device_t*) this->sub_hw_devices[sub_index]; |
| 237 | } |
| 238 | |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 239 | // Returns the device pointer, or NULL if the global handle is invalid. |
| 240 | sensors_poll_device_1_t* sensors_poll_context_t::get_v1_device_by_handle(int global_handle) { |
| 241 | int sub_index = get_module_index(global_handle); |
Nick Vaccaro | a889c09 | 2016-04-15 10:17:07 -0700 | [diff] [blame] | 242 | if (sub_index < 0 || sub_index >= (int) this->sub_hw_devices.size()) { |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 243 | return NULL; |
| 244 | } |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 245 | return (sensors_poll_device_1_t*) this->sub_hw_devices[sub_index]; |
| 246 | } |
| 247 | |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 248 | // Returns the device version, or -1 if the handle is invalid. |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 249 | int sensors_poll_context_t::get_device_version_by_handle(int handle) { |
| 250 | sensors_poll_device_t* v0 = this->get_v0_device_by_handle(handle); |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 251 | if (v0) { |
| 252 | return v0->common.version; |
| 253 | } else { |
| 254 | return -1; |
| 255 | } |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 258 | // Android L requires sensor HALs to be either 1_0 or 1_3 compliant |
| 259 | #define HAL_VERSION_IS_COMPLIANT(version) \ |
| 260 | (version == SENSORS_DEVICE_API_VERSION_1_0 || version >= SENSORS_DEVICE_API_VERSION_1_3) |
| 261 | |
| 262 | // Returns true if HAL is compliant, false if HAL is not compliant or if handle is invalid |
| 263 | static bool halIsCompliant(sensors_poll_context_t *ctx, int handle) { |
| 264 | int version = ctx->get_device_version_by_handle(handle); |
| 265 | return version != -1 && HAL_VERSION_IS_COMPLIANT(version); |
| 266 | } |
| 267 | |
Nick Vaccaro | c1ded2a | 2016-10-14 10:24:10 -0700 | [diff] [blame] | 268 | static bool halIsAPILevelCompliant(sensors_poll_context_t *ctx, int handle, int level) { |
| 269 | int version = ctx->get_device_version_by_handle(handle); |
| 270 | return version != -1 && (version >= level); |
| 271 | } |
| 272 | |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 273 | const char *apiNumToStr(int version) { |
| 274 | switch(version) { |
| 275 | case SENSORS_DEVICE_API_VERSION_1_0: |
| 276 | return "SENSORS_DEVICE_API_VERSION_1_0"; |
| 277 | case SENSORS_DEVICE_API_VERSION_1_1: |
| 278 | return "SENSORS_DEVICE_API_VERSION_1_1"; |
| 279 | case SENSORS_DEVICE_API_VERSION_1_2: |
| 280 | return "SENSORS_DEVICE_API_VERSION_1_2"; |
| 281 | case SENSORS_DEVICE_API_VERSION_1_3: |
| 282 | return "SENSORS_DEVICE_API_VERSION_1_3"; |
Nick Vaccaro | c1ded2a | 2016-10-14 10:24:10 -0700 | [diff] [blame] | 283 | case SENSORS_DEVICE_API_VERSION_1_4: |
| 284 | return "SENSORS_DEVICE_API_VERSION_1_4"; |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 285 | default: |
| 286 | return "UNKNOWN"; |
| 287 | } |
| 288 | } |
| 289 | |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 290 | int sensors_poll_context_t::activate(int handle, int enabled) { |
Nick Vaccaro | 93bf996 | 2014-03-17 13:05:09 -0700 | [diff] [blame] | 291 | int retval = -EINVAL; |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 292 | ALOGV("activate"); |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 293 | int local_handle = get_local_handle(handle); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 294 | sensors_poll_device_t* v0 = this->get_v0_device_by_handle(handle); |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 295 | if (halIsCompliant(this, handle) && local_handle >= 0 && v0) { |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 296 | retval = v0->activate(v0, local_handle, enabled); |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 297 | } else { |
| 298 | ALOGE("IGNORING activate(enable %d) call to non-API-compliant sensor handle=%d !", |
| 299 | enabled, handle); |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 300 | } |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 301 | ALOGV("retval %d", retval); |
| 302 | return retval; |
| 303 | } |
| 304 | |
| 305 | int sensors_poll_context_t::setDelay(int handle, int64_t ns) { |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 306 | int retval = -EINVAL; |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 307 | ALOGV("setDelay"); |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 308 | int local_handle = get_local_handle(handle); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 309 | sensors_poll_device_t* v0 = this->get_v0_device_by_handle(handle); |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 310 | if (halIsCompliant(this, handle) && local_handle >= 0 && v0) { |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 311 | retval = v0->setDelay(v0, local_handle, ns); |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 312 | } else { |
| 313 | ALOGE("IGNORING setDelay() call for non-API-compliant sensor handle=%d !", handle); |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 314 | } |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 315 | ALOGV("retval %d", retval); |
| 316 | return retval; |
| 317 | } |
| 318 | |
| 319 | void sensors_poll_context_t::copy_event_remap_handle(sensors_event_t* dest, sensors_event_t* src, |
| 320 | int sub_index) { |
| 321 | memcpy(dest, src, sizeof(struct sensors_event_t)); |
| 322 | // A normal event's "sensor" field is a local handle. Convert it to a global handle. |
| 323 | // A meta-data event must have its sensor set to 0, but it has a nested event |
| 324 | // with a local handle that needs to be converted to a global handle. |
| 325 | FullHandle full_handle; |
| 326 | full_handle.moduleIndex = sub_index; |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 327 | |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 328 | // If it's a metadata event, rewrite the inner payload, not the sensor field. |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 329 | // If the event's sensor field is unregistered for any reason, rewrite the sensor field |
| 330 | // with a -1, instead of writing an incorrect but plausible sensor number, because |
| 331 | // get_global_handle() returns -1 for unknown FullHandles. |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 332 | if (dest->type == SENSOR_TYPE_META_DATA) { |
| 333 | full_handle.localHandle = dest->meta_data.sensor; |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 334 | dest->meta_data.sensor = get_global_handle(&full_handle); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 335 | } else { |
| 336 | full_handle.localHandle = dest->sensor; |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 337 | dest->sensor = get_global_handle(&full_handle); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
| 341 | int sensors_poll_context_t::poll(sensors_event_t *data, int maxReads) { |
| 342 | ALOGV("poll"); |
| 343 | int empties = 0; |
Nick Vaccaro | c384b18 | 2014-06-10 18:33:07 -0700 | [diff] [blame] | 344 | int queueCount = 0; |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 345 | int eventsRead = 0; |
| 346 | |
| 347 | pthread_mutex_lock(&queue_mutex); |
Nick Vaccaro | c384b18 | 2014-06-10 18:33:07 -0700 | [diff] [blame] | 348 | queueCount = (int)this->queues.size(); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 349 | while (eventsRead == 0) { |
| 350 | while (empties < queueCount && eventsRead < maxReads) { |
| 351 | SensorEventQueue* queue = this->queues.at(this->nextReadIndex); |
| 352 | sensors_event_t* event = queue->peek(); |
| 353 | if (event == NULL) { |
| 354 | empties++; |
| 355 | } else { |
| 356 | empties = 0; |
Nick Vaccaro | c384b18 | 2014-06-10 18:33:07 -0700 | [diff] [blame] | 357 | this->copy_event_remap_handle(&data[eventsRead], event, nextReadIndex); |
| 358 | if (data[eventsRead].sensor == -1) { |
| 359 | // Bad handle, do not pass corrupted event upstream ! |
| 360 | ALOGW("Dropping bad local handle event packet on the floor"); |
| 361 | } else { |
| 362 | eventsRead++; |
| 363 | } |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 364 | queue->dequeue(); |
| 365 | } |
| 366 | this->nextReadIndex = (this->nextReadIndex + 1) % queueCount; |
| 367 | } |
| 368 | if (eventsRead == 0) { |
| 369 | // The queues have been scanned and none contain data, so wait. |
| 370 | ALOGV("poll stopping to wait for data"); |
| 371 | waiting_for_data = true; |
| 372 | pthread_cond_wait(&data_available_cond, &queue_mutex); |
| 373 | waiting_for_data = false; |
| 374 | empties = 0; |
| 375 | } |
| 376 | } |
| 377 | pthread_mutex_unlock(&queue_mutex); |
| 378 | ALOGV("poll returning %d events.", eventsRead); |
| 379 | |
| 380 | return eventsRead; |
| 381 | } |
| 382 | |
| 383 | int sensors_poll_context_t::batch(int handle, int flags, int64_t period_ns, int64_t timeout) { |
| 384 | ALOGV("batch"); |
| 385 | int retval = -EINVAL; |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 386 | int local_handle = get_local_handle(handle); |
| 387 | sensors_poll_device_1_t* v1 = this->get_v1_device_by_handle(handle); |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 388 | if (halIsCompliant(this, handle) && local_handle >= 0 && v1) { |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 389 | retval = v1->batch(v1, local_handle, flags, period_ns, timeout); |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 390 | } else { |
| 391 | ALOGE("IGNORING batch() call to non-API-compliant sensor handle=%d !", handle); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 392 | } |
| 393 | ALOGV("retval %d", retval); |
| 394 | return retval; |
| 395 | } |
| 396 | |
| 397 | int sensors_poll_context_t::flush(int handle) { |
| 398 | ALOGV("flush"); |
| 399 | int retval = -EINVAL; |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 400 | int local_handle = get_local_handle(handle); |
| 401 | sensors_poll_device_1_t* v1 = this->get_v1_device_by_handle(handle); |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 402 | if (halIsCompliant(this, handle) && local_handle >= 0 && v1) { |
Aaron Whyte | 4d7ac52 | 2014-04-09 15:56:54 -0700 | [diff] [blame] | 403 | retval = v1->flush(v1, local_handle); |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 404 | } else { |
| 405 | ALOGE("IGNORING flush() call to non-API-compliant sensor handle=%d !", handle); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 406 | } |
| 407 | ALOGV("retval %d", retval); |
| 408 | return retval; |
| 409 | } |
| 410 | |
Nick Vaccaro | c1ded2a | 2016-10-14 10:24:10 -0700 | [diff] [blame] | 411 | int sensors_poll_context_t::inject_sensor_data(struct sensors_poll_device_1 *dev, |
| 412 | const sensors_event_t *data) { |
| 413 | int retval = -EINVAL; |
| 414 | ALOGV("inject_sensor_data"); |
| 415 | // Get handle for the sensor owning the event being injected |
| 416 | int local_handle = get_local_handle(data->sensor); |
| 417 | sensors_poll_device_1_t* v1 = this->get_v1_device_by_handle(data->sensor); |
| 418 | if (halIsAPILevelCompliant(this, data->sensor, SENSORS_DEVICE_API_VERSION_1_4) && |
| 419 | local_handle >= 0 && v1) { |
| 420 | retval = v1->inject_sensor_data(dev, data); |
| 421 | } else { |
| 422 | ALOGE("IGNORED inject_sensor_data(type=%d, handle=%d) call to non-API-compliant sensor", |
| 423 | data->type, data->sensor); |
| 424 | } |
| 425 | ALOGV("retval %d", retval); |
| 426 | return retval; |
| 427 | |
| 428 | } |
| 429 | |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 430 | int sensors_poll_context_t::close() { |
| 431 | ALOGV("close"); |
| 432 | for (std::vector<hw_device_t*>::iterator it = this->sub_hw_devices.begin(); |
| 433 | it != this->sub_hw_devices.end(); it++) { |
| 434 | hw_device_t* dev = *it; |
| 435 | int retval = dev->close(dev); |
| 436 | ALOGV("retval %d", retval); |
| 437 | } |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | |
| 442 | static int device__close(struct hw_device_t *dev) { |
| 443 | sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; |
| 444 | if (ctx != NULL) { |
| 445 | int retval = ctx->close(); |
| 446 | delete ctx; |
| 447 | } |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static int device__activate(struct sensors_poll_device_t *dev, int handle, |
| 452 | int enabled) { |
| 453 | sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; |
| 454 | return ctx->activate(handle, enabled); |
| 455 | } |
| 456 | |
| 457 | static int device__setDelay(struct sensors_poll_device_t *dev, int handle, |
| 458 | int64_t ns) { |
| 459 | sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; |
| 460 | return ctx->setDelay(handle, ns); |
| 461 | } |
| 462 | |
| 463 | static int device__poll(struct sensors_poll_device_t *dev, sensors_event_t* data, |
| 464 | int count) { |
| 465 | sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; |
| 466 | return ctx->poll(data, count); |
| 467 | } |
| 468 | |
| 469 | static int device__batch(struct sensors_poll_device_1 *dev, int handle, |
| 470 | int flags, int64_t period_ns, int64_t timeout) { |
| 471 | sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; |
| 472 | return ctx->batch(handle, flags, period_ns, timeout); |
| 473 | } |
| 474 | |
| 475 | static int device__flush(struct sensors_poll_device_1 *dev, int handle) { |
| 476 | sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; |
| 477 | return ctx->flush(handle); |
| 478 | } |
| 479 | |
Nick Vaccaro | c1ded2a | 2016-10-14 10:24:10 -0700 | [diff] [blame] | 480 | static int device__inject_sensor_data(struct sensors_poll_device_1 *dev, |
| 481 | const sensors_event_t *data) { |
| 482 | sensors_poll_context_t* ctx = (sensors_poll_context_t*) dev; |
| 483 | return ctx->inject_sensor_data(dev, data); |
| 484 | } |
| 485 | |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 486 | static int open_sensors(const struct hw_module_t* module, const char* name, |
| 487 | struct hw_device_t** device); |
| 488 | |
| 489 | static bool starts_with(const char* s, const char* prefix) { |
| 490 | if (s == NULL || prefix == NULL) { |
| 491 | return false; |
| 492 | } |
| 493 | size_t s_size = strlen(s); |
| 494 | size_t prefix_size = strlen(prefix); |
| 495 | return s_size >= prefix_size && strncmp(s, prefix, prefix_size) == 0; |
| 496 | } |
| 497 | |
| 498 | /* |
| 499 | * Adds valid paths from the config file to the vector passed in. |
| 500 | * The vector must not be null. |
| 501 | */ |
Satya Durga Srinivasu Prabhala | 1fd3618 | 2015-01-20 18:53:35 -0800 | [diff] [blame] | 502 | static void get_so_paths(std::vector<std::string> *so_paths) { |
| 503 | std::string line; |
Nick Vaccaro | 8a83708 | 2016-12-12 16:50:57 -0800 | [diff] [blame^] | 504 | std::ifstream conf_file(MULTI_HAL_CONFIG_FILE_PATH); |
Satya Durga Srinivasu Prabhala | 1fd3618 | 2015-01-20 18:53:35 -0800 | [diff] [blame] | 505 | |
| 506 | if(!conf_file) { |
Nick Vaccaro | 8a83708 | 2016-12-12 16:50:57 -0800 | [diff] [blame^] | 507 | ALOGW("No multihal config file found at %s", MULTI_HAL_CONFIG_FILE_PATH); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 508 | return; |
| 509 | } |
Nick Vaccaro | 8a83708 | 2016-12-12 16:50:57 -0800 | [diff] [blame^] | 510 | ALOGV("Multihal config file found at %s", MULTI_HAL_CONFIG_FILE_PATH); |
Satya Durga Srinivasu Prabhala | 1fd3618 | 2015-01-20 18:53:35 -0800 | [diff] [blame] | 511 | while (std::getline(conf_file, line)) { |
| 512 | ALOGV("config file line: '%s'", line.c_str()); |
| 513 | so_paths->push_back(line); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 514 | } |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | /* |
| 518 | * Ensures that the sub-module array is initialized. |
| 519 | * This can be first called from get_sensors_list or from open_sensors. |
| 520 | */ |
| 521 | static void lazy_init_modules() { |
| 522 | pthread_mutex_lock(&init_modules_mutex); |
| 523 | if (sub_hw_modules != NULL) { |
| 524 | pthread_mutex_unlock(&init_modules_mutex); |
| 525 | return; |
| 526 | } |
Satya Durga Srinivasu Prabhala | 1fd3618 | 2015-01-20 18:53:35 -0800 | [diff] [blame] | 527 | std::vector<std::string> *so_paths = new std::vector<std::string>(); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 528 | get_so_paths(so_paths); |
| 529 | |
| 530 | // dlopen the module files and cache their module symbols in sub_hw_modules |
| 531 | sub_hw_modules = new std::vector<hw_module_t *>(); |
| 532 | dlerror(); // clear any old errors |
| 533 | const char* sym = HAL_MODULE_INFO_SYM_AS_STR; |
Satya Durga Srinivasu Prabhala | 1fd3618 | 2015-01-20 18:53:35 -0800 | [diff] [blame] | 534 | for (std::vector<std::string>::iterator it = so_paths->begin(); it != so_paths->end(); it++) { |
| 535 | const char* path = it->c_str(); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 536 | void* lib_handle = dlopen(path, RTLD_LAZY); |
| 537 | if (lib_handle == NULL) { |
| 538 | ALOGW("dlerror(): %s", dlerror()); |
| 539 | } else { |
Aaron Whyte | f22e1c1 | 2014-04-15 15:41:38 -0700 | [diff] [blame] | 540 | ALOGI("Loaded library from %s", path); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 541 | ALOGV("Opening symbol \"%s\"", sym); |
| 542 | // clear old errors |
| 543 | dlerror(); |
| 544 | struct hw_module_t* module = (hw_module_t*) dlsym(lib_handle, sym); |
| 545 | const char* error; |
| 546 | if ((error = dlerror()) != NULL) { |
| 547 | ALOGW("Error calling dlsym: %s", error); |
| 548 | } else if (module == NULL) { |
| 549 | ALOGW("module == NULL"); |
| 550 | } else { |
Aaron Whyte | f22e1c1 | 2014-04-15 15:41:38 -0700 | [diff] [blame] | 551 | ALOGV("Loaded symbols from \"%s\"", sym); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 552 | sub_hw_modules->push_back(module); |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | pthread_mutex_unlock(&init_modules_mutex); |
| 557 | } |
| 558 | |
| 559 | /* |
| 560 | * Lazy-initializes global_sensors_count, global_sensors_list, and module_sensor_handles. |
| 561 | */ |
| 562 | static void lazy_init_sensors_list() { |
| 563 | ALOGV("lazy_init_sensors_list"); |
| 564 | pthread_mutex_lock(&init_sensors_mutex); |
| 565 | if (global_sensors_list != NULL) { |
| 566 | // already initialized |
| 567 | pthread_mutex_unlock(&init_sensors_mutex); |
| 568 | ALOGV("lazy_init_sensors_list - early return"); |
| 569 | return; |
| 570 | } |
| 571 | |
| 572 | ALOGV("lazy_init_sensors_list needs to do work"); |
| 573 | lazy_init_modules(); |
| 574 | |
| 575 | // Count all the sensors, then allocate an array of blanks. |
| 576 | global_sensors_count = 0; |
| 577 | const struct sensor_t *subhal_sensors_list; |
| 578 | for (std::vector<hw_module_t*>::iterator it = sub_hw_modules->begin(); |
| 579 | it != sub_hw_modules->end(); it++) { |
| 580 | struct sensors_module_t *module = (struct sensors_module_t*) *it; |
| 581 | global_sensors_count += module->get_sensors_list(module, &subhal_sensors_list); |
| 582 | ALOGV("increased global_sensors_count to %d", global_sensors_count); |
| 583 | } |
| 584 | |
| 585 | // The global_sensors_list is full of consts. |
| 586 | // Manipulate this non-const list, and point the const one to it when we're done. |
| 587 | sensor_t* mutable_sensor_list = new sensor_t[global_sensors_count]; |
| 588 | |
| 589 | // index of the next sensor to set in mutable_sensor_list |
| 590 | int mutable_sensor_index = 0; |
| 591 | int module_index = 0; |
| 592 | |
| 593 | for (std::vector<hw_module_t*>::iterator it = sub_hw_modules->begin(); |
| 594 | it != sub_hw_modules->end(); it++) { |
| 595 | hw_module_t *hw_module = *it; |
| 596 | ALOGV("examine one module"); |
| 597 | // Read the sub-module's sensor list. |
| 598 | struct sensors_module_t *module = (struct sensors_module_t*) hw_module; |
| 599 | int module_sensor_count = module->get_sensors_list(module, &subhal_sensors_list); |
| 600 | ALOGV("the module has %d sensors", module_sensor_count); |
| 601 | |
| 602 | // Copy the HAL's sensor list into global_sensors_list, |
| 603 | // with the handle changed to be a global handle. |
| 604 | for (int i = 0; i < module_sensor_count; i++) { |
| 605 | ALOGV("examining one sensor"); |
| 606 | const struct sensor_t *local_sensor = &subhal_sensors_list[i]; |
| 607 | int local_handle = local_sensor->handle; |
| 608 | memcpy(&mutable_sensor_list[mutable_sensor_index], local_sensor, |
| 609 | sizeof(struct sensor_t)); |
| 610 | |
| 611 | // Overwrite the global version's handle with a global handle. |
| 612 | int global_handle = assign_global_handle(module_index, local_handle); |
| 613 | |
| 614 | mutable_sensor_list[mutable_sensor_index].handle = global_handle; |
Aaron Whyte | f22e1c1 | 2014-04-15 15:41:38 -0700 | [diff] [blame] | 615 | ALOGV("module_index %d, local_handle %d, global_handle %d", |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 616 | module_index, local_handle, global_handle); |
| 617 | |
| 618 | mutable_sensor_index++; |
| 619 | } |
| 620 | module_index++; |
| 621 | } |
| 622 | // Set the const static global_sensors_list to the mutable one allocated by this function. |
| 623 | global_sensors_list = mutable_sensor_list; |
| 624 | |
| 625 | pthread_mutex_unlock(&init_sensors_mutex); |
| 626 | ALOGV("end lazy_init_sensors_list"); |
| 627 | } |
| 628 | |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 629 | static int module__get_sensors_list(__unused struct sensors_module_t* module, |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 630 | struct sensor_t const** list) { |
| 631 | ALOGV("module__get_sensors_list start"); |
| 632 | lazy_init_sensors_list(); |
| 633 | *list = global_sensors_list; |
| 634 | ALOGV("global_sensors_count: %d", global_sensors_count); |
| 635 | for (int i = 0; i < global_sensors_count; i++) { |
| 636 | ALOGV("sensor type: %d", global_sensors_list[i].type); |
| 637 | } |
| 638 | return global_sensors_count; |
| 639 | } |
| 640 | |
| 641 | static struct hw_module_methods_t sensors_module_methods = { |
Nick Vaccaro | a889c09 | 2016-04-15 10:17:07 -0700 | [diff] [blame] | 642 | .open = open_sensors |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 643 | }; |
| 644 | |
| 645 | struct sensors_module_t HAL_MODULE_INFO_SYM = { |
Nick Vaccaro | a889c09 | 2016-04-15 10:17:07 -0700 | [diff] [blame] | 646 | .common = { |
| 647 | .tag = HARDWARE_MODULE_TAG, |
| 648 | .version_major = 1, |
| 649 | .version_minor = 1, |
| 650 | .id = SENSORS_HARDWARE_MODULE_ID, |
| 651 | .name = "MultiHal Sensor Module", |
| 652 | .author = "Google, Inc", |
| 653 | .methods = &sensors_module_methods, |
| 654 | .dso = NULL, |
| 655 | .reserved = {0}, |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 656 | }, |
Nick Vaccaro | a889c09 | 2016-04-15 10:17:07 -0700 | [diff] [blame] | 657 | .get_sensors_list = module__get_sensors_list |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 658 | }; |
| 659 | |
Nick Vaccaro | 8a83708 | 2016-12-12 16:50:57 -0800 | [diff] [blame^] | 660 | struct sensors_module_t *get_multi_hal_module_info() { |
| 661 | return (&HAL_MODULE_INFO_SYM); |
| 662 | } |
| 663 | |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 664 | static int open_sensors(const struct hw_module_t* hw_module, const char* name, |
| 665 | struct hw_device_t** hw_device_out) { |
Aaron Whyte | f22e1c1 | 2014-04-15 15:41:38 -0700 | [diff] [blame] | 666 | ALOGV("open_sensors begin..."); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 667 | |
| 668 | lazy_init_modules(); |
| 669 | |
| 670 | // Create proxy device, to return later. |
| 671 | sensors_poll_context_t *dev = new sensors_poll_context_t(); |
| 672 | memset(dev, 0, sizeof(sensors_poll_device_1_t)); |
| 673 | dev->proxy_device.common.tag = HARDWARE_DEVICE_TAG; |
Nick Vaccaro | c1ded2a | 2016-10-14 10:24:10 -0700 | [diff] [blame] | 674 | dev->proxy_device.common.version = SENSORS_DEVICE_API_VERSION_1_4; |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 675 | dev->proxy_device.common.module = const_cast<hw_module_t*>(hw_module); |
| 676 | dev->proxy_device.common.close = device__close; |
| 677 | dev->proxy_device.activate = device__activate; |
| 678 | dev->proxy_device.setDelay = device__setDelay; |
| 679 | dev->proxy_device.poll = device__poll; |
| 680 | dev->proxy_device.batch = device__batch; |
| 681 | dev->proxy_device.flush = device__flush; |
Nick Vaccaro | c1ded2a | 2016-10-14 10:24:10 -0700 | [diff] [blame] | 682 | dev->proxy_device.inject_sensor_data = device__inject_sensor_data; |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 683 | |
| 684 | dev->nextReadIndex = 0; |
| 685 | |
| 686 | // Open() the subhal modules. Remember their devices in a vector parallel to sub_hw_modules. |
| 687 | for (std::vector<hw_module_t*>::iterator it = sub_hw_modules->begin(); |
| 688 | it != sub_hw_modules->end(); it++) { |
| 689 | sensors_module_t *sensors_module = (sensors_module_t*) *it; |
| 690 | struct hw_device_t* sub_hw_device; |
| 691 | int sub_open_result = sensors_module->common.methods->open(*it, name, &sub_hw_device); |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 692 | if (!sub_open_result) { |
| 693 | if (!HAL_VERSION_IS_COMPLIANT(sub_hw_device->version)) { |
Nick Vaccaro | c1ded2a | 2016-10-14 10:24:10 -0700 | [diff] [blame] | 694 | ALOGE("SENSORS_DEVICE_API_VERSION_1_3 or newer is required for all sensor HALs"); |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 695 | ALOGE("This HAL reports non-compliant API level : %s", |
| 696 | apiNumToStr(sub_hw_device->version)); |
| 697 | ALOGE("Sensors belonging to this HAL will get ignored !"); |
| 698 | } |
Nick Vaccaro | 93bf996 | 2014-03-17 13:05:09 -0700 | [diff] [blame] | 699 | dev->addSubHwDevice(sub_hw_device); |
Nick Vaccaro | e914d69 | 2014-10-10 13:32:38 -0700 | [diff] [blame] | 700 | } |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | // Prepare the output param and return |
| 704 | *hw_device_out = &dev->proxy_device.common; |
Aaron Whyte | f22e1c1 | 2014-04-15 15:41:38 -0700 | [diff] [blame] | 705 | ALOGV("...open_sensors end"); |
Mike Lockwood | f847762 | 2013-10-17 08:05:00 -0700 | [diff] [blame] | 706 | return 0; |
| 707 | } |