diff --git a/briar-android/res/layout/activity_password.xml b/briar-android/res/layout/activity_password.xml
index bda170a94..d69ff185f 100644
--- a/briar-android/res/layout/activity_password.xml
+++ b/briar-android/res/layout/activity_password.xml
@@ -40,7 +40,6 @@
android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLines="1" />
-
-
@@ -28,6 +29,8 @@
android:id="@+id/nickname_entry_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_below="@id/nickname_title"
app:errorEnabled="true">
@@ -49,6 +55,8 @@
android:id="@+id/password_entry_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_below="@id/password_title"
app:errorEnabled="true">
@@ -70,6 +81,8 @@
android:id="@+id/password_confirm_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_below="@id/password_confirm_title"
app:errorEnabled="true">
-
+ android:layout_alignTop="@id/create_account"
+ android:layout_alignBottom="@id/create_account"
+ android:layout_centerHorizontal="true"
+ android:visibility="invisible" />
+
+
+
\ 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
index a36252747..138d3447a 100644
--- a/briar-android/src/org/briarproject/android/BaseActivity.java
+++ b/briar-android/src/org/briarproject/android/BaseActivity.java
@@ -4,6 +4,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
+import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
@@ -31,7 +32,6 @@ import roboguice.inject.RoboInjector;
import roboguice.util.RoboContext;
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
-import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY;
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS;
@@ -39,7 +39,7 @@ public abstract class BaseActivity extends AppCompatActivity
implements RoboContext {
private final static String PREFS_DB = "db";
- private final static String KEY_DB_KEY = "key";
+ private final static String PREFS_KEY = "key";
private final HashMap, Object> scopedObjects =
new HashMap, Object>();
@@ -128,38 +128,24 @@ public abstract class BaseActivity extends AppCompatActivity
return scopedObjects;
}
- private SharedPreferences getBriarPrefs(String prefsName) {
- return getSharedPreferences(prefsName, MODE_PRIVATE);
+ private SharedPreferences getSharedPrefs() {
+ return getSharedPreferences(PREFS_DB, MODE_PRIVATE);
}
- protected String getDbKeyInHex() {
- return getBriarPrefs(PREFS_DB).getString(KEY_DB_KEY, null);
+ protected String getEncryptedDatabaseKey() {
+ return getSharedPrefs().getString(PREFS_KEY, null);
}
- private void clearPrefs(String prefsName) {
- SharedPreferences.Editor editor = getBriarPrefs(prefsName).edit();
- editor.clear();
+ protected void storeEncryptedDatabaseKey(final String hex) {
+ SharedPreferences.Editor editor = getSharedPrefs().edit();
+ editor.putString(PREFS_KEY, hex);
editor.apply();
}
- protected void clearDbPrefs() {
- 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 toggleSoftKeyboard() {
- Object o = getSystemService(INPUT_METHOD_SERVICE);
- ((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
+ protected void clearSharedPrefs() {
+ SharedPreferences.Editor editor = getSharedPrefs().edit();
+ editor.clear();
+ editor.apply();
}
protected void showSoftKeyboard(View view) {
@@ -168,8 +154,8 @@ public abstract class BaseActivity extends AppCompatActivity
}
protected void hideSoftKeyboard(View view) {
+ IBinder token = view.getWindowToken();
Object o = getSystemService(INPUT_METHOD_SERVICE);
- ((InputMethodManager) o).hideSoftInputFromWindow(view.getWindowToken(),
- 0);
+ ((InputMethodManager) o).hideSoftInputFromWindow(token, 0);
}
}
diff --git a/briar-android/src/org/briarproject/android/PasswordActivity.java b/briar-android/src/org/briarproject/android/PasswordActivity.java
index 353cb0953..a1f06a3ea 100644
--- a/briar-android/src/org/briarproject/android/PasswordActivity.java
+++ b/briar-android/src/org/briarproject/android/PasswordActivity.java
@@ -38,7 +38,6 @@ public class PasswordActivity extends BaseActivity {
@Inject @CryptoExecutor private Executor cryptoExecutor;
private Button signInButton;
private ProgressBar progress;
- private TextView title;
private TextInputLayout input;
private EditText password;
@@ -52,9 +51,9 @@ public class PasswordActivity extends BaseActivity {
public void onCreate(Bundle state) {
super.onCreate(state);
- String hex = getDbKeyInHex();
+ String hex = getEncryptedDatabaseKey();
if (hex == null || !databaseConfig.databaseExists()) {
- clearDbPrefs();
+ clearSharedPrefsAndDeleteDatabase();
return;
}
encrypted = StringUtils.fromHexString(hex);
@@ -62,7 +61,6 @@ public class PasswordActivity extends BaseActivity {
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);
input = (TextInputLayout) findViewById(R.id.password_layout);
password = (EditText) findViewById(R.id.edit_password);
password.setOnEditorActionListener(new OnEditorActionListener() {
@@ -98,11 +96,12 @@ public class PasswordActivity extends BaseActivity {
startActivity(intent);
}
- @Override
- protected void clearDbPrefs() {
- super.clearDbPrefs();
+ private void clearSharedPrefsAndDeleteDatabase() {
+ clearSharedPrefs();
FileUtils.deleteFileOrDir(databaseConfig.getDatabaseDirectory());
- gotoAndFinish(SetupActivity.class, RESULT_CANCELED);
+ setResult(RESULT_CANCELED);
+ startActivity(new Intent(this, SetupActivity.class));
+ finish();
}
public void onSignInClick(View v) {
@@ -115,12 +114,13 @@ public class PasswordActivity extends BaseActivity {
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();
- }
- });
+ builder.setPositiveButton(R.string.yes,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ clearSharedPrefsAndDeleteDatabase();
+ }
+ });
AlertDialog dialog = builder.create();
dialog.show();
}
diff --git a/briar-android/src/org/briarproject/android/SetupActivity.java b/briar-android/src/org/briarproject/android/SetupActivity.java
index 380792bf1..237dca1f8 100644
--- a/briar-android/src/org/briarproject/android/SetupActivity.java
+++ b/briar-android/src/org/briarproject/android/SetupActivity.java
@@ -1,8 +1,6 @@
package org.briarproject.android;
import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.text.Editable;
@@ -38,7 +36,6 @@ import javax.inject.Inject;
import roboguice.inject.InjectView;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
-import static android.view.View.GONE;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
@@ -134,8 +131,8 @@ public class SetupActivity extends BaseActivity implements OnClickListener,
}
public void onClick(View view) {
- // Replace the feedback text and button with a progress bar
- createAccountButton.setVisibility(GONE);
+ // Replace the button with a progress bar
+ createAccountButton.setVisibility(INVISIBLE);
progress.setVisibility(VISIBLE);
final String nickname = nicknameEntry.getText().toString();
final String password = passwordEntry.getText().toString();
@@ -144,8 +141,8 @@ public class SetupActivity extends BaseActivity implements OnClickListener,
public void run() {
SecretKey key = crypto.generateSecretKey();
databaseConfig.setEncryptionKey(key);
- byte[] encrypted = encryptDatabaseKey(key, password);
- storeEncryptedDatabaseKey(encrypted);
+ String hex = encryptDatabaseKey(key, password);
+ storeEncryptedDatabaseKey(hex);
LocalAuthor localAuthor = createLocalAuthor(nickname);
showDashboard(referenceManager.putReference(localAuthor,
LocalAuthor.class));
@@ -153,24 +150,13 @@ public class SetupActivity extends BaseActivity implements OnClickListener,
});
}
- private void storeEncryptedDatabaseKey(final byte[] encrypted) {
- long now = System.currentTimeMillis();
- SharedPreferences prefs = getSharedPreferences("db", MODE_PRIVATE);
- Editor editor = prefs.edit();
- editor.putString("key", StringUtils.toHexString(encrypted));
- editor.commit();
- long duration = System.currentTimeMillis() - now;
- if (LOG.isLoggable(INFO))
- LOG.info("Key storage took " + duration + " ms");
- }
-
- private byte[] encryptDatabaseKey(SecretKey key, String password) {
+ private String encryptDatabaseKey(SecretKey key, String password) {
long now = System.currentTimeMillis();
byte[] encrypted = crypto.encryptWithPassword(key.getBytes(), password);
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Key derivation took " + duration + " ms");
- return encrypted;
+ return StringUtils.toHexString(encrypted);
}
private LocalAuthor createLocalAuthor(String nickname) {