X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=services%2Fsensorservice%2FSensorDevice.h;h=fd6cee67ea914dde2a54a35a28b5e53b8d1ac809;hb=0249b61e4d58191847ec2d14dc8a43b07cb5c4d0;hp=d340da31c1d10b312d802666254c19db6c70a9fe;hpb=912ff8af49167529afd18d0c9d1da958a544b36b;p=android-x86%2Fframeworks-native.git diff --git a/services/sensorservice/SensorDevice.h b/services/sensorservice/SensorDevice.h index d340da31c1..fd6cee67ea 100644 --- a/services/sensorservice/SensorDevice.h +++ b/services/sensorservice/SensorDevice.h @@ -19,27 +19,66 @@ #include "SensorServiceUtils.h" -#include +#include +#include +#include #include #include #include -#include -#include +#include +#include +#include //std::max std::min + +#include "android/hardware/sensors/1.0/ISensors.h" + +#include "RingBuffer.h" // --------------------------------------------------------------------------- namespace android { + // --------------------------------------------------------------------------- using SensorServiceUtil::Dumpable; +using hardware::Return; class SensorDevice : public Singleton, public Dumpable { public: + + class HidlTransportErrorLog { + public: + + HidlTransportErrorLog() { + mTs = 0; + mCount = 0; + } + + HidlTransportErrorLog(time_t ts, int count) { + mTs = ts; + mCount = count; + } + + String8 toString() const { + String8 result; + struct tm *timeInfo = localtime(&mTs); + result.appendFormat("%02d:%02d:%02d :: %d", timeInfo->tm_hour, timeInfo->tm_min, + timeInfo->tm_sec, mCount); + return result; + } + + private: + time_t mTs; // timestamp of the error + int mCount; // number of transport errors observed + }; + ssize_t getSensorList(sensor_t const** list); + void handleDynamicSensorConnection(int handle, bool connected); status_t initCheck() const; int getHalDeviceVersion() const; + ssize_t poll(sensors_event_t* buffer, size_t count); + status_t activate(void* ident, int handle, int enabled); status_t batch(void* ident, int handle, int flags, int64_t samplingPeriodNs, int64_t maxBatchReportLatencyNs); @@ -47,9 +86,17 @@ public: status_t setDelay(void* ident, int handle, int64_t ns); status_t flush(void* ident, int handle); status_t setMode(uint32_t mode); + + bool isDirectReportSupported() const; + int32_t registerDirectChannel(const sensors_direct_mem_t *memory); + void unregisterDirectChannel(int32_t channelHandle); + int32_t configureDirectChannel(int32_t sensorHandle, + int32_t channelHandle, const struct sensors_direct_cfg_t *config); + void disableAllSensors(); void enableAllSensors(); void autoDisable(void *ident, int handle); + status_t injectSensorData(const sensors_event_t *event); void notifyConnectionDestroyed(void *ident); @@ -57,8 +104,11 @@ public: virtual std::string dump() const; private: friend class Singleton; - sensors_poll_device_1_t* mSensorDevice; - struct sensors_module_t* mSensorModule; + + sp mSensors; + Vector mSensorList; + std::unordered_map mConnectedDynamicSensors; + static const nsecs_t MINIMUM_EVENTS_PERIOD = 1000000; // 1000 Hz mutable Mutex mLock; // protect mActivationCount[].batchParams // fixed-size array after construction @@ -66,15 +116,18 @@ private: // Struct to store all the parameters(samplingPeriod, maxBatchReportLatency and flags) from // batch call. For continous mode clients, maxBatchReportLatency is set to zero. struct BatchParams { - // TODO: Get rid of flags parameter everywhere. - int flags; - nsecs_t batchDelay, batchTimeout; - BatchParams() : flags(0), batchDelay(0), batchTimeout(0) {} - BatchParams(int flag, nsecs_t delay, nsecs_t timeout): flags(flag), batchDelay(delay), - batchTimeout(timeout) { } + nsecs_t mTSample, mTBatch; + BatchParams() : mTSample(INT64_MAX), mTBatch(INT64_MAX) {} + BatchParams(nsecs_t tSample, nsecs_t tBatch): mTSample(tSample), mTBatch(tBatch) {} bool operator != (const BatchParams& other) { - return other.batchDelay != batchDelay || other.batchTimeout != batchTimeout || - other.flags != flags; + return !(mTSample == other.mTSample && mTBatch == other.mTBatch); + } + // Merge another parameter with this one. The updated mTSample will be the min of the two. + // The update mTBatch will be the min of original mTBatch and the apparent batch period + // of the other. the apparent batch is the maximum of mTBatch and mTSample, + void merge(const BatchParams &other) { + mTSample = std::min(mTSample, other.mTSample); + mTBatch = std::min(mTBatch, std::max(other.mTBatch, other.mTSample)); } }; @@ -90,7 +143,6 @@ private: // requested by the client. KeyedVector batchParams; - Info() : bestBatchParams(0, -1, -1) {} // Sets batch parameters for this ident. Returns error if this ident is not already present // in the KeyedVector above. status_t setBatchParamsForIdent(void* ident, int flags, int64_t samplingPeriodNs, @@ -105,12 +157,38 @@ private: }; DefaultKeyedVector mActivationCount; + // Keep track of any hidl transport failures + SensorServiceUtil::RingBuffer mHidlTransportErrors; + int mTotalHidlTransportErrors; + // Use this vector to determine which client is activated or deactivated. SortedVector mDisabledClients; SensorDevice(); + bool connectHidlService(); + + static void handleHidlDeath(const std::string &detail); + template + static Return checkReturn(Return &&ret) { + if (!ret.isOk()) { + handleHidlDeath(ret.description()); + } + return std::move(ret); + } bool isClientDisabled(void* ident); bool isClientDisabledLocked(void* ident); + + using Event = hardware::sensors::V1_0::Event; + using SensorInfo = hardware::sensors::V1_0::SensorInfo; + + void convertToSensorEvent(const Event &src, sensors_event_t *dst); + + void convertToSensorEvents( + const hardware::hidl_vec &src, + const hardware::hidl_vec &dynamicSensorsAdded, + sensors_event_t *dst); + + bool mIsDirectReportSupported; }; // ---------------------------------------------------------------------------