Expedite keep alive time for token refresh

pull/209/head
M66B 2 years ago
parent 85bd4c6967
commit 8162d8e0b3

@ -889,8 +889,8 @@ public class EmailService implements AutoCloseable {
return false;
}
public void check() {
authenticator.checkToken();
public Long getAccessTokenExpirationTime() {
return authenticator.getAccessTokenExpirationTime();
}
public boolean isOpen() {

@ -56,7 +56,7 @@ public class ServiceAuthenticator extends Authenticator {
static final int AUTH_TYPE_GMAIL = 2;
static final int AUTH_TYPE_OAUTH = 3;
static final long MIN_EXPIRE_INTERVAL = 12 * 60 * 1000L;
static final long MIN_EXPIRE_INTERVAL = 15 * 60 * 1000L;
ServiceAuthenticator(
Context context,
@ -125,24 +125,19 @@ public class ServiceAuthenticator extends Authenticator {
return password;
}
void checkToken() {
Long expiration = null;
Long getAccessTokenExpirationTime() {
try {
if (auth == AUTH_TYPE_GMAIL) {
GmailState authState = GmailState.jsonDeserialize(password);
expiration = authState.getAccessTokenExpirationTime();
return authState.getAccessTokenExpirationTime();
} else if (auth == AUTH_TYPE_OAUTH) {
AuthState authState = AuthState.jsonDeserialize(password);
expiration = authState.getAccessTokenExpirationTime();
return authState.getAccessTokenExpirationTime();
}
} catch (JSONException ex) {
Log.e(ex);
}
long slack = Math.min(keep_alive, MIN_EXPIRE_INTERVAL);
if (expiration != null && expiration - slack < new Date().getTime())
throw new IllegalStateException(Log.TOKEN_REFRESH_REQUIRED);
return null;
}
interface IAuthenticated {

@ -2239,10 +2239,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
throw new StoreClosedException(iservice.getStore(), "Unrecoverable", cause);
}
// Check token expiration
if (!account.isTransient(this))
iservice.check();
// Sends store NOOP
if (EmailService.SEPARATE_STORE_CONNECTION) {
EntityLog.log(this, EntityLog.Type.Account, account,
@ -2357,6 +2353,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
try {
long duration = account.poll_interval * 60 * 1000L;
long trigger = System.currentTimeMillis() + duration;
if (!account.isTransient(this)) {
Long expirationTime = iservice.getAccessTokenExpirationTime();
if (expirationTime != null && expirationTime < trigger) {
EntityLog.log(this, EntityLog.Type.Debug, "Expedite keep alive" +
" from " + new Date(trigger) + " to " + new Date(expirationTime));
trigger = expirationTime;
}
}
EntityLog.log(this, EntityLog.Type.Account, account,
"### " + account.name + " keep alive" +
" wait=" + account.poll_interval + " until=" + new Date(trigger));

Loading…
Cancel
Save