Display backup code UI instead of passphrase on decrypt
This commit is contained in:
@@ -29,7 +29,9 @@ import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.KeyEvent;
|
||||
@@ -190,6 +192,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
||||
private EditText mPassphraseEditText;
|
||||
private TextView mPassphraseText;
|
||||
private View mInput, mProgress;
|
||||
private EditText[] mBackupCodeEditText;
|
||||
|
||||
private CanonicalizedSecretKeyRing mSecretRing = null;
|
||||
private boolean mIsCancelled = false;
|
||||
@@ -217,6 +220,13 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
||||
View view = inflater.inflate(R.layout.passphrase_dialog_backup_code, null);
|
||||
alert.setView(view);
|
||||
|
||||
mBackupCodeEditText = new EditText[4];
|
||||
mBackupCodeEditText[0] = (EditText) view.findViewById(R.id.backup_code_1);
|
||||
mBackupCodeEditText[1] = (EditText) view.findViewById(R.id.backup_code_2);
|
||||
mBackupCodeEditText[2] = (EditText) view.findViewById(R.id.backup_code_3);
|
||||
mBackupCodeEditText[3] = (EditText) view.findViewById(R.id.backup_code_4);
|
||||
setupEditTextFocusNext(mBackupCodeEditText);
|
||||
|
||||
AlertDialog dialog = alert.create();
|
||||
dialog.setButton(DialogInterface.BUTTON_POSITIVE,
|
||||
activity.getString(R.string.btn_unlock), (DialogInterface.OnClickListener) null);
|
||||
@@ -348,6 +358,34 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private static void setupEditTextFocusNext(final EditText[] backupCodes) {
|
||||
for (int i = 0; i < backupCodes.length - 1; i++) {
|
||||
|
||||
final int next = i + 1;
|
||||
|
||||
backupCodes[i].addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
boolean inserting = before < count;
|
||||
boolean cursorAtEnd = (start + count) == 6;
|
||||
|
||||
if (inserting && cursorAtEnd) {
|
||||
backupCodes[next].requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
@@ -357,7 +395,24 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
||||
positive.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final Passphrase passphrase = new Passphrase(mPassphraseEditText);
|
||||
|
||||
final Passphrase passphrase;
|
||||
if (mSubKeyId == Constants.key.backup_code) {
|
||||
StringBuilder backupCodeInput = new StringBuilder(26);
|
||||
for (EditText editText : mBackupCodeEditText) {
|
||||
if (editText.getText().length() < 6) {
|
||||
return;
|
||||
}
|
||||
backupCodeInput.append(editText.getText());
|
||||
backupCodeInput.append('-');
|
||||
}
|
||||
backupCodeInput.deleteCharAt(backupCodeInput.length() - 1);
|
||||
|
||||
Log.d(Constants.TAG, "backupCodeInput.toString()"+backupCodeInput.toString());
|
||||
passphrase = new Passphrase(backupCodeInput.toString());
|
||||
} else {
|
||||
passphrase = new Passphrase(mPassphraseEditText);
|
||||
}
|
||||
|
||||
CryptoInputParcel cryptoInputParcel =
|
||||
((PassphraseDialogActivity) getActivity()).mCryptoInputParcel;
|
||||
|
||||
@@ -136,7 +136,8 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
|
||||
}
|
||||
|
||||
case PASSPHRASE:
|
||||
case PASSPHRASE_SYMMETRIC: {
|
||||
case PASSPHRASE_SYMMETRIC:
|
||||
case BACKUP_CODE: {
|
||||
Intent intent = new Intent(activity, PassphraseDialogActivity.class);
|
||||
intent.putExtra(PassphraseDialogActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
||||
intent.putExtra(PassphraseDialogActivity.EXTRA_CRYPTO_INPUT, cryptoInputParcel);
|
||||
|
||||
Reference in New Issue
Block a user