From 19252380f198555a6650654ab5e2e35905b40203 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sat, 13 Sep 2014 14:36:23 +0200 Subject: promote all result parcels to top level classes in their own package --- .../keychain/pgp/PgpKeyOperationTest.java | 6 +- .../pgp/UncachedKeyringCanonicalizeTest.java | 5 +- .../keychain/pgp/UncachedKeyringMergeTest.java | 8 +- .../keychain/pgp/UncachedKeyringTest.java | 4 +- .../keychain/provider/ProviderHelperSaveTest.java | 8 +- .../keychain/support/KeyringTestingHelper.java | 4 +- .../keychain/pgp/PgpDecryptVerify.java | 1 - .../keychain/pgp/PgpImportExport.java | 10 +- .../keychain/pgp/PgpKeyOperation.java | 10 +- .../keychain/pgp/UncachedKeyRing.java | 6 +- .../keychain/provider/ProviderHelper.java | 10 +- .../remote/ui/AccountSettingsActivity.java | 3 +- .../remote/ui/AccountSettingsFragment.java | 10 +- .../keychain/remote/ui/AppSettingsActivity.java | 2 +- .../keychain/service/KeychainIntentService.java | 15 +- .../keychain/service/OperationResultParcel.java | 531 -------------------- .../keychain/service/OperationResults.java | 348 -------------- .../service/results/ConsolidateResult.java | 27 ++ .../keychain/service/results/EditKeyResult.java | 63 +++ .../keychain/service/results/ImportKeyResult.java | 192 ++++++++ .../service/results/OperationResultParcel.java | 532 +++++++++++++++++++++ .../service/results/SaveKeyringResult.java | 68 +++ .../keychain/service/results/SingletonResult.java | 83 ++++ .../keychain/ui/CertifyKeyFragment.java | 2 +- .../keychain/ui/CreateKeyFinalFragment.java | 8 +- .../keychain/ui/EditKeyFragment.java | 8 +- .../keychain/ui/ImportKeysActivity.java | 4 +- .../keychain/ui/KeyListActivity.java | 4 +- .../keychain/ui/LogDisplayFragment.java | 6 +- .../keychain/ui/ViewKeyActivity.java | 2 +- 30 files changed, 1024 insertions(+), 956 deletions(-) delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ConsolidateResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/EditKeyResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResultParcel.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SaveKeyringResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SingletonResult.java diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java index 1992c40ca..6cd30a205 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperationTest.java @@ -38,9 +38,9 @@ import org.spongycastle.bcpg.UserIDPacket; import org.spongycastle.bcpg.sig.KeyFlags; import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.openpgp.PGPSignature; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType; -import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; -import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.OperationLog; +import org.sufficientlysecure.keychain.service.results.EditKeyResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyAdd; diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringCanonicalizeTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringCanonicalizeTest.java index 5792e8326..2457eeb51 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringCanonicalizeTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringCanonicalizeTest.java @@ -30,7 +30,6 @@ import org.spongycastle.bcpg.Packet; import org.spongycastle.bcpg.PacketTags; import org.spongycastle.bcpg.UserIDPacket; import org.spongycastle.bcpg.sig.KeyFlags; -import org.spongycastle.bcpg.PublicKeyAlgorithmTags; import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.openpgp.PGPPrivateKey; import org.spongycastle.openpgp.PGPPublicKey; @@ -46,8 +45,8 @@ import org.spongycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator; import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.service.OperationResultParcel; -import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.EditKeyResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.support.KeyringTestingHelper; diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java index 2e8b53c89..3ffdb8262 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringMergeTest.java @@ -26,17 +26,13 @@ import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.shadows.ShadowLog; import org.spongycastle.bcpg.BCPGInputStream; -import org.spongycastle.bcpg.Packet; import org.spongycastle.bcpg.PacketTags; import org.spongycastle.bcpg.S2K; import org.spongycastle.bcpg.SecretKeyPacket; -import org.spongycastle.bcpg.SecretSubkeyPacket; import org.spongycastle.bcpg.sig.KeyFlags; -import org.spongycastle.bcpg.PublicKeyAlgorithmTags; import org.spongycastle.jce.provider.BouncyCastleProvider; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.service.OperationResultParcel; -import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.EditKeyResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.support.KeyringTestingHelper; diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringTest.java index 636dae90c..8ff5542c1 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/pgp/UncachedKeyringTest.java @@ -26,10 +26,8 @@ import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.shadows.ShadowLog; import org.spongycastle.bcpg.sig.KeyFlags; -import org.spongycastle.bcpg.PublicKeyAlgorithmTags; -import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; +import org.sufficientlysecure.keychain.service.results.EditKeyResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.support.KeyringTestingHelper.RawPacket; diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java index 905984a53..44f3f9145 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java @@ -30,15 +30,9 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult; -import org.sufficientlysecure.keychain.support.KeyringTestingHelper; +import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.ProgressScaler; -import java.io.IOException; -import java.util.Iterator; - @RunWith(RobolectricTestRunner.class) @org.robolectric.annotation.Config(emulateSdk = 18) // Robolectric doesn't yet support 19 public class ProviderHelperSaveTest { diff --git a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java index 6d53f3fcf..5fd64ae95 100644 --- a/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java +++ b/OpenKeychain-Test/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java @@ -24,7 +24,7 @@ import org.spongycastle.util.Arrays; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.service.OperationResults; +import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.ProgressScaler; import java.io.ByteArrayInputStream; @@ -59,7 +59,7 @@ public class KeyringTestingHelper { // Should throw an exception; key is not yet saved retrieveKeyAndExpectNotFound(providerHelper, masterKeyId); - OperationResults.SaveKeyringResult saveKeyringResult = providerHelper.savePublicKeyRing(ring, new ProgressScaler()); + SaveKeyringResult saveKeyringResult = providerHelper.savePublicKeyRing(ring, new ProgressScaler()); boolean saveSuccess = saveKeyringResult.success(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java index aa85b1082..b2b633ed7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java @@ -60,7 +60,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URLConnection; import java.security.SignatureException; -import java.util.Date; import java.util.Iterator; import java.util.Set; 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 511086489..06415cf8a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -33,11 +33,11 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType; -import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; -import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult; -import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.OperationLog; +import org.sufficientlysecure.keychain.service.results.ImportKeyResult; +import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ProgressScaler; 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 9bfea2414..ad592a3e9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -46,11 +46,11 @@ import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.service.OperationResultParcel; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType; -import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; -import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.OperationLog; +import org.sufficientlysecure.keychain.service.results.EditKeyResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Curve; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java index e26fa4446..4239a01dc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java @@ -35,9 +35,9 @@ import org.spongycastle.openpgp.PGPUtil; import org.spongycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType; -import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.OperationLog; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; 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 af7bdb139..f71fcbd80 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -54,11 +54,11 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.remote.AccountSettings; import org.sufficientlysecure.keychain.remote.AppSettings; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType; -import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; -import org.sufficientlysecure.keychain.service.OperationResults.ConsolidateResult; -import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.OperationLog; +import org.sufficientlysecure.keychain.service.results.ConsolidateResult; +import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.ParcelableFileCache; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsActivity.java index 46a557da3..4bf750121 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsActivity.java @@ -30,8 +30,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.ActionBarHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.remote.AccountSettings; -import org.sufficientlysecure.keychain.service.OperationResultParcel; -import org.sufficientlysecure.keychain.ui.CertifyKeyActivity; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; import org.sufficientlysecure.keychain.util.Log; public class AccountSettingsActivity extends ActionBarActivity { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java index 04c202019..d21d83574 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java @@ -26,19 +26,15 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; -import android.widget.Button; import android.widget.Spinner; import android.widget.TextView; -import android.widget.Toast; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; -import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.remote.AccountSettings; -import org.sufficientlysecure.keychain.service.OperationResultParcel; -import org.sufficientlysecure.keychain.service.OperationResults; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; import org.sufficientlysecure.keychain.ui.CreateKeyActivity; import org.sufficientlysecure.keychain.ui.adapter.KeyValueSpinnerAdapter; import org.sufficientlysecure.keychain.ui.widget.KeySpinner; @@ -176,7 +172,7 @@ public class AccountSettingsFragment extends Fragment { case REQUEST_CODE_CREATE_KEY: { if (resultCode == Activity.RESULT_OK) { if (data != null && data.hasExtra(OperationResultParcel.EXTRA_RESULT)) { - OperationResults.SaveKeyringResult result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT); + SaveKeyringResult result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT); mSelectKeySpinner.setSelectedKeyId(result.mRingMasterKeyId); } else { Log.e(Constants.TAG, "missing result!"); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AppSettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AppSettingsActivity.java index 885d06857..8cc05231e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AppSettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AppSettingsActivity.java @@ -32,7 +32,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.remote.AppSettings; -import org.sufficientlysecure.keychain.service.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; import org.sufficientlysecure.keychain.util.Log; public class AppSettingsActivity extends ActionBarActivity { 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 e664570ac..92917fa51 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -55,13 +55,14 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType; -import org.sufficientlysecure.keychain.service.OperationResultParcel.OperationLog; -import org.sufficientlysecure.keychain.service.OperationResults.ConsolidateResult; -import org.sufficientlysecure.keychain.service.OperationResults.EditKeyResult; -import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult; -import org.sufficientlysecure.keychain.service.OperationResults.SaveKeyringResult; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.OperationLog; +import org.sufficientlysecure.keychain.service.results.ConsolidateResult; +import org.sufficientlysecure.keychain.service.results.EditKeyResult; +import org.sufficientlysecure.keychain.service.results.ImportKeyResult; +import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.ParcelableFileCache; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java deleted file mode 100644 index 02caca145..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java +++ /dev/null @@ -1,531 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * Copyright (C) 2014 Vincent Breitmoser - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.service; - -import android.app.Activity; -import android.content.Intent; -import android.os.Parcel; -import android.os.Parcelable; -import android.view.View; - -import com.github.johnpersano.supertoasts.SuperCardToast; -import com.github.johnpersano.supertoasts.SuperToast; -import com.github.johnpersano.supertoasts.util.OnClickWrapper; -import com.github.johnpersano.supertoasts.util.Style; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.ui.LogDisplayActivity; -import org.sufficientlysecure.keychain.ui.LogDisplayFragment; -import org.sufficientlysecure.keychain.util.IterableIterator; -import org.sufficientlysecure.keychain.util.Log; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -/** Represent the result of an operation. - * - * This class holds a result and the log of an operation. It can be subclassed - * to include typed additional information specific to the operation. To keep - * the class structure (somewhat) simple, this class contains an exhaustive - * list (ie, enum) of all possible log types, which should in all cases be tied - * to string resource ids. - * - * - */ -public class OperationResultParcel implements Parcelable { - - public static final String EXTRA_RESULT = "operation_result"; - - /** Holds the overall result, the number specifying varying degrees of success: - * - The first bit is 0 on overall success, 1 on overall failure - * - The second bit indicates if the action was cancelled - may still be an error or success! - * - The third bit should be set if the operation succeeded with warnings - * All other bits may be used for more specific conditions. */ - final int mResult; - - public static final int RESULT_OK = 0; - public static final int RESULT_ERROR = 1; - public static final int RESULT_CANCELLED = 2; - public static final int RESULT_WARNINGS = 4; - - /// A list of log entries tied to the operation result. - final OperationLog mLog; - - public OperationResultParcel(int result, OperationLog log) { - mResult = result; - mLog = log; - } - - public OperationResultParcel(Parcel source) { - mResult = source.readInt(); - mLog = new OperationLog(); - mLog.addAll(source.createTypedArrayList(LogEntryParcel.CREATOR)); - } - - public int getResult() { - return mResult; - } - - public boolean success() { - return (mResult & RESULT_ERROR) == 0; - } - - public boolean cancelled() { - return (mResult & RESULT_CANCELLED) == RESULT_CANCELLED; - } - - public OperationLog getLog() { - return mLog; - } - - /** One entry in the log. */ - public static class LogEntryParcel implements Parcelable { - public final LogLevel mLevel; - public final LogType mType; - public final Object[] mParameters; - public final int mIndent; - - public LogEntryParcel(LogLevel level, LogType type, int indent, Object... parameters) { - mLevel = level; - mType = type; - mParameters = parameters; - mIndent = indent; - Log.v(Constants.TAG, "log: " + this.toString()); - } - - public LogEntryParcel(Parcel source) { - mLevel = LogLevel.values()[source.readInt()]; - mType = LogType.values()[source.readInt()]; - mParameters = (Object[]) source.readSerializable(); - mIndent = source.readInt(); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(mLevel.ordinal()); - dest.writeInt(mType.ordinal()); - dest.writeSerializable(mParameters); - dest.writeInt(mIndent); - } - - public static final Creator CREATOR = new Creator() { - public LogEntryParcel createFromParcel(final Parcel source) { - return new LogEntryParcel(source); - } - - public LogEntryParcel[] newArray(final int size) { - return new LogEntryParcel[size]; - } - }; - - @Override - public String toString() { - return "LogEntryParcel{" + - "mLevel=" + mLevel + - ", mType=" + mType + - ", mParameters=" + Arrays.toString(mParameters) + - ", mIndent=" + mIndent + - '}'; - } - } - - public SuperCardToast createNotify(final Activity activity) { - - String str; - int color; - - // Not an overall failure - if (cancelled()) { - color = Style.RED; - str = "operation cancelled!"; - } else if (success()) { - if (getLog().containsWarnings()) { - color = Style.ORANGE; - } else { - color = Style.GREEN; - } - str = "operation succeeded!"; - // str = activity.getString(R.string.import_error); - } else { - color = Style.RED; - str = "operation failed"; - // str = activity.getString(R.string.import_error); - } - - boolean button = getLog() != null && !getLog().isEmpty(); - SuperCardToast toast = new SuperCardToast(activity, - button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, - Style.getStyle(color, SuperToast.Animations.POPUP)); - toast.setText(str); - toast.setDuration(SuperToast.Duration.EXTRA_LONG); - toast.setIndeterminate(false); - toast.setSwipeToDismiss(true); - // If we have a log and it's non-empty, show a View Log button - if (button) { - toast.setButtonIcon(R.drawable.ic_action_view_as_list, - activity.getResources().getString(R.string.view_log)); - toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); - toast.setTextColor(activity.getResources().getColor(R.color.black)); - toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", - new SuperToast.OnClickListener() { - @Override - public void onClick(View view, Parcelable token) { - Intent intent = new Intent( - activity, LogDisplayActivity.class); - intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResultParcel.this); - activity.startActivity(intent); - } - } - )); - } - - return toast; - - } - - /** This is an enum of all possible log events. - * - * Element names should generally be prefixed with MSG_XX_ where XX is an - * identifier based on the related activity. - * - * Log messages should occur for each distinguishable action group. For - * each such group, one message is displayed followed by warnings or - * errors, and optionally subactions. The granularity should generally be - * optimistic: No "success" messages are printed except for the outermost - * operations - the success of an action group is indicated by the - * beginning message of the next action group. - * - * Log messages should be in present tense, There should be no trailing - * punctuation, except for error messages which may end in an exclamation - * mark. - * - */ - public static enum LogType { - - MSG_INTERNAL_ERROR (R.string.msg_internal_error), - MSG_OPERATION_CANCELLED (R.string.msg_cancelled), - - // import public - MSG_IP(R.string.msg_ip), - MSG_IP_APPLY_BATCH (R.string.msg_ip_apply_batch), - MSG_IP_BAD_TYPE_SECRET (R.string.msg_ip_bad_type_secret), - MSG_IP_DELETE_OLD_FAIL (R.string.msg_ip_delete_old_fail), - MSG_IP_DELETE_OLD_OK (R.string.msg_ip_delete_old_ok), - MSG_IP_ENCODE_FAIL (R.string.msg_ip_encode_fail), - MSG_IP_FAIL_IO_EXC (R.string.msg_ip_fail_io_exc), - MSG_IP_FAIL_OP_EXC (R.string.msg_ip_fail_op_exc), - MSG_IP_FAIL_REMOTE_EX (R.string.msg_ip_fail_remote_ex), - MSG_IP_INSERT_KEYRING (R.string.msg_ip_insert_keyring), - MSG_IP_INSERT_SUBKEYS (R.string.msg_ip_insert_keys), - MSG_IP_PREPARE (R.string.msg_ip_prepare), - MSG_IP_REINSERT_SECRET (R.string.msg_ip_reinsert_secret), - MSG_IP_MASTER (R.string.msg_ip_master), - MSG_IP_MASTER_EXPIRED (R.string.msg_ip_master_expired), - MSG_IP_MASTER_EXPIRES (R.string.msg_ip_master_expires), - MSG_IP_MASTER_FLAGS_CES (R.string.msg_ip_master_flags_ces), - MSG_IP_MASTER_FLAGS_CEX (R.string.msg_ip_master_flags_cex), - MSG_IP_MASTER_FLAGS_CXS (R.string.msg_ip_master_flags_cxs), - MSG_IP_MASTER_FLAGS_XES (R.string.msg_ip_master_flags_xes), - MSG_IP_MASTER_FLAGS_CXX (R.string.msg_ip_master_flags_cxx), - MSG_IP_MASTER_FLAGS_XEX (R.string.msg_ip_master_flags_xex), - MSG_IP_MASTER_FLAGS_XXS (R.string.msg_ip_master_flags_xxs), - MSG_IP_MASTER_FLAGS_XXX (R.string.msg_ip_master_flags_xxx), - MSG_IP_SUBKEY (R.string.msg_ip_subkey), - MSG_IP_SUBKEY_EXPIRED (R.string.msg_ip_subkey_expired), - MSG_IP_SUBKEY_EXPIRES (R.string.msg_ip_subkey_expires), - MSG_IP_SUBKEY_FLAGS_CES (R.string.msg_ip_subkey_flags_ces), - MSG_IP_SUBKEY_FLAGS_CEX (R.string.msg_ip_subkey_flags_cex), - MSG_IP_SUBKEY_FLAGS_CXS (R.string.msg_ip_subkey_flags_cxs), - MSG_IP_SUBKEY_FLAGS_XES (R.string.msg_ip_subkey_flags_xes), - MSG_IP_SUBKEY_FLAGS_CXX (R.string.msg_ip_subkey_flags_cxx), - MSG_IP_SUBKEY_FLAGS_XEX (R.string.msg_ip_subkey_flags_xex), - MSG_IP_SUBKEY_FLAGS_XXS (R.string.msg_ip_subkey_flags_xxs), - MSG_IP_SUBKEY_FLAGS_XXX (R.string.msg_ip_subkey_flags_xxx), - MSG_IP_SUCCESS (R.string.msg_ip_success), - MSG_IP_SUCCESS_IDENTICAL (R.string.msg_ip_success_identical), - MSG_IP_UID_CERT_BAD (R.string.msg_ip_uid_cert_bad), - MSG_IP_UID_CERT_ERROR (R.string.msg_ip_uid_cert_error), - MSG_IP_UID_CERT_GOOD (R.string.msg_ip_uid_cert_good), - MSG_IP_UID_CERTS_UNKNOWN (R.plurals.msg_ip_uid_certs_unknown), - MSG_IP_UID_CLASSIFYING_ZERO (R.string.msg_ip_uid_classifying_zero), - MSG_IP_UID_CLASSIFYING (R.plurals.msg_ip_uid_classifying), - MSG_IP_UID_REORDER(R.string.msg_ip_uid_reorder), - MSG_IP_UID_PROCESSING (R.string.msg_ip_uid_processing), - MSG_IP_UID_REVOKED (R.string.msg_ip_uid_revoked), - - // import secret - MSG_IS(R.string.msg_is), - MSG_IS_BAD_TYPE_PUBLIC (R.string.msg_is_bad_type_public), - MSG_IS_DB_EXCEPTION (R.string.msg_is_db_exception), - MSG_IS_FAIL_IO_EXC (R.string.msg_is_io_exc), - MSG_IS_IMPORTING_SUBKEYS (R.string.msg_is_importing_subkeys), - MSG_IS_PUBRING_GENERATE (R.string.msg_is_pubring_generate), - MSG_IS_SUBKEY_NONEXISTENT (R.string.msg_is_subkey_nonexistent), - MSG_IS_SUBKEY_OK (R.string.msg_is_subkey_ok), - MSG_IS_SUBKEY_STRIPPED (R.string.msg_is_subkey_stripped), - MSG_IS_SUBKEY_DIVERT (R.string.msg_is_subkey_divert), - MSG_IS_SUBKEY_EMPTY (R.string.msg_is_subkey_empty), - MSG_IS_SUCCESS_IDENTICAL (R.string.msg_is_success_identical), - MSG_IS_SUCCESS (R.string.msg_is_success), - - // keyring canonicalization - MSG_KC_PUBLIC (R.string.msg_kc_public), - MSG_KC_SECRET (R.string.msg_kc_secret), - MSG_KC_ERROR_V3 (R.string.msg_kc_error_v3), - MSG_KC_ERROR_NO_UID (R.string.msg_kc_error_no_uid), - MSG_KC_ERROR_MASTER_ALGO (R.string.msg_kc_error_master_algo), - MSG_KC_MASTER (R.string.msg_kc_master), - MSG_KC_REVOKE_BAD_ERR (R.string.msg_kc_revoke_bad_err), - MSG_KC_REVOKE_BAD_LOCAL (R.string.msg_kc_revoke_bad_local), - MSG_KC_REVOKE_BAD_TIME (R.string.msg_kc_revoke_bad_time), - MSG_KC_REVOKE_BAD_TYPE (R.string.msg_kc_revoke_bad_type), - MSG_KC_REVOKE_BAD_TYPE_UID (R.string.msg_kc_revoke_bad_type_uid), - MSG_KC_REVOKE_BAD (R.string.msg_kc_revoke_bad), - MSG_KC_REVOKE_DUP (R.string.msg_kc_revoke_dup), - MSG_KC_SUB (R.string.msg_kc_sub), - MSG_KC_SUB_BAD(R.string.msg_kc_sub_bad), - MSG_KC_SUB_BAD_ERR(R.string.msg_kc_sub_bad_err), - MSG_KC_SUB_BAD_LOCAL(R.string.msg_kc_sub_bad_local), - MSG_KC_SUB_BAD_KEYID(R.string.msg_kc_sub_bad_keyid), - MSG_KC_SUB_BAD_TIME(R.string.msg_kc_sub_bad_time), - MSG_KC_SUB_BAD_TYPE(R.string.msg_kc_sub_bad_type), - MSG_KC_SUB_DUP (R.string.msg_kc_sub_dup), - MSG_KC_SUB_PRIMARY_BAD(R.string.msg_kc_sub_primary_bad), - MSG_KC_SUB_PRIMARY_BAD_ERR(R.string.msg_kc_sub_primary_bad_err), - MSG_KC_SUB_PRIMARY_NONE(R.string.msg_kc_sub_primary_none), - MSG_KC_SUB_NO_CERT(R.string.msg_kc_sub_no_cert), - MSG_KC_SUB_REVOKE_BAD_ERR (R.string.msg_kc_sub_revoke_bad_err), - MSG_KC_SUB_REVOKE_BAD (R.string.msg_kc_sub_revoke_bad), - MSG_KC_SUB_REVOKE_DUP (R.string.msg_kc_sub_revoke_dup), - MSG_KC_SUB_UNKNOWN_ALGO (R.string.msg_kc_sub_unknown_algo), - MSG_KC_SUCCESS_BAD (R.plurals.msg_kc_success_bad), - MSG_KC_SUCCESS_BAD_AND_RED (R.string.msg_kc_success_bad_and_red), - MSG_KC_SUCCESS_REDUNDANT (R.plurals.msg_kc_success_redundant), - MSG_KC_SUCCESS (R.string.msg_kc_success), - MSG_KC_UID_BAD_ERR (R.string.msg_kc_uid_bad_err), - MSG_KC_UID_BAD_LOCAL (R.string.msg_kc_uid_bad_local), - MSG_KC_UID_BAD_TIME (R.string.msg_kc_uid_bad_time), - MSG_KC_UID_BAD_TYPE (R.string.msg_kc_uid_bad_type), - MSG_KC_UID_BAD (R.string.msg_kc_uid_bad), - MSG_KC_UID_CERT_DUP (R.string.msg_kc_uid_cert_dup), - MSG_KC_UID_DUP (R.string.msg_kc_uid_dup), - MSG_KC_UID_FOREIGN (R.string.msg_kc_uid_foreign), - MSG_KC_UID_NO_CERT (R.string.msg_kc_uid_no_cert), - MSG_KC_UID_REVOKE_DUP (R.string.msg_kc_uid_revoke_dup), - MSG_KC_UID_REVOKE_OLD (R.string.msg_kc_uid_revoke_old), - MSG_KC_UID_REMOVE (R.string.msg_kc_uid_remove), - - - // keyring consolidation - MSG_MG_ERROR_SECRET_DUMMY(R.string.msg_mg_error_secret_dummy), - MSG_MG_ERROR_ENCODE(R.string.msg_mg_error_encode), - MSG_MG_ERROR_HETEROGENEOUS(R.string.msg_mg_error_heterogeneous), - MSG_MG_PUBLIC (R.string.msg_mg_public), - MSG_MG_SECRET (R.string.msg_mg_secret), - MSG_MG_NEW_SUBKEY (R.string.msg_mg_new_subkey), - MSG_MG_FOUND_NEW (R.string.msg_mg_found_new), - MSG_MG_UNCHANGED (R.string.msg_mg_unchanged), - - // secret key create - MSG_CR (R.string.msg_cr), - MSG_CR_ERROR_NO_MASTER (R.string.msg_cr_error_no_master), - MSG_CR_ERROR_NO_USER_ID (R.string.msg_cr_error_no_user_id), - MSG_CR_ERROR_NO_CERTIFY (R.string.msg_cr_error_no_certify), - MSG_CR_ERROR_NULL_EXPIRY(R.string.msg_cr_error_null_expiry), - MSG_CR_ERROR_KEYSIZE_512 (R.string.msg_cr_error_keysize_512), - MSG_CR_ERROR_NO_KEYSIZE (R.string.msg_cr_error_no_keysize), - MSG_CR_ERROR_NO_CURVE (R.string.msg_cr_error_no_curve), - MSG_CR_ERROR_UNKNOWN_ALGO (R.string.msg_cr_error_unknown_algo), - MSG_CR_ERROR_INTERNAL_PGP (R.string.msg_cr_error_internal_pgp), - MSG_CR_ERROR_FLAGS_DSA (R.string.msg_cr_error_flags_dsa), - MSG_CR_ERROR_FLAGS_ELGAMAL (R.string.msg_cr_error_flags_elgamal), - MSG_CR_ERROR_FLAGS_ECDSA (R.string.msg_cr_error_flags_ecdsa), - MSG_CR_ERROR_FLAGS_ECDH (R.string.msg_cr_error_flags_ecdh), - - // secret key modify - MSG_MF (R.string.msg_mr), - MSG_MF_ERROR_ENCODE (R.string.msg_mf_error_encode), - MSG_MF_ERROR_FINGERPRINT (R.string.msg_mf_error_fingerprint), - MSG_MF_ERROR_KEYID (R.string.msg_mf_error_keyid), - MSG_MF_ERROR_INTEGRITY (R.string.msg_mf_error_integrity), - MSG_MF_ERROR_MASTER_NONE(R.string.msg_mf_error_master_none), - MSG_MF_ERROR_NO_CERTIFY (R.string.msg_cr_error_no_certify), - MSG_MF_ERROR_NOEXIST_PRIMARY (R.string.msg_mf_error_noexist_primary), - MSG_MF_ERROR_NOEXIST_REVOKE (R.string.msg_mf_error_noexist_revoke), - MSG_MF_ERROR_NULL_EXPIRY (R.string.msg_mf_error_null_expiry), - MSG_MF_ERROR_PASSPHRASE_MASTER(R.string.msg_mf_error_passphrase_master), - MSG_MF_ERROR_PAST_EXPIRY(R.string.msg_mf_error_past_expiry), - MSG_MF_ERROR_PGP (R.string.msg_mf_error_pgp), - MSG_MF_ERROR_REVOKED_PRIMARY (R.string.msg_mf_error_revoked_primary), - MSG_MF_ERROR_SIG (R.string.msg_mf_error_sig), - MSG_MF_ERROR_SUBKEY_MISSING(R.string.msg_mf_error_subkey_missing), - MSG_MF_MASTER (R.string.msg_mf_master), - MSG_MF_PASSPHRASE (R.string.msg_mf_passphrase), - MSG_MF_PASSPHRASE_KEY (R.string.msg_mf_passphrase_key), - MSG_MF_PASSPHRASE_EMPTY_RETRY (R.string.msg_mf_passphrase_empty_retry), - MSG_MF_PASSPHRASE_FAIL (R.string.msg_mf_passphrase_fail), - MSG_MF_PRIMARY_REPLACE_OLD (R.string.msg_mf_primary_replace_old), - MSG_MF_PRIMARY_NEW (R.string.msg_mf_primary_new), - MSG_MF_SUBKEY_CHANGE (R.string.msg_mf_subkey_change), - MSG_MF_SUBKEY_NEW_ID (R.string.msg_mf_subkey_new_id), - MSG_MF_SUBKEY_NEW (R.string.msg_mf_subkey_new), - MSG_MF_SUBKEY_REVOKE (R.string.msg_mf_subkey_revoke), - MSG_MF_SUBKEY_STRIP (R.string.msg_mf_subkey_strip), - MSG_MF_SUCCESS (R.string.msg_mf_success), - MSG_MF_UID_ADD (R.string.msg_mf_uid_add), - MSG_MF_UID_PRIMARY (R.string.msg_mf_uid_primary), - MSG_MF_UID_REVOKE (R.string.msg_mf_uid_revoke), - MSG_MF_UID_ERROR_EMPTY (R.string.msg_mf_uid_error_empty), - MSG_MF_UNLOCK_ERROR (R.string.msg_mf_unlock_error), - MSG_MF_UNLOCK (R.string.msg_mf_unlock), - - // consolidate - MSG_CON_CRITICAL_IN (R.string.msg_con_critical_in), - MSG_CON_CRITICAL_OUT (R.string.msg_con_critical_out), - MSG_CON_DB_CLEAR (R.string.msg_con_db_clear), - MSG_CON_DELETE_PUBLIC (R.string.msg_con_delete_public), - MSG_CON_DELETE_SECRET (R.string.msg_con_delete_secret), - MSG_CON_ERROR_BAD_STATE (R.string.msg_con_error_bad_state), - MSG_CON_ERROR_CONCURRENT(R.string.msg_con_error_concurrent), - MSG_CON_ERROR_DB (R.string.msg_con_error_db), - MSG_CON_ERROR_IO_PUBLIC (R.string.msg_con_error_io_public), - MSG_CON_ERROR_IO_SECRET (R.string.msg_con_error_io_secret), - MSG_CON_ERROR_PUBLIC (R.string.msg_con_error_public), - MSG_CON_ERROR_SECRET (R.string.msg_con_error_secret), - MSG_CON_RECOVER (R.plurals.msg_con_recover), - MSG_CON_RECOVER_UNKNOWN (R.string.msg_con_recover_unknown), - MSG_CON_REIMPORT_PUBLIC (R.plurals.msg_con_reimport_public), - MSG_CON_REIMPORT_PUBLIC_SKIP (R.string.msg_con_reimport_public_skip), - MSG_CON_REIMPORT_SECRET (R.plurals.msg_con_reimport_secret), - MSG_CON_REIMPORT_SECRET_SKIP (R.string.msg_con_reimport_secret_skip), - MSG_CON (R.string.msg_con), - MSG_CON_SAVE_PUBLIC (R.string.msg_con_save_public), - MSG_CON_SAVE_SECRET (R.string.msg_con_save_secret), - MSG_CON_SUCCESS (R.string.msg_con_success), - MSG_CON_WARN_DELETE_PUBLIC (R.string.msg_con_warn_delete_public), - MSG_CON_WARN_DELETE_SECRET (R.string.msg_con_warn_delete_secret), - - // messages used in UI code - MSG_EK_ERROR_DIVERT (R.string.msg_ek_error_divert), - MSG_EK_ERROR_DUMMY (R.string.msg_ek_error_dummy), - MSG_EK_ERROR_NOT_FOUND (R.string.msg_ek_error_not_found), - - ; - - private final int mMsgId; - LogType(int msgId) { - mMsgId = msgId; - } - public int getMsgId() { - return mMsgId; - } - } - - /** Enumeration of possible log levels. */ - public static enum LogLevel { - DEBUG, - INFO, - WARN, - ERROR, // should occur once at the end of a failed operation - START, // should occur once at the start of each independent operation - OK, // should occur once at the end of a successful operation - CANCELLED, // should occur once at the end of a cancelled operation - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(mResult); - if (mLog != null) { - dest.writeTypedList(mLog.toList()); - } - } - - public static final Creator CREATOR = new Creator() { - public OperationResultParcel createFromParcel(final Parcel source) { - return new OperationResultParcel(source); - } - - public OperationResultParcel[] newArray(final int size) { - return new OperationResultParcel[size]; - } - }; - - public static class OperationLog implements Iterable { - - private final List mParcels = new ArrayList(); - - /// Simple convenience method - public void add(LogLevel level, LogType type, int indent, Object... parameters) { - mParcels.add(new OperationResultParcel.LogEntryParcel(level, type, indent, parameters)); - } - - public void add(LogLevel level, LogType type, int indent) { - mParcels.add(new OperationResultParcel.LogEntryParcel(level, type, indent, (Object[]) null)); - } - - public boolean containsType(LogType type) { - for(LogEntryParcel entry : new IterableIterator(mParcels.iterator())) { - if (entry.mType == type) { - return true; - } - } - return false; - } - - public boolean containsWarnings() { - for(LogEntryParcel entry : new IterableIterator(mParcels.iterator())) { - if (entry.mLevel == LogLevel.WARN || entry.mLevel == LogLevel.ERROR) { - return true; - } - } - return false; - } - - public void addAll(List parcels) { - mParcels.addAll(parcels); - } - - public List toList() { - return mParcels; - } - - public boolean isEmpty() { - return mParcels.isEmpty(); - } - - @Override - public Iterator iterator() { - return mParcels.iterator(); - } - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java deleted file mode 100644 index ad8fb2f7a..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * Copyright (C) 2014 Vincent Breitmoser - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.service; - -import android.app.Activity; -import android.content.Intent; -import android.os.Parcel; -import android.os.Parcelable; -import android.view.View; - -import com.github.johnpersano.supertoasts.SuperCardToast; -import com.github.johnpersano.supertoasts.SuperToast; -import com.github.johnpersano.supertoasts.SuperToast.Duration; -import com.github.johnpersano.supertoasts.util.OnClickWrapper; -import com.github.johnpersano.supertoasts.util.Style; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; -import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.ui.LogDisplayActivity; -import org.sufficientlysecure.keychain.ui.LogDisplayFragment; - -public abstract class OperationResults { - - /** This is a simple subclass meant to contain only a single log message. This log - * message is also shown without a log button in the createNotify SuperToast. */ - public static class SingletonResult extends OperationResultParcel { - - /** Construct from a parcel - trivial because we have no extra data. */ - public SingletonResult(Parcel source) { - super(source); - } - - public SingletonResult(int result, LogLevel level, LogType reason) { - super(result, new OperationLog()); - // Prepare the log - mLog.add(level, reason, 0); - } - - @Override - public SuperCardToast createNotify(final Activity activity) { - - // there is exactly one error msg - use that one - String str = activity.getString(mLog.iterator().next().mType.getMsgId()); - int color; - - // Determine color by result type - if (cancelled()) { - color = Style.RED; - } else if (success()) { - if (getLog().containsWarnings()) { - color = Style.ORANGE; - } else { - color = Style.GREEN; - } - } else { - color = Style.RED; - } - - SuperCardToast toast = new SuperCardToast(activity, SuperToast.Type.STANDARD, - Style.getStyle(color, SuperToast.Animations.POPUP)); - toast.setText(str); - toast.setDuration(SuperToast.Duration.EXTRA_LONG); - toast.setIndeterminate(false); - toast.setSwipeToDismiss(true); - return toast; - - } - - public static Creator CREATOR = new Creator() { - public SingletonResult createFromParcel(final Parcel source) { - return new SingletonResult(source); - } - - public SingletonResult[] newArray(final int size) { - return new SingletonResult[size]; - } - }; - - } - - public static class ImportKeyResult extends OperationResultParcel { - - public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret; - - // At least one new key - public static final int RESULT_OK_NEWKEYS = 8; - // At least one updated key - public static final int RESULT_OK_UPDATED = 16; - // At least one key failed (might still be an overall success) - public static final int RESULT_WITH_ERRORS = 32; - - // No keys to import... - public static final int RESULT_FAIL_NOTHING = 64 + 1; - - public boolean isOkBoth() { - return (mResult & (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED)) - == (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED); - } - - public boolean isOkNew() { - return (mResult & RESULT_OK_NEWKEYS) == RESULT_OK_NEWKEYS; - } - - public boolean isOkUpdated() { - return (mResult & RESULT_OK_UPDATED) == RESULT_OK_UPDATED; - } - - public boolean isFailNothing() { - return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING; - } - - public ImportKeyResult(Parcel source) { - super(source); - mNewKeys = source.readInt(); - mUpdatedKeys = source.readInt(); - mBadKeys = source.readInt(); - mSecret = source.readInt(); - } - - public ImportKeyResult(int result, OperationLog log, - int newKeys, int updatedKeys, int badKeys, int secret) { - super(result, log); - mNewKeys = newKeys; - mUpdatedKeys = updatedKeys; - mBadKeys = badKeys; - mSecret = secret; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeInt(mNewKeys); - dest.writeInt(mUpdatedKeys); - dest.writeInt(mBadKeys); - dest.writeInt(mSecret); - } - - public static Creator CREATOR = new Creator() { - public ImportKeyResult createFromParcel(final Parcel source) { - return new ImportKeyResult(source); - } - - public ImportKeyResult[] newArray(final int size) { - return new ImportKeyResult[size]; - } - }; - - public SuperCardToast createNotify(final Activity activity) { - - int resultType = getResult(); - - String str; - int duration, color; - - // Not an overall failure - if ((resultType & OperationResultParcel.RESULT_ERROR) == 0) { - String withWarnings; - - duration = Duration.EXTRA_LONG; - color = Style.GREEN; - withWarnings = ""; - - // Any warnings? - if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { - duration = 0; - color = Style.ORANGE; - withWarnings += activity.getString(R.string.import_with_warnings); - } - if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { - duration = 0; - color = Style.ORANGE; - withWarnings += activity.getString(R.string.import_with_cancelled); - } - - // New and updated keys - if (this.isOkBoth()) { - str = activity.getResources().getQuantityString( - R.plurals.import_keys_added_and_updated_1, mNewKeys, mNewKeys); - str += " " + activity.getResources().getQuantityString( - R.plurals.import_keys_added_and_updated_2, mUpdatedKeys, mUpdatedKeys, withWarnings); - } else if (isOkUpdated()) { - str = activity.getResources().getQuantityString( - R.plurals.import_keys_updated, mUpdatedKeys, mUpdatedKeys, withWarnings); - } else if (isOkNew()) { - str = activity.getResources().getQuantityString( - R.plurals.import_keys_added, mNewKeys, mNewKeys, withWarnings); - } else { - duration = 0; - color = Style.RED; - str = "internal error"; - } - - } else { - duration = 0; - color = Style.RED; - if (isFailNothing()) { - str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0 - ? R.string.import_error_nothing_cancelled - : R.string.import_error_nothing); - } else { - str = activity.getString(R.string.import_error); - } - } - - boolean button = getLog() != null && !getLog().isEmpty(); - SuperCardToast toast = new SuperCardToast(activity, - button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, - Style.getStyle(color, SuperToast.Animations.POPUP)); - toast.setText(str); - toast.setDuration(duration); - toast.setIndeterminate(duration == 0); - toast.setSwipeToDismiss(true); - // If we have a log and it's non-empty, show a View Log button - if (button) { - toast.setButtonIcon(R.drawable.ic_action_view_as_list, - activity.getResources().getString(R.string.view_log)); - toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); - toast.setTextColor(activity.getResources().getColor(R.color.black)); - toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", - new SuperToast.OnClickListener() { - @Override - public void onClick(View view, Parcelable token) { - Intent intent = new Intent( - activity, LogDisplayActivity.class); - intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this); - activity.startActivity(intent); - } - } - )); - } - - return toast; - - } - - } - - public static class EditKeyResult extends OperationResultParcel { - - private transient UncachedKeyRing mRing; - public final long mRingMasterKeyId; - - public EditKeyResult(int result, OperationLog log, - UncachedKeyRing ring) { - super(result, log); - mRing = ring; - mRingMasterKeyId = ring != null ? ring.getMasterKeyId() : Constants.key.none; - } - - public UncachedKeyRing getRing() { - return mRing; - } - - public EditKeyResult(Parcel source) { - super(source); - mRingMasterKeyId = source.readLong(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeLong(mRingMasterKeyId); - } - - public static Creator CREATOR = new Creator() { - public EditKeyResult createFromParcel(final Parcel source) { - return new EditKeyResult(source); - } - - public EditKeyResult[] newArray(final int size) { - return new EditKeyResult[size]; - } - }; - - } - - - public static class SaveKeyringResult extends OperationResultParcel { - - public final long mRingMasterKeyId; - - public SaveKeyringResult(int result, OperationLog log, - CanonicalizedKeyRing ring) { - super(result, log); - mRingMasterKeyId = ring != null ? ring.getMasterKeyId() : Constants.key.none; - } - - // Some old key was updated - public static final int UPDATED = 4; - - // Public key was saved - public static final int SAVED_PUBLIC = 8; - // Secret key was saved (not exclusive with public!) - public static final int SAVED_SECRET = 16; - - public boolean updated() { - return (mResult & UPDATED) == UPDATED; - } - - public SaveKeyringResult(Parcel source) { - super(source); - mRingMasterKeyId = source.readLong(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeLong(mRingMasterKeyId); - } - - public static Creator CREATOR = new Creator() { - public SaveKeyringResult createFromParcel(final Parcel source) { - return new SaveKeyringResult(source); - } - - public SaveKeyringResult[] newArray(final int size) { - return new SaveKeyringResult[size]; - } - }; - } - - public static class ConsolidateResult extends OperationResultParcel { - - public ConsolidateResult(int result, OperationLog log) { - super(result, log); - } - - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ConsolidateResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ConsolidateResult.java new file mode 100644 index 000000000..31f4cabc3 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ConsolidateResult.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * Copyright (C) 2014 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.service.results; + +public class ConsolidateResult extends OperationResultParcel { + + public ConsolidateResult(int result, OperationLog log) { + super(result, log); + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/EditKeyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/EditKeyResult.java new file mode 100644 index 000000000..169ed9f36 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/EditKeyResult.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * Copyright (C) 2014 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.service.results; + +import android.os.Parcel; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; + +public class EditKeyResult extends OperationResultParcel { + + private transient UncachedKeyRing mRing; + public final long mRingMasterKeyId; + + public EditKeyResult(int result, OperationLog log, + UncachedKeyRing ring) { + super(result, log); + mRing = ring; + mRingMasterKeyId = ring != null ? ring.getMasterKeyId() : Constants.key.none; + } + + public UncachedKeyRing getRing() { + return mRing; + } + + public EditKeyResult(Parcel source) { + super(source); + mRingMasterKeyId = source.readLong(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeLong(mRingMasterKeyId); + } + + public static Creator CREATOR = new Creator() { + public EditKeyResult createFromParcel(final Parcel source) { + return new EditKeyResult(source); + } + + public EditKeyResult[] newArray(final int size) { + return new EditKeyResult[size]; + } + }; + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java new file mode 100644 index 000000000..62b5b1b52 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * Copyright (C) 2014 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.service.results; + +import android.app.Activity; +import android.content.Intent; +import android.os.Parcel; +import android.os.Parcelable; +import android.view.View; + +import com.github.johnpersano.supertoasts.SuperCardToast; +import com.github.johnpersano.supertoasts.SuperToast; +import com.github.johnpersano.supertoasts.SuperToast.Duration; +import com.github.johnpersano.supertoasts.util.OnClickWrapper; +import com.github.johnpersano.supertoasts.util.Style; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.LogDisplayActivity; +import org.sufficientlysecure.keychain.ui.LogDisplayFragment; + +public class ImportKeyResult extends OperationResultParcel { + + public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret; + + // At least one new key + public static final int RESULT_OK_NEWKEYS = 8; + // At least one updated key + public static final int RESULT_OK_UPDATED = 16; + // At least one key failed (might still be an overall success) + public static final int RESULT_WITH_ERRORS = 32; + + // No keys to import... + public static final int RESULT_FAIL_NOTHING = 64 + 1; + + public boolean isOkBoth() { + return (mResult & (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED)) + == (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED); + } + + public boolean isOkNew() { + return (mResult & RESULT_OK_NEWKEYS) == RESULT_OK_NEWKEYS; + } + + public boolean isOkUpdated() { + return (mResult & RESULT_OK_UPDATED) == RESULT_OK_UPDATED; + } + + public boolean isFailNothing() { + return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING; + } + + public ImportKeyResult(Parcel source) { + super(source); + mNewKeys = source.readInt(); + mUpdatedKeys = source.readInt(); + mBadKeys = source.readInt(); + mSecret = source.readInt(); + } + + public ImportKeyResult(int result, OperationLog log, + int newKeys, int updatedKeys, int badKeys, int secret) { + super(result, log); + mNewKeys = newKeys; + mUpdatedKeys = updatedKeys; + mBadKeys = badKeys; + mSecret = secret; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(mNewKeys); + dest.writeInt(mUpdatedKeys); + dest.writeInt(mBadKeys); + dest.writeInt(mSecret); + } + + public static Creator CREATOR = new Creator() { + public ImportKeyResult createFromParcel(final Parcel source) { + return new ImportKeyResult(source); + } + + public ImportKeyResult[] newArray(final int size) { + return new ImportKeyResult[size]; + } + }; + + public SuperCardToast createNotify(final Activity activity) { + + int resultType = getResult(); + + String str; + int duration, color; + + // Not an overall failure + if ((resultType & OperationResultParcel.RESULT_ERROR) == 0) { + String withWarnings; + + duration = Duration.EXTRA_LONG; + color = Style.GREEN; + withWarnings = ""; + + // Any warnings? + if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { + duration = 0; + color = Style.ORANGE; + withWarnings += activity.getString(R.string.import_with_warnings); + } + if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { + duration = 0; + color = Style.ORANGE; + withWarnings += activity.getString(R.string.import_with_cancelled); + } + + // New and updated keys + if (this.isOkBoth()) { + str = activity.getResources().getQuantityString( + R.plurals.import_keys_added_and_updated_1, mNewKeys, mNewKeys); + str += " " + activity.getResources().getQuantityString( + R.plurals.import_keys_added_and_updated_2, mUpdatedKeys, mUpdatedKeys, withWarnings); + } else if (isOkUpdated()) { + str = activity.getResources().getQuantityString( + R.plurals.import_keys_updated, mUpdatedKeys, mUpdatedKeys, withWarnings); + } else if (isOkNew()) { + str = activity.getResources().getQuantityString( + R.plurals.import_keys_added, mNewKeys, mNewKeys, withWarnings); + } else { + duration = 0; + color = Style.RED; + str = "internal error"; + } + + } else { + duration = 0; + color = Style.RED; + if (isFailNothing()) { + str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0 + ? R.string.import_error_nothing_cancelled + : R.string.import_error_nothing); + } else { + str = activity.getString(R.string.import_error); + } + } + + boolean button = getLog() != null && !getLog().isEmpty(); + SuperCardToast toast = new SuperCardToast(activity, + button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, + Style.getStyle(color, SuperToast.Animations.POPUP)); + toast.setText(str); + toast.setDuration(duration); + toast.setIndeterminate(duration == 0); + toast.setSwipeToDismiss(true); + // If we have a log and it's non-empty, show a View Log button + if (button) { + toast.setButtonIcon(R.drawable.ic_action_view_as_list, + activity.getResources().getString(R.string.view_log)); + toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); + toast.setTextColor(activity.getResources().getColor(R.color.black)); + toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", + new SuperToast.OnClickListener() { + @Override + public void onClick(View view, Parcelable token) { + Intent intent = new Intent( + activity, LogDisplayActivity.class); + intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this); + activity.startActivity(intent); + } + } + )); + } + + return toast; + + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResultParcel.java new file mode 100644 index 000000000..580072957 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResultParcel.java @@ -0,0 +1,532 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * Copyright (C) 2014 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.service.results; + +import android.app.Activity; +import android.content.Intent; +import android.os.Parcel; +import android.os.Parcelable; +import android.view.View; + +import com.github.johnpersano.supertoasts.SuperCardToast; +import com.github.johnpersano.supertoasts.SuperToast; +import com.github.johnpersano.supertoasts.util.OnClickWrapper; +import com.github.johnpersano.supertoasts.util.Style; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.LogDisplayActivity; +import org.sufficientlysecure.keychain.ui.LogDisplayFragment; +import org.sufficientlysecure.keychain.util.IterableIterator; +import org.sufficientlysecure.keychain.util.Log; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** Represent the result of an operation. + * + * This class holds a result and the log of an operation. It can be subclassed + * to include typed additional information specific to the operation. To keep + * the class structure (somewhat) simple, this class contains an exhaustive + * list (ie, enum) of all possible log types, which should in all cases be tied + * to string resource ids. + * + * TODO ideally, this class should be abstract, and all actual results of a specific subclass + * + */ +public class OperationResultParcel implements Parcelable { + + public static final String EXTRA_RESULT = "operation_result"; + + /** Holds the overall result, the number specifying varying degrees of success: + * - The first bit is 0 on overall success, 1 on overall failure + * - The second bit indicates if the action was cancelled - may still be an error or success! + * - The third bit should be set if the operation succeeded with warnings + * All other bits may be used for more specific conditions. */ + final int mResult; + + public static final int RESULT_OK = 0; + public static final int RESULT_ERROR = 1; + public static final int RESULT_CANCELLED = 2; + public static final int RESULT_WARNINGS = 4; + + /// A list of log entries tied to the operation result. + final OperationLog mLog; + + public OperationResultParcel(int result, OperationLog log) { + mResult = result; + mLog = log; + } + + public OperationResultParcel(Parcel source) { + mResult = source.readInt(); + mLog = new OperationLog(); + mLog.addAll(source.createTypedArrayList(LogEntryParcel.CREATOR)); + } + + public int getResult() { + return mResult; + } + + public boolean success() { + return (mResult & RESULT_ERROR) == 0; + } + + public boolean cancelled() { + return (mResult & RESULT_CANCELLED) == RESULT_CANCELLED; + } + + public OperationLog getLog() { + return mLog; + } + + /** One entry in the log. */ + public static class LogEntryParcel implements Parcelable { + public final LogLevel mLevel; + public final LogType mType; + public final Object[] mParameters; + public final int mIndent; + + public LogEntryParcel(LogLevel level, LogType type, int indent, Object... parameters) { + mLevel = level; + mType = type; + mParameters = parameters; + mIndent = indent; + Log.v(Constants.TAG, "log: " + this.toString()); + } + + public LogEntryParcel(Parcel source) { + mLevel = LogLevel.values()[source.readInt()]; + mType = LogType.values()[source.readInt()]; + mParameters = (Object[]) source.readSerializable(); + mIndent = source.readInt(); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(mLevel.ordinal()); + dest.writeInt(mType.ordinal()); + dest.writeSerializable(mParameters); + dest.writeInt(mIndent); + } + + public static final Creator CREATOR = new Creator() { + public LogEntryParcel createFromParcel(final Parcel source) { + return new LogEntryParcel(source); + } + + public LogEntryParcel[] newArray(final int size) { + return new LogEntryParcel[size]; + } + }; + + @Override + public String toString() { + return "LogEntryParcel{" + + "mLevel=" + mLevel + + ", mType=" + mType + + ", mParameters=" + Arrays.toString(mParameters) + + ", mIndent=" + mIndent + + '}'; + } + } + + public SuperCardToast createNotify(final Activity activity) { + + String str; + int color; + + // Not an overall failure + if (cancelled()) { + color = Style.RED; + str = "operation cancelled!"; + } else if (success()) { + if (getLog().containsWarnings()) { + color = Style.ORANGE; + } else { + color = Style.GREEN; + } + str = "operation succeeded!"; + // str = activity.getString(R.string.import_error); + } else { + color = Style.RED; + str = "operation failed"; + // str = activity.getString(R.string.import_error); + } + + boolean button = getLog() != null && !getLog().isEmpty(); + SuperCardToast toast = new SuperCardToast(activity, + button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, + Style.getStyle(color, SuperToast.Animations.POPUP)); + toast.setText(str); + toast.setDuration(SuperToast.Duration.EXTRA_LONG); + toast.setIndeterminate(false); + toast.setSwipeToDismiss(true); + // If we have a log and it's non-empty, show a View Log button + if (button) { + toast.setButtonIcon(R.drawable.ic_action_view_as_list, + activity.getResources().getString(R.string.view_log)); + toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); + toast.setTextColor(activity.getResources().getColor(R.color.black)); + toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", + new SuperToast.OnClickListener() { + @Override + public void onClick(View view, Parcelable token) { + Intent intent = new Intent( + activity, LogDisplayActivity.class); + intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResultParcel.this); + activity.startActivity(intent); + } + } + )); + } + + return toast; + + } + + /** This is an enum of all possible log events. + * + * Element names should generally be prefixed with MSG_XX_ where XX is an + * identifier based on the related activity. + * + * Log messages should occur for each distinguishable action group. For + * each such group, one message is displayed followed by warnings or + * errors, and optionally subactions. The granularity should generally be + * optimistic: No "success" messages are printed except for the outermost + * operations - the success of an action group is indicated by the + * beginning message of the next action group. + * + * Log messages should be in present tense, There should be no trailing + * punctuation, except for error messages which may end in an exclamation + * mark. + * + */ + public static enum LogType { + + MSG_INTERNAL_ERROR (R.string.msg_internal_error), + MSG_OPERATION_CANCELLED (R.string.msg_cancelled), + + // import public + MSG_IP(R.string.msg_ip), + MSG_IP_APPLY_BATCH (R.string.msg_ip_apply_batch), + MSG_IP_BAD_TYPE_SECRET (R.string.msg_ip_bad_type_secret), + MSG_IP_DELETE_OLD_FAIL (R.string.msg_ip_delete_old_fail), + MSG_IP_DELETE_OLD_OK (R.string.msg_ip_delete_old_ok), + MSG_IP_ENCODE_FAIL (R.string.msg_ip_encode_fail), + MSG_IP_FAIL_IO_EXC (R.string.msg_ip_fail_io_exc), + MSG_IP_FAIL_OP_EXC (R.string.msg_ip_fail_op_exc), + MSG_IP_FAIL_REMOTE_EX (R.string.msg_ip_fail_remote_ex), + MSG_IP_INSERT_KEYRING (R.string.msg_ip_insert_keyring), + MSG_IP_INSERT_SUBKEYS (R.string.msg_ip_insert_keys), + MSG_IP_PREPARE (R.string.msg_ip_prepare), + MSG_IP_REINSERT_SECRET (R.string.msg_ip_reinsert_secret), + MSG_IP_MASTER (R.string.msg_ip_master), + MSG_IP_MASTER_EXPIRED (R.string.msg_ip_master_expired), + MSG_IP_MASTER_EXPIRES (R.string.msg_ip_master_expires), + MSG_IP_MASTER_FLAGS_CES (R.string.msg_ip_master_flags_ces), + MSG_IP_MASTER_FLAGS_CEX (R.string.msg_ip_master_flags_cex), + MSG_IP_MASTER_FLAGS_CXS (R.string.msg_ip_master_flags_cxs), + MSG_IP_MASTER_FLAGS_XES (R.string.msg_ip_master_flags_xes), + MSG_IP_MASTER_FLAGS_CXX (R.string.msg_ip_master_flags_cxx), + MSG_IP_MASTER_FLAGS_XEX (R.string.msg_ip_master_flags_xex), + MSG_IP_MASTER_FLAGS_XXS (R.string.msg_ip_master_flags_xxs), + MSG_IP_MASTER_FLAGS_XXX (R.string.msg_ip_master_flags_xxx), + MSG_IP_SUBKEY (R.string.msg_ip_subkey), + MSG_IP_SUBKEY_EXPIRED (R.string.msg_ip_subkey_expired), + MSG_IP_SUBKEY_EXPIRES (R.string.msg_ip_subkey_expires), + MSG_IP_SUBKEY_FLAGS_CES (R.string.msg_ip_subkey_flags_ces), + MSG_IP_SUBKEY_FLAGS_CEX (R.string.msg_ip_subkey_flags_cex), + MSG_IP_SUBKEY_FLAGS_CXS (R.string.msg_ip_subkey_flags_cxs), + MSG_IP_SUBKEY_FLAGS_XES (R.string.msg_ip_subkey_flags_xes), + MSG_IP_SUBKEY_FLAGS_CXX (R.string.msg_ip_subkey_flags_cxx), + MSG_IP_SUBKEY_FLAGS_XEX (R.string.msg_ip_subkey_flags_xex), + MSG_IP_SUBKEY_FLAGS_XXS (R.string.msg_ip_subkey_flags_xxs), + MSG_IP_SUBKEY_FLAGS_XXX (R.string.msg_ip_subkey_flags_xxx), + MSG_IP_SUCCESS (R.string.msg_ip_success), + MSG_IP_SUCCESS_IDENTICAL (R.string.msg_ip_success_identical), + MSG_IP_UID_CERT_BAD (R.string.msg_ip_uid_cert_bad), + MSG_IP_UID_CERT_ERROR (R.string.msg_ip_uid_cert_error), + MSG_IP_UID_CERT_GOOD (R.string.msg_ip_uid_cert_good), + MSG_IP_UID_CERTS_UNKNOWN (R.plurals.msg_ip_uid_certs_unknown), + MSG_IP_UID_CLASSIFYING_ZERO (R.string.msg_ip_uid_classifying_zero), + MSG_IP_UID_CLASSIFYING (R.plurals.msg_ip_uid_classifying), + MSG_IP_UID_REORDER(R.string.msg_ip_uid_reorder), + MSG_IP_UID_PROCESSING (R.string.msg_ip_uid_processing), + MSG_IP_UID_REVOKED (R.string.msg_ip_uid_revoked), + + // import secret + MSG_IS(R.string.msg_is), + MSG_IS_BAD_TYPE_PUBLIC (R.string.msg_is_bad_type_public), + MSG_IS_DB_EXCEPTION (R.string.msg_is_db_exception), + MSG_IS_FAIL_IO_EXC (R.string.msg_is_io_exc), + MSG_IS_IMPORTING_SUBKEYS (R.string.msg_is_importing_subkeys), + MSG_IS_PUBRING_GENERATE (R.string.msg_is_pubring_generate), + MSG_IS_SUBKEY_NONEXISTENT (R.string.msg_is_subkey_nonexistent), + MSG_IS_SUBKEY_OK (R.string.msg_is_subkey_ok), + MSG_IS_SUBKEY_STRIPPED (R.string.msg_is_subkey_stripped), + MSG_IS_SUBKEY_DIVERT (R.string.msg_is_subkey_divert), + MSG_IS_SUBKEY_EMPTY (R.string.msg_is_subkey_empty), + MSG_IS_SUCCESS_IDENTICAL (R.string.msg_is_success_identical), + MSG_IS_SUCCESS (R.string.msg_is_success), + + // keyring canonicalization + MSG_KC_PUBLIC (R.string.msg_kc_public), + MSG_KC_SECRET (R.string.msg_kc_secret), + MSG_KC_ERROR_V3 (R.string.msg_kc_error_v3), + MSG_KC_ERROR_NO_UID (R.string.msg_kc_error_no_uid), + MSG_KC_ERROR_MASTER_ALGO (R.string.msg_kc_error_master_algo), + MSG_KC_MASTER (R.string.msg_kc_master), + MSG_KC_REVOKE_BAD_ERR (R.string.msg_kc_revoke_bad_err), + MSG_KC_REVOKE_BAD_LOCAL (R.string.msg_kc_revoke_bad_local), + MSG_KC_REVOKE_BAD_TIME (R.string.msg_kc_revoke_bad_time), + MSG_KC_REVOKE_BAD_TYPE (R.string.msg_kc_revoke_bad_type), + MSG_KC_REVOKE_BAD_TYPE_UID (R.string.msg_kc_revoke_bad_type_uid), + MSG_KC_REVOKE_BAD (R.string.msg_kc_revoke_bad), + MSG_KC_REVOKE_DUP (R.string.msg_kc_revoke_dup), + MSG_KC_SUB (R.string.msg_kc_sub), + MSG_KC_SUB_BAD(R.string.msg_kc_sub_bad), + MSG_KC_SUB_BAD_ERR(R.string.msg_kc_sub_bad_err), + MSG_KC_SUB_BAD_LOCAL(R.string.msg_kc_sub_bad_local), + MSG_KC_SUB_BAD_KEYID(R.string.msg_kc_sub_bad_keyid), + MSG_KC_SUB_BAD_TIME(R.string.msg_kc_sub_bad_time), + MSG_KC_SUB_BAD_TYPE(R.string.msg_kc_sub_bad_type), + MSG_KC_SUB_DUP (R.string.msg_kc_sub_dup), + MSG_KC_SUB_PRIMARY_BAD(R.string.msg_kc_sub_primary_bad), + MSG_KC_SUB_PRIMARY_BAD_ERR(R.string.msg_kc_sub_primary_bad_err), + MSG_KC_SUB_PRIMARY_NONE(R.string.msg_kc_sub_primary_none), + MSG_KC_SUB_NO_CERT(R.string.msg_kc_sub_no_cert), + MSG_KC_SUB_REVOKE_BAD_ERR (R.string.msg_kc_sub_revoke_bad_err), + MSG_KC_SUB_REVOKE_BAD (R.string.msg_kc_sub_revoke_bad), + MSG_KC_SUB_REVOKE_DUP (R.string.msg_kc_sub_revoke_dup), + MSG_KC_SUB_UNKNOWN_ALGO (R.string.msg_kc_sub_unknown_algo), + MSG_KC_SUCCESS_BAD (R.plurals.msg_kc_success_bad), + MSG_KC_SUCCESS_BAD_AND_RED (R.string.msg_kc_success_bad_and_red), + MSG_KC_SUCCESS_REDUNDANT (R.plurals.msg_kc_success_redundant), + MSG_KC_SUCCESS (R.string.msg_kc_success), + MSG_KC_UID_BAD_ERR (R.string.msg_kc_uid_bad_err), + MSG_KC_UID_BAD_LOCAL (R.string.msg_kc_uid_bad_local), + MSG_KC_UID_BAD_TIME (R.string.msg_kc_uid_bad_time), + MSG_KC_UID_BAD_TYPE (R.string.msg_kc_uid_bad_type), + MSG_KC_UID_BAD (R.string.msg_kc_uid_bad), + MSG_KC_UID_CERT_DUP (R.string.msg_kc_uid_cert_dup), + MSG_KC_UID_DUP (R.string.msg_kc_uid_dup), + MSG_KC_UID_FOREIGN (R.string.msg_kc_uid_foreign), + MSG_KC_UID_NO_CERT (R.string.msg_kc_uid_no_cert), + MSG_KC_UID_REVOKE_DUP (R.string.msg_kc_uid_revoke_dup), + MSG_KC_UID_REVOKE_OLD (R.string.msg_kc_uid_revoke_old), + MSG_KC_UID_REMOVE (R.string.msg_kc_uid_remove), + + + // keyring consolidation + MSG_MG_ERROR_SECRET_DUMMY(R.string.msg_mg_error_secret_dummy), + MSG_MG_ERROR_ENCODE(R.string.msg_mg_error_encode), + MSG_MG_ERROR_HETEROGENEOUS(R.string.msg_mg_error_heterogeneous), + MSG_MG_PUBLIC (R.string.msg_mg_public), + MSG_MG_SECRET (R.string.msg_mg_secret), + MSG_MG_NEW_SUBKEY (R.string.msg_mg_new_subkey), + MSG_MG_FOUND_NEW (R.string.msg_mg_found_new), + MSG_MG_UNCHANGED (R.string.msg_mg_unchanged), + + // secret key create + MSG_CR (R.string.msg_cr), + MSG_CR_ERROR_NO_MASTER (R.string.msg_cr_error_no_master), + MSG_CR_ERROR_NO_USER_ID (R.string.msg_cr_error_no_user_id), + MSG_CR_ERROR_NO_CERTIFY (R.string.msg_cr_error_no_certify), + MSG_CR_ERROR_NULL_EXPIRY(R.string.msg_cr_error_null_expiry), + MSG_CR_ERROR_KEYSIZE_512 (R.string.msg_cr_error_keysize_512), + MSG_CR_ERROR_NO_KEYSIZE (R.string.msg_cr_error_no_keysize), + MSG_CR_ERROR_NO_CURVE (R.string.msg_cr_error_no_curve), + MSG_CR_ERROR_UNKNOWN_ALGO (R.string.msg_cr_error_unknown_algo), + MSG_CR_ERROR_INTERNAL_PGP (R.string.msg_cr_error_internal_pgp), + MSG_CR_ERROR_FLAGS_DSA (R.string.msg_cr_error_flags_dsa), + MSG_CR_ERROR_FLAGS_ELGAMAL (R.string.msg_cr_error_flags_elgamal), + MSG_CR_ERROR_FLAGS_ECDSA (R.string.msg_cr_error_flags_ecdsa), + MSG_CR_ERROR_FLAGS_ECDH (R.string.msg_cr_error_flags_ecdh), + + // secret key modify + MSG_MF (R.string.msg_mr), + MSG_MF_ERROR_ENCODE (R.string.msg_mf_error_encode), + MSG_MF_ERROR_FINGERPRINT (R.string.msg_mf_error_fingerprint), + MSG_MF_ERROR_KEYID (R.string.msg_mf_error_keyid), + MSG_MF_ERROR_INTEGRITY (R.string.msg_mf_error_integrity), + MSG_MF_ERROR_MASTER_NONE(R.string.msg_mf_error_master_none), + MSG_MF_ERROR_NO_CERTIFY (R.string.msg_cr_error_no_certify), + MSG_MF_ERROR_NOEXIST_PRIMARY (R.string.msg_mf_error_noexist_primary), + MSG_MF_ERROR_NOEXIST_REVOKE (R.string.msg_mf_error_noexist_revoke), + MSG_MF_ERROR_NULL_EXPIRY (R.string.msg_mf_error_null_expiry), + MSG_MF_ERROR_PASSPHRASE_MASTER(R.string.msg_mf_error_passphrase_master), + MSG_MF_ERROR_PAST_EXPIRY(R.string.msg_mf_error_past_expiry), + MSG_MF_ERROR_PGP (R.string.msg_mf_error_pgp), + MSG_MF_ERROR_REVOKED_PRIMARY (R.string.msg_mf_error_revoked_primary), + MSG_MF_ERROR_SIG (R.string.msg_mf_error_sig), + MSG_MF_ERROR_SUBKEY_MISSING(R.string.msg_mf_error_subkey_missing), + MSG_MF_MASTER (R.string.msg_mf_master), + MSG_MF_PASSPHRASE (R.string.msg_mf_passphrase), + MSG_MF_PASSPHRASE_KEY (R.string.msg_mf_passphrase_key), + MSG_MF_PASSPHRASE_EMPTY_RETRY (R.string.msg_mf_passphrase_empty_retry), + MSG_MF_PASSPHRASE_FAIL (R.string.msg_mf_passphrase_fail), + MSG_MF_PRIMARY_REPLACE_OLD (R.string.msg_mf_primary_replace_old), + MSG_MF_PRIMARY_NEW (R.string.msg_mf_primary_new), + MSG_MF_SUBKEY_CHANGE (R.string.msg_mf_subkey_change), + MSG_MF_SUBKEY_NEW_ID (R.string.msg_mf_subkey_new_id), + MSG_MF_SUBKEY_NEW (R.string.msg_mf_subkey_new), + MSG_MF_SUBKEY_REVOKE (R.string.msg_mf_subkey_revoke), + MSG_MF_SUBKEY_STRIP (R.string.msg_mf_subkey_strip), + MSG_MF_SUCCESS (R.string.msg_mf_success), + MSG_MF_UID_ADD (R.string.msg_mf_uid_add), + MSG_MF_UID_PRIMARY (R.string.msg_mf_uid_primary), + MSG_MF_UID_REVOKE (R.string.msg_mf_uid_revoke), + MSG_MF_UID_ERROR_EMPTY (R.string.msg_mf_uid_error_empty), + MSG_MF_UNLOCK_ERROR (R.string.msg_mf_unlock_error), + MSG_MF_UNLOCK (R.string.msg_mf_unlock), + + // consolidate + MSG_CON_CRITICAL_IN (R.string.msg_con_critical_in), + MSG_CON_CRITICAL_OUT (R.string.msg_con_critical_out), + MSG_CON_DB_CLEAR (R.string.msg_con_db_clear), + MSG_CON_DELETE_PUBLIC (R.string.msg_con_delete_public), + MSG_CON_DELETE_SECRET (R.string.msg_con_delete_secret), + MSG_CON_ERROR_BAD_STATE (R.string.msg_con_error_bad_state), + MSG_CON_ERROR_CONCURRENT(R.string.msg_con_error_concurrent), + MSG_CON_ERROR_DB (R.string.msg_con_error_db), + MSG_CON_ERROR_IO_PUBLIC (R.string.msg_con_error_io_public), + MSG_CON_ERROR_IO_SECRET (R.string.msg_con_error_io_secret), + MSG_CON_ERROR_PUBLIC (R.string.msg_con_error_public), + MSG_CON_ERROR_SECRET (R.string.msg_con_error_secret), + MSG_CON_RECOVER (R.plurals.msg_con_recover), + MSG_CON_RECOVER_UNKNOWN (R.string.msg_con_recover_unknown), + MSG_CON_REIMPORT_PUBLIC (R.plurals.msg_con_reimport_public), + MSG_CON_REIMPORT_PUBLIC_SKIP (R.string.msg_con_reimport_public_skip), + MSG_CON_REIMPORT_SECRET (R.plurals.msg_con_reimport_secret), + MSG_CON_REIMPORT_SECRET_SKIP (R.string.msg_con_reimport_secret_skip), + MSG_CON (R.string.msg_con), + MSG_CON_SAVE_PUBLIC (R.string.msg_con_save_public), + MSG_CON_SAVE_SECRET (R.string.msg_con_save_secret), + MSG_CON_SUCCESS (R.string.msg_con_success), + MSG_CON_WARN_DELETE_PUBLIC (R.string.msg_con_warn_delete_public), + MSG_CON_WARN_DELETE_SECRET (R.string.msg_con_warn_delete_secret), + + // messages used in UI code + MSG_EK_ERROR_DIVERT (R.string.msg_ek_error_divert), + MSG_EK_ERROR_DUMMY (R.string.msg_ek_error_dummy), + MSG_EK_ERROR_NOT_FOUND (R.string.msg_ek_error_not_found), + + ; + + private final int mMsgId; + LogType(int msgId) { + mMsgId = msgId; + } + public int getMsgId() { + return mMsgId; + } + } + + /** Enumeration of possible log levels. */ + public static enum LogLevel { + DEBUG, + INFO, + WARN, + ERROR, // should occur once at the end of a failed operation + START, // should occur once at the start of each independent operation + OK, // should occur once at the end of a successful operation + CANCELLED, // should occur once at the end of a cancelled operation + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(mResult); + if (mLog != null) { + dest.writeTypedList(mLog.toList()); + } + } + + public static final Creator CREATOR = new Creator() { + public OperationResultParcel createFromParcel(final Parcel source) { + return new OperationResultParcel(source); + } + + public OperationResultParcel[] newArray(final int size) { + return new OperationResultParcel[size]; + } + }; + + public static class OperationLog implements Iterable { + + private final List mParcels = new ArrayList(); + + /// Simple convenience method + public void add(LogLevel level, LogType type, int indent, Object... parameters) { + mParcels.add(new OperationResultParcel.LogEntryParcel(level, type, indent, parameters)); + } + + public void add(LogLevel level, LogType type, int indent) { + mParcels.add(new OperationResultParcel.LogEntryParcel(level, type, indent, (Object[]) null)); + } + + public boolean containsType(LogType type) { + for(LogEntryParcel entry : new IterableIterator(mParcels.iterator())) { + if (entry.mType == type) { + return true; + } + } + return false; + } + + public boolean containsWarnings() { + for(LogEntryParcel entry : new IterableIterator(mParcels.iterator())) { + if (entry.mLevel == LogLevel.WARN || entry.mLevel == LogLevel.ERROR) { + return true; + } + } + return false; + } + + public void addAll(List parcels) { + mParcels.addAll(parcels); + } + + public List toList() { + return mParcels; + } + + public boolean isEmpty() { + return mParcels.isEmpty(); + } + + @Override + public Iterator iterator() { + return mParcels.iterator(); + } + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SaveKeyringResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SaveKeyringResult.java new file mode 100644 index 000000000..0edb9c617 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SaveKeyringResult.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * Copyright (C) 2014 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.service.results; + +import android.os.Parcel; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; + +public class SaveKeyringResult extends OperationResultParcel { + + public final long mRingMasterKeyId; + + public SaveKeyringResult(int result, OperationLog log, + CanonicalizedKeyRing ring) { + super(result, log); + mRingMasterKeyId = ring != null ? ring.getMasterKeyId() : Constants.key.none; + } + + // Some old key was updated + public static final int UPDATED = 4; + + // Public key was saved + public static final int SAVED_PUBLIC = 8; + // Secret key was saved (not exclusive with public!) + public static final int SAVED_SECRET = 16; + + public boolean updated() { + return (mResult & UPDATED) == UPDATED; + } + + public SaveKeyringResult(Parcel source) { + super(source); + mRingMasterKeyId = source.readLong(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeLong(mRingMasterKeyId); + } + + public static Creator CREATOR = new Creator() { + public SaveKeyringResult createFromParcel(final Parcel source) { + return new SaveKeyringResult(source); + } + + public SaveKeyringResult[] newArray(final int size) { + return new SaveKeyringResult[size]; + } + }; +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SingletonResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SingletonResult.java new file mode 100644 index 000000000..5022c46a7 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SingletonResult.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * Copyright (C) 2014 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.service.results; + +import android.app.Activity; +import android.os.Parcel; + +import com.github.johnpersano.supertoasts.SuperCardToast; +import com.github.johnpersano.supertoasts.SuperToast; +import com.github.johnpersano.supertoasts.util.Style; + +/** This is a simple subclass meant to contain only a single log message. This log + * message is also shown without a log button in the createNotify SuperToast. */ +public class SingletonResult extends OperationResultParcel { + + /** Construct from a parcel - trivial because we have no extra data. */ + public SingletonResult(Parcel source) { + super(source); + } + + public SingletonResult(int result, LogLevel level, LogType reason) { + super(result, new OperationLog()); + // Prepare the log + mLog.add(level, reason, 0); + } + + @Override + public SuperCardToast createNotify(final Activity activity) { + + // there is exactly one error msg - use that one + String str = activity.getString(mLog.iterator().next().mType.getMsgId()); + int color; + + // Determine color by result type + if (cancelled()) { + color = Style.RED; + } else if (success()) { + if (getLog().containsWarnings()) { + color = Style.ORANGE; + } else { + color = Style.GREEN; + } + } else { + color = Style.RED; + } + + SuperCardToast toast = new SuperCardToast(activity, SuperToast.Type.STANDARD, + Style.getStyle(color, SuperToast.Animations.POPUP)); + toast.setText(str); + toast.setDuration(SuperToast.Duration.EXTRA_LONG); + toast.setIndeterminate(false); + toast.setSwipeToDismiss(true); + return toast; + + } + + public static Creator CREATOR = new Creator() { + public SingletonResult createFromParcel(final Parcel source) { + return new SingletonResult(source); + } + + public SingletonResult[] newArray(final int size) { + return new SingletonResult[size]; + } + }; + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java index d921f3cc0..fb2184362 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -54,7 +54,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java index ec4f2e337..a645f18a9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -39,10 +39,10 @@ import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.OperationResultParcel; -import org.sufficientlysecure.keychain.service.OperationResults; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; +import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.Log; public class CreateKeyFinalFragment extends Fragment { @@ -140,7 +140,7 @@ public class CreateKeyFinalFragment extends Fragment { if (returnData == null) { return; } - final OperationResults.SaveKeyringResult result = + final SaveKeyringResult result = returnData.getParcelable(OperationResultParcel.EXTRA_RESULT); if (result == null) { Log.e(Constants.TAG, "result == null"); @@ -189,7 +189,7 @@ public class CreateKeyFinalFragment extends Fragment { getActivity().startService(intent); } - private void uploadKey(final OperationResults.SaveKeyringResult saveKeyResult) { + private void uploadKey(final SaveKeyringResult saveKeyResult) { // Send all information needed to service to upload key in other thread final Intent intent = new Intent(getActivity(), KeychainIntentService.class); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 8feef5e46..8bde3f295 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -48,10 +48,10 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.OperationResultParcel; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType; -import org.sufficientlysecure.keychain.service.OperationResults.SingletonResult; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogType; +import org.sufficientlysecure.keychain.service.results.SingletonResult; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index 3e949cfae..732e59e32 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -46,8 +46,8 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.OperationResultParcel; -import org.sufficientlysecure.keychain.service.OperationResults.ImportKeyResult; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.ImportKeyResult; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout; import org.sufficientlysecure.keychain.util.ParcelableFileCache; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java index 65c4b8605..1b3bb06c3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java @@ -34,8 +34,8 @@ import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.OperationResultParcel; -import org.sufficientlysecure.keychain.service.OperationResults.ConsolidateResult; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.ConsolidateResult; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Notify; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java index 1202de1b7..ddc57b8aa 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java @@ -37,9 +37,9 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.service.OperationResultParcel; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogEntryParcel; -import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogEntryParcel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogLevel; import org.sufficientlysecure.keychain.util.Log; import java.util.HashMap; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 5d8e13349..ef0b95bcc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -56,7 +56,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResultParcel; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout.TabColorizer; -- cgit v1.2.3