1 /* 2 * Copyright (C) 2017 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_DUMMY_DYNAMIC_ACCEL_DAEMON_H 18 #define ANDROID_SENSORHAL_EXT_DUMMY_DYNAMIC_ACCEL_DAEMON_H 19 20 #include "BaseDynamicSensorDaemon.h" 21 #include "BaseSensorObject.h" 22 23 #include <hardware/sensors.h> 24 #include <utils/Thread.h> 25 #include <mutex> 26 #include <unordered_set> 27 28 namespace android { 29 namespace SensorHalExt { 30 31 class ConnectionDetector; 32 33 /** 34 * This daemon simulates dynamic sensor connection without the need of actually connect peripheral 35 * to Android. It is for debugging and testing. It can handle one concurrent connections at maximum. 36 */ 37 class DummyDynamicAccelDaemon : public BaseDynamicSensorDaemon { 38 public: 39 DummyDynamicAccelDaemon(DynamicSensorManager& manager); 40 virtual ~DummyDynamicAccelDaemon() = default; 41 private: 42 class DummySensor : public BaseSensorObject, public Thread { 43 public: 44 DummySensor(const std::string &name); 45 ~DummySensor(); 46 virtual const sensor_t* getSensor() const; 47 virtual void getUuid(uint8_t* uuid) const; 48 virtual int enable(bool enable); 49 virtual int batch(nsecs_t sample_period, nsecs_t batch_period); 50 private: 51 // implement Thread function 52 virtual bool threadLoop() override; 53 54 void waitUntilNextSample(); 55 56 sensor_t mSensor; 57 std::string mSensorName; 58 59 std::mutex mLock; 60 std::mutex mRunLock; 61 bool mRunState; 62 }; 63 // implement BaseDynamicSensorDaemon function 64 virtual BaseSensorVector createSensor(const std::string &deviceKey) override; 65 66 sp<ConnectionDetector> mFileDetector; 67 sp<ConnectionDetector> mSocketDetector; 68 }; 69 } // namespace SensorHalExt 70 } // namespace android 71 72 #endif // ANDROID_SENSORHAL_EXT_DYNAMIC_SENSOR_DAEMON_H 73 74