mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +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.api.android.AndroidExecutor;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.system.AndroidFileUtils;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
@@ -71,12 +70,14 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(CrashReportActivity.class.getName());
|
||||
|
||||
private final FileUtils fileUtils = new AndroidFileUtils();
|
||||
@Inject private FileUtils fileUtils;
|
||||
private final AndroidExecutor androidExecutor = new AndroidExecutorImpl();
|
||||
|
||||
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.SecretKey;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.system.AndroidFileUtils;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
@@ -41,6 +41,7 @@ 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) {
|
||||
@@ -72,7 +73,7 @@ public class PasswordActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void clearDbPrefs() {
|
||||
super.clearDbPrefs();
|
||||
AndroidFileUtils.deleteFileOrDir(databaseConfig.getDatabaseDirectory());
|
||||
fileUtils.deleteFileOrDir(databaseConfig.getDatabaseDirectory());
|
||||
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(Timer.class).to(SystemTimer.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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,6 @@ public interface FileUtils {
|
||||
long getTotalSpace(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);
|
||||
if (OsUtils.isLinux())
|
||||
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.system.FileUtils;
|
||||
import org.briarproject.system.FileUtilsImpl;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -25,6 +26,6 @@ public class TestDatabaseModule extends AbstractModule {
|
||||
|
||||
protected void configure() {
|
||||
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.TestDatabaseConfig;
|
||||
import org.briarproject.TestFileUtils;
|
||||
import org.briarproject.TestMessage;
|
||||
import org.briarproject.TestUtils;
|
||||
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.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;
|
||||
@@ -1610,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 TestFileUtils(), new SystemClock());
|
||||
MAX_SIZE), new FileUtilsImpl(), new SystemClock());
|
||||
if (!resume) TestUtils.deleteTestDirectory(testDir);
|
||||
db.open();
|
||||
return db;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.briarproject.plugins.file;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.TestFileUtils;
|
||||
import org.briarproject.TestUtils;
|
||||
import org.briarproject.api.ContactId;
|
||||
import org.briarproject.api.plugins.TransportConnectionWriter;
|
||||
@@ -34,7 +34,7 @@ public class RemovableDrivePluginTest extends BriarTestCase {
|
||||
|
||||
private final File testDir = TestUtils.getTestDirectory();
|
||||
private final ContactId contactId = new ContactId(234);
|
||||
private final FileUtils fileUtils = new TestFileUtils();
|
||||
@Inject private FileUtils fileUtils;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
Reference in New Issue
Block a user