Small improvement

pull/162/head
M66B 5 years ago
parent cd1e3d8391
commit 5d1cf7a15a

@ -475,15 +475,11 @@ public class FragmentSetup extends FragmentBase {
} }
private void onAccountSelected(Intent data) { private void onAccountSelected(Intent data) {
Log.i("Selected " + data);
Log.logExtras(data);
String name = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); String name = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
String type = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE); String type = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
AccountManager am = AccountManager.get(getContext()); AccountManager am = AccountManager.get(getContext());
Account[] accounts = am.getAccountsByType(type); Account[] accounts = am.getAccountsByType(type);
Log.i("Accounts=" + accounts.length);
for (final Account account : accounts) for (final Account account : accounts)
if (name.equals(account.name)) { if (name.equals(account.name)) {
Snackbar.make(view, R.string.title_authorizing, Snackbar.LENGTH_LONG).show(); Snackbar.make(view, R.string.title_authorizing, Snackbar.LENGTH_LONG).show();
@ -499,11 +495,12 @@ public class FragmentSetup extends FragmentBase {
try { try {
Bundle bundle = future.getResult(); Bundle bundle = future.getResult();
String token = bundle.getString(AccountManager.KEY_AUTHTOKEN); String token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
Log.i("Got token=" + token); Log.i("Got token");
onAuthorized(name, token); onAuthorized(name, token);
} catch (Throwable ex) { } catch (Throwable ex) {
if (ex instanceof AccountsException || ex instanceof IOException) { if (ex instanceof AccountsException || ex instanceof IOException) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) Log.w(ex);
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
Snackbar.make(view, Helper.formatThrowable(ex), Snackbar.LENGTH_LONG).show(); Snackbar.make(view, Helper.formatThrowable(ex), Snackbar.LENGTH_LONG).show();
} else { } else {
Log.e(ex); Log.e(ex);

@ -165,21 +165,21 @@ public class MailService implements AutoCloseable {
if (user.equals(account.name)) { if (user.equals(account.name)) {
Log.i("Refreshing token user=" + user); Log.i("Refreshing token user=" + user);
am.invalidateAuthToken(type, password); am.invalidateAuthToken(type, password);
String refreshed = am.blockingGetAuthToken(account, getAuthTokenType(type), true); String token = am.blockingGetAuthToken(account, getAuthTokenType(type), true);
if (refreshed == null) if (token == null)
throw new IllegalStateException("no token"); throw new IllegalArgumentException("no token");
int count = 0; int count = 0;
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
if ("imap".equals(protocol) || "imaps".equals(protocol)) if ("imap".equals(protocol) || "imaps".equals(protocol))
count = db.account().updateAccountPassword(password, refreshed); count = db.account().updateAccountPassword(password, token);
else if ("smtp".equals(protocol) || "smtps".equals(protocol)) else if ("smtp".equals(protocol) || "smtps".equals(protocol))
count = db.identity().updateIdentityPassword(password, refreshed); count = db.identity().updateIdentityPassword(password, token);
if (count != 1) if (count != 1)
throw new IllegalStateException(protocol + "=" + count); throw new IllegalArgumentException(protocol + "=" + count);
_connect(context, host, port, user, refreshed); _connect(context, host, port, user, token);
break; break;
} }
} catch (Throwable ex1) { } catch (Throwable ex1) {

Loading…
Cancel
Save