From b42bde95cb9d5716e2918c432f71863c1719fcc6 Mon Sep 17 00:00:00 2001 From: Stan Rokita Date: Tue, 28 Apr 2020 17:12:13 -0700 Subject: [PATCH] Search for subhal .so files in additional directories Fixes: 154634207 Test: Load onto flame and confirm that subhal .so android.hardware.sensors@2.X-fakesubhal-config3.so loads when it is living in the /vendor/lib64/hw directory using adb shell lshal debug android.hardware.sensors@2.0::ISensors/default Change-Id: I8a676b97f6f6992e8937ecf31c3b7af06e676ebb Merged-In: I8a676b97f6f6992e8937ecf31c3b7af06e676ebb --- sensors/2.0/multihal/HalProxy.cpp | 21 ++++++++++++++++++++- sensors/2.0/multihal/include/HalProxy.h | 10 ++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/sensors/2.0/multihal/HalProxy.cpp b/sensors/2.0/multihal/HalProxy.cpp index ac6f17a484..fbff24ceac 100644 --- a/sensors/2.0/multihal/HalProxy.cpp +++ b/sensors/2.0/multihal/HalProxy.cpp @@ -360,7 +360,7 @@ void HalProxy::initializeSubHalListFromConfigFile(const char* configFileName) { } else { std::string subHalLibraryFile; while (subHalConfigStream >> subHalLibraryFile) { - void* handle = dlopen(subHalLibraryFile.c_str(), RTLD_NOW); + void* handle = getHandleForSubHalSharedObject(subHalLibraryFile); if (handle == nullptr) { ALOGE("dlopen failed for library: %s", subHalLibraryFile.c_str()); } else { @@ -415,6 +415,25 @@ void HalProxy::initializeSensorList() { } } +void* HalProxy::getHandleForSubHalSharedObject(const std::string& filename) { + static const std::string kSubHalShareObjectLocations[] = { + "", // Default locations will be searched +#ifdef __LP64__ + "/vendor/lib64/hw/", "/odm/lib64/", "/odm/lib64/hw/" +#else + "/vendor/lib/hw/", "/odm/lib/", "/odm/lib/hw/" +#endif + }; + + for (const std::string& dir : kSubHalShareObjectLocations) { + void* handle = dlopen((dir + filename).c_str(), RTLD_NOW); + if (handle != nullptr) { + return handle; + } + } + return nullptr; +} + void HalProxy::init() { initializeSubHalCallbacks(); initializeSensorList(); diff --git a/sensors/2.0/multihal/include/HalProxy.h b/sensors/2.0/multihal/include/HalProxy.h index 978f7cf1ba..10bba55198 100644 --- a/sensors/2.0/multihal/include/HalProxy.h +++ b/sensors/2.0/multihal/include/HalProxy.h @@ -261,6 +261,16 @@ class HalProxy : public ISensors, public IScopedWakelockRefCounter { */ void initializeSensorList(); + /** + * Try using the default include directories as well as the directories defined in + * kSubHalShareObjectLocations to get a handle for dlsym for a subhal. + * + * @param filename The file name to search for. + * + * @return The handle or nullptr if search failed. + */ + void* getHandleForSubHalSharedObject(const std::string& filename); + /** * Calls the helper methods that all ctors use. */