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

Commit 29adc8cc authored by Stan Rokita's avatar Stan Rokita
Browse files

Check if sensor is accessible on flush

In cases where halVersion is less than or equal to 1 or the sensor is
virtual the sensor service does not first check that the sensor is
accessible. This was causing failures for tests where a virtual sensor
was used because the flush command was not returning error. Now
INVALID_OPERATION is returned when flush is called on an idle sensor.

Test: set IGNORE_HARDWARE_FUSION to true and cts-tradefed && run cts -m
CtsSensorTestCases -t
android.hardware.cts.SensorTest#testBatchAndFlushUidIdle which fails
before this change, but passes now
Bug: 160282248

Change-Id: I6860bcdb9be341b5e2025caf7606d071779c9b39
parent 9b2526e5
Loading
Loading
Loading
Loading
+10 −5
Original line number Original line Diff line number Diff line
@@ -272,12 +272,17 @@ void SensorService::SensorEventConnection::updateLooperRegistrationLocked(
    }
    }
}
}


void SensorService::SensorEventConnection::incrementPendingFlushCount(int32_t handle) {
bool SensorService::SensorEventConnection::incrementPendingFlushCountIfHasAccess(int32_t handle) {
    if (hasSensorAccess()) {
        Mutex::Autolock _l(mConnectionLock);
        Mutex::Autolock _l(mConnectionLock);
        if (mSensorInfo.count(handle) > 0) {
        if (mSensorInfo.count(handle) > 0) {
            FlushInfo& flushInfo = mSensorInfo[handle];
            FlushInfo& flushInfo = mSensorInfo[handle];
            flushInfo.mPendingFlushEventsToSend++;
            flushInfo.mPendingFlushEventsToSend++;
        }
        }
        return true;
    } else {
        return false;
    }
}
}


status_t SensorService::SensorEventConnection::sendEvents(
status_t SensorService::SensorEventConnection::sendEvents(
+3 −2
Original line number Original line Diff line number Diff line
@@ -116,8 +116,9 @@ private:
    // for writing send the data from the cache.
    // for writing send the data from the cache.
    virtual int handleEvent(int fd, int events, void* data);
    virtual int handleEvent(int fd, int events, void* data);


    // Increment mPendingFlushEventsToSend for the given sensor handle.
    // Increment mPendingFlushEventsToSend for the given handle if the connection has sensor access.
    void incrementPendingFlushCount(int32_t handle);
    // Returns true if this connection does have sensor access.
    bool incrementPendingFlushCountIfHasAccess(int32_t handle);


    // Add or remove the file descriptor associated with the BitTube to the looper. If mDead is set
    // Add or remove the file descriptor associated with the BitTube to the looper. If mDead is set
    // to true or there are no more sensors for this connection, the file descriptor is removed if
    // to true or there are no more sensors for this connection, the file descriptor is removed if
+4 −1
Original line number Original line Diff line number Diff line
@@ -1774,7 +1774,10 @@ status_t SensorService::flushSensor(const sp<SensorEventConnection>& connection,
        if (halVersion <= SENSORS_DEVICE_API_VERSION_1_0 || isVirtualSensor(handle)) {
        if (halVersion <= SENSORS_DEVICE_API_VERSION_1_0 || isVirtualSensor(handle)) {
            // For older devices just increment pending flush count which will send a trivial
            // For older devices just increment pending flush count which will send a trivial
            // flush complete event.
            // flush complete event.
            connection->incrementPendingFlushCount(handle);
            if (!connection->incrementPendingFlushCountIfHasAccess(handle)) {
                ALOGE("flush called on an inaccessible sensor");
                err = INVALID_OPERATION;
            }
        } else {
        } else {
            if (!canAccessSensor(sensor->getSensor(), "Tried flushing", opPackageName)) {
            if (!canAccessSensor(sensor->getSensor(), "Tried flushing", opPackageName)) {
                err = INVALID_OPERATION;
                err = INVALID_OPERATION;