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/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...");