Throw authenticator exceptions

pull/156/head
M66B 5 years ago
parent 5780253a14
commit 9093486255

@ -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;
}

@ -19,6 +19,8 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
@ -251,7 +253,7 @@ public class ServiceSend extends LifecycleService {
}
};
private void send(EntityMessage message) throws MessagingException, IOException {
private void send(EntityMessage message) throws MessagingException, IOException, AuthenticatorException, OperationCanceledException {
DB db = DB.getInstance(this);
// Mark attempt

@ -19,6 +19,8 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.Context;
import android.content.SharedPreferences;
@ -86,7 +88,7 @@ public class ViewModelBrowse extends ViewModel {
currentState.error = false;
}
int load() throws MessagingException, IOException {
int load() throws MessagingException, IOException, AuthenticatorException, OperationCanceledException {
final State state = currentState;
if (state == null || state.error)
return 0;

Loading…
Cancel
Save