mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
8117ca215f
commit
8e45a7850f
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue