diff --git a/.clang-format b/.clang-format new file mode 120000 index 0000000..973b2fa --- /dev/null +++ b/.clang-format @@ -0,0 +1 @@ +../../../build/soong/scripts/system-clang-format \ No newline at end of file diff --git a/common.mk b/common.mk index a3b28ff..8b96787 100644 --- a/common.mk +++ b/common.mk @@ -310,7 +310,8 @@ PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \ android.hardware.sensors-service.multihal \ sensors.dynamic_sensor_hal \ - sensors.oplus + sensors.oplus \ + sensors.qsh_wrapper PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/configs/hals.conf:$(TARGET_COPY_OUT_VENDOR)/etc/sensors/hals.conf diff --git a/configs/hals.conf b/configs/hals.conf index c87c2cf..0232db9 100644 --- a/configs/hals.conf +++ b/configs/hals.conf @@ -1,3 +1,3 @@ sensors.dynamic_sensor_hal.so sensors.oplus.so -sensors.qsh.so +sensors.qsh_wrapper.so diff --git a/sensors/Android.bp b/sensors/Android.bp new file mode 100644 index 0000000..85b1e69 --- /dev/null +++ b/sensors/Android.bp @@ -0,0 +1,27 @@ +// +// Copyright (C) 2025 The LineageOS Project +// +// SPDX-License-Identifier: Apache-2.0 +// + +cc_library_shared { + name: "sensors.qsh_wrapper", + defaults: ["hidl_defaults"], + srcs: [ + "SensorsSubHal.cpp", + ], + shared_libs: [ + "android.hardware.sensors@2.0", + "android.hardware.sensors@2.1", + "libbase", + "libhidlbase", + "libutils", + ], + header_libs: [ + "android.hardware.sensors@2.X-multihal.header", + ], + cflags: [ + "-DLOG_TAG=\"sensors.qsh_wrapper\"", + ], + vendor: true, +} diff --git a/sensors/SensorsSubHal.cpp b/sensors/SensorsSubHal.cpp new file mode 100644 index 0000000..f1a14ed --- /dev/null +++ b/sensors/SensorsSubHal.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2025 The LineageOS Project + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "SensorsSubHal.h" + +#include +#include + +using ::android::hardware::sensors::V2_1::implementation::ISensorsSubHal; + +namespace android { +namespace hardware { +namespace sensors { +namespace V2_1 { +namespace subhal { +namespace implementation { +namespace qsh_wrapper { + +namespace { +constexpr auto kLibName = "sensors.qsh.so"; +}; // anonymous namespace + +SensorsSubHal::SensorsSubHal() + : lib_handle_(dlopen(kLibName, RTLD_NOW), [](void* p) { + if (p) dlclose(p); + }) { + if (!lib_handle_) { + LOG(FATAL) << __func__ << ": dlopen " << kLibName << " failed, exiting"; + } + + auto get_sub_hal = reinterpret_cast( + dlsym(lib_handle_.get(), "sensorsHalGetSubHal_2_1")); + uint32_t version; + impl_ = get_sub_hal(&version); +} + +Return SensorsSubHal::setOperationMode(OperationMode mode) { + return impl_->setOperationMode(mode); +} + +Return SensorsSubHal::activate(int32_t sensor_handle, bool enabled) { + return impl_->activate(sensor_handle, enabled); +} + +Return SensorsSubHal::batch(int32_t sensor_handle, int64_t sampling_period_ns, + int64_t max_report_latency_ns) { + return impl_->batch(sensor_handle, sampling_period_ns, max_report_latency_ns); +} + +Return SensorsSubHal::flush(int32_t sensor_handle) { + return impl_->flush(sensor_handle); +} + +Return SensorsSubHal::registerDirectChannel(const SharedMemInfo& mem, + ISensors::registerDirectChannel_cb _hidl_cb) { + return impl_->registerDirectChannel(mem, _hidl_cb); +} + +Return SensorsSubHal::unregisterDirectChannel(int32_t channel_handle) { + return impl_->unregisterDirectChannel(channel_handle); +} + +Return SensorsSubHal::configDirectReport(int32_t sensor_handle, int32_t channel_handle, + RateLevel rate, + ISensors::configDirectReport_cb _hidl_cb) { + return impl_->configDirectReport(sensor_handle, channel_handle, rate, _hidl_cb); +} + +Return SensorsSubHal::getSensorsList_2_1(ISensors::getSensorsList_2_1_cb _hidl_cb) { + return impl_->getSensorsList_2_1(_hidl_cb); +} + +Return SensorsSubHal::injectSensorData_2_1(const Event& event) { + return impl_->injectSensorData_2_1(event); +} + +Return SensorsSubHal::debug(const hidl_handle& fd, const hidl_vec& args) { + return impl_->debug(fd, args); +} + +const std::string SensorsSubHal::getName() { + return impl_->getName(); +} + +Return SensorsSubHal::initialize(const sp& hal_proxy_callback) { + return impl_->initialize(hal_proxy_callback); +} + +} // namespace qsh_wrapper +} // namespace implementation +} // namespace subhal +} // namespace V2_1 +} // namespace sensors +} // namespace hardware +} // namespace android + +ISensorsSubHal* sensorsHalGetSubHal_2_1(uint32_t* version) { + static ::android::hardware::sensors::V2_1::subhal::implementation::qsh_wrapper::SensorsSubHal + sub_hal; + *version = SUB_HAL_2_1_VERSION; + return &sub_hal; +} diff --git a/sensors/SensorsSubHal.h b/sensors/SensorsSubHal.h new file mode 100644 index 0000000..849e79c --- /dev/null +++ b/sensors/SensorsSubHal.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2025 The LineageOS Project + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +namespace android { +namespace hardware { +namespace sensors { +namespace V2_1 { +namespace subhal { +namespace implementation { +namespace qsh_wrapper { + +using ::android::hardware::sensors::V1_0::OperationMode; +using ::android::hardware::sensors::V1_0::RateLevel; +using ::android::hardware::sensors::V1_0::Result; +using ::android::hardware::sensors::V1_0::SharedMemInfo; +using ::android::hardware::sensors::V2_1::Event; +using ::android::hardware::sensors::V2_1::implementation::IHalProxyCallback; +using ::android::hardware::sensors::V2_1::implementation::ISensorsSubHal; + +class SensorsSubHal : public ISensorsSubHal { + public: + SensorsSubHal(); + + // ISensors + Return setOperationMode(OperationMode mode) override; + Return activate(int32_t sensor_handle, bool enabled) override; + Return batch(int32_t sensor_handle, int64_t sampling_period_ns, + int64_t max_report_latency_ns) override; + Return flush(int32_t sensor_handle) override; + Return registerDirectChannel(const SharedMemInfo& mem, + ISensors::registerDirectChannel_cb _hidl_cb) override; + Return unregisterDirectChannel(int32_t channel_handle) override; + Return configDirectReport(int32_t sensor_handle, int32_t channel_handle, RateLevel rate, + ISensors::configDirectReport_cb _hidl_cb) override; + Return getSensorsList_2_1(ISensors::getSensorsList_2_1_cb _hidl_cb) override; + Return injectSensorData_2_1(const Event& event) override; + + // ISensorsSubHal + Return debug(const hidl_handle& fd, const hidl_vec& args) override; + const std::string getName() override; + Return initialize(const sp& hal_proxy_callback) override; + + private: + std::unique_ptr> lib_handle_; + V2_1::implementation::ISensorsSubHal* impl_; +}; + +} // namespace qsh_wrapper +} // namespace implementation +} // namespace subhal +} // namespace V2_1 +} // namespace sensors +} // namespace hardware +} // namespace android