Refactoring

This commit is contained in:
M66B 2020-10-26 14:25:10 +01:00
parent 8117ca215f
commit 8e45a7850f
2 changed files with 11 additions and 8 deletions

View File

@ -53,8 +53,8 @@ public class GmailState {
return token; return token;
} }
void refresh(@NonNull Context context, @NonNull String user, boolean expired) throws AuthenticatorException, OperationCanceledException, IOException { void refresh(@NonNull Context context, @NonNull String user, boolean expire) throws AuthenticatorException, OperationCanceledException, IOException {
if (expired || acquired + TOKEN_LIFETIME < new Date().getTime()) if (expire || acquired + TOKEN_LIFETIME < new Date().getTime())
try { try {
if (token != null) { if (token != null) {
EntityLog.log(context, "Invalidating token user=" + user); EntityLog.log(context, "Invalidating token user=" + user);
@ -73,7 +73,10 @@ public class GmailState {
EntityLog.log(context, "Getting token user=" + user); EntityLog.log(context, "Getting token user=" + user);
AccountManager am = AccountManager.get(context); AccountManager am = AccountManager.get(context);
String newToken = am.blockingGetAuthToken(account, ServiceAuthenticator.getAuthTokenType(TYPE_GOOGLE), true); String newToken = am.blockingGetAuthToken(
account,
ServiceAuthenticator.getAuthTokenType(TYPE_GOOGLE),
true);
if (newToken != null && !newToken.equals(token)) { if (newToken != null && !newToken.equals(token)) {
token = newToken; token = newToken;

View File

@ -80,19 +80,19 @@ public class ServiceAuthenticator extends Authenticator {
return new PasswordAuthentication(user, token); return new PasswordAuthentication(user, token);
} }
String refreshToken(boolean expired) throws AuthenticatorException, OperationCanceledException, IOException, JSONException, MessagingException { String refreshToken(boolean expire) throws AuthenticatorException, OperationCanceledException, IOException, JSONException, MessagingException {
if (auth == AUTH_TYPE_GMAIL) { if (auth == AUTH_TYPE_GMAIL) {
GmailState gmailState = GmailState.jsonDeserialize(password); GmailState authState = GmailState.jsonDeserialize(password);
gmailState.refresh(context, user, expired); authState.refresh(context, user, expire);
String newPassword = gmailState.jsonSerializeString(); String newPassword = authState.jsonSerializeString();
if (!Objects.equals(password, newPassword)) { if (!Objects.equals(password, newPassword)) {
password = newPassword; password = newPassword;
if (intf != null) if (intf != null)
intf.onPasswordChanged(password); intf.onPasswordChanged(password);
} }
return gmailState.getAccessToken(); return authState.getAccessToken();
} else if (auth == AUTH_TYPE_OAUTH) { } else if (auth == AUTH_TYPE_OAUTH) {
AuthState authState = AuthState.jsonDeserialize(password); AuthState authState = AuthState.jsonDeserialize(password);
OAuthRefresh(context, provider, authState); OAuthRefresh(context, provider, authState);