From 082722a3cfbae408ae3df1f27b191c62a212ff2b Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 26 Oct 2014 22:00:57 +0100 Subject: prevent cancel dring consolidate, move logic into progressable --- .../java/org/sufficientlysecure/keychain/pgp/Progressable.java | 2 ++ .../org/sufficientlysecure/keychain/provider/ProviderHelper.java | 3 +++ .../keychain/service/KeychainIntentService.java | 8 ++++++-- .../java/org/sufficientlysecure/keychain/util/ProgressScaler.java | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java index fd3e2db8f..5de69b887 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/Progressable.java @@ -23,4 +23,6 @@ public interface Progressable { void setProgress(int resourceId, int current, int total); void setProgress(int current, int total); + + void setPreventCancel(); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index 46f294866..ce9a14a6f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -938,6 +938,9 @@ public class ProviderHelper { progress.setProgress(R.string.progress_con_saving, 0, 100); + // The consolidate operation can never be cancelled! + progress.setPreventCancel(); + try { log.add(LogType.MSG_CON_SAVE_SECRET, indent); 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 044656a31..a2988f2b2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -472,8 +472,7 @@ public class KeychainIntentService extends IntentService implements Progressable // Special: consolidate on secret key import (cannot be cancelled!) if (result.mSecret > 0) { - // cannot cancel from here on out! - sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_PREVENT_CANCEL); + // TODO move this into the import operation providerHelper.consolidateDatabaseStep1(this); } @@ -676,6 +675,11 @@ public class KeychainIntentService extends IntentService implements Progressable setProgress(null, progress, max); } + @Override + public void setPreventCancel() { + sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_PREVENT_CANCEL); + } + private InputData createDecryptInputData(Bundle data) throws IOException, PgpGeneralException { return createCryptInputData(data, DECRYPT_CIPHERTEXT_BYTES); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java index 5256f5212..6bec9ccab 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ProgressScaler.java @@ -60,4 +60,10 @@ public class ProgressScaler implements Progressable { } } + @Override + public void setPreventCancel() { + if (mWrapped != null) { + mWrapped.setPreventCancel(); + } + } } -- cgit v1.2.3