mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Merge branch 'tests-cleanup' into 'master'
Clean up tests * Broke up ConstantsTest (#280) - the key encoding parts are now in KeyEncodingAndParsingTest, the message encoding parts are in MessageSizeIntegrationTest * Renamed the other integration tests in briar-android-tests * Moved the integration tests in briar-android-tests to the top-level package, as they all involve code from multiple packages * Separated DatabaseExecutorModule from DatabaseModule so we can use a different @DatabaseExecutor in integration tests * Merged AppModule with AndroidModule (@ernir, this touches code you're working on but I don't think there are any conflicts) * Renamed some TestUtils methods for consistency * Used TestUtils.getRandomBytes() where applicable Fixes #280. See merge request !133
This commit is contained in:
@@ -26,9 +26,12 @@ import javax.inject.Singleton;
|
||||
import dagger.Component;
|
||||
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {CoreModule.class, AppModule.class, AndroidModule.class,
|
||||
AndroidPluginsModule.class, AndroidSystemModule.class})
|
||||
@Component(modules = {
|
||||
CoreModule.class,
|
||||
AppModule.class,
|
||||
AndroidPluginsModule.class,
|
||||
AndroidSystemModule.class
|
||||
})
|
||||
public interface AndroidComponent extends CoreEagerSingletons {
|
||||
|
||||
void inject(SplashScreenActivity activity);
|
||||
@@ -78,6 +81,5 @@ public interface AndroidComponent extends CoreEagerSingletons {
|
||||
void inject(ShowQrCodeFragment fragment);
|
||||
|
||||
// Eager singleton load
|
||||
void inject(AndroidModule.EagerSingletons init);
|
||||
|
||||
void inject(AppModule.EagerSingletons init);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ package org.briarproject.android;
|
||||
public class AndroidEagerSingletons {
|
||||
|
||||
public static void initEagerSingletons(AndroidComponent c) {
|
||||
c.inject(new AndroidModule.EagerSingletons());
|
||||
c.inject(new AppModule.EagerSingletons());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
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.registerService(notificationManager);
|
||||
eventBus.addListener(notificationManager);
|
||||
return notificationManager;
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,51 @@ package org.briarproject.android;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
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;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
@Module
|
||||
public class AppModule {
|
||||
|
||||
Application application;
|
||||
static class EagerSingletons {
|
||||
@Inject
|
||||
AndroidNotificationManager androidNotificationManager;
|
||||
}
|
||||
|
||||
private final Application application;
|
||||
private final UiCallback uiCallback;
|
||||
|
||||
public AppModule(Application application) {
|
||||
this.application = application;
|
||||
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
|
||||
@@ -21,4 +54,55 @@ public class AppModule {
|
||||
Application providesApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
@Provides
|
||||
public UiCallback provideUICallback() {
|
||||
return uiCallback;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public DatabaseConfig provideDatabaseConfig(Application app) {
|
||||
final File dir = app.getApplicationContext().getDir("db", 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.registerService(notificationManager);
|
||||
eventBus.addListener(notificationManager);
|
||||
return notificationManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
|
||||
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
|
||||
import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS;
|
||||
@@ -28,9 +23,8 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
|
||||
if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
|
||||
AndroidComponent component =
|
||||
((BriarApplication) getApplication()).getApplicationComponent();
|
||||
injectActivity(component);
|
||||
BriarApplication application = (BriarApplication) getApplication();
|
||||
injectActivity(application.getApplicationComponent());
|
||||
}
|
||||
|
||||
public abstract void injectActivity(AndroidComponent component);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.CoreModule;
|
||||
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class BriarApplication extends Application {
|
||||
|
||||
private static final Logger LOG =
|
||||
@@ -18,7 +18,7 @@ public class BriarApplication extends Application {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
LOG.info("Application Created");
|
||||
LOG.info("Created");
|
||||
UncaughtExceptionHandler oldHandler =
|
||||
Thread.getDefaultUncaughtExceptionHandler();
|
||||
Context ctx = getApplicationContext();
|
||||
@@ -27,7 +27,6 @@ public class BriarApplication extends Application {
|
||||
|
||||
applicationComponent = DaggerAndroidComponent.builder()
|
||||
.appModule(new AppModule(this))
|
||||
.androidModule(new AndroidModule())
|
||||
.build();
|
||||
|
||||
// We need to load the eager singletons directly after making the
|
||||
|
||||
@@ -55,8 +55,8 @@ public class BriarService extends Service {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
((BriarApplication) this.getApplication())
|
||||
.getApplicationComponent().inject(this);
|
||||
BriarApplication application = (BriarApplication) getApplication();
|
||||
application.getApplicationComponent().inject(this);
|
||||
|
||||
LOG.info("Created");
|
||||
if (created.getAndSet(true)) {
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import org.briarproject.android.AndroidComponent;
|
||||
import org.briarproject.android.BriarActivity;
|
||||
import org.briarproject.android.BriarApplication;
|
||||
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
@@ -14,8 +13,6 @@ public abstract class BaseFragment extends Fragment {
|
||||
|
||||
protected BaseFragmentListener listener;
|
||||
|
||||
protected BriarActivity briarActivity;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@@ -31,15 +28,15 @@ public abstract class BaseFragment extends Fragment {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
AndroidComponent component =
|
||||
((BriarApplication) getActivity().getApplication())
|
||||
.getApplicationComponent();
|
||||
injectActivity(component);
|
||||
BriarApplication application =
|
||||
(BriarApplication) getActivity().getApplication();
|
||||
injectActivity(application.getApplicationComponent());
|
||||
}
|
||||
|
||||
public abstract void injectActivity(AndroidComponent component);
|
||||
|
||||
public interface BaseFragmentListener {
|
||||
|
||||
void showLoadingScreen(boolean isBlocking, int stringId);
|
||||
|
||||
void hideLoadingScreen();
|
||||
@@ -48,5 +45,4 @@ public abstract class BaseFragment extends Fragment {
|
||||
|
||||
void runOnDbThread(Runnable runnable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user