mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-24 07:01:05 +00:00
Keep old Gmail token
This commit is contained in:
parent
24e289a903
commit
0d6c094f8f
1 changed files with 7 additions and 6 deletions
|
@ -67,6 +67,7 @@ public class GmailState {
|
|||
void refresh(@NonNull Context context, String id, @NonNull String user, boolean forceRefresh)
|
||||
throws AuthenticatorException, OperationCanceledException, IOException {
|
||||
long now = new Date().getTime();
|
||||
EntityLog.Type logType = (BuildConfig.DEBUG ? EntityLog.Type.Debug : EntityLog.Type.General);
|
||||
Long expiration = getAccessTokenExpirationTime();
|
||||
boolean needsRefresh = (expiration != null && expiration < now);
|
||||
boolean neededRefresh = needsRefresh;
|
||||
|
@ -81,6 +82,7 @@ public class GmailState {
|
|||
crumb.put("force", Boolean.toString(forceRefresh));
|
||||
crumb.put("need", Boolean.toString(needsRefresh));
|
||||
crumb.put("needed", Boolean.toString(neededRefresh));
|
||||
crumb.put("token", Boolean.toString(token != null));
|
||||
crumb.put("expiration", expiration == null ? "n/a" : Long.toString((expiration - now) / 1000L));
|
||||
Log.breadcrumb("Token refresh", crumb);
|
||||
|
||||
|
@ -102,12 +104,9 @@ public class GmailState {
|
|||
" exp=" + (expiration == null ? -1 : (expiration - now) / 1000L) + " s");
|
||||
else
|
||||
try {
|
||||
EntityLog.log(context, "Invalidating token user=" + id + ":" + user);
|
||||
EntityLog.log(context, logType, "Invalidating token user=" + id + ":" + user);
|
||||
AccountManager am = AccountManager.get(context);
|
||||
am.invalidateAuthToken(TYPE_GOOGLE, token);
|
||||
|
||||
token = null;
|
||||
acquired = 0;
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
} finally {
|
||||
|
@ -119,7 +118,7 @@ public class GmailState {
|
|||
if (account == null)
|
||||
throw new AuthenticatorException("Account not found for " + id + ":" + user);
|
||||
|
||||
EntityLog.log(context, "Getting token user=" + id + ":" + user);
|
||||
EntityLog.log(context, logType, "Getting token user=" + id + ":" + user);
|
||||
AccountManager am = AccountManager.get(context);
|
||||
String newToken = am.blockingGetAuthToken(
|
||||
account,
|
||||
|
@ -134,8 +133,10 @@ public class GmailState {
|
|||
if (newToken != null && !newToken.equals(token)) {
|
||||
token = newToken;
|
||||
acquired = new Date().getTime();
|
||||
} else if (needsRefresh)
|
||||
} else if (needsRefresh) {
|
||||
EntityLog.log(context, logType, "Token refresh failed user=" + id + ":" + user);
|
||||
Log.e("Token refresh failed id=" + id);
|
||||
}
|
||||
|
||||
if (token == null)
|
||||
throw new AuthenticatorException("Got no token id=" + id);
|
||||
|
|
Loading…
Reference in a new issue