Merge pull request #1453 from Andries-Smit/fix/protection-default-timeout

Fix protection default timeout
This commit is contained in:
Milos Kozak 2022-03-18 13:57:13 +01:00 committed by GitHub
commit 7c4f645d9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View file

@ -87,9 +87,9 @@
android:key="@string/key_protection_timeout"
android:title="@string/protection_timeout_title"
android:summary="@string/protection_timeout_summary"
app:defaultValue="0"
app:defaultValue="1"
validate:maxNumber="180"
validate:minNumber="0"
validate:minNumber="1"
validate:testType="numeric" />
</PreferenceCategory>

View file

@ -16,7 +16,6 @@ class ProtectionCheck @Inject constructor(
) {
private var lastAuthorization = mutableListOf(0L, 0L, 0L)
private val timeout = TimeUnit.SECONDS.toMillis(sp.getInt(R.string.key_protection_timeout, 0).toLong())
enum class Protection {
PREFERENCES,
@ -75,6 +74,9 @@ class ProtectionCheck @Inject constructor(
}
private fun activeSession(protection: Protection): Boolean {
var timeout = TimeUnit.SECONDS.toMillis(sp.getInt(R.string.key_protection_timeout, 0).toLong())
// Default timeout to pass the resume check at start of an activity
timeout = if (timeout < 1000) 1000 else timeout
val last = lastAuthorization[protection.ordinal]
val diff = dateUtil.now() - last
return diff < timeout