1 /* 2 * Copyright (C) 2021 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_SENSORHAL_EXT_DYNAMIC_SENSORS_SUB_HAL_H 18 #define ANDROID_SENSORHAL_EXT_DYNAMIC_SENSORS_SUB_HAL_H 19 20 #include "DynamicSensorManager.h" 21 22 #include <V2_1/SubHal.h> 23 24 namespace android { 25 namespace SensorHalExt { 26 27 class DynamicSensorsSubHal : 28 public SensorEventCallback, 29 public ::android::hardware::sensors::V2_1::implementation::ISensorsSubHal { 30 using Event = ::android::hardware::sensors::V2_1::Event; 31 using hidl_handle = ::android::hardware::hidl_handle; 32 using hidl_string = ::android::hardware::hidl_string; 33 template<class T> using hidl_vec = ::android::hardware::hidl_vec<T>; 34 using IHalProxyCallback = 35 ::android::hardware::sensors::V2_1::implementation::IHalProxyCallback; 36 using OperationMode = ::android::hardware::sensors::V1_0::OperationMode; 37 using RateLevel = ::android::hardware::sensors::V1_0::RateLevel; 38 using Result = ::android::hardware::sensors::V1_0::Result; 39 template<class T> using Return = ::android::hardware::Return<T>; 40 using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo; 41 42 public: 43 DynamicSensorsSubHal(); 44 45 // ISensors. 46 Return<Result> setOperationMode(OperationMode mode) override; 47 Return<Result> activate(int32_t sensor_handle, bool enabled) override; 48 Return<Result> batch(int32_t sensor_handle, int64_t sampling_period_ns, 49 int64_t max_report_latency_ns) override; 50 Return<Result> flush(int32_t sensor_handle) override; 51 Return<void> registerDirectChannel( 52 const SharedMemInfo& mem, 53 registerDirectChannel_cb callback) override; 54 Return<Result> unregisterDirectChannel(int32_t channel_handle) override; 55 Return<void> configDirectReport( 56 int32_t sensor_handle, int32_t channel_handle, RateLevel rate, 57 configDirectReport_cb callback) override; 58 Return<void> getSensorsList_2_1(getSensorsList_2_1_cb callback) override; 59 Return<Result> injectSensorData_2_1(const Event& event) override; 60 Return<void> debug( 61 const hidl_handle& handle, 62 const hidl_vec<hidl_string>& args) override; 63 64 // ISensorsSubHal. getName()65 const std::string getName() override { return "Dynamic-SubHAL"; } 66 Return<Result> initialize( 67 const sp<IHalProxyCallback>& hal_proxy_callback) override; 68 69 // SensorEventCallback. 70 int submitEvent(SP(BaseSensorObject) sensor, 71 const sensors_event_t& e) override; 72 73 private: 74 static constexpr int32_t kDynamicHandleBase = 1; 75 static constexpr int32_t kDynamicHandleEnd = 0x1000000; 76 static constexpr int32_t kMaxDynamicHandleCount = kDynamicHandleEnd - 77 kDynamicHandleBase; 78 79 void onSensorConnected(int handle, const sensor_t* sensor_info); 80 void onSensorDisconnected(int handle); 81 82 std::unique_ptr<DynamicSensorManager> mDynamicSensorManager; 83 sp<IHalProxyCallback> mHalProxyCallback; 84 }; 85 86 } // namespace SensorHalExt 87 } // namespace android 88 89 #endif // ANDROID_SENSORHAL_EXT_DYNAMIC_SENSORS_SUB_HAL_H 90 91