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

Commit 667102f6 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

improve sensorservice dumpsys

Change-Id: I8b53d5cab884c3aca16d95df5fbf288368d52e8b
parent b9e15263
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -167,6 +167,9 @@ Fusion::Fusion() {
    Bm.y = 1;
    Bm.z = 0;

    x0 = 0;
    x1 = 0;

    init();
}

+43 −27
Original line number Diff line number Diff line
@@ -138,9 +138,18 @@ 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\n",
        const Info& info = mActivationCount.valueFor(list[i].handle);
        snprintf(buffer, SIZE, "handle=0x%08x, active-count=%d, rates(ms)={ ",
                list[i].handle,
                mActivationCount.valueFor(list[i].handle).rates.size());
                info.rates.size());
        result.append(buffer);
        for (size_t j=0 ; j<info.rates.size() ; j++) {
            snprintf(buffer, SIZE, "%4.1f%s",
                    info.rates.valueAt(j) / 1e6f,
                    j<info.rates.size()-1 ? ", " : "");
            result.append(buffer);
        }
        snprintf(buffer, SIZE, " }, selected=%4.1f ms\n",  info.delay / 1e6f);
        result.append(buffer);
    }
}
@@ -217,17 +226,9 @@ status_t SensorDevice::activate(void* ident, int handle, int enabled)
        }
    }

    if (!actuateHardware || enabled) {
    { // scope for the lock
        Mutex::Autolock _l(mLock);
        nsecs_t ns = info.rates.valueAt(0);
        for (size_t i=1 ; i<info.rates.size() ; i++) {
            if (info.rates.valueAt(i) < ns) {
                nsecs_t cur = info.rates.valueAt(i);
                if (cur < ns) {
                    ns = cur;
                }
            }
        }
        nsecs_t ns = info.selectDelay();
        mSensorDevice->setDelay(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;
    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 ; i<info.rates.size() ; i++) {
            nsecs_t cur = info.rates.valueAt(i);
            if (cur < ns) {
                ns = cur;
    Info& info( mActivationCount.editValueFor(handle) );
    status_t err = info.setDelayForIdent(ident, ns);
    if (err < 0) return err;
    ns = info.selectDelay();
    return mSensorDevice->setDelay(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;
}

    //LOGD("setDelay: ident=%p, handle=%d, ns=%lld", ident, handle, ns);

    return mSensorDevice->setDelay(mSensorDevice, handle, ns);
nsecs_t SensorDevice::Info::selectDelay()
{
    nsecs_t ns = rates.valueAt(0);
    for (size_t i=1 ; i<rates.size() ; i++) {
        nsecs_t cur = rates.valueAt(i);
        if (cur < ns) {
            ns = cur;
        }
    }
    delay = ns;
    return ns;
}

// ---------------------------------------------------------------------------
+5 −2
Original line number Diff line number Diff line
@@ -37,11 +37,14 @@ class SensorDevice : public Singleton<SensorDevice> {
    friend class Singleton<SensorDevice>;
    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<void*, nsecs_t> rates;
        nsecs_t delay;
        status_t setDelayForIdent(void* ident, int64_t ns);
        nsecs_t selectDelay();
    };
    DefaultKeyedVector<int, Info> mActivationCount;