made PassphraseDialogActivity compatible with null CryptoInputParcel

This commit is contained in:
Adithya Abraham Philip
2015-07-11 16:31:29 +05:30
parent c59196a6f1
commit c1d2beb559
3 changed files with 23 additions and 6 deletions

View File

@@ -43,11 +43,12 @@ import java.util.Arrays;
public class NfcOperationActivity extends BaseNfcActivity {
public static final String EXTRA_REQUIRED_INPUT = "required_input";
public static final String EXTRA_CRYPTO_INPUT = "crypto_input";
// passthrough for OpenPgpService
public static final String EXTRA_SERVICE_INTENT = "data";
public static final String RESULT_DATA = "result_data";
public static final String RESULT_CRYPTO_INPUT = "result_data";
public ViewAnimator vAnimator;
public TextView vErrorText;
@@ -67,6 +68,14 @@ public class NfcOperationActivity extends BaseNfcActivity {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mInputParcel = getIntent().getParcelableExtra(EXTRA_CRYPTO_INPUT);
if (mInputParcel == null) {
// for compatibility when used from OpenPgpService
// (or any place other than CryptoOperationHelper)
mInputParcel = new CryptoInputParcel(mRequiredInput.mSignatureTime);
}
setTitle(R.string.nfc_text);
vAnimator = (ViewAnimator) findViewById(R.id.view_animator);
@@ -112,8 +121,6 @@ public class NfcOperationActivity extends BaseNfcActivity {
@Override
protected void doNfcInBackground() throws IOException {
mInputParcel = new CryptoInputParcel(mRequiredInput.mSignatureTime);
switch (mRequiredInput.mType) {
case NFC_DECRYPT: {
for (int i = 0; i < mRequiredInput.mInputData.length; i++) {
@@ -218,11 +225,16 @@ public class NfcOperationActivity extends BaseNfcActivity {
@Override
protected void onNfcPostExecute() throws IOException {
if (mServiceIntent != null) {
// if we're triggered by OpenPgpService
CryptoInputParcelCacheService.addCryptoInputParcel(this, mServiceIntent, mInputParcel);
mServiceIntent.putExtra(EXTRA_CRYPTO_INPUT,
getIntent().getParcelableExtra(EXTRA_CRYPTO_INPUT));
setResult(RESULT_OK, mServiceIntent);
} else {
Intent result = new Intent();
result.putExtra(NfcOperationActivity.RESULT_DATA, mInputParcel);
result.putExtra(RESULT_CRYPTO_INPUT, mInputParcel);
// send back the CryptoInputParcel we receive, to conform with the pattern in
// CryptoOperationHelper
setResult(RESULT_OK, result);
}

View File

@@ -95,6 +95,11 @@ public class PassphraseDialogActivity extends FragmentActivity {
mCryptoInputParcel = getIntent().getParcelableExtra(EXTRA_CRYPTO_INPUT);
if (mCryptoInputParcel == null) {
// not all usages of PassphraseActivity are from CryptoInputOperation
mCryptoInputParcel = new CryptoInputParcel();
}
// this activity itself has no content view (see manifest)
if (getIntent().hasExtra(EXTRA_SUBKEY_ID)) {

View File

@@ -120,13 +120,13 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
Activity activity = mUseFragment ? mFragment.getActivity() : mActivity;
switch (requiredInput.mType) {
// TODO: make NfcOperationActivity add to cryptoInputParcel
// always use CryptoOperationHelper.startActivityForResult!
case NFC_MOVE_KEY_TO_CARD:
case NFC_DECRYPT:
case NFC_SIGN: {
Intent intent = new Intent(activity, NfcOperationActivity.class);
intent.putExtra(NfcOperationActivity.EXTRA_REQUIRED_INPUT, requiredInput);
intent.putExtra(NfcOperationActivity.EXTRA_CRYPTO_INPUT, cryptoInputParcel);
startActivityForResult(intent, REQUEST_CODE_NFC);
return;
}
@@ -202,7 +202,7 @@ public class CryptoOperationHelper<T extends Parcelable, S extends OperationResu
case REQUEST_CODE_NFC: {
if (resultCode == Activity.RESULT_OK && data != null) {
CryptoInputParcel cryptoInput =
data.getParcelableExtra(NfcOperationActivity.RESULT_DATA);
data.getParcelableExtra(NfcOperationActivity.RESULT_CRYPTO_INPUT);
cryptoOperation(cryptoInput);
}
break;