aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-03-13 09:35:07 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-03-13 09:35:07 +0100
commitf5c50c3896fa0f406ce4b90a9470395eaf6784a4 (patch)
tree76f27ec1b0ff8b64ec50464323f829ab9dfcd5e9 /OpenPGP-Keychain
parent217f4a1cef2a851b82ef1ce69e868f3fb7e90950 (diff)
parentccdf646c199b000ac12ad2ca7ecaaf90a01d79c7 (diff)
downloadopen-keychain-f5c50c3896fa0f406ce4b90a9470395eaf6784a4.tar.gz
open-keychain-f5c50c3896fa0f406ce4b90a9470395eaf6784a4.tar.bz2
open-keychain-f5c50c3896fa0f406ce4b90a9470395eaf6784a4.zip
Merge pull request #388 from ajit766/exportkeyfix
Export is cancellable now
Diffstat (limited to 'OpenPGP-Keychain')
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java30
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java22
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java15
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/KeychainServiceListener.java5
4 files changed, 56 insertions, 16 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java
index 19dfccbde..245c5fda1 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java
@@ -16,17 +16,8 @@
package org.sufficientlysecure.keychain.helper;
-import org.sufficientlysecure.keychain.Constants;
-import org.sufficientlysecure.keychain.Id;
-import org.sufficientlysecure.keychain.R;
-import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
-import org.sufficientlysecure.keychain.service.KeychainIntentService;
-import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
-import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
-import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment;
-import org.sufficientlysecure.keychain.util.Log;
-
import android.app.ProgressDialog;
+import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@@ -36,6 +27,16 @@ import android.os.Messenger;
import android.support.v7.app.ActionBarActivity;
import android.widget.Toast;
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.Id;
+import org.sufficientlysecure.keychain.R;
+import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
+import org.sufficientlysecure.keychain.service.KeychainIntentService;
+import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
+import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
+import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment;
+import org.sufficientlysecure.keychain.util.Log;
+
public class ExportHelper {
protected FileDialogFragment mFileDialog;
protected String mExportFilename;
@@ -115,7 +116,7 @@ public class ExportHelper {
Log.d(Constants.TAG, "exportKeys started");
// Send all information needed to service to export key in other thread
- Intent intent = new Intent(activity, KeychainIntentService.class);
+ final Intent intent = new Intent(activity, KeychainIntentService.class);
intent.setAction(KeychainIntentService.ACTION_EXPORT_KEYRING);
@@ -135,7 +136,12 @@ public class ExportHelper {
// Message is received after exporting is done in ApgService
KeychainIntentServiceHandler exportHandler = new KeychainIntentServiceHandler(activity,
- activity.getString(R.string.progress_exporting), ProgressDialog.STYLE_HORIZONTAL) {
+ activity.getString(R.string.progress_exporting), ProgressDialog.STYLE_HORIZONTAL, true, new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialogInterface) {
+ activity.stopService(intent);
+ }
+ }) {
public void handleMessage(Message message) {
// handle messages by standard ApgHandler first
super.handleMessage(message);
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java
index 138e54f71..3ce9fa7c5 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java
@@ -42,6 +42,7 @@ import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
import org.sufficientlysecure.keychain.util.HkpKeyServer;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.KeyServer.AddKeyException;
+import org.sufficientlysecure.keychain.util.KeychainServiceListener;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
@@ -50,15 +51,25 @@ import android.os.Bundle;
import android.os.Environment;
public class PgpImportExport {
+
private Context mContext;
private ProgressDialogUpdater mProgress;
+ private KeychainServiceListener mKeychainServiceListener;
+
public PgpImportExport(Context context, ProgressDialogUpdater progress) {
super();
this.mContext = context;
this.mProgress = progress;
}
+ public PgpImportExport(Context context, ProgressDialogUpdater progress, KeychainServiceListener keychainListener){
+ super();
+ this.mContext = context;
+ this.mProgress = progress;
+ this.mKeychainServiceListener = keychainListener;
+ }
+
public void updateProgress(int message, int current, int total) {
if (mProgress != null) {
mProgress.setProgress(message, current, total);
@@ -188,8 +199,10 @@ public class PgpImportExport {
if (secretKeyRing != null) {
secretKeyRing.encode(arOutStream);
}
- // Else if it's a public key get the PGPPublicKeyRing
- // and encode that to the output
+ if(mKeychainServiceListener.hasServiceStopped()){
+ arOutStream.close();
+ return null;
+ }
} else {
updateProgress(i * 100 / rowIdsSize, 100);
PGPPublicKeyRing publicKeyRing =
@@ -198,6 +211,11 @@ public class PgpImportExport {
if (publicKeyRing != null) {
publicKeyRing.encode(arOutStream);
}
+
+ if(mKeychainServiceListener.hasServiceStopped()){
+ arOutStream.close();
+ return null;
+ }
}
arOutStream.close();
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
index 93238349d..23f489d35 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
@@ -56,6 +56,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
import org.sufficientlysecure.keychain.util.HkpKeyServer;
import org.sufficientlysecure.keychain.util.InputData;
+import org.sufficientlysecure.keychain.util.KeychainServiceListener;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
@@ -73,7 +74,7 @@ import android.os.RemoteException;
* data from the activities or other apps, queues these intents, executes them, and stops itself
* after doing them.
*/
-public class KeychainIntentService extends IntentService implements ProgressDialogUpdater {
+public class KeychainIntentService extends IntentService implements ProgressDialogUpdater, KeychainServiceListener {
/* extras that can be given by intent */
public static final String EXTRA_MESSENGER = "messenger";
@@ -712,10 +713,15 @@ public class KeychainIntentService extends IntentService implements ProgressDial
Bundle resultData;
- PgpImportExport pgpImportExport = new PgpImportExport(this, this);
+ PgpImportExport pgpImportExport = new PgpImportExport(this, this, this);
+
resultData = pgpImportExport
.exportKeyRings(keyRingRowIds, keyType, outStream);
+ if(mIsCanceled){
+ boolean isDeleted = new File(outputFile).delete();
+ }
+
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData);
} catch (Exception e) {
sendErrorToHandler(e);
@@ -903,4 +909,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial
public void setProgress(int progress, int max) {
setProgress(null, progress, max);
}
+
+ @Override
+ public boolean hasServiceStopped() {
+ return mIsCanceled;
+ }
}
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/KeychainServiceListener.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/KeychainServiceListener.java
new file mode 100644
index 000000000..0d7513057
--- /dev/null
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/KeychainServiceListener.java
@@ -0,0 +1,5 @@
+package org.sufficientlysecure.keychain.util;
+
+public interface KeychainServiceListener {
+ boolean hasServiceStopped();
+}