summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2010-11-30 15:51:00 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2010-11-30 15:51:00 -0800
commit3248b484a246f18853c284d6705b1cb9c2e52d77 (patch)
tree768bc46a9f6d1fc4b34c385a3d0f1e888f436299 /services
parentbe0ece6f855ee2ab52309b6633def90ddeab38ee (diff)
parentb483d5cd134cda393824fd8e9c1a5443bd868ae6 (diff)
downloadframeworks_base-3248b484a246f18853c284d6705b1cb9c2e52d77.zip
frameworks_base-3248b484a246f18853c284d6705b1cb9c2e52d77.tar.gz
frameworks_base-3248b484a246f18853c284d6705b1cb9c2e52d77.tar.bz2
am b483d5cd: fix [3237242] sensormanager sensor active count gets out of sync
* commit 'b483d5cd134cda393824fd8e9c1a5443bd868ae6': fix [3237242] sensormanager sensor active count gets out of sync
Diffstat (limited to 'services')
-rw-r--r--services/sensorservice/GravitySensor.cpp8
-rw-r--r--services/sensorservice/GravitySensor.h2
-rw-r--r--services/sensorservice/LinearAccelerationSensor.cpp4
-rw-r--r--services/sensorservice/LinearAccelerationSensor.h1
-rw-r--r--services/sensorservice/RotationVectorSensor.cpp18
-rw-r--r--services/sensorservice/RotationVectorSensor.h2
-rw-r--r--services/sensorservice/SensorDevice.cpp22
-rw-r--r--services/sensorservice/SensorDevice.h3
-rw-r--r--services/sensorservice/SensorInterface.cpp13
-rw-r--r--services/sensorservice/SensorInterface.h3
10 files changed, 22 insertions, 54 deletions
diff --git a/services/sensorservice/GravitySensor.cpp b/services/sensorservice/GravitySensor.cpp
index da72f9c..5c6aa99 100644
--- a/services/sensorservice/GravitySensor.cpp
+++ b/services/sensorservice/GravitySensor.cpp
@@ -29,7 +29,7 @@ namespace android {
GravitySensor::GravitySensor(sensor_t const* list, size_t count)
: mSensorDevice(SensorDevice::getInstance()),
- mEnabled(false), mAccTime(0),
+ mAccTime(0),
mLowPass(M_SQRT1_2, 1.5f),
mX(mLowPass), mY(mLowPass), mZ(mLowPass)
@@ -71,15 +71,9 @@ bool GravitySensor::process(sensors_event_t* outEvent,
}
return false;
}
-
-bool GravitySensor::isEnabled() const {
- return mEnabled;
-}
-
status_t GravitySensor::activate(void* ident, bool enabled) {
status_t err = mSensorDevice.activate(this, mAccelerometer.getHandle(), enabled);
if (err == NO_ERROR) {
- mEnabled = enabled;
if (enabled) {
mAccTime = 0;
}
diff --git a/services/sensorservice/GravitySensor.h b/services/sensorservice/GravitySensor.h
index ff3bea7..decfbb8 100644
--- a/services/sensorservice/GravitySensor.h
+++ b/services/sensorservice/GravitySensor.h
@@ -33,7 +33,6 @@ namespace android {
class GravitySensor : public SensorInterface {
SensorDevice& mSensorDevice;
Sensor mAccelerometer;
- bool mEnabled;
double mAccTime;
SecondOrderLowPassFilter mLowPass;
@@ -43,7 +42,6 @@ public:
GravitySensor(sensor_t const* list, size_t count);
virtual bool process(sensors_event_t* outEvent,
const sensors_event_t& event);
- virtual bool isEnabled() const;
virtual status_t activate(void* ident, bool enabled);
virtual status_t setDelay(void* ident, int handle, int64_t ns);
virtual Sensor getSensor() const;
diff --git a/services/sensorservice/LinearAccelerationSensor.cpp b/services/sensorservice/LinearAccelerationSensor.cpp
index 2dc12dc..9425a92 100644
--- a/services/sensorservice/LinearAccelerationSensor.cpp
+++ b/services/sensorservice/LinearAccelerationSensor.cpp
@@ -53,10 +53,6 @@ bool LinearAccelerationSensor::process(sensors_event_t* outEvent,
return result;
}
-bool LinearAccelerationSensor::isEnabled() const {
- return mGravitySensor.isEnabled();
-}
-
status_t LinearAccelerationSensor::activate(void* ident, bool enabled) {
return mGravitySensor.activate(ident, enabled);
}
diff --git a/services/sensorservice/LinearAccelerationSensor.h b/services/sensorservice/LinearAccelerationSensor.h
index ee918ce..c577086 100644
--- a/services/sensorservice/LinearAccelerationSensor.h
+++ b/services/sensorservice/LinearAccelerationSensor.h
@@ -40,7 +40,6 @@ class LinearAccelerationSensor : public SensorInterface {
const sensors_event_t& event);
public:
LinearAccelerationSensor(sensor_t const* list, size_t count);
- virtual bool isEnabled() const;
virtual status_t activate(void* ident, bool enabled);
virtual status_t setDelay(void* ident, int handle, int64_t ns);
virtual Sensor getSensor() const;
diff --git a/services/sensorservice/RotationVectorSensor.cpp b/services/sensorservice/RotationVectorSensor.cpp
index 50cd6be..418e7f8 100644
--- a/services/sensorservice/RotationVectorSensor.cpp
+++ b/services/sensorservice/RotationVectorSensor.cpp
@@ -34,7 +34,6 @@ static inline T clamp(T v) {
RotationVectorSensor::RotationVectorSensor(sensor_t const* list, size_t count)
: mSensorDevice(SensorDevice::getInstance()),
- mEnabled(false),
mALowPass(M_SQRT1_2, 5.0f),
mAX(mALowPass), mAY(mALowPass), mAZ(mALowPass),
mMLowPass(M_SQRT1_2, 2.5f),
@@ -133,19 +132,12 @@ bool RotationVectorSensor::process(sensors_event_t* outEvent,
return false;
}
-bool RotationVectorSensor::isEnabled() const {
- return mEnabled;
-}
-
status_t RotationVectorSensor::activate(void* ident, bool enabled) {
- if (mEnabled != enabled) {
- mSensorDevice.activate(this, mAcc.getHandle(), enabled);
- mSensorDevice.activate(this, mMag.getHandle(), enabled);
- mEnabled = enabled;
- if (enabled) {
- mMagTime = 0;
- mAccTime = 0;
- }
+ mSensorDevice.activate(this, mAcc.getHandle(), enabled);
+ mSensorDevice.activate(this, mMag.getHandle(), enabled);
+ if (enabled) {
+ mMagTime = 0;
+ mAccTime = 0;
}
return NO_ERROR;
}
diff --git a/services/sensorservice/RotationVectorSensor.h b/services/sensorservice/RotationVectorSensor.h
index e7f28c9..b7c9512 100644
--- a/services/sensorservice/RotationVectorSensor.h
+++ b/services/sensorservice/RotationVectorSensor.h
@@ -34,7 +34,6 @@ class RotationVectorSensor : public SensorInterface {
SensorDevice& mSensorDevice;
Sensor mAcc;
Sensor mMag;
- bool mEnabled;
float mMagData[3];
double mAccTime;
double mMagTime;
@@ -47,7 +46,6 @@ public:
RotationVectorSensor(sensor_t const* list, size_t count);
virtual bool process(sensors_event_t* outEvent,
const sensors_event_t& event);
- virtual bool isEnabled() const;
virtual status_t activate(void* ident, bool enabled);
virtual status_t setDelay(void* ident, int handle, int64_t ns);
virtual Sensor getSensor() const;
diff --git a/services/sensorservice/SensorDevice.cpp b/services/sensorservice/SensorDevice.cpp
index 73f85ba..f192913 100644
--- a/services/sensorservice/SensorDevice.cpp
+++ b/services/sensorservice/SensorDevice.cpp
@@ -137,9 +137,8 @@ void SensorDevice::dump(String8& result, char* buffer, size_t SIZE)
Mutex::Autolock _l(mLock);
for (size_t i=0 ; i<size_t(count) ; i++) {
- snprintf(buffer, SIZE, "handle=0x%08x, active-count=%d / %d\n",
+ snprintf(buffer, SIZE, "handle=0x%08x, active-count=%d\n",
list[i].handle,
- mActivationCount.valueFor(list[i].handle).count,
mActivationCount.valueFor(list[i].handle).rates.size());
result.append(buffer);
}
@@ -167,22 +166,25 @@ status_t SensorDevice::activate(void* ident, int handle, int enabled)
bool actuateHardware = false;
Info& info( mActivationCount.editValueFor(handle) );
- int32_t& count(info.count);
if (enabled) {
- if (android_atomic_inc(&count) == 0) {
- actuateHardware = true;
- }
Mutex::Autolock _l(mLock);
if (info.rates.indexOfKey(ident) < 0) {
info.rates.add(ident, DEFAULT_EVENTS_PERIOD);
- }
- } else {
- if (android_atomic_dec(&count) == 1) {
actuateHardware = true;
+ } else {
+ // sensor was already activated for this ident
}
+ } else {
Mutex::Autolock _l(mLock);
- info.rates.removeItem(ident);
+ if (info.rates.removeItem(ident) >= 0) {
+ if (info.rates.size() == 0) {
+ actuateHardware = true;
+ }
+ } else {
+ // sensor wasn't enabled for this ident
+ }
}
+
if (actuateHardware) {
err = mSensorDevice->activate(mSensorDevice, handle, enabled);
if (enabled) {
diff --git a/services/sensorservice/SensorDevice.h b/services/sensorservice/SensorDevice.h
index 63ecbcd..c19b2ce 100644
--- a/services/sensorservice/SensorDevice.h
+++ b/services/sensorservice/SensorDevice.h
@@ -40,8 +40,7 @@ class SensorDevice : public Singleton<SensorDevice> {
Mutex mLock; // protect mActivationCount[].rates
// fixed-size array after construction
struct Info {
- Info() : count(0) { }
- int32_t count;
+ Info() { }
KeyedVector<void*, nsecs_t> rates;
};
DefaultKeyedVector<int, Info> mActivationCount;
diff --git a/services/sensorservice/SensorInterface.cpp b/services/sensorservice/SensorInterface.cpp
index 93d23d9..be8eaff 100644
--- a/services/sensorservice/SensorInterface.cpp
+++ b/services/sensorservice/SensorInterface.cpp
@@ -32,7 +32,7 @@ SensorInterface::~SensorInterface()
HardwareSensor::HardwareSensor(const sensor_t& sensor)
: mSensorDevice(SensorDevice::getInstance()),
- mSensor(&sensor), mEnabled(false)
+ mSensor(&sensor)
{
LOGI("%s", sensor.name);
}
@@ -46,15 +46,8 @@ bool HardwareSensor::process(sensors_event_t* outEvent,
return true;
}
-bool HardwareSensor::isEnabled() const {
- return mEnabled;
-}
-
-status_t HardwareSensor::activate(void* ident,bool enabled) {
- status_t err = mSensorDevice.activate(ident, mSensor.getHandle(), enabled);
- if (err == NO_ERROR)
- mEnabled = enabled;
- return err;
+status_t HardwareSensor::activate(void* ident, bool enabled) {
+ return mSensorDevice.activate(ident, mSensor.getHandle(), enabled);
}
status_t HardwareSensor::setDelay(void* ident, int handle, int64_t ns) {
diff --git a/services/sensorservice/SensorInterface.h b/services/sensorservice/SensorInterface.h
index eebd563..084f2f5 100644
--- a/services/sensorservice/SensorInterface.h
+++ b/services/sensorservice/SensorInterface.h
@@ -38,7 +38,6 @@ public:
virtual bool process(sensors_event_t* outEvent,
const sensors_event_t& event) = 0;
- virtual bool isEnabled() const = 0;
virtual status_t activate(void* ident, bool enabled) = 0;
virtual status_t setDelay(void* ident, int handle, int64_t ns) = 0;
virtual Sensor getSensor() const = 0;
@@ -51,7 +50,6 @@ class HardwareSensor : public SensorInterface
{
SensorDevice& mSensorDevice;
Sensor mSensor;
- bool mEnabled;
public:
HardwareSensor(const sensor_t& sensor);
@@ -61,7 +59,6 @@ public:
virtual bool process(sensors_event_t* outEvent,
const sensors_event_t& event);
- virtual bool isEnabled() const;
virtual status_t activate(void* ident, bool enabled);
virtual status_t setDelay(void* ident, int handle, int64_t ns);
virtual Sensor getSensor() const;