Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50b66767 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

fix [3237242] sensormanager sensor active count gets out of sync

whether a physical sensor needed to be active or not was managed by
a simpe reference counter; unfortunatelly nothing prevented it to
get out of sync if a sensor was disabled more than once.

sensorservice already maintainted a list of all the "clients"
connected to a physical sensor; we now use that list to determine if
a sensor should be enabled. This can never be "out-of-sync" since
this is the only data structure linking a sensor to a user of that
sensor.

also removed the isEnabled() method, which was never used and
implemented wrongly (since it didn't take into account that a sensor
could be disabled for a client but not of another).

Change-Id: I789affb877728ca957e99f7ba749def37c4db1c7
parent 87c9dbb7
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -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;
        }
+0 −2
Original line number Diff line number Diff line
@@ -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;
+0 −4
Original line number Diff line number Diff line
@@ -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);
}
+0 −1
Original line number Diff line number Diff line
@@ -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;
+5 −13
Original line number Diff line number Diff line
@@ -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,20 +132,13 @@ 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;
    }
    }
    return NO_ERROR;
}

Loading