Cosmin Tanislav | 75fd635 | 2022-02-16 22:14:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <vector> |
| 20 | |
| 21 | #include "Sensor.h" |
| 22 | #include "V2_1/SubHal.h" |
| 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace sensors { |
| 27 | namespace V2_1 { |
| 28 | namespace subhal { |
| 29 | namespace implementation { |
| 30 | |
| 31 | using ::android::hardware::sensors::V1_0::OperationMode; |
| 32 | using ::android::hardware::sensors::V1_0::RateLevel; |
| 33 | using ::android::hardware::sensors::V1_0::Result; |
| 34 | using ::android::hardware::sensors::V1_0::SharedMemInfo; |
| 35 | using ::android::hardware::sensors::V2_1::Event; |
| 36 | using ::android::hardware::sensors::V2_1::implementation::IHalProxyCallback; |
| 37 | using ::android::hardware::sensors::V2_1::implementation::ISensorsSubHal; |
| 38 | |
| 39 | class SensorsSubHal : public ISensorsSubHal, public ISensorsEventCallback { |
| 40 | public: |
| 41 | SensorsSubHal(); |
| 42 | |
| 43 | Return<void> getSensorsList_2_1(ISensors::getSensorsList_2_1_cb _hidl_cb); |
| 44 | Return<Result> injectSensorData_2_1(const Event& event); |
| 45 | Return<Result> initialize(const sp<IHalProxyCallback>& halProxyCallback); |
| 46 | |
| 47 | virtual Return<Result> setOperationMode(OperationMode mode); |
| 48 | |
| 49 | OperationMode getOperationMode() const { return mCurrentOperationMode; } |
| 50 | |
| 51 | Return<Result> activate(int32_t sensorHandle, bool enabled); |
| 52 | |
| 53 | Return<Result> batch(int32_t sensorHandle, int64_t samplingPeriodNs, int64_t maxReportLatencyNs); |
| 54 | |
| 55 | Return<Result> flush(int32_t sensorHandle); |
| 56 | |
| 57 | Return<void> registerDirectChannel(const SharedMemInfo& mem, |
| 58 | ISensors::registerDirectChannel_cb _hidl_cb); |
| 59 | |
| 60 | Return<Result> unregisterDirectChannel(int32_t channelHandle); |
| 61 | |
| 62 | Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate, |
| 63 | ISensors::configDirectReport_cb _hidl_cb); |
| 64 | |
| 65 | Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args); |
| 66 | |
| 67 | const std::string getName() { return "FakeSubHal"; } |
| 68 | |
| 69 | void postEvents(const std::vector<Event>& events, bool wakeup) override; |
| 70 | |
| 71 | protected: |
| 72 | template <class SensorType> |
| 73 | void AddSensor() { |
| 74 | std::shared_ptr<SensorType> sensor = |
| 75 | std::make_shared<SensorType>(mNextHandle++ /* sensorHandle */, this /* callback */); |
| 76 | mSensors[sensor->getSensorInfo().sensorHandle] = sensor; |
| 77 | } |
| 78 | |
| 79 | std::map<int32_t, std::shared_ptr<Sensor>> mSensors; |
| 80 | |
| 81 | sp<IHalProxyCallback> mCallback; |
| 82 | |
| 83 | private: |
| 84 | OperationMode mCurrentOperationMode = OperationMode::NORMAL; |
| 85 | |
| 86 | int32_t mNextHandle; |
| 87 | }; |
| 88 | |
| 89 | } // namespace implementation |
| 90 | } // namespace subhal |
| 91 | } // namespace V2_1 |
| 92 | } // namespace sensors |
| 93 | } // namespace hardware |
| 94 | } // namespace android |