Merge "libhardware: sensors: update multi hal to support 64bit builds"
This commit is contained in:
commit
3f93d2a970
2 changed files with 15 additions and 35 deletions
|
@ -20,9 +20,9 @@ ifeq ($(USE_SENSOR_MULTI_HAL),true)
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
LOCAL_MODULE := sensors.$(TARGET_DEVICE)
|
LOCAL_MODULE := sensors.$(TARGET_BOARD_PLATFORM)
|
||||||
|
|
||||||
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
|
LOCAL_MODULE_RELATIVE_PATH := hw
|
||||||
|
|
||||||
LOCAL_CFLAGS := -DLOG_TAG=\"MultiHal\"
|
LOCAL_CFLAGS := -DLOG_TAG=\"MultiHal\"
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include <cutils/log.h>
|
#include <cutils/log.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -36,8 +38,6 @@
|
||||||
|
|
||||||
|
|
||||||
static const char* CONFIG_FILENAME = "/system/etc/sensors/hals.conf";
|
static const char* CONFIG_FILENAME = "/system/etc/sensors/hals.conf";
|
||||||
static const char* LEGAL_SUBHAL_PATH_PREFIX = "/system/lib/hw/";
|
|
||||||
static const char* LEGAL_SUBHAL_ALTERNATE_PATH_PREFIX = "/system/vendor/lib/";
|
|
||||||
static const int MAX_CONF_LINE_LENGTH = 1024;
|
static const int MAX_CONF_LINE_LENGTH = 1024;
|
||||||
|
|
||||||
static pthread_mutex_t init_modules_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t init_modules_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
@ -463,39 +463,19 @@ static bool starts_with(const char* s, const char* prefix) {
|
||||||
* Adds valid paths from the config file to the vector passed in.
|
* Adds valid paths from the config file to the vector passed in.
|
||||||
* The vector must not be null.
|
* The vector must not be null.
|
||||||
*/
|
*/
|
||||||
static void get_so_paths(std::vector<char*> *so_paths) {
|
static void get_so_paths(std::vector<std::string> *so_paths) {
|
||||||
FILE *conf_file = fopen(CONFIG_FILENAME, "r");
|
std::string line;
|
||||||
if (conf_file == NULL) {
|
std::ifstream conf_file(CONFIG_FILENAME);
|
||||||
|
|
||||||
|
if(!conf_file) {
|
||||||
ALOGW("No multihal config file found at %s", CONFIG_FILENAME);
|
ALOGW("No multihal config file found at %s", CONFIG_FILENAME);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ALOGV("Multihal config file found at %s", CONFIG_FILENAME);
|
ALOGV("Multihal config file found at %s", CONFIG_FILENAME);
|
||||||
char *line = NULL;
|
while (std::getline(conf_file, line)) {
|
||||||
size_t len = 0;
|
ALOGV("config file line: '%s'", line.c_str());
|
||||||
int line_count = 0;
|
so_paths->push_back(line);
|
||||||
while (getline(&line, &len, conf_file) != -1) {
|
|
||||||
// overwrite trailing eoln with null char
|
|
||||||
char* pch = strchr(line, '\n');
|
|
||||||
if (pch != NULL) {
|
|
||||||
*pch = '\0';
|
|
||||||
}
|
|
||||||
ALOGV("config file line #%d: '%s'", ++line_count, line);
|
|
||||||
char *real_path = realpath(line, NULL);
|
|
||||||
if (starts_with(real_path, LEGAL_SUBHAL_PATH_PREFIX) ||
|
|
||||||
starts_with(real_path, LEGAL_SUBHAL_ALTERNATE_PATH_PREFIX)) {
|
|
||||||
ALOGV("accepting valid path '%s'", real_path);
|
|
||||||
char* compact_line = new char[strlen(real_path) + 1];
|
|
||||||
strcpy(compact_line, real_path);
|
|
||||||
so_paths->push_back(compact_line);
|
|
||||||
} else {
|
|
||||||
ALOGW("rejecting path '%s' because it does not start with '%s' or '%s'",
|
|
||||||
real_path, LEGAL_SUBHAL_PATH_PREFIX, LEGAL_SUBHAL_ALTERNATE_PATH_PREFIX);
|
|
||||||
}
|
|
||||||
free(real_path);
|
|
||||||
}
|
}
|
||||||
free(line);
|
|
||||||
fclose(conf_file);
|
|
||||||
ALOGV("hals.conf contained %d lines", line_count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -508,15 +488,15 @@ static void lazy_init_modules() {
|
||||||
pthread_mutex_unlock(&init_modules_mutex);
|
pthread_mutex_unlock(&init_modules_mutex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::vector<char*> *so_paths = new std::vector<char*>();
|
std::vector<std::string> *so_paths = new std::vector<std::string>();
|
||||||
get_so_paths(so_paths);
|
get_so_paths(so_paths);
|
||||||
|
|
||||||
// dlopen the module files and cache their module symbols in sub_hw_modules
|
// dlopen the module files and cache their module symbols in sub_hw_modules
|
||||||
sub_hw_modules = new std::vector<hw_module_t *>();
|
sub_hw_modules = new std::vector<hw_module_t *>();
|
||||||
dlerror(); // clear any old errors
|
dlerror(); // clear any old errors
|
||||||
const char* sym = HAL_MODULE_INFO_SYM_AS_STR;
|
const char* sym = HAL_MODULE_INFO_SYM_AS_STR;
|
||||||
for (std::vector<char*>::iterator it = so_paths->begin(); it != so_paths->end(); it++) {
|
for (std::vector<std::string>::iterator it = so_paths->begin(); it != so_paths->end(); it++) {
|
||||||
char* path = *it;
|
const char* path = it->c_str();
|
||||||
void* lib_handle = dlopen(path, RTLD_LAZY);
|
void* lib_handle = dlopen(path, RTLD_LAZY);
|
||||||
if (lib_handle == NULL) {
|
if (lib_handle == NULL) {
|
||||||
ALOGW("dlerror(): %s", dlerror());
|
ALOGW("dlerror(): %s", dlerror());
|
||||||
|
|
Loading…
Reference in a new issue