Store schema version in database. Dev task #50.

If the schema of the database is incompatible with the schema expected
by the code, the database throws a DbSchemaException. LifecycleManager
indicates the error to BriarService, which uses HomeScreenActivity to
show a notification and quit the app.
This commit is contained in:
akwizgran
2014-01-09 21:00:40 +00:00
parent c779d7b95a
commit 623e7330ed
20 changed files with 237 additions and 117 deletions

View File

@@ -1,5 +1,6 @@
package org.briarproject.android;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.text.InputType.TYPE_CLASS_TEXT;
import static android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD;
import static android.view.Gravity.CENTER;
@@ -41,10 +42,15 @@ import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.util.StringUtils;
import roboguice.activity.RoboActivity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.text.Editable;
import android.view.KeyEvent;
import android.view.View;
@@ -90,9 +96,17 @@ public class HomeScreenActivity extends RoboActivity {
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
if(LOG.isLoggable(INFO)) LOG.info("Created");
Intent i = getIntent();
long handle = i.getLongExtra("org.briarproject.LOCAL_AUTHOR_HANDLE", -1);
if(handle != -1) {
boolean failed = i.getBooleanExtra("briar.STARTUP_FAILED", false);
long handle = i.getLongExtra("briar.LOCAL_AUTHOR_HANDLE", -1);
if(failed) {
// LifecycleManager failed to start all necessary services
showStartupFailureNotification();
finish();
if(LOG.isLoggable(INFO)) LOG.info("Exiting");
System.exit(0);
} else if(handle != -1) {
// The activity was launched from the setup wizard
if(System.currentTimeMillis() < EXPIRY_DATE) {
showSpinner();
@@ -118,13 +132,30 @@ public class HomeScreenActivity extends RoboActivity {
}
}
private void showStartupFailureNotification() {
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
b.setSmallIcon(android.R.drawable.stat_notify_error);
b.setContentTitle(getText(R.string.startup_failed_notification_title));
b.setContentText(getText(R.string.startup_failed_notification_text));
// Touch the notification to relaunch the app
Intent i = new Intent(this, HomeScreenActivity.class);
i.setFlags(FLAG_ACTIVITY_NEW_TASK);
b.setContentIntent(PendingIntent.getActivity(this, 0, i, 0));
Notification n = b.build();
Object o = getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o;
nm.notify(0, n);
}
private void showSpinner() {
LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(MATCH_MATCH);
layout.setGravity(CENTER);
ProgressBar progress = new ProgressBar(this);
progress.setIndeterminate(true);
layout.addView(progress);
setContentView(layout);
}