Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7a70f32f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Multihal 2.0 - Implement SubHal discovery"

parents 0fe5a0e8 2879067d
Loading
Loading
Loading
Loading
+40 −1
Original line number Diff line number Diff line
@@ -18,12 +18,19 @@

#include <android/hardware/sensors/2.0/types.h>

#include <dlfcn.h>

#include <fstream>
#include <functional>

namespace android {
namespace hardware {
namespace sensors {
namespace V2_0 {
namespace implementation {

typedef ISensorsSubHal*(SensorsHalGetSubHalFunc)(uint32_t*);

// TODO: Use this wake lock name as the prefix to all sensors HAL wake locks acquired.
// constexpr const char* kWakeLockName = "SensorsHAL_WAKEUP";

@@ -62,7 +69,39 @@ class SensorsCallbackProxy : public ISensorsCallback {
};

HalProxy::HalProxy() {
    // TODO: Initialize all sub-HALs and discover sensors.
    const char* kMultiHalConfigFilePath = "/vendor/etc/sensors/hals.conf";
    std::ifstream subHalConfigStream(kMultiHalConfigFilePath);
    if (!subHalConfigStream) {
        LOG_FATAL("Failed to load subHal config file: %s", kMultiHalConfigFilePath);
    } else {
        std::string subHalLibraryFile;
        while (subHalConfigStream >> subHalLibraryFile) {
            void* handle = dlopen(subHalLibraryFile.c_str(), RTLD_NOW);
            if (handle == nullptr) {
                LOG_FATAL("dlopen failed for library: %s", subHalLibraryFile.c_str());
            } else {
                SensorsHalGetSubHalFunc* sensorsHalGetSubHalPtr =
                        (SensorsHalGetSubHalFunc*)dlsym(handle, "sensorsHalGetSubHal");
                if (sensorsHalGetSubHalPtr == nullptr) {
                    LOG_FATAL("Failed to locate sensorsHalGetSubHal function for library: %s",
                              subHalLibraryFile.c_str());
                } else {
                    std::function<SensorsHalGetSubHalFunc> sensorsHalGetSubHal =
                            *sensorsHalGetSubHalPtr;
                    uint32_t version;
                    ISensorsSubHal* subHal = sensorsHalGetSubHal(&version);
                    if (version != SUB_HAL_2_0_VERSION) {
                        LOG_FATAL("SubHal version was not 2.0 for library: %s",
                                  subHalLibraryFile.c_str());
                    } else {
                        ALOGI("Loaded SubHal from library: %s", subHalLibraryFile.c_str());
                        mSubHalList.push_back(subHal);
                    }
                }
            }
        }
    }
    // TODO: Discover sensors
}

HalProxy::~HalProxy() {
+5 −0
Original line number Diff line number Diff line
@@ -111,6 +111,11 @@ struct HalProxy : public ISensors {
     * Callback to the sensors framework to inform it that new sensors have been added or removed.
     */
    sp<ISensorsCallback> mDynamicSensorsCallback;

    /**
     * SubHal object pointers that have been saved from vendor dynamic libraries.
     */
    std::vector<ISensorsSubHal*> mSubHalList;
};

}  // namespace implementation
+1 −1

File changed.

Contains only whitespace changes.