diff --git a/briar-android/src/main/java/org/briarproject/briar/android/AndroidDatabaseConfig.java b/briar-android/src/main/java/org/briarproject/briar/android/AndroidDatabaseConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..3f98bd8cc9c4732392147f4fcf69f84b19ebd401 --- /dev/null +++ b/briar-android/src/main/java/org/briarproject/briar/android/AndroidDatabaseConfig.java @@ -0,0 +1,64 @@ +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; + } +} diff --git a/briar-android/src/main/java/org/briarproject/briar/android/AppModule.java b/briar-android/src/main/java/org/briarproject/briar/android/AppModule.java index 67af25ac69474c763f47a3ec09f3d483afec0feb..4060305a63ad08722b82debd065408a91b82ab81 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/AppModule.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/AppModule.java @@ -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; } + }