diff --git a/modules/sensors/dynamic_sensor/Android.bp b/modules/sensors/dynamic_sensor/Android.bp index 1ebc04d2..3f424b51 100644 --- a/modules/sensors/dynamic_sensor/Android.bp +++ b/modules/sensors/dynamic_sensor/Android.bp @@ -108,7 +108,18 @@ cc_library_shared { cflags: ["-DLOG_TAG=\"DynamicSensorHal\""], - srcs: ["sensors.cpp"], + srcs: [ + "DynamicSensorsSubHal.cpp", + "sensors.cpp", + ], + shared_libs: [ + "android.hardware.sensors@2.0", + "android.hardware.sensors@2.1", + "libhidlbase", + ], + header_libs: [ + "android.hardware.sensors@2.X-multihal.header", + ], } // diff --git a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp new file mode 100644 index 00000000..df636a3b --- /dev/null +++ b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "DynamicSensorsSubHal.h" + +#include +#include + +using ::android::hardware::sensors::V1_0::Result; +template using Return = ::android::hardware::Return; +using ::android::hardware::Void; + +namespace android { +namespace SensorHalExt { + +// ISensors. +Return DynamicSensorsSubHal::setOperationMode(OperationMode mode) { + return (mode == static_cast(SENSOR_HAL_NORMAL_MODE) ? + Result::OK : Result::BAD_VALUE); +} + +Return DynamicSensorsSubHal::activate(int32_t sensor_handle __unused, + bool enabled __unused) { + ALOGE("DynamicSensorsSubHal::activate not supported."); + + return Result::INVALID_OPERATION; +} + +Return DynamicSensorsSubHal::batch( + int32_t sensor_handle __unused, int64_t sampling_period_ns __unused, + int64_t max_report_latency_ns __unused) { + ALOGE("DynamicSensorsSubHal::batch not supported."); + + return Result::INVALID_OPERATION; +} + +Return DynamicSensorsSubHal::flush(int32_t sensor_handle __unused) { + ALOGE("DynamicSensorsSubHal::flush not supported."); + + return Result::INVALID_OPERATION; +} + +Return DynamicSensorsSubHal::registerDirectChannel( + const SharedMemInfo& mem __unused, + registerDirectChannel_cb callback __unused) { + ALOGE("DynamicSensorsSubHal::registerDirectChannel not supported."); + + return Void(); +} + +Return DynamicSensorsSubHal::unregisterDirectChannel( + int32_t channel_handle __unused) { + ALOGE("DynamicSensorsSubHal::unregisterDirectChannel not supported."); + + return Result::INVALID_OPERATION; +} + +Return DynamicSensorsSubHal::configDirectReport( + int32_t sensor_handle __unused, int32_t channel_handle __unused, + RateLevel rate __unused, configDirectReport_cb callback __unused) { + ALOGE("DynamicSensorsSubHal::configDirectReport not supported."); + + return Void(); +} + +Return DynamicSensorsSubHal::getSensorsList_2_1( + getSensorsList_2_1_cb callback __unused) { + ALOGD("DynamicSensorsSubHal::getSensorsList_2_1 invoked."); + + return Void(); +} + +Return DynamicSensorsSubHal::injectSensorData_2_1( + const Event& event __unused) { + ALOGE("DynamicSensorsSubHal::injectSensorData_2_1 not supported."); + + return Result::INVALID_OPERATION; +} + +Return DynamicSensorsSubHal::debug( + const hidl_handle& handle __unused, + const hidl_vec& args __unused) { + return Void(); +} + +// ISensorsSubHal. +Return DynamicSensorsSubHal::initialize( + const sp& hal_proxy_callback __unused) { + ALOGD("DynamicSensorsSubHal::initialize invoked."); + + return Result::OK; +} + +} // namespace SensorHalExt +} // namespace android + +using ::android::hardware::sensors::V2_1::implementation::ISensorsSubHal; +ISensorsSubHal* sensorsHalGetSubHal_2_1(uint32_t* version) { + static android::SensorHalExt::DynamicSensorsSubHal subHal; + + *version = SUB_HAL_2_1_VERSION; + return &subHal; +} + diff --git a/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.h b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.h new file mode 100644 index 00000000..36ed9f5a --- /dev/null +++ b/modules/sensors/dynamic_sensor/DynamicSensorsSubHal.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_SENSORHAL_EXT_DYNAMIC_SENSORS_SUB_HAL_H +#define ANDROID_SENSORHAL_EXT_DYNAMIC_SENSORS_SUB_HAL_H + +#include + +namespace android { +namespace SensorHalExt { + +class DynamicSensorsSubHal : + public ::android::hardware::sensors::V2_1::implementation::ISensorsSubHal { + using Event = ::android::hardware::sensors::V2_1::Event; + using hidl_handle = ::android::hardware::hidl_handle; + using hidl_string = ::android::hardware::hidl_string; + template using hidl_vec = ::android::hardware::hidl_vec; + using IHalProxyCallback = + ::android::hardware::sensors::V2_1::implementation::IHalProxyCallback; + using OperationMode = ::android::hardware::sensors::V1_0::OperationMode; + using RateLevel = ::android::hardware::sensors::V1_0::RateLevel; + using Result = ::android::hardware::sensors::V1_0::Result; + template using Return = ::android::hardware::Return; + using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo; + +public: + // 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, + registerDirectChannel_cb callback) override; + Return unregisterDirectChannel(int32_t channel_handle) override; + Return configDirectReport( + int32_t sensor_handle, int32_t channel_handle, RateLevel rate, + configDirectReport_cb callback) override; + Return getSensorsList_2_1(getSensorsList_2_1_cb callback) override; + Return injectSensorData_2_1(const Event& event) override; + Return debug( + const hidl_handle& handle, + const hidl_vec& args) override; + + // ISensorsSubHal. + const std::string getName() override { return "Dynamic-SubHAL"; } + Return initialize( + const sp& hal_proxy_callback) override; +}; + +} // namespace SensorHalExt +} // namespace android + +#endif // ANDROID_SENSORHAL_EXT_DYNAMIC_SENSORS_SUB_HAL_H +