diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-07-01 14:16:54 +0200 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-07-01 14:16:54 +0200 |
commit | 79f37d3267883110dd1a6ccaf29d8a228fc86176 (patch) | |
tree | e36b0d95a478b20e2128cf828dde1bed7ff75181 /OpenKeychain | |
parent | 88f8a388541404674703c9e1f69029ec2a09c148 (diff) | |
download | open-keychain-79f37d3267883110dd1a6ccaf29d8a228fc86176.tar.gz open-keychain-79f37d3267883110dd1a6ccaf29d8a228fc86176.tar.bz2 open-keychain-79f37d3267883110dd1a6ccaf29d8a228fc86176.zip |
Use operation helper for move to card
Diffstat (limited to 'OpenKeychain')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java | 101 |
1 files changed, 64 insertions, 37 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index 52083a552..7a083ba5e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -18,13 +18,11 @@ package org.sufficientlysecure.keychain.ui; import android.app.Activity; -import android.app.ProgressDialog; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; -import android.os.Message; -import android.os.Messenger; +import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -43,21 +41,17 @@ import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.ExportKeyringParcel; -import org.sufficientlysecure.keychain.service.KeychainService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel; -import org.sufficientlysecure.keychain.service.ServiceProgressHandler; -import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; -import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; import java.util.Iterator; -public class CreateKeyFinalFragment extends CryptoOperationFragment<SaveKeyringParcel, OperationResult> { +public class CreateKeyFinalFragment extends Fragment { public static final int REQUEST_EDIT_KEY = 0x00008007; @@ -73,6 +67,7 @@ public class CreateKeyFinalFragment extends CryptoOperationFragment<SaveKeyringP private CryptoOperationHelper<ExportKeyringParcel, ExportResult> mUploadOpHelper; private CryptoOperationHelper<SaveKeyringParcel, EditKeyResult> mCreateOpHelper; + private CryptoOperationHelper<SaveKeyringParcel, EditKeyResult> mMoveToCardOpHelper; public static CreateKeyFinalFragment newInstance() { CreateKeyFinalFragment frag = new CreateKeyFinalFragment(); @@ -150,6 +145,16 @@ public class CreateKeyFinalFragment extends CryptoOperationFragment<SaveKeyringP @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (mCreateOpHelper != null) { + mCreateOpHelper.handleActivityResult(requestCode, resultCode, data); + } + if (mMoveToCardOpHelper != null) { + mMoveToCardOpHelper.handleActivityResult(requestCode, resultCode, data); + } + if (mUploadOpHelper != null) { + mUploadOpHelper.handleActivityResult(requestCode, resultCode, data); + } + switch (requestCode) { case REQUEST_EDIT_KEY: { if (resultCode == Activity.RESULT_OK) { @@ -172,6 +177,7 @@ public class CreateKeyFinalFragment extends CryptoOperationFragment<SaveKeyringP if (mSaveKeyringParcel == null) { mSaveKeyringParcel = new SaveKeyringParcel(); + if (createKeyActivity.mUseSmartCardSettings) { mSaveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Algorithm.RSA, 2048, null, KeyFlags.SIGN_DATA | KeyFlags.CERTIFY_OTHER, 0L)); @@ -223,10 +229,7 @@ public class CreateKeyFinalFragment extends CryptoOperationFragment<SaveKeyringP public void onCryptoOperationSuccess(EditKeyResult result) { if (createKeyActivity.mUseSmartCardSettings) { - // save key id in between - mSaveKeyringParcel.mMasterKeyId = result.mMasterKeyId; - // calls cryptoOperation corresponding to moveToCard - cryptoOperation(new CryptoInputParcel()); + moveToCard(result); return; } @@ -264,28 +267,26 @@ public class CreateKeyFinalFragment extends CryptoOperationFragment<SaveKeyringP mCreateOpHelper.cryptoOperation(); } - // currently only used for moveToCard - @Override - public SaveKeyringParcel createOperationInput() { + private void moveToCard(final EditKeyResult saveKeyResult) { CachedPublicKeyRing key = (new ProviderHelper(getActivity())) - .getCachedPublicKeyRing(mSaveKeyringParcel.mMasterKeyId); + .getCachedPublicKeyRing(saveKeyResult.mMasterKeyId); - // overwrite mSaveKeyringParcel! + final SaveKeyringParcel changeKeyringParcel; try { - mSaveKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint()); + changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint()); } catch (PgpKeyNotFoundException e) { Log.e(Constants.TAG, "Key that should be moved to YubiKey not found in database!"); - return null; + return; } Cursor cursor = getActivity().getContentResolver().query( - KeychainContract.Keys.buildKeysUri(mSaveKeyringParcel.mMasterKeyId), + KeychainContract.Keys.buildKeysUri(changeKeyringParcel.mMasterKeyId), new String[]{KeychainContract.Keys.KEY_ID,}, null, null, null ); try { while (cursor != null && cursor.moveToNext()) { long subkeyId = cursor.getLong(0); - mSaveKeyringParcel.getOrCreateSubkeyChange(subkeyId).mMoveKeyToCard = true; + changeKeyringParcel.getOrCreateSubkeyChange(subkeyId).mMoveKeyToCard = true; } } finally { if (cursor != null) { @@ -293,27 +294,53 @@ public class CreateKeyFinalFragment extends CryptoOperationFragment<SaveKeyringP } } - return mSaveKeyringParcel; - } + CryptoOperationHelper.Callback<SaveKeyringParcel, EditKeyResult> callback + = new CryptoOperationHelper.Callback<SaveKeyringParcel, EditKeyResult>() { - // currently only used for moveToCard - @Override - public void onCryptoOperationSuccess(OperationResult result) { - EditKeyResult editResult = (EditKeyResult) result; + @Override + public SaveKeyringParcel createOperationInput() { + return changeKeyringParcel; + } + + @Override + public void onCryptoOperationSuccess(EditKeyResult result) { + handleResult(result); + } + + @Override + public void onCryptoOperationCancelled() { + + } + + @Override + public void onCryptoOperationError(EditKeyResult result) { + handleResult(result); + } + + public void handleResult(EditKeyResult result) { + if (result.mMasterKeyId != null && mUploadCheckbox.isChecked()) { + // result will be displayed after upload + uploadKey(result); + return; + } + + Intent data = new Intent(); + data.putExtra(OperationResult.EXTRA_RESULT, result); + getActivity().setResult(Activity.RESULT_OK, data); + getActivity().finish(); + } + + @Override + public boolean onCryptoSetProgress(String msg, int progress, int max) { + return false; + } + }; - if (editResult.mMasterKeyId != null && mUploadCheckbox.isChecked()) { - // result will be displayed after upload - uploadKey(editResult); - return; - } - Intent data = new Intent(); - data.putExtra(OperationResult.EXTRA_RESULT, result); - getActivity().setResult(Activity.RESULT_OK, data); - getActivity().finish(); + mMoveToCardOpHelper = new CryptoOperationHelper<>(this, callback, R.string.progress_modify); + mMoveToCardOpHelper.cryptoOperation(); } - // TODO move into EditKeyOperation private void uploadKey(final EditKeyResult saveKeyResult) { // set data uri as path to keyring final Uri blobUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri( |