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 2c680b1018e73882016a3eddf6c325a423e9a209..b70c9dec9b2a624e88d8d5dd9c7519810f9b08fb 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 7be465d990661b827f86b2b40723ebe45e2972c2..029170c911c4814c76b020115c6172a47ef12f79 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 dc5c63fdc91b4f8362f977f3965dc8c631489a02..6fa851707a240bf412f20e8286ebaa5055bad333 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 5b31a755fd51734f8e4c126c7dd80cf99ddbf1d0..0000000000000000000000000000000000000000 --- 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 90af1aaab47d427140ac6cd2115bd7e0cea0a03c..c682069f77c29abed6b07cb0a20e4b460e86ce90 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>