Enforce minimum token refresh rate

This commit is contained in:
M66B
2022-07-20 10:19:58 +02:00
parent 9fc1dac17c
commit 6afe0a2b11
2 changed files with 13 additions and 3 deletions

View File

@@ -62,14 +62,18 @@ public class GmailState {
void refresh(@NonNull Context context, @NonNull String user, boolean expire, long keep_alive)
throws AuthenticatorException, OperationCanceledException, IOException {
long now = new Date().getTime();
Long expiration = getAccessTokenExpirationTime();
if (expiration != null && expiration - keep_alive < new Date().getTime()) {
if (expiration != null && expiration - keep_alive < now) {
EntityLog.log(context, "Force invalidation" +
" expiration=" + new Date(expiration) +
" keep-alive=" + (keep_alive / 60 / 1000) + "m");
expire = true;
}
if (expiration != null && expiration - ServiceAuthenticator.MIN_EXPIRE_INTERVAL > now)
expire = false;
if (expire)
try {
if (token != null) {