mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
103 lines
2.3 KiB
Java
103 lines
2.3 KiB
Java
package org.briarproject.android;
|
|
|
|
import android.app.Application;
|
|
import android.content.Context;
|
|
|
|
import org.briarproject.android.api.AndroidNotificationManager;
|
|
import org.briarproject.android.api.ReferenceManager;
|
|
import org.briarproject.api.crypto.SecretKey;
|
|
import org.briarproject.api.db.DatabaseConfig;
|
|
import org.briarproject.api.event.EventBus;
|
|
import org.briarproject.api.lifecycle.LifecycleManager;
|
|
import org.briarproject.api.ui.UiCallback;
|
|
|
|
import java.io.File;
|
|
|
|
import javax.inject.Inject;
|
|
import javax.inject.Singleton;
|
|
|
|
import dagger.Module;
|
|
import dagger.Provides;
|
|
|
|
@Module
|
|
public class AndroidModule {
|
|
|
|
static class EagerSingletons {
|
|
@Inject
|
|
AndroidNotificationManager androidNotificationManager;
|
|
}
|
|
|
|
private final UiCallback uiCallback;
|
|
|
|
public AndroidModule() {
|
|
// Use a dummy UI callback
|
|
uiCallback = new UiCallback() {
|
|
|
|
public int showChoice(String[] options, String... message) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
public boolean showConfirmationMessage(String... message) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
|
|
public void showMessage(String... message) {
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
};
|
|
}
|
|
|
|
@Provides
|
|
public UiCallback provideUICallback() {
|
|
return uiCallback;
|
|
}
|
|
|
|
@Provides
|
|
@Singleton
|
|
public DatabaseConfig provideDatabaseConfig(Application app) {
|
|
final File dir = app.getApplicationContext().getDir("db", Context.MODE_PRIVATE);
|
|
return new DatabaseConfig() {
|
|
|
|
private volatile SecretKey key = null;
|
|
|
|
public boolean databaseExists() {
|
|
return dir.isDirectory() && dir.listFiles().length > 0;
|
|
}
|
|
|
|
public File getDatabaseDirectory() {
|
|
return dir;
|
|
}
|
|
|
|
public void setEncryptionKey(SecretKey key) {
|
|
this.key = key;
|
|
}
|
|
|
|
public SecretKey getEncryptionKey() {
|
|
return key;
|
|
}
|
|
|
|
public long getMaxSize() {
|
|
return Long.MAX_VALUE;
|
|
}
|
|
};
|
|
}
|
|
|
|
@Provides
|
|
@Singleton
|
|
ReferenceManager provideReferenceManager() {
|
|
return new ReferenceManagerImpl();
|
|
}
|
|
|
|
@Provides
|
|
@Singleton
|
|
AndroidNotificationManager provideAndroidNotificationManager(
|
|
LifecycleManager lifecycleManager, EventBus eventBus,
|
|
AndroidNotificationManagerImpl notificationManager) {
|
|
lifecycleManager.register(notificationManager);
|
|
eventBus.addListener(notificationManager);
|
|
|
|
return notificationManager;
|
|
}
|
|
|
|
}
|