1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-30 19:56:10 +00:00

Added OAuth fail-safe

This commit is contained in:
M66B 2022-08-28 09:02:48 +02:00
parent 59182fb014
commit 3db1eff23d

View file

@ -38,6 +38,7 @@ import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import javax.mail.Authenticator; import javax.mail.Authenticator;
import javax.mail.MessagingException; import javax.mail.MessagingException;
@ -57,6 +58,7 @@ public class ServiceAuthenticator extends Authenticator {
static final long MIN_REFRESH_INTERVAL = 15 * 60 * 1000L; static final long MIN_REFRESH_INTERVAL = 15 * 60 * 1000L;
static final long MIN_FORCE_REFRESH_INTERVAL = 15 * 60 * 1000L; static final long MIN_FORCE_REFRESH_INTERVAL = 15 * 60 * 1000L;
static final int MAX_TOKEN_WAIT = 90; // seconds
ServiceAuthenticator( ServiceAuthenticator(
Context context, Context context,
@ -189,7 +191,9 @@ public class ServiceAuthenticator extends Authenticator {
} }
}); });
semaphore.acquire(); if (!semaphore.tryAcquire(MAX_TOKEN_WAIT, TimeUnit.SECONDS))
throw new InterruptedException("Timeout getting token id=" + id);
Log.i("OAuth refreshed user=" + id + ":" + user); Log.i("OAuth refreshed user=" + id + ":" + user);
if (holder.error != null) { if (holder.error != null) {