mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-23 00:57:26 +03:00
only refresh when lifecycle state is resumed
This commit is contained in:
parent
5e0f316827
commit
2cc3ede286
@ -19,6 +19,7 @@ package com.yubico.authenticator.oath
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.Observer
|
||||
import com.yubico.authenticator.*
|
||||
@ -144,11 +145,22 @@ class OathManager(
|
||||
if (expirations.isNotEmpty()) {
|
||||
val earliest = expirations.min() * 1000
|
||||
val now = System.currentTimeMillis()
|
||||
|
||||
refreshJob = coroutineScope.launch {
|
||||
if (earliest > now) {
|
||||
delay(earliest - now)
|
||||
val delayMs = earliest - now
|
||||
Log.d(TAG, "Will execute refresh in ${delayMs}ms")
|
||||
if (delayMs > 0) {
|
||||
delay(delayMs)
|
||||
}
|
||||
val currentState = lifecycleOwner.lifecycle.currentState
|
||||
if (currentState.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
requestRefresh()
|
||||
} else {
|
||||
Log.d(
|
||||
TAG,
|
||||
"Cannot run credential refresh in current lifecycle state: $currentState"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user