add debug option to use dummy backup code (fixes #1675)
This commit is contained in:
@@ -28,6 +28,7 @@ import java.util.Random;
|
|||||||
import android.animation.ArgbEvaluator;
|
import android.animation.ArgbEvaluator;
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.animation.ValueAnimator.AnimatorUpdateListener;
|
import android.animation.ValueAnimator.AnimatorUpdateListener;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@@ -39,8 +40,12 @@ import android.support.v4.app.FragmentActivity;
|
|||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
|
import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -85,6 +90,7 @@ public class BackupCodeFragment extends CryptoOperationFragment<BackupKeyringPar
|
|||||||
|
|
||||||
private Uri mCachedBackupUri;
|
private Uri mCachedBackupUri;
|
||||||
private boolean mShareNotSave;
|
private boolean mShareNotSave;
|
||||||
|
private boolean mDebugModeAcceptAnyCode;
|
||||||
|
|
||||||
public static BackupCodeFragment newInstance(long[] masterKeyIds, boolean exportSecret) {
|
public static BackupCodeFragment newInstance(long[] masterKeyIds, boolean exportSecret) {
|
||||||
BackupCodeFragment frag = new BackupCodeFragment();
|
BackupCodeFragment frag = new BackupCodeFragment();
|
||||||
@@ -104,6 +110,41 @@ public class BackupCodeFragment extends CryptoOperationFragment<BackupKeyringPar
|
|||||||
|
|
||||||
BackupCodeState mCurrentState = BackupCodeState.STATE_UNINITIALIZED;
|
BackupCodeState mCurrentState = BackupCodeState.STATE_UNINITIALIZED;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
if (Constants.DEBUG) {
|
||||||
|
setHasOptionsMenu(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
|
if (Constants.DEBUG) {
|
||||||
|
inflater.inflate(R.menu.backup_fragment_debug_menu, menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (Constants.DEBUG && item.getItemId() == R.id.debug_accept_any_log) {
|
||||||
|
boolean newCheckedState = !item.isChecked();
|
||||||
|
item.setChecked(newCheckedState);
|
||||||
|
if (newCheckedState && TextUtils.isEmpty(mCodeEditText[0].getText())) {
|
||||||
|
mCodeEditText[0].setText("ABCDEF");
|
||||||
|
mCodeEditText[1].setText("GHIJKL");
|
||||||
|
mCodeEditText[2].setText("MNOPQR");
|
||||||
|
mCodeEditText[3].setText("STUVW");
|
||||||
|
Notify.create(getActivity(), "Actual backup code is all 'A's", Style.WARN).show();
|
||||||
|
}
|
||||||
|
mDebugModeAcceptAnyCode = newCheckedState;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
void switchState(BackupCodeState state, boolean animate) {
|
void switchState(BackupCodeState state, boolean animate) {
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
@@ -325,6 +366,11 @@ public class BackupCodeFragment extends CryptoOperationFragment<BackupKeyringPar
|
|||||||
|
|
||||||
private void checkIfCodeIsCorrect() {
|
private void checkIfCodeIsCorrect() {
|
||||||
|
|
||||||
|
if (Constants.DEBUG && mDebugModeAcceptAnyCode) {
|
||||||
|
switchState(BackupCodeState.STATE_OK, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder backupCodeInput = new StringBuilder(26);
|
StringBuilder backupCodeInput = new StringBuilder(26);
|
||||||
for (EditText editText : mCodeEditText) {
|
for (EditText editText : mCodeEditText) {
|
||||||
if (editText.getText().length() < 6) {
|
if (editText.getText().length() < 6) {
|
||||||
@@ -509,7 +555,11 @@ public class BackupCodeFragment extends CryptoOperationFragment<BackupKeyringPar
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public BackupKeyringParcel createOperationInput() {
|
public BackupKeyringParcel createOperationInput() {
|
||||||
return new BackupKeyringParcel(new Passphrase(mBackupCode), mMasterKeyIds, mExportSecret, mCachedBackupUri);
|
Passphrase passphrase = new Passphrase(mBackupCode);
|
||||||
|
if (Constants.DEBUG && mDebugModeAcceptAnyCode) {
|
||||||
|
passphrase = new Passphrase("AAAAAA-AAAAAA-AAAAAA-AAAAAA");
|
||||||
|
}
|
||||||
|
return new BackupKeyringParcel(passphrase, mMasterKeyIds, mExportSecret, mCachedBackupUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user