Commit dd7accfa authored by Torsten Grote's avatar Torsten Grote

Merge branch '1576-db-before-signing-in' into 'master'

Retry database tasks after signing in

Closes #1576

See merge request !1131
parents 7ec826cc 1cf99348
Pipeline #3521 canceled with stages
......@@ -2,6 +2,7 @@ package org.briarproject.bramble.db;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.bramble.api.db.DbClosedException;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.MigrationListener;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
......@@ -89,9 +90,9 @@ class H2Database extends JdbcDatabase {
}
@Override
protected Connection createConnection() throws SQLException {
protected Connection createConnection() throws DbException, SQLException {
SecretKey key = this.key;
if (key == null) throw new IllegalStateException();
if (key == null) throw new DbClosedException();
Properties props = new Properties();
props.setProperty("user", "user");
// Separate the file password from the user password with a space
......
......@@ -2,6 +2,7 @@ package org.briarproject.bramble.db;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.bramble.api.db.DbClosedException;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.MigrationListener;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
......@@ -87,9 +88,9 @@ class HyperSqlDatabase extends JdbcDatabase {
}
@Override
protected Connection createConnection() throws SQLException {
protected Connection createConnection() throws DbException, SQLException {
SecretKey key = this.key;
if (key == null) throw new IllegalStateException();
if (key == null) throw new DbClosedException();
String hex = StringUtils.toHexString(key.getBytes());
return DriverManager.getConnection(url + ";crypt_key=" + hex);
}
......
......@@ -347,7 +347,8 @@ abstract class JdbcDatabase implements Database<Connection> {
private int openConnections = 0; // Locking: connectionsLock
private boolean closed = false; // Locking: connectionsLock
protected abstract Connection createConnection() throws SQLException;
protected abstract Connection createConnection()
throws DbException, SQLException;
protected abstract void compactAndClose() throws DbException;
......
......@@ -30,6 +30,7 @@ import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.logging.Level.INFO;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_DOZE_WHITELISTING;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSWORD;
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_UNLOCK;
......@@ -66,9 +67,15 @@ public abstract class BriarActivity extends BaseActivity {
@Nullable Intent data) {
super.onActivityResult(request, result, data);
if (request == REQUEST_PASSWORD) {
// We get RESULT_CANCELED when the account gets deleted or
// StartupActivity finishes before entering the password.
if (result == RESULT_OK) briarController.startAndBindService();
// Recreate the activity so any DB tasks that failed before
// signing in can be retried
if (result == RESULT_OK) {
if (LOG.isLoggable(INFO)) {
LOG.info("Recreating " + getClass().getSimpleName()
+ " after signing in");
}
recreate();
}
} else if (request == REQUEST_UNLOCK && result != RESULT_OK) {
// We arrive here, if the user presses 'back'
// in the Keyguard unlock screen, because UnlockActivity finishes.
......
......@@ -49,6 +49,7 @@ public class AddContactActivity extends BriarActivity implements
viewModel = ViewModelProviders.of(this, viewModelFactory)
.get(AddContactViewModel.class);
viewModel.onCreate();
viewModel.getRemoteLinkEntered().observeEvent(this, entered -> {
if (entered) {
NicknameFragment f = new NicknameFragment();
......@@ -93,13 +94,11 @@ public class AddContactActivity extends BriarActivity implements
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
}
......@@ -53,7 +53,10 @@ public class AddContactViewModel extends AndroidViewModel {
super(application);
this.contactManager = contactManager;
this.dbExecutor = dbExecutor;
loadHandshakeLink();
}
void onCreate() {
if (handshakeLink.getValue() == null) loadHandshakeLink();
}
private void loadHandshakeLink() {
......
......@@ -55,6 +55,7 @@ public class PendingContactListActivity extends BriarActivity
viewModel = ViewModelProviders.of(this, viewModelFactory)
.get(PendingContactListViewModel.class);
viewModel.onCreate();
viewModel.getPendingContacts()
.observe(this, this::onPendingContactsChanged);
......
......@@ -61,7 +61,10 @@ public class PendingContactListViewModel extends AndroidViewModel
this.rendezvousPoller = rendezvousPoller;
this.eventBus = eventBus;
this.eventBus.addListener(this);
loadPendingContacts();
}
void onCreate() {
if (pendingContacts.getValue() == null) loadPendingContacts();
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment