mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-18 05:12:16 -05:00
instrument: change handling in PassphraseDialogActivity to work with espresso
This commit is contained in:
parent
db0266c0ae
commit
ae199313ee
@ -46,6 +46,7 @@ import static android.support.test.espresso.action.ViewActions.typeText;
|
|||||||
import static android.support.test.espresso.matcher.RootMatchers.isDialog;
|
import static android.support.test.espresso.matcher.RootMatchers.isDialog;
|
||||||
import static android.support.test.espresso.matcher.RootMatchers.isPlatformPopup;
|
import static android.support.test.espresso.matcher.RootMatchers.isPlatformPopup;
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||||
|
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||||
import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDrawer;
|
import static org.sufficientlysecure.keychain.actions.CustomActions.actionOpenDrawer;
|
||||||
import static org.sufficientlysecure.keychain.actions.CustomActions.tokenEncryptViewAddToken;
|
import static org.sufficientlysecure.keychain.actions.CustomActions.tokenEncryptViewAddToken;
|
||||||
|
|
||||||
@ -96,8 +97,11 @@ public class EncryptDecryptTests {
|
|||||||
pressBack();
|
pressBack();
|
||||||
onView(withId(R.id.decrypt_from_clipboard)).perform(click());
|
onView(withId(R.id.decrypt_from_clipboard)).perform(click());
|
||||||
|
|
||||||
// synchronization with passphrase caching thing doesn't work
|
{
|
||||||
onView(withId(R.id.passphrase_passphrase)).inRoot(isPlatformPopup()).perform(typeText("x"));
|
onView(withId(R.id.passphrase_passphrase)).perform(typeText("x"));
|
||||||
|
|
||||||
|
onView(withText(R.string.btn_unlock)).perform(click());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
@ -43,14 +44,12 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
||||||
@ -75,8 +74,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
|
|
||||||
// special extra for OpenPgpService
|
// special extra for OpenPgpService
|
||||||
public static final String EXTRA_SERVICE_INTENT = "data";
|
public static final String EXTRA_SERVICE_INTENT = "data";
|
||||||
|
private long mSubKeyId;
|
||||||
private static final int REQUEST_CODE_ENTER_PATTERN = 2;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -93,14 +91,13 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
|
|
||||||
// this activity itself has no content view (see manifest)
|
// this activity itself has no content view (see manifest)
|
||||||
|
|
||||||
long keyId;
|
|
||||||
if (getIntent().hasExtra(EXTRA_SUBKEY_ID)) {
|
if (getIntent().hasExtra(EXTRA_SUBKEY_ID)) {
|
||||||
keyId = getIntent().getLongExtra(EXTRA_SUBKEY_ID, 0);
|
mSubKeyId = getIntent().getLongExtra(EXTRA_SUBKEY_ID, 0);
|
||||||
} else {
|
} else {
|
||||||
RequiredInputParcel requiredInput = getIntent().getParcelableExtra(EXTRA_REQUIRED_INPUT);
|
RequiredInputParcel requiredInput = getIntent().getParcelableExtra(EXTRA_REQUIRED_INPUT);
|
||||||
switch (requiredInput.mType) {
|
switch (requiredInput.mType) {
|
||||||
case PASSPHRASE_SYMMETRIC: {
|
case PASSPHRASE_SYMMETRIC: {
|
||||||
keyId = Constants.key.symmetric;
|
mSubKeyId = Constants.key.symmetric;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PASSPHRASE: {
|
case PASSPHRASE: {
|
||||||
@ -127,7 +124,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
keyId = requiredInput.getSubKeyId();
|
mSubKeyId = requiredInput.getSubKeyId();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -136,62 +133,35 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent serviceIntent = getIntent().getParcelableExtra(EXTRA_SERVICE_INTENT);
|
|
||||||
|
|
||||||
show(this, keyId, serviceIntent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onResume() {
|
||||||
switch (requestCode) {
|
super.onResume();
|
||||||
case REQUEST_CODE_ENTER_PATTERN: {
|
|
||||||
/*
|
|
||||||
* NOTE that there are 4 possible result codes!!!
|
|
||||||
*/
|
|
||||||
switch (resultCode) {
|
|
||||||
case RESULT_OK:
|
|
||||||
// The user passed
|
|
||||||
break;
|
|
||||||
case RESULT_CANCELED:
|
|
||||||
// The user cancelled the task
|
|
||||||
break;
|
|
||||||
// case LockPatternActivity.RESULT_FAILED:
|
|
||||||
// // The user failed to enter the pattern
|
|
||||||
// break;
|
|
||||||
// case LockPatternActivity.RESULT_FORGOT_PATTERN:
|
|
||||||
// // The user forgot the pattern and invoked your recovery Activity.
|
|
||||||
// break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/* Show passphrase dialog to cache a new passphrase the user enters for using it later for
|
||||||
* In any case, there's always a key EXTRA_RETRY_COUNT, which holds
|
|
||||||
* the number of tries that the user did.
|
|
||||||
*/
|
|
||||||
// int retryCount = data.getIntExtra(
|
|
||||||
// LockPatternActivity.EXTRA_RETRY_COUNT, 0);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows passphrase dialog to cache a new passphrase the user enters for using it later for
|
|
||||||
* encryption. Based on mSecretKeyId it asks for a passphrase to open a private key or it asks
|
* encryption. Based on mSecretKeyId it asks for a passphrase to open a private key or it asks
|
||||||
* for a symmetric passphrase
|
* for a symmetric passphrase
|
||||||
*/
|
*/
|
||||||
public static void show(final FragmentActivity context, final long keyId, final Intent serviceIntent) {
|
|
||||||
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
|
Intent serviceIntent = getIntent().getParcelableExtra(EXTRA_SERVICE_INTENT);
|
||||||
public void run() {
|
|
||||||
// do NOT check if the key even needs a passphrase. that's not our job here.
|
|
||||||
PassphraseDialogFragment frag = new PassphraseDialogFragment();
|
PassphraseDialogFragment frag = new PassphraseDialogFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putLong(EXTRA_SUBKEY_ID, keyId);
|
args.putLong(EXTRA_SUBKEY_ID, mSubKeyId);
|
||||||
args.putParcelable(EXTRA_SERVICE_INTENT, serviceIntent);
|
args.putParcelable(EXTRA_SERVICE_INTENT, serviceIntent);
|
||||||
frag.setArguments(args);
|
frag.setArguments(args);
|
||||||
frag.show(context.getSupportFragmentManager(), "passphraseDialog");
|
frag.show(getSupportFragmentManager(), "passphraseDialog");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
|
||||||
|
DialogFragment dialog = (DialogFragment) getSupportFragmentManager().findFragmentByTag("passphraseDialog");
|
||||||
|
if (dialog != null) {
|
||||||
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PassphraseDialogFragment extends DialogFragment implements TextView.OnEditorActionListener {
|
public static class PassphraseDialogFragment extends DialogFragment implements TextView.OnEditorActionListener {
|
||||||
@ -205,9 +175,6 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
|
|
||||||
private Intent mServiceIntent;
|
private Intent mServiceIntent;
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates dialog
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
@ -268,12 +235,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
userId = null;
|
userId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get key type for message */
|
keyType = mSecretRing.getSecretKey(mSubKeyId).getSecretKeyType();
|
||||||
// find a master key id for our key
|
|
||||||
long masterKeyId = new ProviderHelper(activity).getMasterKeyId(mSubKeyId);
|
|
||||||
CachedPublicKeyRing keyRing = new ProviderHelper(activity).getCachedPublicKeyRing(masterKeyId);
|
|
||||||
// get the type of key (from the database)
|
|
||||||
keyType = keyRing.getSecretKeyType(mSubKeyId);
|
|
||||||
switch (keyType) {
|
switch (keyType) {
|
||||||
case PASSPHRASE:
|
case PASSPHRASE:
|
||||||
message = getString(R.string.passphrase_for, userId);
|
message = getString(R.string.passphrase_for, userId);
|
||||||
@ -468,20 +430,16 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
|
|
||||||
// note we need no synchronization here, this variable is only accessed in the ui thread
|
// note we need no synchronization here, this variable is only accessed in the ui thread
|
||||||
mIsCancelled = true;
|
mIsCancelled = true;
|
||||||
|
|
||||||
|
getActivity().setResult(RESULT_CANCELED);
|
||||||
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss(DialogInterface dialog) {
|
public void onDismiss(DialogInterface dialog) {
|
||||||
super.onDismiss(dialog);
|
super.onDismiss(dialog);
|
||||||
|
|
||||||
if (getActivity() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
hideKeyboard();
|
hideKeyboard();
|
||||||
|
|
||||||
getActivity().setResult(RESULT_CANCELED);
|
|
||||||
getActivity().finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideKeyboard() {
|
private void hideKeyboard() {
|
||||||
@ -495,11 +453,9 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Associate the "done" button on the soft keyboard with the okay button in the view
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
|
// Associate the "done" button on the soft keyboard with the okay button in the view
|
||||||
if (EditorInfo.IME_ACTION_DONE == actionId) {
|
if (EditorInfo.IME_ACTION_DONE == actionId) {
|
||||||
AlertDialog dialog = ((AlertDialog) getDialog());
|
AlertDialog dialog = ((AlertDialog) getDialog());
|
||||||
Button bt = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
Button bt = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
|
Loading…
Reference in New Issue
Block a user