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

Commit 3cc2c359 authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Fix logical error in UID idle/active handling

There is a bug where the sensor is not properly deactivated
when ann app becomes idle. This CL fixes the issue, and also
avoids calling batch() if no active clients exist.

Bug: 157934995
Test: Flash, verify sensor is disabled when app goes idle
and re-enabled when app becomes active again

Change-Id: I403b02a20dc89c5ce0630de6ddfd6242bf38ec37
parent b31d3c81
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -820,7 +820,7 @@ status_t SensorDevice::updateBatchParamsLocked(int handle, Info &info) {

    status_t err(NO_ERROR);
    // If the min period or min timeout has changed since the last batch call, call batch.
    if (prevBestBatchParams != info.bestBatchParams) {
    if (prevBestBatchParams != info.bestBatchParams && info.numActiveClients() > 0) {
        ALOGD_IF(DEBUG_CONNECTIONS, "\t>>> actuating h/w BATCH 0x%08x %" PRId64 " %" PRId64, handle,
                 info.bestBatchParams.mTSample, info.bestBatchParams.mTBatch);
        err = checkReturnAndGetStatus(mSensors->batch(
@@ -890,9 +890,9 @@ void SensorDevice::setUidStateForConnection(void* ident, SensorService::UidState
        Info& info = mActivationCount.editValueAt(i);

        if (info.hasBatchParamsForIdent(ident)) {
            if (updateBatchParamsLocked(handle, info) != NO_ERROR) {
                bool enable = info.numActiveClients() == 0 && info.isActive;
                bool disable = info.numActiveClients() > 0 && !info.isActive;
            updateBatchParamsLocked(handle, info);
            bool disable = info.numActiveClients() == 0 && info.isActive;
            bool enable = info.numActiveClients() > 0 && !info.isActive;

            if ((enable || disable) &&
                doActivateHardwareLocked(handle, enable) == NO_ERROR) {
@@ -901,7 +901,6 @@ void SensorDevice::setUidStateForConnection(void* ident, SensorService::UidState
        }
    }
}
}

bool SensorDevice::isSensorActive(int handle) const {
    Mutex::Autolock _l(mLock);