mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Merge branch '1576-db-before-signing-in' into 'master'
Retry database tasks after signing in Closes #1576 See merge request briar/briar!1131
This commit is contained in:
@@ -2,6 +2,7 @@ package org.briarproject.bramble.db;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
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.DbException;
|
||||||
import org.briarproject.bramble.api.db.MigrationListener;
|
import org.briarproject.bramble.api.db.MigrationListener;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
@@ -89,9 +90,9 @@ class H2Database extends JdbcDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Connection createConnection() throws SQLException {
|
protected Connection createConnection() throws DbException, SQLException {
|
||||||
SecretKey key = this.key;
|
SecretKey key = this.key;
|
||||||
if (key == null) throw new IllegalStateException();
|
if (key == null) throw new DbClosedException();
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.setProperty("user", "user");
|
props.setProperty("user", "user");
|
||||||
// Separate the file password from the user password with a space
|
// 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.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
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.DbException;
|
||||||
import org.briarproject.bramble.api.db.MigrationListener;
|
import org.briarproject.bramble.api.db.MigrationListener;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
@@ -87,9 +88,9 @@ class HyperSqlDatabase extends JdbcDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Connection createConnection() throws SQLException {
|
protected Connection createConnection() throws DbException, SQLException {
|
||||||
SecretKey key = this.key;
|
SecretKey key = this.key;
|
||||||
if (key == null) throw new IllegalStateException();
|
if (key == null) throw new DbClosedException();
|
||||||
String hex = StringUtils.toHexString(key.getBytes());
|
String hex = StringUtils.toHexString(key.getBytes());
|
||||||
return DriverManager.getConnection(url + ";crypt_key=" + hex);
|
return DriverManager.getConnection(url + ";crypt_key=" + hex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -347,7 +347,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
private int openConnections = 0; // Locking: connectionsLock
|
private int openConnections = 0; // Locking: connectionsLock
|
||||||
private boolean closed = false; // 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;
|
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_NEW_TASK;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
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_DOZE_WHITELISTING;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSWORD;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSWORD;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_UNLOCK;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_UNLOCK;
|
||||||
@@ -66,9 +67,15 @@ public abstract class BriarActivity extends BaseActivity {
|
|||||||
@Nullable Intent data) {
|
@Nullable Intent data) {
|
||||||
super.onActivityResult(request, result, data);
|
super.onActivityResult(request, result, data);
|
||||||
if (request == REQUEST_PASSWORD) {
|
if (request == REQUEST_PASSWORD) {
|
||||||
// We get RESULT_CANCELED when the account gets deleted or
|
// Recreate the activity so any DB tasks that failed before
|
||||||
// StartupActivity finishes before entering the password.
|
// signing in can be retried
|
||||||
if (result == RESULT_OK) briarController.startAndBindService();
|
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) {
|
} else if (request == REQUEST_UNLOCK && result != RESULT_OK) {
|
||||||
// We arrive here, if the user presses 'back'
|
// We arrive here, if the user presses 'back'
|
||||||
// in the Keyguard unlock screen, because UnlockActivity finishes.
|
// in the Keyguard unlock screen, because UnlockActivity finishes.
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public class AddContactActivity extends BriarActivity implements
|
|||||||
|
|
||||||
viewModel = ViewModelProviders.of(this, viewModelFactory)
|
viewModel = ViewModelProviders.of(this, viewModelFactory)
|
||||||
.get(AddContactViewModel.class);
|
.get(AddContactViewModel.class);
|
||||||
|
viewModel.onCreate();
|
||||||
viewModel.getRemoteLinkEntered().observeEvent(this, entered -> {
|
viewModel.getRemoteLinkEntered().observeEvent(this, entered -> {
|
||||||
if (entered) {
|
if (entered) {
|
||||||
NicknameFragment f = new NicknameFragment();
|
NicknameFragment f = new NicknameFragment();
|
||||||
@@ -93,13 +94,11 @@ public class AddContactActivity extends BriarActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
if (item.getItemId() == android.R.id.home) {
|
||||||
case android.R.id.home:
|
onBackPressed();
|
||||||
onBackPressed();
|
return true;
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ public class AddContactViewModel extends AndroidViewModel {
|
|||||||
super(application);
|
super(application);
|
||||||
this.contactManager = contactManager;
|
this.contactManager = contactManager;
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
loadHandshakeLink();
|
}
|
||||||
|
|
||||||
|
void onCreate() {
|
||||||
|
if (handshakeLink.getValue() == null) loadHandshakeLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadHandshakeLink() {
|
private void loadHandshakeLink() {
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public class PendingContactListActivity extends BriarActivity
|
|||||||
|
|
||||||
viewModel = ViewModelProviders.of(this, viewModelFactory)
|
viewModel = ViewModelProviders.of(this, viewModelFactory)
|
||||||
.get(PendingContactListViewModel.class);
|
.get(PendingContactListViewModel.class);
|
||||||
|
viewModel.onCreate();
|
||||||
viewModel.getPendingContacts()
|
viewModel.getPendingContacts()
|
||||||
.observe(this, this::onPendingContactsChanged);
|
.observe(this, this::onPendingContactsChanged);
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,10 @@ public class PendingContactListViewModel extends AndroidViewModel
|
|||||||
this.rendezvousPoller = rendezvousPoller;
|
this.rendezvousPoller = rendezvousPoller;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.eventBus.addListener(this);
|
this.eventBus.addListener(this);
|
||||||
loadPendingContacts();
|
}
|
||||||
|
|
||||||
|
void onCreate() {
|
||||||
|
if (pendingContacts.getValue() == null) loadPendingContacts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user