1 /* 2 * Copyright (C) 2015 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 SENSORS_H_ 18 #define SENSORS_H_ 19 20 #include <hardware/hardware.h> 21 #include <hardware/sensors.h> 22 #include <media/stagefright/foundation/ABase.h> 23 #include <utils/RefBase.h> 24 25 #include <memory> 26 #include <unordered_set> 27 #include <vector> 28 29 namespace android { 30 namespace SensorHalExt { 31 class DynamicSensorManager; 32 } // namespace BaseSensorObject 33 } // namespace android 34 35 using android::SensorHalExt::DynamicSensorManager; 36 37 class SensorContext { 38 public: 39 struct sensors_poll_device_1 device; 40 41 explicit SensorContext(const struct hw_module_t *module); 42 43 size_t getSensorList(sensor_t const **list); 44 45 private: 46 47 int close(); 48 int activate(int handle, int enabled); 49 int setDelay(int handle, int64_t delayNs); 50 int poll(sensors_event_t *data, int count); 51 52 int batch(int handle, int64_t sampling_period_ns, 53 int64_t max_report_latency_ns); 54 55 int flush(int handle); 56 57 // static wrappers 58 static int CloseWrapper(struct hw_device_t *dev); 59 60 static int ActivateWrapper( 61 struct sensors_poll_device_t *dev, int handle, int enabled); 62 63 static int SetDelayWrapper( 64 struct sensors_poll_device_t *dev, int handle, int64_t delayNs); 65 66 static int PollWrapper( 67 struct sensors_poll_device_t *dev, sensors_event_t *data, int count); 68 69 static int BatchWrapper( 70 struct sensors_poll_device_1 *dev, 71 int handle, 72 int flags, 73 int64_t sampling_period_ns, 74 int64_t max_report_latency_ns); 75 76 static int FlushWrapper(struct sensors_poll_device_1 *dev, int handle); 77 78 static constexpr int32_t kDynamicHandleBase = 0x10000; 79 static constexpr int32_t kDynamicHandleEnd = 0x1000000; 80 static constexpr int32_t kMaxDynamicHandleCount = kDynamicHandleEnd - kDynamicHandleBase; 81 82 std::unique_ptr<DynamicSensorManager> mDynamicSensorManager; 83 84 DISALLOW_EVIL_CONSTRUCTORS(SensorContext); 85 }; 86 87 #endif // SENSORS_H_ 88