From fe981e54989c47ae252a4dfdc2aa41aab295cc7e Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 10 Oct 2014 19:59:25 +0200 Subject: move around package structure a bit --- .../keychain/operations/BaseOperation.java | 55 ++ .../keychain/operations/ImportExportOperation.java | 279 ++++++++ .../keychain/operations/PgpCertifyOperation.java | 145 +++++ .../keychain/operations/results/CertifyResult.java | 151 +++++ .../operations/results/ConsolidateResult.java | 49 ++ .../operations/results/DecryptVerifyResult.java | 132 ++++ .../keychain/operations/results/EditKeyResult.java | 63 ++ .../keychain/operations/results/GetKeyResult.java | 64 ++ .../operations/results/ImportKeyResult.java | 212 ++++++ .../operations/results/OperationResult.java | 710 +++++++++++++++++++++ .../operations/results/SaveKeyringResult.java | 68 ++ .../operations/results/SignEncryptResult.java | 123 ++++ .../operations/results/SingletonResult.java | 87 +++ .../keychain/pgp/PgpDecryptVerify.java | 6 +- .../keychain/pgp/PgpKeyOperation.java | 8 +- .../keychain/pgp/PgpSignEncrypt.java | 6 +- .../keychain/pgp/UncachedKeyRing.java | 4 +- .../keychain/pgp/ops/BaseOperation.java | 55 -- .../keychain/pgp/ops/ImportExportOperation.java | 279 -------- .../keychain/pgp/ops/PgpCertifyOperation.java | 145 ----- .../keychain/provider/ProviderHelper.java | 10 +- .../keychain/remote/OpenPgpService.java | 6 +- .../remote/ui/AccountSettingsActivity.java | 7 +- .../remote/ui/AccountSettingsFragment.java | 4 +- .../keychain/remote/ui/AppSettingsActivity.java | 2 +- .../keychain/service/KeychainIntentService.java | 25 +- .../keychain/service/results/CertifyResult.java | 151 ----- .../service/results/ConsolidateResult.java | 49 -- .../service/results/DecryptVerifyResult.java | 132 ---- .../keychain/service/results/EditKeyResult.java | 63 -- .../keychain/service/results/GetKeyResult.java | 64 -- .../keychain/service/results/ImportKeyResult.java | 212 ------ .../keychain/service/results/OperationResult.java | 710 --------------------- .../service/results/SaveKeyringResult.java | 68 -- .../service/results/SignEncryptResult.java | 123 ---- .../keychain/service/results/SingletonResult.java | 87 --- .../keychain/ui/AddKeysActivity.java | 6 +- .../keychain/ui/CertifyKeyFragment.java | 6 +- .../keychain/ui/CreateKeyFinalFragment.java | 4 +- .../keychain/ui/DecryptActivity.java | 3 +- .../keychain/ui/DecryptFilesFragment.java | 2 +- .../keychain/ui/DecryptFragment.java | 2 +- .../keychain/ui/DecryptTextActivity.java | 4 +- .../keychain/ui/DecryptTextFragment.java | 3 +- .../keychain/ui/EditKeyFragment.java | 8 +- .../keychain/ui/EncryptActivity.java | 2 +- .../keychain/ui/EncryptFilesActivity.java | 2 +- .../keychain/ui/EncryptTextActivity.java | 2 +- .../keychain/ui/ImportKeysActivity.java | 7 +- .../keychain/ui/ImportKeysListFragment.java | 4 +- .../keychain/ui/KeyListActivity.java | 9 +- .../keychain/ui/KeyListFragment.java | 4 +- .../keychain/ui/LogDisplayFragment.java | 8 +- .../keychain/ui/MultiCertifyKeyFragment.java | 5 +- .../keychain/ui/ViewKeyActivity.java | 2 +- .../ui/adapter/AsyncTaskResultWrapper.java | 2 +- .../ui/adapter/ImportKeysListCloudLoader.java | 4 +- .../keychain/ui/adapter/ImportKeysListLoader.java | 4 +- 58 files changed, 2216 insertions(+), 2231 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PgpCertifyOperation.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/CertifyResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/ConsolidateResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/DecryptVerifyResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/EditKeyResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/GetKeyResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/ImportKeyResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/SaveKeyringResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/SignEncryptResult.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/SingletonResult.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/BaseOperation.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/ImportExportOperation.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/PgpCertifyOperation.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/CertifyResult.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ConsolidateResult.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/EditKeyResult.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/GetKeyResult.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java delete 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/SaveKeyringResult.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java delete mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SingletonResult.java (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java new file mode 100644 index 000000000..01889ed82 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java @@ -0,0 +1,55 @@ +package org.sufficientlysecure.keychain.operations; + +import android.content.Context; + +import org.sufficientlysecure.keychain.pgp.Progressable; +import org.sufficientlysecure.keychain.provider.ProviderHelper; + +import java.util.concurrent.atomic.AtomicBoolean; + +public class BaseOperation { + + final public Context mContext; + final public Progressable mProgressable; + final public AtomicBoolean mCancelled; + + final public ProviderHelper mProviderHelper; + + // TODO do we really need the context in these operations? + public BaseOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { + this.mContext = context; + this.mProgressable = progressable; + this.mProviderHelper = providerHelper; + mCancelled = null; + } + + public BaseOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean cancelled) { + mContext = context; + mProgressable = progressable; + mProviderHelper = providerHelper; + mCancelled = cancelled; + } + + public void updateProgress(int message, int current, int total) { + if (mProgressable != null) { + mProgressable.setProgress(message, current, total); + } + } + + public void updateProgress(String message, int current, int total) { + if (mProgressable != null) { + mProgressable.setProgress(message, current, total); + } + } + + public void updateProgress(int current, int total) { + if (mProgressable != null) { + mProgressable.setProgress(current, total); + } + } + + protected boolean checkCancelled() { + return mCancelled != null && mCancelled.get(); + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java new file mode 100644 index 000000000..f8957cc0f --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java @@ -0,0 +1,279 @@ +/* + * Copyright (C) 2012-2014 Dominik Schürmann + * Copyright (C) 2010-2014 Thialfihar + * + * 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.operations; + +import android.content.Context; +import android.os.Bundle; +import android.os.Environment; + +import org.spongycastle.bcpg.ArmoredOutputStream; +import org.spongycastle.openpgp.PGPException; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; +import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException; +import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; +import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; +import org.sufficientlysecure.keychain.pgp.PgpHelper; +import org.sufficientlysecure.keychain.pgp.Progressable; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; +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.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; +import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; +import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; +import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; +import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.ProgressScaler; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.concurrent.atomic.AtomicBoolean; + +public class ImportExportOperation extends BaseOperation { + + public ImportExportOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { + super(context, providerHelper, progressable); + } + + public ImportExportOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean cancelled) { + super(context, providerHelper, progressable, cancelled); + } + + public void uploadKeyRingToServer(HkpKeyserver server, CanonicalizedPublicKeyRing keyring) throws AddKeyException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ArmoredOutputStream aos = null; + try { + aos = new ArmoredOutputStream(bos); + keyring.encode(aos); + aos.close(); + + String armoredKey = bos.toString("UTF-8"); + server.add(armoredKey); + } catch (IOException e) { + Log.e(Constants.TAG, "IOException", e); + throw new AddKeyException(); + } finally { + try { + if (aos != null) { + aos.close(); + } + bos.close(); + } catch (IOException e) { + // this is just a finally thing, no matter if it doesn't work out. + } + } + } + + public ImportKeyResult importKeyRings(Iterator entries, int num) { + updateProgress(R.string.progress_importing, 0, 100); + + OperationLog log = new OperationLog(); + + // If there aren't even any keys, do nothing here. + if (entries == null || !entries.hasNext()) { + return new ImportKeyResult( + ImportKeyResult.RESULT_FAIL_NOTHING, log, 0, 0, 0, 0, + new long[]{}); + } + + int newKeys = 0, oldKeys = 0, badKeys = 0, secret = 0; + ArrayList importedMasterKeyIds = new ArrayList(); + + int position = 0; + double progSteps = 100.0 / num; + + // iterate over all entries + while (entries.hasNext()) { + ParcelableKeyRing entry = entries.next(); + + // Has this action been cancelled? If so, don't proceed any further + if (mCancelled != null && mCancelled.get()) { + break; + } + + try { + UncachedKeyRing key = UncachedKeyRing.decodeFromData(entry.getBytes()); + + String expectedFp = entry.getExpectedFingerprint(); + if(expectedFp != null) { + if(!KeyFormattingUtils.convertFingerprintToHex(key.getFingerprint()).equals(expectedFp)) { + Log.d(Constants.TAG, "fingerprint: " + KeyFormattingUtils.convertFingerprintToHex(key.getFingerprint())); + Log.d(Constants.TAG, "expected fingerprint: " + expectedFp); + Log.e(Constants.TAG, "Actual key fingerprint is not the same as expected!"); + badKeys += 1; + continue; + } else { + Log.d(Constants.TAG, "Actual key fingerprint matches expected one."); + } + } + + SaveKeyringResult result; + mProviderHelper.clearLog(); + if (key.isSecret()) { + result = mProviderHelper.saveSecretKeyRing(key, + new ProgressScaler(mProgressable, (int)(position*progSteps), (int)((position+1)*progSteps), 100)); + } else { + result = mProviderHelper.savePublicKeyRing(key, + new ProgressScaler(mProgressable, (int)(position*progSteps), (int)((position+1)*progSteps), 100)); + } + if (!result.success()) { + badKeys += 1; + } else if (result.updated()) { + oldKeys += 1; + importedMasterKeyIds.add(key.getMasterKeyId()); + } else { + newKeys += 1; + if (key.isSecret()) { + secret += 1; + } + importedMasterKeyIds.add(key.getMasterKeyId()); + } + + log.add(result, 1); + + } catch (IOException e) { + Log.e(Constants.TAG, "Encountered bad key on import!", e); + ++badKeys; + } catch (PgpGeneralException e) { + Log.e(Constants.TAG, "Encountered bad key on import!", e); + ++badKeys; + } + // update progress + position++; + } + + int resultType = 0; + // special return case: no new keys at all + if (badKeys == 0 && newKeys == 0 && oldKeys == 0) { + resultType = ImportKeyResult.RESULT_FAIL_NOTHING; + } else { + if (newKeys > 0) { + resultType |= ImportKeyResult.RESULT_OK_NEWKEYS; + } + if (oldKeys > 0) { + resultType |= ImportKeyResult.RESULT_OK_UPDATED; + } + if (badKeys > 0) { + resultType |= ImportKeyResult.RESULT_WITH_ERRORS; + if (newKeys == 0 && oldKeys == 0) { + resultType |= ImportKeyResult.RESULT_ERROR; + } + } + if (log.containsWarnings()) { + resultType |= ImportKeyResult.RESULT_WARNINGS; + } + } + if (mCancelled != null && mCancelled.get()) { + log.add(LogType.MSG_OPERATION_CANCELLED, 0); + resultType |= ImportKeyResult.RESULT_CANCELLED; + } + + // convert to long array + long[] importedMasterKeyIdsArray = new long[importedMasterKeyIds.size()]; + for (int i = 0; i < importedMasterKeyIds.size(); ++i) { + importedMasterKeyIdsArray[i] = importedMasterKeyIds.get(i); + } + + return new ImportKeyResult(resultType, log, newKeys, oldKeys, badKeys, secret, + importedMasterKeyIdsArray); + } + + public Bundle exportKeyRings(ArrayList publicKeyRingMasterIds, + ArrayList secretKeyRingMasterIds, + OutputStream outStream) throws PgpGeneralException, + PGPException, IOException { + Bundle returnData = new Bundle(); + + int masterKeyIdsSize = publicKeyRingMasterIds.size() + secretKeyRingMasterIds.size(); + int progress = 0; + + updateProgress( + mContext.getResources().getQuantityString(R.plurals.progress_exporting_key, + masterKeyIdsSize), 0, 100); + + if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { + throw new PgpGeneralException( + mContext.getString(R.string.error_external_storage_not_ready)); + } + // For each public masterKey id + for (long pubKeyMasterId : publicKeyRingMasterIds) { + progress++; + // Create an output stream + ArmoredOutputStream arOutStream = new ArmoredOutputStream(outStream); + String version = PgpHelper.getVersionForHeader(mContext); + if (version != null) { + arOutStream.setHeader("Version", version); + } + + updateProgress(progress * 100 / masterKeyIdsSize, 100); + + try { + CanonicalizedPublicKeyRing ring = mProviderHelper.getCanonicalizedPublicKeyRing( + KeychainContract.KeyRings.buildUnifiedKeyRingUri(pubKeyMasterId) + ); + + ring.encode(arOutStream); + } catch (ProviderHelper.NotFoundException e) { + Log.e(Constants.TAG, "key not found!", e); + // TODO: inform user? + } + + arOutStream.close(); + } + + // For each secret masterKey id + for (long secretKeyMasterId : secretKeyRingMasterIds) { + progress++; + // Create an output stream + ArmoredOutputStream arOutStream = new ArmoredOutputStream(outStream); + String version = PgpHelper.getVersionForHeader(mContext); + if (version != null) { + arOutStream.setHeader("Version", version); + } + + updateProgress(progress * 100 / masterKeyIdsSize, 100); + + try { + CanonicalizedSecretKeyRing secretKeyRing = + mProviderHelper.getCanonicalizedSecretKeyRing(secretKeyMasterId); + secretKeyRing.encode(arOutStream); + } catch (ProviderHelper.NotFoundException e) { + Log.e(Constants.TAG, "key not found!", e); + // TODO: inform user? + } + + arOutStream.close(); + } + + returnData.putInt(KeychainIntentService.RESULT_EXPORT, masterKeyIdsSize); + + updateProgress(R.string.progress_done, 100, 100); + + return returnData; + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PgpCertifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PgpCertifyOperation.java new file mode 100644 index 000000000..845326791 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/PgpCertifyOperation.java @@ -0,0 +1,145 @@ +package org.sufficientlysecure.keychain.operations; + +import android.content.Context; + +import org.spongycastle.openpgp.PGPException; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; +import org.sufficientlysecure.keychain.pgp.Progressable; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; +import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.service.CertifyActionsParcel; +import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; +import org.sufficientlysecure.keychain.operations.results.CertifyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; +import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; +import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; +import org.sufficientlysecure.keychain.util.Log; + +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; + +public class PgpCertifyOperation extends BaseOperation { + + public PgpCertifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean cancelled) { + super(context, providerHelper, progressable, cancelled); + } + + public CertifyResult certify(CertifyActionsParcel parcel, String passphrase) { + + OperationLog log = new OperationLog(); + log.add(LogType.MSG_CRT, 0); + + // Retrieve and unlock secret key + CanonicalizedSecretKey certificationKey; + try { + log.add(LogType.MSG_CRT_MASTER_FETCH, 1); + CanonicalizedSecretKeyRing secretKeyRing = + mProviderHelper.getCanonicalizedSecretKeyRing(parcel.mMasterKeyId); + log.add(LogType.MSG_CRT_UNLOCK, 1); + certificationKey = secretKeyRing.getSecretKey(); + if (!certificationKey.unlock(passphrase)) { + log.add(LogType.MSG_CRT_ERROR_UNLOCK, 2); + return new CertifyResult(CertifyResult.RESULT_ERROR, log); + } + } catch (PgpGeneralException e) { + log.add(LogType.MSG_CRT_ERROR_UNLOCK, 2); + return new CertifyResult(CertifyResult.RESULT_ERROR, log); + } catch (NotFoundException e) { + log.add(LogType.MSG_CRT_ERROR_MASTER_NOT_FOUND, 2); + return new CertifyResult(CertifyResult.RESULT_ERROR, log); + } + + ArrayList certifiedKeys = new ArrayList(); + + log.add(LogType.MSG_CRT_CERTIFYING, 1); + + int certifyOk = 0, certifyError = 0; + + // Work through all requested certifications + for (CertifyAction action : parcel.mCertifyActions) { + + // Check if we were cancelled + if (checkCancelled()) { + log.add(LogType.MSG_OPERATION_CANCELLED, 0); + return new CertifyResult(CertifyResult.RESULT_CANCELLED, log); + } + + try { + + if (action.mUserIds == null) { + log.add(LogType.MSG_CRT_CERTIFY_ALL, 2, + KeyFormattingUtils.convertKeyIdToHex(action.mMasterKeyId)); + } else { + log.add(LogType.MSG_CRT_CERTIFY_SOME, 2, action.mUserIds.size(), + KeyFormattingUtils.convertKeyIdToHex(action.mMasterKeyId)); + } + + CanonicalizedPublicKeyRing publicRing = + mProviderHelper.getCanonicalizedPublicKeyRing(action.mMasterKeyId); + + UncachedKeyRing certifiedKey = certificationKey.certifyUserIds(publicRing, action.mUserIds, null, null); + certifiedKeys.add(certifiedKey); + + } catch (NotFoundException e) { + certifyError += 1; + log.add(LogType.MSG_CRT_WARN_NOT_FOUND, 3); + } catch (PGPException e) { + certifyError += 1; + log.add(LogType.MSG_CRT_WARN_CERT_FAILED, 3); + Log.e(Constants.TAG, "Encountered PGPException during certification", e); + } + + } + + log.add(LogType.MSG_CRT_SAVING, 1); + + // Check if we were cancelled + if (checkCancelled()) { + log.add(LogType.MSG_OPERATION_CANCELLED, 0); + return new CertifyResult(CertifyResult.RESULT_CANCELLED, log); + } + + // Write all certified keys into the database + for (UncachedKeyRing certifiedKey : certifiedKeys) { + + // Check if we were cancelled + if (checkCancelled()) { + log.add(LogType.MSG_OPERATION_CANCELLED, 0); + return new CertifyResult(CertifyResult.RESULT_CANCELLED, log, certifyOk, certifyError); + } + + log.add(LogType.MSG_CRT_SAVE, 2, + KeyFormattingUtils.convertKeyIdToHex(certifiedKey.getMasterKeyId())); + // store the signed key in our local cache + mProviderHelper.clearLog(); + SaveKeyringResult result = mProviderHelper.savePublicKeyRing(certifiedKey); + + if (result.success()) { + certifyOk += 1; + } else { + log.add(LogType.MSG_CRT_WARN_SAVE_FAILED, 3); + } + + log.add(result, 2); + + // TODO do something with import results + + } + + if (certifyOk == 0) { + log.add(LogType.MSG_CRT_ERROR_NOTHING, 0); + return new CertifyResult(CertifyResult.RESULT_ERROR, log, certifyOk, certifyError); + } + + log.add(LogType.MSG_CRT_SUCCESS, 0); + return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError); + + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/CertifyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/CertifyResult.java new file mode 100644 index 000000000..49e3d0346 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/CertifyResult.java @@ -0,0 +1,151 @@ +/* + * 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.operations.results; + +import android.app.Activity; +import android.content.Intent; +import android.os.Parcel; +import android.os.Parcelable; +import android.view.View; + +import com.github.johnpersano.supertoasts.SuperCardToast; +import com.github.johnpersano.supertoasts.SuperToast; +import com.github.johnpersano.supertoasts.SuperToast.Duration; +import com.github.johnpersano.supertoasts.util.OnClickWrapper; +import com.github.johnpersano.supertoasts.util.Style; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.LogDisplayActivity; +import org.sufficientlysecure.keychain.ui.LogDisplayFragment; + +public class CertifyResult extends OperationResult { + + int mCertifyOk, mCertifyError; + + public CertifyResult(int result, OperationLog log) { + super(result, log); + } + + public CertifyResult(int result, OperationLog log, int certifyOk, int certifyError) { + this(result, log); + mCertifyOk = certifyOk; + mCertifyError = certifyError; + } + + /** Construct from a parcel - trivial because we have no extra data. */ + public CertifyResult(Parcel source) { + super(source); + mCertifyOk = source.readInt(); + mCertifyError = source.readInt(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(mCertifyOk); + dest.writeInt(mCertifyError); + } + + public static Creator CREATOR = new Creator() { + public CertifyResult createFromParcel(final Parcel source) { + return new CertifyResult(source); + } + + public CertifyResult[] newArray(final int size) { + return new CertifyResult[size]; + } + }; + + public SuperCardToast createNotify(final Activity activity) { + + int resultType = getResult(); + + String str; + int duration, color; + + // Not an overall failure + if ((resultType & OperationResult.RESULT_ERROR) == 0) { + String withWarnings; + + duration = Duration.EXTRA_LONG; + color = Style.GREEN; + withWarnings = ""; + + // Any warnings? + if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { + duration = 0; + color = Style.ORANGE; + withWarnings += activity.getString(R.string.with_warnings); + } + if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { + duration = 0; + color = Style.ORANGE; + withWarnings += activity.getString(R.string.with_cancelled); + } + + // New and updated keys + str = activity.getResources().getQuantityString( + R.plurals.certify_keys_ok, mCertifyOk, mCertifyOk, withWarnings); + if (mCertifyError > 0) { + // definitely switch to warning-style message in this case! + duration = 0; + color = Style.RED; + str += " " + activity.getResources().getQuantityString( + R.plurals.certify_keys_with_errors, mCertifyError, mCertifyError); + } + + } else { + duration = 0; + color = Style.RED; + str = activity.getResources().getQuantityString(R.plurals.certify_error, + mCertifyError, mCertifyError); + } + + boolean button = getLog() != null && !getLog().isEmpty(); + SuperCardToast toast = new SuperCardToast(activity, + button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, + Style.getStyle(color, SuperToast.Animations.POPUP)); + toast.setText(str); + toast.setDuration(duration); + toast.setIndeterminate(duration == 0); + toast.setSwipeToDismiss(true); + // If we have a log and it's non-empty, show a View Log button + if (button) { + toast.setButtonIcon(R.drawable.ic_action_view_as_list, + activity.getResources().getString(R.string.view_log)); + toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); + toast.setTextColor(activity.getResources().getColor(R.color.black)); + toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", + new SuperToast.OnClickListener() { + @Override + public void onClick(View view, Parcelable token) { + Intent intent = new Intent( + activity, LogDisplayActivity.class); + intent.putExtra(LogDisplayFragment.EXTRA_RESULT, CertifyResult.this); + activity.startActivity(intent); + } + } + )); + } + + return toast; + + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/ConsolidateResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/ConsolidateResult.java new file mode 100644 index 000000000..96b799f83 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/ConsolidateResult.java @@ -0,0 +1,49 @@ +/* + * 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.operations.results; + +import android.os.Parcel; + +public class ConsolidateResult extends OperationResult { + + public ConsolidateResult(int result, OperationLog log) { + super(result, log); + } + + /** Construct from a parcel - trivial because we have no extra data. */ + public ConsolidateResult(Parcel source) { + super(source); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + } + + public static Creator CREATOR = new Creator() { + public ConsolidateResult createFromParcel(final Parcel source) { + return new ConsolidateResult(source); + } + + public ConsolidateResult[] newArray(final int size) { + return new ConsolidateResult[size]; + } + }; + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/DecryptVerifyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/DecryptVerifyResult.java new file mode 100644 index 000000000..d81577102 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/DecryptVerifyResult.java @@ -0,0 +1,132 @@ +/* + * 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.operations.results; + +import android.os.Parcel; + +import org.openintents.openpgp.OpenPgpMetadata; +import org.openintents.openpgp.OpenPgpSignatureResult; + +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; + + // fifth to sixth bit in addition indicate specific type of pending + public static final int RESULT_PENDING_ASYM_PASSPHRASE = RESULT_PENDING + 16; + public static final int RESULT_PENDING_SYM_PASSPHRASE = RESULT_PENDING + 32; + public static final int RESULT_PENDING_NFC = RESULT_PENDING + 64; + + long mKeyIdPassphraseNeeded; + + long mNfcSubKeyId; + byte[] mNfcSessionKey; + String mNfcPassphrase; + + OpenPgpSignatureResult mSignatureResult; + OpenPgpMetadata mDecryptMetadata; + + public long getKeyIdPassphraseNeeded() { + return mKeyIdPassphraseNeeded; + } + + public void setKeyIdPassphraseNeeded(long keyIdPassphraseNeeded) { + mKeyIdPassphraseNeeded = keyIdPassphraseNeeded; + } + + public void setNfcState(long subKeyId, byte[] sessionKey, String passphrase) { + mNfcSubKeyId = subKeyId; + mNfcSessionKey = sessionKey; + mNfcPassphrase = passphrase; + } + + public long getNfcSubKeyId() { + return mNfcSubKeyId; + } + + public byte[] getNfcEncryptedSessionKey() { + return mNfcSessionKey; + } + + public String getNfcPassphrase() { + return mNfcPassphrase; + } + + public OpenPgpSignatureResult getSignatureResult() { + return mSignatureResult; + } + + public void setSignatureResult(OpenPgpSignatureResult signatureResult) { + mSignatureResult = signatureResult; + } + + public OpenPgpMetadata getDecryptMetadata() { + return mDecryptMetadata; + } + + public void setDecryptMetadata(OpenPgpMetadata decryptMetadata) { + mDecryptMetadata = decryptMetadata; + } + + public boolean isPending() { + return (mResult & RESULT_PENDING) == RESULT_PENDING; + } + + public DecryptVerifyResult(int result, OperationLog log) { + super(result, log); + } + + public DecryptVerifyResult(Parcel source) { + super(source); + mKeyIdPassphraseNeeded = source.readLong(); + mSignatureResult = source.readParcelable(OpenPgpSignatureResult.class.getClassLoader()); + mDecryptMetadata = source.readParcelable(OpenPgpMetadata.class.getClassLoader()); + mNfcSessionKey = source.readInt() != 0 ? source.createByteArray() : null; + mNfcPassphrase = source.readString(); + } + + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeLong(mKeyIdPassphraseNeeded); + dest.writeParcelable(mSignatureResult, 0); + dest.writeParcelable(mDecryptMetadata, 0); + if (mNfcSessionKey != null) { + dest.writeInt(1); + dest.writeByteArray(mNfcSessionKey); + } else { + dest.writeInt(0); + } + dest.writeString(mNfcPassphrase); + } + + public static final Creator CREATOR = new Creator() { + public DecryptVerifyResult createFromParcel(final Parcel source) { + return new DecryptVerifyResult(source); + } + + public DecryptVerifyResult[] newArray(final int size) { + return new DecryptVerifyResult[size]; + } + }; + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/EditKeyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/EditKeyResult.java new file mode 100644 index 000000000..f2acfef1e --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/EditKeyResult.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * Copyright (C) 2014 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.operations.results; + +import android.os.Parcel; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; + +public class EditKeyResult extends OperationResult { + + private transient UncachedKeyRing mRing; + public final long mRingMasterKeyId; + + public EditKeyResult(int result, OperationLog log, + UncachedKeyRing ring) { + super(result, log); + mRing = ring; + mRingMasterKeyId = ring != null ? ring.getMasterKeyId() : Constants.key.none; + } + + public UncachedKeyRing getRing() { + return mRing; + } + + public EditKeyResult(Parcel source) { + super(source); + mRingMasterKeyId = source.readLong(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeLong(mRingMasterKeyId); + } + + public static Creator CREATOR = new Creator() { + public EditKeyResult createFromParcel(final Parcel source) { + return new EditKeyResult(source); + } + + public EditKeyResult[] newArray(final int size) { + return new EditKeyResult[size]; + } + }; + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/GetKeyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/GetKeyResult.java new file mode 100644 index 000000000..53bc545c5 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/GetKeyResult.java @@ -0,0 +1,64 @@ +/* + * 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.operations.results; + +import android.os.Parcel; + +public class GetKeyResult extends OperationResult { + + public int mNonPgpPartsCount; + + public int getNonPgpPartsCount() { + return mNonPgpPartsCount; + } + + public void setNonPgpPartsCount(int nonPgpPartsCount) { + mNonPgpPartsCount = nonPgpPartsCount; + } + + public GetKeyResult(int result, OperationLog log) { + super(result, log); + } + + public static final int RESULT_ERROR_NO_VALID_KEYS = RESULT_ERROR + 8; + public static final int RESULT_ERROR_NO_PGP_PARTS = RESULT_ERROR + 16; + public static final int RESULT_ERROR_QUERY_TOO_SHORT = RESULT_ERROR + 32; + public static final int RESULT_ERROR_TOO_MANY_RESPONSES = RESULT_ERROR + 64; + public static final int RESULT_ERROR_TOO_SHORT_OR_TOO_MANY_RESPONSES = RESULT_ERROR + 128; + public static final int RESULT_ERROR_QUERY_FAILED = RESULT_ERROR + 256; + + public GetKeyResult(Parcel source) { + super(source); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + } + + public static Creator CREATOR = new Creator() { + public GetKeyResult createFromParcel(final Parcel source) { + return new GetKeyResult(source); + } + + public GetKeyResult[] newArray(final int size) { + return new GetKeyResult[size]; + } + }; +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/ImportKeyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/ImportKeyResult.java new file mode 100644 index 000000000..1dd038a23 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/ImportKeyResult.java @@ -0,0 +1,212 @@ +/* + * 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.operations.results; + +import android.app.Activity; +import android.content.Intent; +import android.os.Parcel; +import android.os.Parcelable; +import android.view.View; + +import com.github.johnpersano.supertoasts.SuperCardToast; +import com.github.johnpersano.supertoasts.SuperToast; +import com.github.johnpersano.supertoasts.SuperToast.Duration; +import com.github.johnpersano.supertoasts.util.OnClickWrapper; +import com.github.johnpersano.supertoasts.util.Style; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.LogDisplayActivity; +import org.sufficientlysecure.keychain.ui.LogDisplayFragment; + +public class ImportKeyResult extends OperationResult { + + public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret; + public final long[] mImportedMasterKeyIds; + + // At least one new key + public static final int RESULT_OK_NEWKEYS = 8; + // At least one updated key + public static final int RESULT_OK_UPDATED = 16; + // At least one key failed (might still be an overall success) + public static final int RESULT_WITH_ERRORS = 32; + + // No keys to import... + public static final int RESULT_FAIL_NOTHING = 64 + 1; + + public boolean isOkBoth() { + return (mResult & (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED)) + == (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED); + } + + public boolean isOkNew() { + return (mResult & RESULT_OK_NEWKEYS) == RESULT_OK_NEWKEYS; + } + + public boolean isOkUpdated() { + return (mResult & RESULT_OK_UPDATED) == RESULT_OK_UPDATED; + } + + public boolean isOkWithErrors() { + return (mResult & RESULT_WITH_ERRORS) == RESULT_WITH_ERRORS; + } + + public boolean isFailNothing() { + return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING; + } + + public long[] getImportedMasterKeyIds() { + return mImportedMasterKeyIds; + } + + public ImportKeyResult(Parcel source) { + super(source); + mNewKeys = source.readInt(); + mUpdatedKeys = source.readInt(); + mBadKeys = source.readInt(); + mSecret = source.readInt(); + mImportedMasterKeyIds = source.createLongArray(); + } + + public ImportKeyResult(int result, OperationLog log, + int newKeys, int updatedKeys, int badKeys, int secret, + long[] importedMasterKeyIds) { + super(result, log); + mNewKeys = newKeys; + mUpdatedKeys = updatedKeys; + mBadKeys = badKeys; + mSecret = secret; + mImportedMasterKeyIds = importedMasterKeyIds; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(mNewKeys); + dest.writeInt(mUpdatedKeys); + dest.writeInt(mBadKeys); + dest.writeInt(mSecret); + dest.writeLongArray(mImportedMasterKeyIds); + } + + public static Creator CREATOR = new Creator() { + public ImportKeyResult createFromParcel(final Parcel source) { + return new ImportKeyResult(source); + } + + public ImportKeyResult[] newArray(final int size) { + return new ImportKeyResult[size]; + } + }; + + public SuperCardToast createNotify(final Activity activity) { + + int resultType = getResult(); + + String str; + int duration, color; + + // Not an overall failure + if ((resultType & OperationResult.RESULT_ERROR) == 0) { + String withWarnings; + + duration = Duration.EXTRA_LONG; + color = Style.GREEN; + withWarnings = ""; + + // Any warnings? + if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { + duration = 0; + color = Style.ORANGE; + withWarnings += activity.getString(R.string.with_warnings); + } + if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { + duration = 0; + color = Style.ORANGE; + withWarnings += activity.getString(R.string.with_cancelled); + } + + // New and updated keys + if (isOkBoth()) { + str = activity.getResources().getQuantityString( + R.plurals.import_keys_added_and_updated_1, mNewKeys, mNewKeys); + str += " " + activity.getResources().getQuantityString( + R.plurals.import_keys_added_and_updated_2, mUpdatedKeys, mUpdatedKeys, withWarnings); + } else if (isOkUpdated()) { + str = activity.getResources().getQuantityString( + R.plurals.import_keys_updated, mUpdatedKeys, mUpdatedKeys, withWarnings); + } else if (isOkNew()) { + str = activity.getResources().getQuantityString( + R.plurals.import_keys_added, mNewKeys, mNewKeys, withWarnings); + } else { + duration = 0; + color = Style.RED; + str = "internal error"; + } + if (isOkWithErrors()) { + // definitely switch to warning-style message in this case! + duration = 0; + color = Style.RED; + str += " " + activity.getResources().getQuantityString( + R.plurals.import_keys_with_errors, mBadKeys, mBadKeys); + } + + } else { + duration = 0; + color = Style.RED; + if (isFailNothing()) { + str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0 + ? R.string.import_error_nothing_cancelled + : R.string.import_error_nothing); + } else { + str = activity.getResources().getQuantityString(R.plurals.import_error, mBadKeys); + } + } + + boolean button = getLog() != null && !getLog().isEmpty(); + SuperCardToast toast = new SuperCardToast(activity, + button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, + Style.getStyle(color, SuperToast.Animations.POPUP)); + toast.setText(str); + toast.setDuration(duration); + toast.setIndeterminate(duration == 0); + toast.setSwipeToDismiss(true); + // If we have a log and it's non-empty, show a View Log button + if (button) { + toast.setButtonIcon(R.drawable.ic_action_view_as_list, + activity.getResources().getString(R.string.view_log)); + toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); + toast.setTextColor(activity.getResources().getColor(R.color.black)); + toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", + new SuperToast.OnClickListener() { + @Override + public void onClick(View view, Parcelable token) { + Intent intent = new Intent( + activity, LogDisplayActivity.class); + intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this); + activity.startActivity(intent); + } + } + )); + } + + return toast; + + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java new file mode 100644 index 000000000..45470ef20 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java @@ -0,0 +1,710 @@ +/* + * 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.operations.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. + * + */ +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() { + // If there is only a single entry, and it's a compound one, return that log + if (mLog.isSingleCompound()) { + return ((SubLogEntryParcel) mLog.getFirst()).getSubResult().getLog(); + } + // Otherwse, return our regular log + return mLog; + } + + /** One entry in the log. */ + public static class LogEntryParcel implements Parcelable { + public final LogType mType; + public final Object[] mParameters; + public final int mIndent; + + public LogEntryParcel(LogType type, int indent, Object... parameters) { + mType = type; + mParameters = parameters; + mIndent = indent; + Log.v(Constants.TAG, "log: " + this); + } + + public LogEntryParcel(Parcel source) { + 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(0); + dest.writeInt(mType.ordinal()); + dest.writeSerializable(mParameters); + dest.writeInt(mIndent); + } + + public static final Creator CREATOR = new Creator() { + public LogEntryParcel createFromParcel(final Parcel source) { + // Actually create LogEntryParcel or SubLogEntryParcel depending on type indicator + if (source.readInt() == 0) { + return new LogEntryParcel(source); + } else { + return new SubLogEntryParcel(source); + } + } + + public LogEntryParcel[] newArray(final int size) { + return new LogEntryParcel[size]; + } + }; + + @Override + public String toString() { + return getClass().getSimpleName() + "{" + + "mLevel=" + mType.mLevel + + ", mType=" + mType + + ", mParameters=" + Arrays.toString(mParameters) + + ", mIndent=" + mIndent + + '}'; + } + } + + public static class SubLogEntryParcel extends LogEntryParcel { + + OperationResult mSubResult; + + public SubLogEntryParcel(OperationResult subResult, LogType type, int indent, Object... parameters) { + super(type, indent, parameters); + mSubResult = subResult; + + Log.v(Constants.TAG, "log: " + this); + } + + public SubLogEntryParcel(Parcel source) { + super(source); + mSubResult = source.readParcelable(SubLogEntryParcel.class.getClassLoader()); + } + + public OperationResult getSubResult() { + return mSubResult; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(1); + dest.writeInt(mType.ordinal()); + dest.writeSerializable(mParameters); + dest.writeInt(mIndent); + dest.writeParcelable(mSubResult, 0); + } + + } + + public SuperCardToast createNotify(final Activity activity) { + + int color; + + Log.d(Constants.TAG, "mLog.getLast()"+mLog.getLast()); + Log.d(Constants.TAG, "mLog.getLast().mType"+mLog.getLast().mType); + Log.d(Constants.TAG, "mLog.getLast().mType.getMsgId()"+mLog.getLast().mType.getMsgId()); + + // 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 (LogLevel.ERROR, R.string.msg_internal_error), + MSG_OPERATION_CANCELLED (LogLevel.CANCELLED, R.string.msg_cancelled), + + // import public + MSG_IP(LogLevel.START, R.string.msg_ip), + MSG_IP_APPLY_BATCH (LogLevel.DEBUG, R.string.msg_ip_apply_batch), + MSG_IP_BAD_TYPE_SECRET (LogLevel.WARN, R.string.msg_ip_bad_type_secret), + MSG_IP_DELETE_OLD_FAIL (LogLevel.DEBUG, R.string.msg_ip_delete_old_fail), + MSG_IP_DELETE_OLD_OK (LogLevel.DEBUG, R.string.msg_ip_delete_old_ok), + MSG_IP_ENCODE_FAIL (LogLevel.DEBUG, R.string.msg_ip_encode_fail), + MSG_IP_ERROR_IO_EXC (LogLevel.ERROR, R.string.msg_ip_error_io_exc), + MSG_IP_ERROR_OP_EXC (LogLevel.ERROR, R.string.msg_ip_error_op_exc), + MSG_IP_ERROR_REMOTE_EX (LogLevel.ERROR, R.string.msg_ip_error_remote_ex), + MSG_IP_INSERT_KEYRING (LogLevel.DEBUG, R.string.msg_ip_insert_keyring), + MSG_IP_INSERT_SUBKEYS (LogLevel.DEBUG, R.string.msg_ip_insert_keys), + MSG_IP_PREPARE (LogLevel.DEBUG, R.string.msg_ip_prepare), + MSG_IP_REINSERT_SECRET (LogLevel.DEBUG, R.string.msg_ip_reinsert_secret), + MSG_IP_MASTER (LogLevel.DEBUG, R.string.msg_ip_master), + MSG_IP_MASTER_EXPIRED (LogLevel.DEBUG, R.string.msg_ip_master_expired), + MSG_IP_MASTER_EXPIRES (LogLevel.DEBUG, R.string.msg_ip_master_expires), + MSG_IP_MASTER_FLAGS_UNSPECIFIED (LogLevel.DEBUG, R.string.msg_ip_master_flags_unspecified), + MSG_IP_MASTER_FLAGS_CESA (LogLevel.DEBUG, R.string.msg_ip_master_flags_cesa), + MSG_IP_MASTER_FLAGS_CESX (LogLevel.DEBUG, R.string.msg_ip_master_flags_cesx), + MSG_IP_MASTER_FLAGS_CEXA (LogLevel.DEBUG, R.string.msg_ip_master_flags_cexa), + MSG_IP_MASTER_FLAGS_CEXX (LogLevel.DEBUG, R.string.msg_ip_master_flags_cexx), + MSG_IP_MASTER_FLAGS_CXSA (LogLevel.DEBUG, R.string.msg_ip_master_flags_cxsa), + MSG_IP_MASTER_FLAGS_CXSX (LogLevel.DEBUG, R.string.msg_ip_master_flags_cxsx), + MSG_IP_MASTER_FLAGS_CXXA (LogLevel.DEBUG, R.string.msg_ip_master_flags_cxxa), + MSG_IP_MASTER_FLAGS_CXXX (LogLevel.DEBUG, R.string.msg_ip_master_flags_cxxx), + MSG_IP_MASTER_FLAGS_XESA (LogLevel.DEBUG, R.string.msg_ip_master_flags_xesa), + MSG_IP_MASTER_FLAGS_XESX (LogLevel.DEBUG, R.string.msg_ip_master_flags_xesx), + MSG_IP_MASTER_FLAGS_XEXA (LogLevel.DEBUG, R.string.msg_ip_master_flags_xexa), + MSG_IP_MASTER_FLAGS_XEXX (LogLevel.DEBUG, R.string.msg_ip_master_flags_xexx), + MSG_IP_MASTER_FLAGS_XXSA (LogLevel.DEBUG, R.string.msg_ip_master_flags_xxsa), + MSG_IP_MASTER_FLAGS_XXSX (LogLevel.DEBUG, R.string.msg_ip_master_flags_xxsx), + MSG_IP_MASTER_FLAGS_XXXA (LogLevel.DEBUG, R.string.msg_ip_master_flags_xxxa), + MSG_IP_MASTER_FLAGS_XXXX (LogLevel.DEBUG, R.string.msg_ip_master_flags_xxxx), + MSG_IP_SUBKEY (LogLevel.DEBUG, R.string.msg_ip_subkey), + MSG_IP_SUBKEY_EXPIRED (LogLevel.DEBUG, R.string.msg_ip_subkey_expired), + MSG_IP_SUBKEY_EXPIRES (LogLevel.DEBUG, R.string.msg_ip_subkey_expires), + MSG_IP_SUBKEY_FLAGS_UNSPECIFIED (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cesa), + MSG_IP_SUBKEY_FLAGS_CESA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cesa), + MSG_IP_SUBKEY_FLAGS_CESX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cesx), + MSG_IP_SUBKEY_FLAGS_CEXA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cexa), + MSG_IP_SUBKEY_FLAGS_CEXX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cexx), + MSG_IP_SUBKEY_FLAGS_CXSA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cxsa), + MSG_IP_SUBKEY_FLAGS_CXSX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cxsx), + MSG_IP_SUBKEY_FLAGS_CXXA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cxxa), + MSG_IP_SUBKEY_FLAGS_CXXX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cxxx), + MSG_IP_SUBKEY_FLAGS_XESA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xesa), + MSG_IP_SUBKEY_FLAGS_XESX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xesx), + MSG_IP_SUBKEY_FLAGS_XEXA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xexa), + MSG_IP_SUBKEY_FLAGS_XEXX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xexx), + MSG_IP_SUBKEY_FLAGS_XXSA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xxsa), + MSG_IP_SUBKEY_FLAGS_XXSX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xxsx), + MSG_IP_SUBKEY_FLAGS_XXXA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xxxa), + MSG_IP_SUBKEY_FLAGS_XXXX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xxxx), + MSG_IP_SUCCESS (LogLevel.OK, R.string.msg_ip_success), + MSG_IP_SUCCESS_IDENTICAL (LogLevel.OK, R.string.msg_ip_success_identical), + MSG_IP_UID_CERT_BAD (LogLevel.WARN, R.string.msg_ip_uid_cert_bad), + MSG_IP_UID_CERT_ERROR (LogLevel.WARN, R.string.msg_ip_uid_cert_error), + MSG_IP_UID_CERT_OLD (LogLevel.DEBUG, R.string.msg_ip_uid_cert_old), + MSG_IP_UID_CERT_NONREVOKE (LogLevel.DEBUG, R.string.msg_ip_uid_cert_nonrevoke), + MSG_IP_UID_CERT_NEW (LogLevel.DEBUG, R.string.msg_ip_uid_cert_new), + MSG_IP_UID_CERT_GOOD (LogLevel.DEBUG, R.string.msg_ip_uid_cert_good), + MSG_IP_UID_CERT_GOOD_REVOKE (LogLevel.DEBUG, R.string.msg_ip_uid_cert_good_revoke), + MSG_IP_UID_CERTS_UNKNOWN (LogLevel.DEBUG, R.plurals.msg_ip_uid_certs_unknown), + MSG_IP_UID_CLASSIFYING_ZERO (LogLevel.DEBUG, R.string.msg_ip_uid_classifying_zero), + MSG_IP_UID_CLASSIFYING (LogLevel.DEBUG, R.plurals.msg_ip_uid_classifying), + MSG_IP_UID_REORDER(LogLevel.DEBUG, R.string.msg_ip_uid_reorder), + MSG_IP_UID_PROCESSING (LogLevel.DEBUG, R.string.msg_ip_uid_processing), + MSG_IP_UID_REVOKED (LogLevel.DEBUG, R.string.msg_ip_uid_revoked), + + // import secret + MSG_IS(LogLevel.START, R.string.msg_is), + MSG_IS_BAD_TYPE_PUBLIC (LogLevel.WARN, R.string.msg_is_bad_type_public), + MSG_IS_DB_EXCEPTION (LogLevel.DEBUG, R.string.msg_is_db_exception), + MSG_IS_ERROR_IO_EXC(LogLevel.DEBUG, R.string.msg_is_error_io_exc), + MSG_IS_IMPORTING_SUBKEYS (LogLevel.DEBUG, R.string.msg_is_importing_subkeys), + MSG_IS_PUBRING_GENERATE (LogLevel.DEBUG, R.string.msg_is_pubring_generate), + MSG_IS_SUBKEY_NONEXISTENT (LogLevel.DEBUG, R.string.msg_is_subkey_nonexistent), + MSG_IS_SUBKEY_OK (LogLevel.OK, R.string.msg_is_subkey_ok), + MSG_IS_SUBKEY_STRIPPED (LogLevel.DEBUG, R.string.msg_is_subkey_stripped), + MSG_IS_SUBKEY_DIVERT (LogLevel.DEBUG, R.string.msg_is_subkey_divert), + MSG_IS_SUBKEY_EMPTY (LogLevel.DEBUG, R.string.msg_is_subkey_empty), + MSG_IS_SUCCESS_IDENTICAL (LogLevel.OK, R.string.msg_is_success_identical), + MSG_IS_SUCCESS (LogLevel.OK, R.string.msg_is_success), + + // keyring canonicalization + MSG_KC_PUBLIC (LogLevel.DEBUG, R.string.msg_kc_public), + MSG_KC_SECRET (LogLevel.DEBUG, R.string.msg_kc_secret), + MSG_KC_ERROR_V3 (LogLevel.ERROR, R.string.msg_kc_error_v3), + MSG_KC_ERROR_NO_UID (LogLevel.ERROR, R.string.msg_kc_error_no_uid), + MSG_KC_ERROR_MASTER_ALGO (LogLevel.ERROR, R.string.msg_kc_error_master_algo), + MSG_KC_ERROR_DUP_KEY (LogLevel.ERROR, R.string.msg_kc_error_dup_key), + MSG_KC_MASTER (LogLevel.DEBUG, R.string.msg_kc_master), + MSG_KC_REVOKE_BAD_ERR (LogLevel.WARN, R.string.msg_kc_revoke_bad_err), + MSG_KC_REVOKE_BAD_LOCAL (LogLevel.WARN, R.string.msg_kc_revoke_bad_local), + MSG_KC_REVOKE_BAD_TIME (LogLevel.WARN, R.string.msg_kc_revoke_bad_time), + MSG_KC_REVOKE_BAD_TYPE (LogLevel.WARN, R.string.msg_kc_revoke_bad_type), + MSG_KC_REVOKE_BAD_TYPE_UID (LogLevel.WARN, R.string.msg_kc_revoke_bad_type_uid), + MSG_KC_REVOKE_BAD (LogLevel.WARN, R.string.msg_kc_revoke_bad), + MSG_KC_REVOKE_DUP (LogLevel.DEBUG, R.string.msg_kc_revoke_dup), + MSG_KC_SUB (LogLevel.DEBUG, R.string.msg_kc_sub), + MSG_KC_SUB_BAD(LogLevel.WARN, R.string.msg_kc_sub_bad), + MSG_KC_SUB_BAD_ERR(LogLevel.WARN, R.string.msg_kc_sub_bad_err), + MSG_KC_SUB_BAD_LOCAL(LogLevel.WARN, R.string.msg_kc_sub_bad_local), + MSG_KC_SUB_BAD_KEYID(LogLevel.WARN, R.string.msg_kc_sub_bad_keyid), + MSG_KC_SUB_BAD_TIME(LogLevel.WARN, R.string.msg_kc_sub_bad_time), + MSG_KC_SUB_BAD_TYPE(LogLevel.WARN, R.string.msg_kc_sub_bad_type), + MSG_KC_SUB_DUP (LogLevel.DEBUG, R.string.msg_kc_sub_dup), + MSG_KC_SUB_PRIMARY_BAD(LogLevel.WARN, R.string.msg_kc_sub_primary_bad), + MSG_KC_SUB_PRIMARY_BAD_ERR(LogLevel.WARN, R.string.msg_kc_sub_primary_bad_err), + MSG_KC_SUB_PRIMARY_NONE(LogLevel.DEBUG, R.string.msg_kc_sub_primary_none), + MSG_KC_SUB_NO_CERT(LogLevel.DEBUG, R.string.msg_kc_sub_no_cert), + MSG_KC_SUB_REVOKE_BAD_ERR (LogLevel.WARN, R.string.msg_kc_sub_revoke_bad_err), + MSG_KC_SUB_REVOKE_BAD (LogLevel.WARN, R.string.msg_kc_sub_revoke_bad), + MSG_KC_SUB_REVOKE_DUP (LogLevel.DEBUG, R.string.msg_kc_sub_revoke_dup), + MSG_KC_SUB_UNKNOWN_ALGO (LogLevel.WARN, R.string.msg_kc_sub_unknown_algo), + MSG_KC_SUB_ALGO_BAD_ENCRYPT (LogLevel.WARN, R.string.msg_kc_sub_algo_bad_encrpyt), + MSG_KC_SUB_ALGO_BAD_SIGN (LogLevel.WARN, R.string.msg_kc_sub_algo_bad_sign), + MSG_KC_SUCCESS_BAD (LogLevel.OK, R.plurals.msg_kc_success_bad), + MSG_KC_SUCCESS_BAD_AND_RED (LogLevel.OK, R.string.msg_kc_success_bad_and_red), + MSG_KC_SUCCESS_REDUNDANT (LogLevel.OK, R.plurals.msg_kc_success_redundant), + MSG_KC_SUCCESS (LogLevel.OK, R.string.msg_kc_success), + MSG_KC_UID_BAD_ERR (LogLevel.WARN, R.string.msg_kc_uid_bad_err), + MSG_KC_UID_BAD_LOCAL (LogLevel.WARN, R.string.msg_kc_uid_bad_local), + MSG_KC_UID_BAD_TIME (LogLevel.WARN, R.string.msg_kc_uid_bad_time), + MSG_KC_UID_BAD_TYPE (LogLevel.WARN, R.string.msg_kc_uid_bad_type), + MSG_KC_UID_BAD (LogLevel.WARN, R.string.msg_kc_uid_bad), + MSG_KC_UID_CERT_DUP (LogLevel.DEBUG, R.string.msg_kc_uid_cert_dup), + MSG_KC_UID_DUP (LogLevel.DEBUG, R.string.msg_kc_uid_dup), + MSG_KC_UID_FOREIGN (LogLevel.DEBUG, R.string.msg_kc_uid_foreign), + MSG_KC_UID_NO_CERT (LogLevel.DEBUG, R.string.msg_kc_uid_no_cert), + MSG_KC_UID_REVOKE_DUP (LogLevel.DEBUG, R.string.msg_kc_uid_revoke_dup), + MSG_KC_UID_REVOKE_OLD (LogLevel.DEBUG, R.string.msg_kc_uid_revoke_old), + MSG_KC_UID_REMOVE (LogLevel.DEBUG, R.string.msg_kc_uid_remove), + MSG_KC_UID_WARN_ENCODING (LogLevel.WARN, R.string.msg_kc_uid_warn_encoding), + + + // keyring consolidation + MSG_MG_ERROR_SECRET_DUMMY(LogLevel.ERROR, R.string.msg_mg_error_secret_dummy), + MSG_MG_ERROR_ENCODE(LogLevel.ERROR, R.string.msg_mg_error_encode), + MSG_MG_ERROR_HETEROGENEOUS(LogLevel.ERROR, R.string.msg_mg_error_heterogeneous), + MSG_MG_PUBLIC (LogLevel.START, R.string.msg_mg_public), + MSG_MG_SECRET (LogLevel.START, R.string.msg_mg_secret), + MSG_MG_NEW_SUBKEY (LogLevel.DEBUG, R.string.msg_mg_new_subkey), + MSG_MG_FOUND_NEW (LogLevel.OK, R.string.msg_mg_found_new), + MSG_MG_UNCHANGED (LogLevel.OK, R.string.msg_mg_unchanged), + + // secret key create + MSG_CR (LogLevel.START, R.string.msg_cr), + MSG_CR_ERROR_NO_MASTER (LogLevel.ERROR, R.string.msg_cr_error_no_master), + MSG_CR_ERROR_NO_USER_ID (LogLevel.ERROR, R.string.msg_cr_error_no_user_id), + MSG_CR_ERROR_NO_CERTIFY (LogLevel.ERROR, R.string.msg_cr_error_no_certify), + MSG_CR_ERROR_NULL_EXPIRY(LogLevel.ERROR, R.string.msg_cr_error_null_expiry), + MSG_CR_ERROR_KEYSIZE_512 (LogLevel.ERROR, R.string.msg_cr_error_keysize_512), + MSG_CR_ERROR_NO_KEYSIZE (LogLevel.ERROR, R.string.msg_cr_error_no_keysize), + MSG_CR_ERROR_NO_CURVE (LogLevel.ERROR, R.string.msg_cr_error_no_curve), + MSG_CR_ERROR_UNKNOWN_ALGO (LogLevel.ERROR, R.string.msg_cr_error_unknown_algo), + MSG_CR_ERROR_INTERNAL_PGP (LogLevel.ERROR, R.string.msg_cr_error_internal_pgp), + MSG_CR_ERROR_FLAGS_DSA (LogLevel.ERROR, R.string.msg_cr_error_flags_dsa), + MSG_CR_ERROR_FLAGS_ELGAMAL (LogLevel.ERROR, R.string.msg_cr_error_flags_elgamal), + MSG_CR_ERROR_FLAGS_ECDSA (LogLevel.ERROR, R.string.msg_cr_error_flags_ecdsa), + MSG_CR_ERROR_FLAGS_ECDH (LogLevel.ERROR, R.string.msg_cr_error_flags_ecdh), + + // secret key modify + MSG_MF (LogLevel.START, R.string.msg_mr), + MSG_MF_ERROR_ENCODE (LogLevel.ERROR, R.string.msg_mf_error_encode), + MSG_MF_ERROR_FINGERPRINT (LogLevel.ERROR, R.string.msg_mf_error_fingerprint), + MSG_MF_ERROR_KEYID (LogLevel.ERROR, R.string.msg_mf_error_keyid), + MSG_MF_ERROR_INTEGRITY (LogLevel.ERROR, R.string.msg_mf_error_integrity), + MSG_MF_ERROR_MASTER_NONE(LogLevel.ERROR, R.string.msg_mf_error_master_none), + MSG_MF_ERROR_NO_CERTIFY (LogLevel.ERROR, R.string.msg_cr_error_no_certify), + MSG_MF_ERROR_NOEXIST_PRIMARY (LogLevel.ERROR, R.string.msg_mf_error_noexist_primary), + MSG_MF_ERROR_NOEXIST_REVOKE (LogLevel.ERROR, R.string.msg_mf_error_noexist_revoke), + MSG_MF_ERROR_NULL_EXPIRY (LogLevel.ERROR, R.string.msg_mf_error_null_expiry), + MSG_MF_ERROR_PASSPHRASE_MASTER(LogLevel.ERROR, R.string.msg_mf_error_passphrase_master), + MSG_MF_ERROR_PAST_EXPIRY(LogLevel.ERROR, R.string.msg_mf_error_past_expiry), + MSG_MF_ERROR_PGP (LogLevel.ERROR, R.string.msg_mf_error_pgp), + MSG_MF_ERROR_REVOKED_PRIMARY (LogLevel.ERROR, R.string.msg_mf_error_revoked_primary), + MSG_MF_ERROR_SIG (LogLevel.ERROR, R.string.msg_mf_error_sig), + MSG_MF_ERROR_SUBKEY_MISSING(LogLevel.ERROR, R.string.msg_mf_error_subkey_missing), + MSG_MF_MASTER (LogLevel.DEBUG, R.string.msg_mf_master), + MSG_MF_PASSPHRASE (LogLevel.INFO, R.string.msg_mf_passphrase), + MSG_MF_PASSPHRASE_KEY (LogLevel.DEBUG, R.string.msg_mf_passphrase_key), + MSG_MF_PASSPHRASE_EMPTY_RETRY (LogLevel.DEBUG, R.string.msg_mf_passphrase_empty_retry), + MSG_MF_PASSPHRASE_FAIL (LogLevel.WARN, R.string.msg_mf_passphrase_fail), + MSG_MF_PRIMARY_REPLACE_OLD (LogLevel.DEBUG, R.string.msg_mf_primary_replace_old), + MSG_MF_PRIMARY_NEW (LogLevel.DEBUG, R.string.msg_mf_primary_new), + MSG_MF_SUBKEY_CHANGE (LogLevel.INFO, R.string.msg_mf_subkey_change), + MSG_MF_SUBKEY_NEW_ID (LogLevel.DEBUG, R.string.msg_mf_subkey_new_id), + MSG_MF_SUBKEY_NEW (LogLevel.INFO, R.string.msg_mf_subkey_new), + MSG_MF_SUBKEY_REVOKE (LogLevel.INFO, R.string.msg_mf_subkey_revoke), + MSG_MF_SUBKEY_STRIP (LogLevel.INFO, R.string.msg_mf_subkey_strip), + MSG_MF_SUCCESS (LogLevel.OK, R.string.msg_mf_success), + MSG_MF_UID_ADD (LogLevel.INFO, R.string.msg_mf_uid_add), + MSG_MF_UID_PRIMARY (LogLevel.INFO, R.string.msg_mf_uid_primary), + MSG_MF_UID_REVOKE (LogLevel.INFO, R.string.msg_mf_uid_revoke), + MSG_MF_UID_ERROR_EMPTY (LogLevel.ERROR, R.string.msg_mf_uid_error_empty), + MSG_MF_UNLOCK_ERROR (LogLevel.ERROR, R.string.msg_mf_unlock_error), + MSG_MF_UNLOCK (LogLevel.DEBUG, R.string.msg_mf_unlock), + + // consolidate + MSG_CON_CRITICAL_IN (LogLevel.DEBUG, R.string.msg_con_critical_in), + MSG_CON_CRITICAL_OUT (LogLevel.DEBUG, R.string.msg_con_critical_out), + MSG_CON_DB_CLEAR (LogLevel.DEBUG, R.string.msg_con_db_clear), + MSG_CON_DELETE_PUBLIC (LogLevel.DEBUG, R.string.msg_con_delete_public), + MSG_CON_DELETE_SECRET (LogLevel.DEBUG, R.string.msg_con_delete_secret), + MSG_CON_ERROR_BAD_STATE (LogLevel.ERROR, R.string.msg_con_error_bad_state), + MSG_CON_ERROR_CONCURRENT(LogLevel.ERROR, R.string.msg_con_error_concurrent), + MSG_CON_ERROR_DB (LogLevel.ERROR, R.string.msg_con_error_db), + MSG_CON_ERROR_IO_PUBLIC (LogLevel.ERROR, R.string.msg_con_error_io_public), + MSG_CON_ERROR_IO_SECRET (LogLevel.ERROR, R.string.msg_con_error_io_secret), + MSG_CON_ERROR_PUBLIC (LogLevel.ERROR, R.string.msg_con_error_public), + MSG_CON_ERROR_SECRET (LogLevel.ERROR, R.string.msg_con_error_secret), + MSG_CON_RECOVER (LogLevel.DEBUG, R.string.msg_con_recover), + MSG_CON_REIMPORT_PUBLIC (LogLevel.DEBUG, R.plurals.msg_con_reimport_public), + MSG_CON_REIMPORT_PUBLIC_SKIP (LogLevel.DEBUG, R.string.msg_con_reimport_public_skip), + MSG_CON_REIMPORT_SECRET (LogLevel.DEBUG, R.plurals.msg_con_reimport_secret), + MSG_CON_REIMPORT_SECRET_SKIP (LogLevel.DEBUG, R.string.msg_con_reimport_secret_skip), + MSG_CON (LogLevel.START, R.string.msg_con), + MSG_CON_SAVE_PUBLIC (LogLevel.DEBUG, R.string.msg_con_save_public), + MSG_CON_SAVE_SECRET (LogLevel.DEBUG, R.string.msg_con_save_secret), + MSG_CON_SUCCESS (LogLevel.OK, R.string.msg_con_success), + MSG_CON_WARN_DELETE_PUBLIC (LogLevel.WARN, R.string.msg_con_warn_delete_public), + MSG_CON_WARN_DELETE_SECRET (LogLevel.WARN, R.string.msg_con_warn_delete_secret), + + // messages used in UI code + MSG_EK_ERROR_DIVERT (LogLevel.ERROR, R.string.msg_ek_error_divert), + MSG_EK_ERROR_DUMMY (LogLevel.ERROR, R.string.msg_ek_error_dummy), + MSG_EK_ERROR_NOT_FOUND (LogLevel.ERROR, R.string.msg_ek_error_not_found), + + // decryptverify + MSG_DC_ASKIP_NO_KEY (LogLevel.DEBUG, R.string.msg_dc_askip_no_key), + MSG_DC_ASKIP_NOT_ALLOWED (LogLevel.DEBUG, R.string.msg_dc_askip_not_allowed), + MSG_DC_ASYM (LogLevel.DEBUG, R.string.msg_dc_asym), + MSG_DC_CLEAR_DATA (LogLevel.DEBUG, R.string.msg_dc_clear_data), + MSG_DC_CLEAR_DECOMPRESS (LogLevel.DEBUG, R.string.msg_dc_clear_decompress), + MSG_DC_CLEAR_META_FILE (LogLevel.DEBUG, R.string.msg_dc_clear_meta_file), + MSG_DC_CLEAR_META_MIME (LogLevel.DEBUG, R.string.msg_dc_clear_meta_mime), + MSG_DC_CLEAR_META_SIZE (LogLevel.DEBUG, R.string.msg_dc_clear_meta_size), + MSG_DC_CLEAR_META_TIME (LogLevel.DEBUG, R.string.msg_dc_clear_meta_time), + MSG_DC_CLEAR (LogLevel.DEBUG, R.string.msg_dc_clear), + MSG_DC_CLEAR_SIGNATURE_BAD (LogLevel.WARN, R.string.msg_dc_clear_signature_bad), + MSG_DC_CLEAR_SIGNATURE_CHECK (LogLevel.DEBUG, R.string.msg_dc_clear_signature_check), + MSG_DC_CLEAR_SIGNATURE_OK (LogLevel.OK, R.string.msg_dc_clear_signature_ok), + MSG_DC_CLEAR_SIGNATURE (LogLevel.DEBUG, R.string.msg_dc_clear_signature), + MSG_DC_ERROR_BAD_PASSPHRASE (LogLevel.ERROR, R.string.msg_dc_error_bad_passphrase), + MSG_DC_ERROR_EXTRACT_KEY (LogLevel.ERROR, R.string.msg_dc_error_extract_key), + MSG_DC_ERROR_INTEGRITY_CHECK (LogLevel.ERROR, R.string.msg_dc_error_integrity_check), + MSG_DC_ERROR_INVALID_SIGLIST(LogLevel.ERROR, R.string.msg_dc_error_invalid_siglist), + MSG_DC_ERROR_IO (LogLevel.ERROR, R.string.msg_dc_error_io), + MSG_DC_ERROR_NO_DATA (LogLevel.ERROR, R.string.msg_dc_error_no_data), + MSG_DC_ERROR_NO_KEY (LogLevel.ERROR, R.string.msg_dc_error_no_key), + MSG_DC_ERROR_PGP_EXCEPTION (LogLevel.ERROR, R.string.msg_dc_error_pgp_exception), + MSG_DC_INTEGRITY_CHECK_OK (LogLevel.INFO, R.string.msg_dc_integrity_check_ok), + MSG_DC_OK_META_ONLY (LogLevel.OK, R.string.msg_dc_ok_meta_only), + MSG_DC_OK (LogLevel.OK, R.string.msg_dc_ok), + MSG_DC_PASS_CACHED (LogLevel.DEBUG, R.string.msg_dc_pass_cached), + MSG_DC_PENDING_NFC (LogLevel.INFO, R.string.msg_dc_pending_nfc), + MSG_DC_PENDING_PASSPHRASE (LogLevel.INFO, R.string.msg_dc_pending_passphrase), + MSG_DC_PREP_STREAMS (LogLevel.DEBUG, R.string.msg_dc_prep_streams), + MSG_DC (LogLevel.DEBUG, R.string.msg_dc), + MSG_DC_SYM (LogLevel.DEBUG, R.string.msg_dc_sym), + MSG_DC_SYM_SKIP (LogLevel.DEBUG, R.string.msg_dc_sym_skip), + MSG_DC_TRAIL_ASYM (LogLevel.DEBUG, R.string.msg_dc_trail_asym), + MSG_DC_TRAIL_SYM (LogLevel.DEBUG, R.string.msg_dc_trail_sym), + MSG_DC_TRAIL_UNKNOWN (LogLevel.DEBUG, R.string.msg_dc_trail_unknown), + MSG_DC_UNLOCKING (LogLevel.INFO, R.string.msg_dc_unlocking), + + // signencrypt + MSG_SE_ASYMMETRIC (LogLevel.INFO, R.string.msg_se_asymmetric), + MSG_SE_CLEARSIGN_ONLY (LogLevel.DEBUG, R.string.msg_se_clearsign_only), + MSG_SE_COMPRESSING (LogLevel.DEBUG, R.string.msg_se_compressing), + MSG_SE_ENCRYPTING (LogLevel.DEBUG, R.string.msg_se_encrypting), + MSG_SE_ERROR_BAD_PASSPHRASE (LogLevel.ERROR, R.string.msg_se_error_bad_passphrase), + MSG_SE_ERROR_IO (LogLevel.ERROR, R.string.msg_se_error_io), + MSG_SE_ERROR_SIGN_KEY(LogLevel.ERROR, R.string.msg_se_error_sign_key), + MSG_SE_ERROR_KEY_SIGN (LogLevel.ERROR, R.string.msg_se_error_key_sign), + MSG_SE_ERROR_NFC (LogLevel.ERROR, R.string.msg_se_error_nfc), + MSG_SE_ERROR_PGP (LogLevel.ERROR, R.string.msg_se_error_pgp), + MSG_SE_ERROR_SIG (LogLevel.ERROR, R.string.msg_se_error_sig), + MSG_SE_ERROR_UNLOCK (LogLevel.ERROR, R.string.msg_se_error_unlock), + MSG_SE_KEY_OK (LogLevel.OK, R.string.msg_se_key_ok), + MSG_SE_KEY_UNKNOWN (LogLevel.DEBUG, R.string.msg_se_key_unknown), + MSG_SE_KEY_WARN (LogLevel.WARN, R.string.msg_se_key_warn), + MSG_SE_OK (LogLevel.OK, R.string.msg_se_ok), + MSG_SE_PENDING_NFC (LogLevel.INFO, R.string.msg_se_pending_nfc), + MSG_SE_PENDING_PASSPHRASE (LogLevel.INFO, R.string.msg_se_pending_passphrase), + MSG_SE (LogLevel.DEBUG, R.string.msg_se), + MSG_SE_SIGNING (LogLevel.DEBUG, R.string.msg_se_signing), + MSG_SE_SIGCRYPTING (LogLevel.DEBUG, R.string.msg_se_sigcrypting), + MSG_SE_SYMMETRIC (LogLevel.INFO, R.string.msg_se_symmetric), + + MSG_CRT_CERTIFYING (LogLevel.DEBUG, R.string.msg_crt_certifying), + MSG_CRT_CERTIFY_ALL (LogLevel.DEBUG, R.string.msg_crt_certify_all), + MSG_CRT_CERTIFY_SOME (LogLevel.DEBUG, R.plurals.msg_crt_certify_some), + MSG_CRT_ERROR_MASTER_NOT_FOUND (LogLevel.ERROR, R.string.msg_crt_error_master_not_found), + MSG_CRT_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_crt_error_nothing), + MSG_CRT_ERROR_UNLOCK (LogLevel.ERROR, R.string.msg_crt_error_unlock), + MSG_CRT (LogLevel.START, R.string.msg_crt), + MSG_CRT_MASTER_FETCH (LogLevel.DEBUG, R.string.msg_crt_master_fetch), + MSG_CRT_SAVE (LogLevel.DEBUG, R.string.msg_crt_save), + MSG_CRT_SAVING (LogLevel.DEBUG, R.string.msg_crt_saving), + MSG_CRT_SUCCESS (LogLevel.OK, R.string.msg_crt_success), + MSG_CRT_UNLOCK (LogLevel.DEBUG, R.string.msg_crt_unlock), + MSG_CRT_WARN_NOT_FOUND (LogLevel.WARN, R.string.msg_crt_warn_not_found), + MSG_CRT_WARN_CERT_FAILED (LogLevel.WARN, R.string.msg_crt_warn_cert_failed), + MSG_CRT_WARN_SAVE_FAILED (LogLevel.WARN, R.string.msg_crt_warn_save_failed), + + MSG_CRT_UPLOAD_SUCCESS (LogLevel.OK, R.string.msg_crt_upload_success), + + MSG_ACC_SAVED (LogLevel.INFO, R.string.api_settings_save_msg), + + MSG_NO_VALID_ENC (LogLevel.ERROR, R.string.error_invalid_data), + + // get key + MSG_GET_SUCCESS(LogLevel.OK, R.string.msg_download_success), + MSG_GET_NO_VALID_KEYS(LogLevel.ERROR, R.string.msg_download_no_valid_keys), + MSG_GET_NO_PGP_PARTS(LogLevel.ERROR, R.string.msg_download_no_pgp_parts), + MSG_GET_QUERY_TOO_SHORT(LogLevel.ERROR, R.string.msg_download_query_too_short), + MSG_GET_TOO_MANY_RESPONSES(LogLevel.ERROR, R.string.msg_download_too_many_responses), + MSG_GET_QUERY_TOO_SHORT_OR_TOO_MANY_RESPONSES(LogLevel.ERROR, R.string.msg_download_query_too_short_or_too_many_responses), + MSG_GET_QUERY_FAILED(LogLevel.ERROR, R.string.msg_download_query_failed) + ; + + public final int mMsgId; + public final LogLevel mLevel; + LogType(LogLevel level, int msgId) { + mLevel = level; + 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(LogType type, int indent, Object... parameters) { + mParcels.add(new OperationResult.LogEntryParcel(type, indent, parameters)); + } + + public void add(LogType type, int indent) { + mParcels.add(new OperationResult.LogEntryParcel(type, indent, (Object[]) null)); + } + + public void add(OperationResult subResult, int indent) { + OperationLog subLog = subResult.getLog(); + mParcels.add(new SubLogEntryParcel(subResult, subLog.getFirst().mType, indent, subLog.getFirst().mParameters)); + } + + boolean isSingleCompound() { + return mParcels.size() == 1 && getFirst() instanceof SubLogEntryParcel; + } + + public void clear() { + mParcels.clear(); + } + + 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.mType.mLevel == LogLevel.WARN || entry.mType.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 getFirst() { + if (mParcels.isEmpty()) { + return null; + } + return mParcels.get(0); + } + + 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/operations/results/SaveKeyringResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/SaveKeyringResult.java new file mode 100644 index 000000000..26d473ef3 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/SaveKeyringResult.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2014 Dominik Schürmann + * Copyright (C) 2014 Vincent Breitmoser + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.sufficientlysecure.keychain.operations.results; + +import android.os.Parcel; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; + +public class SaveKeyringResult extends OperationResult { + + public final long mRingMasterKeyId; + + public SaveKeyringResult(int result, OperationLog log, + CanonicalizedKeyRing ring) { + super(result, log); + mRingMasterKeyId = ring != null ? ring.getMasterKeyId() : Constants.key.none; + } + + // Some old key was updated + public static final int UPDATED = 4; + + // Public key was saved + public static final int SAVED_PUBLIC = 8; + // Secret key was saved (not exclusive with public!) + public static final int SAVED_SECRET = 16; + + public boolean updated() { + return (mResult & UPDATED) == UPDATED; + } + + public SaveKeyringResult(Parcel source) { + super(source); + mRingMasterKeyId = source.readLong(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeLong(mRingMasterKeyId); + } + + public static Creator CREATOR = new Creator() { + public SaveKeyringResult createFromParcel(final Parcel source) { + return new SaveKeyringResult(source); + } + + public SaveKeyringResult[] newArray(final int size) { + return new SaveKeyringResult[size]; + } + }; +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/SignEncryptResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/SignEncryptResult.java new file mode 100644 index 000000000..57daf3430 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/SignEncryptResult.java @@ -0,0 +1,123 @@ +/* + * 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.operations.results; + +import android.os.Parcel; + +import java.util.Date; + +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; + + // fifth to sixth bit in addition indicate specific type of pending + public static final int RESULT_PENDING_PASSPHRASE = RESULT_PENDING + 16; + public static final int RESULT_PENDING_NFC = RESULT_PENDING + 32; + + long mKeyIdPassphraseNeeded; + + long mNfcKeyId; + byte[] mNfcHash; + int mNfcAlgo; + Date mNfcTimestamp; + String mNfcPassphrase; + + public long getKeyIdPassphraseNeeded() { + return mKeyIdPassphraseNeeded; + } + + public void setKeyIdPassphraseNeeded(long keyIdPassphraseNeeded) { + mKeyIdPassphraseNeeded = keyIdPassphraseNeeded; + } + + public void setNfcData(long nfcKeyId, byte[] nfcHash, int nfcAlgo, Date nfcTimestamp, String passphrase) { + mNfcKeyId = nfcKeyId; + mNfcHash = nfcHash; + mNfcAlgo = nfcAlgo; + mNfcTimestamp = nfcTimestamp; + mNfcPassphrase = passphrase; + } + + public long getNfcKeyId() { + return mNfcKeyId; + } + + public byte[] getNfcHash() { + return mNfcHash; + } + + public int getNfcAlgo() { + return mNfcAlgo; + } + + public Date getNfcTimestamp() { + return mNfcTimestamp; + } + + public String getNfcPassphrase() { + return mNfcPassphrase; + } + + public boolean isPending() { + return (mResult & RESULT_PENDING) == RESULT_PENDING; + } + + public SignEncryptResult(int result, OperationLog log) { + super(result, log); + } + + public SignEncryptResult(Parcel source) { + super(source); + mNfcHash = source.readInt() != 0 ? source.createByteArray() : null; + mNfcAlgo = source.readInt(); + mNfcTimestamp = source.readInt() != 0 ? new Date(source.readLong()) : null; + } + + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + if (mNfcHash != null) { + dest.writeInt(1); + dest.writeByteArray(mNfcHash); + } else { + dest.writeInt(0); + } + dest.writeInt(mNfcAlgo); + if (mNfcTimestamp != null) { + dest.writeInt(1); + dest.writeLong(mNfcTimestamp.getTime()); + } else { + dest.writeInt(0); + } + } + + public static final Creator CREATOR = new Creator() { + public SignEncryptResult createFromParcel(final Parcel source) { + return new SignEncryptResult(source); + } + + public SignEncryptResult[] newArray(final int size) { + return new SignEncryptResult[size]; + } + }; + +} \ No newline at end of file diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/SingletonResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/SingletonResult.java new file mode 100644 index 000000000..43cc85522 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/SingletonResult.java @@ -0,0 +1,87 @@ +/* + * 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.operations.results; + +import android.app.Activity; +import android.os.Parcel; + +import com.github.johnpersano.supertoasts.SuperCardToast; +import com.github.johnpersano.supertoasts.SuperToast; +import com.github.johnpersano.supertoasts.util.Style; + +/** This is a simple subclass meant to contain only a single log message. This log + * message is also shown without a log button in the createNotify SuperToast. */ +public class SingletonResult extends OperationResult { + + /** Construct from a parcel - trivial because we have no extra data. */ + public SingletonResult(Parcel source) { + super(source); + } + + public SingletonResult(int result, LogType reason) { + super(result, new OperationLog()); + // Prepare the log + mLog.add(reason, 0); + } + + @Override + public SuperCardToast createNotify(final Activity activity) { + + // there is exactly one error msg - use that one + String str = activity.getString(mLog.iterator().next().mType.getMsgId()); + int color; + + // Determine color by result type + if (cancelled()) { + color = Style.RED; + } else if (success()) { + if (getLog().containsWarnings()) { + color = Style.ORANGE; + } else { + color = Style.GREEN; + } + } else { + color = Style.RED; + } + + SuperCardToast toast = new SuperCardToast(activity, SuperToast.Type.STANDARD, + Style.getStyle(color, SuperToast.Animations.POPUP)); + toast.setText(str); + toast.setDuration(SuperToast.Duration.EXTRA_LONG); + toast.setIndeterminate(false); + toast.setSwipeToDismiss(true); + return toast; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + } + + public static Creator CREATOR = new Creator() { + public SingletonResult createFromParcel(final Parcel source) { + return new SingletonResult(source); + } + + public SingletonResult[] newArray(final int size) { + return new SingletonResult[size]; + } + }; + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java index 06488af44..383592356 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java @@ -48,9 +48,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.DecryptVerifyResult; -import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; -import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog; +import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; 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 43256fe28..6e45fab99 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.OperationResult; -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.operations.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; +import org.sufficientlysecure.keychain.operations.results.EditKeyResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Curve; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java index 6ffa30fe1..670f3bb3c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java @@ -38,9 +38,9 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; -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.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; +import org.sufficientlysecure.keychain.operations.results.SignEncryptResult; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; 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 17d35dc1f..2b2fbf4c2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java @@ -34,8 +34,8 @@ import org.spongycastle.openpgp.PGPUtil; import org.spongycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; -import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/BaseOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/BaseOperation.java deleted file mode 100644 index 811df7563..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/BaseOperation.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.sufficientlysecure.keychain.pgp.ops; - -import android.content.Context; - -import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.ProviderHelper; - -import java.util.concurrent.atomic.AtomicBoolean; - -public class BaseOperation { - - final public Context mContext; - final public Progressable mProgressable; - final public AtomicBoolean mCancelled; - - final public ProviderHelper mProviderHelper; - - // TODO do we really need the context in these operations? - public BaseOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { - this.mContext = context; - this.mProgressable = progressable; - this.mProviderHelper = providerHelper; - mCancelled = null; - } - - public BaseOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean cancelled) { - mContext = context; - mProgressable = progressable; - mProviderHelper = providerHelper; - mCancelled = cancelled; - } - - public void updateProgress(int message, int current, int total) { - if (mProgressable != null) { - mProgressable.setProgress(message, current, total); - } - } - - public void updateProgress(String message, int current, int total) { - if (mProgressable != null) { - mProgressable.setProgress(message, current, total); - } - } - - public void updateProgress(int current, int total) { - if (mProgressable != null) { - mProgressable.setProgress(current, total); - } - } - - protected boolean checkCancelled() { - return mCancelled != null && mCancelled.get(); - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/ImportExportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/ImportExportOperation.java deleted file mode 100644 index 32151c4d9..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/ImportExportOperation.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (C) 2012-2014 Dominik Schürmann - * Copyright (C) 2010-2014 Thialfihar - * - * 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.pgp.ops; - -import android.content.Context; -import android.os.Bundle; -import android.os.Environment; - -import org.spongycastle.bcpg.ArmoredOutputStream; -import org.spongycastle.openpgp.PGPException; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; -import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException; -import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; -import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; -import org.sufficientlysecure.keychain.pgp.PgpHelper; -import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -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.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.ui.util.KeyFormattingUtils; -import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.ProgressScaler; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.concurrent.atomic.AtomicBoolean; - -public class ImportExportOperation extends BaseOperation { - - public ImportExportOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { - super(context, providerHelper, progressable); - } - - public ImportExportOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); - } - - public void uploadKeyRingToServer(HkpKeyserver server, CanonicalizedPublicKeyRing keyring) throws AddKeyException { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ArmoredOutputStream aos = null; - try { - aos = new ArmoredOutputStream(bos); - keyring.encode(aos); - aos.close(); - - String armoredKey = bos.toString("UTF-8"); - server.add(armoredKey); - } catch (IOException e) { - Log.e(Constants.TAG, "IOException", e); - throw new AddKeyException(); - } finally { - try { - if (aos != null) { - aos.close(); - } - bos.close(); - } catch (IOException e) { - // this is just a finally thing, no matter if it doesn't work out. - } - } - } - - public ImportKeyResult importKeyRings(Iterator entries, int num) { - updateProgress(R.string.progress_importing, 0, 100); - - OperationLog log = new OperationLog(); - - // If there aren't even any keys, do nothing here. - if (entries == null || !entries.hasNext()) { - return new ImportKeyResult( - ImportKeyResult.RESULT_FAIL_NOTHING, log, 0, 0, 0, 0, - new long[]{}); - } - - int newKeys = 0, oldKeys = 0, badKeys = 0, secret = 0; - ArrayList importedMasterKeyIds = new ArrayList(); - - int position = 0; - double progSteps = 100.0 / num; - - // iterate over all entries - while (entries.hasNext()) { - ParcelableKeyRing entry = entries.next(); - - // Has this action been cancelled? If so, don't proceed any further - if (mCancelled != null && mCancelled.get()) { - break; - } - - try { - UncachedKeyRing key = UncachedKeyRing.decodeFromData(entry.getBytes()); - - String expectedFp = entry.getExpectedFingerprint(); - if(expectedFp != null) { - if(!KeyFormattingUtils.convertFingerprintToHex(key.getFingerprint()).equals(expectedFp)) { - Log.d(Constants.TAG, "fingerprint: " + KeyFormattingUtils.convertFingerprintToHex(key.getFingerprint())); - Log.d(Constants.TAG, "expected fingerprint: " + expectedFp); - Log.e(Constants.TAG, "Actual key fingerprint is not the same as expected!"); - badKeys += 1; - continue; - } else { - Log.d(Constants.TAG, "Actual key fingerprint matches expected one."); - } - } - - SaveKeyringResult result; - mProviderHelper.clearLog(); - if (key.isSecret()) { - result = mProviderHelper.saveSecretKeyRing(key, - new ProgressScaler(mProgressable, (int)(position*progSteps), (int)((position+1)*progSteps), 100)); - } else { - result = mProviderHelper.savePublicKeyRing(key, - new ProgressScaler(mProgressable, (int)(position*progSteps), (int)((position+1)*progSteps), 100)); - } - if (!result.success()) { - badKeys += 1; - } else if (result.updated()) { - oldKeys += 1; - importedMasterKeyIds.add(key.getMasterKeyId()); - } else { - newKeys += 1; - if (key.isSecret()) { - secret += 1; - } - importedMasterKeyIds.add(key.getMasterKeyId()); - } - - log.add(result, 1); - - } catch (IOException e) { - Log.e(Constants.TAG, "Encountered bad key on import!", e); - ++badKeys; - } catch (PgpGeneralException e) { - Log.e(Constants.TAG, "Encountered bad key on import!", e); - ++badKeys; - } - // update progress - position++; - } - - int resultType = 0; - // special return case: no new keys at all - if (badKeys == 0 && newKeys == 0 && oldKeys == 0) { - resultType = ImportKeyResult.RESULT_FAIL_NOTHING; - } else { - if (newKeys > 0) { - resultType |= ImportKeyResult.RESULT_OK_NEWKEYS; - } - if (oldKeys > 0) { - resultType |= ImportKeyResult.RESULT_OK_UPDATED; - } - if (badKeys > 0) { - resultType |= ImportKeyResult.RESULT_WITH_ERRORS; - if (newKeys == 0 && oldKeys == 0) { - resultType |= ImportKeyResult.RESULT_ERROR; - } - } - if (log.containsWarnings()) { - resultType |= ImportKeyResult.RESULT_WARNINGS; - } - } - if (mCancelled != null && mCancelled.get()) { - log.add(LogType.MSG_OPERATION_CANCELLED, 0); - resultType |= ImportKeyResult.RESULT_CANCELLED; - } - - // convert to long array - long[] importedMasterKeyIdsArray = new long[importedMasterKeyIds.size()]; - for (int i = 0; i < importedMasterKeyIds.size(); ++i) { - importedMasterKeyIdsArray[i] = importedMasterKeyIds.get(i); - } - - return new ImportKeyResult(resultType, log, newKeys, oldKeys, badKeys, secret, - importedMasterKeyIdsArray); - } - - public Bundle exportKeyRings(ArrayList publicKeyRingMasterIds, - ArrayList secretKeyRingMasterIds, - OutputStream outStream) throws PgpGeneralException, - PGPException, IOException { - Bundle returnData = new Bundle(); - - int masterKeyIdsSize = publicKeyRingMasterIds.size() + secretKeyRingMasterIds.size(); - int progress = 0; - - updateProgress( - mContext.getResources().getQuantityString(R.plurals.progress_exporting_key, - masterKeyIdsSize), 0, 100); - - if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { - throw new PgpGeneralException( - mContext.getString(R.string.error_external_storage_not_ready)); - } - // For each public masterKey id - for (long pubKeyMasterId : publicKeyRingMasterIds) { - progress++; - // Create an output stream - ArmoredOutputStream arOutStream = new ArmoredOutputStream(outStream); - String version = PgpHelper.getVersionForHeader(mContext); - if (version != null) { - arOutStream.setHeader("Version", version); - } - - updateProgress(progress * 100 / masterKeyIdsSize, 100); - - try { - CanonicalizedPublicKeyRing ring = mProviderHelper.getCanonicalizedPublicKeyRing( - KeychainContract.KeyRings.buildUnifiedKeyRingUri(pubKeyMasterId) - ); - - ring.encode(arOutStream); - } catch (ProviderHelper.NotFoundException e) { - Log.e(Constants.TAG, "key not found!", e); - // TODO: inform user? - } - - arOutStream.close(); - } - - // For each secret masterKey id - for (long secretKeyMasterId : secretKeyRingMasterIds) { - progress++; - // Create an output stream - ArmoredOutputStream arOutStream = new ArmoredOutputStream(outStream); - String version = PgpHelper.getVersionForHeader(mContext); - if (version != null) { - arOutStream.setHeader("Version", version); - } - - updateProgress(progress * 100 / masterKeyIdsSize, 100); - - try { - CanonicalizedSecretKeyRing secretKeyRing = - mProviderHelper.getCanonicalizedSecretKeyRing(secretKeyMasterId); - secretKeyRing.encode(arOutStream); - } catch (ProviderHelper.NotFoundException e) { - Log.e(Constants.TAG, "key not found!", e); - // TODO: inform user? - } - - arOutStream.close(); - } - - returnData.putInt(KeychainIntentService.RESULT_EXPORT, masterKeyIdsSize); - - updateProgress(R.string.progress_done, 100, 100); - - return returnData; - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/PgpCertifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/PgpCertifyOperation.java deleted file mode 100644 index 63dabc8db..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/ops/PgpCertifyOperation.java +++ /dev/null @@ -1,145 +0,0 @@ -package org.sufficientlysecure.keychain.pgp.ops; - -import android.content.Context; - -import org.spongycastle.openpgp.PGPException; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; -import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; -import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; -import org.sufficientlysecure.keychain.service.CertifyActionsParcel; -import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; -import org.sufficientlysecure.keychain.service.results.CertifyResult; -import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; -import org.sufficientlysecure.keychain.service.results.OperationResult.OperationLog; -import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; -import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; -import org.sufficientlysecure.keychain.util.Log; - -import java.util.ArrayList; -import java.util.concurrent.atomic.AtomicBoolean; - -public class PgpCertifyOperation extends BaseOperation { - - public PgpCertifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); - } - - public CertifyResult certify(CertifyActionsParcel parcel, String passphrase) { - - OperationLog log = new OperationLog(); - log.add(LogType.MSG_CRT, 0); - - // Retrieve and unlock secret key - CanonicalizedSecretKey certificationKey; - try { - log.add(LogType.MSG_CRT_MASTER_FETCH, 1); - CanonicalizedSecretKeyRing secretKeyRing = - mProviderHelper.getCanonicalizedSecretKeyRing(parcel.mMasterKeyId); - log.add(LogType.MSG_CRT_UNLOCK, 1); - certificationKey = secretKeyRing.getSecretKey(); - if (!certificationKey.unlock(passphrase)) { - log.add(LogType.MSG_CRT_ERROR_UNLOCK, 2); - return new CertifyResult(CertifyResult.RESULT_ERROR, log); - } - } catch (PgpGeneralException e) { - log.add(LogType.MSG_CRT_ERROR_UNLOCK, 2); - return new CertifyResult(CertifyResult.RESULT_ERROR, log); - } catch (NotFoundException e) { - log.add(LogType.MSG_CRT_ERROR_MASTER_NOT_FOUND, 2); - return new CertifyResult(CertifyResult.RESULT_ERROR, log); - } - - ArrayList certifiedKeys = new ArrayList(); - - log.add(LogType.MSG_CRT_CERTIFYING, 1); - - int certifyOk = 0, certifyError = 0; - - // Work through all requested certifications - for (CertifyAction action : parcel.mCertifyActions) { - - // Check if we were cancelled - if (checkCancelled()) { - log.add(LogType.MSG_OPERATION_CANCELLED, 0); - return new CertifyResult(CertifyResult.RESULT_CANCELLED, log); - } - - try { - - if (action.mUserIds == null) { - log.add(LogType.MSG_CRT_CERTIFY_ALL, 2, - KeyFormattingUtils.convertKeyIdToHex(action.mMasterKeyId)); - } else { - log.add(LogType.MSG_CRT_CERTIFY_SOME, 2, action.mUserIds.size(), - KeyFormattingUtils.convertKeyIdToHex(action.mMasterKeyId)); - } - - CanonicalizedPublicKeyRing publicRing = - mProviderHelper.getCanonicalizedPublicKeyRing(action.mMasterKeyId); - - UncachedKeyRing certifiedKey = certificationKey.certifyUserIds(publicRing, action.mUserIds, null, null); - certifiedKeys.add(certifiedKey); - - } catch (NotFoundException e) { - certifyError += 1; - log.add(LogType.MSG_CRT_WARN_NOT_FOUND, 3); - } catch (PGPException e) { - certifyError += 1; - log.add(LogType.MSG_CRT_WARN_CERT_FAILED, 3); - Log.e(Constants.TAG, "Encountered PGPException during certification", e); - } - - } - - log.add(LogType.MSG_CRT_SAVING, 1); - - // Check if we were cancelled - if (checkCancelled()) { - log.add(LogType.MSG_OPERATION_CANCELLED, 0); - return new CertifyResult(CertifyResult.RESULT_CANCELLED, log); - } - - // Write all certified keys into the database - for (UncachedKeyRing certifiedKey : certifiedKeys) { - - // Check if we were cancelled - if (checkCancelled()) { - log.add(LogType.MSG_OPERATION_CANCELLED, 0); - return new CertifyResult(CertifyResult.RESULT_CANCELLED, log, certifyOk, certifyError); - } - - log.add(LogType.MSG_CRT_SAVE, 2, - KeyFormattingUtils.convertKeyIdToHex(certifiedKey.getMasterKeyId())); - // store the signed key in our local cache - mProviderHelper.clearLog(); - SaveKeyringResult result = mProviderHelper.savePublicKeyRing(certifiedKey); - - if (result.success()) { - certifyOk += 1; - } else { - log.add(LogType.MSG_CRT_WARN_SAVE_FAILED, 3); - } - - log.add(result, 2); - - // TODO do something with import results - - } - - if (certifyOk == 0) { - log.add(LogType.MSG_CRT_ERROR_NOTHING, 0); - return new CertifyResult(CertifyResult.RESULT_ERROR, log, certifyOk, certifyError); - } - - log.add(LogType.MSG_CRT_SUCCESS, 0); - return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError); - - } - -} 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 b99a06ce0..2f3477c0d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.PgpHelper; -import org.sufficientlysecure.keychain.pgp.ops.ImportExportOperation; +import org.sufficientlysecure.keychain.operations.ImportExportOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; @@ -55,10 +55,10 @@ 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.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.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; +import org.sufficientlysecure.keychain.operations.results.ConsolidateResult; +import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.ParcelableFileCache; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index b78ab8a37..1ed1a7104 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; -import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; +import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; @@ -49,8 +49,8 @@ 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.OperationResult.LogEntryParcel; -import org.sufficientlysecure.keychain.service.results.SignEncryptResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogEntryParcel; +import org.sufficientlysecure.keychain.operations.results.SignEncryptResult; import org.sufficientlysecure.keychain.ui.ImportKeysActivity; import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity; 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 b43dec2f1..0e9678980 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,10 +30,9 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.util.ActionBarHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.remote.AccountSettings; -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.operations.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.SingletonResult; import org.sufficientlysecure.keychain.util.Log; public class AccountSettingsActivity extends ActionBarActivity { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/AccountSettingsFragment.java index a7eb58377..a3027f728 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,8 +33,8 @@ 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.OperationResult; -import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.ui.CreateKeyActivity; import org.sufficientlysecure.keychain.ui.adapter.KeyValueSpinnerAdapter; import org.sufficientlysecure.keychain.ui.widget.KeySpinner; 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 93c792564..56e3b22e2 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.OperationResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.util.Log; public class AppSettingsActivity extends ActionBarActivity { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 14c72970f..f2b96d82c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -29,10 +29,10 @@ import android.os.RemoteException; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.pgp.ops.PgpCertifyOperation; +import org.sufficientlysecure.keychain.operations.PgpCertifyOperation; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; -import org.sufficientlysecure.keychain.service.results.CertifyResult; +import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.util.FileHelper; import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; import org.sufficientlysecure.keychain.util.Preferences; @@ -45,9 +45,9 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.PassphraseCacheInterface; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; -import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; +import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.pgp.PgpHelper; -import org.sufficientlysecure.keychain.pgp.ops.ImportExportOperation; +import org.sufficientlysecure.keychain.operations.ImportExportOperation; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt; import org.sufficientlysecure.keychain.pgp.Progressable; @@ -55,18 +55,17 @@ import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -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.OperationResult; -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; -import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; -import org.sufficientlysecure.keychain.service.results.SignEncryptResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; +import org.sufficientlysecure.keychain.operations.results.ConsolidateResult; +import org.sufficientlysecure.keychain.operations.results.EditKeyResult; +import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; +import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; +import org.sufficientlysecure.keychain.operations.results.SignEncryptResult; import org.sufficientlysecure.keychain.util.ParcelableFileCache; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/CertifyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/CertifyResult.java deleted file mode 100644 index 49bc613bd..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/CertifyResult.java +++ /dev/null @@ -1,151 +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.SuperToast.Duration; -import com.github.johnpersano.supertoasts.util.OnClickWrapper; -import com.github.johnpersano.supertoasts.util.Style; - -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.ui.LogDisplayActivity; -import org.sufficientlysecure.keychain.ui.LogDisplayFragment; - -public class CertifyResult extends OperationResult { - - int mCertifyOk, mCertifyError; - - public CertifyResult(int result, OperationLog log) { - super(result, log); - } - - public CertifyResult(int result, OperationLog log, int certifyOk, int certifyError) { - this(result, log); - mCertifyOk = certifyOk; - mCertifyError = certifyError; - } - - /** Construct from a parcel - trivial because we have no extra data. */ - public CertifyResult(Parcel source) { - super(source); - mCertifyOk = source.readInt(); - mCertifyError = source.readInt(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeInt(mCertifyOk); - dest.writeInt(mCertifyError); - } - - public static Creator CREATOR = new Creator() { - public CertifyResult createFromParcel(final Parcel source) { - return new CertifyResult(source); - } - - public CertifyResult[] newArray(final int size) { - return new CertifyResult[size]; - } - }; - - public SuperCardToast createNotify(final Activity activity) { - - int resultType = getResult(); - - String str; - int duration, color; - - // Not an overall failure - if ((resultType & OperationResult.RESULT_ERROR) == 0) { - String withWarnings; - - duration = Duration.EXTRA_LONG; - color = Style.GREEN; - withWarnings = ""; - - // Any warnings? - if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { - duration = 0; - color = Style.ORANGE; - withWarnings += activity.getString(R.string.with_warnings); - } - if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { - duration = 0; - color = Style.ORANGE; - withWarnings += activity.getString(R.string.with_cancelled); - } - - // New and updated keys - str = activity.getResources().getQuantityString( - R.plurals.certify_keys_ok, mCertifyOk, mCertifyOk, withWarnings); - if (mCertifyError > 0) { - // definitely switch to warning-style message in this case! - duration = 0; - color = Style.RED; - str += " " + activity.getResources().getQuantityString( - R.plurals.certify_keys_with_errors, mCertifyError, mCertifyError); - } - - } else { - duration = 0; - color = Style.RED; - str = activity.getResources().getQuantityString(R.plurals.certify_error, - mCertifyError, mCertifyError); - } - - boolean button = getLog() != null && !getLog().isEmpty(); - SuperCardToast toast = new SuperCardToast(activity, - button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, - Style.getStyle(color, SuperToast.Animations.POPUP)); - toast.setText(str); - toast.setDuration(duration); - toast.setIndeterminate(duration == 0); - toast.setSwipeToDismiss(true); - // If we have a log and it's non-empty, show a View Log button - if (button) { - toast.setButtonIcon(R.drawable.ic_action_view_as_list, - activity.getResources().getString(R.string.view_log)); - toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); - toast.setTextColor(activity.getResources().getColor(R.color.black)); - toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", - new SuperToast.OnClickListener() { - @Override - public void onClick(View view, Parcelable token) { - Intent intent = new Intent( - activity, LogDisplayActivity.class); - intent.putExtra(LogDisplayFragment.EXTRA_RESULT, CertifyResult.this); - activity.startActivity(intent); - } - } - )); - } - - return toast; - - } - -} 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 deleted file mode 100644 index 2c6a96476..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ConsolidateResult.java +++ /dev/null @@ -1,49 +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.os.Parcel; - -public class ConsolidateResult extends OperationResult { - - public ConsolidateResult(int result, OperationLog log) { - super(result, log); - } - - /** Construct from a parcel - trivial because we have no extra data. */ - public ConsolidateResult(Parcel source) { - super(source); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - } - - public static Creator CREATOR = new Creator() { - public ConsolidateResult createFromParcel(final Parcel source) { - return new ConsolidateResult(source); - } - - public ConsolidateResult[] newArray(final int size) { - return new ConsolidateResult[size]; - } - }; - -} 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 deleted file mode 100644 index 7fa1b7363..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/DecryptVerifyResult.java +++ /dev/null @@ -1,132 +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.os.Parcel; - -import org.openintents.openpgp.OpenPgpMetadata; -import org.openintents.openpgp.OpenPgpSignatureResult; - -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; - - // fifth to sixth bit in addition indicate specific type of pending - public static final int RESULT_PENDING_ASYM_PASSPHRASE = RESULT_PENDING + 16; - public static final int RESULT_PENDING_SYM_PASSPHRASE = RESULT_PENDING + 32; - public static final int RESULT_PENDING_NFC = RESULT_PENDING + 64; - - long mKeyIdPassphraseNeeded; - - long mNfcSubKeyId; - byte[] mNfcSessionKey; - String mNfcPassphrase; - - OpenPgpSignatureResult mSignatureResult; - OpenPgpMetadata mDecryptMetadata; - - public long getKeyIdPassphraseNeeded() { - return mKeyIdPassphraseNeeded; - } - - public void setKeyIdPassphraseNeeded(long keyIdPassphraseNeeded) { - mKeyIdPassphraseNeeded = keyIdPassphraseNeeded; - } - - public void setNfcState(long subKeyId, byte[] sessionKey, String passphrase) { - mNfcSubKeyId = subKeyId; - mNfcSessionKey = sessionKey; - mNfcPassphrase = passphrase; - } - - public long getNfcSubKeyId() { - return mNfcSubKeyId; - } - - public byte[] getNfcEncryptedSessionKey() { - return mNfcSessionKey; - } - - public String getNfcPassphrase() { - return mNfcPassphrase; - } - - public OpenPgpSignatureResult getSignatureResult() { - return mSignatureResult; - } - - public void setSignatureResult(OpenPgpSignatureResult signatureResult) { - mSignatureResult = signatureResult; - } - - public OpenPgpMetadata getDecryptMetadata() { - return mDecryptMetadata; - } - - public void setDecryptMetadata(OpenPgpMetadata decryptMetadata) { - mDecryptMetadata = decryptMetadata; - } - - public boolean isPending() { - return (mResult & RESULT_PENDING) == RESULT_PENDING; - } - - public DecryptVerifyResult(int result, OperationLog log) { - super(result, log); - } - - public DecryptVerifyResult(Parcel source) { - super(source); - mKeyIdPassphraseNeeded = source.readLong(); - mSignatureResult = source.readParcelable(OpenPgpSignatureResult.class.getClassLoader()); - mDecryptMetadata = source.readParcelable(OpenPgpMetadata.class.getClassLoader()); - mNfcSessionKey = source.readInt() != 0 ? source.createByteArray() : null; - mNfcPassphrase = source.readString(); - } - - public int describeContents() { - return 0; - } - - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeLong(mKeyIdPassphraseNeeded); - dest.writeParcelable(mSignatureResult, 0); - dest.writeParcelable(mDecryptMetadata, 0); - if (mNfcSessionKey != null) { - dest.writeInt(1); - dest.writeByteArray(mNfcSessionKey); - } else { - dest.writeInt(0); - } - dest.writeString(mNfcPassphrase); - } - - public static final Creator CREATOR = new Creator() { - public DecryptVerifyResult createFromParcel(final Parcel source) { - return new DecryptVerifyResult(source); - } - - public DecryptVerifyResult[] newArray(final int size) { - return new DecryptVerifyResult[size]; - } - }; - -} 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 deleted file mode 100644 index 9385afd8e..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/EditKeyResult.java +++ /dev/null @@ -1,63 +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.os.Parcel; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; - -public class EditKeyResult extends OperationResult { - - private transient UncachedKeyRing mRing; - public final long mRingMasterKeyId; - - public EditKeyResult(int result, OperationLog log, - UncachedKeyRing ring) { - super(result, log); - mRing = ring; - mRingMasterKeyId = ring != null ? ring.getMasterKeyId() : Constants.key.none; - } - - public UncachedKeyRing getRing() { - return mRing; - } - - public EditKeyResult(Parcel source) { - super(source); - mRingMasterKeyId = source.readLong(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeLong(mRingMasterKeyId); - } - - public static Creator CREATOR = new Creator() { - public EditKeyResult createFromParcel(final Parcel source) { - return new EditKeyResult(source); - } - - public EditKeyResult[] newArray(final int size) { - return new EditKeyResult[size]; - } - }; - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/GetKeyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/GetKeyResult.java deleted file mode 100644 index e76d1bd41..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/GetKeyResult.java +++ /dev/null @@ -1,64 +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.os.Parcel; - -public class GetKeyResult extends OperationResult { - - public int mNonPgpPartsCount; - - public int getNonPgpPartsCount() { - return mNonPgpPartsCount; - } - - public void setNonPgpPartsCount(int nonPgpPartsCount) { - mNonPgpPartsCount = nonPgpPartsCount; - } - - public GetKeyResult(int result, OperationLog log) { - super(result, log); - } - - public static final int RESULT_ERROR_NO_VALID_KEYS = RESULT_ERROR + 8; - public static final int RESULT_ERROR_NO_PGP_PARTS = RESULT_ERROR + 16; - public static final int RESULT_ERROR_QUERY_TOO_SHORT = RESULT_ERROR + 32; - public static final int RESULT_ERROR_TOO_MANY_RESPONSES = RESULT_ERROR + 64; - public static final int RESULT_ERROR_TOO_SHORT_OR_TOO_MANY_RESPONSES = RESULT_ERROR + 128; - public static final int RESULT_ERROR_QUERY_FAILED = RESULT_ERROR + 256; - - public GetKeyResult(Parcel source) { - super(source); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - } - - public static Creator CREATOR = new Creator() { - public GetKeyResult createFromParcel(final Parcel source) { - return new GetKeyResult(source); - } - - public GetKeyResult[] newArray(final int size) { - return new GetKeyResult[size]; - } - }; -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java deleted file mode 100644 index b54dcc5d6..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java +++ /dev/null @@ -1,212 +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.SuperToast.Duration; -import com.github.johnpersano.supertoasts.util.OnClickWrapper; -import com.github.johnpersano.supertoasts.util.Style; - -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.ui.LogDisplayActivity; -import org.sufficientlysecure.keychain.ui.LogDisplayFragment; - -public class ImportKeyResult extends OperationResult { - - public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret; - public final long[] mImportedMasterKeyIds; - - // At least one new key - public static final int RESULT_OK_NEWKEYS = 8; - // At least one updated key - public static final int RESULT_OK_UPDATED = 16; - // At least one key failed (might still be an overall success) - public static final int RESULT_WITH_ERRORS = 32; - - // No keys to import... - public static final int RESULT_FAIL_NOTHING = 64 + 1; - - public boolean isOkBoth() { - return (mResult & (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED)) - == (RESULT_OK_NEWKEYS | RESULT_OK_UPDATED); - } - - public boolean isOkNew() { - return (mResult & RESULT_OK_NEWKEYS) == RESULT_OK_NEWKEYS; - } - - public boolean isOkUpdated() { - return (mResult & RESULT_OK_UPDATED) == RESULT_OK_UPDATED; - } - - public boolean isOkWithErrors() { - return (mResult & RESULT_WITH_ERRORS) == RESULT_WITH_ERRORS; - } - - public boolean isFailNothing() { - return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING; - } - - public long[] getImportedMasterKeyIds() { - return mImportedMasterKeyIds; - } - - public ImportKeyResult(Parcel source) { - super(source); - mNewKeys = source.readInt(); - mUpdatedKeys = source.readInt(); - mBadKeys = source.readInt(); - mSecret = source.readInt(); - mImportedMasterKeyIds = source.createLongArray(); - } - - public ImportKeyResult(int result, OperationLog log, - int newKeys, int updatedKeys, int badKeys, int secret, - long[] importedMasterKeyIds) { - super(result, log); - mNewKeys = newKeys; - mUpdatedKeys = updatedKeys; - mBadKeys = badKeys; - mSecret = secret; - mImportedMasterKeyIds = importedMasterKeyIds; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeInt(mNewKeys); - dest.writeInt(mUpdatedKeys); - dest.writeInt(mBadKeys); - dest.writeInt(mSecret); - dest.writeLongArray(mImportedMasterKeyIds); - } - - public static Creator CREATOR = new Creator() { - public ImportKeyResult createFromParcel(final Parcel source) { - return new ImportKeyResult(source); - } - - public ImportKeyResult[] newArray(final int size) { - return new ImportKeyResult[size]; - } - }; - - public SuperCardToast createNotify(final Activity activity) { - - int resultType = getResult(); - - String str; - int duration, color; - - // Not an overall failure - if ((resultType & OperationResult.RESULT_ERROR) == 0) { - String withWarnings; - - duration = Duration.EXTRA_LONG; - color = Style.GREEN; - withWarnings = ""; - - // Any warnings? - if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { - duration = 0; - color = Style.ORANGE; - withWarnings += activity.getString(R.string.with_warnings); - } - if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { - duration = 0; - color = Style.ORANGE; - withWarnings += activity.getString(R.string.with_cancelled); - } - - // New and updated keys - if (isOkBoth()) { - str = activity.getResources().getQuantityString( - R.plurals.import_keys_added_and_updated_1, mNewKeys, mNewKeys); - str += " " + activity.getResources().getQuantityString( - R.plurals.import_keys_added_and_updated_2, mUpdatedKeys, mUpdatedKeys, withWarnings); - } else if (isOkUpdated()) { - str = activity.getResources().getQuantityString( - R.plurals.import_keys_updated, mUpdatedKeys, mUpdatedKeys, withWarnings); - } else if (isOkNew()) { - str = activity.getResources().getQuantityString( - R.plurals.import_keys_added, mNewKeys, mNewKeys, withWarnings); - } else { - duration = 0; - color = Style.RED; - str = "internal error"; - } - if (isOkWithErrors()) { - // definitely switch to warning-style message in this case! - duration = 0; - color = Style.RED; - str += " " + activity.getResources().getQuantityString( - R.plurals.import_keys_with_errors, mBadKeys, mBadKeys); - } - - } else { - duration = 0; - color = Style.RED; - if (isFailNothing()) { - str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0 - ? R.string.import_error_nothing_cancelled - : R.string.import_error_nothing); - } else { - str = activity.getResources().getQuantityString(R.plurals.import_error, mBadKeys); - } - } - - boolean button = getLog() != null && !getLog().isEmpty(); - SuperCardToast toast = new SuperCardToast(activity, - button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, - Style.getStyle(color, SuperToast.Animations.POPUP)); - toast.setText(str); - toast.setDuration(duration); - toast.setIndeterminate(duration == 0); - toast.setSwipeToDismiss(true); - // If we have a log and it's non-empty, show a View Log button - if (button) { - toast.setButtonIcon(R.drawable.ic_action_view_as_list, - activity.getResources().getString(R.string.view_log)); - toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); - toast.setTextColor(activity.getResources().getColor(R.color.black)); - toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", - new SuperToast.OnClickListener() { - @Override - public void onClick(View view, Parcelable token) { - Intent intent = new Intent( - activity, LogDisplayActivity.class); - intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this); - activity.startActivity(intent); - } - } - )); - } - - return toast; - - } - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java deleted file mode 100644 index e3f2c1cc5..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java +++ /dev/null @@ -1,710 +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. - * - */ -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() { - // If there is only a single entry, and it's a compound one, return that log - if (mLog.isSingleCompound()) { - return ((SubLogEntryParcel) mLog.getFirst()).getSubResult().getLog(); - } - // Otherwse, return our regular log - return mLog; - } - - /** One entry in the log. */ - public static class LogEntryParcel implements Parcelable { - public final LogType mType; - public final Object[] mParameters; - public final int mIndent; - - public LogEntryParcel(LogType type, int indent, Object... parameters) { - mType = type; - mParameters = parameters; - mIndent = indent; - Log.v(Constants.TAG, "log: " + this); - } - - public LogEntryParcel(Parcel source) { - 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(0); - dest.writeInt(mType.ordinal()); - dest.writeSerializable(mParameters); - dest.writeInt(mIndent); - } - - public static final Creator CREATOR = new Creator() { - public LogEntryParcel createFromParcel(final Parcel source) { - // Actually create LogEntryParcel or SubLogEntryParcel depending on type indicator - if (source.readInt() == 0) { - return new LogEntryParcel(source); - } else { - return new SubLogEntryParcel(source); - } - } - - public LogEntryParcel[] newArray(final int size) { - return new LogEntryParcel[size]; - } - }; - - @Override - public String toString() { - return getClass().getSimpleName() + "{" + - "mLevel=" + mType.mLevel + - ", mType=" + mType + - ", mParameters=" + Arrays.toString(mParameters) + - ", mIndent=" + mIndent + - '}'; - } - } - - public static class SubLogEntryParcel extends LogEntryParcel { - - OperationResult mSubResult; - - public SubLogEntryParcel(OperationResult subResult, LogType type, int indent, Object... parameters) { - super(type, indent, parameters); - mSubResult = subResult; - - Log.v(Constants.TAG, "log: " + this); - } - - public SubLogEntryParcel(Parcel source) { - super(source); - mSubResult = source.readParcelable(SubLogEntryParcel.class.getClassLoader()); - } - - public OperationResult getSubResult() { - return mSubResult; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(1); - dest.writeInt(mType.ordinal()); - dest.writeSerializable(mParameters); - dest.writeInt(mIndent); - dest.writeParcelable(mSubResult, 0); - } - - } - - public SuperCardToast createNotify(final Activity activity) { - - int color; - - Log.d(Constants.TAG, "mLog.getLast()"+mLog.getLast()); - Log.d(Constants.TAG, "mLog.getLast().mType"+mLog.getLast().mType); - Log.d(Constants.TAG, "mLog.getLast().mType.getMsgId()"+mLog.getLast().mType.getMsgId()); - - // 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 (LogLevel.ERROR, R.string.msg_internal_error), - MSG_OPERATION_CANCELLED (LogLevel.CANCELLED, R.string.msg_cancelled), - - // import public - MSG_IP(LogLevel.START, R.string.msg_ip), - MSG_IP_APPLY_BATCH (LogLevel.DEBUG, R.string.msg_ip_apply_batch), - MSG_IP_BAD_TYPE_SECRET (LogLevel.WARN, R.string.msg_ip_bad_type_secret), - MSG_IP_DELETE_OLD_FAIL (LogLevel.DEBUG, R.string.msg_ip_delete_old_fail), - MSG_IP_DELETE_OLD_OK (LogLevel.DEBUG, R.string.msg_ip_delete_old_ok), - MSG_IP_ENCODE_FAIL (LogLevel.DEBUG, R.string.msg_ip_encode_fail), - MSG_IP_ERROR_IO_EXC (LogLevel.ERROR, R.string.msg_ip_error_io_exc), - MSG_IP_ERROR_OP_EXC (LogLevel.ERROR, R.string.msg_ip_error_op_exc), - MSG_IP_ERROR_REMOTE_EX (LogLevel.ERROR, R.string.msg_ip_error_remote_ex), - MSG_IP_INSERT_KEYRING (LogLevel.DEBUG, R.string.msg_ip_insert_keyring), - MSG_IP_INSERT_SUBKEYS (LogLevel.DEBUG, R.string.msg_ip_insert_keys), - MSG_IP_PREPARE (LogLevel.DEBUG, R.string.msg_ip_prepare), - MSG_IP_REINSERT_SECRET (LogLevel.DEBUG, R.string.msg_ip_reinsert_secret), - MSG_IP_MASTER (LogLevel.DEBUG, R.string.msg_ip_master), - MSG_IP_MASTER_EXPIRED (LogLevel.DEBUG, R.string.msg_ip_master_expired), - MSG_IP_MASTER_EXPIRES (LogLevel.DEBUG, R.string.msg_ip_master_expires), - MSG_IP_MASTER_FLAGS_UNSPECIFIED (LogLevel.DEBUG, R.string.msg_ip_master_flags_unspecified), - MSG_IP_MASTER_FLAGS_CESA (LogLevel.DEBUG, R.string.msg_ip_master_flags_cesa), - MSG_IP_MASTER_FLAGS_CESX (LogLevel.DEBUG, R.string.msg_ip_master_flags_cesx), - MSG_IP_MASTER_FLAGS_CEXA (LogLevel.DEBUG, R.string.msg_ip_master_flags_cexa), - MSG_IP_MASTER_FLAGS_CEXX (LogLevel.DEBUG, R.string.msg_ip_master_flags_cexx), - MSG_IP_MASTER_FLAGS_CXSA (LogLevel.DEBUG, R.string.msg_ip_master_flags_cxsa), - MSG_IP_MASTER_FLAGS_CXSX (LogLevel.DEBUG, R.string.msg_ip_master_flags_cxsx), - MSG_IP_MASTER_FLAGS_CXXA (LogLevel.DEBUG, R.string.msg_ip_master_flags_cxxa), - MSG_IP_MASTER_FLAGS_CXXX (LogLevel.DEBUG, R.string.msg_ip_master_flags_cxxx), - MSG_IP_MASTER_FLAGS_XESA (LogLevel.DEBUG, R.string.msg_ip_master_flags_xesa), - MSG_IP_MASTER_FLAGS_XESX (LogLevel.DEBUG, R.string.msg_ip_master_flags_xesx), - MSG_IP_MASTER_FLAGS_XEXA (LogLevel.DEBUG, R.string.msg_ip_master_flags_xexa), - MSG_IP_MASTER_FLAGS_XEXX (LogLevel.DEBUG, R.string.msg_ip_master_flags_xexx), - MSG_IP_MASTER_FLAGS_XXSA (LogLevel.DEBUG, R.string.msg_ip_master_flags_xxsa), - MSG_IP_MASTER_FLAGS_XXSX (LogLevel.DEBUG, R.string.msg_ip_master_flags_xxsx), - MSG_IP_MASTER_FLAGS_XXXA (LogLevel.DEBUG, R.string.msg_ip_master_flags_xxxa), - MSG_IP_MASTER_FLAGS_XXXX (LogLevel.DEBUG, R.string.msg_ip_master_flags_xxxx), - MSG_IP_SUBKEY (LogLevel.DEBUG, R.string.msg_ip_subkey), - MSG_IP_SUBKEY_EXPIRED (LogLevel.DEBUG, R.string.msg_ip_subkey_expired), - MSG_IP_SUBKEY_EXPIRES (LogLevel.DEBUG, R.string.msg_ip_subkey_expires), - MSG_IP_SUBKEY_FLAGS_UNSPECIFIED (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cesa), - MSG_IP_SUBKEY_FLAGS_CESA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cesa), - MSG_IP_SUBKEY_FLAGS_CESX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cesx), - MSG_IP_SUBKEY_FLAGS_CEXA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cexa), - MSG_IP_SUBKEY_FLAGS_CEXX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cexx), - MSG_IP_SUBKEY_FLAGS_CXSA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cxsa), - MSG_IP_SUBKEY_FLAGS_CXSX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cxsx), - MSG_IP_SUBKEY_FLAGS_CXXA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cxxa), - MSG_IP_SUBKEY_FLAGS_CXXX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_cxxx), - MSG_IP_SUBKEY_FLAGS_XESA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xesa), - MSG_IP_SUBKEY_FLAGS_XESX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xesx), - MSG_IP_SUBKEY_FLAGS_XEXA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xexa), - MSG_IP_SUBKEY_FLAGS_XEXX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xexx), - MSG_IP_SUBKEY_FLAGS_XXSA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xxsa), - MSG_IP_SUBKEY_FLAGS_XXSX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xxsx), - MSG_IP_SUBKEY_FLAGS_XXXA (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xxxa), - MSG_IP_SUBKEY_FLAGS_XXXX (LogLevel.DEBUG, R.string.msg_ip_subkey_flags_xxxx), - MSG_IP_SUCCESS (LogLevel.OK, R.string.msg_ip_success), - MSG_IP_SUCCESS_IDENTICAL (LogLevel.OK, R.string.msg_ip_success_identical), - MSG_IP_UID_CERT_BAD (LogLevel.WARN, R.string.msg_ip_uid_cert_bad), - MSG_IP_UID_CERT_ERROR (LogLevel.WARN, R.string.msg_ip_uid_cert_error), - MSG_IP_UID_CERT_OLD (LogLevel.DEBUG, R.string.msg_ip_uid_cert_old), - MSG_IP_UID_CERT_NONREVOKE (LogLevel.DEBUG, R.string.msg_ip_uid_cert_nonrevoke), - MSG_IP_UID_CERT_NEW (LogLevel.DEBUG, R.string.msg_ip_uid_cert_new), - MSG_IP_UID_CERT_GOOD (LogLevel.DEBUG, R.string.msg_ip_uid_cert_good), - MSG_IP_UID_CERT_GOOD_REVOKE (LogLevel.DEBUG, R.string.msg_ip_uid_cert_good_revoke), - MSG_IP_UID_CERTS_UNKNOWN (LogLevel.DEBUG, R.plurals.msg_ip_uid_certs_unknown), - MSG_IP_UID_CLASSIFYING_ZERO (LogLevel.DEBUG, R.string.msg_ip_uid_classifying_zero), - MSG_IP_UID_CLASSIFYING (LogLevel.DEBUG, R.plurals.msg_ip_uid_classifying), - MSG_IP_UID_REORDER(LogLevel.DEBUG, R.string.msg_ip_uid_reorder), - MSG_IP_UID_PROCESSING (LogLevel.DEBUG, R.string.msg_ip_uid_processing), - MSG_IP_UID_REVOKED (LogLevel.DEBUG, R.string.msg_ip_uid_revoked), - - // import secret - MSG_IS(LogLevel.START, R.string.msg_is), - MSG_IS_BAD_TYPE_PUBLIC (LogLevel.WARN, R.string.msg_is_bad_type_public), - MSG_IS_DB_EXCEPTION (LogLevel.DEBUG, R.string.msg_is_db_exception), - MSG_IS_ERROR_IO_EXC(LogLevel.DEBUG, R.string.msg_is_error_io_exc), - MSG_IS_IMPORTING_SUBKEYS (LogLevel.DEBUG, R.string.msg_is_importing_subkeys), - MSG_IS_PUBRING_GENERATE (LogLevel.DEBUG, R.string.msg_is_pubring_generate), - MSG_IS_SUBKEY_NONEXISTENT (LogLevel.DEBUG, R.string.msg_is_subkey_nonexistent), - MSG_IS_SUBKEY_OK (LogLevel.OK, R.string.msg_is_subkey_ok), - MSG_IS_SUBKEY_STRIPPED (LogLevel.DEBUG, R.string.msg_is_subkey_stripped), - MSG_IS_SUBKEY_DIVERT (LogLevel.DEBUG, R.string.msg_is_subkey_divert), - MSG_IS_SUBKEY_EMPTY (LogLevel.DEBUG, R.string.msg_is_subkey_empty), - MSG_IS_SUCCESS_IDENTICAL (LogLevel.OK, R.string.msg_is_success_identical), - MSG_IS_SUCCESS (LogLevel.OK, R.string.msg_is_success), - - // keyring canonicalization - MSG_KC_PUBLIC (LogLevel.DEBUG, R.string.msg_kc_public), - MSG_KC_SECRET (LogLevel.DEBUG, R.string.msg_kc_secret), - MSG_KC_ERROR_V3 (LogLevel.ERROR, R.string.msg_kc_error_v3), - MSG_KC_ERROR_NO_UID (LogLevel.ERROR, R.string.msg_kc_error_no_uid), - MSG_KC_ERROR_MASTER_ALGO (LogLevel.ERROR, R.string.msg_kc_error_master_algo), - MSG_KC_ERROR_DUP_KEY (LogLevel.ERROR, R.string.msg_kc_error_dup_key), - MSG_KC_MASTER (LogLevel.DEBUG, R.string.msg_kc_master), - MSG_KC_REVOKE_BAD_ERR (LogLevel.WARN, R.string.msg_kc_revoke_bad_err), - MSG_KC_REVOKE_BAD_LOCAL (LogLevel.WARN, R.string.msg_kc_revoke_bad_local), - MSG_KC_REVOKE_BAD_TIME (LogLevel.WARN, R.string.msg_kc_revoke_bad_time), - MSG_KC_REVOKE_BAD_TYPE (LogLevel.WARN, R.string.msg_kc_revoke_bad_type), - MSG_KC_REVOKE_BAD_TYPE_UID (LogLevel.WARN, R.string.msg_kc_revoke_bad_type_uid), - MSG_KC_REVOKE_BAD (LogLevel.WARN, R.string.msg_kc_revoke_bad), - MSG_KC_REVOKE_DUP (LogLevel.DEBUG, R.string.msg_kc_revoke_dup), - MSG_KC_SUB (LogLevel.DEBUG, R.string.msg_kc_sub), - MSG_KC_SUB_BAD(LogLevel.WARN, R.string.msg_kc_sub_bad), - MSG_KC_SUB_BAD_ERR(LogLevel.WARN, R.string.msg_kc_sub_bad_err), - MSG_KC_SUB_BAD_LOCAL(LogLevel.WARN, R.string.msg_kc_sub_bad_local), - MSG_KC_SUB_BAD_KEYID(LogLevel.WARN, R.string.msg_kc_sub_bad_keyid), - MSG_KC_SUB_BAD_TIME(LogLevel.WARN, R.string.msg_kc_sub_bad_time), - MSG_KC_SUB_BAD_TYPE(LogLevel.WARN, R.string.msg_kc_sub_bad_type), - MSG_KC_SUB_DUP (LogLevel.DEBUG, R.string.msg_kc_sub_dup), - MSG_KC_SUB_PRIMARY_BAD(LogLevel.WARN, R.string.msg_kc_sub_primary_bad), - MSG_KC_SUB_PRIMARY_BAD_ERR(LogLevel.WARN, R.string.msg_kc_sub_primary_bad_err), - MSG_KC_SUB_PRIMARY_NONE(LogLevel.DEBUG, R.string.msg_kc_sub_primary_none), - MSG_KC_SUB_NO_CERT(LogLevel.DEBUG, R.string.msg_kc_sub_no_cert), - MSG_KC_SUB_REVOKE_BAD_ERR (LogLevel.WARN, R.string.msg_kc_sub_revoke_bad_err), - MSG_KC_SUB_REVOKE_BAD (LogLevel.WARN, R.string.msg_kc_sub_revoke_bad), - MSG_KC_SUB_REVOKE_DUP (LogLevel.DEBUG, R.string.msg_kc_sub_revoke_dup), - MSG_KC_SUB_UNKNOWN_ALGO (LogLevel.WARN, R.string.msg_kc_sub_unknown_algo), - MSG_KC_SUB_ALGO_BAD_ENCRYPT (LogLevel.WARN, R.string.msg_kc_sub_algo_bad_encrpyt), - MSG_KC_SUB_ALGO_BAD_SIGN (LogLevel.WARN, R.string.msg_kc_sub_algo_bad_sign), - MSG_KC_SUCCESS_BAD (LogLevel.OK, R.plurals.msg_kc_success_bad), - MSG_KC_SUCCESS_BAD_AND_RED (LogLevel.OK, R.string.msg_kc_success_bad_and_red), - MSG_KC_SUCCESS_REDUNDANT (LogLevel.OK, R.plurals.msg_kc_success_redundant), - MSG_KC_SUCCESS (LogLevel.OK, R.string.msg_kc_success), - MSG_KC_UID_BAD_ERR (LogLevel.WARN, R.string.msg_kc_uid_bad_err), - MSG_KC_UID_BAD_LOCAL (LogLevel.WARN, R.string.msg_kc_uid_bad_local), - MSG_KC_UID_BAD_TIME (LogLevel.WARN, R.string.msg_kc_uid_bad_time), - MSG_KC_UID_BAD_TYPE (LogLevel.WARN, R.string.msg_kc_uid_bad_type), - MSG_KC_UID_BAD (LogLevel.WARN, R.string.msg_kc_uid_bad), - MSG_KC_UID_CERT_DUP (LogLevel.DEBUG, R.string.msg_kc_uid_cert_dup), - MSG_KC_UID_DUP (LogLevel.DEBUG, R.string.msg_kc_uid_dup), - MSG_KC_UID_FOREIGN (LogLevel.DEBUG, R.string.msg_kc_uid_foreign), - MSG_KC_UID_NO_CERT (LogLevel.DEBUG, R.string.msg_kc_uid_no_cert), - MSG_KC_UID_REVOKE_DUP (LogLevel.DEBUG, R.string.msg_kc_uid_revoke_dup), - MSG_KC_UID_REVOKE_OLD (LogLevel.DEBUG, R.string.msg_kc_uid_revoke_old), - MSG_KC_UID_REMOVE (LogLevel.DEBUG, R.string.msg_kc_uid_remove), - MSG_KC_UID_WARN_ENCODING (LogLevel.WARN, R.string.msg_kc_uid_warn_encoding), - - - // keyring consolidation - MSG_MG_ERROR_SECRET_DUMMY(LogLevel.ERROR, R.string.msg_mg_error_secret_dummy), - MSG_MG_ERROR_ENCODE(LogLevel.ERROR, R.string.msg_mg_error_encode), - MSG_MG_ERROR_HETEROGENEOUS(LogLevel.ERROR, R.string.msg_mg_error_heterogeneous), - MSG_MG_PUBLIC (LogLevel.START, R.string.msg_mg_public), - MSG_MG_SECRET (LogLevel.START, R.string.msg_mg_secret), - MSG_MG_NEW_SUBKEY (LogLevel.DEBUG, R.string.msg_mg_new_subkey), - MSG_MG_FOUND_NEW (LogLevel.OK, R.string.msg_mg_found_new), - MSG_MG_UNCHANGED (LogLevel.OK, R.string.msg_mg_unchanged), - - // secret key create - MSG_CR (LogLevel.START, R.string.msg_cr), - MSG_CR_ERROR_NO_MASTER (LogLevel.ERROR, R.string.msg_cr_error_no_master), - MSG_CR_ERROR_NO_USER_ID (LogLevel.ERROR, R.string.msg_cr_error_no_user_id), - MSG_CR_ERROR_NO_CERTIFY (LogLevel.ERROR, R.string.msg_cr_error_no_certify), - MSG_CR_ERROR_NULL_EXPIRY(LogLevel.ERROR, R.string.msg_cr_error_null_expiry), - MSG_CR_ERROR_KEYSIZE_512 (LogLevel.ERROR, R.string.msg_cr_error_keysize_512), - MSG_CR_ERROR_NO_KEYSIZE (LogLevel.ERROR, R.string.msg_cr_error_no_keysize), - MSG_CR_ERROR_NO_CURVE (LogLevel.ERROR, R.string.msg_cr_error_no_curve), - MSG_CR_ERROR_UNKNOWN_ALGO (LogLevel.ERROR, R.string.msg_cr_error_unknown_algo), - MSG_CR_ERROR_INTERNAL_PGP (LogLevel.ERROR, R.string.msg_cr_error_internal_pgp), - MSG_CR_ERROR_FLAGS_DSA (LogLevel.ERROR, R.string.msg_cr_error_flags_dsa), - MSG_CR_ERROR_FLAGS_ELGAMAL (LogLevel.ERROR, R.string.msg_cr_error_flags_elgamal), - MSG_CR_ERROR_FLAGS_ECDSA (LogLevel.ERROR, R.string.msg_cr_error_flags_ecdsa), - MSG_CR_ERROR_FLAGS_ECDH (LogLevel.ERROR, R.string.msg_cr_error_flags_ecdh), - - // secret key modify - MSG_MF (LogLevel.START, R.string.msg_mr), - MSG_MF_ERROR_ENCODE (LogLevel.ERROR, R.string.msg_mf_error_encode), - MSG_MF_ERROR_FINGERPRINT (LogLevel.ERROR, R.string.msg_mf_error_fingerprint), - MSG_MF_ERROR_KEYID (LogLevel.ERROR, R.string.msg_mf_error_keyid), - MSG_MF_ERROR_INTEGRITY (LogLevel.ERROR, R.string.msg_mf_error_integrity), - MSG_MF_ERROR_MASTER_NONE(LogLevel.ERROR, R.string.msg_mf_error_master_none), - MSG_MF_ERROR_NO_CERTIFY (LogLevel.ERROR, R.string.msg_cr_error_no_certify), - MSG_MF_ERROR_NOEXIST_PRIMARY (LogLevel.ERROR, R.string.msg_mf_error_noexist_primary), - MSG_MF_ERROR_NOEXIST_REVOKE (LogLevel.ERROR, R.string.msg_mf_error_noexist_revoke), - MSG_MF_ERROR_NULL_EXPIRY (LogLevel.ERROR, R.string.msg_mf_error_null_expiry), - MSG_MF_ERROR_PASSPHRASE_MASTER(LogLevel.ERROR, R.string.msg_mf_error_passphrase_master), - MSG_MF_ERROR_PAST_EXPIRY(LogLevel.ERROR, R.string.msg_mf_error_past_expiry), - MSG_MF_ERROR_PGP (LogLevel.ERROR, R.string.msg_mf_error_pgp), - MSG_MF_ERROR_REVOKED_PRIMARY (LogLevel.ERROR, R.string.msg_mf_error_revoked_primary), - MSG_MF_ERROR_SIG (LogLevel.ERROR, R.string.msg_mf_error_sig), - MSG_MF_ERROR_SUBKEY_MISSING(LogLevel.ERROR, R.string.msg_mf_error_subkey_missing), - MSG_MF_MASTER (LogLevel.DEBUG, R.string.msg_mf_master), - MSG_MF_PASSPHRASE (LogLevel.INFO, R.string.msg_mf_passphrase), - MSG_MF_PASSPHRASE_KEY (LogLevel.DEBUG, R.string.msg_mf_passphrase_key), - MSG_MF_PASSPHRASE_EMPTY_RETRY (LogLevel.DEBUG, R.string.msg_mf_passphrase_empty_retry), - MSG_MF_PASSPHRASE_FAIL (LogLevel.WARN, R.string.msg_mf_passphrase_fail), - MSG_MF_PRIMARY_REPLACE_OLD (LogLevel.DEBUG, R.string.msg_mf_primary_replace_old), - MSG_MF_PRIMARY_NEW (LogLevel.DEBUG, R.string.msg_mf_primary_new), - MSG_MF_SUBKEY_CHANGE (LogLevel.INFO, R.string.msg_mf_subkey_change), - MSG_MF_SUBKEY_NEW_ID (LogLevel.DEBUG, R.string.msg_mf_subkey_new_id), - MSG_MF_SUBKEY_NEW (LogLevel.INFO, R.string.msg_mf_subkey_new), - MSG_MF_SUBKEY_REVOKE (LogLevel.INFO, R.string.msg_mf_subkey_revoke), - MSG_MF_SUBKEY_STRIP (LogLevel.INFO, R.string.msg_mf_subkey_strip), - MSG_MF_SUCCESS (LogLevel.OK, R.string.msg_mf_success), - MSG_MF_UID_ADD (LogLevel.INFO, R.string.msg_mf_uid_add), - MSG_MF_UID_PRIMARY (LogLevel.INFO, R.string.msg_mf_uid_primary), - MSG_MF_UID_REVOKE (LogLevel.INFO, R.string.msg_mf_uid_revoke), - MSG_MF_UID_ERROR_EMPTY (LogLevel.ERROR, R.string.msg_mf_uid_error_empty), - MSG_MF_UNLOCK_ERROR (LogLevel.ERROR, R.string.msg_mf_unlock_error), - MSG_MF_UNLOCK (LogLevel.DEBUG, R.string.msg_mf_unlock), - - // consolidate - MSG_CON_CRITICAL_IN (LogLevel.DEBUG, R.string.msg_con_critical_in), - MSG_CON_CRITICAL_OUT (LogLevel.DEBUG, R.string.msg_con_critical_out), - MSG_CON_DB_CLEAR (LogLevel.DEBUG, R.string.msg_con_db_clear), - MSG_CON_DELETE_PUBLIC (LogLevel.DEBUG, R.string.msg_con_delete_public), - MSG_CON_DELETE_SECRET (LogLevel.DEBUG, R.string.msg_con_delete_secret), - MSG_CON_ERROR_BAD_STATE (LogLevel.ERROR, R.string.msg_con_error_bad_state), - MSG_CON_ERROR_CONCURRENT(LogLevel.ERROR, R.string.msg_con_error_concurrent), - MSG_CON_ERROR_DB (LogLevel.ERROR, R.string.msg_con_error_db), - MSG_CON_ERROR_IO_PUBLIC (LogLevel.ERROR, R.string.msg_con_error_io_public), - MSG_CON_ERROR_IO_SECRET (LogLevel.ERROR, R.string.msg_con_error_io_secret), - MSG_CON_ERROR_PUBLIC (LogLevel.ERROR, R.string.msg_con_error_public), - MSG_CON_ERROR_SECRET (LogLevel.ERROR, R.string.msg_con_error_secret), - MSG_CON_RECOVER (LogLevel.DEBUG, R.string.msg_con_recover), - MSG_CON_REIMPORT_PUBLIC (LogLevel.DEBUG, R.plurals.msg_con_reimport_public), - MSG_CON_REIMPORT_PUBLIC_SKIP (LogLevel.DEBUG, R.string.msg_con_reimport_public_skip), - MSG_CON_REIMPORT_SECRET (LogLevel.DEBUG, R.plurals.msg_con_reimport_secret), - MSG_CON_REIMPORT_SECRET_SKIP (LogLevel.DEBUG, R.string.msg_con_reimport_secret_skip), - MSG_CON (LogLevel.START, R.string.msg_con), - MSG_CON_SAVE_PUBLIC (LogLevel.DEBUG, R.string.msg_con_save_public), - MSG_CON_SAVE_SECRET (LogLevel.DEBUG, R.string.msg_con_save_secret), - MSG_CON_SUCCESS (LogLevel.OK, R.string.msg_con_success), - MSG_CON_WARN_DELETE_PUBLIC (LogLevel.WARN, R.string.msg_con_warn_delete_public), - MSG_CON_WARN_DELETE_SECRET (LogLevel.WARN, R.string.msg_con_warn_delete_secret), - - // messages used in UI code - MSG_EK_ERROR_DIVERT (LogLevel.ERROR, R.string.msg_ek_error_divert), - MSG_EK_ERROR_DUMMY (LogLevel.ERROR, R.string.msg_ek_error_dummy), - MSG_EK_ERROR_NOT_FOUND (LogLevel.ERROR, R.string.msg_ek_error_not_found), - - // decryptverify - MSG_DC_ASKIP_NO_KEY (LogLevel.DEBUG, R.string.msg_dc_askip_no_key), - MSG_DC_ASKIP_NOT_ALLOWED (LogLevel.DEBUG, R.string.msg_dc_askip_not_allowed), - MSG_DC_ASYM (LogLevel.DEBUG, R.string.msg_dc_asym), - MSG_DC_CLEAR_DATA (LogLevel.DEBUG, R.string.msg_dc_clear_data), - MSG_DC_CLEAR_DECOMPRESS (LogLevel.DEBUG, R.string.msg_dc_clear_decompress), - MSG_DC_CLEAR_META_FILE (LogLevel.DEBUG, R.string.msg_dc_clear_meta_file), - MSG_DC_CLEAR_META_MIME (LogLevel.DEBUG, R.string.msg_dc_clear_meta_mime), - MSG_DC_CLEAR_META_SIZE (LogLevel.DEBUG, R.string.msg_dc_clear_meta_size), - MSG_DC_CLEAR_META_TIME (LogLevel.DEBUG, R.string.msg_dc_clear_meta_time), - MSG_DC_CLEAR (LogLevel.DEBUG, R.string.msg_dc_clear), - MSG_DC_CLEAR_SIGNATURE_BAD (LogLevel.WARN, R.string.msg_dc_clear_signature_bad), - MSG_DC_CLEAR_SIGNATURE_CHECK (LogLevel.DEBUG, R.string.msg_dc_clear_signature_check), - MSG_DC_CLEAR_SIGNATURE_OK (LogLevel.OK, R.string.msg_dc_clear_signature_ok), - MSG_DC_CLEAR_SIGNATURE (LogLevel.DEBUG, R.string.msg_dc_clear_signature), - MSG_DC_ERROR_BAD_PASSPHRASE (LogLevel.ERROR, R.string.msg_dc_error_bad_passphrase), - MSG_DC_ERROR_EXTRACT_KEY (LogLevel.ERROR, R.string.msg_dc_error_extract_key), - MSG_DC_ERROR_INTEGRITY_CHECK (LogLevel.ERROR, R.string.msg_dc_error_integrity_check), - MSG_DC_ERROR_INVALID_SIGLIST(LogLevel.ERROR, R.string.msg_dc_error_invalid_siglist), - MSG_DC_ERROR_IO (LogLevel.ERROR, R.string.msg_dc_error_io), - MSG_DC_ERROR_NO_DATA (LogLevel.ERROR, R.string.msg_dc_error_no_data), - MSG_DC_ERROR_NO_KEY (LogLevel.ERROR, R.string.msg_dc_error_no_key), - MSG_DC_ERROR_PGP_EXCEPTION (LogLevel.ERROR, R.string.msg_dc_error_pgp_exception), - MSG_DC_INTEGRITY_CHECK_OK (LogLevel.INFO, R.string.msg_dc_integrity_check_ok), - MSG_DC_OK_META_ONLY (LogLevel.OK, R.string.msg_dc_ok_meta_only), - MSG_DC_OK (LogLevel.OK, R.string.msg_dc_ok), - MSG_DC_PASS_CACHED (LogLevel.DEBUG, R.string.msg_dc_pass_cached), - MSG_DC_PENDING_NFC (LogLevel.INFO, R.string.msg_dc_pending_nfc), - MSG_DC_PENDING_PASSPHRASE (LogLevel.INFO, R.string.msg_dc_pending_passphrase), - MSG_DC_PREP_STREAMS (LogLevel.DEBUG, R.string.msg_dc_prep_streams), - MSG_DC (LogLevel.DEBUG, R.string.msg_dc), - MSG_DC_SYM (LogLevel.DEBUG, R.string.msg_dc_sym), - MSG_DC_SYM_SKIP (LogLevel.DEBUG, R.string.msg_dc_sym_skip), - MSG_DC_TRAIL_ASYM (LogLevel.DEBUG, R.string.msg_dc_trail_asym), - MSG_DC_TRAIL_SYM (LogLevel.DEBUG, R.string.msg_dc_trail_sym), - MSG_DC_TRAIL_UNKNOWN (LogLevel.DEBUG, R.string.msg_dc_trail_unknown), - MSG_DC_UNLOCKING (LogLevel.INFO, R.string.msg_dc_unlocking), - - // signencrypt - MSG_SE_ASYMMETRIC (LogLevel.INFO, R.string.msg_se_asymmetric), - MSG_SE_CLEARSIGN_ONLY (LogLevel.DEBUG, R.string.msg_se_clearsign_only), - MSG_SE_COMPRESSING (LogLevel.DEBUG, R.string.msg_se_compressing), - MSG_SE_ENCRYPTING (LogLevel.DEBUG, R.string.msg_se_encrypting), - MSG_SE_ERROR_BAD_PASSPHRASE (LogLevel.ERROR, R.string.msg_se_error_bad_passphrase), - MSG_SE_ERROR_IO (LogLevel.ERROR, R.string.msg_se_error_io), - MSG_SE_ERROR_SIGN_KEY(LogLevel.ERROR, R.string.msg_se_error_sign_key), - MSG_SE_ERROR_KEY_SIGN (LogLevel.ERROR, R.string.msg_se_error_key_sign), - MSG_SE_ERROR_NFC (LogLevel.ERROR, R.string.msg_se_error_nfc), - MSG_SE_ERROR_PGP (LogLevel.ERROR, R.string.msg_se_error_pgp), - MSG_SE_ERROR_SIG (LogLevel.ERROR, R.string.msg_se_error_sig), - MSG_SE_ERROR_UNLOCK (LogLevel.ERROR, R.string.msg_se_error_unlock), - MSG_SE_KEY_OK (LogLevel.OK, R.string.msg_se_key_ok), - MSG_SE_KEY_UNKNOWN (LogLevel.DEBUG, R.string.msg_se_key_unknown), - MSG_SE_KEY_WARN (LogLevel.WARN, R.string.msg_se_key_warn), - MSG_SE_OK (LogLevel.OK, R.string.msg_se_ok), - MSG_SE_PENDING_NFC (LogLevel.INFO, R.string.msg_se_pending_nfc), - MSG_SE_PENDING_PASSPHRASE (LogLevel.INFO, R.string.msg_se_pending_passphrase), - MSG_SE (LogLevel.DEBUG, R.string.msg_se), - MSG_SE_SIGNING (LogLevel.DEBUG, R.string.msg_se_signing), - MSG_SE_SIGCRYPTING (LogLevel.DEBUG, R.string.msg_se_sigcrypting), - MSG_SE_SYMMETRIC (LogLevel.INFO, R.string.msg_se_symmetric), - - MSG_CRT_CERTIFYING (LogLevel.DEBUG, R.string.msg_crt_certifying), - MSG_CRT_CERTIFY_ALL (LogLevel.DEBUG, R.string.msg_crt_certify_all), - MSG_CRT_CERTIFY_SOME (LogLevel.DEBUG, R.plurals.msg_crt_certify_some), - MSG_CRT_ERROR_MASTER_NOT_FOUND (LogLevel.ERROR, R.string.msg_crt_error_master_not_found), - MSG_CRT_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_crt_error_nothing), - MSG_CRT_ERROR_UNLOCK (LogLevel.ERROR, R.string.msg_crt_error_unlock), - MSG_CRT (LogLevel.START, R.string.msg_crt), - MSG_CRT_MASTER_FETCH (LogLevel.DEBUG, R.string.msg_crt_master_fetch), - MSG_CRT_SAVE (LogLevel.DEBUG, R.string.msg_crt_save), - MSG_CRT_SAVING (LogLevel.DEBUG, R.string.msg_crt_saving), - MSG_CRT_SUCCESS (LogLevel.OK, R.string.msg_crt_success), - MSG_CRT_UNLOCK (LogLevel.DEBUG, R.string.msg_crt_unlock), - MSG_CRT_WARN_NOT_FOUND (LogLevel.WARN, R.string.msg_crt_warn_not_found), - MSG_CRT_WARN_CERT_FAILED (LogLevel.WARN, R.string.msg_crt_warn_cert_failed), - MSG_CRT_WARN_SAVE_FAILED (LogLevel.WARN, R.string.msg_crt_warn_save_failed), - - MSG_CRT_UPLOAD_SUCCESS (LogLevel.OK, R.string.msg_crt_upload_success), - - MSG_ACC_SAVED (LogLevel.INFO, R.string.api_settings_save_msg), - - MSG_NO_VALID_ENC (LogLevel.ERROR, R.string.error_invalid_data), - - // get key - MSG_GET_SUCCESS(LogLevel.OK, R.string.msg_download_success), - MSG_GET_NO_VALID_KEYS(LogLevel.ERROR, R.string.msg_download_no_valid_keys), - MSG_GET_NO_PGP_PARTS(LogLevel.ERROR, R.string.msg_download_no_pgp_parts), - MSG_GET_QUERY_TOO_SHORT(LogLevel.ERROR, R.string.msg_download_query_too_short), - MSG_GET_TOO_MANY_RESPONSES(LogLevel.ERROR, R.string.msg_download_too_many_responses), - MSG_GET_QUERY_TOO_SHORT_OR_TOO_MANY_RESPONSES(LogLevel.ERROR, R.string.msg_download_query_too_short_or_too_many_responses), - MSG_GET_QUERY_FAILED(LogLevel.ERROR, R.string.msg_download_query_failed) - ; - - public final int mMsgId; - public final LogLevel mLevel; - LogType(LogLevel level, int msgId) { - mLevel = level; - 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(LogType type, int indent, Object... parameters) { - mParcels.add(new OperationResult.LogEntryParcel(type, indent, parameters)); - } - - public void add(LogType type, int indent) { - mParcels.add(new OperationResult.LogEntryParcel(type, indent, (Object[]) null)); - } - - public void add(OperationResult subResult, int indent) { - OperationLog subLog = subResult.getLog(); - mParcels.add(new SubLogEntryParcel(subResult, subLog.getFirst().mType, indent, subLog.getFirst().mParameters)); - } - - boolean isSingleCompound() { - return mParcels.size() == 1 && getFirst() instanceof SubLogEntryParcel; - } - - public void clear() { - mParcels.clear(); - } - - 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.mType.mLevel == LogLevel.WARN || entry.mType.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 getFirst() { - if (mParcels.isEmpty()) { - return null; - } - return mParcels.get(0); - } - - 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 deleted file mode 100644 index e229a5c6a..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SaveKeyringResult.java +++ /dev/null @@ -1,68 +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.os.Parcel; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; - -public class SaveKeyringResult extends OperationResult { - - public final long mRingMasterKeyId; - - public SaveKeyringResult(int result, OperationLog log, - CanonicalizedKeyRing ring) { - super(result, log); - mRingMasterKeyId = ring != null ? ring.getMasterKeyId() : Constants.key.none; - } - - // Some old key was updated - public static final int UPDATED = 4; - - // Public key was saved - public static final int SAVED_PUBLIC = 8; - // Secret key was saved (not exclusive with public!) - public static final int SAVED_SECRET = 16; - - public boolean updated() { - return (mResult & UPDATED) == UPDATED; - } - - public SaveKeyringResult(Parcel source) { - super(source); - mRingMasterKeyId = source.readLong(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeLong(mRingMasterKeyId); - } - - public static Creator CREATOR = new Creator() { - public SaveKeyringResult createFromParcel(final Parcel source) { - return new SaveKeyringResult(source); - } - - public SaveKeyringResult[] newArray(final int size) { - return new SaveKeyringResult[size]; - } - }; -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java deleted file mode 100644 index cded70b7f..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SignEncryptResult.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) 2014 Vincent Breitmoser - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.sufficientlysecure.keychain.service.results; - -import android.os.Parcel; - -import java.util.Date; - -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; - - // fifth to sixth bit in addition indicate specific type of pending - public static final int RESULT_PENDING_PASSPHRASE = RESULT_PENDING + 16; - public static final int RESULT_PENDING_NFC = RESULT_PENDING + 32; - - long mKeyIdPassphraseNeeded; - - long mNfcKeyId; - byte[] mNfcHash; - int mNfcAlgo; - Date mNfcTimestamp; - String mNfcPassphrase; - - public long getKeyIdPassphraseNeeded() { - return mKeyIdPassphraseNeeded; - } - - public void setKeyIdPassphraseNeeded(long keyIdPassphraseNeeded) { - mKeyIdPassphraseNeeded = keyIdPassphraseNeeded; - } - - public void setNfcData(long nfcKeyId, byte[] nfcHash, int nfcAlgo, Date nfcTimestamp, String passphrase) { - mNfcKeyId = nfcKeyId; - mNfcHash = nfcHash; - mNfcAlgo = nfcAlgo; - mNfcTimestamp = nfcTimestamp; - mNfcPassphrase = passphrase; - } - - public long getNfcKeyId() { - return mNfcKeyId; - } - - public byte[] getNfcHash() { - return mNfcHash; - } - - public int getNfcAlgo() { - return mNfcAlgo; - } - - public Date getNfcTimestamp() { - return mNfcTimestamp; - } - - public String getNfcPassphrase() { - return mNfcPassphrase; - } - - public boolean isPending() { - return (mResult & RESULT_PENDING) == RESULT_PENDING; - } - - public SignEncryptResult(int result, OperationLog log) { - super(result, log); - } - - public SignEncryptResult(Parcel source) { - super(source); - mNfcHash = source.readInt() != 0 ? source.createByteArray() : null; - mNfcAlgo = source.readInt(); - mNfcTimestamp = source.readInt() != 0 ? new Date(source.readLong()) : null; - } - - public int describeContents() { - return 0; - } - - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - if (mNfcHash != null) { - dest.writeInt(1); - dest.writeByteArray(mNfcHash); - } else { - dest.writeInt(0); - } - dest.writeInt(mNfcAlgo); - if (mNfcTimestamp != null) { - dest.writeInt(1); - dest.writeLong(mNfcTimestamp.getTime()); - } else { - dest.writeInt(0); - } - } - - public static final Creator CREATOR = new Creator() { - public SignEncryptResult createFromParcel(final Parcel source) { - return new SignEncryptResult(source); - } - - public SignEncryptResult[] newArray(final int size) { - return new SignEncryptResult[size]; - } - }; - -} \ No newline at end of file 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 deleted file mode 100644 index 430c739d9..000000000 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/SingletonResult.java +++ /dev/null @@ -1,87 +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.os.Parcel; - -import com.github.johnpersano.supertoasts.SuperCardToast; -import com.github.johnpersano.supertoasts.SuperToast; -import com.github.johnpersano.supertoasts.util.Style; - -/** This is a simple subclass meant to contain only a single log message. This log - * message is also shown without a log button in the createNotify SuperToast. */ -public class SingletonResult extends OperationResult { - - /** Construct from a parcel - trivial because we have no extra data. */ - public SingletonResult(Parcel source) { - super(source); - } - - public SingletonResult(int result, LogType reason) { - super(result, new OperationLog()); - // Prepare the log - mLog.add(reason, 0); - } - - @Override - public SuperCardToast createNotify(final Activity activity) { - - // there is exactly one error msg - use that one - String str = activity.getString(mLog.iterator().next().mType.getMsgId()); - int color; - - // Determine color by result type - if (cancelled()) { - color = Style.RED; - } else if (success()) { - if (getLog().containsWarnings()) { - color = Style.ORANGE; - } else { - color = Style.GREEN; - } - } else { - color = Style.RED; - } - - SuperCardToast toast = new SuperCardToast(activity, SuperToast.Type.STANDARD, - Style.getStyle(color, SuperToast.Animations.POPUP)); - toast.setText(str); - toast.setDuration(SuperToast.Duration.EXTRA_LONG); - toast.setIndeterminate(false); - toast.setSwipeToDismiss(true); - return toast; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - } - - public static Creator CREATOR = new Creator() { - public SingletonResult createFromParcel(final Parcel source) { - return new SingletonResult(source); - } - - public SingletonResult[] newArray(final int size) { - return new SingletonResult[size]; - } - }; - -} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/AddKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/AddKeysActivity.java index 427fc9315..63e640706 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/AddKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/AddKeysActivity.java @@ -42,9 +42,9 @@ import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.results.GetKeyResult; -import org.sufficientlysecure.keychain.service.results.ImportKeyResult; -import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.GetKeyResult; +import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.ui.adapter.AsyncTaskResultWrapper; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader; import org.sufficientlysecure.keychain.ui.util.Notify; 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 0c3eeece4..63d124b88 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -50,8 +50,8 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; -import org.sufficientlysecure.keychain.service.results.CertifyResult; -import org.sufficientlysecure.keychain.service.results.SingletonResult; +import org.sufficientlysecure.keychain.operations.results.CertifyResult; +import org.sufficientlysecure.keychain.operations.results.SingletonResult; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; @@ -59,7 +59,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.PassphraseCacheService; -import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner; 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 a2775de7e..bcc98a5d7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -39,10 +39,10 @@ import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; -import org.sufficientlysecure.keychain.service.results.SaveKeyringResult; +import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.Log; public class CreateKeyFinalFragment extends Fragment { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java index 6001687a1..681e22e1e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptActivity.java @@ -22,7 +22,6 @@ import android.annotation.TargetApi; import android.content.Intent; import android.os.AsyncTask; import android.os.Build; -import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.view.View; @@ -30,7 +29,7 @@ import android.view.View; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; import org.sufficientlysecure.keychain.pgp.PgpHelper; -import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.ui.util.SubtleAttentionSeeker; import java.util.regex.Matcher; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java index 2cc7b0bbb..691f1c240 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFilesFragment.java @@ -36,7 +36,7 @@ import org.openintents.openpgp.util.OpenPgpApi; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.util.FileHelper; -import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; +import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java index b7d204851..7f06d36e8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -29,7 +29,7 @@ import org.openintents.openpgp.OpenPgpSignatureResult; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; +import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; public abstract class DecryptFragment extends Fragment { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java index 28010884b..2da76088a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextActivity.java @@ -28,8 +28,8 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.api.OpenKeychainIntents; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; import org.sufficientlysecure.keychain.pgp.PgpHelper; -import org.sufficientlysecure.keychain.service.results.OperationResult; -import org.sufficientlysecure.keychain.service.results.SingletonResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.SingletonResult; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.ui.util.Notify; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java index 78345e11c..fa7abf0f5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptTextFragment.java @@ -23,7 +23,6 @@ import android.content.Intent; import android.os.Bundle; import android.os.Message; import android.os.Messenger; -import android.text.method.ScrollingMovementMethod; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -37,7 +36,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult; +import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ShareHelper; 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 dce86abd2..e2d241825 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -43,17 +43,15 @@ import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.ui.util.ActionBarHelper; import org.sufficientlysecure.keychain.pgp.KeyRing; -import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; 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.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.operations.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; +import org.sufficientlysecure.keychain.operations.results.SingletonResult; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java index 5fc047911..b9058a37d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptActivity.java @@ -10,7 +10,7 @@ import org.openintents.openpgp.util.OpenPgpApi; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.results.SignEncryptResult; +import org.sufficientlysecure.keychain.operations.results.SignEncryptResult; import java.util.Date; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java index 09d6b3d21..054d85323 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptFilesActivity.java @@ -33,7 +33,7 @@ import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.ShareHelper; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.service.KeychainIntentService; -import org.sufficientlysecure.keychain.service.results.SignEncryptResult; +import org.sufficientlysecure.keychain.operations.results.SignEncryptResult; import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.ui.util.Notify; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java index d05989bb2..958daa122 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptTextActivity.java @@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.ShareHelper; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.service.KeychainIntentService; -import org.sufficientlysecure.keychain.service.results.SignEncryptResult; +import org.sufficientlysecure.keychain.operations.results.SignEncryptResult; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.ui.util.Notify; 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 f0bd2c76c..6ef73cd36 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -34,21 +34,18 @@ import android.support.v7.app.ActionBarActivity; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; -import android.view.ViewGroup; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.api.OpenKeychainIntents; -import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; -import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.results.OperationResult; -import org.sufficientlysecure.keychain.service.results.ImportKeyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout; import org.sufficientlysecure.keychain.util.ParcelableFileCache; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java index ad50ecd3d..aa1b24263 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysListFragment.java @@ -31,11 +31,10 @@ import android.widget.ListView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.service.results.GetKeyResult; +import org.sufficientlysecure.keychain.operations.results.GetKeyResult; import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize; import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; -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; @@ -43,7 +42,6 @@ import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListCloudLoader; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListLoader; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.ui.util.Notify; import java.io.ByteArrayInputStream; import java.io.FileNotFoundException; 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 42d40b008..a0423ccd0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java @@ -24,7 +24,6 @@ import android.net.Uri; import android.os.Bundle; import android.os.Message; import android.os.Messenger; -import android.support.v4.util.LongSparseArray; import android.view.Menu; import android.view.MenuItem; @@ -34,19 +33,17 @@ import com.google.zxing.integration.android.IntentResult; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; -import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; 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.ConsolidateResult; -import org.sufficientlysecure.keychain.service.results.ImportKeyResult; -import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.ConsolidateResult; +import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.ExportHelper; import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4; import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.ParcelableFileCache; import org.sufficientlysecure.keychain.util.Preferences; import java.io.IOException; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 4a04c6c85..b0872a71a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -64,8 +64,8 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; -import org.sufficientlysecure.keychain.service.results.ImportKeyResult; -import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.ExportHelper; import org.sufficientlysecure.keychain.util.KeyUpdateHelper; 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 0f59b6d6a..6166faf10 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java @@ -34,10 +34,10 @@ import android.widget.ImageView; import android.widget.TextView; import org.sufficientlysecure.keychain.R; -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.service.results.OperationResult.SubLogEntryParcel; +import org.sufficientlysecure.keychain.operations.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogEntryParcel; +import org.sufficientlysecure.keychain.operations.results.OperationResult.LogLevel; +import org.sufficientlysecure.keychain.operations.results.OperationResult.SubLogEntryParcel; public class LogDisplayFragment extends ListFragment implements OnItemClickListener { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java index 34589c8e7..b9eab2260 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java @@ -44,7 +44,6 @@ import android.widget.ListView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; -import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; @@ -55,8 +54,8 @@ import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyActio import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.PassphraseCacheService; -import org.sufficientlysecure.keychain.service.results.CertifyResult; -import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.CertifyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.ui.util.Notify; 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 eff1f7d46..d19d3747a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -57,7 +57,7 @@ import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; -import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout; import org.sufficientlysecure.keychain.ui.widget.SlidingTabLayout.TabColorizer; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/AsyncTaskResultWrapper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/AsyncTaskResultWrapper.java index dc0c5846a..152629ef4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/AsyncTaskResultWrapper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/AsyncTaskResultWrapper.java @@ -17,7 +17,7 @@ package org.sufficientlysecure.keychain.ui.adapter; -import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; /** * The AsyncTaskResultWrapper is used to wrap a result from a AsyncTask (for example: Loader). 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 index cb51a15a9..176c3ff5b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java @@ -22,8 +22,8 @@ import android.support.v4.content.AsyncTaskLoader; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.keyimport.Keyserver; -import org.sufficientlysecure.keychain.service.results.GetKeyResult; -import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.GetKeyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.keyimport.CloudSearch; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java index 6664cb61a..41c7e0cbc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java @@ -25,8 +25,8 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.service.results.GetKeyResult; -import org.sufficientlysecure.keychain.service.results.OperationResult; +import org.sufficientlysecure.keychain.operations.results.GetKeyResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.PositionAwareInputStream; -- cgit v1.2.3