diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-08-31 19:20:08 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-08-31 19:20:08 +0200 |
commit | e46bc240793f03f3cd09684a0852e33af96b2e89 (patch) | |
tree | a5418bd164bd2e57369755a815fba958d6c64279 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java | |
parent | d483a8b73e01ab80d8f9098b46df797a7298a09e (diff) | |
download | open-keychain-e46bc240793f03f3cd09684a0852e33af96b2e89.tar.gz open-keychain-e46bc240793f03f3cd09684a0852e33af96b2e89.tar.bz2 open-keychain-e46bc240793f03f3cd09684a0852e33af96b2e89.zip |
add cancel support to edit key action
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 967a7caa9..6b1433cca 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -73,6 +73,7 @@ import java.util.Arrays; import java.util.Date; import java.util.Iterator; import java.util.Stack; +import java.util.concurrent.atomic.AtomicBoolean; /** * This class is the single place where ALL operations that actually modify a PGP public or secret @@ -85,6 +86,7 @@ import java.util.Stack; */ public class PgpKeyOperation { private Stack<Progressable> mProgress; + private AtomicBoolean mCancelled; // most preferred is first private static final int[] PREFERRED_SYMMETRIC_ALGORITHMS = new int[]{ @@ -134,6 +136,15 @@ public class PgpKeyOperation { } } + public PgpKeyOperation(Progressable progress, AtomicBoolean cancelled) { + this(progress); + mCancelled = cancelled; + } + + private boolean checkCancelled() { + return mCancelled != null && mCancelled.get(); + } + private void subProgressPush(int from, int to) { if (mProgress == null) { return; @@ -450,6 +461,12 @@ public class PgpKeyOperation { try { + // Check if we were cancelled + if (checkCancelled()) { + log.add(LogLevel.CANCELLED, LogType.MSG_OPERATION_CANCELLED, indent); + return new EditKeyResult(EditKeyResult.RESULT_CANCELLED, log, null); + } + { // work on master secret key PGPPublicKey modifiedPublicKey = masterPublicKey; @@ -640,6 +657,12 @@ public class PgpKeyOperation { } + // Check if we were cancelled - again + if (checkCancelled()) { + log.add(LogLevel.CANCELLED, LogType.MSG_OPERATION_CANCELLED, indent); + return new EditKeyResult(EditKeyResult.RESULT_CANCELLED, log, null); + } + // 4a. For each subkey change, generate new subkey binding certificate subProgressPush(50, 60); for (int i = 0; i < saveParcel.mChangeSubKeys.size(); i++) { @@ -750,6 +773,12 @@ public class PgpKeyOperation { subProgressPush(70, 90); for (int i = 0; i < saveParcel.mAddSubKeys.size(); i++) { + // Check if we were cancelled - again. This operation is expensive so we do it each loop. + if (checkCancelled()) { + log.add(LogLevel.CANCELLED, LogType.MSG_OPERATION_CANCELLED, indent); + return new EditKeyResult(EditKeyResult.RESULT_CANCELLED, log, null); + } + progress(R.string.progress_modify_subkeyadd, (i-1) * (100 / saveParcel.mAddSubKeys.size())); SaveKeyringParcel.SubkeyAdd add = saveParcel.mAddSubKeys.get(i); log.add(LogLevel.INFO, LogType.MSG_MF_SUBKEY_NEW, indent, @@ -806,6 +835,12 @@ public class PgpKeyOperation { } subProgressPop(); + // Check if we were cancelled - again. This operation is expensive so we do it each loop. + if (checkCancelled()) { + log.add(LogLevel.CANCELLED, LogType.MSG_OPERATION_CANCELLED, indent); + return new EditKeyResult(EditKeyResult.RESULT_CANCELLED, log, null); + } + // 6. If requested, change passphrase if (saveParcel.mNewPassphrase != null) { progress(R.string.progress_modify_passphrase, 90); |