/* * Copyright (C) 2020 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_HARDWARE_SENSORS_V2_0_SENSORS_SUBHAL_H #define ANDROID_HARDWARE_SENSORS_V2_0_SENSORS_SUBHAL_H #include #include "Sensor.h" #include "SubHal.h" using ::android::hardware::sensors::V1_0::SensorType; namespace android { namespace hardware { namespace sensors { namespace V2_0 { namespace subhal { namespace implementation { using ::android::hardware::sensors::V1_0::OperationMode; using ::android::hardware::sensors::V1_0::Result; using ::android::hardware::sensors::V2_0::implementation::IHalProxyCallback; using ::android::hardware::sensors::V2_0::subhal::implementation::ISensorsEventCallback; using ::sensor::hal::configuration::V1_0::Configuration; /** * Implementation of a ISensorsSubHal that can be used as a reference HAL implementation of sensors * multihal 2.0. See the README file for more details. */ class SensorsSubHal : public ISensorsSubHal, public ISensorsEventCallback { using Event = ::android::hardware::sensors::V1_0::Event; using RateLevel = ::android::hardware::sensors::V1_0::RateLevel; using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo; public: SensorsSubHal(); // Methods from ::android::hardware::sensors::V2_0::ISensors follow. Return getSensorsList(getSensorsList_cb _hidl_cb) override; Return setOperationMode(OperationMode mode) override; OperationMode getOperationMode() const { return mCurrentOperationMode; } Return activate(int32_t sensorHandle, bool enabled) override; Return batch(int32_t sensorHandle, int64_t samplingPeriodNs, int64_t maxReportLatencyNs) override; Return flush(int32_t sensorHandle) override; Return injectSensorData(const Event& event) override; Return registerDirectChannel(const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) override; Return unregisterDirectChannel(int32_t channelHandle) override; Return configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate, configDirectReport_cb _hidl_cb) override; Return debug(const hidl_handle& fd, const hidl_vec& args) override; // Methods from ::android::hardware::sensors::V2_0::implementation::ISensorsSubHal follow. const std::string getName() override { return "Google-IIO-SensorsSubhal"; } Return initialize(const sp& halProxyCallback) override; // Method from ISensorsEventCallback. void postEvents(const std::vector& events, bool wakeup) override; protected: void AddSensor(const struct iio_device_data& iio_data, const std::optional>& config); /** * A map of the available sensors */ std::map> mSensors; /** * Callback used to communicate to the HalProxy when dynamic sensors are connected / * disconnected, sensor events need to be sent to the framework, and when a wakelock should be * acquired. */ sp mCallback; private: /** * The current operation mode of the multihal framework. Ensures that all subhals are set to * the same operation mode. */ OperationMode mCurrentOperationMode = OperationMode::NORMAL; /** * The next available sensor handle */ int32_t mNextHandle; }; } // namespace implementation } // namespace subhal } // namespace V2_0 } // namespace sensors } // namespace hardware } // namespace android #endif