Verified Commit 685496fb authored by akwizgran's avatar akwizgran

Extract DatabaseConfig implementation.

parent bffb5c94
package org.briarproject.briar.android;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.io.File;
import javax.annotation.Nullable;
@NotNullByDefault
class AndroidDatabaseConfig implements DatabaseConfig {
private final File dir;
@Nullable
private volatile SecretKey key = null;
@Nullable
private volatile String nickname = null;
AndroidDatabaseConfig(File dir) {
this.dir = dir;
}
@Override
public boolean databaseExists() {
// FIXME should not run on UiThread #620
if (!dir.isDirectory()) return false;
File[] files = dir.listFiles();
return files != null && files.length > 0;
}
@Override
public File getDatabaseDirectory() {
return dir;
}
@Override
public void setEncryptionKey(SecretKey key) {
this.key = key;
}
@Override
public void setLocalAuthorName(String nickname) {
this.nickname = nickname;
}
@Override
@Nullable
public String getLocalAuthorName() {
return nickname;
}
@Override
@Nullable
public SecretKey getEncryptionKey() {
return key;
}
@Override
public long getMaxSize() {
return Long.MAX_VALUE;
}
}
......@@ -5,7 +5,6 @@ import android.content.SharedPreferences;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.PublicKey;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.bramble.api.event.EventBus;
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
......@@ -23,7 +22,6 @@ import org.briarproject.briar.api.android.ScreenFilterMonitor;
import java.io.File;
import java.security.GeneralSecurityException;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
......@@ -87,51 +85,7 @@ public class AppModule {
File dir = app.getApplicationContext().getDir("db", MODE_PRIVATE);
@MethodsNotNullByDefault
@ParametersNotNullByDefault
DatabaseConfig databaseConfig = new DatabaseConfig() {
private volatile SecretKey key;
private volatile String nickname;
@Override
public boolean databaseExists() {
// FIXME should not run on UiThread #620
if (!dir.isDirectory()) return false;
File[] files = dir.listFiles();
return files != null && files.length > 0;
}
@Override
public File getDatabaseDirectory() {
return dir;
}
@Override
public void setEncryptionKey(SecretKey key) {
this.key = key;
}
@Override
public void setLocalAuthorName(String nickname) {
this.nickname = nickname;
}
@Override
@Nullable
public String getLocalAuthorName() {
return nickname;
}
@Override
@Nullable
public SecretKey getEncryptionKey() {
return key;
}
@Override
public long getMaxSize() {
return Long.MAX_VALUE;
}
};
DatabaseConfig databaseConfig = new AndroidDatabaseConfig(dir);
return databaseConfig;
}
......@@ -204,4 +158,5 @@ public class AppModule {
lifecycleManager.registerService(dozeWatchdog);
return dozeWatchdog;
}
}
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