diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java index 0bc3ac0ab..669a7d37e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -46,6 +46,7 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; public class PgpImportExport { @@ -125,11 +126,20 @@ public class PgpImportExport { } /** Imports keys from given data. If keyIds is given only those are imported */ + public ImportKeyResult importKeyRings(List<ParcelableKeyRing> entries, + AtomicBoolean cancelled) { + return importKeyRings(entries.iterator(), entries.size(), cancelled); + } + public ImportKeyResult importKeyRings(List<ParcelableKeyRing> entries) { - return importKeyRings(entries.iterator(), entries.size()); + return importKeyRings(entries.iterator(), entries.size(), null); } public ImportKeyResult importKeyRings(Iterator<ParcelableKeyRing> entries, int num) { + return importKeyRings(entries, num, null); + } + public ImportKeyResult importKeyRings(Iterator<ParcelableKeyRing> entries, int num, + AtomicBoolean cancelled) { updateProgress(R.string.progress_importing, 0, 100); // If there aren't even any keys, do nothing here. @@ -143,6 +153,12 @@ public class PgpImportExport { int position = 0; double progSteps = 100.0 / num; for (ParcelableKeyRing entry : new IterableIterator<ParcelableKeyRing>(entries)) { + // Has this action been cancelled? If so, don't proceed any further + if (cancelled != null && cancelled.get()) { + Log.d(Constants.TAG, "CANCELLED!"); + break; + } + try { UncachedKeyRing key = UncachedKeyRing.decodeFromData(entry.getBytes()); @@ -208,9 +224,12 @@ public class PgpImportExport { } } if (log.containsWarnings()) { - resultType |= ImportKeyResult.RESULT_WITH_WARNINGS; + resultType |= ImportKeyResult.RESULT_WARNINGS; } } + if (cancelled != null && cancelled.get()) { + resultType |= ImportKeyResult.RESULT_CANCELLED; + } return new ImportKeyResult(resultType, log, newKeys, oldKeys, badKeys, secret); |