if (ret != 0 || compatibility == HAL_COMMON_BACKEND_COMPATIBILITY_INCOMPATIBLE) {
struct __hal_module_info *info = _hal_api_conf_get_module_info(module, NULL);
- _W("%s: Failed to check compatibility, ret=%d, compatibility=%d\n",
+ _E("%s: Failed to check compatibility, ret=%d, compatibility=%d\n",
info ? info->module_name : "Unknown", ret, compatibility);
- /**
- * FIXME:
- * Do not return error but just print warning for now. Need time to
- * deploy compatibility manifest to all hal modules.
- *
- * return -ELIBBAD;
- */
+ return -ELIBBAD;
}
return 0;
#include "hal-common-interface.h"
#include "hal-api-common-hook.h"
#include "../../src/hal-api-conf.h"
-#include "../../src/hal-api-list.h"
+#include "../../src/common.h"
/*
* All hal-backend-[module] (e.g., tbm/tdm/audio/camera/devcie/power etc)
static int hal_backend_exit(void *data) { return 0; }
static hal_backend hal_backend_module_data[HAL_MODULE_END];
+static char *g_orig_manifest[HAL_MODULE_END];
/*
* hal-api-common uses the dlopen/dlsym/dlclose/access to load/unload
return HAL_MODULE_UNKNOWN;
for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) {
- struct __hal_module_info *info = &g_hal_module_info[module];
-
- if (info->library_name
- && strncmp(info->library_name,
- library_name, strlen(info->library_name) + 1) == 0)
- return module;
-
- if (info->library_name_64bit
- && strncmp(info->library_name_64bit,
- library_name, strlen(info->library_name_64bit) + 1) == 0)
+ if (_hal_api_conf_get_module_info(module, basename((char *) library_name)))
return module;
}
return HAL_MODULE_UNKNOWN;
}
-int set_module_info_manifest(const char *our_directory)
+int set_module_info_manifest(enum hal_module our_module, const char *our_directory)
{
int ret;
+ struct __hal_module_info *info = NULL;
+ char *orig_manifest = NULL;
if (!our_directory)
return -1;
_hal_api_conf_init();
- for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) {
- struct __hal_module_info *info = _hal_api_conf_get_module_info(module, NULL);
- char *orig_manifest = NULL;
-
- if (!info) {
- _hal_api_conf_exit();
- return -1;
- }
-
- orig_manifest = info->manifest;
- if (!orig_manifest)
- continue;
-
- /* We sneak into the data structure and modify it to what we want */
- ret = asprintf(&info->manifest,
- "%s%s", our_directory, strrchr(orig_manifest, '/'));
- if (ret == -1) {
- _hal_api_conf_exit();
- return -1;
- }
+ info = _hal_api_conf_get_module_info(our_module, NULL);
+
+ if (!info) {
+ _hal_api_conf_exit();
+ return -1;
}
+ orig_manifest = info->manifest;
+ if (!orig_manifest) {
+ _hal_api_conf_exit();
+ return -1;
+ }
+
+ /* We sneak into the data structure and modify it to what we want */
+ ret = asprintf(&info->manifest,
+ "%s%s", our_directory, strrchr(orig_manifest, '/'));
+ if (ret == -1) {
+ _hal_api_conf_exit();
+ return -1;
+ }
+
+ g_orig_manifest[our_module] = orig_manifest;
+
_hal_api_conf_exit();
return 0;
}
-int unset_module_info_manifest(void)
+int set_module_info_manifest_all(const char *our_directory)
{
- int ret;
+ for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module)
+ set_module_info_manifest(module, our_directory);
+
+ return 0;
+}
+
+int unset_module_info_manifest(enum hal_module our_module)
+{
+ struct __hal_module_info *info = NULL;
+ char *modified_manifest = NULL;
_hal_api_conf_init();
- for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module) {
- struct __hal_module_info *info = _hal_api_conf_get_module_info(module, NULL);
- char *orig_manifest = NULL;
-
- if (!info) {
- _hal_api_conf_exit();
- return -1;
- }
-
- orig_manifest = info->manifest;
- if (!orig_manifest)
- continue;
-
- /* Put it back to the original */
- ret = asprintf(&info->manifest,
- "/etc/hal%s", strrchr(orig_manifest, '/'));
- if (ret == -1) {
- _hal_api_conf_exit();
- return -1;
- }
-
- free(orig_manifest);
- orig_manifest = NULL;
+ info = _hal_api_conf_get_module_info(our_module, NULL);
+
+ if (!info || !info->manifest) {
+ _hal_api_conf_exit();
+ return -1;
}
+ modified_manifest = info->manifest;
+
+ /* Put it back to the original */
+ info->manifest = g_orig_manifest[our_module];
+
+ free(modified_manifest);
+ modified_manifest = NULL;
+
_hal_api_conf_exit();
return 0;
}
+int unset_module_info_manifest_all(void)
+{
+ for (enum hal_module module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module)
+ unset_module_info_manifest(module);
+
+ return 0;
+}
+
void mock_hal_backend_data_set_version(enum hal_module module,
unsigned int major, unsigned int minor)
{
*/
#define ACCESS_DO_NOT_HOOK (ACCESS_UNUSED_MODES & -ACCESS_UNUSED_MODES)
-int set_module_info_manifest(const char *our_directory);
-int unset_module_info_manifest(void);
+int set_module_info_manifest(enum hal_module our_module, const char *our_directory);
+int set_module_info_manifest_all(const char *our_directory);
+int unset_module_info_manifest(enum hal_module our_module);
+int unset_module_info_manifest_all(void);
void mock_hal_backend_data_set_version(enum hal_module module,
unsigned int major, unsigned int minor);
void mock_hal_backend_data_unset_version(enum hal_module module);
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_AUDIO</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_BLUETOOTH</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_CAMERA</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_CODEC</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_BATTERY</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_BEZEL</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_DISPLAY</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_IR</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_TOUCHSCREEN</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_LED</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_BOARD</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_EXTERNAL_CONNECTION</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_THERMAL</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_HAPTIC</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_MEMORY</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_INPUT</name>
+ <version>1.0</version>
+ </hal-module>
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_POWER</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_LOCATION</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_NFC</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_POWER</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_RADIO</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_SENSOR</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_TBM</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_TDM</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_WIFI</name>
+ <version>1.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
#include "hal-common.h"
#include "hal-common-interface.h"
+#include "hal-api-common-hook.h"
#include "../../src/hal-api-conf.h"
#include "../../src/common.h"
library_name_64bit_(library_name_64bit), symbol_name_(symbol_name) {}
};
-class HalInfoMatchedTest : public ::testing::TestWithParam<HalInfo> {};
+class HalInfoMatchedTest : public ::testing::TestWithParam<HalInfo> {
+ void SetUp() override {
+ const auto &info = GetParam();
+ int ret = 0;
+ char *modified_manifest_path = NULL;
+
+ /* mock backend library version with 1.0 */
+ mock_hal_backend_data_set_version(info.module_, 1, 0);
+
+ /* set directory for hal manifest mock */
+ ret = asprintf(&modified_manifest_path,
+ "%s/%s", getcwd(NULL, 0), "test-hal-api-common-manifest");
+ if (ret < 0)
+ return;
+
+ set_module_info_manifest(info.module_, modified_manifest_path);
+ modified_manifest_path = NULL; /* don't free. consumed by set_module_info_manifest() */
+ }
+
+ void TearDown() override {
+ const auto &info = GetParam();
+ unset_module_info_manifest(info.module_);
+ mock_hal_backend_data_unset_version(info.module_);
+ }
+};
INSTANTIATE_TEST_CASE_P(HalApiCommonTest,
HalInfoMatchedTest,
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_DISPLAY</name>
+ <version>1.2</version>
+ </hal-module>
+ </manifest>
+ <manifest platform-version="10.0">
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_DISPLAY</name>
+ <version>2.0</version>
+ </hal-module>
+ </manifest>
+ <manifest platform-version="11.0">
+ <hal-module>
+ <name>HAL_MODULE_DEVICE_DISPLAY</name>
+ <version>2.1</version>
+ <version>3.0</version>
+ </hal-module>
+ </manifest>
+</hal-api>
+
--- /dev/null
+<hal-api>
+ <manifest platform-version="9.0">
+ <hal-module>
+ <name>HAL_MODULE_TDM</name>
+ <version>5.5</version>
+ </hal-module>
+ </manifest>
+ <manifest platform-version="10.0">
+ <hal-module>
+ <name>HAL_MODULE_TDM</name>
+ <version>5.5</version>
+ </hal-module>
+ </manifest>
+ <manifest platform-version="11.0">
+ <hal-module>
+ <name>HAL_MODULE_TDM</name>
+ <version>5.5</version>
+ </hal-module>
+ </manifest>
+</hal-api>
+
if (!g_cwd)
FAIL();
- ret = asprintf(&g_manifest_directory, "%s/%s", g_cwd, "test-hal-manifest");
+ ret = asprintf(&g_manifest_directory, "%s/%s", g_cwd, "test-hal-compatibility-checker-manifest");
if (ret == -1)
FAIL();
- set_module_info_manifest(g_manifest_directory);
+ set_module_info_manifest_all(g_manifest_directory);
ret = asprintf(&g_compatibility_result_path, "%s/.hal-backend-compatibility", g_cwd);
if (ret == -1)
for (int module = HAL_MODULE_UNKNOWN; module < HAL_MODULE_END; ++module)
mock_hal_backend_data_unset_version((enum hal_module) module);
unlink(g_compatibility_result_path);
- unset_module_info_manifest();
+ unset_module_info_manifest_all();
hal_api_cc_unset_compatibility_loaded_path();
free(g_compatibility_loaded_path);
free(g_compatibility_result_path);
+++ /dev/null
-<hal-api>
- <manifest platform-version="9.0">
- <hal-module>
- <name>HAL_MODULE_DEVICE_DISPLAY</name>
- <version>1.2</version>
- </hal-module>
- </manifest>
- <manifest platform-version="10.0">
- <hal-module>
- <name>HAL_MODULE_DEVICE_DISPLAY</name>
- <version>2.0</version>
- </hal-module>
- </manifest>
- <manifest platform-version="11.0">
- <hal-module>
- <name>HAL_MODULE_DEVICE_DISPLAY</name>
- <version>2.1</version>
- <version>3.0</version>
- </hal-module>
- </manifest>
-</hal-api>
-
+++ /dev/null
-<hal-api>
- <manifest platform-version="9.0">
- <hal-module>
- <name>HAL_MODULE_TDM</name>
- <version>5.5</version>
- </hal-module>
- </manifest>
- <manifest platform-version="10.0">
- <hal-module>
- <name>HAL_MODULE_TDM</name>
- <version>5.5</version>
- </hal-module>
- </manifest>
- <manifest platform-version="11.0">
- <hal-module>
- <name>HAL_MODULE_TDM</name>
- <version>5.5</version>
- </hal-module>
- </manifest>
-</hal-api>
-