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.
This commit is contained in:
Tim Hetkämper 2022-02-01 00:06:04 +01:00 committed by Marvin W
parent 61957c33cd
commit 75aaeb1fc6
1 changed files with 1 additions and 1 deletions

View File

@ -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)