Added OAuth fail-safe

This commit is contained in:
M66B 2022-08-28 09:02:48 +02:00
parent 59182fb014
commit 3db1eff23d
1 changed files with 5 additions and 1 deletions

View File

@ -38,6 +38,7 @@ import java.io.IOException;
import java.util.Date;
import java.util.Objects;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import javax.mail.Authenticator;
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_FORCE_REFRESH_INTERVAL = 15 * 60 * 1000L;
static final int MAX_TOKEN_WAIT = 90; // seconds
ServiceAuthenticator(
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);
if (holder.error != null) {