From 03d103af0722540c0f636c139fac33d3ffb28a34 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 14 Sep 2014 00:55:50 +0200 Subject: pending results are a type of non-success --- .../java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java | 1 + .../sufficientlysecure/keychain/service/KeychainIntentService.java | 4 ++-- .../keychain/service/results/DecryptVerifyResult.java | 5 +++-- .../keychain/service/results/SignEncryptResult.java | 6 +++--- .../org/sufficientlysecure/keychain/ui/DecryptFileFragment.java | 4 ++-- .../org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) (limited to 'OpenKeychain/src') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java index 9f97ac4c9..a81fa1a5a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java @@ -1,6 +1,7 @@ /* * Copyright (C) 2012-2014 Dominik Schürmann * Copyright (C) 2010-2014 Thialfihar + * 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 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 e09c71787..f012d9a79 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -364,7 +364,7 @@ public class KeychainIntentService extends IntentService implements Progressable outStream.close(); - resultData.putParcelable(RESULT_DECRYPT_VERIFY_RESULT, decryptVerifyResult); + resultData.putParcelable(DecryptVerifyResult.EXTRA_RESULT, decryptVerifyResult); /* Output */ @@ -411,7 +411,7 @@ public class KeychainIntentService extends IntentService implements Progressable DecryptVerifyResult decryptVerifyResult = builder.build().execute(); - resultData.putParcelable(RESULT_DECRYPT_VERIFY_RESULT, decryptVerifyResult); + resultData.putParcelable(DecryptVerifyResult.EXTRA_RESULT, decryptVerifyResult); /* Output */ OtherHelper.logDebugBundle(resultData, "resultData"); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java index e7ac209bf..7339f1306 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java @@ -1,5 +1,6 @@ /* * 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 @@ -24,8 +25,8 @@ import org.openintents.openpgp.OpenPgpSignatureResult; public class DecryptVerifyResult extends OperationResultParcel { - // the fourth bit indicates a "data pending" result! - public static final int RESULT_PENDING = 8; + // the fourth bit indicates a "data pending" result! (it's also a form of non-success) + public static final int RESULT_PENDING = RESULT_ERROR +8; // fifth to sixth bit in addition indicate specific type of pending public static final int RESULT_PENDING_ASYM_PASSPHRASE = RESULT_PENDING +16; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java index 073eab354..100a7c675 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java @@ -1,5 +1,5 @@ /* - * 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 @@ -26,8 +26,8 @@ import java.util.Date; public class SignEncryptResult extends OperationResultParcel { - // the fourth bit indicates a "data pending" result! - public static final int RESULT_PENDING = 8; + // the fourth bit indicates a "data pending" result! (it's also a form of non-success) + public static final int RESULT_PENDING = RESULT_ERROR +8; // fifth to sixth bit in addition indicate specific type of pending public static final int RESULT_PENDING_NFC = RESULT_PENDING +16; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java index 7d9b2b9b3..924c5bec2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFileFragment.java @@ -179,7 +179,7 @@ public class DecryptFileFragment extends DecryptFragment { Bundle returnData = message.getData(); DecryptVerifyResult result = - returnData.getParcelable(KeychainIntentService.RESULT_DECRYPT_VERIFY_RESULT); + returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT); switch (result.getResult()) { case DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE: @@ -259,7 +259,7 @@ public class DecryptFileFragment extends DecryptFragment { Bundle returnData = message.getData(); DecryptVerifyResult result = - returnData.getParcelable(KeychainIntentService.RESULT_DECRYPT_VERIFY_RESULT); + returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT); if (result.isPending()) { switch (result.getResult()) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java index a7a630be1..66ed563d9 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptMessageFragment.java @@ -144,7 +144,7 @@ public class DecryptMessageFragment extends DecryptFragment { Bundle returnData = message.getData(); DecryptVerifyResult result = - returnData.getParcelable(KeychainIntentService.RESULT_DECRYPT_VERIFY_RESULT); + returnData.getParcelable(DecryptVerifyResult.EXTRA_RESULT); if (result.isPending()) { switch (result.getResult()) { -- cgit v1.2.3 From 36ef8a9a62f32f0843c9e317d493a7f136624dce Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sun, 14 Sep 2014 01:14:58 +0200 Subject: work on OperationResultParcel --- .../keychain/pgp/PgpDecryptVerify.java | 6 +- .../keychain/pgp/PgpImportExport.java | 6 +- .../keychain/pgp/PgpKeyOperation.java | 10 +- .../keychain/pgp/PgpSignEncrypt.java | 8 +- .../keychain/pgp/UncachedKeyRing.java | 7 +- .../keychain/provider/ProviderHelper.java | 6 +- .../keychain/remote/OpenPgpService.java | 3 +- .../remote/ui/AccountSettingsActivity.java | 14 +- .../remote/ui/AccountSettingsFragment.java | 6 +- .../keychain/remote/ui/AppSettingsActivity.java | 6 +- .../keychain/service/KeychainIntentService.java | 12 +- .../service/results/ConsolidateResult.java | 2 +- .../service/results/DecryptVerifyResult.java | 2 +- .../keychain/service/results/EditKeyResult.java | 2 +- .../keychain/service/results/ImportKeyResult.java | 4 +- .../keychain/service/results/OperationResult.java | 594 ++++++++++++++++++++ .../service/results/OperationResultParcel.java | 602 --------------------- .../service/results/SaveKeyringResult.java | 2 +- .../service/results/SignEncryptResult.java | 5 +- .../keychain/service/results/SingletonResult.java | 2 +- .../keychain/ui/CertifyKeyFragment.java | 21 +- .../keychain/ui/CreateKeyFinalFragment.java | 8 +- .../keychain/ui/EditKeyFragment.java | 14 +- .../keychain/ui/ImportKeysActivity.java | 4 +- .../keychain/ui/KeyListActivity.java | 8 +- .../keychain/ui/LogDisplayFragment.java | 12 +- .../keychain/ui/ViewKeyActivity.java | 6 +- OpenKeychain/src/main/res/values/strings.xml | 7 +- 28 files changed, 686 insertions(+), 693 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResultParcel.java (limited to 'OpenKeychain/src') 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 6e59a3b9b..58ca2b54a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java @@ -49,9 +49,9 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; -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.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ProgressScaler; 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 06415cf8a..1c994dceb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -33,9 +33,9 @@ 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.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.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.service.results.ImportKeyResult; import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.IterableIterator; 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 ad592a3e9..4ee4ac74c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -46,10 +46,10 @@ 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.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.OperationResult; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.service.results.EditKeyResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; @@ -949,7 +949,7 @@ public class PgpKeyOperation { progress(R.string.progress_done, 100); log.add(LogLevel.OK, LogType.MSG_MF_SUCCESS, indent); - return new EditKeyResult(OperationResultParcel.RESULT_OK, log, new UncachedKeyRing(sKR)); + return new EditKeyResult(OperationResult.RESULT_OK, log, new UncachedKeyRing(sKR)); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java index a81fa1a5a..e4ed740a5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java @@ -36,9 +36,9 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; -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.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.service.results.SignEncryptResult; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; @@ -367,7 +367,7 @@ public class PgpSignEncrypt { KeyRings.buildUnifiedKeyRingUri(id)); CanonicalizedPublicKey key = keyRing.getEncryptionSubKey(); cPk.addMethod(key.getPubKeyEncryptionGenerator()); - log.add(LogLevel.DEBUG, LogType.MSG_SE_KEY_OK, indent +1, + log.add(LogLevel.DEBUG, LogType.MSG_SE_KEY_OK, indent + 1, PgpKeyHelper.convertKeyIdToHex(id)); } catch (PgpGeneralException e) { log.add(LogLevel.WARN, LogType.MSG_SE_KEY_WARN, indent +1, 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 d64c3ea55..c76ecbfab 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java @@ -34,12 +34,11 @@ import org.spongycastle.openpgp.PGPSignatureList; import org.spongycastle.openpgp.PGPUtil; import org.spongycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator; import org.spongycastle.util.Strings; -import org.spongycastle.util.encoders.Hex; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -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.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResult.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 8e6a0dfa5..d2540a97d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -55,9 +55,9 @@ 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.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.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.service.results.ConsolidateResult; import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.ParcelableFileCache; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index 29f888a82..a26ee009a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -32,7 +32,6 @@ import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.util.OpenPgpApi; import org.sufficientlysecure.keychain.nfc.NfcActivity; import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; @@ -45,7 +44,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.remote.ui.RemoteServiceActivity; import org.sufficientlysecure.keychain.service.PassphraseCacheService; -import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogEntryParcel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogEntryParcel; import org.sufficientlysecure.keychain.service.results.SignEncryptResult; import org.sufficientlysecure.keychain.ui.ImportKeysActivity; import org.sufficientlysecure.keychain.ui.ViewKeyActivity; 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 4bf750121..231b26409 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,7 +30,10 @@ 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.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.service.results.SingletonResult; import org.sufficientlysecure.keychain.util.Log; public class AccountSettingsActivity extends ActionBarActivity { @@ -105,9 +108,10 @@ public class AccountSettingsActivity extends ActionBarActivity { private void save() { new ProviderHelper(this).updateApiAccount(mAccountUri, mAccountSettingsFragment.getAccSettings()); // TODO: show "account saved" instead of "operation succeeded" - OperationResultParcel result = new OperationResultParcel(OperationResultParcel.RESULT_OK, null); + SingletonResult result = new SingletonResult( + SingletonResult.RESULT_OK, LogLevel.OK, LogType.MSG_ACC_SAVED); Intent intent = new Intent(); - intent.putExtra(OperationResultParcel.EXTRA_RESULT, result); + intent.putExtra(SingletonResult.EXTRA_RESULT, result); setResult(RESULT_OK, intent); finish(); } @@ -115,8 +119,8 @@ public class AccountSettingsActivity extends ActionBarActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // if a result has been returned, display a notify - if (data != null && data.hasExtra(OperationResultParcel.EXTRA_RESULT)) { - OperationResultParcel result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT); + if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) { + OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT); result.createNotify(this).show(); } else { super.onActivityResult(requestCode, resultCode, data); 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 d21d83574..a7eb58377 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 @@ -33,7 +33,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.remote.AccountSettings; -import org.sufficientlysecure.keychain.service.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResult; import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; import org.sufficientlysecure.keychain.ui.CreateKeyActivity; import org.sufficientlysecure.keychain.ui.adapter.KeyValueSpinnerAdapter; @@ -171,8 +171,8 @@ public class AccountSettingsFragment extends Fragment { switch (requestCode) { case REQUEST_CODE_CREATE_KEY: { if (resultCode == Activity.RESULT_OK) { - if (data != null && data.hasExtra(OperationResultParcel.EXTRA_RESULT)) { - SaveKeyringResult result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT); + if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) { + SaveKeyringResult result = data.getParcelableExtra(OperationResult.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 8cc05231e..1c1978fe9 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.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResult; import org.sufficientlysecure.keychain.util.Log; public class AppSettingsActivity extends ActionBarActivity { @@ -158,8 +158,8 @@ public class AppSettingsActivity extends ActionBarActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // if a result has been returned, display a notify - if (data != null && data.hasExtra(OperationResultParcel.EXTRA_RESULT)) { - OperationResultParcel result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT); + if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) { + OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT); result.createNotify(this).show(); } else { super.onActivityResult(requestCode, resultCode, data); 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 f012d9a79..52638f592 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -55,10 +55,10 @@ 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.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.OperationResult; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.service.results.ConsolidateResult; import org.sufficientlysecure.keychain.service.results.EditKeyResult; import org.sufficientlysecure.keychain.service.results.ImportKeyResult; @@ -813,9 +813,9 @@ public class KeychainIntentService extends IntentService implements Progressable } } - private void sendMessageToHandler(Integer arg1, OperationResultParcel data) { + private void sendMessageToHandler(Integer arg1, OperationResult data) { Bundle bundle = new Bundle(); - bundle.putParcelable(OperationResultParcel.EXTRA_RESULT, data); + bundle.putParcelable(OperationResult.EXTRA_RESULT, data); sendMessageToHandler(arg1, null, bundle); } 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 index 31f4cabc3..44177563f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ConsolidateResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ConsolidateResult.java @@ -18,7 +18,7 @@ package org.sufficientlysecure.keychain.service.results; -public class ConsolidateResult extends OperationResultParcel { +public class ConsolidateResult extends OperationResult { public ConsolidateResult(int result, OperationLog log) { super(result, log); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java index 7339f1306..18533ffe6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java @@ -23,7 +23,7 @@ import android.os.Parcel; import org.openintents.openpgp.OpenPgpMetadata; import org.openintents.openpgp.OpenPgpSignatureResult; -public class DecryptVerifyResult extends OperationResultParcel { +public class DecryptVerifyResult extends OperationResult { // the fourth bit indicates a "data pending" result! (it's also a form of non-success) public static final int RESULT_PENDING = RESULT_ERROR +8; 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 index 169ed9f36..9385afd8e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/EditKeyResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/EditKeyResult.java @@ -23,7 +23,7 @@ import android.os.Parcel; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -public class EditKeyResult extends OperationResultParcel { +public class EditKeyResult extends OperationResult { private transient UncachedKeyRing mRing; public final long mRingMasterKeyId; 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 index 62b5b1b52..ec9c424cf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java @@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.LogDisplayActivity; import org.sufficientlysecure.keychain.ui.LogDisplayFragment; -public class ImportKeyResult extends OperationResultParcel { +public class ImportKeyResult extends OperationResult { public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret; @@ -109,7 +109,7 @@ public class ImportKeyResult extends OperationResultParcel { int duration, color; // Not an overall failure - if ((resultType & OperationResultParcel.RESULT_ERROR) == 0) { + if ((resultType & OperationResult.RESULT_ERROR) == 0) { String withWarnings; duration = Duration.EXTRA_LONG; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java new file mode 100644 index 000000000..d2be1466f --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java @@ -0,0 +1,594 @@ +/* + * 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 abstract class OperationResult 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 OperationResult(int result, OperationLog log) { + mResult = result; + mLog = log; + } + + public OperationResult(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) { + + int color; + + // Take the last message as string + String str = activity.getString(mLog.getLast().mType.getMsgId()); + + // Not an overall failure + if (cancelled()) { + color = Style.RED; + } else if (success()) { + if (getLog().containsWarnings()) { + color = Style.ORANGE; + } else { + color = Style.GREEN; + } + } else { + color = Style.RED; + } + + 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, OperationResult.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), + MSG_KC_UID_WARN_ENCODING (R.string.msg_kc_uid_warn_encoding), + + + // 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), + + // decryptverify + MSG_DC_ASKIP_NO_KEY (R.string.msg_dc_askip_no_key), + MSG_DC_ASKIP_NOT_ALLOWED (R.string.msg_dc_askip_not_allowed), + MSG_DC_ASYM (R.string.msg_dc_asym), + MSG_DC_CLEAR_DATA (R.string.msg_dc_clear_data), + MSG_DC_CLEAR_DECOMPRESS (R.string.msg_dc_clear_decompress), + MSG_DC_CLEAR_META_FILE (R.string.msg_dc_clear_meta_file), + MSG_DC_CLEAR_META_MIME (R.string.msg_dc_clear_meta_mime), + MSG_DC_CLEAR_META_SIZE (R.string.msg_dc_clear_meta_size), + MSG_DC_CLEAR_META_TIME (R.string.msg_dc_clear_meta_time), + MSG_DC_CLEAR (R.string.msg_dc_clear), + MSG_DC_CLEAR_SIGNATURE_BAD (R.string.msg_dc_clear_signature_bad), + MSG_DC_CLEAR_SIGNATURE_CHECK (R.string.msg_dc_clear_signature_check), + MSG_DC_CLEAR_SIGNATURE_OK (R.string.msg_dc_clear_signature_ok), + MSG_DC_CLEAR_SIGNATURE (R.string.msg_dc_clear_signature), + MSG_DC_ERROR_BAD_PASSPHRASE (R.string.msg_dc_error_bad_passphrase), + MSG_DC_ERROR_EXTRACT_KEY (R.string.msg_dc_error_extract_key), + MSG_DC_ERROR_INTEGRITY_CHECK (R.string.msg_dc_error_integrity_check), + MSG_DC_ERROR_INVALID_SIGLIST(R.string.msg_dc_error_invalid_siglist), + MSG_DC_ERROR_IO (R.string.msg_dc_error_io), + MSG_DC_ERROR_NO_DATA (R.string.msg_dc_error_no_data), + MSG_DC_ERROR_NO_KEY (R.string.msg_dc_error_no_key), + MSG_DC_ERROR_PGP_EXCEPTION (R.string.msg_dc_error_pgp_exception), + MSG_DC_INTEGRITY_CHECK_OK (R.string.msg_dc_integrity_check_ok), + MSG_DC_OK_META_ONLY (R.string.msg_dc_ok_meta_only), + MSG_DC_OK (R.string.msg_dc_ok), + MSG_DC_PASS_CACHED (R.string.msg_dc_pass_cached), + MSG_DC_PENDING_NFC (R.string.msg_dc_pending_nfc), + MSG_DC_PENDING_PASSPHRASE (R.string.msg_dc_pending_passphrase), + MSG_DC_PREP_STREAMS (R.string.msg_dc_prep_streams), + MSG_DC (R.string.msg_dc), + MSG_DC_SYM (R.string.msg_dc_sym), + MSG_DC_SYM_SKIP (R.string.msg_dc_sym_skip), + MSG_DC_TRAIL_ASYM (R.string.msg_dc_trail_asym), + MSG_DC_TRAIL_SYM (R.string.msg_dc_trail_sym), + MSG_DC_TRAIL_UNKNOWN (R.string.msg_dc_trail_unknown), + MSG_DC_UNLOCKING (R.string.msg_dc_unlocking), + + // signencrypt + MSG_SE_ASYMMETRIC (R.string.msg_se_asymmetric), + MSG_SE_CLEARSIGN_ONLY (R.string.msg_se_clearsign_only), + MSG_SE_COMPRESSING (R.string.msg_se_compressing), + MSG_SE_ENCRYPTING (R.string.msg_se_encrypting), + MSG_SE_ERROR_BAD_PASSPHRASE (R.string.msg_se_error_bad_passphrase), + MSG_SE_ERROR_IO (R.string.msg_se_error_io), + MSG_SE_ERROR_SIGN_KEY(R.string.msg_se_error_sign_key), + MSG_SE_ERROR_KEY_SIGN (R.string.msg_se_error_key_sign), + MSG_SE_ERROR_NFC (R.string.msg_se_error_nfc), + MSG_SE_ERROR_NO_PASSPHRASE (R.string.msg_se_error_no_passphrase), + MSG_SE_ERROR_PGP (R.string.msg_se_error_pgp), + MSG_SE_ERROR_SIG (R.string.msg_se_error_sig), + MSG_SE_ERROR_UNLOCK (R.string.msg_se_error_unlock), + MSG_SE_KEY_OK (R.string.msg_se_key_ok), + MSG_SE_KEY_UNKNOWN (R.string.msg_se_key_unknown), + MSG_SE_KEY_WARN (R.string.msg_se_key_warn), + MSG_SE_OK (R.string.msg_se_ok), + MSG_SE_PENDING_NFC (R.string.msg_se_pending_nfc), + MSG_SE (R.string.msg_se), + MSG_SE_SIGNING (R.string.msg_se_signing), + MSG_SE_SIGCRYPTING (R.string.msg_se_sigcrypting), + MSG_SE_SYMMETRIC (R.string.msg_se_symmetric), + + MSG_CRT_UPLOAD_SUCCESS (R.string.msg_crt_upload_success), + MSG_CRT_SUCCESS (R.string.msg_crt_success), + + MSG_ACC_SAVED (R.string.api_settings_save) + + ; + + 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 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 OperationResult.LogEntryParcel(level, type, indent, parameters)); + } + + public void add(LogLevel level, LogType type, int indent) { + mParcels.add(new OperationResult.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(); + } + + public LogEntryParcel getLast() { + if (mParcels.isEmpty()) { + return null; + } + return mParcels.get(mParcels.size() -1); + } + + @Override + public Iterator iterator() { + return mParcels.iterator(); + } + } + +} 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 deleted file mode 100644 index 56f5248cb..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResultParcel.java +++ /dev/null @@ -1,602 +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.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), - MSG_KC_UID_WARN_ENCODING (R.string.msg_kc_uid_warn_encoding), - - - // 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), - - // decryptverify - MSG_DC_ASKIP_NO_KEY (R.string.msg_dc_askip_no_key), - MSG_DC_ASKIP_NOT_ALLOWED (R.string.msg_dc_askip_not_allowed), - MSG_DC_ASYM (R.string.msg_dc_asym), - MSG_DC_CLEAR_DATA (R.string.msg_dc_clear_data), - MSG_DC_CLEAR_DECOMPRESS (R.string.msg_dc_clear_decompress), - MSG_DC_CLEAR_META_FILE (R.string.msg_dc_clear_meta_file), - MSG_DC_CLEAR_META_MIME (R.string.msg_dc_clear_meta_mime), - MSG_DC_CLEAR_META_SIZE (R.string.msg_dc_clear_meta_size), - MSG_DC_CLEAR_META_TIME (R.string.msg_dc_clear_meta_time), - MSG_DC_CLEAR (R.string.msg_dc_clear), - MSG_DC_CLEAR_SIGNATURE_BAD (R.string.msg_dc_clear_signature_bad), - MSG_DC_CLEAR_SIGNATURE_CHECK (R.string.msg_dc_clear_signature_check), - MSG_DC_CLEAR_SIGNATURE_OK (R.string.msg_dc_clear_signature_ok), - MSG_DC_CLEAR_SIGNATURE (R.string.msg_dc_clear_signature), - MSG_DC_ERROR_BAD_PASSPHRASE (R.string.msg_dc_error_bad_passphrase), - MSG_DC_ERROR_EXTRACT_KEY (R.string.msg_dc_error_extract_key), - MSG_DC_ERROR_INTEGRITY_CHECK (R.string.msg_dc_error_integrity_check), - MSG_DC_ERROR_INVALID_SIGLIST(R.string.msg_dc_error_invalid_siglist), - MSG_DC_ERROR_IO (R.string.msg_dc_error_io), - MSG_DC_ERROR_NO_DATA (R.string.msg_dc_error_no_data), - MSG_DC_ERROR_NO_KEY (R.string.msg_dc_error_no_key), - MSG_DC_ERROR_PGP_EXCEPTION (R.string.msg_dc_error_pgp_exception), - MSG_DC_INTEGRITY_CHECK_OK (R.string.msg_dc_integrity_check_ok), - MSG_DC_OK_META_ONLY (R.string.msg_dc_ok_meta_only), - MSG_DC_OK (R.string.msg_dc_ok), - MSG_DC_PASS_CACHED (R.string.msg_dc_pass_cached), - MSG_DC_PENDING_NFC (R.string.msg_dc_pending_nfc), - MSG_DC_PENDING_PASSPHRASE (R.string.msg_dc_pending_passphrase), - MSG_DC_PREP_STREAMS (R.string.msg_dc_prep_streams), - MSG_DC (R.string.msg_dc), - MSG_DC_SYM (R.string.msg_dc_sym), - MSG_DC_SYM_SKIP (R.string.msg_dc_sym_skip), - MSG_DC_TRAIL_ASYM (R.string.msg_dc_trail_asym), - MSG_DC_TRAIL_SYM (R.string.msg_dc_trail_sym), - MSG_DC_TRAIL_UNKNOWN (R.string.msg_dc_trail_unknown), - MSG_DC_UNLOCKING (R.string.msg_dc_unlocking), - - // signencrypt - MSG_SE_ASYMMETRIC (R.string.msg_se_asymmetric), - MSG_SE_CLEARSIGN_ONLY (R.string.msg_se_clearsign_only), - MSG_SE_COMPRESSING (R.string.msg_se_compressing), - MSG_SE_ENCRYPTING (R.string.msg_se_encrypting), - MSG_SE_ERROR_BAD_PASSPHRASE (R.string.msg_se_error_bad_passphrase), - MSG_SE_ERROR_IO (R.string.msg_se_error_io), - MSG_SE_ERROR_SIGN_KEY(R.string.msg_se_error_sign_key), - MSG_SE_ERROR_KEY_SIGN (R.string.msg_se_error_key_sign), - MSG_SE_ERROR_NFC (R.string.msg_se_error_nfc), - MSG_SE_ERROR_NO_PASSPHRASE (R.string.msg_se_error_no_passphrase), - MSG_SE_ERROR_PGP (R.string.msg_se_error_pgp), - MSG_SE_ERROR_SIG (R.string.msg_se_error_sig), - MSG_SE_ERROR_UNLOCK (R.string.msg_se_error_unlock), - MSG_SE_KEY_OK (R.string.msg_se_key_ok), - MSG_SE_KEY_UNKNOWN (R.string.msg_se_key_unknown), - MSG_SE_KEY_WARN (R.string.msg_se_key_warn), - MSG_SE_OK (R.string.msg_se_ok), - MSG_SE_PENDING_NFC (R.string.msg_se_pending_nfc), - MSG_SE (R.string.msg_se), - MSG_SE_SIGNING (R.string.msg_se_signing), - MSG_SE_SIGCRYPTING (R.string.msg_se_sigcrypting), - MSG_SE_SYMMETRIC (R.string.msg_se_symmetric), - - ; - - 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(); - } - - public LogEntryParcel getLast() { - if (mParcels.isEmpty()) { - return null; - } - return mParcels.get(mParcels.size() -1); - } - - @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 index 0edb9c617..e229a5c6a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SaveKeyringResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SaveKeyringResult.java @@ -23,7 +23,7 @@ import android.os.Parcel; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; -public class SaveKeyringResult extends OperationResultParcel { +public class SaveKeyringResult extends OperationResult { public final long mRingMasterKeyId; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java index 100a7c675..9d492e545 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java @@ -19,12 +19,9 @@ package org.sufficientlysecure.keychain.service.results; import android.os.Parcel; -import org.openintents.openpgp.OpenPgpMetadata; -import org.openintents.openpgp.OpenPgpSignatureResult; - import java.util.Date; -public class SignEncryptResult extends OperationResultParcel { +public class SignEncryptResult extends OperationResult { // the fourth bit indicates a "data pending" result! (it's also a form of non-success) public static final int RESULT_PENDING = RESULT_ERROR +8; 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 index 5022c46a7..38b2e4bc3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SingletonResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SingletonResult.java @@ -27,7 +27,7 @@ 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 { +public class SingletonResult extends OperationResult { /** Construct from a parcel - trivial because we have no extra data. */ public SingletonResult(Parcel source) { 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 fb2184362..81fa98e7a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -54,8 +54,11 @@ 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.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResult; import org.sufficientlysecure.keychain.service.PassphraseCacheService; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.service.results.SingletonResult; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner; @@ -327,12 +330,10 @@ public class CertifyKeyFragment extends LoaderFragment if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { -// Notify.showNotify(CertifyKeyActivity.this, R.string.key_certify_success, -// Notify.Style.INFO); - - OperationResultParcel result = new OperationResultParcel(OperationResultParcel.RESULT_OK, null); + SingletonResult result = new SingletonResult( + SingletonResult.RESULT_OK, LogLevel.OK, LogType.MSG_CRT_SUCCESS); Intent intent = new Intent(); - intent.putExtra(OperationResultParcel.EXTRA_RESULT, result); + intent.putExtra(SingletonResult.EXTRA_RESULT, result); mActivity.setResult(CertifyKeyActivity.RESULT_OK, intent); // check if we need to send the key to the server or not @@ -383,12 +384,10 @@ public class CertifyKeyFragment extends LoaderFragment super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { - //Notify.showNotify(CertifyKeyActivity.this, R.string.key_send_success, - //Notify.Style.INFO); - - OperationResultParcel result = new OperationResultParcel(OperationResultParcel.RESULT_OK, null); + SingletonResult result = new SingletonResult(SingletonResult.RESULT_OK, + LogLevel.OK, LogType.MSG_CRT_UPLOAD_SUCCESS); Intent intent = new Intent(); - intent.putExtra(OperationResultParcel.EXTRA_RESULT, result); + intent.putExtra(SingletonResult.EXTRA_RESULT, result); mActivity.setResult(CertifyKeyActivity.RESULT_OK, intent); mActivity.finish(); } 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 a645f18a9..dc9fa78e5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -39,7 +39,7 @@ 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.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; @@ -141,7 +141,7 @@ public class CreateKeyFinalFragment extends Fragment { return; } final SaveKeyringResult result = - returnData.getParcelable(OperationResultParcel.EXTRA_RESULT); + returnData.getParcelable(OperationResult.EXTRA_RESULT); if (result == null) { Log.e(Constants.TAG, "result == null"); return; @@ -152,7 +152,7 @@ public class CreateKeyFinalFragment extends Fragment { uploadKey(result); } else { Intent data = new Intent(); - data.putExtra(OperationResultParcel.EXTRA_RESULT, result); + data.putExtra(OperationResult.EXTRA_RESULT, result); getActivity().setResult(Activity.RESULT_OK, data); getActivity().finish(); } @@ -223,7 +223,7 @@ public class CreateKeyFinalFragment extends Fragment { //Notify.Style.INFO); Intent data = new Intent(); - data.putExtra(OperationResultParcel.EXTRA_RESULT, saveKeyResult); + data.putExtra(OperationResult.EXTRA_RESULT, saveKeyResult); getActivity().setResult(Activity.RESULT_OK, data); getActivity().finish(); } 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 8bde3f295..0911a98ae 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -48,9 +48,9 @@ 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.results.OperationResultParcel; -import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogLevel; -import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogType; +import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; import org.sufficientlysecure.keychain.service.results.SingletonResult; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -541,8 +541,8 @@ public class EditKeyFragment extends LoaderFragment implements if (returnData == null) { return; } - final OperationResultParcel result = - returnData.getParcelable(OperationResultParcel.EXTRA_RESULT); + final OperationResult result = + returnData.getParcelable(OperationResult.EXTRA_RESULT); if (result == null) { return; } @@ -555,7 +555,7 @@ public class EditKeyFragment extends LoaderFragment implements // if good -> finish, return result to showkey and display there! Intent intent = new Intent(); - intent.putExtra(OperationResultParcel.EXTRA_RESULT, result); + intent.putExtra(OperationResult.EXTRA_RESULT, result); getActivity().setResult(EditKeyActivity.RESULT_OK, intent); getActivity().finish(); @@ -590,7 +590,7 @@ public class EditKeyFragment extends LoaderFragment implements // Prepare an intent with an EXTRA_RESULT Intent intent = new Intent(); - intent.putExtra(OperationResultParcel.EXTRA_RESULT, + intent.putExtra(OperationResult.EXTRA_RESULT, new SingletonResult(SingletonResult.RESULT_ERROR, LogLevel.ERROR, reason)); // Finish with result 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 732e59e32..d644dabc2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -46,7 +46,7 @@ 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.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResult; import org.sufficientlysecure.keychain.service.results.ImportKeyResult; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout; @@ -459,7 +459,7 @@ public class ImportKeysActivity extends ActionBarActivity { return; } final ImportKeyResult result = - returnData.getParcelable(OperationResultParcel.EXTRA_RESULT); + returnData.getParcelable(OperationResult.EXTRA_RESULT); if (result == null) { Log.e(Constants.TAG, "result == null"); return; 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 1b3bb06c3..4c94d25be 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java @@ -34,7 +34,7 @@ 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.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResult; import org.sufficientlysecure.keychain.service.results.ConsolidateResult; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Notify; @@ -166,7 +166,7 @@ public class KeyListActivity extends DrawerActivity { return; } final ConsolidateResult result = - returnData.getParcelable(OperationResultParcel.EXTRA_RESULT); + returnData.getParcelable(OperationResult.EXTRA_RESULT); if (result == null) { return; } @@ -201,8 +201,8 @@ public class KeyListActivity extends DrawerActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // if a result has been returned, display a notify - if (data != null && data.hasExtra(OperationResultParcel.EXTRA_RESULT)) { - OperationResultParcel result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT); + if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) { + OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT); result.createNotify(this).show(); } else { super.onActivityResult(requestCode, resultCode, data); 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 ddc57b8aa..fcd9324c9 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.results.OperationResultParcel; -import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogEntryParcel; -import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogLevel; +import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogEntryParcel; +import org.sufficientlysecure.keychain.service.results.OperationResult.LogLevel; import org.sufficientlysecure.keychain.util.Log; import java.util.HashMap; @@ -50,7 +50,7 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener LogAdapter mAdapter; LogLevel mLevel = LogLevel.DEBUG; - OperationResultParcel mResult; + OperationResult mResult; GestureDetector mDetector; @@ -66,7 +66,7 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener return; } - mResult = intent.getParcelableExtra(EXTRA_RESULT); + mResult = intent.getParcelableExtra(EXTRA_RESULT); if (mResult == null) { getActivity().finish(); return; @@ -135,7 +135,7 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener private LayoutInflater mInflater; private int dipFactor; - public LogAdapter(Context context, OperationResultParcel.OperationLog log, LogLevel level) { + public LogAdapter(Context context, OperationResult.OperationLog log, LogLevel level) { super(context, R.layout.log_display_item); mInflater = LayoutInflater.from(getContext()); dipFactor = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 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 ef0b95bcc..805fc8753 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.results.OperationResultParcel; +import org.sufficientlysecure.keychain.service.results.OperationResult; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout.TabColorizer; @@ -322,8 +322,8 @@ public class ViewKeyActivity extends ActionBarActivity implements @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // if a result has been returned, display a notify - if (data != null && data.hasExtra(OperationResultParcel.EXTRA_RESULT)) { - OperationResultParcel result = data.getParcelableExtra(OperationResultParcel.EXTRA_RESULT); + if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) { + OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT); result.createNotify(this).show(); } else { super.onActivityResult(requestCode, resultCode, data); diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index e1fcf4a0b..69bcca5a1 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -214,8 +214,6 @@ "%d bad secret keys ignored. Perhaps you exported with the option\n --export-secret-subkeys\nMake sure you export with\n --export-secret-keys\ninstead."" - "Successfully uploaded key to server" - "Successfully certified identities" "This list is empty!" "Successfully sent key with NFC Beam!" "Key has been copied to the clipboard!" @@ -827,6 +825,11 @@ "Starting sign and/or encrypt operation" "Preparing symmetric encryption" + "Successfully uploaded key to server" + "Successfully certified identities" + + "Account saved" + "Click to clear cached passphrases" "OpenKeychain has cached %d passphrases" -- cgit v1.2.3 From 1c32d1df8801968ea6423ee4f1a9160e0c4ff0c3 Mon Sep 17 00:00:00 2001 From: Tim Bray Date: Fri, 12 Sep 2014 08:34:51 -0700 Subject: Add cloud search tab, lose Keybase/Keyserver tabs, re-organize prefs --- .../org/sufficientlysecure/keychain/Constants.java | 2 + .../keychain/helper/EmailKeyHelper.java | 6 +- .../keychain/helper/Preferences.java | 32 ++++ .../keychain/keyimport/CloudSearch.java | 90 ++++++++++ .../keychain/keyimport/ImportKeysList.java | 84 +++++++++ .../keychain/keyimport/ImportKeysListEntry.java | 7 + .../keychain/keyimport/Keyserver.java | 16 +- .../keychain/ui/CreateKeyFinalFragment.java | 2 +- .../keychain/ui/ImportKeysActivity.java | 89 +++------- .../keychain/ui/ImportKeysCloudFragment.java | 160 +++++++++++++++++ .../keychain/ui/ImportKeysKeybaseFragment.java | 122 ------------- .../keychain/ui/ImportKeysListFragment.java | 66 ++----- .../keychain/ui/ImportKeysServerFragment.java | 197 --------------------- .../keychain/ui/PreferencesActivity.java | 88 ++++++--- .../keychain/ui/PreferencesKeyServerActivity.java | 34 ++++ .../ui/adapter/ImportKeysListCloudLoader.java | 122 +++++++++++++ .../ui/adapter/ImportKeysListKeybaseLoader.java | 103 ----------- .../ui/adapter/ImportKeysListServerLoader.java | 125 ------------- .../src/main/res/drawable/button_rounded_blue.xml | 37 ++++ .../main/res/layout/import_keys_cloud_fragment.xml | 57 ++++++ .../res/layout/import_keys_keybase_fragment.xml | 32 ---- .../src/main/res/layout/import_keys_list_entry.xml | 2 + .../res/layout/import_keys_server_fragment.xml | 76 -------- .../src/main/res/layout/key_server_preference.xml | 25 ++- OpenKeychain/src/main/res/values/strings.xml | 8 +- OpenKeychain/src/main/res/xml/adv_preferences.xml | 13 +- .../src/main/res/xml/cloud_search_prefs.xml | 20 +++ OpenKeychain/src/main/res/xml/gen_preferences.xml | 15 -- .../src/main/res/xml/preference_headers.xml | 4 +- 29 files changed, 804 insertions(+), 830 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysKeybaseFragment.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java create mode 100644 OpenKeychain/src/main/res/drawable/button_rounded_blue.xml create mode 100644 OpenKeychain/src/main/res/layout/import_keys_cloud_fragment.xml delete mode 100644 OpenKeychain/src/main/res/layout/import_keys_keybase_fragment.xml delete mode 100644 OpenKeychain/src/main/res/layout/import_keys_server_fragment.xml create mode 100644 OpenKeychain/src/main/res/xml/cloud_search_prefs.xml delete mode 100644 OpenKeychain/src/main/res/xml/gen_preferences.xml (limited to 'OpenKeychain/src') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java index db78a36c1..8ee769fdf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/Constants.java @@ -81,6 +81,8 @@ public final class Constants { public static final String CACHED_CONSOLIDATE = "cachedConsolidate"; public static final String CACHED_CONSOLIDATE_SECRETS = "cachedConsolidateSecrets"; public static final String CACHED_CONSOLIDATE_PUBLICS = "cachedConsolidatePublics"; + public static final String SEARCH_KEYSERVER = "search_keyserver_pref"; + public static final String SEARCH_KEYBASE = "search_keybase_pref"; public static final String USE_DEFAULT_YUBIKEY_PIN = "useDefaultYubikeyPin"; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java index d8efdc480..91325ca1f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/EmailKeyHelper.java @@ -61,9 +61,9 @@ public class EmailKeyHelper { if (keys.isEmpty()) { // Most users don't have the SRV record, so ask a default server as well - String[] servers = Preferences.getPreferences(context).getKeyServers(); - if (servers != null && servers.length != 0) { - HkpKeyserver hkp = new HkpKeyserver(servers[0]); + String server = Preferences.getPreferences(context).getPreferredKeyserver(); + if (server != null) { + HkpKeyserver hkp = new HkpKeyserver(server); keys.addAll(getEmailKeys(mail, hkp)); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java index aa4621893..bf09997a0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/helper/Preferences.java @@ -220,6 +220,9 @@ public class Preferences { } return servers.toArray(chunks); } + public String getPreferredKeyserver() { + return getKeyServers()[0]; + } public void setKeyServers(String[] value) { SharedPreferences.Editor editor = mSharedPreferences.edit(); @@ -248,6 +251,35 @@ public class Preferences { return mSharedPreferences.getBoolean(Constants.Pref.WRITE_VERSION_HEADER, false); } + public void setSearchKeyserver(boolean searchKeyserver) { + SharedPreferences.Editor editor = mSharedPreferences.edit(); + editor.putBoolean(Pref.SEARCH_KEYSERVER, searchKeyserver); + editor.commit(); + } + public void setSearchKeybase(boolean searchKeybase) { + SharedPreferences.Editor editor = mSharedPreferences.edit(); + editor.putBoolean(Pref.SEARCH_KEYBASE, searchKeybase); + editor.commit(); + } + + public CloudSearchPrefs getCloudSearchPrefs() { + return new CloudSearchPrefs(mSharedPreferences.getBoolean(Pref.SEARCH_KEYSERVER, true), + mSharedPreferences.getBoolean(Pref.SEARCH_KEYBASE, true), + getPreferredKeyserver()); + } + + public static class CloudSearchPrefs { + public final boolean searchKeyserver; + public final boolean searchKeybase; + public final String keyserver; + + public CloudSearchPrefs(boolean searchKeyserver, boolean searchKeybase, String keyserver) { + this.searchKeyserver = searchKeyserver; + this.searchKeybase = searchKeybase; + this.keyserver = keyserver; + } + } + public void updatePreferences() { if (mSharedPreferences.getInt(Constants.Pref.PREF_DEFAULT_VERSION, 0) != Constants.Defaults.PREF_VERSION) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java new file mode 100644 index 000000000..27d826c59 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2014 Tim Bray + * + * 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.keyimport; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.helper.Preferences; +import org.sufficientlysecure.keychain.util.Log; + +import java.util.ArrayList; +import java.util.Vector; + +/** + * Search two or more types of server for online keys. + */ +public class CloudSearch { + + private final static long SECONDS = 1000; + + public static ArrayList search(final String query, Preferences.CloudSearchPrefs cloudPrefs) + throws Keyserver.CloudSearchFailureException { + final ArrayList servers = new ArrayList(); + + // it's a Vector for sync, multiple threads might report problems + final Vector problems = new Vector(); + + if (cloudPrefs.searchKeyserver) { + servers.add(new HkpKeyserver(cloudPrefs.keyserver)); + } + if (cloudPrefs.searchKeybase) { + servers.add(new KeybaseKeyserver()); + } + final ImportKeysList results = new ImportKeysList(servers.size()); + + for (final Keyserver keyserver : servers) { + Runnable r = new Runnable() { + @Override + public void run() { + try { + results.addAll(keyserver.search(query)); + } catch (Keyserver.CloudSearchFailureException e) { + problems.add(e); + } + results.finishedAdding(); // notifies if all searchers done + } + }; + new Thread(r).start(); + } + + // wait for either all the searches to come back, or 10 seconds + synchronized(results) { + try { + results.wait(10 * SECONDS); + } catch (InterruptedException e) { + } + } + + if (results.outstandingSuppliers() > 0) { + String message = "Launched " + servers.size() + " cloud searchers, but" + + results.outstandingSuppliers() + "failed to complete."; + problems.add(new Keyserver.QueryFailedException(message)); + } + + if (!problems.isEmpty()) { + for (Keyserver.CloudSearchFailureException e : problems) { + Log.d(Constants.TAG, "Cloud search exception: " + e.getLocalizedMessage()); + } + + // only throw exception if we didn’t get any results + if (results.isEmpty()) { + throw problems.get(0); + } + } + + return results; + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java new file mode 100644 index 000000000..15de8cb8f --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysList.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2014 Tim Bray + * + * 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.keyimport; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * Just an ArrayList, only with a synchronized dupe-merging add/addAll, and a sign-off method + */ +public class ImportKeysList extends ArrayList { + + private int mSupplierCount; + + public ImportKeysList(int supplierCount) { + mSupplierCount = supplierCount; + } + + @Override + public boolean add(ImportKeysListEntry toAdd) { + addOrMerge(toAdd); + return true; // that’s what the ArrayList#add contract says + } + + @Override + public boolean addAll(Collection addThese) { + boolean modified = false; + for (ImportKeysListEntry toAdd : addThese) { + modified = addOrMerge(toAdd) || modified; + } + return modified; + } + + // NOTE: side-effects + // NOTE: synchronized + private synchronized boolean addOrMerge(ImportKeysListEntry toAdd) { + for (ImportKeysListEntry existing : this) { + if (toAdd.hasSameKeyAs(existing)) { + return mergeIDs(toAdd, existing); + } + } + return super.add(toAdd); + } + + // being a little anal about the ArrayList#addAll contract here + private boolean mergeIDs(ImportKeysListEntry incoming, ImportKeysListEntry existing) { + boolean modified = false; + ArrayList incomingIDs = incoming.getUserIds(); + ArrayList existingIDs = existing.getUserIds(); + for (String incomingID : incomingIDs) { + if (!existingIDs.contains(incomingID)) { + existingIDs.add(incomingID); + modified = true; + } + } + return modified; + } + + // NOTE: synchronized + public synchronized void finishedAdding() { + mSupplierCount--; + if (mSupplierCount == 0) { + this.notify(); + } + } + + public int outstandingSuppliers() { + return mSupplierCount; + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java index da70f1505..c10cd2e70 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/ImportKeysListEntry.java @@ -107,6 +107,13 @@ public class ImportKeysListEntry implements Serializable, Parcelable { return super.hashCode(); } + public boolean hasSameKeyAs(Object o) { + if (mFingerprintHex == null || o == null || !(o instanceof ImportKeysListEntry)) { + return false; + } + return mFingerprintHex.equals(((ImportKeysListEntry) o).mFingerprintHex); + } + public String getKeyIdHex() { return mKeyIdHex; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java index b726529f8..5e4bd0b70 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java @@ -24,7 +24,19 @@ import java.io.InputStream; import java.util.List; public abstract class Keyserver { - public static class QueryFailedException extends Exception { + + public static class CloudSearchFailureException extends Exception { + private static final long serialVersionUID = 2703768928624654515L; + + public CloudSearchFailureException(String message) { + super(message); + } + public CloudSearchFailureException() { + super(); + } + } + + public static class QueryFailedException extends CloudSearchFailureException { private static final long serialVersionUID = 2703768928624654512L; public QueryFailedException(String message) { @@ -32,7 +44,7 @@ public abstract class Keyserver { } } - public static class QueryNeedsRepairException extends Exception { + public static class QueryNeedsRepairException extends CloudSearchFailureException { private static final long serialVersionUID = 2693768928624654512L; } 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 dc9fa78e5..c6edc47a1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -204,7 +204,7 @@ public class CreateKeyFinalFragment extends Fragment { Bundle data = new Bundle(); // upload to favorite keyserver - String keyserver = Preferences.getPreferences(getActivity()).getKeyServers()[0]; + String keyserver = Preferences.getPreferences(getActivity()).getPreferredKeyserver(); data.putString(KeychainIntentService.UPLOAD_KEY_SERVER, keyserver); intent.putExtra(KeychainIntentService.EXTRA_DATA, data); 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 d644dabc2..518a8046a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -68,8 +68,6 @@ public class ImportKeysActivity extends ActionBarActivity { + "IMPORT_KEY_FROM_KEY_SERVER_AND_RETURN"; public static final String ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN = Constants.INTENT_PREFIX + "IMPORT_KEY_FROM_FILE_AND_RETURN"; - public static final String ACTION_IMPORT_KEY_FROM_KEYBASE = Constants.INTENT_PREFIX - + "IMPORT_KEY_FROM_KEYBASE"; // Actions for internal use only: public static final String ACTION_IMPORT_KEY_FROM_FILE = Constants.INTENT_PREFIX @@ -101,12 +99,11 @@ public class ImportKeysActivity extends ActionBarActivity { public static final int VIEW_PAGER_HEIGHT = 64; // dp private static final int ALL_TABS = -1; - private static final int TAB_KEYSERVER = 0; + private static final int TAB_CLOUD = 0; private static final int TAB_QR_CODE = 1; private static final int TAB_FILE = 2; - private static final int TAB_KEYBASE = 3; - private int mSwitchToTab = TAB_KEYSERVER; + private int mSwitchToTab = TAB_CLOUD; @Override protected void onCreate(Bundle savedInstanceState) { @@ -193,8 +190,8 @@ public class ImportKeysActivity extends ActionBarActivity { if (query != null && query.length() > 0) { // display keyserver fragment with query serverBundle = new Bundle(); - serverBundle.putString(ImportKeysServerFragment.ARG_QUERY, query); - mSwitchToTab = TAB_KEYSERVER; + serverBundle.putString(ImportKeysCloudFragment.ARG_QUERY, query); + mSwitchToTab = TAB_CLOUD; // action: search immediately startListFragment(savedInstanceState, null, null, query); @@ -214,11 +211,11 @@ public class ImportKeysActivity extends ActionBarActivity { // display keyserver fragment with query serverBundle = new Bundle(); - serverBundle.putString(ImportKeysServerFragment.ARG_QUERY, query); - serverBundle.putBoolean(ImportKeysServerFragment.ARG_DISABLE_QUERY_EDIT, true); + serverBundle.putString(ImportKeysCloudFragment.ARG_QUERY, query); + serverBundle.putBoolean(ImportKeysCloudFragment.ARG_DISABLE_QUERY_EDIT, true); // display server tab only - showTabOnly = TAB_KEYSERVER; - mSwitchToTab = TAB_KEYSERVER; + showTabOnly = TAB_CLOUD; + mSwitchToTab = TAB_CLOUD; // action: search immediately startListFragment(savedInstanceState, null, null, query); @@ -257,12 +254,6 @@ public class ImportKeysActivity extends ActionBarActivity { // NOTE: this only displays the appropriate fragment, no actions are taken mSwitchToTab = TAB_QR_CODE; - // no immediate actions! - startListFragment(savedInstanceState, null, null, null); - } else if (ACTION_IMPORT_KEY_FROM_KEYBASE.equals(action)) { - // NOTE: this only displays the appropriate fragment, no actions are taken - mSwitchToTab = TAB_KEYBASE; - // no immediate actions! startListFragment(savedInstanceState, null, null, null); } else { @@ -299,19 +290,17 @@ public class ImportKeysActivity extends ActionBarActivity { switch (showTabOnly) { case ALL_TABS: - // show all tabs - mTabsAdapter.addTab(ImportKeysServerFragment.class, - serverBundle, getString(R.string.import_tab_keyserver)); + // show default tabs + mTabsAdapter.addTab(ImportKeysCloudFragment.class, + serverBundle, getString(R.string.import_tab_cloud)); mTabsAdapter.addTab(ImportKeysQrCodeFragment.class, null, getString(R.string.import_tab_qr_code)); mTabsAdapter.addTab(ImportKeysFileFragment.class, null, getString(R.string.import_tab_direct)); - mTabsAdapter.addTab(ImportKeysKeybaseFragment.class, - null, getString(R.string.import_tab_keybase)); break; - case TAB_KEYSERVER: - mTabsAdapter.addTab(ImportKeysServerFragment.class, - serverBundle, getString(R.string.import_tab_keyserver)); + case TAB_CLOUD: + mTabsAdapter.addTab(ImportKeysCloudFragment.class, + serverBundle, getString(R.string.import_tab_cloud)); break; case TAB_QR_CODE: mTabsAdapter.addTab(ImportKeysQrCodeFragment.class, @@ -321,10 +310,6 @@ public class ImportKeysActivity extends ActionBarActivity { mTabsAdapter.addTab(ImportKeysFileFragment.class, null, getString(R.string.import_tab_direct)); break; - case TAB_KEYBASE: - mTabsAdapter.addTab(ImportKeysKeybaseFragment.class, - null, getString(R.string.import_tab_keybase)); - break; } // update layout after operations @@ -380,18 +365,17 @@ public class ImportKeysActivity extends ActionBarActivity { if (mViewPager.getAdapter() != null) mViewPager.setAdapter(null); mViewPager.setAdapter(mTabsAdapter); - mViewPager.setCurrentItem(TAB_KEYSERVER); + mViewPager.setCurrentItem(TAB_CLOUD); - ImportKeysServerFragment f = (ImportKeysServerFragment) - getActiveFragment(mViewPager, TAB_KEYSERVER); + ImportKeysCloudFragment f = (ImportKeysCloudFragment) + getActiveFragment(mViewPager, TAB_CLOUD); - // ask favorite keyserver - String keyserver = Preferences.getPreferences(ImportKeysActivity.this).getKeyServers()[0]; + // search config + Preferences prefs = Preferences.getPreferences(ImportKeysActivity.this); + Preferences.CloudSearchPrefs cloudPrefs = new Preferences.CloudSearchPrefs(true, true, prefs.getPreferredKeyserver()); - // set fields of ImportKeysServerFragment - f.setQueryAndKeyserver(query, keyserver); // search directly - loadCallback(new ImportKeysListFragment.KeyserverLoaderState(query, keyserver)); + loadCallback(new ImportKeysListFragment.CloudLoaderState(query, cloudPrefs)); } // http://stackoverflow.com/a/9293207 @@ -522,8 +506,8 @@ public class ImportKeysActivity extends ActionBarActivity { Log.e(Constants.TAG, "Problem writing cache file", e); Notify.showNotify(this, "Problem writing cache file!", Notify.Style.ERROR); } - } else if (ls instanceof ImportKeysListFragment.KeyserverLoaderState) { - ImportKeysListFragment.KeyserverLoaderState sls = (ImportKeysListFragment.KeyserverLoaderState) ls; + } else if (ls instanceof ImportKeysListFragment.CloudLoaderState) { + ImportKeysListFragment.CloudLoaderState sls = (ImportKeysListFragment.CloudLoaderState) ls; // Send all information needed to service to query keys in other thread Intent intent = new Intent(this, KeychainIntentService.class); @@ -533,31 +517,7 @@ public class ImportKeysActivity extends ActionBarActivity { // fill values for this action Bundle data = new Bundle(); - data.putString(KeychainIntentService.DOWNLOAD_KEY_SERVER, sls.keyserver); - - // get selected key entries - ArrayList selectedEntries = mListFragment.getSelectedEntries(); - data.putParcelableArrayList(KeychainIntentService.DOWNLOAD_KEY_LIST, selectedEntries); - - intent.putExtra(KeychainIntentService.EXTRA_DATA, data); - - // Create a new Messenger for the communication back - Messenger messenger = new Messenger(saveHandler); - intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); - - // show progress dialog - saveHandler.showProgressDialog(this); - - // start service with intent - startService(intent); - } else if (ls instanceof ImportKeysListFragment.KeybaseLoaderState) { - // Send all information needed to service to query keys in other thread - Intent intent = new Intent(this, KeychainIntentService.class); - - intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYBASE_KEYS); - - // fill values for this action - Bundle data = new Bundle(); + data.putString(KeychainIntentService.DOWNLOAD_KEY_SERVER, sls.mCloudPrefs.keyserver); // get selected key entries ArrayList selectedEntries = mListFragment.getSelectedEntries(); @@ -574,7 +534,6 @@ public class ImportKeysActivity extends ActionBarActivity { // start service with intent startService(intent); - } else { Notify.showNotify(this, R.string.error_nothing_import, Notify.Style.ERROR); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java new file mode 100644 index 000000000..6b4b833c6 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysCloudFragment.java @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2013-2014 Dominik Schürmann + * + * 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.ui; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; +import android.widget.TextView; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.helper.ContactHelper; +import org.sufficientlysecure.keychain.helper.Preferences; +import org.sufficientlysecure.keychain.util.Log; + +import java.util.List; + +public class ImportKeysCloudFragment extends Fragment { + public static final String ARG_QUERY = "query"; + public static final String ARG_DISABLE_QUERY_EDIT = "disable_query_edit"; + + private ImportKeysActivity mImportActivity; + + private View mSearchButton; + private AutoCompleteTextView mQueryEditText; + private View mConfigButton; + private ArrayAdapter mServerAdapter; + + /** + * Creates new instance of this fragment + */ + public static ImportKeysCloudFragment newInstance(String query, String keyserver, boolean doKeyserver, boolean doKeybase) { + ImportKeysCloudFragment frag = new ImportKeysCloudFragment(); + + Bundle args = new Bundle(); + args.putString(ARG_QUERY, query); + + frag.setArguments(args); + + return frag; + } + + /** + * Inflate the layout for this fragment + */ + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.import_keys_cloud_fragment, container, false); + + mSearchButton = view.findViewById(R.id.cloud_import_server_search); + mQueryEditText = (AutoCompleteTextView) view.findViewById(R.id.cloud_import_server_query); + mConfigButton = view.findViewById(R.id.cloud_import_server_config_button); + + List namesAndEmails = ContactHelper.getContactNames(getActivity()); + namesAndEmails.addAll(ContactHelper.getContactMails(getActivity())); + mQueryEditText.setThreshold(3); + mQueryEditText.setAdapter( + new ArrayAdapter + (getActivity(), android.R.layout.simple_spinner_dropdown_item, + namesAndEmails + ) + ); + + mSearchButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + search(mQueryEditText.getText().toString()); + + // close keyboard after pressing search + InputMethodManager imm = + (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(mQueryEditText.getWindowToken(), 0); + } + }); + + mQueryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == EditorInfo.IME_ACTION_SEARCH) { + search(mQueryEditText.getText().toString()); + + // Don't return true to let the keyboard close itself after pressing search + return false; + } + return false; + } + }); + + mConfigButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent i = new Intent(mImportActivity, PreferencesActivity.class); + // GRR, for some reason I can’t set the Action or I get an incomprehensible + // exception about “modern two-pane layouts” + // i.setAction(PreferencesActivity.ACTION_PREFS_CLOUD); + startActivity(i); + } + }); + + return view; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + // set displayed values + if (getArguments() != null) { + if (getArguments().containsKey(ARG_QUERY)) { + String query = getArguments().getString(ARG_QUERY); + mQueryEditText.setText(query, TextView.BufferType.EDITABLE); + + Log.d(Constants.TAG, "query: " + query); + } + + if (getArguments().getBoolean(ARG_DISABLE_QUERY_EDIT, false)) { + mQueryEditText.setEnabled(false); + } + } + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + + mImportActivity = (ImportKeysActivity) activity; + } + + private void search(String query) { + Preferences prefs = Preferences.getPreferences(getActivity()); + mImportActivity.loadCallback(new ImportKeysListFragment.CloudLoaderState(query, prefs.getCloudSearchPrefs())); + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysKeybaseFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysKeybaseFragment.java deleted file mode 100644 index 3a82bdc32..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysKeybaseFragment.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * 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.ui; - -import android.app.Activity; -import android.content.Context; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.InputMethodManager; -import android.widget.EditText; -import android.widget.TextView; - -import org.sufficientlysecure.keychain.R; - -/** - * Import public keys from the Keybase.io directory. First cut: just raw search. - * TODO: make a pick list of the people you’re following on keybase - */ -public class ImportKeysKeybaseFragment extends Fragment { - - private ImportKeysActivity mImportActivity; - private View mSearchButton; - private EditText mQueryEditText; - - public static final String ARG_QUERY = "query"; - - /** - * Creates new instance of this fragment - */ - public static ImportKeysKeybaseFragment newInstance() { - ImportKeysKeybaseFragment frag = new ImportKeysKeybaseFragment(); - - Bundle args = new Bundle(); - frag.setArguments(args); - - return frag; - } - - /** - * Inflate the layout for this fragment - */ - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.import_keys_keybase_fragment, container, false); - - mQueryEditText = (EditText) view.findViewById(R.id.import_keybase_query); - - mSearchButton = view.findViewById(R.id.import_keybase_search); - mSearchButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - String query = mQueryEditText.getText().toString(); - search(query); - - // close keyboard after pressing search - InputMethodManager imm = - (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(mQueryEditText.getWindowToken(), 0); - } - }); - - mQueryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - if (actionId == EditorInfo.IME_ACTION_SEARCH) { - String query = mQueryEditText.getText().toString(); - search(query); - - // Don't return true to let the keyboard close itself after pressing search - return false; - } - return false; - } - }); - - return view; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - // set displayed values - if (getArguments() != null) { - if (getArguments().containsKey(ARG_QUERY)) { - String query = getArguments().getString(ARG_QUERY); - mQueryEditText.setText(query, TextView.BufferType.EDITABLE); - } - } - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - - mImportActivity = (ImportKeysActivity) activity; - } - - private void search(String query) { - mImportActivity.loadCallback(new ImportKeysListFragment.KeybaseLoaderState(query)); - } -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index fde0f5f23..f1f234461 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -37,9 +37,8 @@ import org.sufficientlysecure.keychain.keyimport.Keyserver; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.ui.adapter.AsyncTaskResultWrapper; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysAdapter; -import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListKeybaseLoader; +import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListCloudLoader; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader; -import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListServerLoader; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Notify; @@ -63,8 +62,7 @@ public class ImportKeysListFragment extends ListFragment implements private LoaderState mLoaderState; private static final int LOADER_ID_BYTES = 0; - private static final int LOADER_ID_SERVER_QUERY = 1; - private static final int LOADER_ID_KEYBASE = 2; + private static final int LOADER_ID_CLOUD = 1; private LongSparseArray mCachedKeyData; @@ -118,21 +116,13 @@ public class ImportKeysListFragment extends ListFragment implements } } - static public class KeyserverLoaderState extends LoaderState { - String serverQuery; - String keyserver; + static public class CloudLoaderState extends LoaderState { + Preferences.CloudSearchPrefs mCloudPrefs; + String mServerQuery; - KeyserverLoaderState(String serverQuery, String keyserver) { - this.serverQuery = serverQuery; - this.keyserver = keyserver; - } - } - - static public class KeybaseLoaderState extends LoaderState { - String keybaseQuery; - - KeybaseLoaderState(String keybaseQuery) { - this.keybaseQuery = keybaseQuery; + CloudLoaderState(String serverQuery, Preferences.CloudSearchPrefs cloudPrefs) { + mServerQuery = serverQuery; + mCloudPrefs = cloudPrefs; } } @@ -161,9 +151,8 @@ public class ImportKeysListFragment extends ListFragment implements } else if (query != null) { // TODO: this is used when updating a key. // Currently it simply uses keyserver nr 0 - String keyserver = Preferences.getPreferences(getActivity()) - .getKeyServers()[0]; - mLoaderState = new KeyserverLoaderState(query, keyserver); + Preferences prefs = Preferences.getPreferences(getActivity()); + mLoaderState = new CloudLoaderState(query, prefs.getCloudSearchPrefs()); } getListView().setOnTouchListener(new OnTouchListener() { @@ -202,11 +191,8 @@ public class ImportKeysListFragment extends ListFragment implements if (getLoaderManager().getLoader(LOADER_ID_BYTES) != null) { getLoaderManager().destroyLoader(LOADER_ID_BYTES); } - if (getLoaderManager().getLoader(LOADER_ID_SERVER_QUERY) != null) { - getLoaderManager().destroyLoader(LOADER_ID_SERVER_QUERY); - } - if (getLoaderManager().getLoader(LOADER_ID_KEYBASE) != null) { - getLoaderManager().destroyLoader(LOADER_ID_KEYBASE); + if (getLoaderManager().getLoader(LOADER_ID_CLOUD) != null) { + getLoaderManager().destroyLoader(LOADER_ID_CLOUD); } if (getView() != null) { setListShown(true); @@ -219,16 +205,11 @@ public class ImportKeysListFragment extends ListFragment implements setListShown(false); getLoaderManager().restartLoader(LOADER_ID_BYTES, null, this); - } else if (mLoaderState instanceof KeyserverLoaderState) { - // Start out with a progress indicator. - setListShown(false); - - getLoaderManager().restartLoader(LOADER_ID_SERVER_QUERY, null, this); - } else if (mLoaderState instanceof KeybaseLoaderState) { + } else if (mLoaderState instanceof CloudLoaderState) { // Start out with a progress indicator. setListShown(false); - getLoaderManager().restartLoader(LOADER_ID_KEYBASE, null, this); + getLoaderManager().restartLoader(LOADER_ID_CLOUD, null, this); } } @@ -241,13 +222,9 @@ public class ImportKeysListFragment extends ListFragment implements InputData inputData = getInputData(ls.keyBytes, ls.dataUri); return new ImportKeysListLoader(mActivity, inputData); } - case LOADER_ID_SERVER_QUERY: { - KeyserverLoaderState ls = (KeyserverLoaderState) mLoaderState; - return new ImportKeysListServerLoader(getActivity(), ls.serverQuery, ls.keyserver); - } - case LOADER_ID_KEYBASE: { - KeybaseLoaderState ls = (KeybaseLoaderState) mLoaderState; - return new ImportKeysListKeybaseLoader(getActivity(), ls.keybaseQuery); + case LOADER_ID_CLOUD: { + CloudLoaderState ls = (CloudLoaderState) mLoaderState; + return new ImportKeysListCloudLoader(getActivity(), ls.mServerQuery, ls.mCloudPrefs); } default: @@ -301,8 +278,7 @@ public class ImportKeysListFragment extends ListFragment implements } break; - case LOADER_ID_SERVER_QUERY: - case LOADER_ID_KEYBASE: + case LOADER_ID_CLOUD: if (error == null) { // No error @@ -333,11 +309,7 @@ public class ImportKeysListFragment extends ListFragment implements // Clear the data in the adapter. mAdapter.clear(); break; - case LOADER_ID_SERVER_QUERY: - // Clear the data in the adapter. - mAdapter.clear(); - break; - case LOADER_ID_KEYBASE: + case LOADER_ID_CLOUD: // Clear the data in the adapter. mAdapter.clear(); break; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java deleted file mode 100644 index 88caebc32..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysServerFragment.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) 2013-2014 Dominik Schürmann - * - * 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.ui; - -import android.app.Activity; -import android.content.Context; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.InputMethodManager; -import android.widget.ArrayAdapter; -import android.widget.AutoCompleteTextView; -import android.widget.EditText; -import android.widget.Spinner; -import android.widget.TextView; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.helper.ContactHelper; -import org.sufficientlysecure.keychain.helper.Preferences; -import org.sufficientlysecure.keychain.util.Log; - -import java.util.List; - -public class ImportKeysServerFragment extends Fragment { - public static final String ARG_QUERY = "query"; - public static final String ARG_KEYSERVER = "keyserver"; - public static final String ARG_DISABLE_QUERY_EDIT = "disable_query_edit"; - - private ImportKeysActivity mImportActivity; - - private View mSearchButton; - private AutoCompleteTextView mQueryEditText; - private View mConfigButton; - private View mConfigLayout; - private Spinner mServerSpinner; - private ArrayAdapter mServerAdapter; - - /** - * Creates new instance of this fragment - */ - public static ImportKeysServerFragment newInstance(String query, String keyserver) { - ImportKeysServerFragment frag = new ImportKeysServerFragment(); - - Bundle args = new Bundle(); - args.putString(ARG_QUERY, query); - args.putString(ARG_KEYSERVER, keyserver); - - frag.setArguments(args); - - return frag; - } - - /** - * Inflate the layout for this fragment - */ - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.import_keys_server_fragment, container, false); - - mSearchButton = view.findViewById(R.id.import_server_search); - mQueryEditText = (AutoCompleteTextView) view.findViewById(R.id.import_server_query); - mConfigButton = view.findViewById(R.id.import_server_config_button); - mConfigLayout = view.findViewById(R.id.import_server_config); - mServerSpinner = (Spinner) view.findViewById(R.id.import_server_spinner); - - // add keyservers to spinner - mServerAdapter = new ArrayAdapter(getActivity(), - android.R.layout.simple_spinner_item, Preferences.getPreferences(getActivity()) - .getKeyServers() - ); - mServerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - mServerSpinner.setAdapter(mServerAdapter); - if (mServerAdapter.getCount() > 0) { - mServerSpinner.setSelection(0); - } else { - mSearchButton.setEnabled(false); - } - - List namesAndEmails = ContactHelper.getContactNames(getActivity()); - namesAndEmails.addAll(ContactHelper.getContactMails(getActivity())); - mQueryEditText.setThreshold(3); - mQueryEditText.setAdapter( - new ArrayAdapter - (getActivity(), android.R.layout.simple_spinner_dropdown_item, - namesAndEmails - ) - ); - - mSearchButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - String query = mQueryEditText.getText().toString(); - String keyServer = (String) mServerSpinner.getSelectedItem(); - search(query, keyServer); - - // close keyboard after pressing search - InputMethodManager imm = - (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(mQueryEditText.getWindowToken(), 0); - } - }); - - mQueryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - if (actionId == EditorInfo.IME_ACTION_SEARCH) { - String query = mQueryEditText.getText().toString(); - String keyServer = (String) mServerSpinner.getSelectedItem(); - search(query, keyServer); - - // Don't return true to let the keyboard close itself after pressing search - return false; - } - return false; - } - }); - - mConfigButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (mImportActivity.getViewPagerHeight() > ImportKeysActivity.VIEW_PAGER_HEIGHT) { - mImportActivity.resizeViewPager(ImportKeysActivity.VIEW_PAGER_HEIGHT); - } else { - mImportActivity.resizeViewPager(ImportKeysActivity.VIEW_PAGER_HEIGHT + 41); - } - } - }); - - return view; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - // set displayed values - if (getArguments() != null) { - if (getArguments().containsKey(ARG_QUERY)) { - String query = getArguments().getString(ARG_QUERY); - mQueryEditText.setText(query, TextView.BufferType.EDITABLE); - - Log.d(Constants.TAG, "query: " + query); - } - - if (getArguments().containsKey(ARG_KEYSERVER)) { - String keyserver = getArguments().getString(ARG_KEYSERVER); - int keyserverPos = mServerAdapter.getPosition(keyserver); - mServerSpinner.setSelection(keyserverPos); - - Log.d(Constants.TAG, "keyserver: " + keyserver); - } - - if (getArguments().getBoolean(ARG_DISABLE_QUERY_EDIT, false)) { - mQueryEditText.setEnabled(false); - } - } - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - - mImportActivity = (ImportKeysActivity) activity; - } - - private void search(String query, String keyserver) { - mImportActivity.loadCallback(new ImportKeysListFragment.KeyserverLoaderState(query, keyserver)); - } - - public void setQueryAndKeyserver(String query, String keyserver) { - mQueryEditText.setText(query, TextView.BufferType.EDITABLE); - int keyServerPos = mServerAdapter.getPosition(keyserver); - mServerSpinner.setSelection(keyServerPos); - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesActivity.java index 1221966e1..dd4fedf9d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesActivity.java @@ -18,6 +18,7 @@ package org.sufficientlysecure.keychain.ui; import android.annotation.SuppressLint; +import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; @@ -40,7 +41,7 @@ import java.util.List; @SuppressLint("NewApi") public class PreferencesActivity extends PreferenceActivity { - public static final String ACTION_PREFS_GEN = "org.sufficientlysecure.keychain.ui.PREFS_GEN"; + public static final String ACTION_PREFS_CLOUD = "org.sufficientlysecure.keychain.ui.PREFS_CLOUD"; public static final String ACTION_PREFS_ADV = "org.sufficientlysecure.keychain.ui.PREFS_ADV"; public static final int REQUEST_CODE_KEYSERVER_PREF = 0x00007005; @@ -55,16 +56,11 @@ public class PreferencesActivity extends PreferenceActivity { String action = getIntent().getAction(); - if (action != null && action.equals(ACTION_PREFS_GEN)) { - addPreferencesFromResource(R.xml.gen_preferences); - - initializePassPassphraceCacheTtl( - (IntegerListPreference) findPreference(Constants.Pref.PASSPHRASE_CACHE_TTL)); + if (action != null && action.equals(ACTION_PREFS_CLOUD)) { + addPreferencesFromResource(R.xml.cloud_search_prefs); mKeyServerPreference = (PreferenceScreen) findPreference(Constants.Pref.KEY_SERVERS); - String servers[] = sPreferences.getKeyServers(); - mKeyServerPreference.setSummary(getResources().getQuantityString(R.plurals.n_keyservers, - servers.length, servers.length)); + mKeyServerPreference.setSummary(keyserverSummary(this)); mKeyServerPreference .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { @@ -76,10 +72,19 @@ public class PreferencesActivity extends PreferenceActivity { return false; } }); + initializeSearchKeyserver( + (CheckBoxPreference) findPreference(Constants.Pref.SEARCH_KEYSERVER) + ); + initializeSearchKeybase( + (CheckBoxPreference) findPreference(Constants.Pref.SEARCH_KEYBASE) + ); } else if (action != null && action.equals(ACTION_PREFS_ADV)) { addPreferencesFromResource(R.xml.adv_preferences); + initializePassPassphraceCacheTtl( + (IntegerListPreference) findPreference(Constants.Pref.PASSPHRASE_CACHE_TTL)); + initializeEncryptionAlgorithm( (IntegerListPreference) findPreference(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM)); @@ -136,8 +141,7 @@ public class PreferencesActivity extends PreferenceActivity { String servers[] = data .getStringArrayExtra(PreferencesKeyServerActivity.EXTRA_KEY_SERVERS); sPreferences.setKeyServers(servers); - mKeyServerPreference.setSummary(getResources().getQuantityString( - R.plurals.n_keyservers, servers.length, servers.length)); + mKeyServerPreference.setSummary(keyserverSummary(this)); break; } @@ -156,9 +160,9 @@ public class PreferencesActivity extends PreferenceActivity { } /** - * This fragment shows the general preferences in android 3.0+ + * This fragment shows the Cloud Search preferences in android 3.0+ */ - public static class GeneralPrefsFragment extends PreferenceFragment { + public static class CloudSearchPrefsFragment extends PreferenceFragment { private PreferenceScreen mKeyServerPreference = null; @@ -167,15 +171,11 @@ public class PreferencesActivity extends PreferenceActivity { super.onCreate(savedInstanceState); // Load the preferences from an XML resource - addPreferencesFromResource(R.xml.gen_preferences); - - initializePassPassphraceCacheTtl( - (IntegerListPreference) findPreference(Constants.Pref.PASSPHRASE_CACHE_TTL)); + addPreferencesFromResource(R.xml.cloud_search_prefs); mKeyServerPreference = (PreferenceScreen) findPreference(Constants.Pref.KEY_SERVERS); - String servers[] = sPreferences.getKeyServers(); - mKeyServerPreference.setSummary(getResources().getQuantityString(R.plurals.n_keyservers, - servers.length, servers.length)); + mKeyServerPreference.setSummary(keyserverSummary(getActivity())); + mKeyServerPreference .setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { @@ -187,6 +187,12 @@ public class PreferencesActivity extends PreferenceActivity { return false; } }); + initializeSearchKeyserver( + (CheckBoxPreference) findPreference(Constants.Pref.SEARCH_KEYSERVER) + ); + initializeSearchKeybase( + (CheckBoxPreference) findPreference(Constants.Pref.SEARCH_KEYBASE) + ); } @Override @@ -199,8 +205,7 @@ public class PreferencesActivity extends PreferenceActivity { String servers[] = data .getStringArrayExtra(PreferencesKeyServerActivity.EXTRA_KEY_SERVERS); sPreferences.setKeyServers(servers); - mKeyServerPreference.setSummary(getResources().getQuantityString( - R.plurals.n_keyservers, servers.length, servers.length)); + mKeyServerPreference.setSummary(keyserverSummary(getActivity())); break; } @@ -224,6 +229,9 @@ public class PreferencesActivity extends PreferenceActivity { // Load the preferences from an XML resource addPreferencesFromResource(R.xml.adv_preferences); + initializePassPassphraceCacheTtl( + (IntegerListPreference) findPreference(Constants.Pref.PASSPHRASE_CACHE_TTL)); + initializeEncryptionAlgorithm( (IntegerListPreference) findPreference(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM)); @@ -271,7 +279,7 @@ public class PreferencesActivity extends PreferenceActivity { protected boolean isValidFragment(String fragmentName) { return AdvancedPrefsFragment.class.getName().equals(fragmentName) - || GeneralPrefsFragment.class.getName().equals(fragmentName) + || CloudSearchPrefsFragment.class.getName().equals(fragmentName) || super.isValidFragment(fragmentName); } @@ -398,6 +406,39 @@ public class PreferencesActivity extends PreferenceActivity { }); } + private static void initializeSearchKeyserver(final CheckBoxPreference mSearchKeyserver) { + Preferences.CloudSearchPrefs prefs = sPreferences.getCloudSearchPrefs(); + mSearchKeyserver.setChecked(prefs.searchKeyserver); + mSearchKeyserver.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + mSearchKeyserver.setChecked((Boolean) newValue); + sPreferences.setSearchKeyserver((Boolean) newValue); + return false; + } + }); + } + + private static void initializeSearchKeybase(final CheckBoxPreference mSearchKeybase) { + Preferences.CloudSearchPrefs prefs = sPreferences.getCloudSearchPrefs(); + mSearchKeybase.setChecked(prefs.searchKeybase); + mSearchKeybase.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + mSearchKeybase.setChecked((Boolean) newValue); + sPreferences.setSearchKeybase((Boolean) newValue); + return false; + } + }); + } + + public static String keyserverSummary(Context context) { + String[] servers = sPreferences.getKeyServers(); + String serverSummary = context.getResources().getQuantityString( + R.plurals.n_keyservers, servers.length, servers.length); + return serverSummary + "; " + context.getString(R.string.label_preferred) + ": " + sPreferences.getPreferredKeyserver(); + } + private static void initializeUseDefaultYubikeyPin(final CheckBoxPreference mUseDefaultYubikeyPin) { mUseDefaultYubikeyPin.setChecked(sPreferences.useDefaultYubikeyPin()); mUseDefaultYubikeyPin.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @@ -408,4 +449,5 @@ public class PreferencesActivity extends PreferenceActivity { } }); } + } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java index 0de675bab..b5e0e2ab5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PreferencesKeyServerActivity.java @@ -43,6 +43,7 @@ public class PreferencesKeyServerActivity extends ActionBarActivity implements O private LayoutInflater mInflater; private ViewGroup mEditors; private View mAdd; + private View mShuffle; private TextView mTitle; private TextView mSummary; @@ -73,6 +74,7 @@ public class PreferencesKeyServerActivity extends ActionBarActivity implements O mTitle = (TextView) findViewById(R.id.title); mSummary = (TextView) findViewById(R.id.summary); + mSummary.setText(getText(R.string.label_first_keyserver_is_used)); mTitle.setText(R.string.label_keyservers); @@ -80,9 +82,29 @@ public class PreferencesKeyServerActivity extends ActionBarActivity implements O mAdd = findViewById(R.id.add); mAdd.setOnClickListener(this); + mShuffle = findViewById(R.id.shuffle); + mShuffle.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + Vector servers = serverList(); + String first = servers.get(0); + if (first != null) { + servers.remove(0); + servers.add(first); + String[] dummy = {}; + makeServerList(servers.toArray(dummy)); + } + } + }); + Intent intent = getIntent(); String servers[] = intent.getStringArrayExtra(EXTRA_KEY_SERVERS); + makeServerList(servers); + } + + private void makeServerList(String[] servers) { if (servers != null) { + mEditors.removeAllViews(); for (String serv : servers) { KeyServerEditor view = (KeyServerEditor) mInflater.inflate( R.layout.key_server_editor, mEditors, false); @@ -114,6 +136,18 @@ public class PreferencesKeyServerActivity extends ActionBarActivity implements O finish(); } + private Vector serverList() { + Vector servers = new Vector(); + for (int i = 0; i < mEditors.getChildCount(); ++i) { + KeyServerEditor editor = (KeyServerEditor) mEditors.getChildAt(i); + String tmp = editor.getValue(); + if (tmp.length() > 0) { + servers.add(tmp); + } + } + return servers; + } + private void okClicked() { Intent data = new Intent(); Vector servers = new Vector(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java new file mode 100644 index 000000000..d39feda76 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * + * 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.ui.adapter; + +import android.content.Context; +import android.support.v4.content.AsyncTaskLoader; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.helper.Preferences; +import org.sufficientlysecure.keychain.keyimport.CloudSearch; +import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; +import org.sufficientlysecure.keychain.util.Log; + +import java.util.ArrayList; + +public class ImportKeysListCloudLoader + extends AsyncTaskLoader>> { + Context mContext; + + + Preferences.CloudSearchPrefs mCloudPrefs; + String mServerQuery; + + private ArrayList mEntryList = new ArrayList(); + private AsyncTaskResultWrapper> mEntryListWrapper; + + public ImportKeysListCloudLoader(Context context, String serverQuery, Preferences.CloudSearchPrefs cloudPrefs) { + super(context); + mContext = context; + mServerQuery = serverQuery; + mCloudPrefs = cloudPrefs; + } + + @Override + public AsyncTaskResultWrapper> loadInBackground() { + mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, null); + + if (mServerQuery == null) { + Log.e(Constants.TAG, "mServerQuery is null!"); + return mEntryListWrapper; + } + + if (mServerQuery.startsWith("0x") && mServerQuery.length() == 42) { + Log.d(Constants.TAG, "This search is based on a unique fingerprint. Enforce a fingerprint check!"); + queryServer(true); + } else { + queryServer(false); + } + + return mEntryListWrapper; + } + + @Override + protected void onReset() { + super.onReset(); + + // Ensure the loader is stopped + onStopLoading(); + } + + @Override + protected void onStartLoading() { + forceLoad(); + } + + @Override + protected void onStopLoading() { + cancelLoad(); + } + + @Override + public void deliverResult(AsyncTaskResultWrapper> data) { + super.deliverResult(data); + } + + /** + * Query keyserver + */ + private void queryServer(boolean enforceFingerprint) { + try { + ArrayList searchResult = CloudSearch.search(mServerQuery, mCloudPrefs); + + mEntryList.clear(); + // add result to data + if (enforceFingerprint) { + String fingerprint = mServerQuery.substring(2); + Log.d(Constants.TAG, "fingerprint: " + fingerprint); + // query must return only one result! + if (searchResult.size() == 1) { + ImportKeysListEntry uniqueEntry = searchResult.get(0); + /* + * set fingerprint explicitly after query + * to enforce a check when the key is imported by KeychainIntentService + */ + uniqueEntry.setFingerprintHex(fingerprint); + uniqueEntry.setSelected(true); + mEntryList.add(uniqueEntry); + } + } else { + mEntryList.addAll(searchResult); + } + mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, null); + } catch (Exception e) { + mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); + } + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java deleted file mode 100644 index d2aefc220..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListKeybaseLoader.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * 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.ui.adapter; - -import android.content.Context; -import android.support.v4.content.AsyncTaskLoader; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; -import org.sufficientlysecure.keychain.keyimport.KeybaseKeyserver; -import org.sufficientlysecure.keychain.keyimport.Keyserver; -import org.sufficientlysecure.keychain.util.Log; - -import java.util.ArrayList; - -public class ImportKeysListKeybaseLoader - extends AsyncTaskLoader>> { - Context mContext; - - String mKeybaseQuery; - - private ArrayList mEntryList = new ArrayList(); - private AsyncTaskResultWrapper> mEntryListWrapper; - - public ImportKeysListKeybaseLoader(Context context, String keybaseQuery) { - super(context); - mContext = context; - mKeybaseQuery = keybaseQuery; - } - - @Override - public AsyncTaskResultWrapper> loadInBackground() { - - mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, null); - - if (mKeybaseQuery == null) { - Log.e(Constants.TAG, "mKeybaseQery is null!"); - return mEntryListWrapper; - } - - queryServer(mKeybaseQuery); - - return mEntryListWrapper; - } - - @Override - protected void onReset() { - super.onReset(); - - // Ensure the loader is stopped - onStopLoading(); - } - - @Override - protected void onStartLoading() { - forceLoad(); - } - - @Override - protected void onStopLoading() { - cancelLoad(); - } - - @Override - public void deliverResult(AsyncTaskResultWrapper> data) { - super.deliverResult(data); - } - - /** - * Query keybase - */ - private void queryServer(String query) { - - KeybaseKeyserver server = new KeybaseKeyserver(); - try { - ArrayList searchResult = server.search(query); - - mEntryList.clear(); - - mEntryList.addAll(searchResult); - mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, null); - } catch (Keyserver.QueryFailedException e) { - mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); - } catch (Keyserver.QueryNeedsRepairException e) { - mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); - } - } -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java deleted file mode 100644 index d62c2db43..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListServerLoader.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2014 Dominik Schürmann - * - * 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.ui.adapter; - -import android.content.Context; -import android.support.v4.content.AsyncTaskLoader; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; -import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; -import org.sufficientlysecure.keychain.keyimport.Keyserver; -import org.sufficientlysecure.keychain.util.Log; - -import java.util.ArrayList; - -public class ImportKeysListServerLoader - extends AsyncTaskLoader>> { - Context mContext; - - String mServerQuery; - String mKeyServer; - - private ArrayList mEntryList = new ArrayList(); - private AsyncTaskResultWrapper> mEntryListWrapper; - - public ImportKeysListServerLoader(Context context, String serverQuery, String keyServer) { - super(context); - mContext = context; - mServerQuery = serverQuery; - mKeyServer = keyServer; - } - - @Override - public AsyncTaskResultWrapper> loadInBackground() { - mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, null); - - if (mServerQuery == null) { - Log.e(Constants.TAG, "mServerQuery is null!"); - return mEntryListWrapper; - } - - if (mServerQuery.startsWith("0x") && mServerQuery.length() == 42) { - Log.d(Constants.TAG, "This search is based on a unique fingerprint. Enforce a fingerprint check!"); - queryServer(mServerQuery, mKeyServer, true); - } else { - queryServer(mServerQuery, mKeyServer, false); - } - - return mEntryListWrapper; - } - - @Override - protected void onReset() { - super.onReset(); - - // Ensure the loader is stopped - onStopLoading(); - } - - @Override - protected void onStartLoading() { - forceLoad(); - } - - @Override - protected void onStopLoading() { - cancelLoad(); - } - - @Override - public void deliverResult(AsyncTaskResultWrapper> data) { - super.deliverResult(data); - } - - /** - * Query keyserver - */ - private void queryServer(String query, String keyServer, boolean enforceFingerprint) { - HkpKeyserver server = new HkpKeyserver(keyServer); - try { - ArrayList searchResult = server.search(query); - - mEntryList.clear(); - // add result to data - if (enforceFingerprint) { - String fingerprint = query.substring(2); - Log.d(Constants.TAG, "fingerprint: " + fingerprint); - // query must return only one result! - if (searchResult.size() == 1) { - ImportKeysListEntry uniqueEntry = searchResult.get(0); - /* - * set fingerprint explicitly after query - * to enforce a check when the key is imported by KeychainIntentService - */ - uniqueEntry.setFingerprintHex(fingerprint); - uniqueEntry.setSelected(true); - mEntryList.add(uniqueEntry); - } - } else { - mEntryList.addAll(searchResult); - } - mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, null); - } catch (Keyserver.QueryFailedException e) { - mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); - } catch (Keyserver.QueryNeedsRepairException e) { - mEntryListWrapper = new AsyncTaskResultWrapper>(mEntryList, e); - } - } - -} diff --git a/OpenKeychain/src/main/res/drawable/button_rounded_blue.xml b/OpenKeychain/src/main/res/drawable/button_rounded_blue.xml new file mode 100644 index 000000000..7e36b0ef8 --- /dev/null +++ b/OpenKeychain/src/main/res/drawable/button_rounded_blue.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/import_keys_cloud_fragment.xml b/OpenKeychain/src/main/res/layout/import_keys_cloud_fragment.xml new file mode 100644 index 000000000..46ec736ca --- /dev/null +++ b/OpenKeychain/src/main/res/layout/import_keys_cloud_fragment.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/import_keys_keybase_fragment.xml b/OpenKeychain/src/main/res/layout/import_keys_keybase_fragment.xml deleted file mode 100644 index c70236e07..000000000 --- a/OpenKeychain/src/main/res/layout/import_keys_keybase_fragment.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/import_keys_list_entry.xml b/OpenKeychain/src/main/res/layout/import_keys_list_entry.xml index 773250dc6..74de77172 100644 --- a/OpenKeychain/src/main/res/layout/import_keys_list_entry.xml +++ b/OpenKeychain/src/main/res/layout/import_keys_list_entry.xml @@ -30,6 +30,8 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:paddingRight="8dp" + android:paddingTop="2dp" + android:gravity="top|center" android:clickable="false" android:focusable="false" android:focusableInTouchMode="false" /> diff --git a/OpenKeychain/src/main/res/layout/import_keys_server_fragment.xml b/OpenKeychain/src/main/res/layout/import_keys_server_fragment.xml deleted file mode 100644 index 62e7d740c..000000000 --- a/OpenKeychain/src/main/res/layout/import_keys_server_fragment.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/key_server_preference.xml b/OpenKeychain/src/main/res/layout/key_server_preference.xml index baf7111af..140b5e3d7 100644 --- a/OpenKeychain/src/main/res/layout/key_server_preference.xml +++ b/OpenKeychain/src/main/res/layout/key_server_preference.xml @@ -12,7 +12,7 @@ android:minHeight="?android:attr/listPreferredItemHeight" android:orientation="horizontal" > - - - + +