Throw authenticator exceptions

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

@ -21,6 +21,8 @@ package eu.faircode.email;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.usage.UsageStatsManager; import android.app.usage.UsageStatsManager;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
@ -934,7 +936,8 @@ public class Helper {
return true; 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 { try {
istore.connect(account.host, account.port, account.user, account.password); istore.connect(account.host, account.port, account.user, account.password);
} catch (AuthenticationFailedException ex) { } catch (AuthenticationFailedException ex) {
@ -961,21 +964,18 @@ public class Helper {
} }
} }
static String refreshToken(Context context, String type, String name, String current) { static String refreshToken(Context context, String type, String name, String current)
try { throws AuthenticatorException, OperationCanceledException, IOException {
AccountManager am = AccountManager.get(context); AccountManager am = AccountManager.get(context);
Account[] accounts = am.getAccountsByType(type); Account[] accounts = am.getAccountsByType(type);
for (Account account : accounts) for (Account account : accounts)
if (name.equals(account.name)) { if (name.equals(account.name)) {
Log.i("Refreshing token"); Log.i("Refreshing token");
am.invalidateAuthToken(type, current); am.invalidateAuthToken(type, current);
String refreshed = am.blockingGetAuthToken(account, getAuthTokenType(type), true); String refreshed = am.blockingGetAuthToken(account, getAuthTokenType(type), true);
Log.i("Refreshed token"); Log.i("Refreshed token");
return refreshed; return refreshed;
} }
} catch (Throwable ex) {
Log.w(ex);
}
return current; return current;
} }

@ -19,6 +19,8 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B) Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/ */
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; 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); DB db = DB.getInstance(this);
// Mark attempt // Mark attempt

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

Loading…
Cancel
Save