mirror of
https://github.com/TeamVanced/VancedMicroG
synced 2024-12-24 03:35:50 +01:00
EN: Display last exposure report in settings
This commit is contained in:
parent
876e32acd5
commit
fd6d915f0a
@ -8,10 +8,13 @@ package org.microg.gms.ui
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.format.DateUtils
|
||||
import android.util.JsonReader
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.google.android.gms.R
|
||||
import org.json.JSONObject
|
||||
import org.microg.gms.nearby.exposurenotification.ExposureDatabase
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class ExposureNotificationsAppPreferencesFragment : PreferenceFragmentCompat() {
|
||||
private lateinit var open: Preference
|
||||
@ -53,6 +56,19 @@ class ExposureNotificationsAppPreferencesFragment : PreferenceFragmentCompat() {
|
||||
if (lastCheckTime != null && lastCheckTime != 0L) {
|
||||
str += "\n" + getString(R.string.pref_exposure_app_last_check_summary, DateUtils.getRelativeDateTimeString(context, lastCheckTime, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, DateUtils.FORMAT_SHOW_TIME))
|
||||
}
|
||||
val lastExposureSummaryTime = database.lastMethodCall(packageName, "getExposureSummary")
|
||||
val lastExposureSummary = database.lastMethodCallArgs(packageName, "getExposureSummary")
|
||||
if (lastExposureSummaryTime != null && lastExposureSummary != null && System.currentTimeMillis() - lastExposureSummaryTime <= TimeUnit.DAYS.toMillis(1)) {
|
||||
try {
|
||||
val json = JSONObject(lastExposureSummary)
|
||||
val matchedKeys = json.optInt("response_matched_keys")
|
||||
val daysSince = json.optInt("response_days_since", -1)
|
||||
if (matchedKeys > 0 && daysSince >= 0) {
|
||||
str += "\n" + resources.getQuantityString(R.plurals.pref_exposure_app_last_report_summary, matchedKeys, matchedKeys, daysSince)
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
checks.summary = str
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@
|
||||
<item quantity="one">Request missing permission</item>
|
||||
<item quantity="other">Request missing permissions</item>
|
||||
</plurals>
|
||||
</resources>
|
||||
<plurals name="pref_exposure_app_last_report_summary">
|
||||
<item quantity="one">Last report: <xliff:g example="1">%1$d</xliff:g> match, <xliff:g example="3">%2$d</xliff:g> days ago</item>
|
||||
<item quantity="other">Last report: <xliff:g example="2">%1$d</xliff:g> matches, latest <xliff:g example="3">%2$d</xliff:g> days ago</item>
|
||||
</plurals>
|
||||
</resources>
|
||||
|
@ -16,6 +16,6 @@
|
||||
<Preference
|
||||
android:key="pref_exposure_app_checks"
|
||||
android:selectable="false"
|
||||
tools:summary="7 checks in past 14 days\nLast check: 3 hours ago" />
|
||||
tools:summary="7 checks in past 14 days\nLast check: 3 hours ago\nLast report: 2 matches, latest 3 days ago" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
@ -444,6 +444,16 @@ class ExposureDatabase private constructor(private val context: Context) : SQLit
|
||||
}
|
||||
}
|
||||
|
||||
fun lastMethodCallArgs(packageName: String, method: String): String? = readableDatabase.run {
|
||||
query(TABLE_APP_LOG, arrayOf("args"), "package = ? AND method = ?", arrayOf(packageName, method), null, null, "timestamp DESC", "1").use { cursor ->
|
||||
if (cursor.moveToNext()) {
|
||||
cursor.getString(0)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val currentTemporaryExposureKey: TemporaryExposureKey
|
||||
get() = findOwnKeyAt(currentRollingStartNumber.toInt())
|
||||
?: storeOwnKey(generateCurrentTemporaryExposureKey())
|
||||
|
@ -72,24 +72,14 @@ class ExposureNotificationServiceImpl(private val context: Context, private val
|
||||
}
|
||||
|
||||
override fun stop(params: StopParams) {
|
||||
if (!ExposurePreferences(context).enabled) {
|
||||
params.callback.onResult(Status.SUCCESS)
|
||||
return
|
||||
ExposurePreferences(context).enabled = false
|
||||
ExposureDatabase.with(context) { database ->
|
||||
database.noteAppAction(packageName, "stop")
|
||||
}
|
||||
confirm(CONFIRM_ACTION_STOP) { resultCode, _ ->
|
||||
if (resultCode == SUCCESS) {
|
||||
ExposurePreferences(context).enabled = false
|
||||
}
|
||||
ExposureDatabase.with(context) { database ->
|
||||
database.noteAppAction(packageName, "stop", JSONObject().apply {
|
||||
put("result", resultCode)
|
||||
}.toString())
|
||||
}
|
||||
try {
|
||||
params.callback.onResult(Status.SUCCESS)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Callback failed", e)
|
||||
}
|
||||
try {
|
||||
params.callback.onResult(Status.SUCCESS)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Callback failed", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ data class MergedExposure internal constructor(val key: TemporaryExposureKey, va
|
||||
get() = TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - timestamp)
|
||||
|
||||
val attenuation
|
||||
get() = subs.map { it.attenuation }.min()!!
|
||||
get() = (subs.map { it.attenuation * it.duration }.sum().toDouble() / subs.map { it.duration }.sum().toDouble()).toInt()
|
||||
|
||||
fun getAttenuationRiskScore(configuration: ExposureConfiguration): Int {
|
||||
return when {
|
||||
|
Loading…
Reference in New Issue
Block a user