mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
Added dependency injections for FileUtils and removed redundant code
This commit is contained in:
@@ -45,7 +45,6 @@ import org.briarproject.android.util.LayoutUtils;
|
|||||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||||
import org.briarproject.api.android.AndroidExecutor;
|
import org.briarproject.api.android.AndroidExecutor;
|
||||||
import org.briarproject.api.system.FileUtils;
|
import org.briarproject.api.system.FileUtils;
|
||||||
import org.briarproject.system.AndroidFileUtils;
|
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.util.StringUtils;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
@@ -71,12 +70,14 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
public class CrashReportActivity extends Activity implements OnClickListener {
|
public class CrashReportActivity extends Activity implements OnClickListener {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(CrashReportActivity.class.getName());
|
Logger.getLogger(CrashReportActivity.class.getName());
|
||||||
|
|
||||||
private final FileUtils fileUtils = new AndroidFileUtils();
|
@Inject private FileUtils fileUtils;
|
||||||
private final AndroidExecutor androidExecutor = new AndroidExecutorImpl();
|
private final AndroidExecutor androidExecutor = new AndroidExecutorImpl();
|
||||||
|
|
||||||
private ScrollView scroll = null;
|
private ScrollView scroll = null;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import org.briarproject.api.crypto.CryptoComponent;
|
|||||||
import org.briarproject.api.crypto.CryptoExecutor;
|
import org.briarproject.api.crypto.CryptoExecutor;
|
||||||
import org.briarproject.api.crypto.SecretKey;
|
import org.briarproject.api.crypto.SecretKey;
|
||||||
import org.briarproject.api.db.DatabaseConfig;
|
import org.briarproject.api.db.DatabaseConfig;
|
||||||
import org.briarproject.system.AndroidFileUtils;
|
import org.briarproject.api.system.FileUtils;
|
||||||
import org.briarproject.util.StringUtils;
|
import org.briarproject.util.StringUtils;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -41,6 +41,7 @@ public class PasswordActivity extends BaseActivity {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile CryptoComponent crypto;
|
@Inject private volatile CryptoComponent crypto;
|
||||||
@Inject private volatile DatabaseConfig databaseConfig;
|
@Inject private volatile DatabaseConfig databaseConfig;
|
||||||
|
@Inject private FileUtils fileUtils;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
@@ -72,7 +73,7 @@ public class PasswordActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void clearDbPrefs() {
|
protected void clearDbPrefs() {
|
||||||
super.clearDbPrefs();
|
super.clearDbPrefs();
|
||||||
AndroidFileUtils.deleteFileOrDir(databaseConfig.getDatabaseDirectory());
|
fileUtils.deleteFileOrDir(databaseConfig.getDatabaseDirectory());
|
||||||
gotoAndFinish(SetupActivity.class, RESULT_CANCELED);
|
gotoAndFinish(SetupActivity.class, RESULT_CANCELED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
package org.briarproject.system;
|
|
||||||
|
|
||||||
import org.briarproject.api.system.FileUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class AndroidFileUtils implements FileUtils {
|
|
||||||
|
|
||||||
public long getTotalSpace(File f) throws IOException {
|
|
||||||
return f.getTotalSpace();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getFreeSpace(File f) throws IOException {
|
|
||||||
return f.getUsableSpace();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void deleteFileOrDir(File f) {
|
|
||||||
if (f.isFile())
|
|
||||||
f.delete();
|
|
||||||
else if (f.isDirectory())
|
|
||||||
for (File child : f.listFiles())
|
|
||||||
deleteFileOrDir(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,7 +14,7 @@ public class AndroidSystemModule extends AbstractModule {
|
|||||||
bind(Clock.class).to(SystemClock.class);
|
bind(Clock.class).to(SystemClock.class);
|
||||||
bind(Timer.class).to(SystemTimer.class);
|
bind(Timer.class).to(SystemTimer.class);
|
||||||
bind(SeedProvider.class).to(AndroidSeedProvider.class);
|
bind(SeedProvider.class).to(AndroidSeedProvider.class);
|
||||||
bind(FileUtils.class).to(AndroidFileUtils.class);
|
bind(FileUtils.class).to(FileUtilsImpl.class);
|
||||||
bind(LocationUtils.class).to(AndroidLocationUtils.class);
|
bind(LocationUtils.class).to(AndroidLocationUtils.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,6 @@ public interface FileUtils {
|
|||||||
long getTotalSpace(File f) throws IOException;
|
long getTotalSpace(File f) throws IOException;
|
||||||
|
|
||||||
long getFreeSpace(File f) throws IOException;
|
long getFreeSpace(File f) throws IOException;
|
||||||
|
|
||||||
|
void deleteFileOrDir(File f);
|
||||||
}
|
}
|
||||||
|
|||||||
25
briar-core/src/org/briarproject/system/FileUtilsImpl.java
Normal file
25
briar-core/src/org/briarproject/system/FileUtilsImpl.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package org.briarproject.system;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.briarproject.api.system.FileUtils;
|
|
||||||
|
|
||||||
class DesktopFileUtils 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,6 +15,6 @@ public class DesktopSystemModule extends AbstractModule {
|
|||||||
bind(Timer.class).to(SystemTimer.class);
|
bind(Timer.class).to(SystemTimer.class);
|
||||||
if (OsUtils.isLinux())
|
if (OsUtils.isLinux())
|
||||||
bind(SeedProvider.class).to(LinuxSeedProvider.class);
|
bind(SeedProvider.class).to(LinuxSeedProvider.class);
|
||||||
bind(FileUtils.class).to(DesktopFileUtils.class);
|
bind(FileUtils.class).to(FileUtilsImpl.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.google.inject.AbstractModule;
|
|||||||
|
|
||||||
import org.briarproject.api.db.DatabaseConfig;
|
import org.briarproject.api.db.DatabaseConfig;
|
||||||
import org.briarproject.api.system.FileUtils;
|
import org.briarproject.api.system.FileUtils;
|
||||||
|
import org.briarproject.system.FileUtilsImpl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@@ -25,6 +26,6 @@ public class TestDatabaseModule extends AbstractModule {
|
|||||||
|
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(DatabaseConfig.class).toInstance(config);
|
bind(DatabaseConfig.class).toInstance(config);
|
||||||
bind(FileUtils.class).to(TestFileUtils.class);
|
bind(FileUtils.class).to(FileUtilsImpl.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package org.briarproject;
|
|
||||||
|
|
||||||
import org.briarproject.api.system.FileUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class TestFileUtils implements FileUtils {
|
|
||||||
|
|
||||||
public long getTotalSpace(File f) throws IOException {
|
|
||||||
return f.getTotalSpace();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getFreeSpace(File f) throws IOException {
|
|
||||||
return f.getUsableSpace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ package org.briarproject.db;
|
|||||||
|
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
import org.briarproject.TestDatabaseConfig;
|
import org.briarproject.TestDatabaseConfig;
|
||||||
import org.briarproject.TestFileUtils;
|
|
||||||
import org.briarproject.TestMessage;
|
import org.briarproject.TestMessage;
|
||||||
import org.briarproject.TestUtils;
|
import org.briarproject.TestUtils;
|
||||||
import org.briarproject.api.Author;
|
import org.briarproject.api.Author;
|
||||||
@@ -20,6 +19,7 @@ import org.briarproject.api.messaging.Message;
|
|||||||
import org.briarproject.api.messaging.MessageId;
|
import org.briarproject.api.messaging.MessageId;
|
||||||
import org.briarproject.api.transport.Endpoint;
|
import org.briarproject.api.transport.Endpoint;
|
||||||
import org.briarproject.api.transport.TemporarySecret;
|
import org.briarproject.api.transport.TemporarySecret;
|
||||||
|
import org.briarproject.system.FileUtilsImpl;
|
||||||
import org.briarproject.system.SystemClock;
|
import org.briarproject.system.SystemClock;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -1610,7 +1610,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
private Database<Connection> open(boolean resume) throws Exception {
|
private Database<Connection> open(boolean resume) throws Exception {
|
||||||
Database<Connection> db = new H2Database(new TestDatabaseConfig(testDir,
|
Database<Connection> db = new H2Database(new TestDatabaseConfig(testDir,
|
||||||
MAX_SIZE), new TestFileUtils(), new SystemClock());
|
MAX_SIZE), new FileUtilsImpl(), new SystemClock());
|
||||||
if (!resume) TestUtils.deleteTestDirectory(testDir);
|
if (!resume) TestUtils.deleteTestDirectory(testDir);
|
||||||
db.open();
|
db.open();
|
||||||
return db;
|
return db;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.briarproject.plugins.file;
|
package org.briarproject.plugins.file;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import org.briarproject.BriarTestCase;
|
import org.briarproject.BriarTestCase;
|
||||||
import org.briarproject.TestFileUtils;
|
|
||||||
import org.briarproject.TestUtils;
|
import org.briarproject.TestUtils;
|
||||||
import org.briarproject.api.ContactId;
|
import org.briarproject.api.ContactId;
|
||||||
import org.briarproject.api.plugins.TransportConnectionWriter;
|
import org.briarproject.api.plugins.TransportConnectionWriter;
|
||||||
@@ -34,7 +34,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
|||||||
|
|
||||||
private final File testDir = TestUtils.getTestDirectory();
|
private final File testDir = TestUtils.getTestDirectory();
|
||||||
private final ContactId contactId = new ContactId(234);
|
private final ContactId contactId = new ContactId(234);
|
||||||
private final FileUtils fileUtils = new TestFileUtils();
|
@Inject private FileUtils fileUtils;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|||||||
Reference in New Issue
Block a user