mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Refactored FileUtils.
Removed methods that are no longer needed for Java 6, moved the remaining method into the utils directory.
This commit is contained in:
@@ -1,52 +1,5 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE;
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
import static android.content.Intent.ACTION_SEND;
|
||||
import static android.content.Intent.EXTRA_EMAIL;
|
||||
import static android.content.Intent.EXTRA_STREAM;
|
||||
import static android.content.Intent.EXTRA_SUBJECT;
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED;
|
||||
import static android.view.Gravity.CENTER;
|
||||
import static android.view.Gravity.CENTER_HORIZONTAL;
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.widget.LinearLayout.VERTICAL;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.TestingConstants.SHARE_CRASH_REPORTS;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
import org.briarproject.android.util.HorizontalBorder;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||
import org.briarproject.api.android.AndroidExecutor;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
@@ -70,14 +23,57 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
import org.briarproject.android.util.HorizontalBorder;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||
import org.briarproject.api.android.AndroidExecutor;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE;
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
import static android.content.Intent.ACTION_SEND;
|
||||
import static android.content.Intent.EXTRA_EMAIL;
|
||||
import static android.content.Intent.EXTRA_STREAM;
|
||||
import static android.content.Intent.EXTRA_SUBJECT;
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED;
|
||||
import static android.view.Gravity.CENTER;
|
||||
import static android.view.Gravity.CENTER_HORIZONTAL;
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.widget.LinearLayout.VERTICAL;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.TestingConstants.SHARE_CRASH_REPORTS;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||
|
||||
public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(CrashReportActivity.class.getName());
|
||||
|
||||
@Inject private FileUtils fileUtils;
|
||||
private final AndroidExecutor androidExecutor = new AndroidExecutorImpl();
|
||||
|
||||
private ScrollView scroll = null;
|
||||
@@ -235,28 +231,20 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
statusMap.put("Virtual machine memory:", vmMemory);
|
||||
|
||||
// Internal storage
|
||||
try {
|
||||
File root = Environment.getRootDirectory();
|
||||
long rootTotal = fileUtils.getTotalSpace(root);
|
||||
long rootFree = fileUtils.getFreeSpace(root);
|
||||
String internal = (rootTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (rootFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("Internal storage:", internal);
|
||||
} catch (IOException e) {
|
||||
statusMap.put("Internal storage:", "Unknown");
|
||||
}
|
||||
File root = Environment.getRootDirectory();
|
||||
long rootTotal = root.getTotalSpace();
|
||||
long rootFree = root.getFreeSpace();
|
||||
String internal = (rootTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (rootFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("Internal storage:", internal);
|
||||
|
||||
// External storage (SD card)
|
||||
try {
|
||||
File sd = Environment.getExternalStorageDirectory();
|
||||
long sdTotal = fileUtils.getTotalSpace(sd);
|
||||
long sdFree = fileUtils.getFreeSpace(sd);
|
||||
String external = (sdTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (sdFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("External storage:", external);
|
||||
} catch (IOException e) {
|
||||
statusMap.put("External storage:", "Unknown");
|
||||
}
|
||||
File sd = Environment.getExternalStorageDirectory();
|
||||
long sdTotal = sd.getTotalSpace();
|
||||
long sdFree = sd.getFreeSpace();
|
||||
String external = (sdTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (sdFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("External storage:", external);
|
||||
|
||||
// Is mobile data available?
|
||||
o = getSystemService(CONNECTIVITY_SERVICE);
|
||||
@@ -345,7 +333,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
// Is Bluetooth connectable?
|
||||
boolean btConnectable = bt != null &&
|
||||
(bt.getScanMode() == SCAN_MODE_CONNECTABLE ||
|
||||
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
// Is Bluetooth discoverable?
|
||||
boolean btDiscoverable = bt != null &&
|
||||
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.util.FileUtils;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
|
||||
|
||||
public class PasswordActivity extends BaseActivity {
|
||||
|
||||
@Inject @CryptoExecutor private Executor cryptoExecutor;
|
||||
@@ -41,7 +41,6 @@ public class PasswordActivity extends BaseActivity {
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile CryptoComponent crypto;
|
||||
@Inject private volatile DatabaseConfig databaseConfig;
|
||||
@Inject private FileUtils fileUtils;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
@@ -55,14 +54,14 @@ public class PasswordActivity extends BaseActivity {
|
||||
encrypted = StringUtils.fromHexString(hex);
|
||||
|
||||
setContentView(R.layout.activity_password);
|
||||
signInButton = (Button)findViewById(R.id.btn_sign_in);
|
||||
progress = (ProgressBar)findViewById(R.id.progress_wheel);
|
||||
title = (TextView)findViewById(R.id.title_password);
|
||||
password = (EditText)findViewById(R.id.edit_password);
|
||||
signInButton = (Button) findViewById(R.id.btn_sign_in);
|
||||
progress = (ProgressBar) findViewById(R.id.progress_wheel);
|
||||
title = (TextView) findViewById(R.id.title_password);
|
||||
password = (EditText) findViewById(R.id.edit_password);
|
||||
password.setOnEditorActionListener(new OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
if (actionId == IME_ACTION_DONE) {
|
||||
validatePassword(encrypted, password.getText());
|
||||
}
|
||||
return false;
|
||||
@@ -73,7 +72,7 @@ public class PasswordActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void clearDbPrefs() {
|
||||
super.clearDbPrefs();
|
||||
fileUtils.deleteFileOrDir(databaseConfig.getDatabaseDirectory());
|
||||
FileUtils.deleteFileOrDir(databaseConfig.getDatabaseDirectory());
|
||||
gotoAndFinish(SetupActivity.class, RESULT_CANCELED);
|
||||
}
|
||||
|
||||
@@ -100,7 +99,7 @@ public class PasswordActivity extends BaseActivity {
|
||||
private void validatePassword(final byte[] encrypted, Editable e) {
|
||||
hideSoftKeyboard();
|
||||
// Replace the button with a progress bar
|
||||
signInButton.setVisibility(View.INVISIBLE);
|
||||
signInButton.setVisibility(GONE);
|
||||
progress.setVisibility(VISIBLE);
|
||||
// Decrypt the database key in a background thread
|
||||
final String password = e.toString();
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.android.util.StrengthMeter;
|
||||
import org.briarproject.api.AuthorFactory;
|
||||
import org.briarproject.api.LocalAuthor;
|
||||
import org.briarproject.api.android.ReferenceManager;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.api.crypto.KeyPair;
|
||||
import org.briarproject.api.crypto.PasswordStrengthEstimator;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import roboguice.activity.RoboActivity;
|
||||
|
||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||
import static android.text.InputType.TYPE_CLASS_TEXT;
|
||||
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS;
|
||||
@@ -19,42 +56,6 @@ import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
|
||||
import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.api.crypto.PasswordStrengthEstimator.WEAK;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.android.util.StrengthMeter;
|
||||
import org.briarproject.api.AuthorFactory;
|
||||
import org.briarproject.api.LocalAuthor;
|
||||
import org.briarproject.api.android.ReferenceManager;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.api.crypto.KeyPair;
|
||||
import org.briarproject.api.crypto.PasswordStrengthEstimator;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import roboguice.activity.RoboActivity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
public class SetupActivity extends RoboActivity implements OnClickListener,
|
||||
OnEditorActionListener {
|
||||
|
||||
@@ -149,7 +150,7 @@ OnEditorActionListener {
|
||||
layout.addView(passwordConfirmation);
|
||||
|
||||
strengthMeter = new StrengthMeter(this);
|
||||
strengthMeter.setPadding(pad, 2 * pad, pad, 0);
|
||||
strengthMeter.setPadding(pad, pad, pad, pad);
|
||||
strengthMeter.setVisibility(INVISIBLE);
|
||||
layout.addView(strengthMeter);
|
||||
|
||||
|
||||
@@ -1,61 +1,5 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE;
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
import static android.content.Intent.ACTION_SEND;
|
||||
import static android.content.Intent.EXTRA_EMAIL;
|
||||
import static android.content.Intent.EXTRA_STREAM;
|
||||
import static android.content.Intent.EXTRA_SUBJECT;
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED;
|
||||
import static android.view.Gravity.CENTER;
|
||||
import static android.view.Gravity.CENTER_HORIZONTAL;
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.widget.LinearLayout.VERTICAL;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
import org.briarproject.android.util.ElasticHorizontalSpace;
|
||||
import org.briarproject.android.util.HorizontalBorder;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.android.AndroidExecutor;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.plugins.Plugin;
|
||||
import org.briarproject.api.plugins.PluginManager;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
@@ -77,6 +21,61 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.AndroidUtils;
|
||||
import org.briarproject.android.util.ElasticHorizontalSpace;
|
||||
import org.briarproject.android.util.HorizontalBorder;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.TransportProperties;
|
||||
import org.briarproject.api.android.AndroidExecutor;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.plugins.Plugin;
|
||||
import org.briarproject.api.plugins.PluginManager;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE;
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
import static android.content.Intent.ACTION_SEND;
|
||||
import static android.content.Intent.EXTRA_EMAIL;
|
||||
import static android.content.Intent.EXTRA_STREAM;
|
||||
import static android.content.Intent.EXTRA_SUBJECT;
|
||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED;
|
||||
import static android.view.Gravity.CENTER;
|
||||
import static android.view.Gravity.CENTER_HORIZONTAL;
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.widget.LinearLayout.VERTICAL;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||
|
||||
public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
@@ -92,8 +91,6 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
private ImageButton refresh = null, share = null;
|
||||
private File temp = null;
|
||||
|
||||
@Inject private volatile FileUtils fileUtils;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
@@ -245,28 +242,20 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
statusMap.put("Virtual machine memory:", vmMemory);
|
||||
|
||||
// Internal storage
|
||||
try {
|
||||
File root = Environment.getRootDirectory();
|
||||
long rootTotal = fileUtils.getTotalSpace(root);
|
||||
long rootFree = fileUtils.getFreeSpace(root);
|
||||
String internal = (rootTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (rootFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("Internal storage:", internal);
|
||||
} catch (IOException e) {
|
||||
statusMap.put("Internal storage:", "Unknown");
|
||||
}
|
||||
File root = Environment.getRootDirectory();
|
||||
long rootTotal = root.getTotalSpace();
|
||||
long rootFree = root.getFreeSpace();
|
||||
String internal = (rootTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (rootFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("Internal storage:", internal);
|
||||
|
||||
// External storage (SD card)
|
||||
try {
|
||||
File sd = Environment.getExternalStorageDirectory();
|
||||
long sdTotal = fileUtils.getTotalSpace(sd);
|
||||
long sdFree = fileUtils.getFreeSpace(sd);
|
||||
String external = (sdTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (sdFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("External storage:", external);
|
||||
} catch (IOException e) {
|
||||
statusMap.put("External storage:", "Unknown");
|
||||
}
|
||||
File sd = Environment.getExternalStorageDirectory();
|
||||
long sdTotal = sd.getTotalSpace();
|
||||
long sdFree = sd.getFreeSpace();
|
||||
String external = (sdTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (sdFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("External storage:", external);
|
||||
|
||||
// Is mobile data available?
|
||||
o = getSystemService(CONNECTIVITY_SERVICE);
|
||||
@@ -355,7 +344,7 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
// Is Bluetooth connectable?
|
||||
boolean btConnectable = bt != null &&
|
||||
(bt.getScanMode() == SCAN_MODE_CONNECTABLE ||
|
||||
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
// Is Bluetooth discoverable?
|
||||
boolean btDiscoverable = bt != null &&
|
||||
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package org.briarproject.system;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
import org.briarproject.api.system.Clock;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.api.system.LocationUtils;
|
||||
import org.briarproject.api.system.SeedProvider;
|
||||
import org.briarproject.api.system.Timer;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
public class AndroidSystemModule extends AbstractModule {
|
||||
|
||||
protected void configure() {
|
||||
bind(Clock.class).to(SystemClock.class);
|
||||
bind(Timer.class).to(SystemTimer.class);
|
||||
bind(SeedProvider.class).to(AndroidSeedProvider.class);
|
||||
bind(FileUtils.class).to(FileUtilsImpl.class);
|
||||
bind(LocationUtils.class).to(AndroidLocationUtils.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package org.briarproject.api.system;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface FileUtils {
|
||||
|
||||
long getTotalSpace(File f) throws IOException;
|
||||
|
||||
long getFreeSpace(File f) throws IOException;
|
||||
|
||||
void deleteFileOrDir(File f);
|
||||
}
|
||||
@@ -1,6 +1,15 @@
|
||||
package org.briarproject.db;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||
import org.briarproject.system.SystemClock;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
@@ -12,17 +21,7 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.system.SystemClock;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
public class DatabaseModule extends AbstractModule {
|
||||
|
||||
@@ -45,9 +44,8 @@ public class DatabaseModule extends AbstractModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
Database<Connection> getDatabase(DatabaseConfig config,
|
||||
FileUtils fileUtils) {
|
||||
return new H2Database(config, fileUtils, new SystemClock());
|
||||
Database<Connection> getDatabase(DatabaseConfig config) {
|
||||
return new H2Database(config, new SystemClock());
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package org.briarproject.db;
|
||||
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.system.Clock;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
@@ -10,12 +15,6 @@ import java.util.Properties;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.system.Clock;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
/** Contains all the H2-specific code for the database. */
|
||||
class H2Database extends JdbcDatabase {
|
||||
|
||||
@@ -25,14 +24,12 @@ class H2Database extends JdbcDatabase {
|
||||
private static final String SECRET_TYPE = "BINARY(32)";
|
||||
|
||||
private final DatabaseConfig config;
|
||||
private final FileUtils fileUtils;
|
||||
private final String url;
|
||||
|
||||
@Inject
|
||||
H2Database(DatabaseConfig config, FileUtils fileUtils, Clock clock) {
|
||||
H2Database(DatabaseConfig config, Clock clock) {
|
||||
super(HASH_TYPE, BINARY_TYPE, COUNTER_TYPE, SECRET_TYPE, clock);
|
||||
this.config = config;
|
||||
this.fileUtils = fileUtils;
|
||||
String path = new File(config.getDatabaseDirectory(), "db").getAbsolutePath();
|
||||
// FIXME: Remove WRITE_DELAY=0 after implementing BTPv2?
|
||||
url = "jdbc:h2:split:" + path + ";CIPHER=AES;MULTI_THREADED=1"
|
||||
@@ -58,15 +55,10 @@ class H2Database extends JdbcDatabase {
|
||||
public long getFreeSpace() throws DbException {
|
||||
File dir = config.getDatabaseDirectory();
|
||||
long maxSize = config.getMaxSize();
|
||||
try {
|
||||
long free = fileUtils.getFreeSpace(dir);
|
||||
long used = getDiskSpace(dir);
|
||||
long quota = maxSize - used;
|
||||
long min = Math.min(free, quota);
|
||||
return min;
|
||||
} catch (IOException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
long free = dir.getFreeSpace();
|
||||
long used = getDiskSpace(dir);
|
||||
long quota = maxSize - used;
|
||||
return Math.min(free, quota);
|
||||
}
|
||||
|
||||
private long getDiskSpace(File f) {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.briarproject.plugins.file;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH;
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.plugins.TransportConnectionReader;
|
||||
import org.briarproject.api.plugins.TransportConnectionWriter;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPlugin;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -13,12 +16,8 @@ import java.util.Locale;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.plugins.TransportConnectionReader;
|
||||
import org.briarproject.api.plugins.TransportConnectionWriter;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPlugin;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.api.transport.TransportConstants.MIN_STREAM_LENGTH;
|
||||
|
||||
public abstract class FilePlugin implements SimplexPlugin {
|
||||
|
||||
@@ -26,7 +25,6 @@ public abstract class FilePlugin implements SimplexPlugin {
|
||||
Logger.getLogger(FilePlugin.class.getName());
|
||||
|
||||
protected final Executor ioExecutor;
|
||||
protected final FileUtils fileUtils;
|
||||
protected final SimplexPluginCallback callback;
|
||||
protected final int maxLatency;
|
||||
|
||||
@@ -37,10 +35,9 @@ public abstract class FilePlugin implements SimplexPlugin {
|
||||
protected abstract void writerFinished(File f);
|
||||
protected abstract void readerFinished(File f);
|
||||
|
||||
protected FilePlugin(Executor ioExecutor, FileUtils fileUtils,
|
||||
SimplexPluginCallback callback, int maxLatency) {
|
||||
protected FilePlugin(Executor ioExecutor, SimplexPluginCallback callback,
|
||||
int maxLatency) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.fileUtils = fileUtils;
|
||||
this.callback = callback;
|
||||
this.maxLatency = maxLatency;
|
||||
}
|
||||
@@ -84,7 +81,7 @@ public abstract class FilePlugin implements SimplexPlugin {
|
||||
if (dir == null || !dir.exists() || !dir.isDirectory()) return null;
|
||||
File f = new File(dir, filename);
|
||||
try {
|
||||
long capacity = fileUtils.getFreeSpace(dir);
|
||||
long capacity = dir.getFreeSpace();
|
||||
if (capacity < MIN_STREAM_LENGTH) return null;
|
||||
OutputStream out = new FileOutputStream(f);
|
||||
return new FileTransportWriter(f, out, capacity, this);
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package org.briarproject.system;
|
||||
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FileUtilsImpl implements FileUtils {
|
||||
|
||||
public long getTotalSpace(File f) throws IOException {
|
||||
return f.getTotalSpace(); // Requires Java 1.6
|
||||
}
|
||||
|
||||
public long getFreeSpace(File f) throws IOException {
|
||||
return f.getUsableSpace(); // Requires Java 1.6
|
||||
}
|
||||
|
||||
public void deleteFileOrDir(File f) {
|
||||
if (f.isFile())
|
||||
f.delete();
|
||||
else if (f.isDirectory())
|
||||
for (File child : f.listFiles())
|
||||
deleteFileOrDir(child);
|
||||
}
|
||||
}
|
||||
15
briar-core/src/org/briarproject/util/FileUtils.java
Normal file
15
briar-core/src/org/briarproject/util/FileUtils.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package org.briarproject.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static void deleteFileOrDir(File f) {
|
||||
if (f.isFile()) {
|
||||
f.delete();
|
||||
} else if (f.isDirectory()) {
|
||||
for (File child : f.listFiles()) deleteFileOrDir(child);
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.briarproject.plugins;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.Executor;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.lifecycle.IoExecutor;
|
||||
@@ -12,24 +10,26 @@ import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginConfig;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
||||
import org.briarproject.api.reliability.ReliabilityLayerFactory;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.plugins.bluetooth.BluetoothPluginFactory;
|
||||
import org.briarproject.plugins.file.RemovableDrivePluginFactory;
|
||||
import org.briarproject.plugins.modem.ModemPluginFactory;
|
||||
import org.briarproject.plugins.tcp.LanTcpPluginFactory;
|
||||
import org.briarproject.plugins.tcp.WanTcpPluginFactory;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class DesktopPluginsModule extends PluginsModule {
|
||||
|
||||
@Provides
|
||||
SimplexPluginConfig getSimplexPluginConfig(@IoExecutor Executor ioExecutor,
|
||||
FileUtils fileUtils) {
|
||||
SimplexPluginConfig getSimplexPluginConfig(
|
||||
@IoExecutor Executor ioExecutor) {
|
||||
SimplexPluginFactory removable =
|
||||
new RemovableDrivePluginFactory(ioExecutor, fileUtils);
|
||||
new RemovableDrivePluginFactory(ioExecutor);
|
||||
final Collection<SimplexPluginFactory> factories =
|
||||
Arrays.asList(removable);
|
||||
Collections.singletonList(removable);
|
||||
return new SimplexPluginConfig() {
|
||||
public Collection<SimplexPluginFactory> getFactories() {
|
||||
return factories;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.briarproject.plugins.file;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -11,10 +13,7 @@ import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
class RemovableDrivePlugin extends FilePlugin
|
||||
implements RemovableDriveMonitor.Callback {
|
||||
@@ -27,10 +26,10 @@ implements RemovableDriveMonitor.Callback {
|
||||
private final RemovableDriveFinder finder;
|
||||
private final RemovableDriveMonitor monitor;
|
||||
|
||||
RemovableDrivePlugin(Executor ioExecutor, FileUtils fileUtils,
|
||||
SimplexPluginCallback callback, RemovableDriveFinder finder,
|
||||
RemovableDriveMonitor monitor, int maxLatency) {
|
||||
super(ioExecutor, fileUtils, callback, maxLatency);
|
||||
RemovableDrivePlugin(Executor ioExecutor, SimplexPluginCallback callback,
|
||||
RemovableDriveFinder finder, RemovableDriveMonitor monitor,
|
||||
int maxLatency) {
|
||||
super(ioExecutor, callback, maxLatency);
|
||||
this.finder = finder;
|
||||
this.monitor = monitor;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package org.briarproject.plugins.file;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPlugin;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.util.OsUtils;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
||||
|
||||
// Maximum latency 14 days (Royal Mail or lackadaisical carrier pigeon)
|
||||
@@ -16,12 +15,9 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
||||
private static final int POLLING_INTERVAL = 10 * 1000; // 10 seconds
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final FileUtils fileUtils;
|
||||
|
||||
public RemovableDrivePluginFactory(Executor ioExecutor,
|
||||
FileUtils fileUtils) {
|
||||
public RemovableDrivePluginFactory(Executor ioExecutor) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.fileUtils = fileUtils;
|
||||
}
|
||||
|
||||
public TransportId getId() {
|
||||
@@ -49,7 +45,7 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return new RemovableDrivePlugin(ioExecutor, fileUtils, callback,
|
||||
finder, monitor, MAX_LATENCY);
|
||||
return new RemovableDrivePlugin(ioExecutor, callback, finder, monitor,
|
||||
MAX_LATENCY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package org.briarproject.system;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
import org.briarproject.api.system.Clock;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.api.system.SeedProvider;
|
||||
import org.briarproject.api.system.Timer;
|
||||
import org.briarproject.util.OsUtils;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
public class DesktopSystemModule extends AbstractModule {
|
||||
|
||||
protected void configure() {
|
||||
@@ -15,6 +14,5 @@ public class DesktopSystemModule extends AbstractModule {
|
||||
bind(Timer.class).to(SystemTimer.class);
|
||||
if (OsUtils.isLinux())
|
||||
bind(SeedProvider.class).to(LinuxSeedProvider.class);
|
||||
bind(FileUtils.class).to(FileUtilsImpl.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.briarproject;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.system.FileUtilsImpl;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -26,6 +24,5 @@ public class TestDatabaseModule extends AbstractModule {
|
||||
|
||||
protected void configure() {
|
||||
bind(DatabaseConfig.class).toInstance(config);
|
||||
bind(FileUtils.class).to(FileUtilsImpl.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package org.briarproject;
|
||||
|
||||
import org.briarproject.api.UniqueId;
|
||||
import org.briarproject.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -15,27 +13,13 @@ public class TestUtils {
|
||||
new AtomicInteger((int) (Math.random() * 1000 * 1000));
|
||||
private static final Random random = new Random();
|
||||
|
||||
public static void delete(File f) {
|
||||
if (f.isDirectory()) for (File child : f.listFiles()) delete(child);
|
||||
f.delete();
|
||||
}
|
||||
|
||||
public static void createFile(File f, String s) throws IOException {
|
||||
f.getParentFile().mkdirs();
|
||||
PrintStream out = new PrintStream(new FileOutputStream(f));
|
||||
out.print(s);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
public static File getTestDirectory() {
|
||||
int name = nextTestDir.getAndIncrement();
|
||||
File testDir = new File("test.tmp/" + name);
|
||||
return testDir;
|
||||
return new File("test.tmp/" + name);
|
||||
}
|
||||
|
||||
public static void deleteTestDirectory(File testDir) {
|
||||
delete(testDir);
|
||||
FileUtils.deleteFileOrDir(testDir);
|
||||
testDir.getParentFile().delete(); // Delete if empty
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.briarproject.api.messaging.Message;
|
||||
import org.briarproject.api.messaging.MessageId;
|
||||
import org.briarproject.api.transport.Endpoint;
|
||||
import org.briarproject.api.transport.TemporarySecret;
|
||||
import org.briarproject.system.FileUtilsImpl;
|
||||
import org.briarproject.system.SystemClock;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -1611,7 +1610,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
private Database<Connection> open(boolean resume) throws Exception {
|
||||
Database<Connection> db = new H2Database(new TestDatabaseConfig(testDir,
|
||||
MAX_SIZE), new FileUtilsImpl(), new SystemClock());
|
||||
MAX_SIZE), new SystemClock());
|
||||
if (!resume) TestUtils.deleteTestDirectory(testDir);
|
||||
db.open();
|
||||
return db;
|
||||
|
||||
@@ -5,10 +5,8 @@ import org.briarproject.TestUtils;
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.plugins.TransportConnectionWriter;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginCallback;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.plugins.ImmediateExecutor;
|
||||
import org.briarproject.plugins.file.RemovableDriveMonitor.Callback;
|
||||
import org.briarproject.system.FileUtilsImpl;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.junit.After;
|
||||
@@ -34,7 +32,6 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
|
||||
private final File testDir = TestUtils.getTestDirectory();
|
||||
private final ContactId contactId = new ContactId(234);
|
||||
private final FileUtils fileUtils = new FileUtilsImpl();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -61,7 +58,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||
fileUtils, callback, finder, monitor, 0);
|
||||
callback, finder, monitor, 0);
|
||||
plugin.start();
|
||||
|
||||
assertNull(plugin.createWriter(contactId));
|
||||
@@ -96,7 +93,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||
fileUtils, callback, finder, monitor, 0);
|
||||
callback, finder, monitor, 0);
|
||||
plugin.start();
|
||||
|
||||
assertNull(plugin.createWriter(contactId));
|
||||
@@ -133,7 +130,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||
fileUtils, callback, finder, monitor, 0);
|
||||
callback, finder, monitor, 0);
|
||||
plugin.start();
|
||||
|
||||
assertNull(plugin.createWriter(contactId));
|
||||
@@ -172,7 +169,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||
fileUtils, callback, finder, monitor, 0);
|
||||
callback, finder, monitor, 0);
|
||||
plugin.start();
|
||||
|
||||
assertNull(plugin.createWriter(contactId));
|
||||
@@ -211,7 +208,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||
fileUtils, callback, finder, monitor, 0);
|
||||
callback, finder, monitor, 0);
|
||||
plugin.start();
|
||||
|
||||
assertNotNull(plugin.createWriter(contactId));
|
||||
@@ -254,7 +251,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||
fileUtils, callback, finder, monitor, 0);
|
||||
callback, finder, monitor, 0);
|
||||
plugin.start();
|
||||
|
||||
TransportConnectionWriter writer = plugin.createWriter(contactId);
|
||||
@@ -293,7 +290,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||
fileUtils, callback, finder, monitor, 0);
|
||||
callback, finder, monitor, 0);
|
||||
plugin.start();
|
||||
|
||||
plugin.driveInserted(testDir);
|
||||
@@ -313,7 +310,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
context.mock(RemovableDriveMonitor.class);
|
||||
|
||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(executor,
|
||||
fileUtils, callback, finder, monitor, 0);
|
||||
callback, finder, monitor, 0);
|
||||
|
||||
assertFalse(plugin.isPossibleConnectionFilename("abcdefg.dat"));
|
||||
assertFalse(plugin.isPossibleConnectionFilename("abcdefghi.dat"));
|
||||
@@ -341,8 +338,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
}});
|
||||
|
||||
RemovableDrivePlugin plugin = new RemovableDrivePlugin(
|
||||
new ImmediateExecutor(), fileUtils, callback, finder, monitor,
|
||||
0);
|
||||
new ImmediateExecutor(), callback, finder, monitor, 0);
|
||||
plugin.start();
|
||||
|
||||
File f = new File(testDir, "abcdefgh.dat");
|
||||
|
||||
Reference in New Issue
Block a user