aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-08-31 17:32:13 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-08-31 17:32:13 +0200
commit7da783228499ea9d5b0a98201e8ba5b17e30bb10 (patch)
tree610e3d5ef33d717eaa56d091ebe7d92c5b237bbb /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
parent38c6cf045c6e451b3a150bf9b659056c2252d27c (diff)
downloadopen-keychain-7da783228499ea9d5b0a98201e8ba5b17e30bb10.tar.gz
open-keychain-7da783228499ea9d5b0a98201e8ba5b17e30bb10.tar.bz2
open-keychain-7da783228499ea9d5b0a98201e8ba5b17e30bb10.zip
Add cancelable mechanism and support in key import
Closes #323
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
index 021e6bc07..bc570385a 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
@@ -72,6 +72,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* This Service contains all important long lasting operations for APG. It receives Intents with
@@ -110,6 +111,8 @@ public class KeychainIntentService extends IntentService
public static final String ACTION_CONSOLIDATE = Constants.INTENT_PREFIX + "CONSOLIDATE";
+ public static final String ACTION_CANCEL = Constants.INTENT_PREFIX + "CANCEL";
+
/* keys for data bundle */
// encrypt, decrypt, import export
@@ -196,6 +199,8 @@ public class KeychainIntentService extends IntentService
Messenger mMessenger;
private boolean mIsCanceled;
+ // this attribute can possibly merged with the one above? not sure...
+ private AtomicBoolean mActionCanceled = new AtomicBoolean(false);
public KeychainIntentService() {
super("KeychainIntentService");
@@ -214,6 +219,10 @@ public class KeychainIntentService extends IntentService
*/
@Override
protected void onHandleIntent(Intent intent) {
+
+ // We have not been cancelled! (yet)
+ mActionCanceled.set(false);
+
Bundle extras = intent.getExtras();
if (extras == null) {
Log.e(Constants.TAG, "Extras bundle is null!");
@@ -500,7 +509,7 @@ public class KeychainIntentService extends IntentService
ProviderHelper providerHelper = new ProviderHelper(this);
PgpImportExport pgpImportExport = new PgpImportExport(this, providerHelper, this);
- ImportKeyResult result = pgpImportExport.importKeyRings(entries);
+ ImportKeyResult result = pgpImportExport.importKeyRings(entries, mActionCanceled);
if (result.mSecret > 0) {
providerHelper.consolidateDatabaseStep1(this);
@@ -612,7 +621,6 @@ public class KeychainIntentService extends IntentService
ArrayList<ParcelableKeyRing> keyRings = new ArrayList<ParcelableKeyRing>(entries.size());
for (ImportKeysListEntry entry : entries) {
-
Keyserver server;
if (entry.getOrigin() == null) {
server = new HkpKeyserver(keyServer);
@@ -874,6 +882,15 @@ public class KeychainIntentService extends IntentService
}
}
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (ACTION_CANCEL.equals(intent.getAction())) {
+ mActionCanceled.set(true);
+ return START_STICKY;
+ }
+ return super.onStartCommand(intent, flags, startId);
+ }
+
private String getOriginalFilename(Bundle data) throws PgpGeneralException, FileNotFoundException {
int target = data.getInt(TARGET);
switch (target) {