From 667102f6b072582fe497599e0b760f9fc94ceffa Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 14 Sep 2011 16:43:34 -0700 Subject: [PATCH] improve sensorservice dumpsys Change-Id: I8b53d5cab884c3aca16d95df5fbf288368d52e8b --- services/sensorservice/Fusion.cpp | 3 ++ services/sensorservice/SensorDevice.cpp | 70 +++++++++++++++---------- services/sensorservice/SensorDevice.h | 7 ++- 3 files changed, 51 insertions(+), 29 deletions(-) diff --git a/services/sensorservice/Fusion.cpp b/services/sensorservice/Fusion.cpp index 0ab86c3e7..d76f19c1a 100644 --- a/services/sensorservice/Fusion.cpp +++ b/services/sensorservice/Fusion.cpp @@ -167,6 +167,9 @@ Fusion::Fusion() { Bm.y = 1; Bm.z = 0; + x0 = 0; + x1 = 0; + init(); } diff --git a/services/sensorservice/SensorDevice.cpp b/services/sensorservice/SensorDevice.cpp index 38d498c06..d82a7e238 100644 --- a/services/sensorservice/SensorDevice.cpp +++ b/services/sensorservice/SensorDevice.cpp @@ -138,9 +138,18 @@ void SensorDevice::dump(String8& result, char* buffer, size_t SIZE) Mutex::Autolock _l(mLock); for (size_t i=0 ; isetDelay(mSensorDevice, handle, ns); } @@ -237,24 +238,39 @@ status_t SensorDevice::activate(void* ident, int handle, int enabled) status_t SensorDevice::setDelay(void* ident, int handle, int64_t ns) { if (!mSensorDevice) return NO_INIT; + Mutex::Autolock _l(mLock); Info& info( mActivationCount.editValueFor(handle) ); - { // scope for lock - Mutex::Autolock _l(mLock); - ssize_t index = info.rates.indexOfKey(ident); - if (index < 0) return BAD_INDEX; - info.rates.editValueAt(index) = ns; - ns = info.rates.valueAt(0); - for (size_t i=1 ; isetDelay(mSensorDevice, handle, ns); +} + +// --------------------------------------------------------------------------- + +status_t SensorDevice::Info::setDelayForIdent(void* ident, int64_t ns) +{ + ssize_t index = rates.indexOfKey(ident); + if (index < 0) { + LOGE("Info::setDelayForIdent(ident=%p, ns=%lld) failed (%s)", + ident, ns, strerror(-index)); + return BAD_INDEX; + } + rates.editValueAt(index) = ns; + return NO_ERROR; +} + +nsecs_t SensorDevice::Info::selectDelay() +{ + nsecs_t ns = rates.valueAt(0); + for (size_t i=1 ; isetDelay(mSensorDevice, handle, ns); + delay = ns; + return ns; } // --------------------------------------------------------------------------- diff --git a/services/sensorservice/SensorDevice.h b/services/sensorservice/SensorDevice.h index c19b2ced4..728b6cb86 100644 --- a/services/sensorservice/SensorDevice.h +++ b/services/sensorservice/SensorDevice.h @@ -37,11 +37,14 @@ class SensorDevice : public Singleton { friend class Singleton; struct sensors_poll_device_t* mSensorDevice; struct sensors_module_t* mSensorModule; - Mutex mLock; // protect mActivationCount[].rates + mutable Mutex mLock; // protect mActivationCount[].rates // fixed-size array after construction struct Info { - Info() { } + Info() : delay(0) { } KeyedVector rates; + nsecs_t delay; + status_t setDelayForIdent(void* ident, int64_t ns); + nsecs_t selectDelay(); }; DefaultKeyedVector mActivationCount;