mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Remove logic from DatabaseConfig.
This commit is contained in:
@@ -7,8 +7,6 @@ import java.io.File;
|
||||
@NotNullByDefault
|
||||
public interface DatabaseConfig {
|
||||
|
||||
boolean databaseExists();
|
||||
|
||||
File getDatabaseDirectory();
|
||||
|
||||
File getDatabaseKeyDirectory();
|
||||
|
||||
@@ -50,8 +50,7 @@ class H2Database extends JdbcDatabase {
|
||||
public boolean open(SecretKey key, @Nullable MigrationListener listener)
|
||||
throws DbException {
|
||||
this.key = key;
|
||||
boolean reopen = config.databaseExists();
|
||||
if (!reopen) config.getDatabaseDirectory().mkdirs();
|
||||
boolean reopen = !config.getDatabaseDirectory().mkdirs();
|
||||
super.open("org.h2.Driver", reopen, key, listener);
|
||||
return reopen;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,7 @@ class HyperSqlDatabase extends JdbcDatabase {
|
||||
public boolean open(SecretKey key, @Nullable MigrationListener listener)
|
||||
throws DbException {
|
||||
this.key = key;
|
||||
boolean reopen = config.databaseExists();
|
||||
if (!reopen) config.getDatabaseDirectory().mkdirs();
|
||||
boolean reopen = !config.getDatabaseDirectory().mkdirs();
|
||||
super.open("org.hsqldb.jdbc.JDBCDriver", reopen, key, listener);
|
||||
return reopen;
|
||||
}
|
||||
|
||||
@@ -17,13 +17,6 @@ public class TestDatabaseConfig implements DatabaseConfig {
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean databaseExists() {
|
||||
if (!dbDir.isDirectory()) return false;
|
||||
File[] files = dbDir.listFiles();
|
||||
return files != null && files.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDatabaseDirectory() {
|
||||
return dbDir;
|
||||
|
||||
@@ -4,16 +4,10 @@ import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
|
||||
@NotNullByDefault
|
||||
class AndroidDatabaseConfig implements DatabaseConfig {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(AndroidDatabaseConfig.class.getName());
|
||||
|
||||
private final File dbDir, keyDir;
|
||||
|
||||
AndroidDatabaseConfig(File dbDir, File keyDir) {
|
||||
@@ -21,38 +15,13 @@ class AndroidDatabaseConfig implements DatabaseConfig {
|
||||
this.keyDir = keyDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean databaseExists() {
|
||||
// FIXME should not run on UiThread #620
|
||||
if (!dbDir.isDirectory()) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info(dbDir.getAbsolutePath() + " is not a directory");
|
||||
return false;
|
||||
}
|
||||
File[] files = dbDir.listFiles();
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
if (files == null) {
|
||||
LOG.info("Could not list files in " + dbDir.getAbsolutePath());
|
||||
} else {
|
||||
LOG.info("Files in " + dbDir.getAbsolutePath() + ":");
|
||||
for (File f : files) LOG.info(f.getName());
|
||||
}
|
||||
LOG.info("Database exists: " + (files != null && files.length > 0));
|
||||
}
|
||||
return files != null && files.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDatabaseDirectory() {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Database directory: " + dbDir.getAbsolutePath());
|
||||
return dbDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDatabaseKeyDirectory() {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Database key directory: " + keyDir.getAbsolutePath());
|
||||
return keyDir;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,7 @@ import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
import org.briarproject.bramble.api.plugin.PluginConfig;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||
@@ -86,11 +84,7 @@ public class AppModule {
|
||||
File dbDir = app.getApplicationContext().getDir("db", MODE_PRIVATE);
|
||||
File keyDir = app.getApplicationContext().getDir("key", MODE_PRIVATE);
|
||||
StrictMode.setThreadPolicy(tp);
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
DatabaseConfig databaseConfig =
|
||||
new AndroidDatabaseConfig(dbDir, keyDir);
|
||||
return databaseConfig;
|
||||
return new AndroidDatabaseConfig(dbDir, keyDir);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -76,8 +76,8 @@ public class ConfigControllerImpl implements ConfigController {
|
||||
|
||||
@Override
|
||||
public boolean accountExists() {
|
||||
String hex = getEncryptedDatabaseKey();
|
||||
return hex != null && databaseConfig.databaseExists();
|
||||
return getEncryptedDatabaseKey() != null &&
|
||||
databaseConfig.getDatabaseDirectory().isDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,8 @@ public class SignInReminderReceiver extends BroadcastReceiver {
|
||||
if (action == null) return;
|
||||
if (action.equals(ACTION_BOOT_COMPLETED) ||
|
||||
action.equals(ACTION_MY_PACKAGE_REPLACED)) {
|
||||
if (databaseConfig.databaseExists()) {
|
||||
// TODO: Use account manager to check whether account exists
|
||||
if (databaseConfig.getDatabaseDirectory().isDirectory()) {
|
||||
SharedPreferences prefs = app.getDefaultSharedPreferences();
|
||||
if (prefs.getBoolean(NOTIFY_SIGN_IN, true)) {
|
||||
showSignInNotification(ctx);
|
||||
|
||||
Reference in New Issue
Block a user