Sensors: MultiHal: Add HIDL-based Multi-Hal
Add the ability to use more than a single sensor HAL
to the HIDL sensor service.
Bug: 32022308
Change-Id: I99866adbbbee6d93350327aaaba136682ae069ae
diff --git a/sensors/1.0/default/Android.bp b/sensors/1.0/default/Android.bp
index 7fbe117..994febe 100644
--- a/sensors/1.0/default/Android.bp
+++ b/sensors/1.0/default/Android.bp
@@ -8,7 +8,6 @@
"libhardware",
"libhwbinder",
"libbase",
- "libcutils",
"libutils",
"libhidlbase",
"libhidltransport",
@@ -16,6 +15,7 @@
],
static_libs: [
"android.hardware.sensors@1.0-convert",
+ "multihal",
],
local_include_dirs: ["include/sensors"],
}
@@ -30,7 +30,6 @@
"libhardware",
"libhwbinder",
"libbase",
- "libcutils",
"libutils",
"libhidlbase",
"libhidltransport",
diff --git a/sensors/1.0/default/Android.mk b/sensors/1.0/default/Android.mk
index b2b2c60..f37c3cb 100644
--- a/sensors/1.0/default/Android.mk
+++ b/sensors/1.0/default/Android.mk
@@ -5,21 +5,21 @@
LOCAL_MODULE := android.hardware.sensors@1.0-service
LOCAL_INIT_RC := android.hardware.sensors@1.0-service.rc
LOCAL_SRC_FILES := \
- service.cpp \
+ service.cpp \
LOCAL_SHARED_LIBRARIES := \
- liblog \
- libcutils \
- libdl \
- libbase \
- libutils \
- libhardware_legacy \
- libhardware \
+ liblog \
+ libcutils \
+ libdl \
+ libbase \
+ libutils \
+ libhardware_legacy \
+ libhardware \
LOCAL_SHARED_LIBRARIES += \
- libhwbinder \
- libhidlbase \
- libhidltransport \
- android.hardware.sensors@1.0 \
+ libhwbinder \
+ libhidlbase \
+ libhidltransport \
+ android.hardware.sensors@1.0 \
include $(BUILD_EXECUTABLE)
diff --git a/sensors/1.0/default/Sensors.cpp b/sensors/1.0/default/Sensors.cpp
index ef052c3..c76369f 100644
--- a/sensors/1.0/default/Sensors.cpp
+++ b/sensors/1.0/default/Sensors.cpp
@@ -15,17 +15,29 @@
*/
#include "Sensors.h"
-
#include "convert.h"
+#include "multihal.h"
#include <android-base/logging.h>
+#include <sys/stat.h>
+
namespace android {
namespace hardware {
namespace sensors {
namespace V1_0 {
namespace implementation {
+/*
+ * If a multi-hal configuration file exists in the proper location,
+ * return true indicating we need to use multi-hal functionality.
+ */
+static bool UseMultiHal() {
+ const std::string& name = MULTI_HAL_CONFIG_FILE_PATH;
+ struct stat buffer;
+ return (stat (name.c_str(), &buffer) == 0);
+}
+
static Result ResultFromStatus(status_t err) {
switch (err) {
case OK:
@@ -43,10 +55,14 @@
: mInitCheck(NO_INIT),
mSensorModule(nullptr),
mSensorDevice(nullptr) {
- status_t err = hw_get_module(
+ status_t err = OK;
+ if (UseMultiHal()) {
+ mSensorModule = ::get_multi_hal_module_info();
+ } else {
+ err = hw_get_module(
SENSORS_HARDWARE_MODULE_ID,
(hw_module_t const **)&mSensorModule);
-
+ }
if (mSensorModule == NULL) {
err = UNKNOWN_ERROR;
}