mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-28 00:20:50 +01:00
Throw authenticator exceptions
This commit is contained in:
@@ -21,6 +21,8 @@ package eu.faircode.email;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
@@ -934,7 +936,8 @@ public class Helper {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void connect(Context context, IMAPStore istore, EntityAccount account) throws MessagingException {
|
||||
static void connect(Context context, IMAPStore istore, EntityAccount account)
|
||||
throws MessagingException, AuthenticatorException, OperationCanceledException, IOException {
|
||||
try {
|
||||
istore.connect(account.host, account.port, account.user, account.password);
|
||||
} catch (AuthenticationFailedException ex) {
|
||||
@@ -961,21 +964,18 @@ public class Helper {
|
||||
}
|
||||
}
|
||||
|
||||
static String refreshToken(Context context, String type, String name, String current) {
|
||||
try {
|
||||
AccountManager am = AccountManager.get(context);
|
||||
Account[] accounts = am.getAccountsByType(type);
|
||||
for (Account account : accounts)
|
||||
if (name.equals(account.name)) {
|
||||
Log.i("Refreshing token");
|
||||
am.invalidateAuthToken(type, current);
|
||||
String refreshed = am.blockingGetAuthToken(account, getAuthTokenType(type), true);
|
||||
Log.i("Refreshed token");
|
||||
return refreshed;
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
static String refreshToken(Context context, String type, String name, String current)
|
||||
throws AuthenticatorException, OperationCanceledException, IOException {
|
||||
AccountManager am = AccountManager.get(context);
|
||||
Account[] accounts = am.getAccountsByType(type);
|
||||
for (Account account : accounts)
|
||||
if (name.equals(account.name)) {
|
||||
Log.i("Refreshing token");
|
||||
am.invalidateAuthToken(type, current);
|
||||
String refreshed = am.blockingGetAuthToken(account, getAuthTokenType(type), true);
|
||||
Log.i("Refreshed token");
|
||||
return refreshed;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user