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