Brian Stack | c9ef483 | 2018-09-14 11:59:18 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | #ifndef ANDROID_SENSORS_WRAPPER_H |
| 18 | #define ANDROID_SENSORS_WRAPPER_H |
| 19 | |
| 20 | #include "android/hardware/sensors/1.0/ISensors.h" |
| 21 | #include "android/hardware/sensors/2.0/ISensors.h" |
| 22 | |
| 23 | #include <utils/LightRefBase.h> |
| 24 | |
| 25 | namespace android { |
| 26 | namespace SensorServiceUtil { |
| 27 | |
| 28 | using ::android::hardware::MQDescriptorSync; |
| 29 | using ::android::hardware::Return; |
| 30 | using ::android::hardware::sensors::V1_0::Event; |
| 31 | using ::android::hardware::sensors::V1_0::ISensors; |
| 32 | using ::android::hardware::sensors::V1_0::OperationMode; |
| 33 | using ::android::hardware::sensors::V1_0::RateLevel; |
| 34 | using ::android::hardware::sensors::V1_0::Result; |
| 35 | using ::android::hardware::sensors::V1_0::SharedMemInfo; |
| 36 | |
| 37 | /* |
| 38 | * The ISensorsWrapper interface includes all function from supported Sensors HAL versions. This |
| 39 | * allows for the SensorDevice to use the ISensorsWrapper interface to interact with the Sensors |
| 40 | * HAL regardless of the current version of the Sensors HAL that is loaded. Each concrete |
| 41 | * instantiation of ISensorsWrapper must correspond to a specific Sensors HAL version. This design |
| 42 | * is beneficial because only the functions that change between Sensors HAL versions must be newly |
| 43 | * newly implemented, any previously implemented function that does not change may remain the same. |
| 44 | * |
| 45 | * Functions that exist across all versions of the Sensors HAL should be implemented as pure |
| 46 | * virtual functions which forces the concrete instantiations to implement the functions. |
| 47 | * |
| 48 | * Functions that do not exist across all versions of the Sensors HAL should include a default |
| 49 | * implementation that generates an error if called. The default implementation should never |
| 50 | * be called and must be overridden by Sensors HAL versions that support the function. |
| 51 | */ |
| 52 | class ISensorsWrapper : public VirtualLightRefBase { |
| 53 | public: |
| 54 | virtual bool supportsPolling() const = 0; |
| 55 | |
| 56 | virtual bool supportsMessageQueues() const = 0; |
| 57 | |
| 58 | virtual Return<void> getSensorsList(ISensors::getSensorsList_cb _hidl_cb) = 0; |
| 59 | |
| 60 | virtual Return<Result> setOperationMode(OperationMode mode) = 0; |
| 61 | |
| 62 | virtual Return<Result> activate(int32_t sensorHandle, bool enabled) = 0; |
| 63 | |
| 64 | virtual Return<Result> batch(int32_t sensorHandle, int64_t samplingPeriodNs, |
| 65 | int64_t maxReportLatencyNs) = 0; |
| 66 | |
| 67 | virtual Return<Result> flush(int32_t sensorHandle) = 0; |
| 68 | |
| 69 | virtual Return<Result> injectSensorData(const Event& event) = 0; |
| 70 | |
| 71 | virtual Return<void> registerDirectChannel(const SharedMemInfo& mem, |
| 72 | ISensors::registerDirectChannel_cb _hidl_cb) = 0; |
| 73 | |
| 74 | virtual Return<Result> unregisterDirectChannel(int32_t channelHandle) = 0; |
| 75 | |
| 76 | virtual Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, |
| 77 | RateLevel rate, |
| 78 | ISensors::configDirectReport_cb _hidl_cb) = 0; |
| 79 | |
| 80 | virtual Return<void> poll(int32_t maxCount, ISensors::poll_cb _hidl_cb) { |
| 81 | (void)maxCount; |
| 82 | (void)_hidl_cb; |
| 83 | // TODO (b/111070257): Generate an assert-level error since this should never be called |
| 84 | // directly |
| 85 | return Return<void>(); |
| 86 | } |
| 87 | |
| 88 | virtual Return<Result> initializeMessageQueues(const MQDescriptorSync<Event>& eventQueueDesc, |
| 89 | const MQDescriptorSync<uint32_t>& wakeLockDesc) { |
| 90 | (void)eventQueueDesc; |
| 91 | (void)wakeLockDesc; |
| 92 | // TODO (b/111070257): Generate an assert-level error since this should never be called |
| 93 | // directly |
| 94 | return Result::INVALID_OPERATION; |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | }; // namespace SensorServiceUtil |
| 99 | }; // namespace android |
| 100 | |
| 101 | #endif // ANDROID_SENSORS_WRAPPER_H |