From ce9b7e82e2e7a721cdfa4e43d02a06d1f2efc41d Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 20 Jun 2019 08:39:37 +0200 Subject: [PATCH] Improved error handling --- FAQ.md | 6 +- .../java/eu/faircode/email/ActivityView.java | 10 +-- .../eu/faircode/email/AdapterMessage.java | 1 + app/src/main/java/eu/faircode/email/Core.java | 16 ++--- .../eu/faircode/email/EntityOperation.java | 3 + .../eu/faircode/email/FragmentAccount.java | 61 +++++++++---------- .../eu/faircode/email/FragmentIdentity.java | 45 ++++++++++---- .../java/eu/faircode/email/ServiceSend.java | 2 +- .../eu/faircode/email/ServiceSynchronize.java | 2 +- app/src/main/res/layout/fragment_account.xml | 2 +- app/src/main/res/layout/fragment_folders.xml | 16 ++--- app/src/main/res/layout/fragment_identity.xml | 10 +++ .../main/res/layout/fragment_quick_setup.xml | 2 +- 13 files changed, 100 insertions(+), 76 deletions(-) diff --git a/FAQ.md b/FAQ.md index db1f69d040..399a47bb5f 100644 --- a/FAQ.md +++ b/FAQ.md @@ -334,7 +334,11 @@ Unfortunately, it is impossible to make everybody happy and adding lots of setti To use a Gmail/G suite account, you'll need to enable access for "less secure" apps, see [here](https://support.google.com/accounts/answer/6010255) for Google's instructions or go [directy to the setting](https://www.google.com/settings/security/lesssecureapps). -You can solve the error *535-5.7.8 Username and Password not accepted* by enabling "less secure" apps. +When "less secure" apps is not enabled, +you'll get the error *Authentication failed - invalid credentials* for accounts (IMAP) +and *Username and Password not accepted* for identities (SMTP). + +If you use multiple Gmail accounts, make sure you change the "less secure" setting of the right account. You might get the alert "*Please log in via your web browser*". This security measure can for example be triggered when too many IP addresses were used in a too short time or when you are using a VPN. diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index bb99379893..8399ef426d 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -448,15 +448,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } else if ("outbox".equals(action)) onMenuOutbox(); - - else if ("error".equals(action)) { - Intent ifaq = new Intent(Intent.ACTION_VIEW); - ifaq.setData(Uri.parse(Helper.FAQ_URI + "#frequently-asked-questions")); - ifaq.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - if (ifaq.resolveActivity(getPackageManager()) != null) - startActivity(ifaq); - - } else if (action.startsWith("thread")) { + else if (action.startsWith("thread")) { intent.putExtra("thread", action.split(":", 2)[1]); onViewThread(intent); } diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index dcc8381221..da8a02c6ec 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -3069,6 +3069,7 @@ public class AdapterMessage extends RecyclerView.Adapter 0 ? View.VISIBLE : View.GONE); if (position == 0) { tvError.setVisibility(View.GONE); + tvInstructions.setVisibility(View.GONE); grpAdvanced.setVisibility(View.GONE); } tilPassword.setEndIconMode(position == 0 ? END_ICON_PASSWORD_TOGGLE : END_ICON_NONE); @@ -429,6 +434,7 @@ public class FragmentIdentity extends FragmentBase { btnSave.setVisibility(View.GONE); pbSave.setVisibility(View.GONE); tvError.setVisibility(View.GONE); + tvInstructions.setVisibility(View.GONE); grpAuthorize.setVisibility(View.GONE); grpAdvanced.setVisibility(View.GONE); @@ -525,6 +531,7 @@ public class FragmentIdentity extends FragmentBase { Helper.setViewsEnabled(view, false); pbSave.setVisibility(View.VISIBLE); tvError.setVisibility(View.GONE); + tvInstructions.setVisibility(View.GONE); } @Override @@ -659,10 +666,12 @@ public class FragmentIdentity extends FragmentBase { String identityRealm = (identity == null ? null : identity.realm); boolean check = (synchronize && (identity == null || + !identity.synchronize || !host.equals(identity.host) || Integer.parseInt(port) != identity.port || !user.equals(identity.user) || !password.equals(identity.password) || !Objects.equals(realm, identityRealm) || - use_ip != identity.use_ip)); + use_ip != identity.use_ip) || + !TextUtils.isEmpty(identity.error)); Long last_connected = null; if (identity != null && synchronize == identity.synchronize) @@ -784,20 +793,34 @@ public class FragmentIdentity extends FragmentBase { protected void onException(Bundle args, Throwable ex) { if (ex instanceof IllegalArgumentException) Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show(); - else { - tvError.setText(Helper.formatThrowable(ex)); - tvError.setVisibility(View.VISIBLE); - new Handler().post(new Runnable() { - @Override - public void run() { - scroll.smoothScrollTo(0, tvError.getBottom()); - } - }); - } + else + showError(ex); } }.execute(FragmentIdentity.this, args, "identity:save"); } + private void showError(Throwable ex) { + tvError.setText(Helper.formatThrowable(ex)); + tvError.setVisibility(View.VISIBLE); + + final View target; + + EmailProvider provider = (EmailProvider) spProvider.getSelectedItem(); + if (provider != null && provider.documentation != null) { + tvInstructions.setText(HtmlHelper.fromHtml(provider.documentation.toString())); + tvInstructions.setVisibility(View.VISIBLE); + target = tvInstructions; + } else + target = tvError; + + new Handler().post(new Runnable() { + @Override + public void run() { + scroll.smoothScrollTo(0, target.getBottom()); + } + }); + } + @Override public void onSaveInstanceState(Bundle outState) { outState.putInt("fair:account", spAccount.getSelectedItemPosition()); diff --git a/app/src/main/java/eu/faircode/email/ServiceSend.java b/app/src/main/java/eu/faircode/email/ServiceSend.java index acc32f05e3..d2b0c05f2a 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -416,7 +416,7 @@ public class ServiceSend extends LifecycleService { Log.i("Reporting send error after=" + delayed); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify("send", message.identity.intValue(), - Core.getNotificationError(this, ident.name, ex).build()); + Core.getNotificationError(this, "error", ident.name, ex).build()); } throw ex; diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 49202f4f2f..51ae850551 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -711,7 +711,7 @@ public class ServiceSynchronize extends LifecycleService { .format(account.last_connected)), ex); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify("receive", account.id.intValue(), - Core.getNotificationError(this, "warning", account.name, warning, false) + Core.getNotificationError(this, "warning", account.name, warning) .build()); } } diff --git a/app/src/main/res/layout/fragment_account.xml b/app/src/main/res/layout/fragment_account.xml index 63dcd7f8bd..a0504da527 100644 --- a/app/src/main/res/layout/fragment_account.xml +++ b/app/src/main/res/layout/fragment_account.xml @@ -707,7 +707,7 @@ android:layout_height="wrap_content" android:layout_marginTop="12dp" android:text="provider instructions" - android:textAppearance="@style/TextAppearance.AppCompat.Small" + android:textAppearance="@style/TextAppearance.AppCompat.Medium" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvError" /> diff --git a/app/src/main/res/layout/fragment_folders.xml b/app/src/main/res/layout/fragment_folders.xml index 54616e0122..0fc79f6cf5 100644 --- a/app/src/main/res/layout/fragment_folders.xml +++ b/app/src/main/res/layout/fragment_folders.xml @@ -36,10 +36,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/title_legend_close_hint" - app:srcCompat="@drawable/baseline_close_24" app:layout_constraintBottom_toBottomOf="@id/tvHintActions" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toTopOf="@id/tvHintActions" /> + app:layout_constraintTop_toTopOf="@id/tvHintActions" + app:srcCompat="@drawable/baseline_close_24" /> + app:layout_constraintTop_toTopOf="@id/tvHintSync" + app:srcCompat="@drawable/baseline_close_24" /> + app:backgroundTint="?attr/colorAccent" + app:srcCompat="@drawable/baseline_create_new_folder_24" /> + app:backgroundTint="@color/lightColorWarning" + app:srcCompat="@drawable/baseline_warning_24" /> diff --git a/app/src/main/res/layout/fragment_identity.xml b/app/src/main/res/layout/fragment_identity.xml index 93e67f5eb6..27308d63db 100644 --- a/app/src/main/res/layout/fragment_identity.xml +++ b/app/src/main/res/layout/fragment_identity.xml @@ -612,6 +612,16 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/btnSave" /> + +