diff --git a/briar-android/res/layout/activity_password.xml b/briar-android/res/layout/activity_password.xml new file mode 100644 index 0000000000000000000000000000000000000000..5a306a79cf1e8fc7d67f3f9d3cf315f83a999f11 --- /dev/null +++ b/briar-android/res/layout/activity_password.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:paddingBottom="@dimen/margin_activity_vertical" + android:paddingEnd="@dimen/margin_activity_horizontal" + android:paddingStart="@dimen/margin_activity_horizontal" + android:paddingTop="@dimen/margin_activity_vertical"> + + <TextView + android:id="@+id/title_password" + style="@style/BriarTextTitle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_centerHorizontal="true" + android:padding="@dimen/margin_large" + android:text="@string/enter_password" /> + + <EditText + android:id="@+id/edit_password" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/title_password" + android:hint="@string/password_hint" + android:imeOptions="actionDone" + android:inputType="textPassword" + android:lines="1" + android:maxLines="1" /> + + <Button + android:id="@+id/btn_sign_in" + style="@style/BriarButton.Default" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/edit_password" + android:layout_marginTop="@dimen/margin_xlarge" + android:onClick="onSignInClick" + android:text="@string/sign_in_button" /> + + <ProgressBar + android:id="@+id/progress_wheel" + style="?android:attr/progressBarStyleInverse" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_alignTop="@id/btn_sign_in" + android:visibility="invisible" /> + + <TextView + style="@style/BriarTextBody" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@id/btn_sign_in" + android:layout_centerHorizontal="true" + android:layout_marginTop="@dimen/margin_large" + android:clickable="true" + android:onClick="onForgottenPasswordClick" + android:text="@string/forgotten_password" + android:textColor="?android:attr/textColorLink" /> + +</RelativeLayout> \ No newline at end of file diff --git a/briar-android/res/values-v14/styles.xml b/briar-android/res/values-v14/styles.xml index 9fd201d23c101e862855c8b11aa02588276603a1..c1fc08f072d372b00cab63c2724370d4671ef3fc 100644 --- a/briar-android/res/values-v14/styles.xml +++ b/briar-android/res/values-v14/styles.xml @@ -9,4 +9,9 @@ <item name="android:textColor">@color/action_bar_text</item> <item name="android:background">@color/action_bar_background</item> </style> + + <style name="BriarButton.Default"> + <item name="android:textAllCaps">true</item> + </style> + </resources> \ No newline at end of file diff --git a/briar-android/res/values/color.xml b/briar-android/res/values/color.xml index 00b5d2412b0ae23a6aafb492a0935dcc6e1811fc..18e88d64c8bdc0a9de6a0259c71600308856f34b 100644 --- a/briar-android/res/values/color.xml +++ b/briar-android/res/values/color.xml @@ -14,4 +14,6 @@ <color name="no_posts">#AAAAAA</color> <color name="settings_title_text">#2D3E50</color> <color name="settings_title_underline">#2D3E50</color> + + <color name="text_link">#2D3E50</color> </resources> \ No newline at end of file diff --git a/briar-android/res/values/dimens.xml b/briar-android/res/values/dimens.xml new file mode 100644 index 0000000000000000000000000000000000000000..35c316f1216ce179e2cc4f1c6120e04fda42d7b4 --- /dev/null +++ b/briar-android/res/values/dimens.xml @@ -0,0 +1,21 @@ +<resources> + + <!-- Default screen margins, per the Android Design guidelines. --> + <dimen name="margin_activity_horizontal">16dp</dimen> + <dimen name="margin_activity_vertical">16dp</dimen> + + <dimen name="margin_seperator">1dp</dimen> + <dimen name="margin_tiny">2dp</dimen> + <dimen name="margin_small">4dp</dimen> + <dimen name="margin_medium">8dp</dimen> + <dimen name="margin_large">16dp</dimen> + <dimen name="margin_xlarge">32dp</dimen> + + <!-- v2 dimens --> + <dimen name="text_size_tiny">12sp</dimen> + <dimen name="text_size_small">14sp</dimen> + <dimen name="text_size_medium">16sp</dimen> + <dimen name="text_size_large">20sp</dimen> + <dimen name="text_size_xlarge">34sp</dimen> + +</resources> diff --git a/briar-android/res/values/strings.xml b/briar-android/res/values/strings.xml index d429004d6fda1ab03b661bf7524c71347607384c..6532d77d8a105c55ee96a9684282b88ab136f3fe 100644 --- a/briar-android/res/values/strings.xml +++ b/briar-android/res/values/strings.xml @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <resources> + + <string name="app_name">Briar</string> <string name="crash_report_title">Briar Crash Report</string> <string name="ongoing_notification_title">Signed into Briar</string> @@ -13,6 +15,10 @@ <string name="passwords_do_not_match">Passwords do not match</string> <string name="create_account_button">Create Account</string> <string name="enter_password">Enter your password:</string> + <string name="password_hint">Password</string> + <string name="yes">Yes</string> + <string name="no">No</string> + <string name="forgotten_password">I have forgotten my password</string> <string name="try_again">Wrong password, try again:</string> <string name="sign_in_button">Sign In</string> <string name="startup_failed_notification_title">Briar could not start</string> @@ -104,4 +110,8 @@ <string name="notify_sound_setting_default">Default ringtone</string> <string name="notify_sound_setting_disabled">None</string> <string name="choose_ringtone_title">Choose ringtone</string> + + <!-- Dialogs --> + <string name="dialog_title_lost_password">Lost password</string> + <string name="dialog_message_lost_password">Password recovery is not possible. Do you wish to delete your user, all contacts, and re-register ?</string> </resources> \ No newline at end of file diff --git a/briar-android/res/values/styles.xml b/briar-android/res/values/styles.xml index 79b84d8b72935e8915f2aecacfcf60ca791c4ed3..4c59289224e3ce9f970a34d2881a585bde2329c2 100644 --- a/briar-android/res/values/styles.xml +++ b/briar-android/res/values/styles.xml @@ -12,4 +12,21 @@ <style name="WindowTitleBackground"> <item name="android:background">@color/action_bar_background</item> </style> + + <style name="BriarButton"> + <item name="android:textSize">@dimen/text_size_medium</item> + <item name="android:padding">@dimen/margin_large</item> + </style> + + <style name="BriarButton.Default"/> + + <style name="BriarTextTitle"> + <item name="android:textSize">@dimen/text_size_medium</item> + <item name="android:textColor">@android:color/primary_text_light</item> + </style> + + <style name="BriarTextBody"> + <item name="android:textSize">@dimen/text_size_small</item> + <item name="android:textColor">@android:color/primary_text_light</item> + </style> </resources> \ No newline at end of file diff --git a/briar-android/src/org/briarproject/android/BaseActivity.java b/briar-android/src/org/briarproject/android/BaseActivity.java new file mode 100644 index 0000000000000000000000000000000000000000..f2b2fdeefb8c67c36cfedefca47c5de545df7cd8 --- /dev/null +++ b/briar-android/src/org/briarproject/android/BaseActivity.java @@ -0,0 +1,59 @@ +package org.briarproject.android; + +import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY; +import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS; +import static android.view.WindowManager.LayoutParams.FLAG_SECURE; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.inputmethod.InputMethodManager; + +import roboguice.activity.RoboActivity; + +public abstract class BaseActivity extends RoboActivity { + + private final static String PREFS_DB = "db"; + private final static String KEY_DB_KEY = "key"; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE); + } + + private SharedPreferences getBriarPrefs(String prefsName) { + return getSharedPreferences(prefsName, MODE_PRIVATE); + } + + protected String getDbKeyInHex() { + return getBriarPrefs(PREFS_DB).getString(KEY_DB_KEY, null); + } + + private void clearPrefs(String prefsName) { + SharedPreferences.Editor editor = getBriarPrefs(prefsName).edit(); + editor.clear(); + editor.apply(); + } + + protected void clearDbPrefs() { + this.clearPrefs(PREFS_DB); + } + + protected void gotoAndFinish(Class classInstance, int resultCode) { + if (resultCode != Integer.MIN_VALUE) + setResult(resultCode); + startActivity(new Intent(this, classInstance)); + finish(); + } + + protected void gotoAndFinish(Class classInstance) { + gotoAndFinish(classInstance, Integer.MIN_VALUE); + } + + protected void hideSoftKeyboard() { + Object o = getSystemService(INPUT_METHOD_SERVICE); + ((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0); + } +} diff --git a/briar-android/src/org/briarproject/android/BriarActivity.java b/briar-android/src/org/briarproject/android/BriarActivity.java index e098bfee7bb4ca785bd9304e0181d2d0160926df..49a02591469dc86a82f5cbd8ce8d393f88396027 100644 --- a/briar-android/src/org/briarproject/android/BriarActivity.java +++ b/briar-android/src/org/briarproject/android/BriarActivity.java @@ -25,7 +25,7 @@ import android.os.IBinder; import android.view.inputmethod.InputMethodManager; @SuppressLint("Registered") -public class BriarActivity extends RoboActivity { +public class BriarActivity extends BaseActivity { public static final int REQUEST_PASSWORD = 1; @@ -45,7 +45,6 @@ public class BriarActivity extends RoboActivity { @Override public void onCreate(Bundle state) { super.onCreate(state); - if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE); if (databaseConfig.getEncryptionKey() != null) startAndBindService(); } diff --git a/briar-android/src/org/briarproject/android/CrashReportActivity.java b/briar-android/src/org/briarproject/android/CrashReportActivity.java index 539591cb7ce94be77aa5f3a077deb5f76fc0c209..a2b8b2ac9aa1f44905f338f20d6be2d52ed2fe0d 100644 --- a/briar-android/src/org/briarproject/android/CrashReportActivity.java +++ b/briar-android/src/org/briarproject/android/CrashReportActivity.java @@ -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; diff --git a/briar-android/src/org/briarproject/android/PasswordActivity.java b/briar-android/src/org/briarproject/android/PasswordActivity.java index c3437852da16ad52cb4f3ed07df8ae70c5910551..383fa88b89dfcb709c62b3bcdfcae2041fe4bee0 100644 --- a/briar-android/src/org/briarproject/android/PasswordActivity.java +++ b/briar-android/src/org/briarproject/android/PasswordActivity.java @@ -1,138 +1,106 @@ package org.briarproject.android; -import static android.text.InputType.TYPE_CLASS_TEXT; -import static android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD; -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.view.WindowManager.LayoutParams.FLAG_SECURE; -import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY; -import static android.widget.LinearLayout.VERTICAL; -import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS; -import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH; -import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP; - -import java.io.File; + import java.util.concurrent.Executor; import javax.inject.Inject; import org.briarproject.R; -import org.briarproject.android.util.FixedVerticalSpace; -import org.briarproject.android.util.LayoutUtils; 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 roboguice.activity.RoboActivity; -import android.content.Intent; -import android.content.SharedPreferences; +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.View.OnClickListener; -import android.view.inputmethod.InputMethodManager; +import android.view.inputmethod.EditorInfo; import android.widget.Button; import android.widget.EditText; -import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; -public class PasswordActivity extends RoboActivity { +public class PasswordActivity extends BaseActivity { @Inject @CryptoExecutor private Executor cryptoExecutor; - private TextView enterPassword = null; - private EditText passwordEntry = null; - private Button signInButton = null; - private ProgressBar progress = null; + private Button signInButton; + private ProgressBar progress; + private TextView title; + private EditText password; + + private byte[] encrypted; // 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) { super.onCreate(state); - if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE); - - SharedPreferences prefs = getSharedPreferences("db", MODE_PRIVATE); - String hex = prefs.getString("key", null); + String hex = getDbKeyInHex(); if (hex == null || !databaseConfig.databaseExists()) { - // Storage has been deleted - clean up and return to setup - prefs.edit().clear().commit(); - delete(databaseConfig.getDatabaseDirectory()); - setResult(RESULT_CANCELED); - startActivity(new Intent(this, SetupActivity.class)); - finish(); + clearDbPrefs(); return; } - final byte[] encrypted = StringUtils.fromHexString(hex); - - LinearLayout layout = new LinearLayout(this); - layout.setLayoutParams(MATCH_MATCH); - layout.setOrientation(VERTICAL); - layout.setGravity(CENTER_HORIZONTAL); - int pad = LayoutUtils.getPadding(this); - layout.setPadding(pad, pad, pad, pad); - - enterPassword = new TextView(this); - enterPassword.setGravity(CENTER); - enterPassword.setTextSize(18); - enterPassword.setText(R.string.enter_password); - layout.addView(enterPassword); - - passwordEntry = new EditText(this); - passwordEntry.setId(1); - passwordEntry.setMaxLines(1); - int inputType = TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD; - passwordEntry.setInputType(inputType); - passwordEntry.setOnEditorActionListener(new OnEditorActionListener() { - public boolean onEditorAction(TextView v, int action, KeyEvent e) { - validatePassword(encrypted, passwordEntry.getText()); - return true; + 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); + password.setOnEditorActionListener(new OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == EditorInfo.IME_ACTION_DONE) { + validatePassword(encrypted, password.getText()); + } + return false; } }); - layout.addView(passwordEntry); + } - // Adjusting the padding of buttons and EditTexts has the wrong results - layout.addView(new FixedVerticalSpace(this)); + @Override + protected void clearDbPrefs() { + super.clearDbPrefs(); + fileUtils.deleteFileOrDir(databaseConfig.getDatabaseDirectory()); + gotoAndFinish(SetupActivity.class, RESULT_CANCELED); + } - signInButton = new Button(this); - signInButton.setLayoutParams(WRAP_WRAP); - signInButton.setText(R.string.sign_in_button); - signInButton.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - validatePassword(encrypted, passwordEntry.getText()); - } - }); - layout.addView(signInButton); - - progress = new ProgressBar(this); - progress.setLayoutParams(WRAP_WRAP); - progress.setIndeterminate(true); - progress.setVisibility(GONE); - layout.addView(progress); - setContentView(layout); + public void onSignInClick(View v) { + validatePassword(encrypted, password.getText()); } - private void delete(File f) { - if (f.isFile()) f.delete(); - else if (f.isDirectory()) for (File child : f.listFiles()) delete(child); + public void onForgottenPasswordClick(View v) { + // TODO Encapsulate the dialog in a re-usable fragment + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.dialog_title_lost_password); + builder.setMessage(R.string.dialog_message_lost_password); + builder.setNegativeButton(R.string.no, null); + builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + clearDbPrefs(); + } + }); + AlertDialog dialog = builder.create(); + dialog.show(); } private void validatePassword(final byte[] encrypted, Editable e) { - if (progress == null) return; // Not created yet - // Hide the soft keyboard - Object o = getSystemService(INPUT_METHOD_SERVICE); - ((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0); + hideSoftKeyboard(); // Replace the button with a progress bar - signInButton.setVisibility(GONE); + signInButton.setVisibility(View.INVISIBLE); progress.setVisibility(VISIBLE); // Decrypt the database key in a background thread final String password = e.toString(); @@ -152,10 +120,10 @@ public class PasswordActivity extends RoboActivity { private void tryAgain() { runOnUiThread(new Runnable() { public void run() { - enterPassword.setText(R.string.try_again); - passwordEntry.setText(""); + title.setText(R.string.try_again); signInButton.setVisibility(VISIBLE); progress.setVisibility(GONE); + password.setText(""); } }); } diff --git a/briar-android/src/org/briarproject/system/AndroidFileUtils.java b/briar-android/src/org/briarproject/system/AndroidFileUtils.java deleted file mode 100644 index c0beb54d8111d89102f5c8d60768c0dcf7908895..0000000000000000000000000000000000000000 --- a/briar-android/src/org/briarproject/system/AndroidFileUtils.java +++ /dev/null @@ -1,17 +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(); - } -} diff --git a/briar-android/src/org/briarproject/system/AndroidSystemModule.java b/briar-android/src/org/briarproject/system/AndroidSystemModule.java index aa6769e59bf8bcf53723af9494985d1f38e36c6c..03fd56dcc49a23bb9d86b79f3f5f79b1120ad235 100644 --- a/briar-android/src/org/briarproject/system/AndroidSystemModule.java +++ b/briar-android/src/org/briarproject/system/AndroidSystemModule.java @@ -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); } } diff --git a/briar-api/src/org/briarproject/api/system/FileUtils.java b/briar-api/src/org/briarproject/api/system/FileUtils.java index bde3960497f99d34458af49043e0968f634200e7..baf68ca0140b7b5654a6243212a7d867270d9331 100644 --- a/briar-api/src/org/briarproject/api/system/FileUtils.java +++ b/briar-api/src/org/briarproject/api/system/FileUtils.java @@ -8,4 +8,6 @@ public interface FileUtils { long getTotalSpace(File f) throws IOException; long getFreeSpace(File f) throws IOException; + + void deleteFileOrDir(File f); } diff --git a/briar-core/src/org/briarproject/system/FileUtilsImpl.java b/briar-core/src/org/briarproject/system/FileUtilsImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..923f35c9a159bc25e5cf98a8b996710664338fe1 --- /dev/null +++ b/briar-core/src/org/briarproject/system/FileUtilsImpl.java @@ -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); + } +} diff --git a/briar-desktop/src/org/briarproject/system/DesktopFileUtils.java b/briar-desktop/src/org/briarproject/system/DesktopFileUtils.java deleted file mode 100644 index c397068646923d52f59a3d912ca2fd5dd0873f72..0000000000000000000000000000000000000000 --- a/briar-desktop/src/org/briarproject/system/DesktopFileUtils.java +++ /dev/null @@ -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 - } -} diff --git a/briar-desktop/src/org/briarproject/system/DesktopSystemModule.java b/briar-desktop/src/org/briarproject/system/DesktopSystemModule.java index e6286d17d2019c4b25c6ffe582cc2438c6547857..e605fe95079c3bfe6b75d71cea214d42b8efba6b 100644 --- a/briar-desktop/src/org/briarproject/system/DesktopSystemModule.java +++ b/briar-desktop/src/org/briarproject/system/DesktopSystemModule.java @@ -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); } } diff --git a/briar-tests/src/org/briarproject/TestDatabaseModule.java b/briar-tests/src/org/briarproject/TestDatabaseModule.java index 263ec20c2f3341c504d3e88dc3c76028c3922356..c04b3ba51d27123eb7da0e8b19f8e3e537ac6504 100644 --- a/briar-tests/src/org/briarproject/TestDatabaseModule.java +++ b/briar-tests/src/org/briarproject/TestDatabaseModule.java @@ -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); } } diff --git a/briar-tests/src/org/briarproject/TestFileUtils.java b/briar-tests/src/org/briarproject/TestFileUtils.java deleted file mode 100644 index 78a02ff818068411f3b807db3dacfdf6d81c4af9..0000000000000000000000000000000000000000 --- a/briar-tests/src/org/briarproject/TestFileUtils.java +++ /dev/null @@ -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(); - } -} diff --git a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java index 5aff9c74ab98c597509f80adbec0e88c6ff006ad..430a9a7ec9d8f67ca604b70815d0d84088f153d4 100644 --- a/briar-tests/src/org/briarproject/db/H2DatabaseTest.java +++ b/briar-tests/src/org/briarproject/db/H2DatabaseTest.java @@ -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; diff --git a/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java b/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java index f4326e9e685d292c0bd54c9aa068fe270a7fb45a..cb29fc2694ec89909a934617376574b545f4158d 100644 --- a/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java +++ b/briar-tests/src/org/briarproject/plugins/file/RemovableDrivePluginTest.java @@ -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() {