From 46406d8d1a3f4a919f5f5ad106ef73e2161cc3b1 Mon Sep 17 00:00:00 2001 From: Torsten Grote <t@grobox.de> Date: Mon, 26 Feb 2018 12:59:25 -0300 Subject: [PATCH] Improve UX for startup failures Show a proper error message when database is too new or too old. --- .../api/lifecycle/LifecycleManager.java | 7 +++- .../lifecycle/LifecycleManagerImpl.java | 10 +++++ .../briar/android/StartupFailureActivity.java | 37 +++++++++++++++---- .../res/layout/activity_startup_failure.xml | 24 ------------ briar-android/src/main/res/values/strings.xml | 6 ++- 5 files changed, 49 insertions(+), 35 deletions(-) delete mode 100644 briar-android/src/main/res/layout/activity_startup_failure.xml diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/lifecycle/LifecycleManager.java b/bramble-api/src/main/java/org/briarproject/bramble/api/lifecycle/LifecycleManager.java index 2c680b1018..b70c9dec9b 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/lifecycle/LifecycleManager.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/lifecycle/LifecycleManager.java @@ -21,7 +21,12 @@ public interface LifecycleManager { * The result of calling {@link #startServices(String)}. */ enum StartResult { - ALREADY_RUNNING, DB_ERROR, SERVICE_ERROR, SUCCESS + ALREADY_RUNNING, + DB_ERROR, + DATA_TOO_OLD_ERROR, + DATA_TOO_NEW_ERROR, + SERVICE_ERROR, + SUCCESS } /** diff --git a/bramble-core/src/main/java/org/briarproject/bramble/lifecycle/LifecycleManagerImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/lifecycle/LifecycleManagerImpl.java index 7be465d990..029170c911 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/lifecycle/LifecycleManagerImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/lifecycle/LifecycleManagerImpl.java @@ -2,6 +2,8 @@ package org.briarproject.bramble.lifecycle; import org.briarproject.bramble.api.crypto.CryptoComponent; import org.briarproject.bramble.api.crypto.KeyPair; +import org.briarproject.bramble.api.db.DataTooNewException; +import org.briarproject.bramble.api.db.DataTooOldException; import org.briarproject.bramble.api.db.DatabaseComponent; import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.Transaction; @@ -30,6 +32,8 @@ import javax.inject.Inject; import static java.util.logging.Level.INFO; import static java.util.logging.Level.WARNING; import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.ALREADY_RUNNING; +import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.DATA_TOO_NEW_ERROR; +import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.DATA_TOO_OLD_ERROR; import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.DB_ERROR; import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.SERVICE_ERROR; import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult.SUCCESS; @@ -159,6 +163,12 @@ class LifecycleManagerImpl implements LifecycleManager { } startupLatch.countDown(); return SUCCESS; + } catch (DataTooOldException e) { + if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); + return DATA_TOO_OLD_ERROR; + } catch (DataTooNewException e) { + if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); + return DATA_TOO_NEW_ERROR; } catch (DbException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); return DB_ERROR; diff --git a/briar-android/src/main/java/org/briarproject/briar/android/StartupFailureActivity.java b/briar-android/src/main/java/org/briarproject/briar/android/StartupFailureActivity.java index dc5c63fdc9..6fa851707a 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/StartupFailureActivity.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/StartupFailureActivity.java @@ -3,23 +3,25 @@ package org.briarproject.briar.android; import android.app.NotificationManager; import android.content.Intent; import android.os.Bundle; -import android.widget.TextView; import org.briarproject.briar.R; import org.briarproject.briar.android.activity.ActivityComponent; import org.briarproject.briar.android.activity.BaseActivity; +import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener; +import org.briarproject.briar.android.fragment.ErrorFragment; import static org.briarproject.bramble.api.lifecycle.LifecycleManager.StartResult; import static org.briarproject.briar.android.BriarService.EXTRA_NOTIFICATION_ID; import static org.briarproject.briar.android.BriarService.EXTRA_START_RESULT; -public class StartupFailureActivity extends BaseActivity { +public class StartupFailureActivity extends BaseActivity implements + BaseFragmentListener { @Override public void onCreate(Bundle state) { super.onCreate(state); - setContentView(R.layout.activity_startup_failure); + setContentView(R.layout.activity_fragment_container); handleIntent(getIntent()); } @@ -41,12 +43,31 @@ public class StartupFailureActivity extends BaseActivity { } // show proper error message - TextView view = findViewById(R.id.errorView); - if (result.equals(StartResult.DB_ERROR)) { - view.setText(getText(R.string.startup_failed_db_error)); - } else if (result.equals(StartResult.SERVICE_ERROR)) { - view.setText(getText(R.string.startup_failed_service_error)); + String errorMsg; + switch (result) { + case DATA_TOO_OLD_ERROR: + errorMsg = getString(R.string.startup_failed_db_error); + break; + case DATA_TOO_NEW_ERROR: + errorMsg = + getString(R.string.startup_failed_data_too_new_error); + break; + case DB_ERROR: + errorMsg = + getString(R.string.startup_failed_data_too_old_error); + break; + case SERVICE_ERROR: + errorMsg = getString(R.string.startup_failed_service_error); + break; + default: + throw new IllegalArgumentException(); } + showInitialFragment(ErrorFragment.newInstance(errorMsg)); + } + + @Override + public void runOnDbThread(Runnable runnable) { + throw new AssertionError("Deprecated and should not be used"); } } diff --git a/briar-android/src/main/res/layout/activity_startup_failure.xml b/briar-android/src/main/res/layout/activity_startup_failure.xml deleted file mode 100644 index 5b31a755fd..0000000000 --- a/briar-android/src/main/res/layout/activity_startup_failure.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:padding="@dimen/margin_activity_horizontal"> - - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - style="@style/BriarTextTitle" - android:text="@string/startup_failed_notification_title" - android:layout_gravity="center_horizontal" - android:layout_marginTop="7dp" - android:layout_marginBottom="7dp"/> - - <TextView - android:id="@+id/errorView" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/startup_failed_notification_text"/> - -</LinearLayout> \ No newline at end of file diff --git a/briar-android/src/main/res/values/strings.xml b/briar-android/src/main/res/values/strings.xml index 90af1aaab4..c682069f77 100644 --- a/briar-android/src/main/res/values/strings.xml +++ b/briar-android/src/main/res/values/strings.xml @@ -34,9 +34,11 @@ <string name="dialog_title_lost_password">Lost Password</string> <string name="dialog_message_lost_password">Your Briar account is stored encrypted on your device, not in the cloud, so we can\'t reset your password. Would you like to delete your account and start again?\n\nCaution: Your identities, contacts and messages will be permanently lost.</string> <string name="startup_failed_notification_title">Briar could not start</string> - <string name="startup_failed_notification_text">You may need to reinstall Briar.</string> + <string name="startup_failed_notification_text">Tap for more information.</string> <string name="startup_failed_activity_title">Briar Startup Failure</string> - <string name="startup_failed_db_error">For some reason, your Briar database is corrupted beyond repair. Your account, your data and all your contacts are lost. Unfortunately, you need to reinstall Briar and set up a new account.</string> + <string name="startup_failed_db_error">For some reason, your Briar database is corrupted beyond repair. Your account, your data and all your contacts are lost. Unfortunately, you need to reinstall Briar and set up a new account by choosing \'I have forgotten my password\' at the password prompt.</string> + <string name="startup_failed_data_too_old_error">Your account was created with an old version of this app and cannot be opened with this version. You must either reinstall the old version or delete your old account by choosing \'I have forgotten my password\' at the password prompt.</string> + <string name="startup_failed_data_too_new_error">This version of the app is too old. Please upgrade to the latest version and try again.</string> <string name="startup_failed_service_error">Briar was unable to start a required plugin. Reinstalling Briar usually solves this problem. However, please note that you will then lose your account and all data associated with it since Briar is not using central servers to store your data on.</string> <plurals name="expiry_warning"> <item quantity="one">This is a test version of Briar. Your account will expire in %d day and cannot be renewed.</item> -- GitLab