From 45744de2450b9135a9b3a00b5b1930b671d90705 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 27 Jan 2024 08:08:32 +0100 Subject: [PATCH] Refresh tokens 5 minutes earlier --- app/src/main/java/eu/faircode/email/ServiceAuthenticator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceAuthenticator.java b/app/src/main/java/eu/faircode/email/ServiceAuthenticator.java index 0681dba75a..d7c1ab1307 100644 --- a/app/src/main/java/eu/faircode/email/ServiceAuthenticator.java +++ b/app/src/main/java/eu/faircode/email/ServiceAuthenticator.java @@ -65,6 +65,7 @@ public class ServiceAuthenticator extends Authenticator { static final int AUTH_TYPE_OAUTH = 3; static final int AUTH_TYPE_GRAPH = 4; + static final long ADVANCE_REFRESH_TIME = 5 * 60 * 1000L; static final long MIN_REFRESH_INTERVAL = 15 * 60 * 1000L; static final long MIN_FORCE_REFRESH_INTERVAL = 15 * 60 * 1000L; static final int MAX_TOKEN_WAIT = 90; // seconds @@ -161,7 +162,7 @@ public class ServiceAuthenticator extends Authenticator { try { long now = new Date().getTime(); Long expiration = authState.getAccessTokenExpirationTime(); - boolean needsRefresh = (expiration != null && expiration < now); + boolean needsRefresh = (expiration != null && expiration - ADVANCE_REFRESH_TIME < now); if (!needsRefresh && forceRefresh && expiration != null &&