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

Commit 75aaeb1f authored by Tim Hetkämper's avatar Tim Hetkämper Committed by Marvin W.
Browse files

ENF: Fix average RSSI calculation

Correctly discard new measurements when the reported timestamp is older
than the timestamp in the database.
Fixes https://github.com/microg/GmsCore/issues/1655.
parent 61957c33
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -181,7 +181,7 @@ class ExposureDatabase private constructor(private val context: Context) : SQLit
    }

    fun noteAdvertisement(rpi: ByteArray, aem: ByteArray, rssi: Int, timestamp: Long = Date().time) = writableDatabase.run {
        val update = compileStatement("UPDATE $TABLE_ADVERTISEMENTS SET rssi = IFNULL(((rssi * duration) + (? * MIN(0, ? - timestamp - duration))) / MAX(duration, ? - timestamp), -100), duration = MAX(duration, ? - timestamp) WHERE rpi = ? AND timestamp > ? AND timestamp < ?").run {
        val update = compileStatement("UPDATE $TABLE_ADVERTISEMENTS SET rssi = IFNULL(((rssi * duration) + (? * MAX(0, ? - timestamp - duration))) / MAX(duration, ? - timestamp), -100), duration = MAX(duration, ? - timestamp) WHERE rpi = ? AND timestamp > ? AND timestamp < ?").run {
            bindLong(1, rssi.toLong())
            bindLong(2, timestamp)
            bindLong(3, timestamp)