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

Commit 4e291338 authored by Anh Pham's avatar Anh Pham
Browse files

Update sensor get methods related to sampling rate

The following methods are updated: Sensor::getMinDelay(),Sensor::getHighestDirectReportRateLevel() and SensorManager::getSensorList().

Test: atest CtsSensorTestCases CtsSensorRatePermissionTestCases
Bug: 136069189
Change-Id: I33893c93949f0f055ce5ded1a5ed9d188de709ed
parent 532e655e
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -468,6 +468,19 @@ void Sensor::setId(int32_t id) {
    mUuid.i64[1] = 0;
}

void Sensor::capMinDelayMicros(int32_t cappedMinDelay) {
    if (mMinDelay < cappedMinDelay) {
        mMinDelay = cappedMinDelay;
    }
}

void Sensor::capHighestDirectReportRateLevel(int32_t cappedRateLevel) {
    if (cappedRateLevel < getHighestDirectReportRateLevel()) {
        mFlags &= ~SENSOR_FLAG_MASK_DIRECT_REPORT;
        mFlags |= cappedRateLevel << SENSOR_FLAG_SHIFT_DIRECT_REPORT;
    }
}

int32_t Sensor::getId() const {
    return int32_t(mUuid.i64[0]);
}
+3 −0
Original line number Diff line number Diff line
@@ -104,6 +104,9 @@ public:
    int32_t getId() const;
    void setId(int32_t id);

    void capMinDelayMicros(int32_t cappedMinDelay);
    void capHighestDirectReportRateLevel(int32_t cappedRateLevel);

    // LightFlattenable protocol
    inline bool isFixedSize() const { return false; }
    size_t getFlattenedSize() const;
+7 −1
Original line number Diff line number Diff line
@@ -1244,14 +1244,20 @@ void SensorService::makeUuidsIntoIdsForSensorList(Vector<Sensor> &sensorList) co
    }
}

Vector<Sensor> SensorService::getSensorList(const String16& /* opPackageName */) {
Vector<Sensor> SensorService::getSensorList(const String16& opPackageName) {
    char value[PROPERTY_VALUE_MAX];
    property_get("debug.sensors", value, "0");
    const Vector<Sensor>& initialSensorList = (atoi(value)) ?
            mSensors.getUserDebugSensors() : mSensors.getUserSensors();
    Vector<Sensor> accessibleSensorList;

    bool isCapped = isRateCappedBasedOnPermission(opPackageName);
    for (size_t i = 0; i < initialSensorList.size(); i++) {
        Sensor sensor = initialSensorList[i];
        if (isCapped && isSensorInCappedSet(sensor.getType())) {
            sensor.capMinDelayMicros(SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS / 1000);
            sensor.capHighestDirectReportRateLevel(SENSOR_SERVICE_CAPPED_SAMPLING_RATE_LEVEL);
        }
        accessibleSensorList.add(sensor);
    }
    makeUuidsIntoIdsForSensorList(accessibleSensorList);