Sensors: MultiHal: add support for HIDL
Add get_multi_hal_module_info() to support using multi-hal
functionality within the HIDL sensor implementation.
Move externally relevant constants and prototypes to new multihal.h
file.
Add new Android.bp for Treble to build multi-hal into a static
library that is now included by the HIDL sensor implementation.
Bug: 32022308
Change-Id: I2b3afa9ff1e0a2e5a098e643dde99ec86bb88206
diff --git a/modules/sensors/Android.bp b/modules/sensors/Android.bp
new file mode 100644
index 0000000..f19cee3
--- /dev/null
+++ b/modules/sensors/Android.bp
@@ -0,0 +1,14 @@
+cc_library_static {
+ name: "multihal",
+ srcs: [
+ "multihal.cpp",
+ "SensorEventQueue.cpp"
+ ],
+ shared_libs: [
+ "liblog",
+ "libcutils",
+ "libutils",
+ "libdl"
+ ],
+ export_include_dirs: ["."],
+}
diff --git a/modules/sensors/multihal.cpp b/modules/sensors/multihal.cpp
index f38d90d..603a8c6 100644
--- a/modules/sensors/multihal.cpp
+++ b/modules/sensors/multihal.cpp
@@ -14,33 +14,30 @@
* limitations under the License.
*/
-#include <hardware/sensors.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <dirent.h>
-#include <math.h>
-#include <poll.h>
-#include <pthread.h>
-#include <cutils/atomic.h>
+#include "SensorEventQueue.h"
+#include "multihal.h"
#define LOG_NDEBUG 1
#include <cutils/log.h>
+#include <cutils/atomic.h>
+#include <hardware/sensors.h>
#include <vector>
#include <string>
#include <fstream>
#include <map>
-#include <string>
-#include <stdio.h>
+#include <dirent.h>
#include <dlfcn.h>
-#include <SensorEventQueue.h>
-
+#include <errno.h>
+#include <fcntl.h>
#include <limits.h>
+#include <math.h>
+#include <poll.h>
+#include <pthread.h>
+#include <stdio.h>
#include <stdlib.h>
-static const char* CONFIG_FILENAME = "/system/etc/sensors/hals.conf";
-static const int MAX_CONF_LINE_LENGTH = 1024;
static pthread_mutex_t init_modules_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t init_sensors_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -504,13 +501,13 @@
*/
static void get_so_paths(std::vector<std::string> *so_paths) {
std::string line;
- std::ifstream conf_file(CONFIG_FILENAME);
+ std::ifstream conf_file(MULTI_HAL_CONFIG_FILE_PATH);
if(!conf_file) {
- ALOGW("No multihal config file found at %s", CONFIG_FILENAME);
+ ALOGW("No multihal config file found at %s", MULTI_HAL_CONFIG_FILE_PATH);
return;
}
- ALOGV("Multihal config file found at %s", CONFIG_FILENAME);
+ ALOGV("Multihal config file found at %s", MULTI_HAL_CONFIG_FILE_PATH);
while (std::getline(conf_file, line)) {
ALOGV("config file line: '%s'", line.c_str());
so_paths->push_back(line);
@@ -660,6 +657,10 @@
.get_sensors_list = module__get_sensors_list
};
+struct sensors_module_t *get_multi_hal_module_info() {
+ return (&HAL_MODULE_INFO_SYM);
+}
+
static int open_sensors(const struct hw_module_t* hw_module, const char* name,
struct hw_device_t** hw_device_out) {
ALOGV("open_sensors begin...");
diff --git a/modules/sensors/multihal.h b/modules/sensors/multihal.h
new file mode 100644
index 0000000..210c7cc
--- /dev/null
+++ b/modules/sensors/multihal.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef HARDWARE_LIBHARDWARE_MODULES_SENSORS_MULTIHAL_H_
+#define HARDWARE_LIBHARDWARE_MODULES_SENSORS_MULTIHAL_H_
+
+#include <hardware/sensors.h>
+#include <hardware/hardware.h>
+
+static const char* MULTI_HAL_CONFIG_FILE_PATH = "/system/etc/sensors/hals.conf";
+
+struct sensors_module_t *get_multi_hal_module_info(void);
+
+#endif // HARDWARE_LIBHARDWARE_MODULES_SENSORS_MULTIHAL_H_