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;
}
void refresh(@NonNull Context context, @NonNull String user, boolean expired) throws AuthenticatorException, OperationCanceledException, IOException {
if (expired || acquired + TOKEN_LIFETIME < new Date().getTime())
void refresh(@NonNull Context context, @NonNull String user, boolean expire) throws AuthenticatorException, OperationCanceledException, IOException {
if (expire || acquired + TOKEN_LIFETIME < new Date().getTime())
try {
if (token != null) {
EntityLog.log(context, "Invalidating token user=" + user);
@ -73,7 +73,10 @@ public class GmailState {
EntityLog.log(context, "Getting token user=" + user);
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)) {
token = newToken;

View File

@ -80,19 +80,19 @@ public class ServiceAuthenticator extends Authenticator {
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) {
GmailState gmailState = GmailState.jsonDeserialize(password);
gmailState.refresh(context, user, expired);
GmailState authState = GmailState.jsonDeserialize(password);
authState.refresh(context, user, expire);
String newPassword = gmailState.jsonSerializeString();
String newPassword = authState.jsonSerializeString();
if (!Objects.equals(password, newPassword)) {
password = newPassword;
if (intf != null)
intf.onPasswordChanged(password);
}
return gmailState.getAccessToken();
return authState.getAccessToken();
} else if (auth == AUTH_TYPE_OAUTH) {
AuthState authState = AuthState.jsonDeserialize(password);
OAuthRefresh(context, provider, authState);